This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Newbie lost with a segmentation fault
- To: help-gcc at gnu dot org
- Subject: Re: Newbie lost with a segmentation fault
- From: Chris Majewski <majewski at cascade dot cs dot ubc dot ca>
- Date: 28 Oct 1999 04:32:35 GMT
- Newsgroups: gnu.gcc.help
- Organization: Computer Science, University of British Columbia, Canada
- References: <3817AC35.4C6C827E@erols.com>
- Xref: wodc7nx0 gnu.gcc.help:1630
That's a good book though some of the exercises are tricky!
The secret to finding seg faults and other bugs is to use gdb, the GNU
debugger. If you're already using a good editor like Emacs you can run
this inside your editor (M-x gdb). Gdb expects the name of the
executable (eg a.out) as its argument. Once inside gdb you can type
help
or you can read the Info file on gdb (M-x info RET gdb).
(Usually seg faults come from pointer bugs like this:
int *x = 0;
int y = *x;)
-chris
John Soltow <jasoltow@erols.com> wrote:
> I'm in the process of teaching myself C through "The C Programming
> Language" (Brian Kernighan & Dennis Ritchie) and
> am having problem with a piece of code. The code compiles ok (using GCC
> under Linux), but segmentation faults when run.
> I'm not as concerned about what is wrong with the code (for the
> purpose of this message) as I am with how to go about finding the
> problem when I get a seg fault/core dump. In this case, everything in
> the code looks fine. I know from reading elsewhere in Usenet that the
> core file can be used as a troubleshooting aid in finding the problem in
> the code. Can someone point me to the documentation that explains how
> to do that?
> If it matters, I'm running gcc version egcs-2.91.66 19990314/Linux
> (egcs-1.1.2 release)
> Thanks,
> John Soltow