Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger #46

Draft
wants to merge 232 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
7c4c908
Add debugger module
dxrcy Sep 26, 2024
6cb9fde
Convert debugger option to a subcommand
dxrcy Sep 26, 2024
2c5d6f1
Merge remote-tracking branch 'upstream/main' into debugger
dxrcy Sep 26, 2024
c93d3a4
Implement basic debugger command input
dxrcy Sep 27, 2024
8b552c8
Support debugger command-line input
dxrcy Sep 28, 2024
92f47e5
Refactor debugger command source
dxrcy Sep 28, 2024
3e295be
Tidy up debugger module
dxrcy Sep 28, 2024
910280b
Support stdin for debugger command
dxrcy Sep 28, 2024
3dd623b
Refactor debugger command source into submodule
dxrcy Sep 28, 2024
a5a5774
Save original memory state to debugger
dxrcy Sep 28, 2024
2861876
Rename debugger types and add comments
dxrcy Sep 28, 2024
bdfa70d
Parse debugger command arguments
dxrcy Sep 29, 2024
41ddcae
Use iterator for command parser
dxrcy Sep 29, 2024
83c2bf3
Add debugger command variants (without functionality)
dxrcy Sep 29, 2024
bb2d7fc
Extract argument parsing to methods
dxrcy Sep 29, 2024
a3e8447
Check integer bounds in debugger more safely
dxrcy Sep 29, 2024
2f220ac
Check for semicolon when parsing debugger command
dxrcy Sep 29, 2024
b760356
Re-use `Term` instance for debugger
dxrcy Sep 29, 2024
a7da6a8
Re-use `Stdin` instance for debugger
dxrcy Sep 29, 2024
3584a30
Support multiple debugger commands on single terminal line
dxrcy Sep 29, 2024
a501513
Merge branch 'main' into debugger
dxrcy Sep 29, 2024
50d66a1
Refactor terminal reader for debugger
dxrcy Oct 1, 2024
85ad756
Remove repeated character index calculation for debugger argument
dxrcy Oct 1, 2024
09d0f5f
Add reference to run state in debugger
dxrcy Oct 1, 2024
df831bc
Implement some get/set debugger commands
dxrcy Oct 1, 2024
9d8037f
Separate run state into state and environment
dxrcy Oct 1, 2024
b588770
Overhaul debugger integer parsing, with tests
dxrcy Oct 4, 2024
00cb638
Fix debugger test
dxrcy Oct 4, 2024
a14922a
Test debugger label parsing
dxrcy Oct 4, 2024
fc8367f
Test debugger register parsing
dxrcy Oct 5, 2024
d2f589b
Reuse macro for debugger tests
dxrcy Oct 5, 2024
3c41309
Use `-c`/`--command` for debugger command
dxrcy Oct 6, 2024
9a95b67
Refactor command parsing
dxrcy Oct 6, 2024
bfed798
Use macro for debugger printing
dxrcy Oct 6, 2024
93e94dc
Move debugger command argument parsing to module
dxrcy Oct 7, 2024
095d258
Support explicit positive sign for debugger commands
dxrcy Oct 7, 2024
ae4161d
Change `allow_sign` to `require_sign` for debugger command parsing
dxrcy Oct 7, 2024
e4e1696
Tidy up code for debugger command parsing
dxrcy Oct 7, 2024
b1cc980
Update comments on debugger sources
dxrcy Oct 7, 2024
9ed0b16
Replace unsafe line with inlined function
dxrcy Oct 8, 2024
13f12b8
Implement set memory for debugger
dxrcy Oct 8, 2024
00310f8
Preserve history for debugger in local file
dxrcy Oct 8, 2024
0126e15
Remove undefined behaviour
dxrcy Oct 15, 2024
a9dfe75
Move debugger loop to debugger struct
dxrcy Oct 16, 2024
cd7149a
Implement debugger control flow
dxrcy Oct 17, 2024
70ac85b
Continue commands for debugger
dxrcy Oct 17, 2024
1484146
Print debugger command parsing errors
dxrcy Oct 20, 2024
ae2e6a7
Use enum for debugger command names
dxrcy Oct 20, 2024
1e7f81d
Refactor debugger command errors
dxrcy Oct 20, 2024
1f7d9e0
Always pause debugger on `HALT`
dxrcy Oct 23, 2024
32e2b9f
Fix debugger printing
dxrcy Oct 23, 2024
b4ff8b4
Add breakpoint commands to debugger
dxrcy Oct 23, 2024
4235af5
Merge branch 'main' into debugger
dxrcy Oct 23, 2024
e7578f2
Fix tests
dxrcy Oct 23, 2024
5f593c5
Add `help` debugger command (without proper information)
dxrcy Nov 23, 2024
706aa34
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Nov 23, 2024
6b2712c
Only pause once on breakpoint
dxrcy Nov 23, 2024
b434c91
refactor: remove unnecessary `Box` for initial state
dxrcy Nov 23, 2024
c8c5ec3
feat: avoid printing extra newlines by checking printed characters
dxrcy Nov 23, 2024
5974bbd
fix: use debugger stream for debugger messages
dxrcy Nov 23, 2024
1d34f9d
feat: support labels for debugger location arguments
dxrcy Nov 23, 2024
7db5de1
fix: make temporary debug prints dim
dxrcy Nov 23, 2024
47ad37b
feat: add more command aliases
dxrcy Nov 23, 2024
4f0b955
feat: add proper help command
dxrcy Nov 23, 2024
2230993
feat: use user cache dir for debugger history file
dxrcy Nov 24, 2024
4d4f4aa
opt: read history file without unnecessary allocation
dxrcy Nov 24, 2024
5e6580f
feat: use `colored` for debugger color
dxrcy Nov 27, 2024
e8b4f92
feat: use bold styles in help text
dxrcy Nov 27, 2024
dfc871d
refactor: move `DEBUGGER_COLOR` to `debugger::print`
dxrcy Nov 27, 2024
dd16a64
feat: strip colors if minimal
dxrcy Nov 27, 2024
81050c9
feat: use `--minimal` argument for printing
dxrcy Nov 27, 2024
9c0932b
feat: use common interface for all debugger printing
dxrcy Nov 27, 2024
9a82684
feat: debugger: const-initialize `IS_MINIMAL`
dxrcy Nov 27, 2024
e7e1b94
fix: only print temporary debugger messages if debugger is active
dxrcy Nov 27, 2024
c6551b9
feat: add `.BREAK` directive
dxrcy Nov 28, 2024
d3cbff7
refactor: change `Air` iterator to `&Air`
dxrcy Nov 28, 2024
334d27d
refactor: use `pc` for breakpoint `orig`
dxrcy Nov 28, 2024
82d4012
fix: tests compile
dxrcy Nov 28, 2024
9a0adad
fix: print new line after halt
dxrcy Nov 28, 2024
fc03139
lint: tidy `terminal_cursor` functions
dxrcy Nov 28, 2024
f489aa0
lint: tidy `debugger::print` module
dxrcy Nov 28, 2024
eca1b08
refactor: convert 'minimal' static variable into module
dxrcy Nov 28, 2024
dda915f
refactor: convert 'line start' static variable into module
dxrcy Nov 28, 2024
a7b3aa8
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Nov 29, 2024
a135bfb
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Nov 29, 2024
21ab64c
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Nov 29, 2024
b1f39f0
fix: use updated runtime api in debugger code
dxrcy Nov 29, 2024
e70bc72
refactor: convert `RunState::pc` to immutable
dxrcy Nov 29, 2024
5bc84f6
fix: update comments
dxrcy Dec 1, 2024
8bfb140
fix: use correct address for breakpoints
dxrcy Dec 1, 2024
da7fee7
feat: print registers as hex, int, uint, and char
dxrcy Dec 1, 2024
ec6a84c
refactor: separate `print_*` methods from `Debugger`
dxrcy Dec 1, 2024
2793c9e
feat: print table header for `registers` command
dxrcy Dec 1, 2024
f052840
refactor: make `print_registers` generic for `impl io::Write`
dxrcy Dec 1, 2024
dc40087
feat: use debugger `print_registers` for `REG` trap
dxrcy Dec 1, 2024
82fbb0e
feat: align register print to columns
dxrcy Dec 1, 2024
cc4f642
feat: use box-drawing characters for register print
dxrcy Dec 1, 2024
c9b0a8b
feat: style register print
dxrcy Dec 1, 2024
0bdf6bd
feat: change non-printable character in register print
dxrcy Dec 1, 2024
527acc3
feat: remove temporary debug prints
dxrcy Dec 1, 2024
781b5a1
feat: print some debugger info only if not `--minimal`
dxrcy Dec 1, 2024
5086d24
refactor!: use `Output` struct for all printing in program
dxrcy Dec 2, 2024
1884a83
fix: debugger newlines
dxrcy Dec 2, 2024
a5be80c
feat: set line start on `Normal` `print_str`
dxrcy Dec 2, 2024
acd70fc
fix: terminal source uses correct prompt style
dxrcy Dec 2, 2024
60dc84e
feat: don't print eof indicator in minimal output
dxrcy Dec 2, 2024
b41204c
fix: start line on `REG` trap
dxrcy Dec 2, 2024
626b8db
refactor: move debugger print functions to `output` module
dxrcy Dec 3, 2024
d0734b7
refactor: move 'minimal' and 'line start' variables to `Output` struct
dxrcy Dec 4, 2024
46927bd
chore: add tests for `output::Decolored`
dxrcy Dec 4, 2024
9a01d00
feat: replace `print(ln)!` calls with `Output::Normal` methods
dxrcy Dec 4, 2024
6273bda
refactor: create `Output::start_new_line` method
dxrcy Dec 4, 2024
24bf251
fix: implement `Output::Debugger.print_char`
dxrcy Dec 4, 2024
b49b9bf
fix: show better errors for misuse of `dprint(ln)!`
dxrcy Dec 4, 2024
11396aa
feat: show how many instructions were executed between debugger commands
dxrcy Dec 4, 2024
4ab4977
fix: pause at correct address when using `next` command
dxrcy Dec 4, 2024
f9d2d01
feat: show message if `next` called a subroutine
dxrcy Dec 4, 2024
610eaf8
feat: update debugger help
dxrcy Dec 4, 2024
e7bf36f
feat: distinguish pre-defined and impromptu breakpoints
dxrcy Dec 4, 2024
50d98ee
feat: only print pc if could have changed
dxrcy Dec 4, 2024
f44b11c
feat: read `eval` instruction
dxrcy Dec 4, 2024
7b89f4c
feat: parse `eval` instruction
dxrcy Dec 4, 2024
cb393d0
feat: execute `eval` instruction
dxrcy Dec 4, 2024
1b7a447
fix: check empty file to prevent underflow
dxrcy Dec 4, 2024
00fbfb4
feat: use better error handling for `eval`
dxrcy Dec 4, 2024
7826f7f
fix: handle invalid tokens better
dxrcy Dec 4, 2024
9e188a7
fix: free `eval` string
dxrcy Dec 4, 2024
4aeaf2a
fix: don't free string before use
dxrcy Dec 5, 2024
525f1c8
refactor: use `StaticStr` struct to abstract unsafe behaviour
dxrcy Dec 5, 2024
0525899
refactor: organize function in `eval.rs`
dxrcy Dec 5, 2024
c00ed9f
lint: separate `use` statements in new files
dxrcy Dec 5, 2024
5516006
fix: make debug messages consistent
dxrcy Dec 5, 2024
856ed59
chore: remove commented prints
dxrcy Dec 5, 2024
7b6039e
feat: use `--minimal` arg in non-debugger run
dxrcy Dec 5, 2024
349ae0b
feat: print minimal register display if `--minimal`
dxrcy Dec 5, 2024
d003da1
feat: print minimal number with `get` if `--minimal`
dxrcy Dec 5, 2024
584b5b0
feat: change character display for unrepresentable values
dxrcy Dec 5, 2024
68d8773
feat: show `PC` and `CC` in `registers`/`REG` output
dxrcy Dec 5, 2024
260afe2
fix: use grammar correct
dxrcy Dec 5, 2024
2ccfe06
feat: save source and spans in `Air`
dxrcy Dec 7, 2024
7b82f2a
feat: access source in debugger
dxrcy Dec 7, 2024
12539bf
feat: implement `source` command
dxrcy Dec 7, 2024
61c78d5
chore: fix comments for `source.rs`
dxrcy Dec 7, 2024
1deb63c
feat: increase context lines in all source-code errors
dxrcy Dec 7, 2024
0073039
feat: show nice display for `source`
dxrcy Dec 7, 2024
84a9d45
feat: use entire instruction for span
dxrcy Dec 7, 2024
785218d
feat: use real span for directives
dxrcy Dec 7, 2024
4812045
refactor: use (unused) real span for `.BREAK`
dxrcy Dec 7, 2024
49a60e9
feat: remove unnecessary 'count' argument for `source`
dxrcy Dec 7, 2024
f40c51f
chore: remove dead code `tokenize`
dxrcy Dec 7, 2024
6d38e82
fix(tests): `parser.rs`
dxrcy Dec 7, 2024
7891467
fix(tests): `air.rs`
dxrcy Dec 7, 2024
11308cb
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Dec 7, 2024
022c748
fix: impl `Copy` for `ImmediateOrReg`
dxrcy Dec 7, 2024
d9c54b3
chore: update comment
dxrcy Dec 7, 2024
6dc2bbf
fix: show pc at start of program
dxrcy Dec 7, 2024
790c0c8
feat: mark debugger prints with symbol characters
dxrcy Dec 7, 2024
e053079
feat: add aliases for `source` and `eval`
dxrcy Dec 7, 2024
b130b34
fix: command starting with non-alphanumeric non-whitespace character
dxrcy Dec 7, 2024
ef5e125
refactor: use `debug_assert` instead of custom `panic`
dxrcy Dec 7, 2024
2218ac4
fix: prevent panic for terminal source
dxrcy Dec 7, 2024
65bf901
chore: add comment
dxrcy Dec 7, 2024
157b823
refactor: pass 'category' to `dprint(ln)!`
dxrcy Dec 15, 2024
ac27d69
refactor: call `dprint!` within `dprintln!`
dxrcy Dec 15, 2024
b79e26d
refactor: overhaul `output` module
dxrcy Dec 16, 2024
f6d218d
opt: remove unnecessary `format!` calls in `output`
dxrcy Dec 16, 2024
028fb0b
feat: don't print category indicator if `--minimal`
dxrcy Dec 16, 2024
523bfb3
feat: update category symbols
dxrcy Dec 16, 2024
fd8342f
chore: add some doc comments to `output.rs`
dxrcy Dec 16, 2024
a340bfa
feat: color debugger output based on category
dxrcy Dec 17, 2024
58736f3
fix: `break list` color
dxrcy Dec 17, 2024
71e81c3
fix: always use stderr for debugger output
dxrcy Dec 17, 2024
5c11ddb
refactor: use `{` and `}` to delimit ansi codes in debugger help file
dxrcy Dec 17, 2024
fb3f4c9
Merge remote-tracking branch 'origin/main' into debugger
dxrcy Dec 18, 2024
5a63fae
fix(tests): new label parsing tests
dxrcy Dec 18, 2024
ac76a6a
lint: remove unnecessary import
dxrcy Dec 18, 2024
f7971c2
fix(`eval`): check labels exist
dxrcy Dec 18, 2024
19541d6
feat: better prevent running into device address space
dxrcy Dec 18, 2024
249b669
feat: use primary color for most debugger messages
dxrcy Dec 18, 2024
7db02df
feat!: add `jump` instruction
dxrcy Dec 18, 2024
8d30f28
feat: disallow `eval br* ...`
dxrcy Dec 18, 2024
f3c491d
feat!: read commands from argument first, then read from stdin/terminal
dxrcy Dec 19, 2024
e8389d7
feat: report history file errors nicely
dxrcy Dec 19, 2024
15030d2
refactor: move terminal history code to `TerminalHistory` struct
dxrcy Dec 19, 2024
87c907e
fix: push history
dxrcy Dec 19, 2024
c4f12fe
refactor: remove unused code
dxrcy Dec 19, 2024
ae0434b
chore(`debugger/source`): update comments
dxrcy Dec 19, 2024
2f4eb21
refactor: rename `SourceReader` to `SourceRead`
dxrcy Dec 19, 2024
1954033
refactor: use constant for debugger primary color
dxrcy Dec 19, 2024
3bab9d3
chore: document rest of items in `output.rs`
dxrcy Dec 19, 2024
e269395
refactor: rename methods of `Output`
dxrcy Dec 19, 2024
90551c7
chore: fix comments in `output.rs`
dxrcy Dec 19, 2024
9ecb21d
fix(output): only reset color at end of `dprint!`
dxrcy Dec 19, 2024
cb9a90a
refactor(`output`): move line tracker write to each writer implementa…
dxrcy Dec 19, 2024
b473404
chore(`debugger/parse.rs`): update comments
dxrcy Dec 19, 2024
1a1d69d
chore(`debugger/command.rs`): update comments
dxrcy Dec 19, 2024
cfa7419
opt: check command name case-insensitive without allocation
dxrcy Dec 19, 2024
89407b6
lint: clippy new files
dxrcy Dec 19, 2024
7fed3ce
refactor: use method to increment instruction count
dxrcy Dec 19, 2024
dc4d25e
refactor: move `Breakpoint` and `Breakpoints` to module
dxrcy Dec 19, 2024
a447109
feat: keep breakpoints sorted
dxrcy Dec 19, 2024
818614f
refactor: move more logic to `Breakpoints` struct
dxrcy Dec 19, 2024
5ca6422
feat: show command name in debugger parse error
dxrcy Dec 19, 2024
74176cf
refactor: separate parsing error kinds
dxrcy Dec 19, 2024
5192314
refactor: use static strings for command name in error
dxrcy Dec 19, 2024
86d5f48
refactor: separate more parsing error kinds
dxrcy Dec 19, 2024
6685642
refactor: move parsing errors to module
dxrcy Dec 19, 2024
18251a6
feat: show expected/actual argument count for some parse errors
dxrcy Dec 19, 2024
57b9b2c
feat: change parsing error messages
dxrcy Dec 19, 2024
945cc8e
feat: show expected/actual value kind for parsing errors
dxrcy Dec 19, 2024
3894e07
refactor: clean up argument parsing methods
dxrcy Dec 20, 2024
6d9ea31
refactor: remove duplication from argument parsing methods
dxrcy Dec 20, 2024
c6db41c
refactor: rename error enum fields
dxrcy Dec 20, 2024
f72a7a0
refactor: rename error enum variants
dxrcy Dec 20, 2024
c973bf9
feat: show actual arg count for missing argument error
dxrcy Dec 20, 2024
5a871da
fix(tests): parse
dxrcy Dec 20, 2024
33c4e0a
fix(debugger/source): fix unicode problems
dxrcy Dec 20, 2024
28e8866
feat: add more colors to help message
dxrcy Dec 20, 2024
5c8e856
feat: change debugger prompt
dxrcy Dec 20, 2024
4110577
refactor: organize command names
dxrcy Dec 20, 2024
26dfeea
feat: change command names
dxrcy Dec 20, 2024
b4d0fbc
feat: parse PC offset arguments
dxrcy Dec 20, 2024
1e9b09b
feat: accept pc offset arguments for commands
dxrcy Dec 20, 2024
13934c7
feat: update help message for new address syntax
dxrcy Dec 20, 2024
66524cf
feat: support pc offset arguments for `get` and `set`
dxrcy Dec 20, 2024
7290300
chore: remove unused error variant
dxrcy Dec 20, 2024
fcf4850
feat: print registers/memory fancy
dxrcy Dec 21, 2024
f0b8711
refactor: change parameter for `show_source`
dxrcy Dec 21, 2024
35d2edc
feat: show snippet of source code in `break list`
dxrcy Dec 21, 2024
e38b2f9
feat: update debugger help message
dxrcy Dec 22, 2024
536de48
chore(debugger): document better
dxrcy Dec 22, 2024
6067bc7
fix: cycle between halt/breakpoint
dxrcy Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use miette::{bail, Result, Severity};
use crate::symbol::{Flag, Label, Register};

/// Assembly intermediate representation, contains starting address and list of instructions
#[derive(Clone)]
pub struct Air {
/// Memory address to start program at
orig: Option<u16>,
Expand Down Expand Up @@ -65,7 +66,7 @@ impl IntoIterator for Air {
}

/// Single LC3 statement. Has optional labels.
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum AirStmt {
/// Add src_reg with src_reg_imm and store in dest
Add {
Expand Down Expand Up @@ -129,7 +130,7 @@ pub enum AirStmt {

/// Used for ADD and AND commands as they support either 5-bit immediate values or registers as the
/// last operand.
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum ImmediateOrReg {
Reg(Register),
Imm5(u8),
Expand All @@ -150,7 +151,7 @@ impl ImmediateOrReg {
pub struct RawWord(pub u16);

/// A line (16 bits) of assembly.
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct AsmLine {
pub line: u16,
pub stmt: AirStmt,
Expand Down
Loading
Loading