[Lldb-commits] [lldb] [lldb] Remove empty target groups after target destruction (PR #232991)
satyanarayana reddy janga via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 16 17:58:30 PDT 2026
https://github.com/satyajanga created https://github.com/llvm/llvm-project/pull/232991
### Summary
Remove target groups from the debugger registry when target destruction removes their last member.
Groups with surviving targets remain registered.
### Testing
- `TargetTests --gtest_filter='TargetGroupTest.*'`
- `TargetTests`
>From 87409399dc4be5ecc1bb131356472bf917187cfd Mon Sep 17 00:00:00 2001
From: satya janga <satyajanga at fb.com>
Date: Fri, 16 Oct 2026 17:57:59 -0700
Subject: [PATCH] [lldb] Remove empty target groups after target destruction
---
lldb/include/lldb/Target/TargetGroup.h | 4 ++--
lldb/source/Target/TargetGroupList.cpp | 5 ++++-
lldb/unittests/Target/TargetGroupTest.cpp | 4 ++++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/lldb/include/lldb/Target/TargetGroup.h b/lldb/include/lldb/Target/TargetGroup.h
index 5b1ead4aee044..f225cc94d103d 100644
--- a/lldb/include/lldb/Target/TargetGroup.h
+++ b/lldb/include/lldb/Target/TargetGroup.h
@@ -24,8 +24,8 @@ namespace lldb_private {
/// A group of related targets and the roles they play in that relationship.
///
-/// Target::Destroy() automatically removes a target from all its groups;
-/// clients do not need to remove memberships during target destruction.
+/// Target::Destroy() automatically removes a target from all its groups and
+/// removes groups left empty from the Debugger's registry.
class TargetGroup : public std::enable_shared_from_this<TargetGroup> {
public:
/// Describes the part a target plays in this group.
diff --git a/lldb/source/Target/TargetGroupList.cpp b/lldb/source/Target/TargetGroupList.cpp
index 474d3285e55a5..5a732dd6112da 100644
--- a/lldb/source/Target/TargetGroupList.cpp
+++ b/lldb/source/Target/TargetGroupList.cpp
@@ -62,8 +62,11 @@ void TargetGroupList::RemoveTarget(const TargetSP &target_sp) {
std::lock_guard<std::recursive_mutex> guard(*m_mutex);
std::vector<TargetGroupSP> groups = m_groups;
- for (const TargetGroupSP &group_sp : groups)
+ for (const TargetGroupSP &group_sp : groups) {
group_sp->RemoveTarget(target_sp);
+ if (group_sp->GetTargets().empty())
+ m_debugger.GetTargetGroupList().DeleteTargetGroup(group_sp);
+ }
m_groups.clear();
}
diff --git a/lldb/unittests/Target/TargetGroupTest.cpp b/lldb/unittests/Target/TargetGroupTest.cpp
index ca307b3812f4d..14b002cdffb70 100644
--- a/lldb/unittests/Target/TargetGroupTest.cpp
+++ b/lldb/unittests/Target/TargetGroupTest.cpp
@@ -154,10 +154,14 @@ TEST_F(TargetGroupTest, TargetDestructionRemovesEveryMembership) {
target_sp->Destroy();
EXPECT_TRUE(target_sp->GetTargetGroups().empty());
+ EXPECT_EQ(std::vector<TargetGroupSP>{second_group_sp}, groups.GetGroups());
EXPECT_EQ(std::nullopt, first_group_sp->GetRole(target_sp));
EXPECT_EQ(std::nullopt, second_group_sp->GetRole(target_sp));
EXPECT_EQ(std::optional(TargetGroup::Role::CPU),
second_group_sp->GetRole(survivor_sp));
+
+ survivor_sp->Destroy();
+ EXPECT_TRUE(groups.GetGroups().empty());
}
TEST_F(TargetGroupTest, RejectsTargetFromAnotherDebugger) {
More information about the lldb-commits
mailing list