From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id 699BE3857C56 for ; Fri, 7 Oct 2022 18:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 699BE3857C56 Received: by mail-io1-xd2e.google.com with SMTP id p70so4200832iod.13 for ; Fri, 07 Oct 2022 11:01:35 -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=jEmlNxR1UiMcVfE0Y3GNarlQEAwTYRxqwcrE1FMD9w4=; b=nclMAUUmbqG7dvfElJB9tBTJY/bo38HesNetcIpssyqjOQOal3GaYRXzxpxM/LqHdG RzeIzR0/PMC0PPJJwKytfheBWc5GbIvgx3gSviE0f/+sWTUtmyTwA7u4l3D4EbAt+Wu5 y0rN+J4hSVAUzyNH0FeUzBpNekovcfpB7BCE+/7MgqWqBOf/pD+Tj1Ds0xQ6kOWjhpE6 XIJktYkW0Ozu88taLeqlcaR6dys2pxzm+d7jFgUPbQhUE1qD2q55flD6lipbRwNyn5qJ AUD14XLpRWjTzk0t4e/hbogLb6z0zaKaH0/uCZyXjvCuHIyMCZjAPfuD6zz+xt+TpBii ySDA== X-Gm-Message-State: ACrzQf00yXWTK035J+W7lR41DNYyG00Ima3bSaLqxm59Bjxq4uSKjO4l ZdWFrQPU1hviH7opAiaQbN0U1SQbyNujPA== X-Google-Smtp-Source: AMsMyM5VI8IQ5gjxvgxWCdzdZknGfDkSm3PlTjM5huzIwtyWaUywNMmSwpwnVJor91T2nBw4OQj47w== X-Received: by 2002:a02:6d5d:0:b0:35b:2d20:6be1 with SMTP id e29-20020a026d5d000000b0035b2d206be1mr3125948jaf.266.1665165694497; Fri, 07 Oct 2022 11:01:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 11:01:34 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/9] Convert selected architectures to gdbarch_return_value_as_value Date: Fri, 7 Oct 2022 12:01:17 -0600 Message-Id: <20221007180120.1866772-7-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 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-List-Received-Date: Fri, 07 Oct 2022 18:02:33 -0000 This converts a few selected architectures to use gdbarch_return_value_as_value rather than gdbarch_return_value. The architectures are just the ones that I am able to test. This patch should not introduce any behavior changes. --- gdb/aarch64-tdep.c | 10 ++++++++-- gdb/amd64-tdep.c | 13 ++++++++++--- gdb/amd64-windows-tdep.c | 11 +++++++++-- gdb/arm-tdep.c | 11 +++++++++-- gdb/i386-tdep.c | 21 ++++++++++++++++----- gdb/ppc-linux-tdep.c | 12 ++++++++++-- gdb/riscv-tdep.c | 11 +++++++++-- gdb/sparc-tdep.c | 11 +++++++++-- gdb/sparc64-tdep.c | 1 + 9 files changed, 81 insertions(+), 20 deletions(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 78bf1225e97..6d24f5ab495 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2447,8 +2447,14 @@ aarch64_store_return_value (struct type *type, struct regcache *regs, static enum return_value_convention aarch64_return_value (struct gdbarch *gdbarch, struct value *func_value, struct type *valtype, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + 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 (); + } if (valtype->code () == TYPE_CODE_STRUCT || valtype->code () == TYPE_CODE_UNION @@ -3704,7 +3710,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_dwarf2_reg_to_regnum (gdbarch, aarch64_dwarf_reg_to_regnum); /* Returning results. */ - set_gdbarch_return_value (gdbarch, aarch64_return_value); + set_gdbarch_return_value_as_value (gdbarch, aarch64_return_value); /* Disassembly. */ set_gdbarch_print_insn (gdbarch, aarch64_gdb_print_insn); diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 22d69c85387..c250c07e4ce 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -789,7 +789,7 @@ amd64_classify (struct type *type, enum amd64_reg_class theclass[2]) static enum return_value_convention amd64_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + struct value **read_value, const gdb_byte *writebuf) { enum amd64_reg_class theclass[2]; int len = type->length (); @@ -799,7 +799,14 @@ amd64_return_value (struct gdbarch *gdbarch, struct value *function, int sse_reg = 0; int i; - gdb_assert (!(readbuf && writebuf)); + gdb_assert (!(read_value && writebuf)); + + gdb_byte *readbuf = nullptr; + if (read_value != nullptr) + { + *read_value = allocate_value (type); + readbuf = value_contents_raw (*read_value).data (); + } /* 1. Classify the return type with the classification algorithm. */ amd64_classify (type, theclass); @@ -3236,7 +3243,7 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, set_gdbarch_register_to_value (gdbarch, i387_register_to_value); set_gdbarch_value_to_register (gdbarch, i387_value_to_register); - set_gdbarch_return_value (gdbarch, amd64_return_value); + set_gdbarch_return_value_as_value (gdbarch, amd64_return_value); set_gdbarch_skip_prologue (gdbarch, amd64_skip_prologue); diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c index 8573e4c0676..05a5990f1e0 100644 --- a/gdb/amd64-windows-tdep.c +++ b/gdb/amd64-windows-tdep.c @@ -355,11 +355,18 @@ amd64_windows_push_dummy_call static enum return_value_convention amd64_windows_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + struct value **read_value, const gdb_byte *writebuf) { int len = type->length (); int regnum = -1; + gdb_byte *readbuf = nullptr; + if (read_value != nullptr) + { + *read_value = allocate_value (type); + readbuf = value_contents_raw (*read_value).data (); + } + /* See if our value is returned through a register. If it is, then store the associated register number in REGNUM. */ switch (type->code ()) @@ -1297,7 +1304,7 @@ amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch) /* Function calls. */ set_gdbarch_push_dummy_call (gdbarch, amd64_windows_push_dummy_call); - set_gdbarch_return_value (gdbarch, amd64_windows_return_value); + set_gdbarch_return_value_as_value (gdbarch, amd64_windows_return_value); set_gdbarch_skip_main_prologue (gdbarch, amd64_skip_main_prologue); set_gdbarch_skip_trampoline_code (gdbarch, amd64_windows_skip_trampoline_code); diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index d357066653b..132c10b1ca6 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9008,8 +9008,15 @@ arm_store_return_value (struct type *type, struct regcache *regs, static enum return_value_convention arm_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + 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 (); + } + arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); struct type *func_type = function ? value_type (function) : NULL; enum arm_vfp_cprc_base_type vfp_base_type; @@ -10546,7 +10553,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_register_name (gdbarch, arm_register_name); /* Returning results. */ - set_gdbarch_return_value (gdbarch, arm_return_value); + set_gdbarch_return_value_as_value (gdbarch, arm_return_value); /* Disassembly. */ set_gdbarch_print_insn (gdbarch, gdb_print_insn_arm); diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index a2f0017612b..e609b7c833e 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -3032,10 +3032,17 @@ i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type) static enum return_value_convention i386_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + struct value **read_value, const gdb_byte *writebuf) { enum type_code code = type->code (); + gdb_byte *readbuf = nullptr; + if (read_value != nullptr) + { + *read_value = allocate_value (type); + readbuf = value_contents_raw (*read_value).data (); + } + if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION || code == TYPE_CODE_ARRAY) @@ -3083,9 +3090,13 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function, here. */ if (code == TYPE_CODE_STRUCT && type->num_fields () == 1) { - type = check_typedef (type->field (0).type ()); - return i386_return_value (gdbarch, function, type, regcache, - readbuf, writebuf); + struct type *inner_type = check_typedef (type->field (0).type ()); + enum return_value_convention result + = i386_return_value (gdbarch, function, inner_type, regcache, + read_value, writebuf); + if (read_value != nullptr) + deprecated_set_value_type (*read_value, type); + return result; } if (readbuf) @@ -8574,7 +8585,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_register_to_value (gdbarch, i386_register_to_value); set_gdbarch_value_to_register (gdbarch, i386_value_to_register); - set_gdbarch_return_value (gdbarch, i386_return_value); + set_gdbarch_return_value_as_value (gdbarch, i386_return_value); set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue); diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 96eb931743f..2ea838acef1 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -249,8 +249,15 @@ ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch, static enum return_value_convention ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + 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 (); + } + if ((valtype->code () == TYPE_CODE_STRUCT || valtype->code () == TYPE_CODE_UNION) && !((valtype->length () == 16 || valtype->length () == 8) @@ -2094,7 +2101,8 @@ ppc_linux_init_abi (struct gdbarch_info info, (well ignoring vectors that is). When this was corrected, it wasn't fixed for GNU/Linux native platform. Use the PowerOpen struct convention. */ - set_gdbarch_return_value (gdbarch, ppc_linux_return_value); + set_gdbarch_return_value_as_value (gdbarch, ppc_linux_return_value); + set_gdbarch_return_value (gdbarch, nullptr); set_gdbarch_memory_remove_breakpoint (gdbarch, ppc_linux_memory_remove_breakpoint); diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index feca17d9141..ed92ff67c7b 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -3221,13 +3221,20 @@ riscv_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, - gdb_byte *readbuf, + struct value **read_value, const gdb_byte *writebuf) { struct riscv_call_info call_info (gdbarch); struct riscv_arg_info info; struct type *arg_type; + gdb_byte *readbuf = nullptr; + if (read_value != nullptr) + { + *read_value = allocate_value (type); + readbuf = value_contents_raw (*read_value).data (); + } + arg_type = check_typedef (type); riscv_arg_location (gdbarch, &info, &call_info, arg_type, false); @@ -3889,7 +3896,7 @@ riscv_gdbarch_init (struct gdbarch_info info, set_gdbarch_type_align (gdbarch, riscv_type_align); /* Information about the target architecture. */ - set_gdbarch_return_value (gdbarch, riscv_return_value); + set_gdbarch_return_value_as_value (gdbarch, riscv_return_value); set_gdbarch_breakpoint_kind_from_pc (gdbarch, riscv_breakpoint_kind_from_pc); set_gdbarch_sw_breakpoint_from_kind (gdbarch, riscv_sw_breakpoint_from_kind); set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c index 320f898eb98..bbb98ef5ed7 100644 --- a/gdb/sparc-tdep.c +++ b/gdb/sparc-tdep.c @@ -1497,10 +1497,17 @@ sparc32_store_return_value (struct type *type, struct regcache *regcache, static enum return_value_convention sparc32_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, - gdb_byte *readbuf, const gdb_byte *writebuf) + struct value **read_value, const gdb_byte *writebuf) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + gdb_byte *readbuf = nullptr; + if (read_value != nullptr) + { + *read_value = allocate_value (type); + readbuf = value_contents_raw (*read_value).data (); + } + /* The psABI says that "...every stack frame reserves the word at %fp+64. If a function returns a structure, union, or quad-precision value, this word should hold the address of the @@ -1854,7 +1861,7 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_push_dummy_code (gdbarch, sparc32_push_dummy_code); set_gdbarch_push_dummy_call (gdbarch, sparc32_push_dummy_call); - set_gdbarch_return_value (gdbarch, sparc32_return_value); + set_gdbarch_return_value_as_value (gdbarch, sparc32_return_value); set_gdbarch_stabs_argument_has_addr (gdbarch, sparc32_stabs_argument_has_addr); diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c index 6b9d9eaa957..8cd0b2df82b 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -1838,6 +1838,7 @@ sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call); set_gdbarch_return_value (gdbarch, sparc64_return_value); + set_gdbarch_return_value_as_value (gdbarch, default_gdbarch_return_value); set_gdbarch_stabs_argument_has_addr (gdbarch, default_stabs_argument_has_addr); -- 2.34.3