本文介绍了如何从App1的app2的main()中触发gdb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供的app2由app1触发,其中有类似system(./ app2)的内容。 app1也做了很多准备工作,例如创建dirs,文件,配置等等,以便运行app2。



我怎样才能从其主要的第一行gdb app2 )?



我试过以下的方法无效。

  gdb app2 
b main
shell ./app1


解决方案 div>

有几种方法可以实现这一点:


  1. 如果 app1 不会关闭 stdin,stdout,stderr ,您可以修改 app1 来代替:`system (gdb ./app2)

  2. 您可以修改 app2 wait ,例如显示。然后运行 app1 ,并从另一个窗口使用 gdb -p $ child_pid
  3. 如果 app1 没有在 app2 之前分支任何子元素,则可以使用( gdb)设置follow-fork子并让GDB在 app1 分叉后自动开始调试 app2 它。


Provided app2 is triggered by app1 in which there is something like system("./app2"). app1 also does a lot of preparation such as creating dirs, files, configuration... for app2 running.

How can I gdb app2 from the first line of its main()?

What I tried as below doesn't work.

gdb app2
  b main
  shell ./app1
解决方案

There are a few ways to achieve this:

  1. If app1 doesn't close stdin, stdout, stderr, you could modify app1 to do this instead: `system("gdb ./app2")
  2. You could modify app2 to wait for debugger to be attached, as e.g. this answer shows. Then run app1, and use gdb -p $child_pid from another window.
  3. If app1 doesn't fork any children prior to app2, you could use (gdb) set follow-fork child and have GDB automatically start debugging app2 after app1 forks it.

这篇关于如何从App1的app2的main()中触发gdb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:34