Skip to content

Instantly share code, notes, and snippets.

@thlorenz
Last active October 16, 2019 09:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thlorenz/72ead62cd09bec40d8d2 to your computer and use it in GitHub Desktop.
Save thlorenz/72ead62cd09bec40d8d2 to your computer and use it in GitHub Desktop.
gdb: automatically step through a binary one instruction at a time and log registers at each step

gdbinit

set disassemble-next-line on
set dissasembly-flavor intel

b _start
run

while 1
  info registers
  stepi
end

quit

Run via: gdb -nx < ./gdbinit > ./out.txt

gdb complains at the end, but all is good and the info we want is in out.txt Don't do this for large binaries obviously ;)

sample out.txt

gdb header removed

➝  head out.txt -n 70
[ .. ]
Breakpoint 1, _start () at inc.asm:8
/home/thlorenz/dev/asm/visulator/test/asm/inc.asm:8:170:beg:0x8048060
=> 0x08048060 <_start+0>:       90      nop
(gdb) (gdb)  > > >eax            0x0    0
ecx            0x0      0
edx            0x0      0
ebx            0x0      0
esp            0xffffd350       0xffffd350
ebp            0x0      0x0
esi            0x0      0
edi            0x0      0
eip            0x8048060        0x8048060 <_start>
eflags         0x202    [ IF ]
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
/home/thlorenz/dev/asm/visulator/test/asm/inc.asm:11:190:beg:0x8048061
=> 0x08048061 <_start.start_test+0>:    40      inc    eax
eax            0x0      0
ecx            0x0      0
edx            0x0      0
ebx            0x0      0
esp            0xffffd350       0xffffd350
ebp            0x0      0x0
esi            0x0      0
edi            0x0      0
eip            0x8048061        0x8048061 <_start.start_test>
eflags         0x202    [ IF ]
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
/home/thlorenz/dev/asm/visulator/test/asm/inc.asm:12:231:beg:0x8048062
=> 0x08048062 <_start.start_test+1>:    40      inc    eax
eax            0x1      1
ecx            0x0      0
edx            0x0      0
ebx            0x0      0
esp            0xffffd350       0xffffd350
ebp            0x0      0x0
esi            0x0      0
edi            0x0      0
eip            0x8048062        0x8048062 <_start.start_test+1>
eflags         0x202    [ IF ]
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment