Seg Faults

M

Matt

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
 
R

Richard

Matt said:
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.
 
A

Army1987

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.
 
D

David Resnick

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
 
C

Christopher Benson-Manica

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.
 
J

John Gordon

In said:
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.
 
P

phuong.d.nguyen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top