免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 64686 | 回复: 8

请问gdb调试运行中进程的attach和detach细节 [复制链接]

论坛徽章:
0
发表于 2008-02-03 09:54 |显示全部楼层
现在有一个多线程程序,运行时可能会有几个线程停止执行,表面看来似乎是在无限等待某条件变量的通知。但是通过程序打印显示已经有线程给他们发送条件变量通知了,也没有哪个线程还锁定着互斥量。

我用gdb attach这个进程去看,查看了某些全局变量后,再detach,然后就可以发现这几个线程开始运行了。

实在不知道为什么会这样。gdb的attach和detach操作应该不会对进程有什么特殊影响吧?

请问有谁知道gdb attach和detach进程时的具体操作细节吗?

时间紧,gdb的源代码也不是那么好看的。只好上这里来问了。这个问题困扰我几天了。

论坛徽章:
0
发表于 2008-02-03 11:52 |显示全部楼层
原帖由 kokobar 于 2008-2-3 09:54 发表
现在有一个多线程程序,运行时可能会有几个线程停止执行,表面看来似乎是在无限等待某条件变量的通知。但是通过程序打印显示已经有线程给他们发送条件变量通知了,也没有哪个线程还锁定着互斥量。

我用gdb a ...

http://shekel.jct.ac.il/cc-res/online-doc/gdb/gdb_23.html
Debugging an already-running process

attach process-id
This command attaches to a running process--one that was started outside GDB. (info files shows your active targets.) The command takes as argument a process ID. The usual way to find out the process-id of a Unix process is with the ps utility, or with the `jobs -l' shell command.
attach does not repeat if you press RET a second time after executing the command.

To use attach, your program must be running in an environment which supports processes; for example, attach does not work for programs on bare-board targets that lack an operating system. You must also have permission to send the process a signal.

When using attach, you should first use the file command to specify the program running in the process and load its symbol table. See section Commands to specify files.

The first thing GDB does after arranging to debug the specified process is to stop it. You can examine and modify an attached process with all the GDB commands that are ordinarily available when you start processes with run. You can insert breakpoints; you can step and continue; you can modify storage. If you would rather the process continue running, you may use the continue command after attaching GDB to the process.


detach
When you have finished debugging the attached process, you can use the detach command to release it from GDB control. Detaching the process continues its execution. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another process or start one with run. detach does not repeat if you press RET again after executing the command.
If you exit GDB or use the run command while you have an attached process, you kill that process. By default, GDB asks for confirmation if you try to do either of these things; you can control whether or not you need to confirm by using the set confirm command (see section Optional warnings and messages).

论坛徽章:
0
发表于 2008-02-04 09:56 |显示全部楼层
Thank you all the same , Bayweb.
But the explanation above just tells about how to use attach and detach, not including the detail operation inside attach and detach.

论坛徽章:
0
发表于 2012-05-02 14:24 |显示全部楼层
你好,在论坛上看到了你的这个帖子
http://bbs.chinaunix.net/thread-2081192-1-1.html
我现在也遇到了一模一样的问题,很棘手,不知道你现在找到原因了吗?解决了吗?

论坛徽章:
0
发表于 2012-05-03 12:24 |显示全部楼层
运行时可能会有几个线程停止执行,表面看来似乎是在无限等待某条件变量的通知。但是通过程序打印显示已经有线程给他们发送条件变量通知了,也没有哪个线程还锁定着互斥量

===========
按照你的描述,问题和gdb无关。还是程序本身有问题。

论坛徽章:
0
发表于 2012-05-04 19:49 |显示全部楼层
但是为什么attach 完了再detach程序又可以接着跑呢?难到gdb会自己发送什么信号给程序吗?

论坛徽章:
0
发表于 2012-05-06 16:19 |显示全部楼层
但是为什么attach 完了再detach程序又可以接着跑呢?难到gdb会自己发送什么信号给程序吗? 请问你是否知道gdb attach的细节?求指教~~回复 5# GFree_Wind


   

论坛徽章:
0
发表于 2012-09-29 10:53 |显示全部楼层
本帖最后由 herbert_he_wang 于 2012-09-29 10:53 编辑

当attach发生时产生了一条中断,所以所有挂起的部分都会收到中断,退出挂起,检查条件。估计你的程序条件满足了,缺乏的只是让程序退出挂起的动作。

论坛徽章:
0
发表于 2019-05-24 14:21 |显示全部楼层
回复 1# kokobar

请问你这个问题怎么解决的?我也遇到这个问题了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP