This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Segmentation fault
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: beamendsltd <beamendsltd at btconnect dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 25 Mar 2010 04:45:22 -0700
- Subject: RE: Segmentation fault
- References: <1269516508.7204.9.camel@beamends-1>
Hi Richard,
Segmentation faults are usually one of the easiest bugs to track down. At least at the point of failure.
1. Compile your program with debug information:
# gcc -g -o MyApp MyCode.c
2. Run your program in the debugger:
# gdb ./MyApp
(gdb) run
3. When your program crashes, look at the stack backtrace:
(gdb) bt
The first few frames will give you the context of the crash, at the point of failure.
If the cause of the failure is distant in time/space from the point of failure, that can be trickier to figure out.
If the crash is hard to reproduce consistently, that may make things trickier to figure out.
For bug classification, here are some amusing (yet surprisingly useful) types of bugs:
http://en.wikipedia.org/wiki/Heisenbug
And here are some more, and a recap of the above:
http://catb.org/jargon/html/S/smash-the-stack.html
http://catb.org/jargon/html/B/buffer-overflow.html
http://catb.org/jargon/html/A/aliasing-bug.html
http://catb.org/jargon/html/F/fandango-on-core.html
http://catb.org/jargon/html/M/memory-leak.html
http://catb.org/jargon/html/M/memory-smash.html
http://catb.org/jargon/html/O/overrun-screw.html
http://catb.org/jargon/html/S/secondary-damage.html
http://catb.org/jargon/html/H/heisenbug.html
http://catb.org/jargon/html/B/Bohr-bug.html
http://catb.org/jargon/html/M/mandelbug.html
http://catb.org/jargon/html/S/schroedinbug.html
Sincerely,
--Eljay