Thread: gdb

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    14

    gdb

    Is it good for gdb to run successfully but not your program?


    For some reason I am getting a seg fault with my malloc and it is really annoying.



    Sorry if its bad code but I'm just learning C right now.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    First step is to stop casting the returns of malloc.

    Oh and in C // is not a valid comment code

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >Oh and in C // is not a valid comment code
    I think that it is in C99.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    True in C99 it is but the chances that they are using a C99 compiler are...

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    It'll segfault if the file doesn't exist because the Load_List function will fclose( NULL ). Otherwise, it didn't segfault for me (GCC3.3, Linux).
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    14
    arrrgg,

    The file does exist but I'm limited to what compiler I'm allowed to use because it has to be able to run on the school lab computers.


    uhhh, I'm // has been working fine for me, I wouldn't know why though.


    Thanks for the help

  7. #7
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    Yeah, // works in all of my compilers: MSVC++7 (in a C project), DMC, GCC, etc...

    It's pretty much standard now.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    One major thing I noticed is the lack of proper error checking. Every malloc call needs to be checked for errors.

    Since you mentioned the school's lab I'm gonna venture a guess that it is using a windows platform.

    If that is correct then your path should be:
    "\\stud\\rdonnell\\word"

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    14
    no I'm on linux redhat 9.0

    The reason I don't have error checking is because I'm just trying to get some basics out of the way. I will put it in but later.

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok just wanted to make sure on the file system part

    The thing is that malloc error checking and file opening error checking (which you do have) are of such importance you can't throw them to the side for later.

    Granted they usally don't fail but the risk is too high.

    BTW is the function In_File() important? You don't have it in the code.

    Edit: moved the fclose into the if statement and it exit normally.

    If the file exist, do you have the proper permissions?
    Last edited by Thantos; 03-25-2004 at 10:19 PM.

  11. #11
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try just putting the "word" file in the same directory as the executable. Then you don't need to worry about paths.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  12. #12
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by EvilBaby
    no I'm on linux redhat 9.0

    The reason I don't have error checking is because I'm just trying to get some basics out of the way. I will put it in but later.
    When do you think the most errors occur, during initial development or after the basics are out of the way?

    "I'm building a rocket car and I've got the Saturn V engine installed. I'll add the brakes after I've got the engine basics tested. EvilBaby, you get the first test drive."
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  13. #13
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    You might find lint to be helpful when trying to work a bug out.
    Directly from the man page:
    NAME:-
    lint - a C program verifier

    DESCRIPTION:-
    lint attempts to detect features of the named C program files that are
    likely to be bugs, non-portable, or wasteful. It also performs stricter
    type checking than the C compiler. lint runs the C preprocessor as its
    first phase, with the preprocessor symbol lint defined to allow certain
    questionable code to be altered or skipped by lint. Therefore, this sym-
    bol should be thought of as a reserved word for all code that is to be
    checked by lint.
    By the time I'm done with lint, there's barely a reason to turn to gdb.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. buffered vs unbuffered question
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 07-04-2008, 04:57 PM
  2. Memory allocation error
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2008, 04:24 PM
  3. Contiguous Array version of Linked List
    By ampersand11 in forum C Programming
    Replies: 19
    Last Post: 10-07-2007, 03:05 AM
  4. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  5. does gdb lie?
    By dinjas in forum C Programming
    Replies: 8
    Last Post: 03-10-2005, 05:17 PM