diff --git a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py index 5aaf68575623c..9519c576689d0 100644 --- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py +++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py @@ -187,6 +187,10 @@ def cleanup(): + os.path.join(self.getSourceDir(), scripted_process_example_relpath) ) + self.runCmd( + "target stop-hook add -k first -v 1 -k second -v 2 -P dummy_scripted_process.DummyStopHook" + ) + launch_info = lldb.SBLaunchInfo(None) launch_info.SetProcessPluginName("ScriptedProcess") launch_info.SetScriptedProcessClassName( @@ -207,6 +211,9 @@ def cleanup(): self.assertTrue(hasattr(py_impl, "my_super_secret_member")) self.assertEqual(py_impl.my_super_secret_method(), 42) + self.assertTrue(hasattr(py_impl, "handled_stop")) + self.assertTrue(py_impl.handled_stop) + # Try reading from target #0 process ... addr = 0x500000000 message = "Hello, target 0" diff --git a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py index 5aff3aa4bb559..cb07bf32c5080 100644 --- a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py @@ -7,6 +7,16 @@ from lldb.plugins.scripted_process import ScriptedThread +class DummyStopHook: + def __init__(self, target, args, internal_dict): + self.target = target + self.args = args + + def handle_stop(self, exe_ctx, stream): + print("My DummyStopHook triggered. Printing args: \n%s" % self.args) + sp = exe_ctx.process.GetScriptedImplementation() + sp.handled_stop = True + class DummyScriptedProcess(ScriptedProcess): memory = None @@ -18,6 +28,7 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData debugger = self.target.GetDebugger() index = debugger.GetIndexOfTarget(self.target) self.memory[addr] = "Hello, target " + str(index) + self.handled_stop = False def read_memory_at_address( self, addr: int, size: int, error: lldb.SBError @@ -99,7 +110,13 @@ def get_register_context(self) -> str: def __lldb_init_module(debugger, dict): + # This is used when loading the script in an interactive debug session to + # automatically, register the stop-hook and launch the scripted process. if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ: + debugger.HandleCommand( + "target stop-hook add -k first -v 1 -k second -v 2 -P %s.%s" + % (__name__, DummyStopHook.__name__) + ) debugger.HandleCommand( "process launch -C %s.%s" % (__name__, DummyScriptedProcess.__name__) ) @@ -108,3 +125,7 @@ def __lldb_init_module(debugger, dict): "Name of the class that will manage the scripted process: '%s.%s'" % (__name__, DummyScriptedProcess.__name__) ) + print( + "Name of the class that will manage the stop-hook: '%s.%s'" + % (__name__, DummyStopHook.__name__) + )