After reading "Debugging with GDB" by RMS I've made this reference sheet, since I rarely program in Linux I've excluded everything Linux specific:
| General Usage | |
| file a.out | Load the program a.out |
| symbol-file symbol | Load symbol file symbol |
| run | Run program |
| continue | Execute program until the next breakpoint |
| print i | Print variable i |
| print i=3 | Change variable i to 3 |
| x 0x200 | Print value at 0x200 |
| break printf | Set breakpoint at function printf |
| info breakpoints | List breakpoints |
| delete 2 | Delete breakpoint 2 |
| delete | Delete all breakpoints |
| info locals | Show variables in stack |
| backtrace | Show stack |
| info frame | stack info |
| list + | Show sourcecode before last printed |
| list - | Show sourcecode before last printed |
| list func | Show sourcecode around function name func |
| list 30 | Show sourcecode around line 30 |
| info line func | Get start and end memory addresses of function func |
| info line 30 | Get start and end memory addresses of section around line 30 |
| disassemble 0x300 0x400 | Disassemble between memory addresses 0x300 and 0x400 |
| info registers | Display registers |
| info all-registers | Display all registers |
| set $rax = 0x5 | Set register rax to 0x5 |
| info symbol printf | shows memory location of printf |
| info address printf | Shows section of printf |
| whatis printf | Gives data type of symbol |
| ptype /o struct exstruct | Gives layout and offsets of the struct exstruct |
| info scope printf | Show variables within scope of function printf |
| info functions | Print all defined functions |
| info variables | Print all defined variables |
| jump func | Jump to function func |
| return 0 | Force function to return 0 |
| set $pc-= 1 | Effectively goes back one instruction |
| signal 9 | Resume program and send sigkill |
| Display | |
| layout src | Displays Source window |
| layout asm | Displays disassembly window |
| layout split | Displays source and disassembly windows |
| layout regs | Displays register window |
| set disassembly-flavor intel | Set preferred assembly syntax |
| OS Development | |
| set architecture i8086 | For debugging x86 bootloader code |
| set architecture i8086 | For debugging x86 bootloader code |
| set architecture i386:x86-64 | For debugging AMD64 code |
| target remote localhost:26000 | For connecting to $ qemu-system-x86_64 -gdb tcp::26000 ... |