通过脚本桥启动交互式会话



我正在尝试通过 SWIG 生成的lldb模块从 python 脚本启动交互式调试会话。要调试的程序只不过是一个空的main函数。这是我目前的尝试:

import lldb
import sys
import os
debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTargetWithFileAndArch("a.out", "")
# The breakpoint itself works fine:    
fileSpec = lldb.SBFileSpecList()
mainBp = target.BreakpointCreateByName("main", 4, fileSpec, fileSpec)
mainBp.SetAutoContinue(False)
# Use the current terminal for IO    
stdout = os.ttyname(sys.stdout.fileno())
stdin = os.ttyname(sys.stdin.fileno())
stderr = os.ttyname(sys.stderr.fileno())
flag = lldb.eLaunchFlagNone
target.Launch(target.GetDebugger().GetListener(), [], [], stdin, stdout,
    stderr, os.getcwd(), flag, False, lldb.SBError())

在我看来,无论我传递给target.Launch flag(我在这些标志中尝试过),都无法切换到交互式编辑行会话。我确实知道 python 绑定的主要目的是非交互式脚本,但我仍然很好奇这种情况是否可以实现。

SBDebugger 上有一个方法可以做到这一点(RunCommandInterpreter)。 这就是 Xcode 和类似产品制作 lldb 控制台窗口的方式。 但到目前为止,它只从 C 中使用,并且此函数的 C++ -> Python 绑定存在问题,因此当您尝试从 Python 调用它时,您会得到一个奇怪的错误,即第 5 个参数的类型错误。 该参数是一个int&,它会在运行时给出 SWIG(接口生成器)错误。

当然,你可以在启动后开始从STDIN读取,每次你得到一个完整的行时,把它传递给"SBCommandInterpreter::HandleCommand"。 但是让 RunCommandInterpreter 工作是更可取的解决方案。

最新更新