- Compiler your C program
- Create a C program and compile it with
-O0 -g -no-pie -fno-omit-frame-pointer -oto get an executable with debugger info in it. Or you can also use the sameple files provided insamplesdirectory
- Create a C program and compile it with
- Run the debugger
- Use the command
cargo run <path to your compiled executable>to start the debugger
- Use the command
- Start the debugger:
r <optional arguments to your C program>
- Set breakpoints:
br <address, line number or function name in your C program>
- Pause the debugger:
ctrl + c - Print backtrace from the current breakpoints:
bt
- Continue from breakpoints:
c
- Quit the debugger:
q
- print the value of variables
- When the program is compiled, only the value of global/static variables are stored at a fixed location in the final executable(Please refer to ELF format for more details). and the value of local variables are not determined until runtime where the the stack frames of the functions where local variables are declared are created. Hence, it makes it more difficult to obtain the values for the variables as the debugger is not able to directly access them from the final executable and has to wait until the program is being run