Author: Pavel Labath
Date: 2026-05-08T17:49:48+02:00
New Revision: d17e1ee98b545ac5192bfd417c885d76e48f001a

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

LOG: Revert "[lldb] Do not refcount breakpoints in lldb-server (#195858)"

This reverts commit 0059df2a5b53c31f3eb53147a193af9329f7b10d.

Added: 
    

Modified: 
    lldb/include/lldb/Host/common/NativeProcessProtocol.h
    lldb/source/Host/common/NativeProcessProtocol.cpp
    lldb/test/API/functionalities/multi-breakpoint/TestMultiBreakpoint.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h 
b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
index 186a3d0f2f612..06b36c2cc9eb5 100644
--- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h
+++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
@@ -419,6 +419,7 @@ class NativeProcessProtocol {
 
 protected:
   struct SoftwareBreakpoint {
+    uint32_t ref_count;
     llvm::SmallVector<uint8_t, 4> saved_opcodes;
     llvm::ArrayRef<uint8_t> breakpoint_opcodes;
   };

diff  --git a/lldb/source/Host/common/NativeProcessProtocol.cpp 
b/lldb/source/Host/common/NativeProcessProtocol.cpp
index dbffdc619ef42..196f54b93538d 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -344,8 +344,10 @@ Status 
NativeProcessProtocol::SetSoftwareBreakpoint(lldb::addr_t addr,
   LLDB_LOG(log, "addr = {0:x}, size_hint = {1}", addr, size_hint);
 
   auto it = m_software_breakpoints.find(addr);
-  if (it != m_software_breakpoints.end())
+  if (it != m_software_breakpoints.end()) {
+    ++it->second.ref_count;
     return Status();
+  }
   auto expected_bkpt = EnableSoftwareBreakpoint(addr, size_hint);
   if (!expected_bkpt)
     return Status::FromError(expected_bkpt.takeError());
@@ -360,10 +362,14 @@ Status 
NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) {
   auto it = m_software_breakpoints.find(addr);
   if (it == m_software_breakpoints.end())
     return Status::FromErrorString("Breakpoint not found.");
+  assert(it->second.ref_count > 0);
+  if (--it->second.ref_count > 0)
+    return Status();
 
   // Remove the entry from m_software_breakpoints rightaway, so that we don't
-  // leave behind an entry in case one of the following conditions returns an
-  // error. The breakpoint is moved so that it can be accessed below.
+  // leave behind an entry with ref_count == 0 in case one of the following
+  // conditions returns an error. The breakpoint is moved so that it can be
+  // accessed below.
   SoftwareBreakpoint bkpt = std::move(it->second);
   m_software_breakpoints.erase(it);
 
@@ -497,7 +503,7 @@ 
NativeProcessProtocol::EnableSoftwareBreakpoint(lldb::addr_t addr,
   }
 
   LLDB_LOG(log, "addr = {0:x}: SUCCESS", addr);
-  return SoftwareBreakpoint{saved_opcode_bytes, *expected_trap};
+  return SoftwareBreakpoint{1, saved_opcode_bytes, *expected_trap};
 }
 
 llvm::Expected<llvm::ArrayRef<uint8_t>>

diff  --git 
a/lldb/test/API/functionalities/multi-breakpoint/TestMultiBreakpoint.py 
b/lldb/test/API/functionalities/multi-breakpoint/TestMultiBreakpoint.py
index a4d6351e05d65..eb9e2952d5a49 100644
--- a/lldb/test/API/functionalities/multi-breakpoint/TestMultiBreakpoint.py
+++ b/lldb/test/API/functionalities/multi-breakpoint/TestMultiBreakpoint.py
@@ -17,8 +17,6 @@
 # Runs on systems where we can always predict the software break size
 @skipIf(archs=no_match(["x86_64", "arm64", "aarch64"]))
 class TestMultiBreakpoint(TestBase):
-    NO_DEBUG_INFO_TESTCASE = True
-
     def check_invalid_packet(self, packet_str):
         reply = lldbutil.send_packet_get_reply(self, packet_str)
         if reply.startswith("E"):
@@ -62,9 +60,6 @@ def get_function_address(self, name):
         return f"{addr:x}"
 
     def test_multi_breakpoint(self):
-        # Debugserver uses refcounted breakpoints
-        breakpoints_are_refcounted = self.platformIsDarwin()
-
         self.build()
         source_file = lldb.SBFileSpec("main.c")
         self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
@@ -156,9 +151,7 @@ def make_packet(array):
         # Clean up both.
         array = [f"z0,{addr_a},{bp_kind}", f"z0,{addr_a},{bp_kind}"]
         reply = self.send_packet(make_packet(array))
-        self.assertMultiResponse(
-            reply, ["OK", "OK" if breakpoints_are_refcounted else "error"]
-        )
+        self.assertMultiResponse(reply, ["OK", "OK"])
 
         # --- Set the same breakpoint twice, but remove it thrice.
         array = [f"Z0,{addr_a},{bp_kind}", f"Z0,{addr_a},{bp_kind}"]
@@ -170,9 +163,7 @@ def make_packet(array):
             f"z0,{addr_a},{bp_kind}",
         ]
         reply = self.send_packet(make_packet(array))
-        self.assertMultiResponse(
-            reply, ["OK", "OK" if breakpoints_are_refcounted else "error", 
"error"]
-        )
+        self.assertMultiResponse(reply, ["OK", "OK", "error"])
 
         # --- Set and remove the same address in a single packet ---
         # The spec requires requests to be executed in order, so the set


        
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to