GDB
What gdb Does During Startup
GNU GDB Debugger Command Cheat Sheet
--command=<file>, -x <file> File listing GDB commands to perform. Good for automating set-up. --batch -x <file> Run in batch (not interactive) mode. Execute commands from file.
Source Code Directory
Gdb basics
Gdb looks for source files in $cdir (directory embedded in executable recorded during compilation) and $cwd (current working directory). You can add to this list via dir e.g. dir ..\..\WebCore\platform. See current list via show dir. If you need this, it’s a perfect candidate for putting inside .gdbinit file.
(gdb) info sources Source files for which symbols have been read in: /home/andreas/src/hcpp/software/app/src/hcpp/ptp2_master.c, [...]
Stack / Stack Trace
GDB corrupted stack frame – How to debug?
Examining the Stack
Watchpoint
Eclipse Help: Adding watchpoints
Watchpoints: Data Breakpoints
Eclipse CDT + GDB: Setting Watchpoints (Juno)
Assembler
Assembly Instruction Stepping
Eclipse GDB in combination with OpenOCD
Scripting
github Gdbinit: A user-friendly gdb configuration file, for x86/x86_64 and ARM platforms
github Gdbinit: gdbinit
Automating GDB Sessions
Automate gdb: show backtrace at every call to function puts
Remote Debugging
$ gdbserver :2345 ./program Process ./program created; pid = 1851 Listening on port 2345 Remote debugging from host 127.0.0.1
$ gdb GNU gdb (GDB) 7.5-ubuntu Copyright (C) 2012 Free Software Foundation, Inc. This GDB was configured as "x86_64-linux-gnu". No symbol table is loaded. Use the "file" command. (gdb) file ./program Reading symbols from ./program...done. (gdb) target remote :2345 Remote debugging using :2345 Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 0x00007ffff7ddb6c0 in _start () from /lib64/ld-linux-x86-64.so.2
Or using Eclipse: C/C++ Remote Application