中文快速入门:

http://coolshell.cn/articles/3643.html (关于多线程的部署说的并不太对)

进阶:

多进程相关概念:

inferiors 是什么?

  http://moss.cs.iit.edu/cs351/gdb-inferiors.html

多线程怎么调试:

  分 all-stop 和 non-stop 两个模式。

  all-stop 模式下,一个断点。所以线程全部终止运行。

  使用 set non-stop on命令可以进入non-stop模式。其他线程不会受到一个线程停止的影响。

例如:non-stop模式下设置了一个中断: 其他线程正常运行。

(gdb) info thread
Id Target Id Frame
Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" (running)
* Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" (running)
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" (running)
Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" (running)
(gdb)

例如:all-stop模式下,scheduler-locking off 时:一个线程中断,所有线程都中断

Breakpoint , lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
(gdb) info thread
Id Target Id Frame
* Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.
Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
(gdb) show non-stop
Controlling the inferior in non-stop mode is off.
(gdb) show scheduler-locking
Mode for locking scheduler during execution is "off".
(gdb)
(gdb) c
Continuing.
[Switching to Thread 0x7fffb4dfd700 (LWP 10107)] Breakpoint 6, lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07.1/examples/l3fwd/l3fwd_lpm.c:177
177                             nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
(gdb) info thread            
 Id   Target Id         Frame  
 5    Thread 0x7fffb45fc700 (LWP 10108) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07.1/examples/l3fwd/l3fwd_lpm.c:177
* 4    Thread 0x7fffb4dfd700 (LWP 10107) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07.1/examples/l3fwd/l3fwd_lpm.c:177
 3    Thread 0x7fffb55fe700 (LWP 10106) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07.1/examples/l3fwd/l3fwd_lpm.c:177
 2    Thread 0x7fffb5dff700 (LWP 10105) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.6
 1    Thread 0x7ffff7fef8c0 (LWP 10104) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07.1/examples/l3fwd/l3fwd_lpm.c:177
(gdb) c
Continuing.

scheduler-locking 等于 on时。线程的调试,单步执行。其他线程都不运行改变其当前执行位置。

(gdb) thread
[Switching to thread (Thread 0x7ffff7fef8c0 (LWP ))]
# lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
(gdb) info thread
Id Target Id Frame
Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.
* Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
(gdb) n
if (nb_rx == )
(gdb) n
continue;
(gdb) n
for (i = ; i < qconf->n_rx_queue; ++i) {
(gdb) info thread
Id Target Id Frame
Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.
* Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
(gdb)

当 scheduler-locking 切换成 off,当进程执行一个next,其他进程就都执行了,并且被中断到其他线程里。承接上图代码:

如果每一个线程里都有中断,这种情况下,完全无法进行单步调试。

(gdb) set scheduler-locking off
(gdb) info thread
Id Target Id Frame
Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.
* Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
(gdb) n
[Switching to Thread 0x7fffb4dfd700 (LWP )] Breakpoint , lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
(gdb) info thread
Id Target Id Frame
Thread 0x7fffb45fc700 (LWP ) "lcore-slave-7" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
* Thread 0x7fffb4dfd700 (LWP ) "lcore-slave-6" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb55fe700 (LWP ) "lcore-slave-3" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
Thread 0x7fffb5dff700 (LWP ) "eal-intr-thread" 0x00007ffff71e62c3 in epoll_wait () from /lib64/libc.so.
Thread 0x7ffff7fef8c0 (LWP ) "l3fwd" lpm_main_loop (dummy=0x0) at /root/src/sdk/@dpdk/dpdk-stable-16.07./examples/l3fwd/l3fwd_lpm.c:
(gdb)

还有一个step模式。含义是:当用"step"命令调试线程时,其它线程不会执行,但是用其它命令(比如"next")调试线程时,其它线程也许会执行。

应该是还有一些特殊情况的,不过含义既如此!

  https://sourceware.org/gdb/current/onlinedocs/gdb/Thread-Stops.html#Thread-Stops

总结一下:

  0. set non-stop on 之前需要设置 set pagination off

  1. 对整个进程全局调试,即哪里有中断就断到哪里。断的时候,整个进程停止执行。

    此时,使用默认设置: non-step = off  scheduler-locking = off

  2. 需要专心调试一个线程,其他线程保持正常运行状态。

    使用 non-step = on

  3. 需要专心调试一个线程,其他线程保持停止状态,并且不影响当前线程。

    使用 non-stop = off  scheduler-locking = on

  4. 还没遇到我需要这个场景的时候

    使用 non-stop = off  scheduler-locking = step

一个真实的多线程调试例子:

1。 程序正常启动了 (在这和gdb还没有关系)

[root@dpdk build]# ./l3fwd -l2,,, -- -p3 --config "(0,0,2),(1,0,6)" --parse-ptype
EAL: Detected lcore(s)
EAL: Probing VFIO support...
EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles !
... ...

2. 启动gdb,并设一设,然后后台attach。

  TODO: 并不知道,attach出来的进程如何non-stop。且该进程也不支持 attach &

[skill][gdb] gdb 多线程调试的更多相关文章

  1. 利用GDB进行多线程调试

    一.多线程调试 多线程调试重要就是下面几个命令: info thread 查看当前进程的线程. thread <ID> 切换调试的线程为指定ID的线程. break file.c:100 ...

  2. gdb的多线程调试

    info threads 可以查看当前进程有哪些线程 thread ID 可以切换到线程ID bt 查看当前线程堆栈 set scheduler-locking on多线程调试过程中, 线程会来回切换 ...

  3. gdb进行多线程调试

    http://blog.csdn.net/xabc3000/article/details/6819867 http://www.cnblogs.com/xuxm2007/archive/2011/0 ...

  4. GDB 多线程调试:只停止断点的线程,其他线程任然执行; 或只运行某些线程 其他线程中断

    多线程调试之痛 调试器(如VS2008和老版GDB)往往只支持all-stop模式,调试多线程程序时,如果某个线程断在一个断点上,你的调试器会让整个程序freeze,直到你continue这个线程,程 ...

  5. 调试多线程 & 查死锁的bug & gcore命令 & gdb对多线程的调试 & gcore & pstack & 调试常用命令

    gdb thread apply all bt 如果你发现有那么几个栈停在 pthread_wait 或者类似调用上,大致就可以得出结论:就是它们几个儿女情长,耽误了整个进程. 注意gdb的版本要高于 ...

  6. gdb 多线程调试

    gdb 多线程调试 http://hi.baidu.com/hcq11/blog/item/9f5bfc6e696209d680cb4a25.html  http://hi.baidu.com/lit ...

  7. GDB多线程调试

    一.多线程调试1. 多线程调试,最重要的几个命令:info threads                        查看当前进程的线程.                              ...

  8. GDB常用调试命令以及多进程多线程调试

    http://blog.csdn.net/freeelinux/article/details/53700266 一:普通命令   1.list命令 list  linenum      显示程序第l ...

  9. 多线程调试必杀技 - GDB的non-stop模式

     作者:破砂锅  (转) 开源的GDB被广泛使用在Linux.OSX.Unix和各种嵌入式系统(例如手机),这次它又带给我们一个惊喜. 多线程调试之痛 调试器(如VS2008和老版GDB)往往只支持a ...

随机推荐

  1. PHP写的异步高并发服务器,基于libevent

    PHP写的异步高并发服务器,基于libevent 博客分类: PHP PHPFPSocketLinuxQQ  本文章于2013年11月修改. swoole已使用C重写作为PHP扩展来运行.项目地址:h ...

  2. Angularjs 双向绑定机制解析

    文章转自:http://www.2cto.com/kf/201408/327594.html AngularJs 的元素与模型双向绑定依赖于循环检测它们之间的值,这种做法叫做脏检测,这几天研究了一下其 ...

  3. 出现个Expression(str != NULL)

    CPrimerPlus的11章复习题10:编写个函数,其参数为一个字符串指针,返回一个指针,返回的指针指向字符串中第一个空格的位置(如果没有空格就返回空指针) #include <stdio.h ...

  4. 网络知识学习1---(基础知识:ISO/OSI七层模型和TCP/IP四层模型)

    以下的内容和之后的几篇博客只是比较初级的介绍,想要深入学习的话建议自己钻研<TCP/IP详解 卷1:协议> 1.ISO/OSI七层模型    下四层是为数据传输服务的,物理层是真正的传输数 ...

  5. mysql explain用法

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了,如: explai ...

  6. 测试Oracle 11gr2 RAC 非归档模式下,offline drop数据文件后的数据库的停止与启动测试全过程

    测试Oracle 11gr2 RAC 非归档模式下,offline drop数据文件后的数据库的停止与启动测试全过程 最近系统出现问题,由于数据库产生的日志量太大无法开启归档模式,导致offline的 ...

  7. 注解:【无连接表的】Hibernate双向1->N关联

    Person与Address关联:双向1->N,[无连接表的],推荐使用 #由N端控制关联关系 #对于指定了mappedBy属性的@OneToMany,@ManyToMany,@OneToOne ...

  8. 关于tarjan算法的理解

    理解要点如下 理解LOW[i]数组的迭代过程.. low[u]=min(dfn[v],dfn[u],low[v]); 理解这个..如果有环..那么后代就可以更新祖先 那么low[v]就有用了.. 那么 ...

  9. winform对话框控件、打印控件

    对话框控件: ColorDialog:颜色选择对话框,让用户自行选择一种颜色,使用方法类似FontDialog FontDialog:字体选择对话框,让用户自行选择一种字体(也可以选择字体颜色,需要在 ...

  10. 数字转IP地址函数

    --------------------------------------------------------------------- -- Author : htl258(Tony) -- Da ...