GDB - Opty-Forks/SSof GitHub Wiki
Below is a simple list of basic GDB commands. They should get you going for most of our exercises
- To analyse a program with gdb type
gdb <file_to_analyse> - To disassemble a function use:
disassemble <fn_name>ordisassemble <memory_address>- e.g.
disassemble mainordisassemble 0x0804843b. - in
gdp-pedayou can usepdisass <fn_name/address>to do it with colours.
- e.g.
-
b <memory_address>inserts a breakpoint at addressmemory_address- eg
b *0x0804846aorb *main+47
- eg
-
rruns the current program -
ccontinues execution until the next breakpoint -
nexecutes the next instrution -
ssteps into functionfnwhen the instruction is acall fn -
pprints the value of an expression-
p variable_nameprints the content of the variable (if the symbolvariable_nameis defined) -
p &variable_nameprints the address where the variable is in memory -
p *memory_addressprints the content in this address
-
-
btprints a backtrace of the entire stack, that is, shows how you got to the current frame -
info fprints the information about the current frame. This is usefull whenever you need to know where the return address of the function is stored and/or the value contained there. -
stack nshows thenregisters of the stack afteresp. -
x/nx $rsp--- shows thenregisters after the register$rsp -
x/nx address--- shows thenregisters after the addressaddress