Skip to content

Commit e08689b

Browse files
committed
[lldb/docs] Add scripting extensions documentation to the website
This patch adds the documentation for a subset of scripting extensions such as scripted process, scripted thread, operating system threads & scritped thread plans to the lldb website. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 6f60d2b commit e08689b

File tree

7 files changed

+156
-47
lines changed

7 files changed

+156
-47
lines changed

lldb/docs/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
2525
# Pretend that the SWIG generated API is a Python package.
2626
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb)
2727
get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
28+
2829
add_custom_target(lldb-python-doc-package
2930
COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py"
31+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins"
32+
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
33+
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
34+
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
35+
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
3036
COMMENT "Copying lldb.py to pretend its a Python package.")
31-
add_dependencies(lldb-python-doc-package swig_wrapper_python)
37+
38+
add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
3239

3340
# FIXME: Don't treat Sphinx warnings as errors. The files generated by
3441
# automodapi are full of warnings (partly caused by SWIG, our documentation

lldb/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ interesting areas to contribute to lldb.
141141
use/python
142142
use/python-reference
143143
Python API <python_api>
144+
Python Extensions <python_extensions>
144145

145146

146147
.. toctree::

lldb/docs/python_extensions.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Python Extensions
2+
=================
3+
4+
LLDB provides many scriptable extensions to augment the debugger capabilities
5+
and give the ability to the user to tailor their experience to their own needs.
6+
7+
This page describes some of these scripting extension:
8+
9+
Operating System Thread Plugins
10+
-------------------------------
11+
12+
.. automodapi:: lldb.plugins.operating_system
13+
:no-heading:
14+
:no-inheritance-diagram:
15+
16+
Scripted Process Plugins
17+
-------------------------------
18+
19+
.. automodapi:: lldb.plugins.scripted_process
20+
:no-heading:
21+
:no-inheritance-diagram:
22+
23+
Scripted Platform Plugins
24+
-------------------------------
25+
26+
.. automodapi:: lldb.plugins.scripted_platform
27+
:no-heading:
28+
:no-inheritance-diagram:
29+
30+
Scripted Thread Plan Plugins
31+
-------------------------------
32+
33+
.. automodapi:: lldb.plugins.scripted_thread_plan
34+
:no-heading:
35+
:no-inheritance-diagram:
36+

lldb/examples/python/templates/operating_system.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class OperatingSystem(ScriptedThread):
1010
"""
1111
Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class.
1212
13-
```
14-
thread_info = {
15-
"tid": tid,
16-
"name": "four",
17-
"queue": "queue4",
18-
"state": "stopped",
19-
"stop_reason": "none",
20-
"core" : 2
21-
}
22-
```
13+
.. code-block:: python
14+
15+
thread_info = {
16+
"tid": tid,
17+
"name": "four",
18+
"queue": "queue4",
19+
"state": "stopped",
20+
"stop_reason": "none",
21+
"core" : 2
22+
}
2323
2424
- tid : thread ID (mandatory)
2525
- name : thread name (optional key/value pair)

lldb/examples/python/templates/scripted_platform.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class ScriptedPlatform(metaclass=ABCMeta):
1010
1111
Most of the base class methods are `@abstractmethod` that need to be
1212
overwritten by the inheriting class.
13-
14-
DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
15-
THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
1613
"""
1714

1815
processes = None
@@ -32,16 +29,18 @@ def __init__(self, exe_ctx, args):
3229
def list_processes(self):
3330
"""Get a list of processes that are running or that can be attached to on the platform.
3431
35-
processes = {
36-
420: {
37-
name: a.out,
38-
arch: aarch64,
39-
pid: 420,
40-
parent_pid: 42 (optional),
41-
uid: 0 (optional),
42-
gid: 0 (optional),
43-
},
44-
}
32+
.. code-block:: python
33+
34+
processes = {
35+
420: {
36+
name: a.out,
37+
arch: aarch64,
38+
pid: 420,
39+
parent_pid: 42 (optional),
40+
uid: 0 (optional),
41+
gid: 0 (optional),
42+
},
43+
}
4544
4645
Returns:
4746
Dict: The processes represented as a dictionary, with at least the

lldb/examples/python/templates/scripted_process.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class ScriptedProcess(metaclass=ABCMeta):
1111
1212
Most of the base class methods are `@abstractmethod` that need to be
1313
overwritten by the inheriting class.
14-
15-
DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
16-
THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
1714
"""
1815

1916
capabilities = None
@@ -106,8 +103,8 @@ def write_memory_at_address(self, addr, data, error):
106103
107104
Args:
108105
addr (int): Address from which we should start reading.
109-
data (lldb.SBData): An `lldb.SBData` buffer to write to the
110-
process memory.
106+
data (lldb.SBData): An `lldb.SBData` buffer to write to the process
107+
memory.
111108
error (lldb.SBError): Error object.
112109
113110
Returns:
@@ -121,13 +118,13 @@ def write_memory_at_address(self, addr, data, error):
121118
def get_loaded_images(self):
122119
"""Get the list of loaded images for the scripted process.
123120
124-
```
125-
scripted_image = {
126-
uuid = "c6ea2b64-f77c-3d27-9528-74f507b9078b",
127-
path = "/usr/lib/dyld"
128-
load_addr = 0xbadc0ffee
129-
}
130-
```
121+
.. code-block:: python
122+
123+
scripted_image = {
124+
uuid = "c6ea2b64-f77c-3d27-9528-74f507b9078b",
125+
path = "/usr/lib/dyld"
126+
load_addr = 0xbadc0ffee
127+
}
131128
132129
Returns:
133130
List[scripted_image]: A list of `scripted_image` dictionaries
@@ -238,9 +235,6 @@ class ScriptedThread(metaclass=ABCMeta):
238235
239236
Most of the base class methods are `@abstractmethod` that need to be
240237
overwritten by the inheriting class.
241-
242-
DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
243-
THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
244238
"""
245239

246240
@abstractmethod
@@ -305,10 +299,12 @@ def get_name(self):
305299
def get_state(self):
306300
"""Get the scripted thread state type.
307301
302+
.. code-block:: python
303+
308304
eStateStopped, ///< Process or thread is stopped and can be examined.
309305
eStateRunning, ///< Process or thread is running and can't be examined.
310-
eStateStepping, ///< Process or thread is in the process of stepping and can
311-
/// not be examined.
306+
eStateStepping, ///< Process or thread is in the process of stepping and
307+
/// can not be examined.
312308
eStateCrashed, ///< Process or thread has crashed and can be examined.
313309
314310
Returns:
@@ -340,12 +336,12 @@ def get_stop_reason(self):
340336
def get_stackframes(self):
341337
"""Get the list of stack frames for the scripted thread.
342338
343-
```
344-
scripted_frame = {
345-
idx = 0,
346-
pc = 0xbadc0ffee
347-
}
348-
```
339+
.. code-block:: python
340+
341+
scripted_frame = {
342+
idx = 0,
343+
pc = 0xbadc0ffee
344+
}
349345
350346
Returns:
351347
List[scripted_frame]: A list of `scripted_frame` dictionaries
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from abc import abstractmethod
2+
3+
import lldb
4+
5+
6+
class ScriptedThreadPlan:
7+
"""
8+
Class that provides data for an instance of a LLDB 'ScriptedThreadPlan' plug-in class used to construct custom stepping logic.
9+
10+
"""
11+
12+
def __init__(self, thread_plan: lldb.SBThreadPlan):
13+
"""Initialization needs a valid lldb.SBThreadPlan object. This plug-in will get created after a live process is valid and has stopped.
14+
15+
Args:
16+
thread_plan (lldb.SBThreadPlan): The underlying `ThreadPlan` that is pushed onto the plan stack.
17+
"""
18+
self.thread_plan = thread_plan
19+
20+
def explains_stop(self, event: lldb.SBEvent) -> bool:
21+
"""Each plan is asked from youngest to oldest if it "explains" the stop. The first plan to claim the stop wins.
22+
23+
Args:
24+
event (lldb.SBEvent): The process stop event.
25+
26+
Returns:
27+
bool: `True` if this stop could be claimed by this thread plan, `False` otherwise.
28+
Defaults to `True`.
29+
"""
30+
return True
31+
32+
def is_stale(self) -> bool:
33+
"""If your plan is no longer relevant (for instance, you were stepping in a particular stack frame, but some other operation pushed that frame off the stack) return True and your plan will get popped.
34+
35+
Returns:
36+
bool: `True` if this thread plan is stale, `False` otherwise.
37+
Defaults to `False`.
38+
"""
39+
return False
40+
41+
def should_stop(self, event: lldb.SBEvent) -> bool:
42+
"""Whether this thread plan should stop and return control to the user.
43+
If your plan is done at this point, call SetPlanComplete on your thread plan instance. Also, do any work you need here to set up the next stage of stepping.
44+
45+
Args:
46+
event (lldb.SBEvent): The process stop event.
47+
48+
Returns:
49+
bool: `True` if this plan wants to stop and return control to the user at this point, `False` otherwise.
50+
Defaults to `False`.
51+
"""
52+
self.thread_plan.SetPlanComplete(True)
53+
return True
54+
55+
def should_step(self) -> bool:
56+
"""Whether this thread plan should instruction step one instruction, or continue till the next breakpoint is hit.
57+
58+
Returns:
59+
bool: `True` if this plan will instruction step one instruction, `False` otherwise.
60+
Defaults to `True`.
61+
"""
62+
return True
63+
64+
def stop_description(self, stream: lldb.SBStream) -> None:
65+
"""Customize the thread plan stop reason when the thread plan is complete.
66+
67+
Args:
68+
stream (lldb.SBStream): The stream containing the stop description.
69+
"""
70+
pass

0 commit comments

Comments
 (0)