Skip to content

Commit 64c26c8

Browse files
authored
Fix a bug copying the stop hooks from the dummy target. (llvm#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.
1 parent 44badc9 commit 64c26c8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Target::~Target() {
211211

212212
void Target::PrimeFromDummyTarget(Target &target) {
213213
m_stop_hooks = target.m_stop_hooks;
214+
m_stop_hook_next_id = target.m_stop_hook_next_id;
214215

215216
for (const auto &breakpoint_sp : target.m_breakpoint_list.Breakpoints()) {
216217
if (breakpoint_sp->IsInternal())

lldb/test/API/commands/target/stop-hooks/TestStopHooks.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ def test_stop_hooks_step_out(self):
2626
self.step_out_test()
2727

2828
def test_stop_hooks_after_expr(self):
29-
"""Test that a stop hook fires when hitting a breakpoint
30-
that runs an expression"""
29+
"""Test that a stop hook fires when hitting a breakpoint that
30+
runs an expression"""
3131
self.after_expr_test()
3232

33+
def test_stop_hooks_before_and_after_creation(self):
34+
"""Test that if we add stop hooks in the dummy target,
35+
they aren't overridden by the ones set directly in the target."""
36+
self.before_and_after_target()
37+
3338
def step_out_test(self):
3439
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
3540
self, "Set a breakpoint here", self.main_source_file
@@ -85,3 +90,19 @@ def after_expr_test(self):
8590
var = target.FindFirstGlobalVariable("g_var")
8691
self.assertTrue(var.IsValid())
8792
self.assertEqual(var.GetValueAsUnsigned(), 1, "Updated g_var")
93+
94+
def before_and_after_target(self):
95+
interp = self.dbg.GetCommandInterpreter()
96+
result = lldb.SBCommandReturnObject()
97+
interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result)
98+
self.assertTrue(result.Succeeded(), "Set the target stop hook")
99+
100+
(target, process, thread, first_bkpt) = lldbutil.run_to_source_breakpoint(
101+
self, "Set a breakpoint here", self.main_source_file
102+
)
103+
104+
interp.HandleCommand("target stop-hook add -o 'thread backtrace'", result)
105+
self.assertTrue(result.Succeeded(), "Set the target stop hook")
106+
self.expect(
107+
"target stop-hook list", substrs=["expr g_var++", "thread backtrace"]
108+
)

0 commit comments

Comments
 (0)