LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-16-2015, 04:10 PM   #1
larryburns
LQ Newbie
 
Registered: Nov 2014
Posts: 19

Rep: Reputation: Disabled
Using gdb to detect segmentation fault in sh?


I am using scientific linux. In the directory user/project/Build, after I ran 'make' to compile and link all the cpp files,I had no problems. But then, when I went to directory user/run/run.sh, which runs the project binary in user/project/Build/bin/project, I get a segmentation fault error. In the directory user/run, I enter 'gdb' in the command prompt and get the message "*** No targets specified and no makefile found. Stop."

What am I supposed to do to detect the segmentation fault?
 
Old 01-16-2015, 04:29 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,667

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
Code:
gdb program core
Where program is probably /user/project/Build/bin/project and core is the core file generated when the program faulted. If you have core files disabled or limited in size, you may need to adjust ulimit settings to get a full core dump. Once in gdb, the 'bt' command will give you a stack trace to tell you the location of the crash. Post back in this thread of you need help deciphering it.
 
Old 01-16-2015, 05:09 PM   #3
larryburns
LQ Newbie
 
Registered: Nov 2014
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Code:
gdb program core
Where program is probably /user/project/Build/bin/project and core is the core file generated when the program faulted. If you have core files disabled or limited in size, you may need to adjust ulimit settings to get a full core dump. Once in gdb, the 'bt' command will give you a stack trace to tell you the location of the crash. Post back in this thread of you need help deciphering it.
I just entered
Code:
gdb /user/project/Build/bin/project core
and got the message
Code:
gdb /user/project/Build/core: No such file or directory.

When I then use the command prompt to go into directory
Code:
/user/project/Build/bin
and then type
Code:
gdb project
and then "run", I see

Code:
Thread debugging using libthread_db enabled.. Program exited with code 01.
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.4.x86_64 libICE-1.0.6-1.el6.x86_64 ...

Last edited by larryburns; 01-16-2015 at 06:18 PM.
 
Old 01-16-2015, 06:15 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,667

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
ulimit -c will tell you whether crashes will create core files. The core files will typically be named something like core.55909 where 55909 is the process ID. The core file will be located in the current working directory of the process that crashed, which may not be the directory that you are in.
 
Old 01-16-2015, 06:30 PM   #5
larryburns
LQ Newbie
 
Registered: Nov 2014
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
ulimit -c will tell you whether crashes will create core files. The core files will typically be named something like core.55909 where 55909 is the process ID. The core file will be located in the current working directory of the process that crashed, which may not be the directory that you are in.
When I then use the command prompt to go into directory

Code:
/user/project/Build/bin
and then type
Code:
ulimit -c
I just see the output "0". Same output if I go to the directory
Code:
/user/project/Build
 
Old 01-17-2015, 08:49 AM   #6
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,667

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
You have an interesting experimental approach to finding out what commands do. Boring people just use the man pages.
 
Old 01-18-2015, 02:00 PM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Try running:

Code:
ulimit -c unlimited
so that the program will generate core files when it segfaults. On modern distros they're usually named core.XXXX where XXXX is the process ID of the crashed process. Once you have that file, you can use the commands above. Note that you may need to compile your program with special debugging options to extract meaningful information from the core dump.
 
  


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
[SOLVED] Understanding Segmentation fault in Qt project through GDB TheIndependentAquarius Programming 1 02-02-2011 06:36 AM
Segmentation Fault and GDB McCoder Programming 1 07-23-2010 03:30 PM
gftp Segmentation fault need help with gdb j0hn-d0e Linux - Software 4 11-05-2009 03:14 AM
gdb segmentation fault i.you Linux - Software 1 04-11-2007 05:25 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM


All times are GMT -5. The time now is 11:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration