[v2] gdb/tdesc: Don't assign custom-group tdesc registers to 'general'

Message ID 20230913114126.23101-1-ciaranwoodward@xmos.com
State New
Headers
Series [v2] gdb/tdesc: Don't assign custom-group tdesc registers to 'general' |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Ciaran Woodward Sept. 13, 2023, 11:41 a.m. UTC
  The 'Target Description' mechanism in GDB enables the target to
supply the full set of registers available on the system to gdb
in an XML format.

This format enables setting the 'group' of each register, such
that they can be queried using the 'info registers <group>'
mechanism.

However prior to this change, even if a register was explicitly
assigned to a group, it would still show up in the
'info registers general' report. This is unexpected, and also
disagrees with the comment above the tdesc_register_in_reggroup_p
function, which says that '-1' should be returned if the register
group is not-known, not the register group is known, but differs.

There was a previous change that did address this issue in
aa66aac47b4dd38f9524ddb5546c08cc09930d37
but it also caused registers with *no* group in the target
description to be removed from 'general', so it was reverted in
440cf44eb0f70830b8d8ac35289f84129c7a35c1
as that behaviour was used by some targets.

The change in this commit enhances the usefulness of the tdesc
'group' attribute for adding system configuration registers,
of which there may be hundreds - very inconvenient to request
and print on every 'info registers' call.
---
 gdb/target-descriptions.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index cdedf88c793..6eb626b9c5a 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -954,13 +954,17 @@  tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
 {
   struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
 
-  if (reg != NULL && !reg->group.empty ()
-      && (reg->group == reggroup->name ()))
+  if (reg != NULL)
+    {
+      if (reggroup == all_reggroup)
 	return 1;
 
-  if (reg != NULL
-      && (reggroup == save_reggroup || reggroup == restore_reggroup))
-    return reg->save_restore;
+      if (reggroup == save_reggroup || reggroup == restore_reggroup)
+	return reg->save_restore;
+
+      if (reg != NULL && !reg->group.empty ())
+	return (reg->group == reggroup->name ());
+    }
 
   return -1;
 }