使用崩溃实用程序在堆栈上查找局部变量

pku*_*arn 3 linux crash crash-dumps

我正在使用崩溃实用工具来分析vmcore(linux)结果,但在提取函数中的局部变量值时遇到困难。谷歌搜索相同的说一个人可以使用“信息本地人”,但当我使用它时,它说找不到命令。

搜索了一段时间后,发现下面的链接说,这种支持存在于进行自动编译的崩溃购买中。 http://www.redhat.com/archives/crash-utility/2009-May/msg00003.html

在vmcore转储中是否有用于提取局部变量的指针?

小智 5

请查看这篇描述x86堆栈框架布局的文章:http : //eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/

如果要查找函数参数,请注意,参数1-6是通过寄存器(rdi,rsi,..)传递的,而参数7- ..是通过堆栈传递的。

因此,根据定义,很容易看到参数7- ..的值-只需转储堆栈上下文:crash> bt -f ...

 #6 [ffff88107fc23e08] delayed_work_timer_fn at ffffffff8108a060
    ffff88107fc23e10: ffff88107fc23e50 **ffffffff8107e329** <-- return address 
 #7 [ffff88107fc23e18] call_timer_fn at **ffffffff8107e329**
    ffff88107fc23e20: ffff88101dc6d660 ffff881020f44000 
    ffff88107fc23e30: ffff88101dc6d660 ffff88107fc23e90 
    ffff88107fc23e40: ffff881020f45020 ffffffff8108a030 
    ffff88107fc23e50: ffff88107fc23ed0 ffffffff8107e739 
Run Code Online (Sandbox Code Playgroud)

请参阅链接。参数7- ..将被压入返回地址下方的堆栈中(此处没有此类参数)。

对于通过寄存器传递的参数1-6,您必须分解调用函数的代码,并遵循它们如何获取值。大多数情况下,您会看到它们从另一个寄存器获取值。您尝试查找的是是否在某个时刻从堆栈中读取了该值。这是一个例子:

0xffffffff8107e723 <run_timer_softirq+307>:     sti    
0xffffffff8107e724 <run_timer_softirq+308>:     nopw   0x0(%rax,%rax,1)
0xffffffff8107e72a <run_timer_softirq+314>:     mov    -0x48(%rbp),%rdx <-- rdx = rbp[-0x48] <-- rdx is from the stack!!!
0xffffffff8107e72e <run_timer_softirq+318>:     mov    %r12,%rdi
0xffffffff8107e731 <run_timer_softirq+321>:     mov    %r15,%rsi
0xffffffff8107e734 <run_timer_softirq+324>:     callq  0xffffffff8107e2e0 <call_timer_fn>

static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
                          unsigned long data)
Run Code Online (Sandbox Code Playgroud)

所以'call_timer_fn'第三个参数(rdx)是我们在位置rbp [-0x48]处的'call_timer_fn'堆栈中拥有的...

这很棒...

如果不是这种情况,则必须继续进行调用跟踪和汇编(:-(),直到您首先知道寄存器为止:

#14 [ffff88107fc23fb0] apic_timer_interrupt at ffffffff81515e33
--- <IRQ stack> ---
#15 [ffff881020f75da8] apic_timer_interrupt at ffffffff81515e33
    [exception RIP: intel_idle+193]
    RIP: ffffffff812bce31  RSP: ffff881020f75e58  RFLAGS: 00000202
    RAX: 0000000000000000  RBX: ffff88107fc2e3c0  RCX: 0000000000000000
    RDX: 0000000000007cd0  RSI: 0000000000000000  RDI: 0000000001e78df8
    RBP: ffff881020f75ea8   R8: 0000000000004183   R9: 000000000000003b
    R10: 000000a89c12c7e8  R11: 0000000000000001  R12: ffffffff81515e2e
    R13: ffff88107fc2e500  R14: 0000000000000000  R15: ffff88107fc2e3c0
    ORIG_RAX: ffffffffffffff10  CS: 0010  SS: 0018
Run Code Online (Sandbox Code Playgroud)

有关局部函数变量,请参见链接。如果没有优化,它们将被推入堆栈。如果可以的话,我建议禁用优化。现在您应该能够从堆栈中获取它们。