调试多线程记录

线程默认是所有线程并发执行,所以我不用执行thread apply all command

accept_request方法要accept有连接进来了,才创建线程,所以程序刚开始执行的时候,拿不到线程id。

那就直接break accept_request

然后连接上以后,果然停住了。然后info threadsd,看到线程id是24244,再开一个终端,执行pstree -p 24242

vvvvvv@vvvvvv-PC:/media/vvvvvv/Data/gameserver/Tinyhttpd$ pstree -p 24242
gdb(24242)───httpd(24244)───{httpd}(24283)

24244确实是新开的线程。

 

gdb httpd
GNU gdb (Ubuntu 9.0.50.20191019-0ubuntu1) 9.0.50.20191019-git
Copyright (C) 2019 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from httpd...
(gdb) break 111
Breakpoint 1 at 0x18c2: file httpd.c, line 111.
(gdb) r
Starting program: /media/tankweight/Data/gameserver/Tinyhttpd/httpd 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
httpd running on port 8556
[New Thread 0x7ffff7d96700 (LWP 24283)]
[Switching to Thread 0x7ffff7d96700 (LWP 24283)]

Thread 2 "httpd" hit Breakpoint 1, accept_request (arg=0x4) at httpd.c:111
111        sprintf(path, "htdocs%s", url);
(gdb) infor threads
Undefined command: "infor".  Try "help".
(gdb) info threads
  Id   Target Id                                 Frame 
  1    Thread 0x7ffff7d97740 (LWP 24244) "httpd" 0x00007ffff7f9f44f in __libc_accept (fd=3, addr=..., len=0x7fffffffcb2c)
    at ../sysdeps/unix/sysv/linux/accept.c:26
* 2    Thread 0x7ffff7d96700 (LWP 24283) "httpd" accept_request (arg=0x4) at httpd.c:111
(gdb) c
Continuing.
[New Thread 0x7ffff7595700 (LWP 24395)]

Thread 3 "httpd" received signal SIGPIPE, Broken pipe.
[Switching to Thread 0x7ffff7595700 (LWP 24395)]
__libc_send (flags=<optimized out>, len=24, buf=0x7ffff75941f0, fd=5) at ../sysdeps/unix/sysv/linux/send.c:28
28    ../sysdeps/unix/sysv/linux/send.c: 没有那个文件或目录.
(gdb) c
Continuing.
[Thread 0x7ffff7595700 (LWP 24395) exited]
[Thread 0x7ffff7d96700 (LWP 24283) exited]

Program terminated with signal SIGPIPE, Broken pipe.
The program no longer exists.
(gdb)

ps -al
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000 24242 24227  0  80   0 - 18306 poll_s pts/0    00:00:00 gdb
0 t  1000 24244 24242  0  80   0 -  2711 ptrace pts/0    00:00:00 httpd
4 R  1000 24306 24298  0  80   0 -  6621 -      pts/1    00:00:00 ps
vvvvvv@vvvvvv-PC:/media/vvvvvv/Data/gameserver/Tinyhttpd$ pstree -p 24242
gdb(24242)───httpd(24244)───{httpd}(24283)
vvvvvv@vvvvvv-PC:/media/vvvvvv/Data/gameserver/Tinyhttpd$ gdb attach 24244
GNU gdb (Ubuntu 9.0.50.20191019-0ubuntu1) 9.0.50.20191019-git
Copyright (C) 2019 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
attach: 没有那个文件或目录.
Attaching to process 24244
Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
warning: process 24244 is already traced by process 24242
ptrace: 不允许的操作.
/media/vvvvvv/Data/gameserver/Tinyhttpd/24244: 没有那个文件或目录.
(gdb)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值