2017-01-03 74 views
0

我想用LLDB使用Python和我写我的Python脚本是这样的:如何使用lldb.frame.variables在Python脚本

import lldb 
import commands 
import optparse 
import shlex 

def __lldb_init_module(debugger, internal_dict): 
    list1=[] 
    for i in lldb.frame.variables: 
     list1.append(str(i.name)) 
    print list1 

我想现在就打印在框架中的变量。当我将其导入在LLDB,

(LLDB)命令脚本导入〜/ str.py

结果是空的。

但是,如果我先输入“脚本”并退出,Python脚本会根据需要输出正确的结果。

(LLDB)脚本

Python解释。要退出,请输入'quit()','exit()'或Ctrl-D。

退出

(LLDB)命令脚本进口〜/ str.py

[ 'A', 'B', 'C', 'd']

断点被设置在正确的地方,程序可以运行没有任何错误。 我想知道为什么,以及如何得到的结果我想要的东西,而不输入查询“脚本”第一

回答

0

lldb.framelldb.threadlldb.processlldb.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。