I want to debug ac program with gdb which is invoked by shell script. In this shell script , there are lot of things done and many environment variables are set.
This shell script is invoked by boost::process::launch from a c++ program.
I can change c++ program, shell script, and the c program itself, but can't change the architecture of this flow.
Is there any way , so that i can use gdb to debug the program.
If there is no solution, is there a way to dump all environment settings before launching shell script, so that i can launch same script with these settings to debug it later. I will prefer a portable and long term solution.
Two easy options:
Attach gdb after the program has started with gdb -p <pid of process>
if it doesn't matter to stop it at a specific point.
Insert a raise(SIGSTOP);
in the C program where you want it to stop. Once the process is stopped, attach gdb as in 1
, set any breakpoints you need and then send the process a SIGCONT
signal ( kill -CONT <pid of process>
) to cause it to continue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.