[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 'Segmentation Fault' - how do i find out what thr problem is?



> 
> Hi,
> 
> Excuse the vague problem definiton, but on a variety of programs I've 
> compiled (but not written...), when i try to run the resulting program I 
> just get a 'Segmentation Fault' immediately.
> 
> Any clues either as to what causes this, or how to find out what 
> does/doesn't (<-for elimination purposes...) cause it?

If a program generates a segmentation fault, it tries to access memory
that doesn't belong to its allocated address space.  Typical examples
are overrunning arrays (declare an array of 10 elements, and try to
access the 11th element) and using uninitalized pointers (like 
char *s;
strcpy(s, "disaster");
}

Somtimes segmentation faults are indicative of bad memory chips.  If you
can do a few kernel compiles without them, this is probably not the
case.

> A couple of test progs. I wrote ran fine.
> 
> One of the programs that seg faults here at work doesn't at home.

This is also typical for segmentation fault type of errors.  They do not
always occur, even though the bug that causes them is there.  Another
nasty property is that the segmentation fault often appears much later
than the offending statement.  The offending statement screws up the
memory, which then causes trouble later on in the program, although
there is no bug at that place.

> Of the seg faulting programs, one is compiled with g++ (the standard one 
> in hamm) and the other with g77 (again, the vesion that's in hamm).

I think you have some debugging ahead :)  For the g++ program it can be
useful to install the electric fence library, read `man efence', and
link with `-umalloc -lefence'.

HTH,
Eric

-- 
 E.L. Meijer (tgakem@chem.tue.nl)          | tel. office +31 40 2472189
 Eindhoven Univ. of Technology             | tel. lab.   +31 40 2475032
 Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax    +31 40 2455054


Reply to: