-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(debugger): basic Breakpoints View
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
- Loading branch information
1 parent
0a8d5d4
commit 69176d0
Showing
10 changed files
with
257 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
namespace Spice86.ViewModels; | ||
|
||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
using Spice86.Core.Emulator.VM; | ||
using Spice86.Core.Emulator.VM.Breakpoint; | ||
using Spice86.Models.Debugging; | ||
|
||
using System; | ||
|
||
public partial class BreakpointViewModel : ViewModelBase { | ||
private readonly BreakPoint _breakPoint; | ||
private readonly EmulatorBreakpointsManager _emulatorBreakpointsManager; | ||
|
||
public BreakpointViewModel(EmulatorBreakpointsManager emulatorBreakpointsManager, BreakPoint breakPoint) { | ||
public BreakpointViewModel(EmulatorBreakpointsManager emulatorBreakpointsManager, AddressBreakPoint breakPoint) { | ||
_breakPoint = breakPoint; | ||
_emulatorBreakpointsManager = emulatorBreakpointsManager; | ||
IsEnabled = true; | ||
Address = breakPoint.Address; | ||
} | ||
|
||
public string Type => _breakPoint.BreakPointType.ToString(); | ||
|
||
//Can't get out of sync since GDB can't be used at the same tiem as the internal debugger | ||
[ObservableProperty] | ||
private bool _isEnabled; | ||
|
||
public bool IsRemovedOnTrigger => _breakPoint.IsRemovedOnTrigger; | ||
|
||
public long Address { get; } | ||
|
||
public void Toggle() { | ||
if (IsEnabled) { | ||
Disable(); | ||
} else { | ||
Enable(); | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void Enable() => _emulatorBreakpointsManager.ToggleBreakPoint(_breakPoint, on: true); | ||
|
||
public void Enable() { | ||
_emulatorBreakpointsManager.ToggleBreakPoint(_breakPoint, on: true); | ||
IsEnabled = true; | ||
} | ||
|
||
[RelayCommand] | ||
private void Disable() => _emulatorBreakpointsManager.ToggleBreakPoint(_breakPoint, on: false); | ||
public void Disable() { | ||
_emulatorBreakpointsManager.ToggleBreakPoint(_breakPoint, on: false); | ||
IsEnabled = false; | ||
} | ||
|
||
internal bool IsFor(CpuInstructionInfo instructionInfo) { | ||
return _breakPoint is AddressBreakPoint addressBreakPoint && addressBreakPoint.Address == instructionInfo.Address; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
namespace Spice86.ViewModels; | ||
|
||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
using Spice86.Core.Emulator.VM; | ||
using Spice86.Core.Emulator.VM.Breakpoint; | ||
using Spice86.Models.Debugging; | ||
|
||
using System; | ||
using System.Collections.ObjectModel; | ||
|
||
public partial class BreakpointsViewModel : ViewModelBase { | ||
private readonly EmulatorBreakpointsManager _emulatorBreakpointsManager; | ||
|
||
public BreakpointsViewModel(EmulatorBreakpointsManager emulatorBreakpointsManager) { | ||
_emulatorBreakpointsManager = emulatorBreakpointsManager; | ||
} | ||
|
||
[ObservableProperty] | ||
private bool _showBreakpointCreationDialog = false; | ||
|
||
[ObservableProperty] | ||
private ObservableCollection<BreakpointViewModel> _breakpoints = new(); | ||
|
||
[RelayCommand(CanExecute = nameof(ToggleSelectedBreakpointCanExecute))] | ||
private void ToggleSelectedBreakpoint() { | ||
if (SelectedBreakpoint is not null) { | ||
SelectedBreakpoint.Toggle(); | ||
} | ||
} | ||
|
||
private bool ToggleSelectedBreakpointCanExecute() => SelectedBreakpoint is not null; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(RemoveBreakpointCommand))] | ||
[NotifyCanExecuteChangedFor(nameof(ToggleSelectedBreakpointCommand))] | ||
private BreakpointViewModel? _selectedBreakpoint; | ||
|
||
internal void AddAddressBreakpoint(AddressBreakPoint addressBreakPoint) { | ||
var breakpointViewModel = new BreakpointViewModel(_emulatorBreakpointsManager, addressBreakPoint); | ||
Breakpoints.Add(breakpointViewModel); | ||
SelectedBreakpoint = breakpointViewModel; | ||
} | ||
|
||
[RelayCommand] | ||
private void Create() { | ||
ShowBreakpointCreationDialog = true; | ||
} | ||
|
||
private bool RemoveBreakpointCanExecute() => SelectedBreakpoint is not null; | ||
|
||
|
||
[RelayCommand(CanExecute = nameof(RemoveBreakpointCanExecute))] | ||
private void RemoveBreakpoint() { | ||
if (SelectedBreakpoint is not null) { | ||
Breakpoints.Remove(SelectedBreakpoint); | ||
} | ||
} | ||
|
||
internal bool HasBreakpoint(CpuInstructionInfo instructionInfo) { | ||
return Breakpoints.Any(x => x.IsFor(instructionInfo)); | ||
} | ||
|
||
internal void RemoveBreakpoint(CpuInstructionInfo selectedInstruction) { | ||
BreakpointViewModel? breakpoint = Breakpoints.FirstOrDefault(x => x.IsFor(selectedInstruction)); | ||
if (breakpoint is not null) { | ||
breakpoint.Disable(); | ||
Breakpoints.Remove(breakpoint); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:viewModels="clr-namespace:Spice86.ViewModels" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="Spice86.Views.BreakpointsView" | ||
x:DataType="viewModels:BreakpointsViewModel"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center"> | ||
<Button Content="Create..." Command="{Binding CreateCommand}" Margin="5"/> | ||
<Button Content="Remove" Command="{Binding RemoveBreakpointCommand}" Margin="5"/> | ||
<Button Content="Toggle" Command="{Binding ToggleSelectedBreakpointCommand}" Margin="5"/> | ||
</StackPanel> | ||
<DataGrid Grid.Row="1" | ||
ItemsSource="{Binding Breakpoints}" | ||
SelectedItem="{Binding SelectedBreakpoint, Mode=TwoWay}" | ||
AutoGenerateColumns="False" | ||
CanUserReorderColumns="True" | ||
CanUserResizeColumns="True" | ||
CanUserSortColumns="False" | ||
IsReadOnly="True" | ||
SelectionMode="Extended"> | ||
<DataGrid.Columns> | ||
<DataGridCheckBoxColumn Binding="{Binding IsEnabled}" Header="Is Enabled ?" /> | ||
<DataGridCheckBoxColumn Binding="{Binding IsRemovedOnTrigger}" Header="Is removed on trigger ?" /> | ||
<DataGridTextColumn Binding="{Binding Address}" Header="Address" /> | ||
<DataGridTextColumn Binding="{Binding Type}" Header="Type" /> | ||
</DataGrid.Columns> | ||
</DataGrid> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Spice86.Views; | ||
using Avalonia.Controls; | ||
|
||
public partial class BreakpointsView : UserControl | ||
{ | ||
public BreakpointsView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
Oops, something went wrong.