gdb 调试多线程程序 断点处不停止

bytxl 2014-09-02 06:03:11
系统中一个deamon程序,/lib下存在libpthread-2.6.1.so
现在要用gdb调试这个程序,上传libthread_db-1.0.so到/lib下,修改权限777
$ sudo ldconfig
重启该deamon,开始调试
$ gdb test `pidof test` -d ~/code
可以看到如下信息(部分省略),说明成功attach到该deamon,并且可以调试多线程:
GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
Attaching to program: /test, process 12813
......
Reading symbols from /lib/libpthread.so.0...done.
[Thread debugging using libthread_db enabled]
[New Thread 0xb610caf0 (LWP 12813)]
......

然后在程序中打上断点,c继续运行,在界面触发该断点所在功能,出现如下类似信息:

[Switching to Thread 0xb4f09b90 (LWP 12820)]

Breakpoint 1, login_handle (r=0xb4f0930c) at handle.c:235
235 char *psz_username = NULL;
(gdb)
Continuing.

没有在断点处停止,只是显示了一下断点的信息,然后就Continuing了(上面不是本人使用命令c继续运行的),请牛人指教原因
(另附:几周前还是可以正常调试的,昨天到今天,突然不能这么调试了。本人检查过代码,跟该deamon程序应该是一样的)
...全文
961 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bytxl 2014-09-18
  • 打赏
  • 举报
回复
多谢各位回复,刚才运气来了,被我弄好了,不敢藏私,分享如下: 我的错误调试步骤是这样的: 1、停止状态,打上断点或者查看一些信息 2、输入c命令 3、输入很多回车用以跟上边的信息分隔(错误步骤,这一步坚决不能要) 4、触发程序 上述第三步是错误的,因为什么都不输入,”回车“,在gdb中就是继续运行,那么下次断点来的时候,shell才会读取第三步中输入的回车,这就让程序继续运行了,在断点处没有停止。 综上,第三步多余,去掉就行。
bytxl 2014-09-18
  • 打赏
  • 举报
回复
引用 1 楼 micropentium6 的回复:
are u sure the daemon has the same code base as you indicated on the command line to gdb? did you do any optimization during compilation? did u try to set breakpoint on the function name instead of a line inside the function? is this function running in a child process?
又仔细调了一下 我确定代码跟程序完全一样; 并且代码编译加了-g选项,没有做优化; 在函数上加断点,效果还是一样; 代码不是运行在子进程中。 现在还是不能调试,谢谢回复。
mhpmii 2014-09-09
  • 打赏
  • 举报
回复
多进程 一直用的printf....... 
  • 打赏
  • 举报
回复
are u sure the daemon has the same code base as you indicated on the command line to gdb? did you do any optimization during compilation? did u try to set breakpoint on the function name instead of a line inside the function? is this function running in a child process?

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧