Seg Faults

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    Seg Faults

    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

  • Richard

    #2
    Re: Seg Faults

    Matt <mattb95@hotmai l.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.


    Comment

    • Army1987

      #3
      Re: Seg Faults

      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 (?)

      Comment

      • David Resnick

        #4
        Re: Seg Faults

        On Aug 6, 6:17 am, Matt <matt...@hotmai l.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

        Comment

        • Christopher Benson-Manica

          #5
          Re: Seg Faults

          Army1987 <army1987@nospa m.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)gma il.com |
          ----------------------| I do not currently read any posts posted through
          sdf.lonestar.or g | Google groups, due to rampant unchecked spam.

          Comment

          • John Gordon

            #6
            Re: Seg Faults

            In <1186395438.777 369.166930@b79g 2000hse.googleg roups.comMatt <mattb95@hotmai l.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
            gordon@panix.co m B is for Basil, assaulted by bears
            -- Edward Gorey, "The Gashlycrumb Tinies"

            Comment

            • phuong.d.nguyen

              #7
              Re: Seg Faults

              On Aug 6, 3:17 am, Matt <matt...@hotmai l.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.

              Comment

              Working...