[lldb-dev] Python interface for loading core file

Samuel Jacob samueldotj at gmail.com
Wed Feb 27 12:30:35 PST 2013


I couldnt find a way to load core files from python. Is there a way?

The attached patch solves my problem. I tried it only on Linux and a
elf-core.

Thanks
Samuel

Here is the test program
$cat ./test.py
#!/usr/bin/env python

import lldb
import sys, os

exe = sys.argv[1]
core = sys.argv[2]

# Create a new debugger instance
debugger = lldb.SBDebugger.Create()

# Create a target from a file and arch
print "Creating a target for '%s'" % exe
target = debugger.CreateTarget(exe)
if target:
    process = target.LoadCore(core)
    if process:
        state = process.GetState ()
        thread = process.GetThreadAtIndex (0)
        if thread:
            for i in range(thread.GetNumFrames()):
                frame = thread.GetFrameAtIndex (i)
                if frame:
                    print frame

And output

$./test.py ./test/a.out ./test/core
Creating a target for './test/a.out'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named embedded_interpreter
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
frame #0: 0x00000000004004c4 a.out`function4(arg=0) + 16 at test.c:4
frame #1: 0x00000000004004d7 a.out`function3 + 11 at test.c:8
frame #2: 0x00000000004004e7 a.out`function2(arg=4195559) + 11 at test.c:11
frame #3: 0x00000000004004f7 a.out`function1(arg1=0, arg2=140736328348032,
str=0x00000000004004e7) + 3 at test.c:15
frame #4: 0x0000000000400507 a.out`function1(arg1=0, arg2=140736328348048,
str=0x00000000004004f7) + 19 at test.c:15
frame #5: 0x00007fbcdfe6c76d libc.so.6`__libc_start_main + 237
frame #6: 0x00000000004003f9 a.out`_start + 41
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130227/1137b0c2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: core-python.diff
Type: application/octet-stream
Size: 2163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130227/1137b0c2/attachment.obj>


More information about the lldb-dev mailing list