Index: [thread] [date] [subject] [author]
  From: Peter Amstutz <tetron@student.umass.edu>
  To  : ggi-develop@eskimo.com
  Date: Mon, 12 Jul 1999 20:45:51 +0000 (GMT)

Re: hacking methods to find out bugs

On Mon, 12 Jul 1999, Christoph Egger wrote:

> On Mon, 12 Jul 1999, Jon M. Taylor wrote:
> 
> > On Mon, 12 Jul 1999, Christoph Egger wrote:
> > 
> > > 
> > > Hi all!
> > > 
> > > I have tried to debug my lib with ddd again. Now I found some bugs, but
> > > not all.
> > > 
> > > 
> > > program exited with SIGSEGV at 0x400e807
> > > 
> > > 
> > > How can I find out with this ddd error, what is buggy? I have no
> > > experience about memory dumbing... Can anyone help me?
> > 
> > 	What is usually do with a bugs like this is to fall back to using
> > printf() (or the equivalent) to zero in on the line which is causing the
> > segfault.  Crude but often quite effective debugging technique.  Once you 
> > have found the line which is causing the segfault, most of the time the 
> > problem will jump out at you.
> 
> Can you give an example?

This is a pretty basic debugging skill, but in a nutshell:

somefunction(...) {
	/* some possibly buggy code */
	printf("Checkpoint #1\n");
	/* more possibly buggy code */
	printf("Checkpoint #2\n");
	/* even more possibly buggy code */	
	printf("Checkpoint #3\n");
}

Then look for the last "Checkpoint" statement that was printed out before
things blew up.  That will give you an idea of where the code failed.  
For example, if it prints out "Checkpoint #1" and "Checkpoint #2" but NOT
"Checkpoint #3" then clearly the failure happened somewhere in the "even
more possibly buggy code" block.

Of course you can print anything, recently I was doing some debugging like
this using the names of several japanese and european cities, intermixed
with four-letter words (a rather naughty race condition that may still be
lurking in there, unfortunatly, hence the foul language :)

           ------------------ Peter Amstutz --------------------
           -------------- tetron@student.umass.edu -------------
           ------- http://www-unix.oit.umass.edu/~tetron -------
           -----------------------------------------------------

Index: [thread] [date] [subject] [author]