https://github.com/hapeeeeee created https://github.com/llvm/llvm-project/pull/136682
This PR fixes a crash in `LLDB` caused by a dangling pointer to a reused `ValueObjectSP` when re-running the debuggee and setting the same watchpoint again. As described by @jasonmolenda, the fix is to reinitialize the dangling pointer in `Watchpoint::SetEnabled`. This PR closes [#135590](https://github.com/llvm/llvm-project/issues/135590). >From 563cbddfe9b7da394c818a03e05924c0f7d39d5f Mon Sep 17 00:00:00 2001 From: hapeeeeee <623151...@qq.com> Date: Tue, 22 Apr 2025 11:34:38 +0800 Subject: [PATCH] [lldb] Fix crash after second run when set a previous watchpoint. --- lldb/source/Breakpoint/Watchpoint.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp index 2df848aaa0576..0fcc9b90c0ab5 100644 --- a/lldb/source/Breakpoint/Watchpoint.cpp +++ b/lldb/source/Breakpoint/Watchpoint.cpp @@ -409,6 +409,15 @@ bool Watchpoint::IsDisabledDuringEphemeralMode() { } void Watchpoint::SetEnabled(bool enabled, bool notify) { + // Whenever setting the enabled state of a watchpoint, we need to ensure + // that `m_new_value_sp` exists to avoid crash when reading old_data later. + // See https://github.com/llvm/llvm-project/issues/135590. + if (!m_new_value_sp) { + ExecutionContext exe_ctx; + m_target.GetProcessSP()->CalculateExecutionContext(exe_ctx); + CaptureWatchedValue(exe_ctx); + } + if (!enabled) { if (m_is_ephemeral) ++m_disabled_count; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits