Summary of GDB commands for x86-64 Systems

原文: http://csapp.cs.cmu.edu/2e/docs/gdbnotes-x86-64.pdf

Summary of GDB commands for x86-64 Systems

Starting:
 gdb
 gdb <file>
Running and stopping
CommandEffect
quitExit gdb
runRun program
run 1 2 3Run program with command-line arguments 1 2 3
killStop the program
quitExit gdb
Ctrl-dExit gdb

Note: Ctrl-Cdoes not exit from gdb, but halts the current
gdb command

Breakpoints
CommandEffect
break sumSet breakpoint at the entry to function sum
break *0x80483c3Set breakpoint at address 0x80483c3
delete 1Delete breakpoint 1
disable 1Disable the breakpoint 1 (gdb numbers each breakpoint you create)
enable 1Enable breakpoint 1
deleteDelete all breakpoints
clear sumClear any breakpoints at the entry to function sum
Execution
CommandEffect
stepiExecute one instruction
stepi 4Execute four instructions
nextiLike stepi, but proceed through function calls without stopping
stepExecute one C statement
continueResume execution until the next breakpoint
until 3Continue executing until program hits breakpoint 3
finishResume execution until current function returns
call sum(1, 2)Call sum(1,2) and print return value
Examining code
CommandEffect
disasDisassemble current function
disas sumDisassemble function sum
disas 0x80483b7Disassemble function around 0x80483b7
disas 0x80483b7 0x80483c7Disassemble code within specified address range
print /x $ripPrint program counter in hex
print /d $ripPrint program counter in decimal
print /t $ripPrint program counter in binary
Examining data
CommandEffect
print /d $raxPrint contents of %rax in decimal
print /x $raxPrint contents of %rax in hex
print /t $raxPrint contents of %rax in binary
print /d (int)$raxPrint contents of %rax in decimal after sign-extending lower 32-bits.

You need this to print 32-bit, negative numbers stored in the lower 32 bits of %rax. For example, if the lower 32-bits of %rax store 0xffffffff, you will see
(gdb) print $rax
$1 = 4294967295
(gdb) print (int)$rax
$2 = -1
(gdb)

CommandEffect
print 0x100Print decimal representation of 0x100
print /x 555Print hex representation of 555
print /x ($rsp+8)Print (contents of %rsp) + 8 in hex
print *(int *) 0xbffff890Print integer at address 0xbffff890
print *(int *) ($rsp+8)Print integer at address %rsp + 8
print (char *) 0xbfff890Examine a string stored at 0xbffff890
x/w 0xbffff890Examine (4-byte) word starting at address 0xbffff890
x/w $rspExamine (4-byte) word starting at address in $rsp
x/wd $rspExamine (4-byte) word starting at address in $rsp. Print in decimal
x/2w $rspExamine two (4-byte) words starting at address in $rsp
x/2wd $rspExamine two (4-byte) words starting at address in $rsp. Print in decimal
x/g $rspExamine (8-byte) word starting at address in $rsp.
x/gd $rspExamine (8-byte) word starting at address in $rsp. Print in decimal
x/a $rspExamine address in $rsp. Print as offset from previous global symbol.
x/s 0xbffff890Examine a string stored at 0xbffff890
x/20b sumExamine first 20 opcode bytes of function sum
x/10i sumExamine first 10 instructions of function sum

(Note: the format string for the ‘x’ command has the general form x/[NUM][SIZE][FORMAT] where
NUM = number of objects to display
SIZE = size of each object (b=byte, h=half-word, w=word, g=giant (quad-word))
FORMAT = how to display each object (d=decimal, x=hex, o=octal, etc.)
If you don’t specify SIZE or FORMAT, either a default value, or the last
value you specified in a previous ‘print’ or ‘x’ command is used. )

Useful information
CommandEffect
backtracePrint the current address and stack backtrace
wherePrint the current address and stack backtrace
info programPrint current status of the program)
info functionsPrint functions in program
info stackPrint backtrace of the stack)
info framePrint information about the current stack frame
info registersPrint registers and their contents
info breakpointsPrint status of user-settable breakpoints
display /FMT EXPRPrint expression EXPR using format FMT every time GDB stops
undisplayTurn off display mode
helpGet information about gdb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值