Thread: debugging segmentation fault

  1. #1
    Registered User
    Join Date
    Jan 2008

    debugging segmentation fault

    When I run the program it gives me a segmentation fault, the most annoying thing is that it doesn't tell me where this error occurs? Is there any way or an option in gcc, where I can show an option to show where this error occurs?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Yeah, run it in the debugger.

    gcc -g prog.c
    gdb a.out

    Sit back and wait, or interact with the program as normal.

    When it blows up, use the 'bt' command to reveal all.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2008
    With gdb you can step through your code and it'll abend at sigsegv.

  4. #4
    Registered User
    Join Date
    Jan 2008
    the program takes an input file from stdin , so how do I modify this?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    set arg < blah.txt
    will make gdb redirect blah.txt to stdin in your application.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  2. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM
  5. debugging: sigsegv, segmentation fault???
    By Gonzo in forum C Programming
    Replies: 9
    Last Post: 09-16-2003, 06:56 AM