Use GDB to debug a C++ program called from a shell script

解决了我一个大问题!!!

http://stackoverflow.com/questions/5048112/use-gdb-to-debug-a-c-program-called-from-a-shell-script

 

There are two options that you can do:

1) invoke GDB directly within the shell script. This would imply that you don't have standard in and standard out redirected.

2) run the shell script and then attach the debugger to the already running c++ process like so: gdb progname 1234 where 1234 is the process ID of the running c++ process.

If you need to do things before the program starts running then option 1 would be the better choice, otherwise option 2 is the cleaner way.

if test -f $ASHA_HOME/bin/hasocket; then
    #exec $ASHA_HOME/bin/hasocket $PRODUCT_HOME/bin/$EXE $*
    echo "$PRODUCT_HOME/bin/$EXE $*"
    gdb "$PRODUCT_HOME/bin/$EXE"
else
    #exec $PRODUCT_HOME/bin/$EXE $*
    echo "$PRODUCT_HOME/bin/$EXE $*"
    gdb $PRODUCT_HOME/bin/$EXE
fi

 

posted @ 2016-12-06 10:52  johnsonshu  阅读(277)  评论(0编辑  收藏  举报