WATCHPOINT COMMANDS

GDB

LLDB

Set a watchpoint on a variable when it is written to.

(gdb) watch global_var

(lldb) watchpoint set variable global_var(lldb) wa s v global_var

Set a watchpoint on a memory location when it is written into. The size of the region to watch for defaults to the pointer size if no ‘-x byte_size’ is specified. This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the ‘–‘ option terminator.

List information about the currently selected frame in the current thread.

(lldb) frame info

Select the stack frame that called the current stack frame.

(gdb) up

(lldb) up(lldb) frame select –relative=1

Select the stack frame that is called by the current stack frame.

(gdb) down

(lldb) down(lldb) frame select –relative=-1(lldb) fr s -r-1

Select a different stack frame using a relative offset.

(gdb) up 2(gdb) down 3

(lldb) frame select –relative 2(lldb) fr s -r2

(lldb) frame select –relative -3(lldb) fr s -r-3

Show the general purpose registers for the current thread.

(gdb) info registers

(lldb) register read

Write a new decimal value ‘123’ to the current thread register ‘rax’.

(gdb) p $rax = 123

(lldb) register write rax 123

Skip 8 bytes ahead of the current program counter (instruction pointer). Note that we use backticks to evaluate an expression and insert the scalar result in LLDB.

(gdb) jump *$pc+8

(lldb) register write pc `$pc+8`

Show the general purpose registers for the current thread formatted as signed decimal. LLDB tries to use the same format characters as printf(3) when possible. Type “help format” to see the full list of format specifiers.

(lldb) register read –format i(lldb) re r -f i

LLDB now supports the GDB shorthand format syntax but there can’t be space after the command:(lldb) register read/d

Show all registers in all register sets for the current thread.

(gdb) info all-registers

(lldb) register read –all(lldb) re r -a

Show the values for the registers named “rax”, “rsp” and “rbp” in the current thread.

(gdb) info all-registers rax rsp rbp

(lldb) register read rax rsp rbp

Show the values for the register named “rax” in the current thread formatted as binary.

(gdb) p/t $rax

(lldb) register read –format binary rax(lldb) re r -f b rax

LLDB now supports the GDB shorthand format syntax but there can’t be space after the command:(lldb) register read/t rax(lldb) p/t $rax

(lldb) memory read `argv[0]`NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:(lldb) memory read –size `sizeof(int)` `argv[0]`

Read 512 bytes of memory from address 0xbffff3c0 and save results to a local file as text.

(gdb) set logging on(gdb) set logging file /tmp/mem.txt(gdb) x/512bx 0xbffff3c0(gdb) set logging off

MISCELLANEOUS

GDB

LLDB

Search command help for a keyword.

(gdb) apropos keyword

(lldb) apropos keyword

Echo text to the screen.

(gdb) echo Here is some text\n

(lldb) script print “Here is some text”

Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built — maybe the program was built on a different computer — you need to tell the debugger how to find the sources at their local file path instead of the build system’s file path.