Skip to content

Commit b3a835e

Browse files
authored
[lldb] Verify target stop-hooks support with scripted process (#91107)
This patch makes sure that scripted process are compatible with target stop-hooks. This wasn't tested in the past, but it turned out to be working out of the box. rdar://124396534 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 7c1b289 commit b3a835e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ def cleanup():
187187
+ os.path.join(self.getSourceDir(), scripted_process_example_relpath)
188188
)
189189

190+
self.runCmd(
191+
"target stop-hook add -k first -v 1 -k second -v 2 -P dummy_scripted_process.DummyStopHook"
192+
)
193+
190194
launch_info = lldb.SBLaunchInfo(None)
191195
launch_info.SetProcessPluginName("ScriptedProcess")
192196
launch_info.SetScriptedProcessClassName(
@@ -207,6 +211,9 @@ def cleanup():
207211
self.assertTrue(hasattr(py_impl, "my_super_secret_member"))
208212
self.assertEqual(py_impl.my_super_secret_method(), 42)
209213

214+
self.assertTrue(hasattr(py_impl, "handled_stop"))
215+
self.assertTrue(py_impl.handled_stop)
216+
210217
# Try reading from target #0 process ...
211218
addr = 0x500000000
212219
message = "Hello, target 0"

lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from lldb.plugins.scripted_process import ScriptedThread
88

99

10+
class DummyStopHook:
11+
def __init__(self, target, args, internal_dict):
12+
self.target = target
13+
self.args = args
14+
15+
def handle_stop(self, exe_ctx, stream):
16+
print("My DummyStopHook triggered. Printing args: \n%s" % self.args)
17+
sp = exe_ctx.process.GetScriptedImplementation()
18+
sp.handled_stop = True
19+
1020
class DummyScriptedProcess(ScriptedProcess):
1121
memory = None
1222

@@ -18,6 +28,7 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
1828
debugger = self.target.GetDebugger()
1929
index = debugger.GetIndexOfTarget(self.target)
2030
self.memory[addr] = "Hello, target " + str(index)
31+
self.handled_stop = False
2132

2233
def read_memory_at_address(
2334
self, addr: int, size: int, error: lldb.SBError
@@ -99,7 +110,13 @@ def get_register_context(self) -> str:
99110

100111

101112
def __lldb_init_module(debugger, dict):
113+
# This is used when loading the script in an interactive debug session to
114+
# automatically, register the stop-hook and launch the scripted process.
102115
if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ:
116+
debugger.HandleCommand(
117+
"target stop-hook add -k first -v 1 -k second -v 2 -P %s.%s"
118+
% (__name__, DummyStopHook.__name__)
119+
)
103120
debugger.HandleCommand(
104121
"process launch -C %s.%s" % (__name__, DummyScriptedProcess.__name__)
105122
)
@@ -108,3 +125,7 @@ def __lldb_init_module(debugger, dict):
108125
"Name of the class that will manage the scripted process: '%s.%s'"
109126
% (__name__, DummyScriptedProcess.__name__)
110127
)
128+
print(
129+
"Name of the class that will manage the stop-hook: '%s.%s'"
130+
% (__name__, DummyStopHook.__name__)
131+
)

0 commit comments

Comments
 (0)