From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id E8D833858D38; Sun, 2 Oct 2022 16:27:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8D833858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664728065; bh=SqV4Z2T//usywccU3L86DBkpra6xa1/+Kdm8EPhsKO0=; h=From:To:Subject:Date:From; b=emaSoa4IMD0b/rG9mI2d6DHe/u7GmxC4Rji83pORtSBG2xIvsZtiSncYe5rT3bx9l ZyVKdijhf+qoq3sZkUNmykar2a7srNr8cTFuoyZHOBjBHiNaZKEdMkbPn7a6y/Np1Q OWvorAo4FmH6Is1y2KScNaKguWEnAR1f0GO5rSLQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/gdbarch: add a comment to gdbarch_register_name X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: bd93abe8d5513ceecc10a91452a85c803cac895b X-Git-Newrev: 89e601ac3a2e29da46275a3dcb83855e662fb0c9 Message-Id: <20221002162745.E8D833858D38@sourceware.org> Date: Sun, 2 Oct 2022 16:27:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D89e601ac3a2e= 29da46275a3dcb83855e662fb0c9 commit 89e601ac3a2e29da46275a3dcb83855e662fb0c9 Author: Andrew Burgess Date: Sun Aug 28 21:19:50 2022 +0100 gdb/gdbarch: add a comment to gdbarch_register_name =20 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. =20 I think architectures that don't comply with the API laid out here will fail the gdb.base/completion.exp test. =20 The claims in the comment are I feel, best demonstrated with the asserts in this code: =20 const char * gdbarch_register_name (struct gdbarch *gdbarch, int regnr) { gdb_assert (regnr >=3D 0); gdb_assert (regnr < gdbarch_num_cooked_regs (gdbarch)); =20 const char *name =3D gdbarch->register_name (gdbarch, regnr); =20 gdb_assert (name !=3D nullptr); =20 return name; } =20 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. =20 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 t= his wrong. ) =20 Method( + comment=3D""" +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=3D"const char *", name=3D"register_name", params=3D[("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) (stru= ct gdbarch *gdbarch, int d extern int gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int dwar= f2_regnr); extern void set_gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, gdb= arch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum); =20 +/* 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 *gdbarc= h, int regnr); extern const char * gdbarch_register_name (struct gdbarch *gdbarch, int re= gnr); extern void set_gdbarch_register_name (struct gdbarch *gdbarch, gdbarch_re= gister_name_ftype *register_name);