|
| 1 | +# Simple Instruction Level Debugger |
| 2 | + |
| 3 | +In this homework, we are going to implement a simple instruction-level debugger that allows a user to debug a program interactively at the assembly instruction level. You can implement the debugger by using the ptrace interface. The commands you have to implement are summarized as follows: |
| 4 | + |
| 5 | +- break {instruction-address}: add a break point |
| 6 | +- cont: continue execution |
| 7 | +- delete {break-point-id}: remove a break point |
| 8 | +- disasm addr: disassemble instructions in a file or a memory region |
| 9 | +- dump addr [length]: dump memory content |
| 10 | +- exit: terminate the debugger |
| 11 | +- get reg: get a single value from a register |
| 12 | +- getregs: show registers |
| 13 | +- help: show this message |
| 14 | +- list: list break points |
| 15 | +- load {path/to/a/program}: load a program |
| 16 | +- run: run the program |
| 17 | +- vmmap: show memory layout |
| 18 | +- set reg val: get a single value to a register |
| 19 | +- si: step into instruction |
| 20 | +- start: start the program and stop at the first instruction |
| 21 | + |
| 22 | +The details of each command are explained below. In a debugging process, you have to load a program first, configure the debugger, and start debugging by running the program. A debugger command may be only used in certain "states." The states include **any**, **loaded**, and **running**. **any** means that a command can be used at any time. **loaded** means that a command can be only used when a program is loaded. **running** means that a command can be only used when the program is running. We will use brackets right after a command to enclose the list of the state(s) that should be supported by the command. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +- **break** or **b** [**loaded** and **running**]: Setup a break point. If a program is loaded but is not running, the address should be within the range specified by the text segment in the ELF file. When a break point is hit, you have to output a message and indicate the corresponding address and instruction. |
| 27 | +- **cont** or **c** [**running**]: continue the execution when a running program is stopped (suspended). |
| 28 | +- **delete** [**any**]: remove a break point. |
| 29 | +- **disasm** or **d** [**loaded** and **running**]: Disassemble instructions in a file or a memory region. The address should be within the range specified by the text segment in the ELF file. You only have to dump 10 instructions for each command. If **disasm** command is executed without an address, it should disassemble the codes right after the previously disassembled codes. See the demonstration section for the sample output format. |
| 30 | +- **dump** or **x** [**running**]: Dump memory content. You only have to dump 80 bytes from a given address. The output contains the addresses, the hex values, and printable ascii characters. If **dump** command is executed without an address, it should dump the region right after the previous dump. |
| 31 | +- **exit** or **q** [**any**]: Quit from the debugger. The program being debugged should be killed as well. |
| 32 | +- **get** or **g** [**running**]: Get the value of a register. Register names are all in lowercase. |
| 33 | +- **getregs** [**running**]: Get the value of all registers. |
| 34 | +- **help** or **h** [**any**]: Show the help message. |
| 35 | +- **list** or **l** [**any**]: List break points, which contains index numbers (for deletion) and addresses. |
| 36 | +- **load** [not **loaded**]: Load a program into the debugger. When a program is loaded, you have to print out the entry point, the address, the offset, and the size for the text segment. |
| 37 | +- **run** or **r** [**loaded** and **running**]: Run the program. If the program is already running, show a warning message and continue the execution. |
| 38 | +- **vmmap** or **m** [**loaded** and **running**]: Show memory layout for a running program. If a program is loaded but is not running, it should display the text segment address of the loaded program. |
| 39 | +- **set** or **s** [**running**]: Set the value of a register |
| 40 | +- **si** [**running**]: Run a single instruction, and step into function calls. |
| 41 | +- **start** [**loaded**]: Start the program and stop at the first instruction. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +For more details about the implementation, please check the demonstration section for the sample input and the corresponding output. |
0 commit comments