代码改变世界

如何使用gdb观察core的时候线程表现

2023-07-14 20:29  轩脉刃  阅读(127)  评论(1编辑  收藏  举报

如何使用gdb观察core的时候线程表现

> info thread

显示内容如下:

(gdb) info thread
  Id   Target Id         Frame 
  70   Thread 0x7fe31f7fe700 (LWP 1416944) 0x00007fe4102c6945 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  69   Thread 0x7fe31effd700 (LWP 1416945) 0x00007fe4102c6cf2 in pthread_cond_timedwait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  68   Thread 0x7fe348ff9700 (LWP 1416936) 0x00007fe4102c6945 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  67   Thread 0x7fe407f28700 (LWP 1415961) 0x00007fe40f4f8fd3 in epoll_wait () from /lib64/libc.so.6
  66   Thread 0x7fe3ee91f700 (LWP 1415970) 0x00007fe40f4f8fd3 in epoll_wait () from /lib64/libc.so.6
  65   Thread 0x7fe30effd700 (LWP 1416949) 0x00007fe4102c6945 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  64   Thread 0x7fe3c99bc700 (LWP 1415988) 0x00007fe40f4bf8ed in nanosleep () from /lib64/libc.so.6
  63   Thread 0x7fe30f7fe700 (LWP 1416948) 0x00007fe4102c6945 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  62   Thread 0x7fe30ffff700 (LWP 1416947) 0x00007fe4102c6cf2 in pthread_cond_timedwait@@GLIBC_2.3.2 ()
   from /home/demo/libpthread.so.0
  61   Thread 0x7fe36f7fe700 (LWP 1416917) 0x00007fe4102c3f57 in pthread_join ()
  ...

可以看到,这个进程启动了70个线程,gdb给每个线程进行了编号,比如线程号为 1416944 的编号为 70。

使用命令t [id]进入到线程中(这里的id就是上面看到的线程编号),再使用命令 bt 查看core的时候线程运行堆栈。

表现如下:

(gdb) t 1
[Switching to thread 1 (Thread 0x7fe30dffb700 (LWP 1417760))]
#0  0x00007fe40f4303d7 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007fe40f4303d7 in raise () from /lib64/libc.so.6
#1  0x00007fe40f431ac8 in abort () from /lib64/libc.so.6
#2  0x00007fe418238155 in __gnu_cxx::__verbose_terminate_handler () at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007fe418235f16 in __cxxabiv1::__terminate (handler=<optimized out>) at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x00007fe418235f61 in std::terminate () at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x00007fe418260e6e in std::execute_native_thread_routine (__p=0x7fe36449e590) at ../../../../../libstdc++-v3/src/c++11/thread.cc:91
#6  0x00007fe4102c2e25 in start_thread () from /home/demo/libpthread.so.0
#7  0x00007fe40f4f89fd in clone () from /lib64/libc.so.6