Debug fork() in eclipse cdt

ぐ巨炮叔叔 提交于 2019-12-05 01:36:44

Your problems are probably due to "detach-on-fork" being set to off. DSF sets this by default (it's also gdb's default).

1) Put a breakpoint onto lines with "execlp..." and "returnedpid =...". 2) In debug configuration enable "non-stop mode" and "automatically debug forked process". 3) Start debug session. You will hit a breakpoint either in child or parent. Now see debug view.

You will notice your binary shows two threads.

4) Click on one or the other (lines with main() in above image) to switch debug context.

It might be because the init process reaps the child before you go to wait. Try blocking sigchld as you go into fork and then unblock the signals after your forks/execs. Maybe that should give you some idea as to what is exactly happening.

Using sigprocmask should help you.

  1. In debug configuration window -> Debugger -> Check "Automatically debug forked processes"
  2. Open breakpoint window -> View menu -> Add Event Breakpoint C/C++ -> "fork called"
  3. Now once the event breakpoint occurred, press F6 -> you'll see new process in debug window
  4. Choose new process and press F6 - You are in the child
  5. Enjoy
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!