的lldb.frame
,lldb.thread
,lldb.process
,lldb.target
快捷键在交互式脚本解释器不独立Python命令存在 - 存在在给定的时间可能比这些对象中的任何一个都多,我们希望脚本具体说明它正在使用哪一个。
有相同的做法是通过SB API让我当前选择的东西。例如
debugger.GetSelectedTarget()
debugger.GetSelectedTarget().GetProcess()
debugger.GetSelectedTarget().GetProcess().GetThread()
debugger.GetSelectedTarget().GetProcess().GetThread().GetSelectedFrame()
你在上面的例子中做的工作在你的init方法(以便你的Python只能当有一个正在运行的进程,对不对?装),但如果你在Python中定义一个新的命令LLDB ,新的lldb's(在过去一年或两年内)将通过一个SBExecutionContext
,它会给你当前选择的一切。例如
def disthis(debugger, command, *args):
"""Usage: disthis
Disables the breakpoint the currently selected thread is stopped at."""
target = lldb.SBQueue() # some random object that will be invalid
thread = lldb.SBQueue() # some random object that will be invalid
if len(args) == 2:
# Old lldb invocation style
result = args[0]
if debugger and debugger.GetSelectedTarget() and debugger.GetSelectedTarget().GetProcess():
target = debugger.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetSelectedThread()
elif len(args) == 3:
# New (2015 & later) lldb invocation style where we're given the execution context
exe_ctx = args[0]
result = args[1]
target = exe_ctx.GetTarget()
thread = exe_ctx.GetThread()
if thread.IsValid() != True:
print >>result, "error: process is not paused."
result.SetStatus (lldb.eReturnStatusFailed)
return
[...]
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f %s.disthis disthis' % __name__)
说实话,在这一点上我还不包括为LLDB未通过的SBExecutionContext
任何更多的代码,我可以期待每个人都要运行足够新的lldb's。