查看多线程相关信息
如果以下环境变量采用默认的 OFF 值,则系统会完全禁止适当的调试列表,这意味着 dbx 命令将显示不出任何对象:
AIXTHREAD_MUTEX_DEBUG
AIXTHREAD_COND_DEBUG
AIXTHREAD_RWLOCK_DEBUG
可以使用
export AIXTHREAD_MUTEX_DEBUG=ON
打开 AIXTHREAD_MUTEX_DEBUG。
- 查看线程信息 (dbx) print $t1 // 打印 t1 线程的基本信息
(dbx) attribute
(dbx) condition
(dbx) mutex
(dbx) rwlock
(dbx) thread
例如:
(thread_id = 1, state_u = 4, priority = 60, policy = other, attributes = 0x20001078)
- 切换当前线程(默认当前线程为收到 core 触发信号所在线程)(dbx) thread current [tid]
例如(> 表明 core dump 时的当前线程):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| (dbx)thread
thread state-k wchan state-u k-tid mode held scope function
$t1 wait 0x31bbb558 running 10321 k no pro _ptrgl
$t2 wait 0x311fb958 running 6275 k no pro _ptrgl
>$t3 run running 6985 k no pro _p_nsleep
$t4 wait 0x31bbbb18 running 6571 k no pro _ptrgl
$t5 wait 0x311fb9d8 running 7999 k no pro _ptrgl
$t6 wait 0x31bf8f98 running 8257 k no pro _ptrgl
$t7 wait 0x311fba18 running 8515 k no pro _ptrgl
$t8 wait 0x311fb7d8 running 8773 k no pro _ptrgl
$t9 wait 0x311fbb18 running 9031 k no pro _ptrgl
$t10 wait 0x311fb898 running 9547 k no pro _ptrgl
$t11 wait 0x311fb818 running 9805 k no pro _ptrgl
$t12 wait 0x311fba58 running 10063 k no pro _ptrgl
$t13 wait 0x311fb8d8 running 10579 k no pro _ptrgl
(dbx) thread current 3
(dbx) where
_p_nsleep(??, ??) at 0xd005f740
raise.nsleep(??, ??) at 0xd022de3c
sleep(??) at 0xd0260344
helper(??) at 0x100005ac
(dbx) thread current 4
warning: Thread is in kernel mode, not all registers can be accessed.
(dbx) where
ptrgl._ptrgl() at 0xd020e470
raise.nsleep(??, ??) at 0xd022de3c
raise.nsleep(??, ??) at 0xd022de3c
sleep(??) at 0xd0260344
helper(??) at 0x100005ac
(dbx)
|
core dump 分析的局限性
不要期待能依赖 core dump 分析解决所有的问题,下面是一个简单的模拟缓冲区溢出的例子,在这个例子中由于缓冲区溢出覆盖了调用栈信息,从而完全丢失了定位依据:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| root@/tmp#>xlC test.C -g -o test2
root@/tmp#>
root@/tmp#>./test
input str!
012345678901234567890123456789
Segmentation fault(coredump)
root@/tmp#>dbx ./test2 core
Type 'help' for help.
[using memory image in core]
reading symbolic information ...
Segmentation fault in test2. at 0x34353634
0x34353634 (???) warning: Unable to access address 0x34353634 from core
(dbx) where
warning: Unable to access address 0x34353634 from core
warning: Unable to access address 0x34353634 from core
warning: Unable to access address 0x34353630 from core
warning: Unable to access address 0x34353630 from core
warning: Unable to access address 0x34353634 from core
warning: Unable to access address 0x34353634 from core
warning: Unable to access address 0x34353630 from core
warning: Unable to access address 0x34353630 from core
warning: Unable to access address 0x34353634 from core
warning: Unable to access address 0x36373841 from core
test2.() at 0x34353634
warning: Unable to access address 0x36373839 from core
warning: Unable to access address 0x36373839 from core
(dbx)
|
|