Skip to content

Commit 622df0e

Browse files
authored
[lldb] Add scripted thread plan python base class to lldb & website (#97481)
Following a feedback request in #97262, I took out the scripted thread plan python base class from it and make a separate PR for it. This patch adds the scripted thread plan base python class to the lldb python module as well as the lldb documentation website. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 21276fd commit 622df0e

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

lldb/bindings/python/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
108108
"${LLDB_SOURCE_DIR}/examples/python/templates/parsed_cmd.py"
109109
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
110110
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
111-
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py")
111+
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py"
112+
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py"
113+
)
112114

113115
if(APPLE)
114116
create_python_package(

lldb/docs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
3131
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
3232
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
3333
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
34+
COMMAND "${CMAKE_COMMAND}" -E copy "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
3435
COMMENT "Copying lldb.py to pretend its a Python package.")
3536

3637
add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)

lldb/docs/python_extensions.rst

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