By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

Seg Faults

P: n/a
Hey guys. I've got a general question here regarding segmentation
faults.

I've got some code that I started working on a few weeks ago which at
the time ran without any problems. In the course of my coding I came
across a segmentation fault and needed to check something in the
original version of the code in hope of finding where I had gone
wrong. However, the original code now seg faults as well! The fault
ocurs in roughly the same place as before as the output from both
versions is identical.

I have tried loading up my original archive over and over but nothing
seems to be working. I am certain the archive is sound as I have been
using it as a reference point over the last few weeks without any
problems.

So, as the programme is far too large to post up, I was hoping to draw
on the experience of you guys and come up with some possible sources
of this error. Any suggestions are welcome.

Kind Regards,

Matt

Aug 6 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matt <ma*****@hotmail.comwrites:
Hey guys. I've got a general question here regarding segmentation
faults.

I've got some code that I started working on a few weeks ago which at
the time ran without any problems. In the course of my coding I came
across a segmentation fault and needed to check something in the
original version of the code in hope of finding where I had gone
wrong. However, the original code now seg faults as well! The fault
ocurs in roughly the same place as before as the output from both
versions is identical.

I have tried loading up my original archive over and over but nothing
seems to be working. I am certain the archive is sound as I have been
using it as a reference point over the last few weeks without any
problems.

So, as the programme is far too large to post up, I was hoping to draw
on the experience of you guys and come up with some possible sources
of this error. Any suggestions are welcome.

Kind Regards,

Matt
Number 1 "doh" check : are you 100% sure you are executing your
recompiled from archive version? Check your path.

Number 2 "why didn't I think of that" is simply compile your archive
code with a comment in it indicating "test day" or something and run it
in a debugger .... when you run debugger check the "test day" comment is
in your code and run it until it segfaults.
Aug 6 '07 #2

P: n/a
On Mon, 06 Aug 2007 03:17:18 -0700, Matt wrote:
Hey guys. I've got a general question here regarding segmentation
faults.

I've got some code that I started working on a few weeks ago which at
the time ran without any problems. In the course of my coding I came
across a segmentation fault and needed to check something in the
original version of the code in hope of finding where I had gone
wrong. However, the original code now seg faults as well! The fault
ocurs in roughly the same place as before as the output from both
versions is identical.

I have tried loading up my original archive over and over but nothing
seems to be working. I am certain the archive is sound as I have been
using it as a reference point over the last few weeks without any
problems.

So, as the programme is far too large to post up, I was hoping to draw
on the experience of you guys and come up with some possible sources
of this error. Any suggestions are welcome.
Carefully check that you're never dereferencing a pointer which
doesn't point to memory you own. (Note that doing so does not
always causes a segfault, it may depend on many more conditions
that you could imagine.)
Try to isolate the part which causes the segfault, i.e. write the
smallest possible program which exhibits the problem. This will
usually show you where the problem is, if it doesn't post the
reduced program here.

--
Army1987 (Replace "NOSPAM" with "email")
"Never attribute to malice that which can be adequately explained
by stupidity." -- R. J. Hanlon (?)

Aug 6 '07 #3

P: n/a
On Aug 6, 6:17 am, Matt <matt...@hotmail.comwrote:
Hey guys. I've got a general question here regarding segmentation
faults.
.....
>
So, as the programme is far too large to post up, I was hoping to draw
on the experience of you guys and come up with some possible sources
of this error. Any suggestions are welcome.
Without code, people can only offer generalities, like checking
pointers for NULL prior to dereferencing them, not using freed memory,
not using uninitialized pointers, not overwriting bounds of allocated
memory, etc. If you always crash at the same point in the program
(seen by logging/etc), it is usually straightforward to figure out
why. Add some print statements showing the objects in use (pointers,
etc), and figure out the problem that way. If you crash at random
points, that is trickier.

<OT>If you are on a system where a core file is available after a
segmentation fault, that can be helpful. Sometimes you need to enable
this (e.g. via ulimit on linux).

There are also lots of tools that can rescue you. If you always crash
in the same place, running under a debugger, putting a breakpoint
there, and looking at things can help. There are some tools, which
may be available on your system, some free, some not, like valgrind,
electric fence, purify, etc, that can be very nice for tracking down
this sort of problem. If you use glibc, the MALLOC_CHECK_ environment
variable set to 2 can occasionally help too, causes core dump on
bounds overwrites, though only when the memory is actually freed.
</OT>

-David

Aug 6 '07 #4

P: n/a
Army1987 <ar******@nospam.itwrote:
On Mon, 06 Aug 2007 03:17:18 -0700, Matt wrote:
Hey guys. I've got a general question here regarding segmentation
faults.
Finding them can be a painful exercise. If you're not able to spot
your error by examining the code, you might find a program such as
valgrind to be useful - check Google for more details.

--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
Aug 6 '07 #5

P: n/a
In <11**********************@b79g2000hse.googlegroups .comMatt <ma*****@hotmail.comwrites:
I've got some code that I started working on a few weeks ago which at
the time ran without any problems. In the course of my coding I came
across a segmentation fault and needed to check something in the
original version of the code in hope of finding where I had gone
wrong. However, the original code now seg faults as well! The fault
ocurs in roughly the same place as before as the output from both
versions is identical.
One explanation is that the original code actually did have the problem,
but due to sheer luck you just never saw it.

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Aug 6 '07 #6

P: n/a
On Aug 6, 3:17 am, Matt <matt...@hotmail.comwrote:
Hey guys. I've got a general question here regarding segmentation
faults.

I've got some code that I started working on a few weeks ago which at
the time ran without any problems. In the course of my coding I came
across a segmentation fault and needed to check something in the
original version of the code in hope of finding where I had gone
wrong. However, the original code now seg faults as well! The fault
ocurs in roughly the same place as before as the output from both
versions is identical.

I have tried loading up my original archive over and over but nothing
seems to be working. I am certain the archive is sound as I have been
using it as a reference point over the last few weeks without any
problems.

So, as the programme is far too large to post up, I was hoping to draw
on the experience of you guys and come up with some possible sources
of this error. Any suggestions are welcome.

Kind Regards,

Matt

Assuming that "both" version of your code fail then chances are:

-You ran the code under different users, earlier one might have access
to resources that later one does not?
-Resources which were available earlier are gone now?

In both cases you could have a failed open/mmap/ioctl and did not
properly check return value. Then using those bad handle/pointer could
lead to segfault.

Aug 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.