2017-01-03 4 views
0

에 lldb.frame.variables를 사용하는 방법을 파이썬으로 LLDB를 사용하려면 내가 이렇게 내 파이썬 스크립트를 작성 :파이썬 스크립트

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에서 가져올 때,

~/str.py

(lldb) 명령 스크립트 가져 오기

결과는 비어 있습니다.

그러나 "script"를 먼저 입력하고 종료하면 Python 스크립트가 원하는 결과를 출력합니다.

(lldb) 스크립트

파이썬 대화 형 인터프리터. 종료하려면 'quit()', 'exit()'또는 Ctrl-D를 입력하십시오.

을 중단 점 [ 'A', 'B', 'C', 'D']

str.py/

(lldb) 명령 스크립트 수입 하였다 ~ 종료 올바른 위치에 설정하면 프로그램이 오류없이 실행될 수 있습니다. 나는 왜, 어떻게 최초의 "스크립트"를 inputing하지 않고 내가 원하는 결과를 얻을 수 알고 싶어

답변

0

lldb.framelldb.thread는, lldb.process은, 대화 형 스크립트 인터프리터 lldb.target 바로 가기 독립형 파이썬 명령에 존재하지 않는 -이 주어진 시간에 이러한 객체 중 하나 이상일 수 있으며 우리는 스크립트가 어떤 객체를 사용하고 있는지에 대해 특정 스크립트를 원합니다.

SB API를 통해 동일한 "나에게 현재 선택된 항목"을 가져 오는 것과 동일한 기능이 있습니다. 예 : 당신은 위의 예에서 init 메소드에서 작업을하고있는

debugger.GetSelectedTarget() 
debugger.GetSelectedTarget().GetProcess() 
debugger.GetSelectedTarget().GetProcess().GetThread() 
debugger.GetSelectedTarget().GetProcess().GetThread().GetSelectedFrame() 

는 (그래서 파이썬은 바로?, 실행중인 프로세스에있을 때로드 할 수 있습니다)하지만 당신은 파이썬에서 새로운 lldb 명령을 정의하는 경우 , 새로운 lldb (지난 1 년 또는 2 년 이내) 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__) 

은 심지어 더 이상 SBExecutionContext를 통과하지 않는 lldb에 대한 코드를 포함하지 않을이 시점에서, 솔직히 말해서, 나는 예상 할 수있다 모두 새로운 lldb를 실행해야합니다.