LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-21-2004, 05:24 PM   #1
sonitbk
LQ Newbie
 
Registered: Mar 2004
Location: Russia
Posts: 8

Rep: Reputation: 0
Segmentation fault, So strange..


So strange, I run the program and it gives the result, but when debugging it, using kdbg , It gives the message "Segmentation fault"
and even strange when it come to
->{
and stop....and give the message"Segmentation fault"
Any Ideas?
 
Old 04-21-2004, 05:41 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: Segmentation fault, So strange..

Quote:
Originally posted by sonitbk
Any Ideas?
No, of course not. Not without some code.
You are only telling your program segfaults, and that the same thing happens when you run it in a debugger. You didn't even tell what the program is for or what it should do. What ideas did you expect from people here?

Last edited by Hko; 04-21-2004 at 05:44 PM.
 
Old 04-21-2004, 06:55 PM   #3
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
after a SegFault.......you need to "dump the core" and then
use GDB to de-bug it.......
 
Old 04-21-2004, 09:27 PM   #4
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16
Hi,

To continue where 320mb left off. Try this:

ulimit -c unlimited

Then, compile the program with the -g flag if you're using gcc and run the program and make it crash. This time, the program should say something like: Segmentation Fault (Core dumped).

Now, type this:

gdb program core

where, program is the name of your program and core is the dumped core file (it could also be named core.xxxx, where xxxx is the pid of the crashed program).

I'm not going to go into a detailed gdb tutorial. You can find many of those online. Go google for one of them. But, as soon as you enter gdb, if'll probably tell you the line number and function where it crashed.

Happy bug hunting,
Arvind
 
Old 04-22-2004, 11:06 AM   #5
sonitbk
LQ Newbie
 
Registered: Mar 2004
Location: Russia
Posts: 8

Original Poster
Rep: Reputation: 0
The strange thing is : when running, it is ok, no error message, but when debuging, it give"segmentation fault" . And more : when debuging : if I press F5 fast and continously, it gives the right result (no error), but when slowing pressing F5 , it comes to that error "segme....."
and one more question : kdbg and gbd , for you, which is better?( not about the graphical interface)?
(the code is so long, I can not put here"
 
Old 04-22-2004, 12:05 PM   #6
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16
Well, from your description, I cannot figure out what is wrong. I don't even know what kind of an application you're talking about. If you can get it to crash inside gdb (is that what you meant when you said it crashes during debugging?), then you can type "bt" inside gdb to find out what happened.

I prefer gdb to kdbg. But, it's just my personal preference. You might want to check out ddd.

Arvind
 
Old 04-22-2004, 05:54 PM   #7
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
You might give Electric Fence a shot. It may make the seg fault more consistent, and/or cause it at the soure of the problem rather than later on. Once you get it installed, just run "LD_PRELOAD=libefence.so.0.0 ./yourprogram", and if it seg faults you can "gdb yourprogram core"

This will only help *if* the problem happens because you're writing past the end of a dynamically allocated array, but that condition does happen a lot. Without electric fence you may get past the bad write and then crash somewhere else because you overwrote random memory. Sometimes this will happen only under some seemingly condition.
 
Old 04-22-2004, 08:17 PM   #8
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16
Oh, if you're looking for things like that, Valgrind is the best thing I've come across. It's awesome.

Arvind
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
strange segmentation fault alltime Programming 4 11-10-2005 02:49 AM
Segmentation Fault ceenu99 Linux - Software 0 07-20-2005 05:42 AM
Segmentation fault compjinx Linux - Newbie 4 11-09-2003 04:51 PM
What is segmentation fault? Tommi Linux - General 11 05-06-2003 12:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration