Example GDB commands (from demo 9/11/2013) These examples use abbreviated command names, because I'm lazy that way. GDB has online help with the "help" command, or you can find the extensive manual on the web (Google "GDB manual"). This list should include all the commands I showed in class, plus a few extra ones. Run a program with arguments and also under GDB: % gdb --args ./eg 5 6 7 Set breakpoint on the first line of a function: (gdb) b main (gdb) b func Start program running: (gdb) run Print environment variables: (gdb) show environment Print process ID: (gdb) info proc Print information about shared libraries: (gdb) info shared Print information about threads: (gdb) info thread Print stack backtrace: (gdb) bt Continue after a breakpoint: (gdb) c Disassemble the current function, EIP shown with "=>": (gdb) disass Single-step one instruction: (gdb) stepi List source code: (gdb) l Single-step one instruction, skipping over calls: (gdb) nexti Print the program counter (%eip): (gdb) p $eip Disassemble the current instruction: (gdb) x/i $eip Disassemble a range of instructions: (gdb) disass 0x0804854f,0x0804855d Print all integer registers: (gdb) info reg Print values of local variables: (gdb) info locals Print function arguments: (gdb) info args Print information about current stack frame: (gdb) info frame Print the value at a memory location, C style: (gdb) p *(void **)(0xffffd49c) Print the value at a memory location, with "x": (gdb) x/xw 0xffffd49c Print the value at 4(%ebp), C style: (gdb) p *(void **)($ebp + 4) Print the address of a local variable, C style: (gdb) p &buf Print the distance between two stack locations, C style: (gdb) p (void *)($ebp + 4) - (void *)&buf Set a breakpoint at an instruction: (gdb) b *0x0804857d Print the type of a variable: (gdb) ptype buf Print the definition of a type (when debug info available): (gdb) ptype struct stat Break on changes to a memory location: (gdb) watch *(void **)0xffffd49c