From 9454c9ce88b25646d279feed329c9cdba69b4905 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 18 Oct 2022 10:17:33 -0400 Subject: [PATCH] gdb: check for groups with duplicate names in reggroups:add In the downstream ROCm GDB port, we would create multiple register groups with duplicate names. While it did not really hurt, it certainly wasn't the intent. And I don't think it ever makes sense to do so. To catch these, change the assert in reggroups::add to check for duplicate names. It's no longer necessary to check for duplicate reggroup pointers, because adding the same group twice would be caught by the duplicate name check. Change-Id: Id216a58acf91f1b314d3cba2d02de73656f8851d Approved-By: Tom Tromey --- gdb/reggroups.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gdb/reggroups.c b/gdb/reggroups.c index 8e4af303c54..a012bf08526 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -71,8 +71,13 @@ struct reggroups void add (const reggroup *group) { gdb_assert (group != nullptr); - gdb_assert (std::find (m_groups.begin(), m_groups.end(), group) - == m_groups.end()); + + auto find_by_name = [group] (const reggroup *g) + { + return streq (group->name (), g->name ()); + }; + gdb_assert (std::find_if (m_groups.begin (), m_groups.end (), find_by_name) + == m_groups.end ()); m_groups.push_back (group); } -- 2.30.2