我正在尝试通过一个线程。当我使用debugger.SetAsync(False)时,此方法有效,但我想异步执行此操作。这是一个重现它的脚本。当设置debugger.SetAsync (False)而不是True时,它将逐步执行。我添加了time.sleep,以便有时间执行我的指令。我期望frame.pc中的下一条指令

import time
import sys
lldb_path = "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python"
sys.path = sys.path + [lldb_path]

import lldb
import os
exe = "./a.out"
debugger = lldb.SBDebugger.Create()

debugger.SetAsync (True) # change this to False, to make it work


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

if target:
    main_bp = target.BreakpointCreateByName ("main", target.GetExecutable().GetFilename())
    print main_bp

    launch_info = lldb.SBLaunchInfo(None)
    launch_info.SetExecutableFile (lldb.SBFileSpec(exe), True)
    error = lldb.SBError()
    process = target.Launch (launch_info, error)
    time.sleep(1)
    # Make sure the launch went ok
    if process:
        # Print some simple process info
        state = process.GetState ()
        print 'process state'
        print state
        thread = process.GetThreadAtIndex(0)
        frame = thread.GetFrameAtIndex(0)
        print 'stop loc'
        print hex(frame.pc)
        print 'thread stop reason'
        print thread.stop_reason

        print 'stepping'
        thread.StepInstruction(False)

        time.sleep(1)

        print 'process state'
        print process.GetState ()

        print 'thread stop reason'
        print thread.stop_reason
        frame = thread.GetFrameAtIndex(0)
        print 'stop loc'
        print hex(frame.pc)  # invalid output?


版本:lldb-340.4.110(随Xcode提供)
Python:Python 2.7.10
操作系统:Mac Yosemite

最佳答案

lldb API的“异步”版本使用基于事件的系统。您不能等待使用sleep发生的事情-而是使用WaitForEvent API的lldb提供的功能。有关如何执行此操作的示例,请参见:

http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py

该示例的开头有很多东西,展示了如何加载lldb模块以及如何进行参数解析。您要看的部分是循环:

        listener = debugger.GetListener()
        # sign up for process state change events
        stop_idx = 0
        done = False
        while not done:
            event = lldb.SBEvent()
            if listener.WaitForEvent (options.event_timeout, event):


及以下。

关于python - LLDB Python/C++绑定(bind):异步步骤说明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33412504/

10-12 17:57