debugger/core dump(strange!!!)

Q

questions?

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
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
 
N

nelu

questions? said:
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
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)
 
Q

questions?

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!!!
 
Q

questions?

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!!!
 
R

Robert Gamble

questions? said:
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:

run with
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
 
R

Robert Gamble

questions? said:
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
 
N

nelu

questions? said:
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.
 
H

haroon

questions? said:
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>
 
Q

questions?

Robert said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top