debugging segmentation fault

This is a discussion on debugging segmentation fault within the C Programming forums, part of the General Programming Boards category; When I run the program it gives me a segmentation fault, the most annoying thing is that it doesn't tell ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Yeah, run it in the debugger.

    gcc -g prog.c
    gdb a.out
    run

    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

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

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

    --
    Mats
    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, 02:29 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21