多进程多线程GDB调试
一、线程调试指南:
1. gdb attach pid 挂载到调试进程
2. gdb$ set scheduler-locking on 只执行当前选定线程的开关
3. gdb$ info threads 显示当前进程中的线程
==============out put example=========================
12 Thread 0x41f16940 (LWP 6922) 0x00000036e74cced2 in select () from /lib64/libc.so.6
11 Thread 0x42917940 (LWP 6923) 0x00000036e74cced2 in select () from /lib64/libc.so.6
10 Thread 0x43318940 (LWP 6924) 0x00000036e74cced2 in select () from /lib64/libc.so.6
9 Thread 0x43d19940 (LWP 6925) 0x00000036e74cced2 in select () from /lib64/libc.so.6
8 Thread 0x4471a940 (LWP 6926) 0x00000036e74cced2 in select () from /lib64/libc.so.6
7 Thread 0x4511b940 (LWP 6927) 0x00000036e74cced2 in select () from /lib64/libc.so.6
6 Thread 0x40a03940 (LWP 6928) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
5 Thread 0x40b04940 (LWP 6929) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
4 Thread 0x40c05940 (LWP 6930) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
3 Thread 0x4521c940 (LWP 6931) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
2 Thread 0x45c1d940 (LWP 6932) 0x00000036e74cced2 in select () from /lib64/libc.so.6
1 Thread 0x2b277c3bba40 (LWP 6913) 0x00000036e74cced2 in select () from /lib64/libc.so.6
==============out put example=========================
说明 进程中的线程安装 1,2,3 ..编号
4. gdb$ thread 1 调试1线程
gdb$ info threads
==============out put example=========================
12 Thread 0x41f16940 (LWP 6922) 0x00000036e74cced2 in select () from /lib64/libc.so.6
11 Thread 0x42917940 (LWP 6923) 0x00000036e74cced2 in select () from /lib64/libc.so.6
10 Thread 0x43318940 (LWP 6924) 0x00000036e74cced2 in select () from /lib64/libc.so.6
9 Thread 0x43d19940 (LWP 6925) 0x00000036e74cced2 in select () from /lib64/libc.so.6
8 Thread 0x4471a940 (LWP 6926) 0x00000036e74cced2 in select () from /lib64/libc.so.6
7 Thread 0x4511b940 (LWP 6927) 0x00000036e74cced2 in select () from /lib64/libc.so.6
6 Thread 0x40a03940 (LWP 6928) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
5 Thread 0x40b04940 (LWP 6929) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
4 Thread 0x40c05940 (LWP 6930) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
3 Thread 0x4521c940 (LWP 6931) 0x00000036e7c0ab99 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
2 Thread 0x45c1d940 (LWP 6932) 0x00000036e74cced2 in select () from /lib64/libc.so.6
*1 Thread 0x2b277c3bba40 (LWP 6913) 0x00000036e74cced2 in select () from /lib64/libc.so.6
==============out put example=========================
*代表选定线程
5. gdb$ b function_name 设置断点端到的函数
6. 通过执行
gdb$ thread id 调试id线程
执行
gdb$ continue
如果能够到达断点说明,函数在该函数中执行,运气很好,直接开始调试
否则,CTRL+C 跳出该线程
调试下一个线程,直到找到调试线程,开始调试。
二、进程调试指南:
程序又多个进程组成,在一个父进程中创建子进程,调试方法如下:
gdb$ set follow-fork-mode [child|parent] 设置fork后,跟踪进程
后续可以再进行多线程调试。
以上功能是在gdb6.4的功能
gdb6.6中增加了
gdb$ set detach-on-fork [on|off]
on: 断开 follow-fork-mode 指定进程
off:gdb控制调试父子进程,follow-fork-mode指定进程被调试,另外一个被挂起。
阅读(8579) | 评论(0) | 转发(1) |