LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-06-2007, 12:43 PM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
Need Help Tracing a Segmentation Fault


I'm making a program that needs to be able to display a list of files. For the most part things are working. But every now and then I get a segmentation fault. I have tried tracing it by displaying messages before functions calls using cerr and the fault occurs before the functions are called. Are there any useful debugging tools for tracing a fault like this?
 
Old 12-06-2007, 01:00 PM   #2
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
gdb is a pretty easy way to go. Often just running your program through gdb will give you your enough info.

However, you may need to step through it to see which call is the problem. Compile your program with -g option and run it with:

gdb myapp

Where "myapp" is the name of your executable. Then, use b within gdb to set a breakpoint. If you want, you can just do: 'b main' to set a breakpoint in main.

Use 'n' and 'si' for "Next" and "Step Into" respectively. A good gdb command reference is here: http://www.st.ewi.tudelft.nl/~koen/S...db-refcard.pdf
 
Old 12-06-2007, 01:09 PM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
Or, you can use a gdb front end such as ddd to provide a GUI.

Also, valgrind is very useful in tracking those memory problems.

Last edited by SciYro; 12-06-2007 at 01:10 PM.
 
Old 12-06-2007, 01:27 PM   #4
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
Yep, good point. I've used ddd in the past and like it.
 
Old 12-06-2007, 03:27 PM   #5
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Try Valgrind. It's a great tool, or rather set of tools for debugging as well as profiling. Much better than gdb alone as it analyzes the allocation and freeing sequences automatically which means it does the dirty job for you and reports all anomalies. Extremely useful piece of software.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
segmentation fault! sharath patil Debian 5 04-22-2006 04:57 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
segmentation fault vibhory2j Programming 7 10-16-2005 07:06 AM
segmentation fault ice99 Linux - Software 1 08-19-2005 11:33 AM
Segmentation Fault OGreenOLeaf Slackware 7 01-03-2004 08:57 PM

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

All times are GMT -5. The time now is 05:43 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