GDB常用功能
执行时,常用-q去掉copyright等无用信息:
gdb ./a.out -q
Command | simple cmd | Effect |
Starting and stopping | ||
quit | q | Exit GDB |
run | r | Run your program(give command line arguments here) |
kill | k | stop your program |
set args | before run, set running args | |
BreakPoints | ||
break sum | b sum | set breakpoint at entry to function sum |
break *0x80483c3 | b *0x80483c3 | set breakpoint at address 0x80483c3 |
delete 1 | d 1 | delete breakpoint 1 |
delete | d | delete all breakpoint |
Execution | ||
stepi | si | execute one instruction |
stepi 4 | si 4 | execute 4 instructions |
nexti | ni | Like stepi, but process through function calls |
continue | c | resume execution |
finish | f | run until current function returns |
Examining code | ||
disas | Disassemble current function | |
disas sum | Disassemble function sum | |
disas 0x80483b7 | Disassemble function around address 0x80483b7 | |
disas 0x80483b7 0x80483c7 | Disassemble code within specified address range | |
print /x $eip | Print program counter in hex | |
Examining data | ||
print $eax | p $eax |
Print contents of %eax in decimal |
print /x $eax |
Print contents of %eax in hex |
|
print /t $eax |
Print contents of %eax in binary |
|
print 0x100 |
Print decimal representation of 0x100 |
|
print /x 555 |
Print hex representation of 555 |
|
print /x ($ebp+8) |
Print contents of %ebp plus 8 in hex |
|
print*(int*)0xbffff890 |
Printintegerataddress0xbffff890 |
|
print *(int *) ($ebp+8) |
Print integer at address %ebp + 8 |
|
x/2w 0xbffff890 |
Examine two (4-byte) words starting at address 0xbffff890 |
|
x/20b sum |
Examine first 20 bytes of function sum |
|
Useful information | ||
info frame |
Information about current stack frame |
|
info registers |
Values of all the registers |