[Lldb-commits] [lldb] [lldb] Add target groups for related targets (PR #229180)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 12 11:51:20 PDT 2026
================
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/TargetGroup.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/TargetGroupList.h"
+
+#include <algorithm>
+
+using namespace lldb;
+using namespace lldb_private;
+
+bool TargetGroup::AddTarget(const TargetSP &target_sp, TargetRole role) {
+ if (!target_sp || role == TargetRole::None)
+ return false;
+
+ std::lock_guard<std::recursive_mutex> guard(*m_mutex);
+ if (!m_active || &target_sp->GetDebugger() != m_debugger)
+ return false;
+
+ for (auto it = m_entries.begin(); it != m_entries.end();) {
+ TargetSP member_sp = it->target_wp.lock();
+ if (!member_sp) {
+ it = m_entries.erase(it);
+ continue;
+ }
+ if (member_sp == target_sp) {
+ it->role = role;
+ target_sp->AddTargetGroup(shared_from_this());
+ return true;
+ }
+ ++it;
+ }
+
+ m_entries.push_back({target_sp, role});
+ target_sp->AddTargetGroup(shared_from_this());
+ return true;
+}
+
+bool TargetGroup::RemoveTarget(const TargetSP &target_sp) {
+ if (!target_sp)
+ return false;
+
+ std::lock_guard<std::recursive_mutex> guard(*m_mutex);
+ if (!m_active)
+ return false;
+
+ bool removed = false;
+ auto it = std::remove_if(m_entries.begin(), m_entries.end(),
----------------
clayborg wrote:
We are doing the culling of expired weak pointer targets in the middle of all loops through each entry. Maybe all functions that loop through the target entries should be doing:
```
std::lock_guard<std::recursive_mutex> guard(*m_mutex);
RemoveExpiredTargets();
/// Add funcitonality here to remove the target without worrying about invalid ones.
```
https://github.com/llvm/llvm-project/pull/229180
More information about the lldb-commits
mailing list