summaryrefslogtreecommitdiffstats
path: root/docs/re/gdb.txt
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2021-07-30 01:20:53 -0400
committerMalfurious <m@lfurio.us>2021-08-01 18:41:37 -0400
commita2a34551dd82d57de7da8354e4f995ef76390d99 (patch)
treeef71f4625154c2e3f3d43f36a653cac29380587b /docs/re/gdb.txt
parent2018bf98c1cc0dbdc73f13c8d567c2460252845d (diff)
downloadlib-des-gnux-a2a34551dd82d57de7da8354e4f995ef76390d99.tar.gz
lib-des-gnux-a2a34551dd82d57de7da8354e4f995ef76390d99.zip
Add gdb cheat sheet
Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'docs/re/gdb.txt')
-rw-r--r--docs/re/gdb.txt101
1 files changed, 101 insertions, 0 deletions
diff --git a/docs/re/gdb.txt b/docs/re/gdb.txt
new file mode 100644
index 0000000..5772815
--- /dev/null
+++ b/docs/re/gdb.txt
@@ -0,0 +1,101 @@
+GNU Debugger (gdb) Basic Cheat Sheet
+====================================
+
+If possible, compile program with '-ggdb' to enable GDB-specific debugging
+symbols.
+
+
+Getting started
+---------------
+Launch GDB:
+ > gdb <executable> # note: any arguments to the exe are supplied separately
+ > gdb -p <process id> # attach to an already running process (requires root)
+
+ (gdb) run <argument0> <argument1> ... # Start running program
+
+Quit GDB:
+ (gdb) quit
+ (gdb) q
+
+
+Breakpoints
+-----------
+Set a breakpoint:
+ (gdb) break <function>
+ (gdb) break <function><+offset>
+ (gdb) break <address>
+ (gdb) b <arg>
+
+List breakpoints:
+ (gdb) info break
+ (gdb) i b
+
+Remove breakpoint:
+ (gdb) delete <id>
+ (gdb) d <id>
+ (gdb) d # deletes all breakpoints
+
+
+Debugging
+---------
+Inspect registers:
+ (gdb) info registers
+ (gdb) i r
+
+Get call stack / backtrace:
+ (gdb) backtrace
+ (gdb) bt
+
+Single-step program:
+ (gdb) display/i $pc # If debugging symbols missing, set prompt to display
+ current instruction disassembly
+ (gdb) n # next source code statement
+ (gdb) s # step source code statement (will follow calls)
+ (gdb) ni # next machine instruction
+ (gdb) si # step machine instruction (will follow calls)
+
+ (gdb) continue # resume execution (until next breakpoint)
+ (gdb) c
+
+ (gdb) finish # resume execution (until ret - step out of function)
+ (gdb) fin
+
+Disassemble program:
+ (gdb) disassemble <function>
+ (gdb) disassemble <address>
+ (gdb) disas <arg>
+
+
+Memory
+------
+Examine memory:
+ (gdb) x/nfu <address> # List contents of memory starting at <address>
+ and interpret data according to n, f, u
+
+ 'n' is a repeat count: Specifies how many values to display
+ 'f' is the display format: one of
+ x, d, u, o, t, a, c, f, s, i, m
+ 'u' is the unit size: one of
+ b, h, w, g
+
+ Example:
+ (gdb) x/32xg $sp # Display the first 32 64-bit 'giant' words on the
+ stack
+
+Alter memory:
+ (gdb) set {type}<address> = <value>
+
+ Example:
+ (gdb) set {int}0x7fffffdead = 69 # Write the value 69 to given address
+ as a 32-bit integer
+
+
+Process forks
+-------------
+ (gdb) set follow-fork-mode <parent|child> # Define debugging behavior on
+ fork()
+ (gdb) set detach-on-fork <on|off> # If set to 'off' gdb will keep a debugger
+ on both processes - Default is on
+
+ (gdb) show follow-fork-mode # Check config
+ (gdb) show detach-on-fork # Check config