Archive for March, 2007

Stopping right before your crash

Thursday, March 15th, 2007

I just got this question from Steve down the hall.  It’s so mind-bogglingly useful, that everyone who uses dbx needs to know how to do it.  The scenario goes like this. Your program crashes in strcpy sometime in the middle of the run, after about a zillion calls to strcpy.  But you want to stop on entry to the strcpy call which is going to cause the crash.  Here’s how to do it.

(dbx) stop in strcpy -count infinity
(dbx) run
[[ crash ]]
(dbx) status
 (2) stop in strcpy -count 2435/infinity 
(dbx) delete all
(dbx) stop in strcpy -count 2435
(dbx) run
(dbx) where
[[ stopped right before the crash ]]

Of course, you can do the same thing in gdb, but I’ll leave that as an exercise for the reader. 🙂