[Lldb-commits] [lldb] [lldb] Fix possible invalidated iterator. (PR #198482)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Tue May 19 05:49:50 PDT 2026
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/198482
>From 52ee2af582094e39a2cd5f1b59d0bb02f057f3b6 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <e_ezike at apple.com>
Date: Tue, 19 May 2026 11:05:09 +0100
Subject: [PATCH 1/2] [lldb] Fix possible invalidated iterator.
The begin or end interator may be invalidated when an
idx_pos in erased from the vector
---
lldb/source/Target/Target.cpp | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index d6bf25630fa65..e2523c4d9206b 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -72,6 +72,7 @@
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timer.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/ErrorExtras.h"
@@ -977,20 +978,18 @@ void Target::DescribeBreakpointOverrides(Stream &stream,
return;
}
- auto begin = idxs.begin();
- auto end = idxs.end();
- bool empty = idxs.empty();
+ const bool empty = idxs.empty();
bool print_first = true;
- for (auto const &elem : m_breakpoint_overrides) {
- auto idx_pos = empty ? end : std::find(begin, end, elem.first);
- if (empty || idx_pos != end) {
+ for (const auto &[id, resolver] : m_breakpoint_overrides) {
+ auto idx_pos = llvm::find(idxs, id);
+ if (empty || idx_pos != idxs.end()) {
if (print_first) {
// FIXME: Is there some good way to flow the description?
stream << "ID Description\n";
stream << "---- -----------\n";
print_first = false;
}
- stream.Format("{0,4} {1}\n", elem.first, elem.second->GetDescription());
+ stream.Format("{0,4} {1}\n", id, resolver->GetDescription());
if (!empty)
idxs.erase(idx_pos);
}
>From 85aa1c61ca5c85c913b8295d6d3b019b9ad038e1 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <e_ezike at apple.com>
Date: Tue, 19 May 2026 13:49:23 +0100
Subject: [PATCH 2/2] add review changes
---
lldb/source/Target/Target.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index e2523c4d9206b..f654f267b9f56 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -978,10 +978,10 @@ void Target::DescribeBreakpointOverrides(Stream &stream,
return;
}
- const bool empty = idxs.empty();
+ bool empty = idxs.empty();
bool print_first = true;
- for (const auto &[id, resolver] : m_breakpoint_overrides) {
- auto idx_pos = llvm::find(idxs, id);
+ for (auto const &elem : m_breakpoint_overrides) {
+ auto idx_pos = llvm::find(idxs, elem.first);
if (empty || idx_pos != idxs.end()) {
if (print_first) {
// FIXME: Is there some good way to flow the description?
@@ -989,7 +989,7 @@ void Target::DescribeBreakpointOverrides(Stream &stream,
stream << "---- -----------\n";
print_first = false;
}
- stream.Format("{0,4} {1}\n", id, resolver->GetDescription());
+ stream.Format("{0,4} {1}\n", elem.first, elem.second->GetDescription());
if (!empty)
idxs.erase(idx_pos);
}
More information about the lldb-commits
mailing list