Getting Started: ================ To get a disassembled version of a program objdump -d puzzle > puzzle.s x86-64 supplement to Chapter 3 of the textbook: =============================================== Especially the section on the calling convention, and how some things are compiled differently on x86-64 than x86. http://www.cs.cmu.edu/~fp/courses/15213-s07/misc/asm64-handout.pdf Other relevant materials are at http://www.cs.cmu.edu/~fp/courses/15213-s07/resources.html GDB NOTES: ========= To start gdb and load a program gdb puzzle To get help about a command within GDB: help examine help print ... To run the program with some arguments: run arg1 arg2 ... argN To display the next instruction to be executed after every step: display/i $rip To display the value of some register after every step as hex: display/x $rax To see what displays are set up: info display To stop displaying something: undisplay NUM # NUM is the number of the # display from ``info display'' To print the value of something: print 0x123 # prints the decimal of 0x123 print/x 10+90 # prints the hex of 100 print/t $rax # prints the binary (base 'T'wo) of contents of rax To examine a particular memory address: exmaine ADDRESS or x ADDRESS Examine has lots of options: x/i main+0x10 # disassemble the instruction at the address x/s 0x400bfe # display the string at the address x/4wd $rax # display the four 32-bit words as decimal numbers # starting at address in register rax x/3gx 0xFOOF # display 3 64-bit values as hex To see what's in all the registers: info registers To disassemble the function currently executing: disas To disassemble some other function: disas string_length To disassemble some range of memory: disas 0xC0FFEE 0xDEADBEEF To set a breakpoint at the start of ``main'': break main To set a breakpoint at some address: break 0x1234ABCD To see what breakpoints are set: info break To clear a breakpoint: clear 0x1234ABCD or clear main To step a single machine instruction: stepi or si To step a single instruction but treating `call' as a single instruction: nexti or ni To continue the execution until the next breakpoint cont To quit GBD quit For more information, see the GDB manual or go to http://csapp.cs.cmu.edu/public/docs/gdbnotes.txt