线程默认是所有线程并发执行,所以我不用执行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)