(配置遵循叉模式小孩)后叉gdb调试子进程 [英] gdb debugging child process after fork (follow-fork-mode child configured)

查看:164
本文介绍了(配置遵循叉模式小孩)后叉gdb调试子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,它的父叉子来处理某些任务。我在那里我已经配置了GDB遵循叉型孩子,但fork之后,达到一个断点后,它会发送SIGTRAP但孩子莫名其妙地终止和发送SIGCHLD给父的问题。

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 fork, after reaching a breakpoint, it sends a SIGTRAP but the child somehow terminates and send SIGCHLD to the parent.

我已经配置了信号(SIGTRAP,SIG_IGN)叉之前,所以我的理解是,孩子要继承和忽略SIGTRAP到达断点,但没有发生的时候。

I've configured signal(SIGTRAP, SIG_IGN) before fork so my understanding is that the child should inherit and ignore SIGTRAP when the breakpoint is reached but it's not happening.

请帮我明白这一点,如果我不正确。

Please help me to understand this if I'm incorrect.

如何才能成功地调试子进程?

How can I successfully debug the child process?

推荐答案

子进程继承父信号处理程序,而不是挂起信号。
分叉尝试在code其中分叉后的子进程执行的地方安装了SIGTRAP信号处理程序之后。如果你不处理SIGTRAP,默认的动作是孩子被终止。

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 the child is get terminated.

如果您要调试子进程,则必须使用跟踪叉模式
那么你必须使用设定的模式

If you want to Debug the Child process , you must use follow-fork-mode you must then set the mode using

set follow-fork-mode child

不过,现在只有孩子可以进行调试,并且父运行选中。

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

有调试子进程的另一种肮脏的方式。

There is Another dirty way of debugging the child process.

执行fork()的之后,把一个睡眠()调用在code里子执行,用PS工具得到孩子的PID,然后装上PID。

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>

现在,您可以调试子进程,像任何其他过程。
调试结束后,您可以使用分离PID

Now , you can debug the child process , like any other process. After debugging , you can detach the pid using

detach

这篇关于(配置遵循叉模式小孩)后叉gdb调试子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆