Summary of GDB commands
Starting
gdb
gdb <filename>
Running and stopping
Command | Effect |
---|---|
quit |
Exit gdb |
run |
Run program |
run 1 2 3 |
Run program with command-line arguments |
kill |
Stop the program |
Ctrl-d |
Exit gdb |
Breakpoints
Command | Effect |
---|---|
break sum |
Set breakpoint at the entry to function sum |
break *0x80483c3 |
Set breakpoint at address 0x80483c3 |
delete 1 |
Delete breakpoint 1 |
disable 1 |
Disable breakpoint 1 |
enable 1 |
Enable breakpoint 1 |
delete |
Delete all breakpoints |
clear sum |
Clear any breakpoints at the entry to function sum |
Execution
Command | Effect |
---|---|
stepi |
Execute one assembly instruction |
stepi 4 |
Execute four assembly instructions |
nexti |
Like stepi , but proceed through function calls without stopping |
step |
Execute one C statement |
continue |
Resume executing until the next breakpoint |
until 3 |
Continue executing until program hits breakpoint 3 |
finish |
Resume execution until current function returns |
call sum(1, 2) |
Call sum(1,2) and print return value |
Examining code
Command | Effect |
---|---|
disas |
Disassemble current function |
disas sum |
Disassemble function sum |
disas 0x80483b7 |
Disassemble function around 0x80483b7 |
disas 0x80483b7 0x80483c7 |
Disassemble code within specified range |
print /x $rip |
Print program counter in hex |
print /d $rip |
Print program counter in decimal |
print /t $rip |
Print program counter in binary |
Examining data
Command | Effect |
---|---|
print /d $rax |
Print contents of %rax in decimal |
print /x $rax |
Print contents of %rax in hex |
print /t $rax |
Print contents of %rax in binary |
print /d (int) $rax |
Print contents of %rax in decimal after sign-extending lower 32-bits |
print 0x100 |
Print decimal representation of 0x100 |
print /x 555 |
Print hex representation of 555 |
print /x ($rsp+8) |
Print contents of %rsp + 8 in hex |
print *(int *) 0xbffff890 |
Print integer at address 0xbffff890 |
print *(int *) ($rsp+8) |
Print integer at address %rsp + 8 |
x/w 0xbffff890 |
Examine (4-byte) word starting at address 0xbffff890 |
x/w $rsp |
Examine (4-byte) word starting at address in %rsp |
x/wd $rsp |
Examine (4-byte) word starting at address in %rsp in decimal |
x/2w $rsp |
Examine two (4-byte) words starting at address in %rsp |
x/2wd $rsp |
Examine two (4-byte) words starting at address in %rsp in decimal |
x/g $rsp |
Examine (8-byte) word starting at address in %rsp |
x/gd $rsp |
Examine (8-byte) word starting at address in %rsp in decimal |
x/a $rsp |
Examine address in %rsp and print as offset from previous global symbol |
x/s 0xbffff890 |
Examine string stored at 0xbffff890 |
x20b sum |
Examine first 20 opcode bytes of function sum |
x10i sum |
Examine first 10 instructions of function sum |
Note: the format string for the x
command has the general form
x/[NUM][SIZE][FORMAT]
where
NUM
is the number of objects to displaySIZE
is the size of each object (b=byte, h=half-word, w=word, g=giant (quad-word))FORMAT
is how to display each object (d=decimal, x=hex, etc)
Useful Information
Command | Effect |
---|---|
backtrace |
Print the current address and stack backtrace |
where |
Print the current address and stack backtrace |
info program |
Print current status of the program |
info functions |
Print functions in program |
info stack |
Print backtrace of the stack |
info frame |
Print information about the current stack frame |
info registers |
Print registers and their contents |
info breakpoints |
Print status of user-settable breakpoints |
help |
Get help about gdb |