Skip to content

Commit

Permalink
refactor: Step into with UnconditionalBreakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien-noal committed Dec 10, 2024
1 parent 45abead commit e69f978
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Spice86/Spice86DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public Spice86DependencyInjection(ILoggerService loggerService, Configuration co
DebugWindowViewModel? debugWindowViewModel = null;
if (textClipboard != null && hostStorageProvider != null && uiThreadDispatcher != null) {
IMessenger messenger = WeakReferenceMessenger.Default;
debugWindowViewModel = new DebugWindowViewModel(cpu, state, stack, memory,
debugWindowViewModel = new DebugWindowViewModel(state, stack, memory,
midiDevice, videoState.DacRegisters.ArgbPalette, softwareMixer, vgaRenderer, videoState,
cfgCpu.ExecutionContextManager, messenger, uiThreadDispatcher, textClipboard, hostStorageProvider,
emulatorBreakpointsManager,
Expand Down
8 changes: 8 additions & 0 deletions src/Spice86/ViewModels/BreakpointsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ private void ToggleSelectedBreakpoint() {
[NotifyCanExecuteChangedFor(nameof(ToggleSelectedBreakpointCommand))]
private BreakpointViewModel? _selectedBreakpoint;

internal void AddUnconditionalBreakpoint(Action onReached, bool removedOnTrigger) {
_emulatorBreakpointsManager.ToggleBreakPoint(
new UnconditionalBreakPoint(
BreakPointType.EXECUTION,
(_) => onReached(),
removedOnTrigger), on: true);
}

internal void AddAddressBreakpoint(
long address,
BreakPointType type,
Expand Down
4 changes: 2 additions & 2 deletions src/Spice86/ViewModels/DebugWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public partial class DebugWindowViewModel : ViewModelBase,

private readonly IPauseHandler _pauseHandler;

public DebugWindowViewModel(IInstructionExecutor cpu, State cpuState, Stack stack, IMemory memory, Midi externalMidiDevice,
public DebugWindowViewModel(State cpuState, Stack stack, IMemory memory, Midi externalMidiDevice,
ArgbPalette argbPalette, SoftwareMixer softwareMixer, IVgaRenderer vgaRenderer, VideoState videoState,
ExecutionContextManager executionContextManager, IMessenger messenger, IUIDispatcher uiDispatcher,
ITextClipboard textClipboard, IHostStorageProvider storageProvider, EmulatorBreakpointsManager emulatorBreakpointsManager,
Expand All @@ -79,7 +79,7 @@ public DebugWindowViewModel(IInstructionExecutor cpu, State cpuState, Stack stac
pauseHandler.Pausing += () => uiDispatcher.Post(() => IsPaused = true);
pauseHandler.Resumed += () => uiDispatcher.Post(() => IsPaused = false);
DisassemblyViewModel disassemblyVm = new(
cpu, memory, cpuState, functionsInformation.ToDictionary(x => x.Key.ToPhysical(), x => x.Value),
memory, cpuState, functionsInformation.ToDictionary(x => x.Key.ToPhysical(), x => x.Value),
BreakpointsViewModel, pauseHandler,
uiDispatcher, messenger, textClipboard);
DisassemblyViewModels.Add(disassemblyVm);
Expand Down
18 changes: 12 additions & 6 deletions src/Spice86/ViewModels/DisassemblyViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ public partial class DisassemblyViewModel : ViewModelWithErrorDialog {
private readonly State _state;
private readonly IMessenger _messenger;
private readonly IPauseHandler _pauseHandler;
private readonly IInstructionExecutor _cpu;
private readonly BreakpointsViewModel _breakpointsViewModel;
private readonly IDictionary<uint, FunctionInformation> _functionsInformation;
private readonly InstructionsDecoder _instructionsDecoder;

public DisassemblyViewModel(
IInstructionExecutor cpu, IMemory memory, State state,
IMemory memory, State state,
IDictionary<uint, FunctionInformation> functionsInformation,
BreakpointsViewModel breakpointsViewModel,
IPauseHandler pauseHandler, IUIDispatcher uiDispatcher,
IMessenger messenger, ITextClipboard textClipboard, bool canCloseTab = false)
: base(uiDispatcher, textClipboard) {
_cpu = cpu;
_functionsInformation = functionsInformation;
Functions = new(functionsInformation
.Select(x => new FunctionInfo() {
Expand Down Expand Up @@ -201,7 +199,10 @@ private void EnableBreakpoint() {

[RelayCommand(CanExecute = nameof(IsPaused))]
private async Task StepInto() {
_cpu.ExecuteNext();
_breakpointsViewModel.AddUnconditionalBreakpoint(
() => Pause("Step into unconditional breakpoint was reached"),
removedOnTrigger: true);
_pauseHandler.Resume();
if (!Instructions.GetRange(0, 15).Any(x => x.Address == _state.IpPhysicalAddress)) {
await GoToCsIp();
} else {
Expand All @@ -212,8 +213,9 @@ private async Task StepInto() {
[RelayCommand(CanExecute = nameof(IsPaused))]
private void NewDisassemblyView() {
DisassemblyViewModel disassemblyViewModel = new(
_cpu, _memory, _state, _functionsInformation,
_breakpointsViewModel, _pauseHandler, _uiDispatcher, _messenger,
_memory, _state, _functionsInformation,
_breakpointsViewModel,
_pauseHandler, _uiDispatcher, _messenger,
_textClipboard, canCloseTab: true) {
IsPaused = IsPaused
};
Expand Down Expand Up @@ -302,6 +304,10 @@ private async Task CopyLine() {

private void RequestPause(long address) {
string message = $"Execution breakpoint was reached at address {address}.";
Pause(message);
}

private void Pause(string message) {
_pauseHandler.RequestPause(message);
_uiDispatcher.Post(() => {
_messenger.Send(new StatusMessage(DateTime.Now, this, message));
Expand Down

0 comments on commit e69f978

Please sign in to comment.