I am trying to add the ability to generate a stack trace from a core dump on a Mac automatically when one of our tests fails.
I was able to do this quite easily on linux using
gdb --batch --quiet -ex "thread apply all bt" -ex "quit" <binary> <core file> 2> /dev/null
But I am having problems with the same as on mac (OSX 10.8) with lldb. For starters, the lldb version I'm using is lldb-310.2.37.
My initial approach was to use a parameter -sand pass the script file as follows:
target create -c <core file> <binary>
thread backtrace all
quit
Initially, I had some problems that, in my opinion, were caused by the absence of a new line at the end of the script file, due to which lldb did not exit, but after that it was fixed: I get the following: Executing commands in '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
Aborting after_file command execution, command file: 'lldbSource' failed.
, lldb, "thread backtrace all" .
, № 2 python script API- python ( , , , - ).
script:
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 script.