[Lldb-commits] [lldb] Fix a potential use-after-free in StopInfoBreakpoint. (PR #163471)

via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 14 16:12:11 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,h,cpp -- lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h lldb/source/Breakpoint/BreakpointLocationCollection.cpp lldb/source/Target/StopInfo.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
index 10a22476a..af02d608b 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
@@ -27,7 +27,7 @@ public:
   /// then you need to make sure the breakpoints don't get deleted out from
   /// under you.  To do that, pass true for preserving, and so long as there is
   /// a location for a given breakpoint in the collection, the breakpoint will
-  /// not get destroyed. 
+  /// not get destroyed.
   BreakpointLocationCollection(bool preserving = false);
 
   virtual ~BreakpointLocationCollection();
@@ -178,9 +178,9 @@ private:
   struct RefCountedBPSP {
     RefCountedBPSP(lldb::BreakpointSP in_bp_sp) : ref_cnt(1), bp_sp(in_bp_sp) {}
     uint64_t ref_cnt;
-    lldb::BreakpointSP bp_sp; 
+    lldb::BreakpointSP bp_sp;
   };
-  std::map<lldb::break_id_t, RefCountedBPSP> m_preserved_bps; 
+  std::map<lldb::break_id_t, RefCountedBPSP> m_preserved_bps;
 
 public:
   typedef llvm::iterator_range<collection::const_iterator>
diff --git a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp
index f250091e4..ef8921e2d 100644
--- a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp
+++ b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp
@@ -17,8 +17,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 // BreakpointLocationCollection constructor
-BreakpointLocationCollection::BreakpointLocationCollection(bool preserving) : 
-    m_preserving_bkpts(preserving) {}
+BreakpointLocationCollection::BreakpointLocationCollection(bool preserving)
+    : m_preserving_bkpts(preserving) {}
 
 // Destructor
 BreakpointLocationCollection::~BreakpointLocationCollection() = default;
@@ -35,8 +35,8 @@ void BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) {
       auto entry = m_preserved_bps.find(bp_id);
       if (entry == m_preserved_bps.end())
         m_preserved_bps.emplace(bp_id, RefCountedBPSP(bkpt.shared_from_this()));
-    else
-      entry->second.ref_cnt++;
+      else
+        entry->second.ref_cnt++;
     }
   }
 }
@@ -48,8 +48,8 @@ bool BreakpointLocationCollection::Remove(lldb::break_id_t bp_id,
   if (pos != m_break_loc_collection.end()) {
     if (m_preserving_bkpts) {
       auto entry = m_preserved_bps.find(bp_id);
-      assert(entry != m_preserved_bps.end() 
-        && "Breakpoint added to base but not preserving map.");
+      assert(entry != m_preserved_bps.end() &&
+             "Breakpoint added to base but not preserving map.");
       if (--entry->second.ref_cnt == 0)
         m_preserved_bps.erase(entry);
     }
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index 6d5572c62..e9e534a57 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -94,7 +94,7 @@ public:
       : StopInfo(thread, break_id), m_should_stop(false),
         m_should_stop_is_valid(false), m_should_perform_action(true),
         m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID),
-        m_was_all_internal(false), m_was_one_shot(false), 
+        m_was_all_internal(false), m_was_one_shot(false),
         m_async_stopped_locs(true) {
     StoreBPInfo();
   }
@@ -103,7 +103,7 @@ public:
       : StopInfo(thread, break_id), m_should_stop(should_stop),
         m_should_stop_is_valid(true), m_should_perform_action(true),
         m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID),
-        m_was_all_internal(false), m_was_one_shot(false), 
+        m_was_all_internal(false), m_was_one_shot(false),
         m_async_stopped_locs(true) {
     StoreBPInfo();
   }
diff --git a/lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c b/lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c
index 279b35952..2ffb897b2 100644
--- a/lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c
+++ b/lldb/test/API/functionalities/breakpoint/callback_deletes_breakpoints/main.c
@@ -1,14 +1,11 @@
 #include <stdio.h>
 
-int
-do_something(int input) {
+int do_something(int input) {
   return input % 5; // Deletable location
 }
 
-int
-main()
-{
-  printf ("Set a breakpoint here.\n");
+int main() {
+  printf("Set a breakpoint here.\n");
   do_something(100);
   do_something(200);
   return 0;

``````````

</details>


https://github.com/llvm/llvm-project/pull/163471


More information about the lldb-commits mailing list