Debugging child process after fork (follow-fork-mode child configured)

后端 未结 1 585
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 01:06

I\'m developing an application which the parent forks a child to handle certain tasks. I\'m having an issue where I\'ve configured gdb to follow-fork-mode child but after fo

相关标签:
1条回答
  • 2020-12-01 01:36

    The child process inherits signal handlers from the parent, but not the pending signal.

    After forking try installing the signal handler for SIGTRAP at a place in code where the child process executes after forking. If you don't handle SIGTRAP, the default action is that the child is terminated.

    If you want to debug the child process, you must use follow-fork-mode. You must set the mode using

    set follow-fork-mode child
    

    However, now only the child can be debugged, and the parent runs unchecked.

    There is an alternative way of debugging the child process.

    After fork() is executed, put a sleep() call in the code where the child executes, get the PID of the child using the ps utility, then attach the PID.

    attach <PID of child process>
    

    Now, you can debug the child process, like any other process.

    After debugging, you can detach the PID using

    detach
    
    0 讨论(0)
提交回复
热议问题