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 3/9] gdb/gdbarch: add a comment to gdbarch_register_name
Date: Thu,  1 Sep 2022 22:31:11 +0100	[thread overview]
Message-ID: <cc34cb57379d57f868e63b48430f283cc92fafbe.1662067442.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1662067442.git.aburgess@redhat.com>

After the previous commit, this commit sets out to formalise the API
for gdbarch_register_name.  Not every architecture is actually in
compliance with the API I set out here, but I believe that most are.

I think architectures that don't comply with the API laid out here
will fail the gdb.base/completion.exp test.

The claims in the comment are I feel, best demonstrated with the
asserts in this code:

  const char *
  gdbarch_register_name (struct gdbarch *gdbarch, int regnr)
  {
    gdb_assert (regnr >= 0);
    gdb_assert (regnr < gdbarch_num_cooked_regs (gdbarch));

    const char *name = gdbarch->register_name (gdbarch, regnr);

    gdb_assert (name != nullptr);

    return name;
  }

Like I said, I don't believe every architecture follows these rules
right now, which is why I'm not actually adding any asserts.  Instead,
this commit adds a comment to gdbarch_register_name, this comment is
where I'd like to get to, rather than where we are right now.

Subsequent commits will fix all targets to be in compliance with this
comment, and will even add the asserts shown above to
gdbarch_register_name.
---
 gdb/gdbarch-components.py | 7 +++++++
 gdb/gdbarch-gen.h         | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py
index 71aa5991fbe..fcef090c2eb 100644
--- a/gdb/gdbarch-components.py
+++ b/gdb/gdbarch-components.py
@@ -558,6 +558,13 @@ Return -1 for bad REGNUM.  Note: Several targets get this wrong.
 )
 
 Method(
+    comment="""
+Return the name of register REGNR for the specified architecture.
+REGNR can be any value greater than, or equal to zero, and less than
+'gdbarch_num_cooked_regs (GDBARCH)'.  If REGNR is not supported for
+GDBARCH, then this function will return an empty string, this function
+should never return nullptr.
+""",
     type="const char *",
     name="register_name",
     params=[("int", "regnr")],
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 0504962e50d..a3df62536c6 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -288,6 +288,12 @@ typedef int (gdbarch_dwarf2_reg_to_regnum_ftype) (struct gdbarch *gdbarch, int d
 extern int gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int dwarf2_regnr);
 extern void set_gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, gdbarch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum);
 
+/* Return the name of register REGNR for the specified architecture.
+   REGNR can be any value greater than, or equal to zero, and less than
+   'gdbarch_num_cooked_regs (GDBARCH)'.  If REGNR is not supported for
+   GDBARCH, then this function will return an empty string, this function
+   should never return nullptr. */
+
 typedef const char * (gdbarch_register_name_ftype) (struct gdbarch *gdbarch, int regnr);
 extern const char * gdbarch_register_name (struct gdbarch *gdbarch, int regnr);
 extern void set_gdbarch_register_name (struct gdbarch *gdbarch, gdbarch_register_name_ftype *register_name);
-- 
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 ` Andrew Burgess [this message]
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 ` [PATCH 7/9] gdb/csky: remove nullptr return from csky_pseudo_register_name Andrew Burgess
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=cc34cb57379d57f868e63b48430f283cc92fafbe.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).