public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/gdbarch: add a comment to gdbarch_register_name
@ 2022-10-02 16:27 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-10-02 16:27 UTC (permalink / raw)
  To: gdb-cvs

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

commit 89e601ac3a2e29da46275a3dcb83855e662fb0c9
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Sun Aug 28 21:19:50 2022 +0100

    gdb/gdbarch: add a comment to gdbarch_register_name
    
    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.

Diff:
---
 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 6374240ae4b..9e0a3e99417 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 706dbb3befe..383d84f8142 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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-02 16:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 16:27 [binutils-gdb] gdb/gdbarch: add a comment to gdbarch_register_name Andrew Burgess

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).