-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Verify target stop-hooks support with scripted process #91107
[lldb] Verify target stop-hooks support with scripted process #91107
Conversation
@llvm/pr-subscribers-lldb Author: Med Ismail Bennani (medismailben) ChangesThis 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 Full diff: https://github.com/llvm/llvm-project/pull/91107.diff 2 Files Affected:
diff --git a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index 5aaf68575623ce..9519c576689d0e 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 5aff3aa4bb5597..d256586eb9ae58 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
@@ -100,6 +111,10 @@ def get_register_context(self) -> str:
def __lldb_init_module(debugger, dict):
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__)
)
|
@@ -100,6 +111,10 @@ def get_register_context(self) -> str: | |||
|
|||
def __lldb_init_module(debugger, dict): | |||
if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ: | |||
debugger.HandleCommand( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to add the stop hook here when the module is initialized and also in the test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this for when loading the file it by hand when debugging, so I don't have to type the command every time I load it in an interactive debug session. As you can see it only takes this path when SKIP_SCRIPTED_PROCESS_LAUNCH
is set, which is not the case in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it would be worth documenting in a comment?
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 <ismail@bennani.ma>
8b1e84b
to
d34abd5
Compare
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