Thread: Question about dealing with segmentation faults

  1. #1
    Registered User
    Join Date
    Jun 2010

    Question Question about dealing with segmentation faults

    Hi guys,
    I am writing a large complex problem and I wanted some general advice. Right now the program is supposed to run a bunch of programs 1700 times. However at counter # 1018 it get a Segmentation fault.
    My problem is that I do not understand how to debug the program. The program takes 20 minutes to run so I cant step through the program. I was wondering if any of you could help give me some debugging tips in very large programs.

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    1) Put asserts. Make sure that the program's state is valid at all times.
    2) If you know at what iteration it occurs, try skipping the other iterations to the specific one and do line-by-line stepping.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Run it in the debugger.

    Wait for it to crash.

    The debugger will catch the segfault, and then you can look around to try and determine how the program got to that state.

    Fix the code.

    Rinse and repeat as necessary.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Another Question Dealing With I/O.
    By The7thCrest in forum C++ Programming
    Replies: 16
    Last Post: 02-04-2009, 08:16 PM
  3. newbie question dealing with an error
    By zack787 in forum C Programming
    Replies: 2
    Last Post: 02-27-2008, 04:49 PM
  4. Replies: 5
    Last Post: 08-14-2007, 10:34 AM
  5. Segmentation Fault Error
    By jcramer in forum C Programming
    Replies: 2
    Last Post: 11-23-2003, 02:16 PM