I have a small C++ program my-program. When I run my-program directly
./my-program arg1
everything is ok. I don't get any errors. Besides I have my-script.sh:
#!/bin/sh
my-program $1
When I run this script directly:
./my-script.sh arg1
I don't get any errors.
The problem appears when my-script.sh is run from other linux processes. In this case I sometimes(!) get Segmentation fault error. What I did: I added the -g switch to c++ compiler and edited my-script.sh, so it became:
#!/bin/sh
gdb -batch -x gdb-script --args my-program $1
In gdb-script I wrote:
run
However, I still can't find the line which causes Segmentation fault error. How can I make dgb print the stacktrace to some file after error? Or maybe there are ways to get the place in program which causes this error?
bt(orbacktraceorwhere) to your "gdb-script" file? - if you have many threads, you may want to do more to print all stacks for all threads - I'm not sure what that command is, but I know it can be done.