Skip to content

Commit 8b1e84b

Browse files
committed
[lldb] Verify target stop-hooks support with scripted process
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 5445a35 commit 8b1e84b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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: 15 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
@@ -100,6 +111,10 @@ def get_register_context(self) -> str:
100111

101112
def __lldb_init_module(debugger, dict):
102113
if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ:
114+
debugger.HandleCommand(
115+
"target stop-hook add -k first -v 1 -k second -v 2 -P %s.%s"
116+
% (__name__, DummyStopHook.__name__)
117+
)
103118
debugger.HandleCommand(
104119
"process launch -C %s.%s" % (__name__, DummyScriptedProcess.__name__)
105120
)

0 commit comments

Comments
 (0)