博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GDB中打印pthread_internal_t的方法
阅读量:5937 次
发布时间:2019-06-19

本文共 4721 字,大约阅读时间需要 15 分钟。

每个进程所有pthread_internal_t结构是用g_thread_list链起来的。因此可以通过这个静态变量来查找想要的pthread_internal_t,如:

(gdb) p  g_thread_list$87 = (pthread_internal_t *) 0x7f6a51a450(gdb) p *g_thread_list$88 = {  next = 0x7f69bc6450,   prev = 0x0,   tid = 31561,   cached_pid_ = 1448,   attr = {    flags = 1,     stack_base = 0x7f6a41e000,     stack_size = 1033296,     guard_size = 4096,     sched_policy = 0,     sched_priority = 0,     __reserved = " REf\177\000\000\000\020\020\253k\177\000\000"  },   join_state = THREAD_DETACHED,   cleanup_stack = 0x0,   start_routine = 0x7f97147cd0 
, start_routine_arg = 0x7f66455260, return_value = 0x0, alternate_signal_stack = 0x0, startup_handshake_lock = { state = Lock::Unlocked, process_shared = false }, mmap_size = 1036288, thread_local_dtors = 0x0, tls = {0x7f6a51a4e8, 0x7f6a51a450, 0x0, 0x0, 0x0, 0x2212c0df7ebda00b, 0x0, 0x0, 0x0}, key_data = {
{ seq = 0, data = 0x0 }
}, dlerror_buffer = '\000'
}
(gdb) p *(pthread_internal_t *)0x7f69bc6450$91 = {  next = 0x7f6b695450,   prev = 0x7f6a51a450,   tid = 30974,   cached_pid_ = 1448,   attr = {    flags = 1,     stack_base = 0x7f69aca000,     stack_size = 1033296,     guard_size = 4096,     sched_policy = 0,     sched_priority = 0,     __reserved = "\v\240\275~\337\300\022\"\310\362O\222\177\000\000"  },   join_state = THREAD_DETACHED,   cleanup_stack = 0x0,   start_routine = 0x7f943ca7b4 <__timer_thread_start(void*)>,   start_routine_arg = 0x7f75b694f0,   return_value = 0x0,   alternate_signal_stack = 0x7f6e6c1000,   startup_handshake_lock = {    state = Lock::LockedWithoutWaiter,     process_shared = false  },   mmap_size = 1036288,   thread_local_dtors = 0x0,   tls = {0x7f69bc64e8, 0x7f69bc6450, 0x0, 0x0, 0x0, 0x2212c0df7ebda00b, 0x0, 0x0, 0x0},   key_data = {
{ seq = 0, data = 0x0 }
}, dlerror_buffer = '\000'
}

pthread_internal_t中有很多有用的数据可供我们分析和调试问题。

如果需要通过tid或者栈指针获取对应的pthread_internal_t,可以用以下脚本实现:

define print_thread_by_tid    set $tid = $arg0    set $pThread = g_thread_list    while $pThread != 0          if $pThread->tid == $tid             p $pThread             p *$pThread             loop_break         end          set $pThread = $pThread->next    endenddefine print_thread_by_sp    set $cursp = $arg0    set $pThread = g_thread_list        while $pThread != 0       if $pThread->attr.stack_base <= $cursp && $pThread->attr.stack_base + $pThread->attr.stack_size >= $cursp           p $pThread           p *$pThread           loop_break       end        set $pThread = $pThread->next    endend

如果要找当前线程的pthread_internal_t,则可以利用当前的sp,如:

define print_current_thread    print_thread_by_sp $spend

运行结果:

(gdb) print_current_thread $92 = (pthread_internal_t *) 0x7f6b466450$93 = {  next = 0x7f6987a450,   prev = 0x7f6ad59450,   tid = 2047,   cached_pid_ = 1448,   attr = {    flags = 1,     stack_base = 0x7f6b36a000,     stack_size = 1033296,     guard_size = 4096,     sched_policy = 0,     sched_priority = 0,     __reserved = "\200\025\324u\177\000\000\000@\373\212\311\177\000\000"  },   join_state = THREAD_DETACHED,   cleanup_stack = 0x0,   start_routine = 0x7f97147cd0 
, start_routine_arg = 0x7f75d415a0, return_value = 0x0, alternate_signal_stack = 0x7f721be000, startup_handshake_lock = { state = Lock::LockedWithoutWaiter, process_shared = false }, mmap_size = 1036288, thread_local_dtors = 0x0, tls = {0x7f6b4664e8, 0x7f6b466450, 0x0, 0x7f954ad7f0
, 0x0, 0x2212c0df7ebda00b, 0x0, 0x7f76239200, 0x0}, key_data = {
{ seq = 1, data = 0x7f75d40080 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 1, data = 0x7f86abe180 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 0, data = 0x0 }, { seq = 1, data = 0x7f76018010 }, { seq = 1, data = 0x7f75d42fa0 }, { seq = 1, data = 0x7f75d9dc00 }, { seq = 0, data = 0x0 }, { seq = 1, data = 0x7f67be29a0 }, { seq = 1, data = 0x7f67917c50 }, { seq = 0, data = 0x0 }
}, dlerror_buffer = '\000'
}

 

转载于:https://www.cnblogs.com/YYPapa/p/6902857.html

你可能感兴趣的文章
[转载] 七龙珠第一部——第004话 掳人的妖怪——乌龙
查看>>
【leetcode】75.Sort Colors
查看>>
Xcode常用快捷键
查看>>
如何快速有效的投诉上海移动
查看>>
python3爬虫-下载网易云音乐,评论
查看>>
【文文殿下】[BZOJ4008] [HNOI2015] 亚瑟王
查看>>
31.图片放大镜插件——jqzoom
查看>>
安装MySQL时,出现的1067问题详解
查看>>
【Gamma】Scrum Meeting 6
查看>>
WindowsForm 增 删 查 改
查看>>
为页内的tab添加的iframe添加加载动画过渡效果
查看>>
P1067 多项式输出 (模拟)
查看>>
javap使用
查看>>
php gettext
查看>>
Linux下通过脚本自动备份Oracle数据库并删除指定天数前的备份
查看>>
练习方法--刻意练习
查看>>
多进程
查看>>
Java方式 MySQL数据库连接
查看>>
MATLAB2012 licence失效解决方法
查看>>
Android ListView初始化将实例化多少个item
查看>>