[Lldb-commits] [lldb] [lldb] Introduce internal stop hooks (PR #164506)
Julian Lettner via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 24 11:33:45 PDT 2025
================
@@ -3098,6 +3107,23 @@ void Target::SetAllStopHooksActiveState(bool active_state) {
}
}
+// FIXME: Ideally we would like to return a `const &` (const reference) instead
----------------
yln wrote:
```
typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
StopHookCollection m_stop_hooks;
```
Iteration order of `std::map` is defined by its keys (ascending).
Previously, we were *also* using `std::map` iteration order, just in a really convoluted/inefficient way:
```
size_t GetNumStopHooks() const { return m_stop_hooks.size(); }
StopHookSP GetStopHookAtIndex(size_t index) { // <<< this is 0-based index, not the "user ID"
if (index >= GetNumStopHooks())
return StopHookSP();
StopHookCollection::iterator pos = m_stop_hooks.begin(); // <<< std::map iterator
while (index > 0) {
pos++;
index--;
}
return (*pos).second;
}
// Call sites:
size_t num_hooks = target.GetNumStopHooks();
for (size_t i = 0; i < num_hooks; i++) {
Target::StopHookSP hook = target.GetStopHookAtIndex(i);
...
}
```
https://github.com/llvm/llvm-project/pull/164506
More information about the lldb-commits
mailing list