From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ciBhKHLJqWK4VgIAWB0awg (envelope-from ) for ; Wed, 15 Jun 2022 07:58:42 -0400 Received: by simark.ca (Postfix, from userid 112) id 8FADD1E224; Wed, 15 Jun 2022 07:58:42 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ks4fdpn5; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B8D261E15D for ; Wed, 15 Jun 2022 07:58:41 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2713383B7A9 for ; Wed, 15 Jun 2022 11:58:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2713383B7A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655294321; bh=PyDZ/qfwNyO+6uFG6pIIIxmZPm5g0a1RHX3ZkFTtREI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ks4fdpn5FU6Wmxjb+Ot3OHhK7akLFC/FDP8gWmghsO1GqfLkgn09N63rkIcO8k+1D FqWVZx8rp4nOjBFtZxcXNxwfya0/f2eEUXRKwNtzf6ymxiZ9MnNrRc0XHbsf2ote2w 9E8Ga7Co3sIf61R//5YpytJcJYPu/6ysY/4PRnxk= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D57CE385734C for ; Wed, 15 Jun 2022 11:58:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D57CE385734C Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1A55E21C19; Wed, 15 Jun 2022 11:58:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F007D139F3; Wed, 15 Jun 2022 11:58:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WKdhOVvJqWInfgAAMHmgww (envelope-from ); Wed, 15 Jun 2022 11:58:19 +0000 Date: Wed, 15 Jun 2022 13:58:18 +0200 To: gdb-patches@sourceware.org Subject: [RFC][gdb] gdbarch_return_value selftest, powerpc failures Message-ID: <20220615115816.GA17077@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Ulrich Weigand Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, In PR29247 the following assert was reported: ... (gdb) p t_structs_ldc(struct_val1)^M gdb/ppc-sysv-tdep.c:1945: internal-error: ppc64_sysv_abi_return_value: \ Assertion `ok' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ... I had trouble finding a machine to easily reproduce this on, so I tried to write a selftest that calls gdbarch_return_value for a function returning a complex long double, for all arch/osabi combinations. This allowed me to hit the same assert (though I can't be sure yet it's the same root cause). I also hit a couple of other asserts. Interestingly, only for powerpc archs do we hit asserts, all other targets pass. By turning the asserts into errors (included in this patch for demonstration purposes), catching them in the selftest and printing them as warning in arch/osabi:fn:assert format, we get an overview of where things go wrong: ... $ gdb -q -batch -ex "maint selftest gdbarch_return_value" 2>&1 | grep warning: warning: powerpc:620/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:620/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:620/NetBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:620/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:630/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:630/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:630/NetBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:630/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:a35/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:a35/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:a35/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:common64/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:common64/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:common64/NetBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:common64/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:e500/AIX:rs6000_return_value: !ppc_floating_point_unit_p (gdbarch) warning: powerpc:e500/LynxOS178:rs6000_lynx178_return_value: !ppc_floating_point_unit_p (gdbarch) warning: powerpc:rs64ii/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:rs64ii/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:rs64ii/NetBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:rs64ii/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:rs64iii/none:ppc64_sysv_abi_return_value: !ok warning: powerpc:rs64iii/FreeBSD:ppc64_sysv_abi_return_value: !ok warning: powerpc:rs64iii/NetBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 warning: powerpc:rs64iii/OpenBSD:do_ppc_sysv_return_value: tdep->wordsize != 4 ... There are three clusters: - 'ppc64_sysv_abi_return_value: !ok' For osabi none and FreeBSD, and some 64-bit powerpc archs. - 'do_ppc_sysv_return_value: tdep->wordsize != 4' For osabi NetBSD and OpenBSD and the same set of 64-bit powerpc archs. - 'rs6000{,_lynx178}_return_value: !ppc_floating_point_unit_p (gdbarch)' For osabi AIX and LynxOS178, and arch e500. Based on the information from the selftest, I then managed to reproduce the first cluster outside a selftest context using: ... $ gdb -q -batch ./outputs/gdb.base/callfuncs/callfuncs \ -ex "start" \ -ex "set osabi none" \ -ex "p t_structs_ldc(struct_val1)" ... on a power9 machine with arch set to auto/powerpc:common64", and after rebuilding with --enable-targets=all I managed the same with osabi FreeBSD. Likewise for the second cluster, using "set osabi NetBSD/OpenBSD". I didn't manage to reproduce the third cluster. Using LynxOS178 and "set arch powerpc:e500" doesn't trigger an assert, AFAICT because "set arch powerpc:e500" doesn't make "ppc_floating_point_unit_p (gdbarch)" return false, so that probably needs a setup with an actual e500 executable. Using AIX, I run into a SIGSEGV: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. 0x0000000010bc4930 in xcoff_get_toc_offset (objfile=0x12874730) at \ src/gdb/xcoffread.c:2848 2848 return XCOFF_DATA (objfile)->toc_offset; (gdb) up ... because of trying to dereference XCOFF_DATA (objfile) which is a nullptr: ... (gdb) p xcoff_objfile_data_key.get (objfile) $6 = (xcoff_symfile_info *) 0x0 ... So, it looks like at least the first two clusters, and the SIGSEGV need fixing. As for the third cluster, if we want to commit this selftest, we'll either need to explicitly skip that case, or also fix it. Any comments on the selftest, or how to fix the asserts/SIGSEGV are welcome. Thanks, - Tom [gdb] gdbarch_return_value selftest, powerpc failures --- gdb/gdbarch-selftests.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ gdb/ppc-sysv-tdep.c | 12 ++++++++---- gdb/rs6000-aix-tdep.c | 3 ++- gdb/rs6000-lynx178-tdep.c | 3 ++- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c index 198346bddec..3959d727e3b 100644 --- a/gdb/gdbarch-selftests.c +++ b/gdb/gdbarch-selftests.c @@ -122,6 +122,53 @@ register_to_value_test (struct gdbarch *gdbarch) } } +static void +gdbarch_return_value (struct gdbarch *gdbarch) +{ + const char *name = gdbarch_bfd_arch_info (gdbarch)->printable_name; + + struct type *t = builtin_type (gdbarch)->builtin_long_double; + struct type *c = init_complex_type ("complex long double", t); + struct type *f = lookup_function_type (c); + struct value *v + = allocate_value_lazy (f); + + struct gdbarch_info info; + info.bfd_arch_info = gdbarch_bfd_arch_info (gdbarch); + + enum gdb_osabi it; + for (it = GDB_OSABI_UNKNOWN; it != GDB_OSABI_INVALID; + it = static_cast(static_cast(it) + 1)) + { + if (it == GDB_OSABI_UNKNOWN) + continue; + + info.osabi = it; + + if (it != GDB_OSABI_NONE) + { + if (!has_gdb_osabi_handler (info)) + /* Unsupported. Skip to prevent warnings like: + A handler for the OS ABI is not built into this + configuration of GDB. Attempting to continue with the + default settings. */ + continue; + } + + gdbarch = gdbarch_find_by_info (info); + SELF_CHECK (gdbarch != NULL); + + try + { + gdbarch_return_value (gdbarch, v, c, nullptr, nullptr, nullptr); + } + catch (const gdb_exception_error &e) + { + warning ("%s/%s:%s", name, gdbarch_osabi_name (info.osabi), e.what ()); + } + } +} + } // namespace selftests void _initialize_gdbarch_selftests (); @@ -130,4 +177,6 @@ _initialize_gdbarch_selftests () { selftests::register_test_foreach_arch ("register_to_value", selftests::register_to_value_test); + selftests::register_test_foreach_arch ("gdbarch_return_value", + selftests::gdbarch_return_value); } diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index 6c2fd1bfc99..2c7c0dbe615 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -679,7 +679,8 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type, enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0; - gdb_assert (tdep->wordsize == 4); + if (tdep->wordsize != 4) + error ("do_ppc_sysv_return_value: tdep->wordsize != 4"); if (type->code () == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8 @@ -1942,7 +1943,8 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, { ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, readbuf, writebuf, i); - gdb_assert (ok); + if (!ok) + error ("ppc64_sysv_abi_return_value: !ok"); if (readbuf) readbuf += TYPE_LENGTH (eltype); @@ -1968,7 +1970,8 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, { ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, readbuf, writebuf, i); - gdb_assert (ok); + if (!ok) + error ("ppc64_sysv_abi_return_value: !ok"); if (readbuf) readbuf += TYPE_LENGTH (eltype); @@ -2024,7 +2027,8 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, { ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, readbuf, writebuf, i); - gdb_assert (ok); + if (!ok) + error ("ppc64_sysv_abi_return_value: !ok"); if (readbuf) readbuf += TYPE_LENGTH (eltype); diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index 867f21dc634..a729f15a24d 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -528,7 +528,8 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function, /* The calling convention this function implements assumes the processor has floating-point registers. We shouldn't be using it on PowerPC variants that lack them. */ - gdb_assert (ppc_floating_point_unit_p (gdbarch)); + if (!ppc_floating_point_unit_p (gdbarch)) + error ("rs6000_return_value: !ppc_floating_point_unit_p (gdbarch)"); /* AltiVec extension: Functions that declare a vector data type as a return value place that return value in VR2. */ diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c index 844d0a4ede2..b7270b3bfc8 100644 --- a/gdb/rs6000-lynx178-tdep.c +++ b/gdb/rs6000-lynx178-tdep.c @@ -271,7 +271,8 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function, /* The calling convention this function implements assumes the processor has floating-point registers. We shouldn't be using it on PowerPC variants that lack them. */ - gdb_assert (ppc_floating_point_unit_p (gdbarch)); + if (!ppc_floating_point_unit_p (gdbarch)) + error ("rs6000_lynx178_return_value: !ppc_floating_point_unit_p (gdbarch)"); /* AltiVec extension: Functions that declare a vector data type as a return value place that return value in VR2. */