GDB/DDD Reference Sheet V1.0 (All commands work both in GDB ...

GDB/DDD Reference Sheet V1.0 (All commands work both in GDB ... GDB/DDD Reference Sheet V1.0 (All commands work both in GDB ...

students.cs.byu.edu
from students.cs.byu.edu More from this publisher
12.07.2015 Views

GDB/DDD Reference Sheet V1.0(All commands work both in GDB and DDD unless specified otherwise)(Examples are for the CS324 Bomb Lab)Starting:GDB:gdbgdb gdb -h(lists command line options)DDD:ddd (loads the files already)dddLoading EXE Inside DDD:Select FILE => OPEN PROGRAMExiting:GDB: quitDDD: Select FILE => EXITGeneral commandsrun (start your program) (optional Textfile for Input)DDD: Click on the Run Buttonkill(stop the program)Breakpointsb FUNCTION (set a breakpoint at the entry to the function)EX. b explode_bombb phase_1 (Puts a break at phase_1)b *ADDRESS (set a breakpoint at the specified address)DDD: Just Right-Click on the address in the Machine-Code Window andClick on “Set BreakPoint”disable (disable the breakpoint with that number)enable (enable the breakpoint with that number)clear FUNCTION (clear any breakpoints at the entry to the function)d (deletes the breakpoint with that number)DDD: (Right-Click on the Breakpoint and Select “Delete BreakPoint”)d(deletes all breakpoints)Working at breakpointsstepistepi stepnextinexti next(execute one machine code instruction)(execute NUM instructions)(execute one C statement)(like stepi, but proceed through subroutine calls)until LOCATION (continue running until LOCATION is reached)continue (resume execution)continue (continue, ignoring this breakpoint NUM times)finish(run until the current function returns)DDD: Make sure the COMMAND TOOL is Loaded (i.e. select VIEW => COMMAND TOOL)Then Click desired Command listed above to execute

<strong>GDB</strong>/<strong>DDD</strong> <strong>Reference</strong> <strong>Sheet</strong> <strong>V1.0</strong>(<strong>All</strong> <strong>commands</strong> <strong>work</strong> <strong>both</strong> <strong>in</strong> <strong>GDB</strong> and <strong>DDD</strong> unless specified otherwise)(Examples are for the CS324 Bomb Lab)Start<strong>in</strong>g:<strong>GDB</strong>:gdbgdb gdb -h(lists command l<strong>in</strong>e options)<strong>DDD</strong>:ddd (loads the files already)dddLoad<strong>in</strong>g EXE Inside <strong>DDD</strong>:Select FILE => OPEN PROGRAMExit<strong>in</strong>g:<strong>GDB</strong>: quit<strong>DDD</strong>: Select FILE => EXITGeneral <strong>commands</strong>run (start your program) (optional Textfile for Input)<strong>DDD</strong>: Click on the Run Buttonkill(stop the program)Breakpo<strong>in</strong>tsb FUNCTION (set a breakpo<strong>in</strong>t at the entry to the function)EX. b explode_bombb phase_1 (Puts a break at phase_1)b *ADDRESS (set a breakpo<strong>in</strong>t at the specified address)<strong>DDD</strong>: Just Right-Click on the address <strong>in</strong> the Mach<strong>in</strong>e-Code W<strong>in</strong>dow andClick on “Set BreakPo<strong>in</strong>t”disable (disable the breakpo<strong>in</strong>t with that number)enable (enable the breakpo<strong>in</strong>t with that number)clear FUNCTION (clear any breakpo<strong>in</strong>ts at the entry to the function)d (deletes the breakpo<strong>in</strong>t with that number)<strong>DDD</strong>: (Right-Click on the Breakpo<strong>in</strong>t and Select “Delete BreakPo<strong>in</strong>t”)d(deletes all breakpo<strong>in</strong>ts)Work<strong>in</strong>g at breakpo<strong>in</strong>tsstepistepi stepnext<strong>in</strong>exti next(execute one mach<strong>in</strong>e code <strong>in</strong>struction)(execute NUM <strong>in</strong>structions)(execute one C statement)(like stepi, but proceed through subrout<strong>in</strong>e calls)until LOCATION (cont<strong>in</strong>ue runn<strong>in</strong>g until LOCATION is reached)cont<strong>in</strong>ue (resume execution)cont<strong>in</strong>ue (cont<strong>in</strong>ue, ignor<strong>in</strong>g this breakpo<strong>in</strong>t NUM times)f<strong>in</strong>ish(run until the current function returns)<strong>DDD</strong>: Make sure the COMMAND TOOL is Loaded (i.e. select VIEW => COMMAND TOOL)Then Click desired Command listed above to execute


Exam<strong>in</strong><strong>in</strong>g codepr<strong>in</strong>t/a $pc (pr<strong>in</strong>t the program counter)pr<strong>in</strong>t $sp (pr<strong>in</strong>t the stack po<strong>in</strong>ter)disas(display the function around the current l<strong>in</strong>e)<strong>DDD</strong>: (Have the Mach<strong>in</strong>e Code W<strong>in</strong>dow Display<strong>in</strong>g)To Turn Mach<strong>in</strong>e Code W<strong>in</strong>dow ON/OFF (SELECT => MACHINE CODE WINDOW)disas ADDR (display the function around the address)disas ADDR1 ADDR2 (display the function between the addresses)disas FUNCTION (displays the mach<strong>in</strong>e <strong>in</strong>structions for that function)EX. disas phase_1 (disassembles phase_1 function <strong>in</strong>structions)Exam<strong>in</strong><strong>in</strong>g datapr<strong>in</strong>t $eaxp/x $eaxp/a $eaxp/d $eaxp/t $eaxp/c $eaxp 0x100p/x 555(pr<strong>in</strong>t the contents of %eax)(pr<strong>in</strong>t the contents of %eax as hex)(pr<strong>in</strong>t the contents of %eax as an address)(pr<strong>in</strong>t the contents of %eax as decimal)(pr<strong>in</strong>t the contents of %eax as b<strong>in</strong>ary)(pr<strong>in</strong>t the contents of %eax as a character)(pr<strong>in</strong>t decimal repr. of hex value)(pr<strong>in</strong>t hex repr. of decimal value)x ADDR (pr<strong>in</strong>t the contents of ADDR <strong>in</strong> memory)x/NFU ADDR (pr<strong>in</strong>t the contents at ADDR <strong>in</strong> memory:N = number of units to displayF = display format-Uses all the same ones as pr<strong>in</strong>t (p) and hasthese additional ones:s = (pr<strong>in</strong>t-out null-term<strong>in</strong>ated str<strong>in</strong>g)i = (pr<strong>in</strong>t out mach<strong>in</strong>e <strong>in</strong>structions)U = b (bytes), h (2 bytes), w (4 bytes))Autodisplay<strong>in</strong>g <strong>in</strong>formationdisplay $eax (pr<strong>in</strong>t contents of %eax every time the program stops)display(pr<strong>in</strong>t the auto-displayed items)delete display (stop display<strong>in</strong>g item NUM)<strong>DDD</strong> (THIS WILL REALLY HELP!!):Display<strong>in</strong>g <strong>in</strong> the DATA WINDOWNote: To Turn Data W<strong>in</strong>dow ON/OFF (SELECT => DATA WINDOW)graph display `(p or x Command)`Ex. graph display `x/a $ebp+8`Ex. graph display `x/s *(<strong>in</strong>t*)($ebp+8)`(I casted value to a po<strong>in</strong>ter and than dereferenced)Ex. graph display `x/8xb 0x08048e2c`` = Tick Mark (below the Escape Key)Useful <strong>in</strong>formation <strong>commands</strong>help <strong>in</strong>fo<strong>in</strong>fo r (registers and their contents)<strong>DDD</strong>: Select Status => Registers<strong>in</strong>fo b (status of user-settable breakpo<strong>in</strong>ts)<strong>DDD</strong>: Select Source => Breakpo<strong>in</strong>ts<strong>in</strong>fo stack (backtrace of the stack)<strong>DDD</strong>: Select Status => Backtrace<strong>in</strong>fo address SYMBOL (use for look<strong>in</strong>g up addresses of functions)<strong>in</strong>fo frame (<strong>in</strong>formation about the current stack frame)


Other Useful <strong>commands</strong> (NOT for <strong>GDB</strong>/<strong>DDD</strong>)• objdump ­t This will pr<strong>in</strong>t out the bomb’s symbol table. The symbol table <strong>in</strong>cludes the names of all functions andglobal variables <strong>in</strong> the bomb, the names of all the functions the bomb calls, and their addresses. Youmay learn someth<strong>in</strong>g by look<strong>in</strong>g at the function names!• objdump ­d Use this to disassemble all of the code <strong>in</strong> the bomb. You can also just look at <strong>in</strong>dividual functions.Read<strong>in</strong>g the assembler code can tell you how the bomb <strong>work</strong>s.Although objdump ­d gives you a lot of <strong>in</strong>formation, it doesn’t tell you the whole story. Calls tosystem­level functions are displayed <strong>in</strong> a cryptic form. For example, a call to sscanf might appearas:8048c36: e8 99 fc ff ff call 80488d4 To determ<strong>in</strong>e that the call was to sscanf, you would need to disassemble with<strong>in</strong> gdb/ddd.• str<strong>in</strong>gs This utility will display the pr<strong>in</strong>table str<strong>in</strong>gs <strong>in</strong> your bomb.EXTRA INFO SECTIONSFor more <strong>in</strong>formation on Mach<strong>in</strong>e­Level Debugg<strong>in</strong>g <strong>in</strong> <strong>DDD</strong> see:http://www.gnu.org/software/ddd/manual/html_mono/ddd.htmlFor more <strong>in</strong>formation on Output Formats and Exam<strong>in</strong><strong>in</strong>g Memory see:http://sources.redhat.com/gdb/current/onl<strong>in</strong>edocs/gdb_9.html#SEC58SEE LABHANDOUT FOR MORE TIPS

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!