GDB and LLDB debug commands
A short cheatsheet for debugging.
Original source: https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-command-examples.html
Execution commands
Aliases and short forms separated by
/
Task | GDB | LLDB |
---|---|---|
Launch a process without any argument | (gdb) run / |
(lldb) process launch / run / r |
Launch a process with arguments | (gdb) run <args> / r <args> |
(lldb) process launch -- <args> / r <args> |
Launch process a.out with arguments 1 2 3 without supplying them (defaults) |
$ gdb --args a.out 1 2 3 |
$ lldb -- a.out 1 2 3 |
Set env. variables before launching | (gdb) set env VAR VALUE |
(lldb) settings set target.env-vars VAR=VALUE / set se ... |
Attach to the process with PID 123 | (gdb) attach 123 |
(lldb) process attach --pid 123 / attach -p 123 |
Attach to a process named a.out | (gdb) attach a.out |
(lldb) process attach --name a.out / pro at -n a.out |
Wait for a process named a.out to launch and attach | (gdb) attach -waitfor a.out |
(lldb) process attach --name a.out --waitfor / pro at -n a.out -w |
Attach to a remote GDB protocol server | (gdb) target remote domain:port |
(lldb) gdb-remote domain:port |
Attach to a local GDB protocol server | (gdb) target remote localhost:port |
(lldb) gdb-remote port |
Source-based single step in the currently selected thread | (gdb) step / s |
(lldb) thread step-in / step / s |
Source-based single step over the currently selected thread | (gdb) next / n |
(lldb) thread step-over / next / n |
Instruction-based single step in the currently selected thread | (gdb) stepi / si |
(lldb) thread step-inst / si |
Instruction-based single step over the currently selected thread | (gdb) nexti / ni |
(lldb) thread step-inst-over / ni |
Step out of the currently selected frame | (gdb) finish |
(lldb) thread step-out / finish |
Breakpoint commands
Task | GDB | LLDB |
---|---|---|
Set a breakpoint in all functions named main |
(gdb) break main |
(lldb) breakpoint set --name main / br s -n main / b main |
Set a breakpoint in file test.c at line 12 |
(gdb) break test.c:12 |
(lldb) breakpoint set --file test.c --line 12 / br s -f test.c -l 12 / b test.c:12 |
Set a breakpoint at all C++ methods whose basename is main. | (gdb) break main |
(lldb) breakpoint set --method main / br s -M main |
Set a breakpoint at an Objective-C function: -[NSString stringWithFormat:] |
(gdb) break -[NSString stringWithFormat:] |
(lldb) breakpoint set --name "-[NSString stringWithFormat:]" / b -[NSString stringWithFormat:] |
Set a breakpoint at all Objective-C methods whose selector is count |
(gdb) break count |
(lldb) breakpoint set --selector count / br s -S count |
Set a breakpoint by a regex on a function name | (gdb) rbreak regular-expression |
(lldb) breakpoint set --regex regular-expression / br s -r regular-expression |
Set a breakpoint by a regular expression on a source file’s content | (gdb) shell grep -e -n pattern source-file / break source-file:CopyLineNumbers |
(lldb) breakpoint set --source-pattern regular-expression --file SourceFile / br s -p regular-expression -f file |
List all breakpoints | (gdb) info break |
(lldb) breakpoint list / br l |
Delete a breakpoint | (gdb) delete 1 |
(lldb) breakpoint delete 1 / br del 1 |
Watchpoint Commands
TODO
Examining variables
TODO
Evaluating Expressions
TODO
Examining Thread State
TODO
Executable and Shared Library Query Commands
TODO
Misc.
TODO
No Comments