This is a homework of the course "Advanced Programming in the UNIX Environment" at NYCU. I implement a simple instruction-level debugger that allows a user to debug a program interactively at the assembly instruction level.
The debugger supports following features:
- Shows disassembly of 5 instructions following the program counter.
- Step one instruction with command
si. - Set breakpoints with command
break <address>. - Continue the program until it it terminates or hits a breakpoint with command
cont. - Time travel: set an anchor point at any time with command
anchorand go back to the latest anchor with commandtimetravel. The program state is restored when going back to an anchor.
You should have Rust programming language environment installed.
cargo build
cargo run <program being debugged>$ cargo run ./guess
* program './guess' loaded. entry point 0x40108b
40108b: f3 0f 1e fa endbr64
40108f: 55 push rbp
401090: 48 89 e5 mov rbp, rsp
401093: 48 83 ec 10 sub rsp, 0x10
401097: ba 12 00 00 00 mov edx, 0x12
(sdb) break 0x4010bf
** set a breakpoint at 0x4010bf
(sdb) break 0x40111e
** set a breakpoint at 0x40111e
(sdb) cont
guess a number > ** hit a breakpoint at 0x4010bf
4010bf: bf 00 00 00 00 mov edi, 0
4010c4: e8 67 00 00 00 call 0x401130
4010c9: 48 89 45 f8 mov qword ptr [rbp - 8], rax
4010cd: 48 8d 05 3e 0f 00 00 lea rax, [rip + 0xf3e]
4010d4: 48 89 c6 mov rsi, rax
(sdb) anchor
** dropped an anchor
(sdb) cont
haha
no no no
** hit a breakpoint at 0x40111e
40111e: bf 00 00 00 00 mov edi, 0
401123: e8 10 00 00 00 call 0x401138
401128: b8 01 00 00 00 mov eax, 1
40112d: 0f 05 syscall
40112f: c3 ret
(sdb) timetravel
** go back to the anchor point
4010bf: bf 00 00 00 00 mov edi, 0
4010c4: e8 67 00 00 00 call 0x401130
4010c9: 48 89 45 f8 mov qword ptr [rbp - 8], rax
4010cd: 48 8d 05 3e 0f 00 00 lea rax, [rip + 0xf3e]
4010d4: 48 89 c6 mov rsi, rax
(sdb) cont
42
yes
** hit a breakpoint at 0x40111e
40111e: bf 00 00 00 00 mov edi, 0
401123: e8 10 00 00 00 call 0x401138
401128: b8 01 00 00 00 mov eax, 1
40112d: 0f 05 syscall
40112f: c3 ret
(sdb) cont
** the target program terminated.