Skip to content

Latest commit

 

History

History
84 lines (74 loc) · 2.82 KB

File metadata and controls

84 lines (74 loc) · 2.82 KB

Command ( Hai Dang )

1. Running and stopping

quit			Exit gdb
run			Run program
run 1 2 3		Run program with command-line arguments 1 2 3
kill 			Stop the program
Ctrl-d			Exit gdb

2. Breakpoints

break sum (function)	Set breakpoint at the entry to function
break *0x80483c3	Set breakpoint at address 0x80483c3
delete 1		Delete breakpoint 1
disable 1		Disable the breakpoint 1
enable 1		Enable breakpoint 1
delete 			Delete all breakpoints
clear sum (function)	Clear any breakpoints at the entry to function sum

3. Execution

stepi			Execute one instruction
stepi 4			Execute 4 instruction
step			Execute one C statement
continue		Resume execution uuntil the next breakpoint
until 3			Continue executing until program hits breakpointt 3
finish			Resume execution untitil current function returns
call sum(1,2)		Call sum(1,2) and print retsurn value

4. Examining code

disas 			Disassemble current function
disas 	sum		Disassemble function sum
disas   0x80483b7	Disassemble function around 0x80483b7
print /x $rip		Print program counter in hex
print /d $rip		Print program counter in decimal
print /t $rip		Print program counter in binary

5. Useful information

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 thte 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 information about gdb

6.Examining data

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 *) 0xbfff8	Print integer at address 0xbfff8
priint (char *) 0xbff8	Examine a string stored at 0xbff8
x/w 	0xbffff890	Examine (4-byte) word starting at address
x/w 	$rsp		Examine (4-byte) word starting at address in $rsp, print in decimal
x/2w 	$rsp		Examine two (4-byte) word starting at address in $rsp
x/a	$rsp		Examine address in $rsp. Print as offset from previous global
x/s     0xbffff8890	Examine a string stored at 0xbfff8890
x/20b   sum		Examine first 20 opcode bytes of function sum
x/10i 	sum		Examine first 10 instructions of function sum

(Note: the format string for the `x' command has the generall form
	x/[NUM][SIZE][FORMAT] where
NUM    = number of objects to display
SIZE   = size of each object (b = byte, h = half-word, w = word)
FORMAT = how to display each object (d=decimal, x=hex, etc...)  
)

Tutorial gdb

Reference link

Markdown tutorial