From patchwork Fri Oct 7 18:01:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 58535 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B53938983A2 for ; Fri, 7 Oct 2022 18:02:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B53938983A2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665165726; bh=sor3zxUe5EI35bVAQHVA8OpFDvotSRG1pxDbnQXYHnc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=dxYJ1Cu2ko+JPMq66cm2UNqWrkFj2Kq1zvyxPjqLN0MPmj52leLIV/ioU5wtHPQ9i KWPqIxVxcjNYSh9Lgf1yeBn5RaarKexQNfCyX2BN6UlfWowvdUzco82NpUDqWCQ8h1 cAHGftCdDWmeBlzzHjUUzJ/7sTQLo0hNGhyGN/fs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 29B8B3858C20 for ; Fri, 7 Oct 2022 18:01:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29B8B3858C20 Received: by mail-il1-x12f.google.com with SMTP id u2so2886605ilv.6 for ; Fri, 07 Oct 2022 11:01:33 -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:message-id:reply-to; bh=sor3zxUe5EI35bVAQHVA8OpFDvotSRG1pxDbnQXYHnc=; b=3KvNXpovrZpB04P9H7Lp8PeD9yTUgWt1DUXr9CJBdWirb1DogwgrCvF1W1F5bPnciY cG0qBIWdI5sFiFREseuVgZgDwDjOVIQGQWASJxdJBqB9dm0KWuv8omWwp3s8c3J8Kxgv jrXWNN9MT+fx9W0sz46Clmx/KHx8Cw4aCXMsZ8sGQwzx2eMtkx/sMElEsp9FKCI9Gc1Y 8FOCDZY+i5Vu0j6rRUoHgJW4c85ck0wvAQFl7xNYaHJ07jFlGMCHOoyiEkAG/sH/cQw2 caIXaUH3ki1EammN7zUtugrbN2gG67mnrS1Rea8oHiNJ7Mnmo9NzQupKf7zu/ii4dXn+ 7R/A== X-Gm-Message-State: ACrzQf3QbqRj/j3cQ+6sgyiAisUe7LQJ70YqaNEQH5iIN2/BJbj5XMjZ d980ayYje4YnPcOCIM8Ptf9PqPJsG3FdbA== X-Google-Smtp-Source: AMsMyM4IvFzMwLI2cgkuGxhgxHtRIqxu6LUcOdnzUfZDxPQRVCAdwwG5rwUZ4/fGinpuZaQMm7UGGQ== X-Received: by 2002:a92:c566:0:b0:2f5:f3f4:f978 with SMTP id b6-20020a92c566000000b002f5f3f4f978mr2969899ilj.8.1665165692312; Fri, 07 Oct 2022 11:01:32 -0700 (PDT) Received: from localhost.localdomain (71-211-160-49.hlrn.qwest.net. [71.211.160.49]) by smtp.gmail.com with ESMTPSA id h11-20020a056602154b00b006814fd71117sm1203228iow.12.2022.10.07.11.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 11:01:31 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 3/9] Don't emit gdbarch_return_value Date: Fri, 7 Oct 2022 12:01:14 -0600 Message-Id: <20221007180120.1866772-4-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221007180120.1866772-1-tromey@adacore.com> References: <20221007180120.1866772-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Cc: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The previous patch introduced a new overload of gdbarch_return_value. The intent here is that this new overload always be called by the core of gdb -- the previous implementation is effectively deprecated, because a call to the old-style method will not work with any converted architectures (whereas calling the new-style method is will delegate when needed). This patch changes gdbarch.py so that the old gdbarch_return_value wrapper function can be omitted. This will prevent any errors from creeping in. --- gdb/arch-utils.c | 36 ++++++++++---------- gdb/gdbarch-components.py | 6 ++++ gdb/gdbarch-gen.h | 1 - gdb/gdbarch.c | 10 ------ gdb/gdbarch.py | 70 +++++++++++++++++++++------------------ 5 files changed, 61 insertions(+), 62 deletions(-) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 677e405fd6c..cce0bf809f5 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1092,24 +1092,6 @@ default_read_core_file_mappings { } -enum return_value_convention -default_gdbarch_return_value - (struct gdbarch *gdbarch, struct value *function, struct type *valtype, - struct regcache *regcache, struct value **read_value, - const gdb_byte *writebuf) -{ - gdb_byte *readbuf = nullptr; - - if (read_value != nullptr) - { - *read_value = allocate_value (valtype); - readbuf = value_contents_raw (*read_value).data (); - } - - return gdbarch_return_value (gdbarch, function, valtype, regcache, - readbuf, writebuf); -} - /* Non-zero if we want to trace architecture code. */ #ifndef GDBARCH_DEBUG @@ -1180,6 +1162,24 @@ pstring_list (const char *const *list) #include "gdbarch.c" +enum return_value_convention +default_gdbarch_return_value + (struct gdbarch *gdbarch, struct value *function, struct type *valtype, + struct regcache *regcache, struct value **read_value, + const gdb_byte *writebuf) +{ + gdb_byte *readbuf = nullptr; + + if (read_value != nullptr) + { + *read_value = allocate_value (valtype); + readbuf = value_contents_raw (*read_value).data (); + } + + return gdbarch->return_value (gdbarch, function, valtype, regcache, + readbuf, writebuf); +} + obstack *gdbarch_obstack (gdbarch *arch) { return &arch->obstack; diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py index 844eb4f161d..3b0f62e334d 100644 --- a/gdb/gdbarch-components.py +++ b/gdb/gdbarch-components.py @@ -113,6 +113,9 @@ # 'result' can be used to reference the result of the function/method # implementation. The 'result_checks' can only be used if the 'type' # of this Function/Method is not 'void'. +# +# * "implement" - optional, a boolean. If True (the default), a +# wrapper function for this function will be emitted. Info( type="const struct bfd_arch_info *", @@ -868,6 +871,9 @@ method can properly handle variably-sized types. ("const gdb_byte *", "writebuf"), ], invalid=False, + # We don't want to accidentally introduce calls to this, as gdb + # should only ever call return_value_new (see below). + implement=False, ) Method( diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 4ec11fd4eee..059865e86f7 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -439,7 +439,6 @@ extern void set_gdbarch_integer_to_address (struct gdbarch *gdbarch, gdbarch_int method can properly handle variably-sized types. */ typedef enum return_value_convention (gdbarch_return_value_ftype) (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf); -extern enum return_value_convention gdbarch_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf); extern void set_gdbarch_return_value (struct gdbarch *gdbarch, gdbarch_return_value_ftype *return_value); /* Return the return-value convention that will be used by FUNCTION diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 911aa0ec277..3c7e99e0874 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -2664,16 +2664,6 @@ set_gdbarch_integer_to_address (struct gdbarch *gdbarch, gdbarch->integer_to_address = integer_to_address; } -enum return_value_convention -gdbarch_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) -{ - gdb_assert (gdbarch != NULL); - gdb_assert (gdbarch->return_value != NULL); - if (gdbarch_debug >= 2) - gdb_printf (gdb_stdlog, "gdbarch_return_value called\n"); - return gdbarch->return_value (gdbarch, function, valtype, regcache, readbuf, writebuf); -} - void set_gdbarch_return_value (struct gdbarch *gdbarch, gdbarch_return_value_ftype return_value) diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py index da848feae84..df01dd11c05 100755 --- a/gdb/gdbarch.py +++ b/gdb/gdbarch.py @@ -119,6 +119,7 @@ class Function(_Component): printer=None, param_checks=None, result_checks=None, + implement=True, ): super().__init__( comment=comment, @@ -132,6 +133,7 @@ class Function(_Component): params=params, param_checks=param_checks, result_checks=result_checks, + implement=implement, ) def ftype(self): @@ -246,10 +248,11 @@ with open("gdbarch-gen.h", "w") as f: f"typedef {c.type} ({c.ftype()}) ({c.param_list()});", file=f, ) - print( - f"extern {c.type} gdbarch_{c.name} ({c.set_list()});", - file=f, - ) + if c.implement: + print( + f"extern {c.type} gdbarch_{c.name} ({c.set_list()});", + file=f, + ) print( f"extern void set_gdbarch_{c.name} (struct gdbarch *gdbarch, {c.ftype()} *{c.name});", file=f, @@ -441,38 +444,39 @@ with open("gdbarch.c", "w") as f: print(f" return {c.get_predicate()};", file=f) print("}", file=f) if isinstance(c, Function): - print(file=f) - print(f"{c.type}", file=f) - print(f"gdbarch_{c.name} ({c.set_list()})", file=f) - print("{", file=f) - print(" gdb_assert (gdbarch != NULL);", file=f) - print(f" gdb_assert (gdbarch->{c.name} != NULL);", file=f) - if c.predicate and c.predefault: - # Allow a call to a function with a predicate. + if c.implement: + print(file=f) + print(f"{c.type}", file=f) + print(f"gdbarch_{c.name} ({c.set_list()})", file=f) + print("{", file=f) + print(" gdb_assert (gdbarch != NULL);", file=f) + print(f" gdb_assert (gdbarch->{c.name} != NULL);", file=f) + if c.predicate and c.predefault: + # Allow a call to a function with a predicate. + print( + f" /* Do not check predicate: {c.get_predicate()}, allow call. */", + file=f, + ) + if c.param_checks: + for rule in c.param_checks: + print(f" gdb_assert ({rule});", file=f) + print(" if (gdbarch_debug >= 2)", file=f) print( - f" /* Do not check predicate: {c.get_predicate()}, allow call. */", + f""" gdb_printf (gdb_stdlog, "gdbarch_{c.name} called\\n");""", file=f, ) - if c.param_checks: - for rule in c.param_checks: - print(f" gdb_assert ({rule});", file=f) - print(" if (gdbarch_debug >= 2)", file=f) - print( - f""" gdb_printf (gdb_stdlog, "gdbarch_{c.name} called\\n");""", - file=f, - ) - print(" ", file=f, end="") - if c.type != "void": - if c.result_checks: - print("auto result = ", file=f, end="") - else: - print("return ", file=f, end="") - print(f"gdbarch->{c.name} ({c.actuals()});", file=f) - if c.type != "void" and c.result_checks: - for rule in c.result_checks: - print(f" gdb_assert ({rule});", file=f) - print(" return result;", file=f) - print("}", file=f) + print(" ", file=f, end="") + if c.type != "void": + if c.result_checks: + print("auto result = ", file=f, end="") + else: + print("return ", file=f, end="") + print(f"gdbarch->{c.name} ({c.actuals()});", file=f) + if c.type != "void" and c.result_checks: + for rule in c.result_checks: + print(f" gdb_assert ({rule});", file=f) + print(" return result;", file=f) + print("}", file=f) print(file=f) print("void", file=f) print(f"set_gdbarch_{c.name} (struct gdbarch *gdbarch,", file=f)