GNU Project Debugger (GDB)
GDB allows you to see what is going on ‘inside’ another program while it executes.
Super useful for debugging in C and C++!
GDB on M1 Mac
Unfortunately, it seems that I cannot use gdb yet on my M1 Mac, it’s not supported on the Macbook’s arm64 architecture. Instead, I use lldb.
When you compile, make sure to use the -g
flag
Resources
Commands
This is the high level commands.
Commands that I use a lot
next
: runs one line of the programn
print variable
: allows you to see value of that variable at that timep
display var
: prints the value of var after each next/stepcontinue
: runs the program until the next breakpointc
refresh
: fix the layout src display
More Commands
watch var
: breaks the program whenever var is changedstep
: runs one instruction of the programlist
: show surrounding lines of the programbacktrace
: lists the sequence of function calls that got you to your current locationup/down
: change the function in the call stack we are observing so as to inspect other variablesset var
: allows us to set a variable at runtimeundipslay 1
: stops displaying first var set with displaydelete breakpoint number
: rename break point from use (watch and break)