Add debugger to machine code monitor#701
Draft
chrisgleissner wants to merge 113 commits into
Draft
Conversation
… files: home/F2 (start of file) and end/F8 (end of file)
…prove keyboard shortcuts.
…correct CPU bank switching
…ctly and via Telnet
…switch (similar to joystick switch) with CBM-I. Improve ROM cache handling.
…, editing, and commit features
…ve opcode picker functionality
Removed section on patch safety and related details.
…debug PC visibility adjustments
…ndling, cleanup tests and RAM editing regressions. Improve transfer command to optionally amend absolute operands.
…EST memory writing logic
…nt highlighting to breakpoint label.
…for register value polling and breakpoint management.
…stale owner expiration
…nsure correct setup
…ing functionality
…ing and enhance freeze/restore functionality.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a debugger to the Machine Code Monitor introduced by PR 358.
Overview
The debugger is available from the Assembly view and works across Telnet, UI Overlay, and UI Freeze modes. It adds interactive stepping, breakpoints, live CPU status and target prediction.
Please note that all features described below are fully implemented and tested on a U64 Elite I. This PR is in Draft mode nevertheless until the underlying Machine Code Monitor work will have been merged to
master, at which point I'll merge master into this PR's branch, resolve any merge conflicts, and remove the Draft status.The following chapters list features, show a demo as well as screenshots, and then cover the design, test approach, and known limitations.
Looking for U2 Testers
I only own an Ultimate 64 (and Commodore 64 Ultimate).
Thus, if anyone owns a U2 cartridge, I'd very much appreciate it if you could test this new feature on your device and let me know what works and what doesn't. Please have a look at the Known Limitations chapter first.
Many thanks.
Features
In the following overview, keyboard shortcuts are bolded.
Stepping and execution
Live CPU status
$0314/$0315and$0318/$0319.NV-BDIZC) are highlighted.Target prediction
Breakpoints
Free exploration while debugging
Multi-mode debugging
Convenient reset
Notes:
BRKopcode in the in-memory mirror of the ROM file. On a U2, such a mirror does not exist and hardware ROM can of course not be modified.Demo
The demo shows a small program cycling the background colour, followed by stepping through KERNAL and BASIC:
https://youtu.be/ECsqq5HKPlE
Screenshots
Debugger
The following screenshot shows the debugger paused in the Kernal
SCNKEYsubroutine, which checks for pressed keys:Dbgflag in the top right shows that debug mode is active. At$EA87, the start of the subroutine,[KEY]marks a breakpoint.$EA98. PressingDwould take the highlighted branch to$EAFB, shown by the white target address. Without highlighting, the branch would not be taken.>....<. Here, the cursor row and next instruction happen to be the same.Entering and leaving Debug mode
Din Assembly view to enter Debug mode.C=+DorRUN/STOP.Debug footer
The debug footer shows:
The next opcode to be executed is marked with
>.....<and is also reflected by thePCvalue in the footer. This lets the developer move freely around memory while still keeping track of the active debug state.Breakpoints
Breakpoints are shown on the right side of assembly opcode lines as
[BRKx], wherexis the breakpoint index from0to9. Custom labels are shown as[LABL]. Lines with breakpoints are also highlighted.The breakpoint list popup is intentionally similar to the existing bookmarks popup. It supports jumping to breakpoints, deleting breakpoints, enabling or disabling breakpoints, and assigning custom labels.
Debug help page
Some rarely used monitor shortcuts have debug-specific meanings while Debug mode is active. These mappings are shown at the top of the help screen.
Design
The following chapter discusses key design considerations.
Breakpoints
BRKinstructions because the FPGA core does not expose hardware breakpoints or direct 6510 register access usable by the application-hosted monitor.MemoryBackend::create_debug_session()is the only seam between the monitor and platform-specific debug backends. Host tests use fake backends; firmware builds use the real U64 and U2 implementations.DebugSessionabstraction (over,trace,step_out,go). The shared BRK engine owns trap installation, sentinel polling, register capture, resume, cleanup, breakpoint orchestration and patch tracking.$00(i.e. the BRK opcode), let the CPU trap, read the register snapshot from the BRK catcher stub, then restore the saved byte. RAM breakpoints work on both U64 and U2.$0316/$0317. Any changes are temporary and cleaned up on leaving debug mode.Stepping
Dsteps overJSR,Ttraces into it,Oruns to the caller-side return, andGinstalls enabled breakpoints and free-runs. IfGstarts on a breakpoint, it first steps past it to avoid immediately re-trapping.JSR, rather than relying only on live stack inspection.ROM Support
Cleanup and Modes
RUN/STOP,C=+OandC=+X.C=+Xclears transient debug state, resets through the backend, and either reopens the monitor or exits cleanly depending on the mode.Implementation
Debug mode is implemented as a modal layer on top of the Assembly view. Normal monitor behaviour is unchanged.
The main source code files are:
machine_monitor.ccmonitor_debug.{h,cc}monitor_breakpoints.{h,cc}monitor_debug_session.hmonitor_debug_brk_session.ccmonitor_debug_u64.ccandmonitor_debug_u2.ccTesting
Hardware testing
Test feedback for other devices would be greatly appreciated.
Unit tests
software/test/monitor/machine_monitor_debug_test.ccCoverage includes:
C=+Xreset and monitor re-entry.End-to-end tests
./tools/developer/machine-code-monitor/monitor_debug_test.py --host <u64-ip>The E2E test drives deployed firmware through Telnet and uses the U64 REST API for memory setup. It asserts screen contents after each step.
Output:
Soak test
./tools/developer/machine-code-monitor/monitor_debug_soak.py --host <u64-ip>This long-running test loops high-risk scenarios such as freeze/refreeze handling, parking trampoline cleanup, and breakpoint re-entry.
Known Limitations
$01value used by the running 6510. If these diverge in banked regions, stepping may decode or patch the wrong visible target and time out without corruption.BRKopcode in the volatile ROM shadow as this feature only exists on a U64.Related Work
feature/151-machine-code-monitor, which has since been merged into thetest-mergebranch on Gideon's1541ultimaterepo.test-mergehas been merged intomaster,masterwill be merged into this PR branch.