python - LLDB Python/C++ 绑定(bind) : Async Step instructions

标签 python lldb

我正在尝试单步执行一个线程。这在我使用 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 来等待事情发生,而是使用 lldb 提供的 WaitForEvent API。如何执行此操作的示例位于:

https://github.com/llvm/llvm-project/blob/main/lldb/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) : Async Step instructions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412504/

相关文章:

python - 将两个列表添加到字典中并允许合并具有相似标题的值

xcode - 查看 LLDB 中的数组 : equivalent of GDB's '@' operator in Xcode 4. 1

ios - 在 Swift 中为 DebugPrintable 实现 debugDescription

c++ - 使用 Makefile 构建时在 Xcode 中忽略的断点

python - Scipy最小二乘: "func() missing n required positional argument: ' n_ 1', ' n_ 2'..."

python - 如何删除文本列中的微小变化

python - 更新从其他函数创建的paintEvent对象的颜色

python - 如何使脚本仅在半小时内每小时激活一次?

ios - 如何覆盖为 lldb po 命令打印的内容,以获得快速枚举?

ios - LLDB Python 访问 iOS 变量?