的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。