Thread: Segmentation Fault before faulty code is ever reached?

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Boy, it's amazing the lengths people go to to defend their statements. Even more so, when those statements are all partially right and partially incorrect.


    Quote Originally Posted by cyberfish View Post
    Just get over it... a segfault is a UNIX/Linux/BSD thing, and GDB is the debugger that has >99% userbase on those systems.
    You forget there are several commercial variants of unix (solaris, irix, MacOS/Darwin, etc) where gdb is not the default debugger.
    Quote Originally Posted by cyberfish View Post
    It's like saying we can't assume a person saying he is using IE 7 is on Windows.
    As a matter of fact, you can't assume that. There are windows emulators that run under other operating systems.
    Quote Originally Posted by Elysia View Post
    Segmentation fault is a technical term, and believe or not, it also exists on Windows.
    Yes, it does. However, when a forum post asks for help with code that generates a segmentation fault, it is a fair bet the poster is working under some variant of Unix. I would agree (see above) that does not justify an assumption they can/will use gdb.

    Segmentation faults, when they occur under windows, are usually reported as a STATUS_ACCESS_VIOLATION exception (in either an error message, or within a popup dialog). There is no reference in that error message to the term "segmentation fault".

  2. #17
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    You forget there are several commercial variants of unix (solaris, irix, MacOS/Darwin, etc) where gdb is not the default debugger.
    That's why I said 99%. Mac I think uses gdb/gcc, too, and I think Linux + Mac + BSD makes up 99% of *nix machines.

    As a matter of fact, you can't assume that. There are windows emulators that run under other operating systems.
    That's exactly the point. It's between politically correct and practically correct. How many people (in terms of % of IE users) runs IE under wine anyways?

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    182
    Wow, well this has been informative.

    Thanks for all the input. Using gdb was useful. Does anyone know of a good starting point for learning gdb?

    Should I be learning any other tools at this stage?

  4. #19
    Registered User bboozzoo's Avatar
    Join Date
    Jan 2009
    Posts
    14
    https://www.cs.colostate.edu/wiki/Gdb here's a decent bunch of references to number of tutorials

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by yougene
    Does anyone know of a good starting point for learning gdb?
    I "cheat" by using Code::Blocks as a front end.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    Yes. Learning valgrind is usefull. It is really good with finding spots where memory is incorrectly used.

    And with gdb you can get started with following basic commands:

    start it

    gdb <exename>

    <run program>
    type run <exe parameters if there is such>

    To interrupt, hit ctrl+c

    <getting backtrace from stack>
    type bt

    going "up" and "down" at stack calls, use
    frame <number shown in backtrace>

    To see local variables, type
    info locals

    to get a value of variable type
    inspect <var name>

    to continue executing program, type
    c

    To kill program being debugged, type
    kill

    If app is threaded, type
    info threads

    To switch to another threads context, type
    thread <number>

    to set a breakpoint, type
    bp <function name, or file:line>

    And finally, to dig deeper,
    type help

    I wrote these out of my head, so some mistakes may be present.

    EDIT: Another lightweight frontend to gdb is ddd. Some also use eclipse as IDE, and it supports gdb too - also remote debugging (with gdbserver).

    Me? I like things simple. gdb as it is, and vim is enough as an "IDE" for me
    Last edited by Maz; 01-12-2009 at 05:10 PM.

  7. #22
    Registered User
    Join Date
    May 2006
    Posts
    182
    Thanks for all the suggestions I'll look through them and get on it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation Fault?
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-10-2008, 07:26 AM
  2. Searching and matching strings: segmentation fault
    By Smola in forum C Programming
    Replies: 18
    Last Post: 07-11-2005, 12:25 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 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