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

Re: GDB



> 
> I'm using the "-g" flag.  But gdb will tell me what code is causing the
> crash right?

Maybe.  The error you got, a segmentation fault, means that you tried
to access an illegal memory address.  It could be that you wrote beyond
the limits of an array, or made an error in memory allocation.  The
problem with this kind of errors is, that they don't always occur in
the part of the code where the bug is.  Often you will find that that
the segmentation fault arises in a piece of library code, like malloc()
or free(), or in a piece of the code way beyond the bug.  Sometimes the
code might run seemingly `OK' on a different machine or on a different
input set.  To improve on this situation you could install the
electric-fence library (it is in a debian package).  This has
replacements for malloc() and friends that crash immediately at the
actual offending memory access.  Then you would link the program with
-umalloc -lefence, e.g.:

gcc -o myprg -g -O2 *.o -umalloc -lefence

The run `myprg' in gdb, like

gdb myprg

Type `run' to run the program, and after it crashes, type `where'.  This
should get you going.  Be sure to read the man page from efence
carefully (man efence).  You need to set environment variables for
different kinds of checks, like overruns or underruns.

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


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: