1

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?

user4352158
  • 731
  • 4
  • 13
  • 24
  • 2
    Use gdb on the project not the sh file. – tom Jan 16 '15 at 21:12
  • When I then use the command prompt to go into directory `/user/project/Build/bin` and then type `gdb project` and then `run`, I see `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 ...` – user4352158 Jan 17 '15 at 00:16

1 Answers1

3

First of all you have to build your project with debug symbols support. For gcc this is accomplished using the -g option. Then your run the gdb with the executable of your program. For example:

gdb ./a.out

The gdb command promt appears. In order to start your program, you should execute the command run. If your program needs some command line arguments, you specify them too. E.g run -d firstarg -l secondarg etc.

When your program receives a segmentation fault, just execute to the gdb prompt the command bt full

This will give you the backtrace of your program, the variable states and the source code line where the segfault received.

Manos
  • 2,136
  • 17
  • 28
  • When I then use the command prompt to go into directory `/user/project/Build/bin` and then type `gdb project` and then `run`, I see `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 ...` – user4352158 Jan 17 '15 at 00:16
  • The GDB informs you that you might want to install the additional debuginfo packages for libc and libICE. Often this is not mandatory, but you can install them if you want. The exit code, is the number that main returns. – Manos Jan 17 '15 at 00:39
  • so if I don't want to install libc and libICE, how can I resolve this problem? – user4352158 Jan 17 '15 at 19:39
  • Try to reproduce the segfault when running your program from the `gdb`. Pass the same parameters, do the same actions e.t.c. The `Program exited with code 01.` that you get indicates that the program exits successfully. If a segfault occurs use the commands of my answer. However, there is a rare situation that in the `gdb` the segfault can not be reproduced. Take a look at this very interesting discussion http://stackoverflow.com/questions/4628521/segfault-only-when-not-using-debugger – Manos Jan 17 '15 at 22:14
  • The program does not need some command line arguments. When I enter `bt full`, the output is `no stack`. Also, I forgot to mention that the specific seg fault error I'm getting is `PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation ... ` – user4352158 Jan 17 '15 at 23:11
  • Yeah, this is a segmentation fault. But as I can guess, your project has a signal handler for the SEGV signal raised from segmentation faults. That why `gdb` thinks that your program seems to exit manually. Try to post some code, in order to get more specific help tips. – Manos Jan 17 '15 at 23:44