在python

时间:2018-01-17 21:30:31

标签: lldb

我正在学习在python中使用LLDB.py模块,并尝试运行我在http://lldb.llvm.org/python-reference上找到的以下示例。我已经将lldb.so添加到了PYTHONPATH。这是我得到的结果:

  

为' ./ a.out' 创建目标   的的a.out
   SBBreakpoint:id = 1,name =' main',module = a.out,locations = 1
   SBProcess:pid = 0,state = launch,threads = 0,executable = a.out

似乎程序没有开始,进程状态总是启动。是否有任何配置问题或任何遗漏代码?

import lldb
import os

def disassemble_instructions(insts):
    for i in insts:
        print i

# Set the path to the executable to debug
exe = "./a.out"

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

# When we step or continue, don't return from the function until the process 
# stops. Otherwise we would have to handle the process events ourselves which, while doable is
#a little tricky.  We do this by setting the async mode to false.
debugger.SetAsync (False)

# Create a target from a file and arch
print "Creating a target for '%s'" % exe

target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)

if target:
# If the target is valid set a breakpoint at main
main_bp = target.BreakpointCreateByName ("main", target.GetExecutable().GetFilename());

print main_bp

# Launch the process. Since we specified synchronous mode, we won't return
# from this function until we hit the breakpoint at main
process = target.LaunchSimple (["./story.txt"], None, os.getcwd())

# Make sure the launch went ok
if process:
    # Print some simple process info
    state = process.GetState ()
    print process
    if state == lldb.eStateStopped:
        # Get the first thread
        thread = process.GetThreadAtIndex (0)
        if thread:
            # Print some simple thread info
            print thread
            # Get the first frame
            frame = thread.GetFrameAtIndex (0)
            if frame:
                # Print some simple frame info
                print frame
                function = frame.GetFunction()
                # See if we have debug info (a function)
                if function:
                    # We do have a function, print some info for the function
                    print function
                    # Now get all instructions for this function and print them
                    insts = function.GetInstructions(target)
                    disassemble_instructions (insts)
                else:
                    # See if we have a symbol in the symbol table for where we stopped
                    symbol = frame.GetSymbol();
                    if symbol:
                        # We do have a symbol, print some info for the symbol
                        print symbol
}

1 个答案:

答案 0 :(得分:0)

我没有足够的声誉来发表评论,但想分享我的发现。

lldb上的email chain讨论了我认为相同的问题:

  

我们将异步模式设置为false,因此target.LaunchSimple()不应在进程停止或退出之前返回。请注意,在您的示例中,它以“状态=启动”返回,因此这就是失败的原因。由于某种原因,未遵循同步模式。

他们似乎发现它不适用于Ubuntu 16上的lldb版本> v3.9。结论如下:

  

我注意到apt创建了一些无效的符号链接,但是修复了它们   没有帮助。我有一种直觉,认为问题出在预建套件中   来自http://apt.llvm.org/,而不是lldb来源。   但是我们需要其他人使用Ubuntu 16.04进行确认。

很遗憾,我尚未找到解决此问题的方法。