[Lldb-commits] [lldb] 64c26c8 - Fix a bug copying the stop hooks from the dummy target. (#129340)

via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 3 09:59:45 PST 2025


Author: jimingham
Date: 2025-03-03T09:59:42-08:00
New Revision: 64c26c8f16aeff3b4ef99f171c771c08353cfbdf

URL: https://github.com/llvm/llvm-project/commit/64c26c8f16aeff3b4ef99f171c771c08353cfbdf
DIFF: https://github.com/llvm/llvm-project/commit/64c26c8f16aeff3b4ef99f171c771c08353cfbdf.diff

LOG: Fix a bug copying the stop hooks from the dummy target. (#129340)

We didn't also copy over the next stop hook id, which meant we would
overwrite the stop hooks from the dummy target with stop hooks set after
they are copied over.

Added: 
    

Modified: 
    lldb/source/Target/Target.cpp
    lldb/test/API/commands/target/stop-hooks/TestStopHooks.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index db289fe9c4b64..550424720e095 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -211,6 +211,7 @@ Target::~Target() {
 
 void Target::PrimeFromDummyTarget(Target &target) {
   m_stop_hooks = target.m_stop_hooks;
+  m_stop_hook_next_id = target.m_stop_hook_next_id;
 
   for (const auto &breakpoint_sp : target.m_breakpoint_list.Breakpoints()) {
     if (breakpoint_sp->IsInternal())

diff  --git a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
index fe59bd8a5d007..0c42fda260d1b 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
@@ -26,10 +26,15 @@ def test_stop_hooks_step_out(self):
         self.step_out_test()
 
     def test_stop_hooks_after_expr(self):
-        """Test that a stop hook fires when hitting a breakpoint
-        that runs an expression"""
+        """Test that a stop hook fires when hitting a breakpoint that
+        runs an expression"""
         self.after_expr_test()
 
+    def test_stop_hooks_before_and_after_creation(self):
+        """Test that if we add stop hooks in the dummy target,
+        they aren't overridden by the ones set directly in the target."""
+        self.before_and_after_target()
+
     def step_out_test(self):
         (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
             self, "Set a breakpoint here", self.main_source_file
@@ -85,3 +90,19 @@ def after_expr_test(self):
         var = target.FindFirstGlobalVariable("g_var")
         self.assertTrue(var.IsValid())
         self.assertEqual(var.GetValueAsUnsigned(), 1, "Updated g_var")
+
+    def before_and_after_target(self):
+        interp = self.dbg.GetCommandInterpreter()
+        result = lldb.SBCommandReturnObject()
+        interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result)
+        self.assertTrue(result.Succeeded(), "Set the target stop hook")
+
+        (target, process, thread, first_bkpt) = lldbutil.run_to_source_breakpoint(
+            self, "Set a breakpoint here", self.main_source_file
+        )
+
+        interp.HandleCommand("target stop-hook add -o 'thread backtrace'", result)
+        self.assertTrue(result.Succeeded(), "Set the target stop hook")
+        self.expect(
+            "target stop-hook list", substrs=["expr g_var++", "thread backtrace"]
+        )


        


More information about the lldb-commits mailing list