public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: check for groups with duplicate names in reggroups:add
@ 2022-10-18 14:17 Simon Marchi
  2022-10-18 18:42 ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2022-10-18 14:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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
---
 gdb/reggroups.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/reggroups.c b/gdb/reggroups.c
index 8e4af303c545..a012bf085265 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.38.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-18 14:17 [PATCH] gdb: check for groups with duplicate names in reggroups:add Simon Marchi
@ 2022-10-18 18:42 ` Tom Tromey
  2022-10-18 18:54   ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2022-10-18 18:42 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> In the downstream ROCm GDB port, we would create multiple register
Simon> groups with duplicate names.  While it did not really hurt, it certainly
Simon> wasn't the intent.  And I don't think it ever makes sense to do so.

Simon> To catch these, change the assert in reggroups::add to check for
Simon> duplicate names.  It's no longer necessary to check for duplicate
Simon> reggroup pointers, because adding the same group twice would be caught
Simon> by the duplicate name check.

I haven't looked but would it be possible for malformed XML from the
target to trigger this assert?

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-18 18:42 ` Tom Tromey
@ 2022-10-18 18:54   ` Simon Marchi
  2022-10-18 19:01     ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2022-10-18 18:54 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 10/18/22 14:42, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> In the downstream ROCm GDB port, we would create multiple register
> Simon> groups with duplicate names.  While it did not really hurt, it certainly
> Simon> wasn't the intent.  And I don't think it ever makes sense to do so.
> 
> Simon> To catch these, change the assert in reggroups::add to check for
> Simon> duplicate names.  It's no longer necessary to check for duplicate
> Simon> reggroup pointers, because adding the same group twice would be caught
> Simon> by the duplicate name check.
> 
> I haven't looked but would it be possible for malformed XML from the
> target to trigger this assert?
> 
> Tom

I don't think so, because the target description support code creates
the groups as it finds them while iterating registers.  It only creates
a group if it doesn't exist already:

  https://gitlab.com/gnutools/binutils-gdb/-/blob/152cc35ebff44eb06a00364ca1dbcf5fca6772b4/gdb/target-descriptions.c#L1124-1125

In other words, the XML tdesc doesn't have a list of groups, where if a
group was duplicated, it could trigger this assert.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-18 18:54   ` Simon Marchi
@ 2022-10-18 19:01     ` Tom Tromey
  2022-10-18 20:47       ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2022-10-18 19:01 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Tom Tromey, Simon Marchi

Simon> I don't think so, because the target description support code creates
Simon> the groups as it finds them while iterating registers.

Thanks, in that case this seems like a good idea to me.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-18 19:01     ` Tom Tromey
@ 2022-10-18 20:47       ` Simon Marchi
  2022-10-19  1:54         ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2022-10-18 20:47 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 10/18/22 15:01, Tom Tromey wrote:
> Simon> I don't think so, because the target description support code creates
> Simon> the groups as it finds them while iterating registers.
> 
> Thanks, in that case this seems like a good idea to me.
> 
> Tom

I am asking, because these things are still new, so better safe than
sorry: are you fine with me adding your Approved-By?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-18 20:47       ` Simon Marchi
@ 2022-10-19  1:54         ` Tom Tromey
  2022-10-19  2:12           ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2022-10-19  1:54 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, Simon Marchi via Gdb-patches, Simon Marchi

Simon> I am asking, because these things are still new, so better safe than
Simon> sorry: are you fine with me adding your Approved-By?

Yes, definitely.

thanks,
Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb: check for groups with duplicate names in reggroups:add
  2022-10-19  1:54         ` Tom Tromey
@ 2022-10-19  2:12           ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-10-19  2:12 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Simon Marchi via Gdb-patches, Simon Marchi



On 2022-10-18 21:54, Tom Tromey wrote:
> Simon> I am asking, because these things are still new, so better safe than
> Simon> sorry: are you fine with me adding your Approved-By?
> 
> Yes, definitely.
> 
> thanks,
> Tom

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-19  2:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 14:17 [PATCH] gdb: check for groups with duplicate names in reggroups:add Simon Marchi
2022-10-18 18:42 ` Tom Tromey
2022-10-18 18:54   ` Simon Marchi
2022-10-18 19:01     ` Tom Tromey
2022-10-18 20:47       ` Simon Marchi
2022-10-19  1:54         ` Tom Tromey
2022-10-19  2:12           ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).