[英]how to attach a child process in gdb?
My program spawns a child thread with execvp to run another program in xterm: 我的程序使用execvp产生一个子线程,以在xterm中运行另一个程序:
char *argv[] = {"xterm",
"-e",
"./anotherProgram",
0
};
execvp("xterm", argv);
I know anotherProgram is running but in gdb, "info thread" doesn't show it. 我知道另一个程序正在运行,但是在gdb中,“信息线程”没有显示它。 How can I attach the child thread and debug it?
如何附加子线程并进行调试? Thanks.
谢谢。
Maybe it's sufficient for you to just find the process id of the child using ps aux | grep anotherProgram
也许使用
ps aux | grep anotherProgram
找出孩子的进程ID就足够了ps aux | grep anotherProgram
ps aux | grep anotherProgram
and then attach to it using a new gdb instance like this? ps aux | grep anotherProgram
,然后使用这样的新gdb实例将其附加到它? gdb ./anotherProgram <pid>
If not, you could just patch the source code like this and recompile: 如果没有,您可以像这样修补源代码并重新编译:
char *argv[] = {"xterm",
"-e",
"gdb",
"./anotherProgram",
0
};
execvp("xterm", argv);
I don't know a cleaner way to do this. 我不知道更干净的方法可以做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.