Watch our video which goes through the code examples above and uses GDB on Linux and LLDB on macOS to contrast the following debugger commands. Remember that any specific addresses used in the commands will likely be different on your system!
Resources:
- Appendix D: Command-line Debugging with GDB
- https://lldb.llvm.org/lldb-gdb.html
-
examine registers
(gdb) info registers (lldb) register read --all
-
examine a specific register
(gdb) print/x $eax (lldb) register read eax (lldb) register read --format decimal eax
-
examine memory
(gdb) x/8xw 0x80490b4 (gdb) x/8dw 0x80490b4 (lldb) x/8dw 0x2000 (lldb) memory read/4xw 0xbffff3c0 (lldb) x/4xw 0xbffff3c0
-
examine a function
(gdb) disassemble _main (lldb) disassemble --name main
-
examine memory where a register is pointing
(gdb) x/8xw $esp (lldb) x/8xw $esp
-
next instruction
(gdb) nexti (lldb) nexti
-
examine a variable
(gdb) p value (lldb) p/d value
-
examine a string (character array)
(gdb) x/14cb 0x80490a4 (lldb) memory read --size 1 --format c --count 14 0x2000
-
examine an integer array
(gdb) x/6dw 0x80490b4 (lldb) memory read --size 4 --format h --count 6 0x2014
-
examine a floating point array
(gdb) x/4f &floats (lldb) x/4f &floats
-
examine a specific element in an array
(gdb) x/f &floats+1 (gdb) p (double[4])vector1 (lldb) x/f &floats+1
-
examine a floating point register
(gdb) print $xmm0 (gdb) p/f $xmm0.v4_float (gdb) p/f $xmm0.v4_float[1] (lldb) po (float __attribute__((ext_vector_type(4)))) $xmm0