Python GDB Rocks!
I wanted a non-painful way to figure out what’s causing bonus file IO. I’ve noticed that gtk likes to open files, but I didn’t have the exact details. So I grabbed python gdb, and with some tips on syscalls from gdb old-timers managed to produce a report to assign blame for open()ing files to relevant Mozilla functions.
Other than the gdb-hating syscalls issue, achieving this was simple
- Compile python-enabled gdb(Next set of distribution releases should have it..I hope)
- Define a new gdb command in a python file. I called mine “taras” for lack of a better name.
- Set a breakpoint, attach your command to it. :
1 2 3 4 5 6 7 8 9
- Have the script walk the backtrace to figure out the filename and the last Mozilla function. Log the info, issue gdb continue command.
- Print out a report and profit:
Here is my script. The only nasty part here is that I had to read the filename out of a register (i’m on amd64, on 32 it’d be $esi instead of $rdi) because gdb doesn’t deal well with system calls.
I’ve never throught it would be this fun to use gdb. I always thought debuggers should be scriptable, thanks to Tom Tromey (lots of gdb tutorials on Tom’s blog) and any others who finally made this a reality.