From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4EEDC3858C62 for ; Thu, 1 Sep 2022 21:31:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4EEDC3858C62 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-456-6OmC5GY-PLOmsT-bzpkqEA-1; Thu, 01 Sep 2022 17:31:27 -0400 X-MC-Unique: 6OmC5GY-PLOmsT-bzpkqEA-1 Received: by mail-wm1-f71.google.com with SMTP id i7-20020a1c3b07000000b003a534ec2570so1843753wma.7 for ; Thu, 01 Sep 2022 14:31:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=UAENUSJZMh56KWniLV5PsNdFVJl0oP6vtk5jMOKUbkE=; b=j9vSZ/VoO/0hS/HDsbPNd9m16AjHlBS5hlY1jgpDmyo9daXTNI2xXCfjHaeWA4a225 9HyYywNjG1uOL6UmbzH+kZRXhNms6cRk0RvhKCKgSBJX7eBhgfJ9NYQippqoA/iS+POs XCP9KatV2aH5hDRuvBNI8hOIkF1yoUA3F0C2tPsU1h97jVlTWFyQfp4gI1rph2M/F08c +c8zqu6c2bBqtCT1dFfUiqvi70dF6yekQ0xAbyfsQZNLRO/CCEpyTI8p6vkLC3BeGXj2 yflf0VXGg50KPFcJr0TpH4J+cBcBC6cl6IzJLSC7fGJvsV/h1fiNB/rUaANi5PCBKuP9 aTTQ== X-Gm-Message-State: ACgBeo0o8aTBQWMdcI5A59gk8PxjT+wuUKdv6sVq4K6S3Ot/RA3ufd7x nuWci9MIXmsLoE6ENEwL701W2zK1CLtKUnttnW3v4L1/Rf/aHWgMJcNIhRYqK+zCjSg2m/GQ2lp ixDnf8nsHM10bdQISfmwfAY9oDmFrroK/lTIxLhxhomk0cFtr+ydZ6VYQ9kFRihEBOB5RNQ1qhg == X-Received: by 2002:a05:600c:3d93:b0:3a5:eb9b:b495 with SMTP id bi19-20020a05600c3d9300b003a5eb9bb495mr615846wmb.91.1662067885104; Thu, 01 Sep 2022 14:31:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+mgZSImcqoANr8PvC8COw6XCqwuuTQmHjESdm4VLmm8Z4Gd+wNA1YGXPLBk8c7af/FBgFJA== X-Received: by 2002:a05:600c:3d93:b0:3a5:eb9b:b495 with SMTP id bi19-20020a05600c3d9300b003a5eb9bb495mr615830wmb.91.1662067884799; Thu, 01 Sep 2022 14:31:24 -0700 (PDT) Received: from localhost ([31.111.84.229]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c304500b003a5de95b105sm6257779wmh.41.2022.09.01.14.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 14:31:24 -0700 (PDT) From: Andrew Burgess 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 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2022 21:31:31 -0000 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