作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个 C linux 应用程序 (A),它在启动时生成另一个进程 (P)。当我想调试 P 时,我像往常一样启动 A,然后使用 ddd/gdb 连接到 P。
当我想调试 P 的入口点(main 的开始)时出现问题。如果我在将调试器连接到 P 时遵循通常的方法,已经太晚了。我找到的解决方案是在 P 的主体开始时插休眠眠,这样我就有时间连接 gdb,但这不是一个非常优雅的解决方案。
我也尝试过使用 asm("int $3")
但它似乎不起作用。
你知道我该如何解决这个问题吗? (最好不改变A或P的代码)
最佳答案
你应该使用这个选项:
set follow-fork-mode
mode
Where mode is one of parent
, child
or ask
.
To follow the parent (this is the default) use:
set follow-fork-mode parent
跟随 child :
set follow-fork-mode child
让调试器每次都询问您:
set follow-fork-mode ask
所以基本上你会开始将 gdb 连接到 A,然后设置 gdb 跟随 child ,然后当 A 产生 P 时,gdb 将连接到 P 并与 A 分离。
关于c - 如何在GDB中调试fork-exec进程的入口点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/377195/
我是一名优秀的程序员,十分优秀!