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

前端 未结 6 1710
自闭症患者
自闭症患者 2020-12-24 13:18

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 si

6条回答
  •  清歌不尽
    2020-12-24 13:49

    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.

提交回复
热议问题