Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
🐛 LLDB
🐛 LLDB

Using LLDB

Scripting LLDB

Developing LLDB

External Links

Back to top

Embedded Python Interpreter#

The embedded python interpreter can be accessed in a variety of ways fromwithin LLDB. The easiest way is to use the lldb command script with noarguments at the lldb command prompt:

(lldb)scriptPythonInteractiveInterpreter.Toexit,type'quit()','exit()'orCtrl-D.>>>2+35>>>hex(12345)'0x3039'>>>

This drops you into the embedded python interpreter. When running under thescript command, lldb sets some convenience variables that give you quick accessto the currently selected entities that characterize the program and debuggerstate. In each case, if there is no currently selected entity of theappropriate type, the variable’s IsValid method will return false. Thesevariables are:

Variable

Type

Equivalent

Description

lldb.debugger

lldb.SBDebugger

SBTarget.GetDebugger

Contains the debugger object whosescript command was invoked. Thelldb.SBDebugger object owns the command interpreter and all the targets in your debug session. There will always be a Debugger in the embedded interpreter.

lldb.target

lldb.SBTarget

SBDebugger.GetSelectedTargetSBProcess.GetTarget

Contains the currently selected target - for instance the one made with thefile or selected by thetargetselect<target-index> command. Thelldb.SBTarget manages one running process, and all the executable and debug files for the process.

lldb.process

lldb.SBProcess

SBTarget.GetProcessSBThread.GetProcess

Contains the process of the currently selected target. Thelldb.SBProcess object manages the threads and allows access to memory for the process.

lldb.thread

lldb.SBThread

SBProcess.GetSelectedThreadSBFrame.GetThread

Contains the currently selected thread. Thelldb.SBThread object manages the stack frames in that thread. A thread is always selected in the command interpreter when a target stops. Thethreadselect<thread-index> command can be used to change the currently selected thread. So as long as you have a stopped process, there will be some selected thread.

lldb.frame

lldb.SBFrame

SBThread.GetSelectedFrame

Contains the currently selected stack frame. Thelldb.SBFrame object manage the stack locals and the register set for that stack. A stack frame is always selected in the command interpreter when a target stops. Theframeselect<frame-index> command can be used to change the currently selected frame. So as long as you have a stopped process, there will be some selected frame.

While extremely convenient, these variables have a couple caveats that youshould be aware of. First of all, they hold the values of the selected objectson entry to the embedded interpreter. They do not update as you use the LLDBAPI’s to change, for example, the currently selected stack frame or thread.

Moreover, they are only defined and meaningful while in the interactive Pythoninterpreter. There is no guarantee on their value in any other situation, henceyou should not use them when defining Python formatters, breakpoint scripts andcommands (or any other Python extension point that LLDB provides). For thelatter you’ll be passed anSBDebugger,SBTarget,SBProcess,SBThread orSBFrame instance and you can use the functions from the “Equivalent” columnto navigate between them.

As a rationale for such behavior, consider that lldb can run in a multithreadedenvironment, and another thread might call the “script” command, changing thevalue out from under you.

To get started with these objects and LLDB scripting, please note that almostall of the lldb Python objects are able to briefly describe themselves when youpass them to the Python print function:

(lldb)scriptPythonInteractiveInterpreter.Toexit,type'quit()','exit()'orCtrl-D.>>>print(lldb.debugger)Debugger(instance:"debugger_1",id:1)>>>print(lldb.target)a.out>>>print(lldb.process)SBProcess:pid=58842,state=stopped,threads=1,executable=a.out>>>print(lldb.thread)thread#1: tid = 0x2265ce3, 0x0000000100000334 a.out`main at t.c:2:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1>>>print(lldb.frame)frame#0: 0x0000000100000334 a.out`main at t.c:2:3

[8]
ページ先頭

©2009-2025 Movatter.jp