gdb usage

gdb usage

attach process

gdb attach $pid

查看进程内的所有线程

info thread

切换跟踪线程

thread $thread_id   #此thread_id为info thread结果行首的thread id

查看变量值

先bt查看backtrace,再f $n设置栈帧,再p *mutex打印变量值(这里的mutex为一个结构体指针)

(gdb) f 3
#3  __pthread_cond_wait (cond=0x10da6a0, mutex=0x10da688)
    at pthread_cond_wait.c:638
638     pthread_cond_wait.c: No such file or directory.
(gdb) p *mutex
$1 = {__data = {__lock = 0, __count = 0, __owner = 0, __kind = 2, 
    __nusers = 1, {__spins = 0, __list = {__next = 0x0}}}, 
  __size = '\000' <repeats 12 times>, "\002\000\000\000\001\000\000\000\000\000\000", __align = 0}
(gdb) 

查看attach的进程内的所有线程的backtrace

thread apply all bt

 

posted @ 2022-10-26 21:29  aspirs  阅读(17)  评论(0编辑  收藏  举报