【问题标题】:How to make the command interpreter aware of the newly created target如何让命令解释器知道新创建的目标
【发布时间】:2020-01-12 16:09:30
【问题描述】:

我想将 LLDB 用作 Python 库,如此处https://lldb.llvm.org/use/python-reference.html#using-the-lldb-py-module-in-python 所述。

使用

创建目标后
debugger = lldb.SBDebugger.Create()
target = debugger.CreateTargetWithFileAndArch(path_to_executable, lldb.LLDB_ARCH_DEFAULT)

并使用

获取命令解释器
interpreter = debugger.GetCommandInterpreter()

我尝试用

开始目标
ret = llldb.SBCommandReturnObject()
interpreter.HandleCommand('/r', ret)

我收到error: invalid target, create a target using the 'target create' command。我还尝试使用debugger.SetSelectedTarget(target) 设置选定的目标,但它也不起作用。在命令处理程序中运行 file <path_to_target> 按预期工作。

有没有办法在 python 中创建一个目标并在解释器中针对它运行命令?

【问题讨论】:

    标签: python debugging lldb


    【解决方案1】:

    显然,debugger.CreateTargetWithFileAndArch 不会返回有效目标,您可以通过执行 bool(target) 来查看。使用

    target = debugger.CreateTargetWithFileAndArch(path_to_executable, lldb.LLDB_ARCH_DEFAULT)
    debugger.SetSelectedTarget(target)
    

    【讨论】:

    • 如果目标无效,那么debugger.SetSelectedTarget(target) 有什么帮助?
    【解决方案2】:

    显然,lldb.LLDB_ARCH_DEFAULT 在 MacOS 上由于某种原因无法工作。所以我用一个明确的名字代替了它:

    target = debugger.CreateTargetWithFileAndArch(exe, "x86_64-apple-macosx10.15.0")
    

    接着是:

    assert target
    

    这应该有助于避免意外空目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2021-08-13
      • 2011-07-03
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多