2004-07-19-0605Z


gdb is great. Here's the .gdbinit file I have for my current project:

printf "************** DEBUGGING nfsmount **************\n"
printf "invoke simply as 'gdb', this file does the rest.\n"
printf "it must be named gdb.ini on some systems, .gdbinit on others.\n"
printf "i'm using a symlink to take care of both cases.\n"
file nfsmount
break cold
break *cold+5
printf "to advance one instruction, type 'si'\n"
printf "to do the same, but go through subroutine calls, type 'ni'\n"
display/5i $pc
display/x $esp
display/x $ebp
display/x $edi
display/x $esi
display/x $edx
display/x $ecx
display/x $ebx
display/x $eax
run

I'd forgotten all this shit. When you start running, the number at $esp is the C language argc, and the words following are pointers to the argv strings. Following that is a zero, then the environment strings, again followed by a zero. How easy can it get? Here's an illustration, after invoking gdb with the above .gdbinit:

(gdb) x/20x $esp
0xbffff7b0:     0x00000001      0xbffff8d9      0x00000000      0xbffff8fd
0xbffff7c0:     0xbffff944      0xbffff9b4      0xbffff9c8      0xbffff9e6
0xbffff7d0:     0xbffff9f1      0xbffffa01      0xbffffa39      0xbffffa48
0xbffff7e0:     0xbffffa60      0xbffffa86      0xbffffad0      0xbffffae8
0xbffff7f0:     0xbffffaf5      0xbffffb08      0xbffffcbb      0xbffffcc9
(gdb) x/s 0xbffff8d9
0xbffff8d9:      "/home/jcomeau/src/nfsmount/nfsmount"
(gdb) x/s 0xbffff8fd
0xbffff8fd:      "CPLUS_INCLUDE_PATH=/usr/lib/qt-3.2.1/include:/usr/lib/qt-3.2.1/include"
(gdb)

So what do we need the goddamned half-megabyte of glibc for? Linus Torvalds and Richard Stallman (and a cast of thousands) made it so easy to write apps in assembly! OK, so I'm joking a little here... but only a little.

Back to blog or home page

last updated 2013-01-10 20:24:44. served from tektonic.jcomeau.com