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()
Вы делаете работу в методе инициализации в приведенном выше примере (так что ваш питон может быть загружен только тогда, когда есть бегущий процесс, не так ли?), Но если вы определяете новую команду lldb в питоне , новый lldb (в течение последнего года или двух) будет проходить в 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.