[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:19 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;
+ }
----------------
clayborg wrote:
We shouldn't allow someone to add the same target using a different role. Maybe this should be:
```
if (member_sp == target_sp)
return it->role == role;
```
We also shouldn't need to call `target_sp->AddTargetGroup(shared_from_this());` if this target is already in the TargetGroup because the code below on line 41 would have done it already.
https://github.com/llvm/llvm-project/pull/229180
More information about the lldb-commits
mailing list