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

1998-12-16 Thread Sean
Sorry if this is too basic .

a segmentation fault (seg fault) is a UNIX app crashing.  The most common cause
is a pointer writing or reading an incorrect memory location.  Possibly you are
not compiling the bin correctly (leaving off a libray or a define).

to find out why you can use gdb (gnu debugger).  Compile the app with the -g
compiler flag (both compilers will accept this).  Then run it as: gdb app. 
At the gdb prompt type run and the app will run.  If/when it dies type bt to
get a back trace of the calls to see where it seg'ed.  You can also run the app
via strace or ltrace which will print each syscall the app makes until it dies.

another good start is to run: ldd app.  This will output all the libraries
your app needs.  If you notice any of them listed incorrectly this could be a
problem.

Need more help?  Just ask.


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

1998-12-16 Thread E.L. Meijer \(Eric\)
 
 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 ([EMAIL PROTECTED])  | 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