From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gFyTOj43zWRqTzcAWB0awg (envelope-from ) for ; Fri, 04 Aug 2023 13:37:02 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=VT9U953P; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id ECC091E098; Fri, 4 Aug 2023 13:37:02 -0400 (EDT) Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DA6911E0BB for ; Fri, 4 Aug 2023 13:37:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33115385734F for ; Fri, 4 Aug 2023 17:37:00 +0000 (GMT) Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 6494D3857726 for ; Fri, 4 Aug 2023 17:36:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6494D3857726 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id AFFE61003A117 for ; Fri, 4 Aug 2023 17:36:45 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id RyjFqBHZh8fl9RyjFqTHXL; Fri, 04 Aug 2023 17:36:45 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Adl0o1bG c=1 sm=1 tr=0 ts=64cd372d a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=UttIx32zK-AA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=Tz_8nxrO5beYrQ1rYkgA:9 a=ul9cdbp4aOFLsgKbc677:22 a=_FVE-zBwftR9WsbkzFJk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=+LPW4t6jqJk0Jcpmi7qupFHves68I5GuZjzxj+epSfI=; b=VT9U953PLwqPBQmHOQrEdZMdI7 zLILKqghl24bqeKmeDRxzIy05c+BCThZZgiktfnZItqvMRGKeZHdbpcyHlaGE32Phj1tFSwcgrde8 mU8Iugr1sP/lJxdEUDDjiG5GG; Received: from 71-211-152-221.hlrn.qwest.net ([71.211.152.221]:45408 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qRyjF-002mja-1H; Fri, 04 Aug 2023 11:36:45 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use get_frame_address_in_block in print_frame Date: Fri, 4 Aug 2023 11:36:35 -0600 Message-ID: <20230804173635.392319-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.152.221 X-Source-L: No X-Exim-ID: 1qRyjF-002mja-1H X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-152-221.hlrn.qwest.net (localhost.localdomain) [71.211.152.221]:45408 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" The author of 'mold' pointed out that with a certain shared library, gdb would fail to find the shared library's name in 'bt'. The function in question appeared at the end of the .so's .text segment and ended with a call to 'abort'. This turned out to be a classic case of calling get_frame_pc when get_frame_address_in_block is needed -- the former will be off-by-one for purposes of finding the enclosing function or shared library. The included test fails without the patch on my system. However, I imagine it can't be assumed to reliably fail. Nevertheless it seemed worth doing. Regression tested on x86-64 Fedora 38. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29074 --- gdb/stack.c | 2 +- gdb/testsuite/gdb.base/solib-abort-lib.c | 23 ++++++++++ gdb/testsuite/gdb.base/solib-abort.c | 25 +++++++++++ gdb/testsuite/gdb.base/solib-abort.exp | 56 ++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/solib-abort-lib.c create mode 100644 gdb/testsuite/gdb.base/solib-abort.c create mode 100644 gdb/testsuite/gdb.base/solib-abort.exp diff --git a/gdb/stack.c b/gdb/stack.c index 002bf580634..0b35d62f82f 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1420,7 +1420,7 @@ print_frame (const frame_print_options &fp_opts, { const char *lib = solib_name_from_address (get_frame_program_space (frame), - get_frame_pc (frame)); + get_frame_address_in_block (frame)); if (lib) { diff --git a/gdb/testsuite/gdb.base/solib-abort-lib.c b/gdb/testsuite/gdb.base/solib-abort-lib.c new file mode 100644 index 00000000000..22543230d3b --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-abort-lib.c @@ -0,0 +1,23 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +void +callee (void) +{ + abort (); +} diff --git a/gdb/testsuite/gdb.base/solib-abort.c b/gdb/testsuite/gdb.base/solib-abort.c new file mode 100644 index 00000000000..42f4dc54ed6 --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-abort.c @@ -0,0 +1,25 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +extern void callee (void); + +int +main () +{ + callee (); + return 0; +} + diff --git a/gdb/testsuite/gdb.base/solib-abort.exp b/gdb/testsuite/gdb.base/solib-abort.exp new file mode 100644 index 00000000000..fcc229623bc --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-abort.exp @@ -0,0 +1,56 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test corner case of printing solib name when unwinding. +# https://sourceware.org/bugzilla/show_bug.cgi?id=29074 + +require allow_shlib_tests + +# Library file. +set libname "solib-abort-lib" +set srcfile_lib ${srcdir}/${subdir}/${libname}.c +set binfile_lib [standard_output_file ${libname}.so] +# Note: no debugging info here, since this will assure that the solib +# name is printed in the stack trace. +set lib_flags {} + +# Binary file. +set testfile "solib-abort" +set srcfile ${srcdir}/${subdir}/${testfile}.c +set binfile [standard_output_file ${testfile}] +set bin_flags [list debug shlib=${binfile_lib}] + +if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != "" + || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } { + untested "failed to compile" + return -1 +} + +clean_restart $binfile + +if {![runto_main]} { + return 0 +} + +# Run until the program dies. +gdb_test "cont" "Program received signal SIGABRT,.*" + +# The solib name should show up in the stack trace. The bug here was +# that if the function calling abort appeared last in the text +# section, and if GCC didn't emit an epilogue after the call, then gdb +# would use the wrong PC to find the solib name. This test doesn't +# exactly test this in all situations, but with the correct +# environment it is sufficient. +gdb_test "bt" "#$decimal .* in callee .* from .*${libname}\\.so.*" -- 2.41.0