LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using gdb to detect segmentation fault in sh? (https://www.linuxquestions.org/questions/linux-newbie-8/using-gdb-to-detect-segmentation-fault-in-sh-4175531248/)

larryburns 01-16-2015 03:10 PM

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?

smallpond 01-16-2015 03:29 PM

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.

larryburns 01-16-2015 04:09 PM

Quote:

Originally Posted by smallpond (Post 5302071)
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 ...


smallpond 01-16-2015 05:15 PM

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.

larryburns 01-16-2015 05:30 PM

Quote:

Originally Posted by smallpond (Post 5302117)
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

smallpond 01-17-2015 07:49 AM

You have an interesting experimental approach to finding out what commands do. Boring people just use the man pages.

btmiller 01-18-2015 01:00 PM

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.


All times are GMT -5. The time now is 05:48 PM.