public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb/csky: remove nullptr return from csky_pseudo_register_name
Date: Sun,  2 Oct 2022 16:28:06 +0000 (GMT)	[thread overview]
Message-ID: <20221002162806.3BE183858D38@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7ac20d65a8d0c9cdb329d49e8d9e58e38c39fec4

commit 7ac20d65a8d0c9cdb329d49e8d9e58e38c39fec4
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu Sep 1 15:39:59 2022 +0100

    gdb/csky: remove nullptr return from csky_pseudo_register_name
    
    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.

Diff:
---
 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 cbf12c18063..17820aab6eb 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];
 }
 
@@ -2543,15 +2534,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.  */

                 reply	other threads:[~2022-10-02 16:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221002162806.3BE183858D38@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@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).