Segmentation fault

John (Eljay) Love-Jensen eljay@adobe.com
Thu Mar 25 14:33:00 GMT 2010


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



More information about the Gcc-help mailing list