我有这个 gdb 宏,用于在调试 Mono 运行时时打印有意义的堆栈跟踪。它迭代所有堆栈帧,确定该帧是 native 的还是托管的。如果它被管理,它会使用来自 mono_pmip() 的信息来打印该帧的正确描述。如果是native,它会调用gdb的“frame”来描述frame。
define mono_backtrace
select-frame 0
set $i = 0
while ($i < $arg0)
set $foo = mono_pmip ($pc)
if ($foo == 0x00)
frame
else
printf "#%d %p in %s\n", $i, $pc, $foo
end
up-silently
set $i = $i + 1
end
end
与此相关的两个问题:
如何删除 $arg0 参数,并让它循环遍历所有帧,直到到达堆栈顶部?
如何让“frame”(或替代方案)仅打印函数名称(如 bt 那样),而不是该函数中的实际源代码行?当前输出为:
#1 0x000c21f6 in mono_handle_exception (ctx=0xbfffe7f0, obj=0x64bf18, original_ip=0x65024a, test_only=0) at mini-exceptions.c:1504
1504 return mono_handle_exception_internal (ctx, obj, original_ip, test_only, NULL, NULL);
#2 0x00115b92 in mono_x86_throw_exception (regs=0xbfffe850, exc=0x64bf18, eip=6619722, rethrow=0) at exceptions-x86.c:438
438 mono_handle_exception (&ctx, exc, (gpointer)eip, FALSE);
而我希望输出与 bt 的功能相匹配:
#1 0x000c21f6 in mono_handle_exception (ctx=0xbfffe7f0, obj=0x64bf18, original_ip=0x65024a, test_only=0) at mini-exceptions.c:1504
#2 0x00115b92 in mono_x86_throw_exception (regs=0xbfffe850, exc=0x64bf18, eip=6619722, rethrow=0) at exceptions-x86.c:438
最佳答案
How can I remove the $arg0 argument, and have it loop trough all frames, until it reaches the top of the stack?
只需执行while (1)
即可。最终 up-silently
将失败,并且评估将停止。
How can I get "frame" (or an alternative) to only print the name of the function (like bt does), and not the actual line of sourcecode in that function?
在 GDB 7.3 中 frames got exposed to Python ,让您可以对它们进行更精细的编程控制。
关于mono - 改进GDB宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2880939/