public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 7/9] gdb/csky: remove nullptr return from csky_pseudo_register_name
Date: Thu,  1 Sep 2022 22:31:15 +0100	[thread overview]
Message-ID: <5beaa5051ffccb148e1e02cbd36f0317c2a46253.1662067442.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1662067442.git.aburgess@redhat.com>

Building on the previous commits, in this commit I remove two
instances of 'return NULL' from csky_pseudo_register_name, and replace
them with a return of the empty string.

These two are particularly interesting, and worth pulling into their
own commit, because these returns of NULL appear to be depended on
within other parts of the csky code.

In csky-linux-tdep.c in the register collect/supply code, GDB checks
for the register name being nullptr in order to decide if a target
supports a particular feature or not.  I've updated the code to check
for the empty string.

I have no way of testing this change.
---
 gdb/csky-linux-tdep.c | 14 +++++++-------
 gdb/csky-tdep.c       | 17 ++++-------------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/gdb/csky-linux-tdep.c b/gdb/csky-linux-tdep.c
index 7bcc1712180..ea306cded09 100644
--- a/gdb/csky-linux-tdep.c
+++ b/gdb/csky-linux-tdep.c
@@ -155,7 +155,7 @@ csky_supply_fregset (const struct regset *regset,
       /* Supply vr0~vr15.  */
       for (i = 0; i < 16; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, (CSKY_VR0_REGNUM + i)))
+	  if (*gdbarch_register_name (gdbarch, (CSKY_VR0_REGNUM + i)) != '\0')
 	    {
 	      offset = 16 * i;
 	      regcache->raw_supply (CSKY_VR0_REGNUM + i, fregs + offset);
@@ -164,7 +164,7 @@ csky_supply_fregset (const struct regset *regset,
       /* Supply fr0~fr15.  */
       for (i = 0; i < 16; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, (CSKY_FR0_REGNUM + i)))
+	  if (*gdbarch_register_name (gdbarch, (CSKY_FR0_REGNUM + i)) != '\0')
 	    {
 	      offset = 16 * i;
 	      regcache->raw_supply (CSKY_FR0_REGNUM + i, fregs + offset);
@@ -173,7 +173,7 @@ csky_supply_fregset (const struct regset *regset,
       /* Supply fr16~fr31.  */
       for (i = 0; i < 16; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, (CSKY_FR16_REGNUM + i)))
+	  if (*gdbarch_register_name (gdbarch, (CSKY_FR16_REGNUM + i)) != '\0')
 	    {
 	      offset = (16 * 16) + (8 * i);
 	      regcache->raw_supply (CSKY_FR16_REGNUM + i, fregs + offset);
@@ -182,7 +182,7 @@ csky_supply_fregset (const struct regset *regset,
      /* Supply fcr, fesr, fid.  */
       for (i = 0; i < 3; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, fcr_regno[i]))
+	  if (*gdbarch_register_name (gdbarch, fcr_regno[i]) != '\0')
 	    {
 	      offset = (16 * 16) + (16 * 8) + (4 * i);
 	      regcache->raw_supply (fcr_regno[i], fregs + offset);
@@ -245,7 +245,7 @@ csky_collect_fregset (const struct regset *regset,
       /* Supply vr0~vr15.  */
       for (i = 0; i < 16; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, (CSKY_VR0_REGNUM + i)))
+	  if (*gdbarch_register_name (gdbarch, (CSKY_VR0_REGNUM + i)) != '\0')
 	    {
 	      offset = 16 * i;
 	      regcache ->raw_collect (CSKY_VR0_REGNUM + i, fregs + offset);
@@ -254,7 +254,7 @@ csky_collect_fregset (const struct regset *regset,
       /* Supply fr16~fr31.  */
       for (i = 0; i < 16; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, (CSKY_FR16_REGNUM + i)))
+	  if (*gdbarch_register_name (gdbarch, (CSKY_FR16_REGNUM + i)) != '\0')
 	    {
 	      offset = (16 * 16) + (8 * i);
 	      regcache ->raw_collect (CSKY_FR16_REGNUM + i, fregs + offset);
@@ -263,7 +263,7 @@ csky_collect_fregset (const struct regset *regset,
       /* Supply fcr, fesr, fid.  */
       for (i = 0; i < 3; i ++)
 	{
-	  if (gdbarch_register_name (gdbarch, fcr_regno[i]))
+	  if (*gdbarch_register_name (gdbarch, fcr_regno[i]) != '\0')
 	    {
 	      offset = (16 * 16) + (16 * 8) + (4 * i);
 	      regcache ->raw_collect (fcr_regno[i], fregs + offset);
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index ba53c1b10ca..51336148b6d 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -660,21 +660,12 @@ static const char * const csky_register_names[] =
 static const char *
 csky_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  int num_regs = gdbarch_num_regs (gdbarch);
-  int num_pseudo_regs =  gdbarch_num_pseudo_regs (gdbarch);
-
-  if ((reg_nr >= num_regs) && (reg_nr < (num_regs + num_pseudo_regs)))
+  if (reg_nr >= gdbarch_num_regs (gdbarch))
     return csky_pseudo_register_name (gdbarch, reg_nr);
 
   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
     return tdesc_register_name (gdbarch, reg_nr);
 
-  if (reg_nr < 0)
-    return NULL;
-
-  if (reg_nr >= gdbarch_num_regs (gdbarch))
-    return NULL;
-
   return csky_register_names[reg_nr];
 }
 
@@ -2712,15 +2703,15 @@ csky_pseudo_register_name (struct gdbarch *gdbarch, int regno)
       if (regno < tdep->fv_pseudo_registers_count)
         {
           if ((regno < 64) && ((regno % 4) >= 2) && !tdep->has_vr0)
-            return NULL;
+            return "";
           else if ((regno >= 64) && ((regno % 4) >= 2))
-            return NULL;
+            return "";
           else
             return fv_pseudo_names[regno];
         }
     }
 
-  return NULL;
+  return "";
 }
 
 /* Read for csky pseudo regs.  */
-- 
2.25.4


  parent reply	other threads:[~2022-09-01 21:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01 21:31 [PATCH 0/9] Lots of changes to gdbarch_register_name (many architectures) Andrew Burgess
2022-09-01 21:31 ` [PATCH 1/9] gdb/testsuite: rewrite capture_command_output proc Andrew Burgess
2022-09-01 21:31 ` [PATCH 2/9] gdb/riscv: fix failure in gdb.base/completion.exp Andrew Burgess
2022-09-01 21:31 ` [PATCH 3/9] gdb/gdbarch: add a comment to gdbarch_register_name Andrew Burgess
2022-09-01 21:31 ` [PATCH 4/9] gdb: add a gdbarch_register_name self test, and fix some architectures Andrew Burgess
2022-09-01 21:31 ` [PATCH 5/9] gdb: check for duplicate register names in selftest Andrew Burgess
2022-09-01 21:31 ` [PATCH 6/9] gdb: add asserts to gdbarch_register_name Andrew Burgess
2022-09-21 18:04   ` Tom Tromey
2022-09-01 21:31 ` Andrew Burgess [this message]
2022-09-01 21:31 ` [PATCH 8/9] gdb: final cleanup of various gdbarch_register_name methods Andrew Burgess
2022-09-01 21:31 ` [PATCH 9/9] gdb: update now gdbarch_register_name doesn't return nullptr Andrew Burgess
2022-09-21 18:07 ` [PATCH 0/9] Lots of changes to gdbarch_register_name (many architectures) Tom Tromey
2022-10-02 16:28   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5beaa5051ffccb148e1e02cbd36f0317c2a46253.1662067442.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).