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

cdebugginggdbshell

I have a extremely complicated shell script, within which it calls a C++ program I want to debug via GDB. It is extremely hard to separate this c++ program from the shell since it has a lot of branches and a lot of environmental variables setting.

Is there a way to invoke GDB on this shell script? Looks like gdb requires me to call on a C++ program directly.

Best Answer

In addition to options mentioned by @diverscuba23, you could do the following:

gdb --args bash <script>

(assuming it's a bash script. Else adapt accordingly)