https://github.com/hapeeeeee updated 
https://github.com/llvm/llvm-project/pull/136682

>From 2b8cce2ca76287d4620801878079f5dad453cc9a 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 ++++++++
 .../ReuseWatchpointAfterReExecProcess.test    | 21 +++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 
lldb/test/Shell/Watchpoint/ReuseWatchpointAfterReExecProcess.test

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;
diff --git a/lldb/test/Shell/Watchpoint/ReuseWatchpointAfterReExecProcess.test 
b/lldb/test/Shell/Watchpoint/ReuseWatchpointAfterReExecProcess.test
new file mode 100644
index 0000000000000..6af27856e6ee6
--- /dev/null
+++ b/lldb/test/Shell/Watchpoint/ReuseWatchpointAfterReExecProcess.test
@@ -0,0 +1,21 @@
+# RUN: %clangxx_host %p/Inputs/languages.cpp -g -o %t.out
+# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error 
false' -s %s %t.out 2>&1 | FileCheck %s
+
+b main
+run
+# CHECK: stopped
+# CHECK-NEXT: stop reason = breakpoint
+
+watchpoint set variable val
+# CHECK: Watchpoint created:
+
+kill
+run
+# CHECK: stopped
+# CHECK-NEXT: stop reason = breakpoint
+
+watchpoint set variable val
+# CHECK: Watchpoint created:
+
+continue
+# CHECK: Watchpoint 1 hit:
\ No newline at end of file

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to