GDB -- 多线程堆栈

1.死机后,输入:
   info threads ------- 查看所有thread信息
2. thread apply all bt
      显示所有的线程堆栈

示例:
(gdb) info threads           
  Id   Target Id         Frame
  3    Thread 0xb77f5b40 (LWP 12947) "dielock.elf" __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
  2    Thread 0xb6ff5b40 (LWP 12948) "dielock.elf" __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
* 1    Thread 0xb77f76c0 (LWP 12946) "dielock.elf" __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
(gdb) thread apply all bt

Thread 3 (Thread 0xb77f5b40 (LWP 12947)):
#0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
#1  0x00bb6b19 in _L_lock_770 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0x00bb6953 in __GI___pthread_mutex_lock (mutex=0x804a040) at pthread_mutex_lock.c:64
#3  0x080486d2 in lock_mux () at ./dielock.c:9
#4  0x00bb4a0d in start_thread (arg=0xb77f5b40) at pthread_create.c:311
#5  0x001e9e9e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:131

Thread 2 (Thread 0xb6ff5b40 (LWP 12948)):
#0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
#1  0x00bb6b19 in _L_lock_770 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0x00bb6953 in __GI___pthread_mutex_lock (mutex=0x804a040) at pthread_mutex_lock.c:64
#3  0x080486d2 in lock_mux () at ./dielock.c:9
#4  0x00bb4a0d in start_thread (arg=0xb6ff5b40) at pthread_create.c:311
#5  0x001e9e9e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:131

Thread 1 (Thread 0xb77f76c0 (LWP 12946)):
#0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S:146
#1  0x00bb6b19 in _L_lock_770 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0x00bb6953 in __GI___pthread_mutex_lock (mutex=0x804a040) at pthread_mutex_lock.c:64
#3  0x080486d2 in lock_mux () at ./dielock.c:9
#4  0x0804889a in main (argc=1, argv=0xbfd24504) at ./dielock.c:59
(gdb)



root@libz-Lenovo:/home/libz/project/gdb_test# gdb ./test_gdb.elf  -q

Reading symbols from /home/libz/project/gdb_test/test_gdb.elf...done.
(gdb) r
Starting program: /home/libz/project/gdb_test/test_gdb.elf
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
[New Thread 0xb7ffcb40 (LWP 11253)]
g_stPid = [-1207973056] i32Num = [0]
[New Thread 0xb7fdbb40 (LWP 11254)]
g_stPid = [-1208108224] i32Num = [1]
[New Thread 0xb7fbbb40 (LWP 11255)]
g_stPid = [-1208239296] i32Num = [2]
[New Thread 0xb7f9bb40 (LWP 11256)]
g_stPid = [-1208370368] i32Num = [3]
[New Thread 0xb7f7bb40 (LWP 11257)]
g_stPid = [-1208501440] i32Num = [4]
[New Thread 0xb7f5bb40 (LWP 11258)]
g_stPid = [-1208632512] i32Num = [5]
[New Thread 0xb7f3bb40 (LWP 11259)]
g_stPid = [-1208763584] i32Num = [6]
[New Thread 0xb7f1bb40 (LWP 11260)]
g_stPid = [-1208894656] i32Num = [7]
[New Thread 0xb7efbb40 (LWP 11261)]
g_stPid = [-1209025728] i32Num = [8]
[New Thread 0xb7edbb40 (LWP 11262)]
g_stPid = [-1209156800] i32Num = [9]
[New Thread 0xb7ebbb40 (LWP 11263)]
g_stPid = [-1209287872] i32Num = [10]
[New Thread 0xb7e9bb40 (LWP 11264)]
g_stPid = [-1209418944] i32Num = [11]
[New Thread 0xb7e7bb40 (LWP 11265)]
g_stPid = [-1209550016] i32Num = [12]
[New Thread 0xb7e5bb40 (LWP 11266)]
g_stPid = [-1209681088] i32Num = [13]
[New Thread 0xb7e3bb40 (LWP 11267)]
g_stPid = [-1209812160] i32Num = [14]
[New Thread 0xb7e1bb40 (LWP 11268)]
g_stPid = [-1209943232] i32Num = [15]
[New Thread 0xb7dfbb40 (LWP 11269)]
g_stPid = [-1210074304] i32Num = [16]
[New Thread 0xb7ddbb40 (LWP 11270)]
g_stPid = [-1210205376] i32Num = [17]
^C
Program received signal SIGINT, Interrupt.
0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
81      ../sysdeps/unix/syscall-template.S: No such file or directory.
        in ../sysdeps/unix/syscall-template.S
(gdb) q
A debugging session is active.

        Inferior 1 [process 11250] will be killed.

Quit anyway? (y or n) n
Not confirmed.
(gdb) info threads
  Id   Target Id         Frame
  19   Thread 0xb7ddbb40 (LWP 11270) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  18   Thread 0xb7dfbb40 (LWP 11269) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  17   Thread 0xb7e1bb40 (LWP 11268) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  16   Thread 0xb7e3bb40 (LWP 11267) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  15   Thread 0xb7e5bb40 (LWP 11266) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  14   Thread 0xb7e7bb40 (LWP 11265) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  13   Thread 0xb7e9bb40 (LWP 11264) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  12   Thread 0xb7ebbb40 (LWP 11263) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  11   Thread 0xb7edbb40 (LWP 11262) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  10   Thread 0xb7efbb40 (LWP 11261) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  9    Thread 0xb7f1bb40 (LWP 11260) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  8    Thread 0xb7f3bb40 (LWP 11259) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  7    Thread 0xb7f5bb40 (LWP 11258) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  6    Thread 0xb7f7bb40 (LWP 11257) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  5    Thread 0xb7f9bb40 (LWP 11256) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  4    Thread 0xb7fbbb40 (LWP 11255) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  3    Thread 0xb7fdbb40 (LWP 11254) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
  2    Thread 0xb7ffcb40 (LWP 11253) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
* 1    Thread 0xb7ffd6c0 (LWP 11250) "test_gdb.elf" 0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
(gdb) thread 18                                     ---------------------------------第18个线程
[Switching to thread 18 (Thread 0xb7dfbb40 (LWP 11269))]
#0  0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
81      in ../sysdeps/unix/syscall-template.S
(gdb) where                                     ---------------------------------第18个线程调用过程
#0  0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1  0x001f0844 in __sleep (seconds=2147483648) at ../sysdeps/unix/sysv/linux/sleep.c:137
#2  0x080489d4 in func () at ./gdb_test.c:40
#3  0x00138a0d in start_thread (arg=0xb7dfbb40) at pthread_create.c:311
#4  0x00225e9e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:131
(gdb) bt                                     ---------------------------------第18个线程调用过程
#0  0x001f0a0c in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1  0x001f0844 in __sleep (seconds=2147483648) at ../sysdeps/unix/sysv/linux/sleep.c:137
#2  0x080489d4 in func () at ./gdb_test.c:40
#3  0x00138a0d in start_thread (arg=0xb7dfbb40) at pthread_create.c:311
#4  0x00225e9e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:131
(gdb)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值