debugger/core dump(strange!!!)

Discussion in 'C Programming' started by questions?, Jan 5, 2006.

  1. questions?

    questions? Guest

    I am a newbie in programming and was reading O'Reilly <<Practical C
    programming>>
    I was trying to play with the debugger. I am using gdb under Fedora.

    I was trying to reproduce an error in the book. It is a binary search
    program. In the program, I have a line which is
    sscanf(line,"%d",data[index]), in front of data[index], it missed the
    &. so it will produce a runtime error.

    I compile with:
    >gcc -o run -g search.c


    run with
    >./run

    segmentation fault

    It suppose to create a core file, but in my directory, I didn't see it.
    How can I produce that file so that my debugger will load it?

    Thank you very much for any comments
    questions?, Jan 5, 2006
    #1
    1. Advertising

  2. questions?

    nelu Guest

    questions? wrote:
    > I am a newbie in programming and was reading O'Reilly <<Practical C
    > programming>>
    > I was trying to play with the debugger. I am using gdb under Fedora.
    >
    > I was trying to reproduce an error in the book. It is a binary search
    > program. In the program, I have a line which is
    > sscanf(line,"%d",data[index]), in front of data[index], it missed the
    > &. so it will produce a runtime error.
    >
    > I compile with:
    > >gcc -o run -g search.c

    >
    > run with
    > >./run

    > segmentation fault
    >
    > It suppose to create a core file, but in my directory, I didn't see it.
    > How can I produce that file so that my debugger will load it?
    >
    > Thank you very much for any comments


    This is not a C question and that behavior is system specific, you
    should ask the question in the apropriate group.

    However, I'll tell you the answer ;-)
    Because 'core' files can be rather large, some systems (including mine)
    are setup not to dump core files on errors.
    If you type:
    $ ulimit -c
    ($ replaces the prompt, don't type it)
    and the result is 0, then core files are not created.

    If you want core files to be created type:
    $ ulimit -c unlimited
    Now start the program, and it should display:
    Segmentation fault (core dumped)
    nelu, Jan 5, 2006
    #2
    1. Advertising

  3. questions?

    questions? Guest

    cool, very nice. This is exactly what I want.

    If I can change back to default setting, should I do: $ ulimit -c 0

    Is this right?

    Thank you very much for the help!!!
    questions?, Jan 5, 2006
    #3
  4. questions?

    questions? Guest

    cool, very nice. This is exactly what I want.

    If I want to change back to default setting, should I do: $ ulimit -c 0

    Is this right?

    Thank you very much for the help!!!
    questions?, Jan 5, 2006
    #4
  5. questions? wrote:
    > I am a newbie in programming and was reading O'Reilly <<Practical C
    > programming>>


    Yuck. Do yourself a favor, put that book down and pick up something
    worth its salt, "The C Programming language" is highly recommended,
    "The C Book" is available for free online at
    http://publications.gbdirect.co.uk/c_book/preface/about.html and is
    also a good text. Both these texts are aimed at someone with some
    level of programming experience though so you may have better luck with
    "Pointers on C" which is a fantastic book for someone new to
    programming. "C Programming: A Modern Approach" is also a great book
    although I recommend that if you choose to pick it up you buy it used
    as it is very expensive new (it is used as a college textbook) and the
    second edition is coming out soon.

    > I was trying to play with the debugger. I am using gdb under Fedora.


    This group is about the C language as defined by the ISO/ANSI
    Standards, we don't deal with platform specific questions. If you have
    a question specific to your platform your best bet would be to ask in a
    group that deals with your platform, this helps ensure that the answers
    you get will be from people with experience with your enviornment.

    > I was trying to reproduce an error in the book. It is a binary search
    > program. In the program, I have a line which is
    > sscanf(line,"%d",data[index]), in front of data[index], it missed the
    > &. so it will produce a runtime error.


    Providing an incorrect argument type to sscanf produces undefined
    behavior, this may include any number of things including running as
    expected or reformatting your hard drive.

    > I compile with:
    > >gcc -o run -g search.c

    >
    > run with
    > >./run

    > segmentation fault


    In your case this undefined behavior manifested itself as a memory
    violation, consider yourself lucky.

    > It suppose to create a core file, but in my directory, I didn't see it.
    > How can I produce that file so that my debugger will load it?


    This is the platform specific part. Core files are not part of C, they
    are an artifact of your the operating system (Linux). This would be a
    question to ask in comp.unix.programmer or a linux newsgroup.

    <OT> If you are using bash, try running "ulimit -c unlimited" before
    running your program. If this doesn't help you'll understand why we
    don't like to indulge off-topic questions here ;)
    </OT>

    If you have any questions about C itself, please feel free to ask here.
    If you have more linux questions, please ask in an appropriate group.

    Robert Gamble
    Robert Gamble, Jan 5, 2006
    #5
  6. questions? wrote:
    > cool, very nice. This is exactly what I want.
    >
    > If I want to change back to default setting, should I do: $ ulimit -c 0
    >
    > Is this right?
    >
    > Thank you very much for the help!!!


    I see that you are posting via Google Groups, please read
    http://cfaj.freeshell.org/google/ before posting again. As for your
    question, see my response to your original post about asking in a group
    that discusses your platform.

    Robert Gamble
    Robert Gamble, Jan 5, 2006
    #6
  7. questions?

    nelu Guest

    questions? wrote:
    > cool, very nice. This is exactly what I want.
    >
    > If I want to change back to default setting, should I do: $ ulimit -c 0


    That should do it.
    Please follow the link Robert provided so you know what to do the next
    time you post.
    nelu, Jan 5, 2006
    #7
  8. questions?

    haroon Guest

    questions? wrote:
    > cool, very nice. This is exactly what I want.
    >
    > If I want to change back to default setting, should I do: $ ulimit -c 0
    >
    > Is this right?
    >
    > Thank you very much for the help!!!


    first read this ===> http://cfaj.freeshell.org/google/
    this will give you alot of thought
    <OT>
    once u know of a *nix command try using man <command>. it helps alot.
    </OT>
    haroon, Jan 5, 2006
    #8
  9. questions?

    questions? Guest

    Robert Gamble wrote:
    > questions? wrote:
    > > I am a newbie in programming and was reading O'Reilly <<Practical C
    > > programming>>

    >
    > Yuck. Do yourself a favor, put that book down and pick up something
    > worth its salt, "The C Programming language" is highly recommended,
    > "The C Book" is available for free online at
    > http://publications.gbdirect.co.uk/c_book/preface/about.html and is
    > also a good text. Both these texts are aimed at someone with some
    > level of programming experience though so you may have better luck with
    > "Pointers on C" which is a fantastic book for someone new to
    > programming. "C Programming: A Modern Approach" is also a great book
    > although I recommend that if you choose to pick it up you buy it used
    > as it is very expensive new (it is used as a college textbook) and the
    > second edition is coming out soon.



    Thanks for the recommendation for the books.
    questions?, Jan 5, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    692
  2. BlueDoze
    Replies:
    2
    Views:
    1,095
    Gordon Beaton
    May 4, 2004
  3. Amit
    Replies:
    0
    Views:
    959
  4. halfdog
    Replies:
    12
    Views:
    12,415
  5. Ralph Shnelvar
    Replies:
    0
    Views:
    137
    Ralph Shnelvar
    Dec 25, 2009
Loading...

Share This Page