John Chang posted some tips for debugging Mac OS X apps on his blog. Most of them should be old hat to most people, but surprisingly are not (I, for instance, once wrote a set of gdb macros to do what print-object did, because I did not know it was there at the time I needed it). He left out one of my favorite techniques though, programmmed break points.
Here is the idea. gdb lets you set a break point. It also lets you script a command to execute when the break point is hit. If the last command you do is continue, the program will keep running. The most basic thing you can do is something like:
(gdb) b myFunc
Breakpoint 1 at 0x900107a8
(gdb) commands 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>bt
>c
>end
(gdb)
That will tell the debugger to print out a back trace and then continue the app. That can be really useful to track down rogue API callers, etc. You can do much more advanced things, such as argument replacement or filtering, but you get the idea.
Posted by louis at August 29, 2003 11:11 AM | TrackBack