From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id A6DBC3858D39; Wed, 19 Oct 2022 02:12:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6DBC3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666145546; bh=rGVmVJ64ZV8Ig9X4t9hRdVHD/mHjCjwB3MvV4tz9Kq0=; h=From:To:Subject:Date:From; b=vGwOzI6h9vnbr1I9PPeF6qL0q8sHuRXv9RaH3hTBETyEFZoijfS+bOsP9FNCok0xc Fa2ynUJBe9f1C7BIKLnzlswfDq+E/xTUEJ9P0tZbkgaKeCVXKtepanhbZ5znkK+J+3 pEJnjOqNeuSIMx4IP29wlAyotwnqGIhwLPr1wb/0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: check for groups with duplicate names in reggroups:add X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: fd320c4c29c9a1915d24a68a167a5fd6d2c27e60 X-Git-Newrev: 9454c9ce88b25646d279feed329c9cdba69b4905 Message-Id: <20221019021226.A6DBC3858D39@sourceware.org> Date: Wed, 19 Oct 2022 02:12:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9454c9ce88b2= 5646d279feed329c9cdba69b4905 commit 9454c9ce88b25646d279feed329c9cdba69b4905 Author: Simon Marchi Date: Tue Oct 18 10:17:33 2022 -0400 gdb: check for groups with duplicate names in reggroups:add =20 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. =20 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. =20 Change-Id: Id216a58acf91f1b314d3cba2d02de73656f8851d Approved-By: Tom Tromey Diff: --- 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 !=3D nullptr); - gdb_assert (std::find (m_groups.begin(), m_groups.end(), group) - =3D=3D m_groups.end()); + + auto find_by_name =3D [group] (const reggroup *g) + { + return streq (group->name (), g->name ()); + }; + gdb_assert (std::find_if (m_groups.begin (), m_groups.end (), find_by_= name) + =3D=3D m_groups.end ()); =20 m_groups.push_back (group); }