通过脚本桥启动交互式会话
Launch interactive session via script bridge
我正在尝试通过 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())
在我看来,无论我将 flag
传递给 target.Launch
(我在 those flags 中尝试过),都无法切换到交互式编辑行会话。我知道 python 绑定的主要目的是非交互式脚本,但我仍然很好奇这种情况是否可能成为可能。
SBDebugger 上有一个方法可以执行此操作 (RunCommandInterpreter)。这就是 Xcode 和类似的方法使 lldb 控制台 windows。但到目前为止,它仅在 C 中使用,并且 C++ -> Python 绑定此函数存在问题,因此当您尝试从 Python 调用它时,您会收到关于第 5 个参数的奇怪错误是错误的类型。参数是一个 int&
并且在运行时给出 SWIG(接口生成器)错误。
当然,您可以在启动后从 STDIN 开始读取,每次获得完整的行时将其传递给 "SBCommandInterpreter::HandleCommand"。但是让 RunCommandInterpreter 工作是更好的解决方案。
我正在尝试通过 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())
在我看来,无论我将 flag
传递给 target.Launch
(我在 those flags 中尝试过),都无法切换到交互式编辑行会话。我知道 python 绑定的主要目的是非交互式脚本,但我仍然很好奇这种情况是否可能成为可能。
SBDebugger 上有一个方法可以执行此操作 (RunCommandInterpreter)。这就是 Xcode 和类似的方法使 lldb 控制台 windows。但到目前为止,它仅在 C 中使用,并且 C++ -> Python 绑定此函数存在问题,因此当您尝试从 Python 调用它时,您会收到关于第 5 个参数的奇怪错误是错误的类型。参数是一个 int&
并且在运行时给出 SWIG(接口生成器)错误。
当然,您可以在启动后从 STDIN 开始读取,每次获得完整的行时将其传递给 "SBCommandInterpreter::HandleCommand"。但是让 RunCommandInterpreter 工作是更好的解决方案。