【发布时间】:2015-01-04 21:10:48
【问题描述】:
我正在尝试添加在我们的一项测试崩溃时自动从 mac 上的核心转储生成堆栈跟踪的功能。
我可以很容易地在 linux 上做到这一点
gdb --batch --quiet -ex "thread apply all bt" -ex "quit" <binary> <core file> 2> /dev/null
但是我在使用 lldb 的 mac (OSX 10.8) 上做同样的事情时遇到了一些麻烦。首先,我使用的 lldb 版本是 lldb-310.2.37。
我最初的方法是使用-s 选项并像这样传入一个脚本文件:
target create -c <core file> <binary>
thread backtrace all
quit
最初我遇到了一些麻烦,我认为这是由于在脚本文件末尾缺少换行符导致 lldb 无法退出,但在修复之后,我得到以下信息: 在 'lldbSource' 中执行命令。
(lldb) target create -c <core file> <binary>
Core file '<core file>' (x86_64) was loaded.
(lldb) thread backtrace all
error: Aborting reading of commands after command #1: 'thread backtrace all' failed with error: invalid thread
Aborting after_file command execution, command file: 'lldbSource' failed.
有趣的是,在那之后,我们仍在运行 lldb,手动发出“thread backtrace all”就可以了。
因此,方法 #2 是创建一个 python 脚本并使用他们的 python API(我在确定我描述的初始阻止程序是由于缺少换行符之前尝试了这个)。
我的脚本:
import lldb
debugger = lldb.SBDebugger.Create()
target = debugger.CreateTarget('<binary>')
if target:
process = target.LoadCore('<core file>')
if process:
print process.exit_description
for thread in process:
print 'Thread %s:' % str(thread.GetThreadID())
print '\n'.join(str(frame) for frame in thread)
我在使用这种方法时遇到的问题是 process.exit_description 正在返回 None(我尝试过的所有其他事情也是如此;LLDB 的 python API 文档几乎完全没用)。
我从该调用中寻找的输出类似于以下内容:
Process 0 stopped
* thread #1: tid = 0x0000, 0x00007fff8aca4670 libsystem_c.dylib`strlen + 16, stop reason = signal SIGSTOP
frame #0: 0x00007fff8aca4670 libsystem_c.dylib`strlen + 16
libsystem_c.dylib`strlen + 16:
-> 0x7fff8aca4670: pcmpeqb (%rdi), %xmm0
0x7fff8aca4674: andl $0xf, %ecx
0x7fff8aca4677: shll %cl, %eax
0x7fff8aca4679: pmovmskb %xmm0, %ecx
这是在加载核心文件时由 LLDB 自动输出的。我不一定需要程序集转储,但我至少需要线程、框架和原因。
我认为我使用的第一种方法,如果它可以工作,将是理想的,但任何一种方法对我来说都可以。不幸的是,我无法控制将要使用的 LLDB 版本,所以我不能只更新到最新版本,看看它是否是已修复的错误。
也欢迎使用其他方法来获得所需的输出。对于上下文,这将从 perl 脚本中调用。
【问题讨论】:
标签: crash automation lldb