From patchwork Tue Mar 14 13:37:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66370 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 BB663385B523 for ; Tue, 14 Mar 2023 13:37:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB663385B523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678801074; bh=QBM+o2EvLv6KBSRD0EKRF4PjRtEugUI/Fe6D8/HNe18=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=G/pIL4wvHPwgQV8y8rKQEJLLCmqmxFYQzKhtHCBpF7SZb3ukqNNBdDhn75wwei/Qe ZbDBCunY+9tMCrtEMf4JN+bjjTEOODr5Dm3YFNIt340+tUaM8kmYnz2dg+iuq2sn9M splahnRqnxjI7jyZEtrN4pD4u3wr2oTZFch1yNug= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 2AE883858C83 for ; Tue, 14 Mar 2023 13:37:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AE883858C83 Received: by mail-io1-xd33.google.com with SMTP id o12so419524iow.6 for ; Tue, 14 Mar 2023 06:37:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678801039; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QBM+o2EvLv6KBSRD0EKRF4PjRtEugUI/Fe6D8/HNe18=; b=6aLSfgnpcGaQ43+33afS8z+JyVmmS1U8k3y/GnbvBiR7pBlf57GU1jj33Pw/twJTUl 7IM6isNybk6uRDQAekBWkafoV4H049tOq27L6/gU/szO35L3yyIJjF7N1qn/n/1E4KkR DJrK8HZ1UvC7eQC19/14XgiupiYmQOHo+iEZX7LS41uPx/SctVuAX2OVaVRuovilwidx AyHAn2FYkBIvIoqaAczxNghezxUZyBdFNXriWgu2o0DTTtZnjXvTawn2cf0qKPEPEfHl QCHxlNKfvrqfLDDIO5uqaVAXj6zJdAn+InPITs8KLjxUa9XmFMX4EKOLtLHFzb/G/9cD RBzw== X-Gm-Message-State: AO0yUKVjAkUt2H1VSFid2ittUEZk6kbwuPxpJ0XUc182ZxwiPyT4ytI2 sRDvap77JXewH7eGRcJEIH907ikNjt8O6E5fzg0= X-Google-Smtp-Source: AK7set9JAOQa0Ttl0GT1pA6m+HqoB5wPInwNM9puwwQh3gW2NnfSvT3OKpfitYSJ54rQ943ss2hX/g== X-Received: by 2002:a05:6602:2159:b0:74d:46eb:6a57 with SMTP id y25-20020a056602215900b0074d46eb6a57mr27871797ioy.20.1678801039357; Tue, 14 Mar 2023 06:37:19 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id d7-20020a6b7d47000000b0071664d0a4d7sm809045ioq.49.2023.03.14.06.37.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 06:37:19 -0700 (PDT) Date: Tue, 14 Mar 2023 07:37:16 -0600 Subject: [PATCH 1/3] Handle function descriptors in call_site_target MIME-Version: 1.0 Message-Id: <20230314-submit-ppc-finish-fixes-v1-1-5f2f461b52f8@adacore.com> References: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> In-Reply-To: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" call_site_target::iterate_over_addresses may look up a minimal symbol. On platforms like PPC64 that use function descriptors, this may find an unexpected address. The fix is to use gdbarch_convert_from_func_ptr_addr to convert from a function descriptor to the address recorded at the call site. I've added a new test case that is based on the internal AdaCore test that provoked this bug. However, I'm unable to test it as-is on PPC64. --- gdb/dwarf2/loc.c | 6 ++++- gdb/testsuite/gdb.ada/finish-large.exp | 30 ++++++++++++++++++++++++ gdb/testsuite/gdb.ada/finish-large/p.adb | 24 +++++++++++++++++++ gdb/testsuite/gdb.ada/finish-large/pck.adb | 28 ++++++++++++++++++++++ gdb/testsuite/gdb.ada/finish-large/pck.ads | 37 ++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 914e016f085..d9615870aeb 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -711,7 +711,11 @@ call_site_target::iterate_over_addresses : msym.minsym->print_name ())); } - callback (msym.value_address ()); + + CORE_ADDR addr = (gdbarch_convert_from_func_ptr_addr + (call_site_gdbarch, msym.value_address (), + current_inferior ()->top_target ())); + callback (addr); } break; diff --git a/gdb/testsuite/gdb.ada/finish-large.exp b/gdb/testsuite/gdb.ada/finish-large.exp new file mode 100644 index 00000000000..5661d132a18 --- /dev/null +++ b/gdb/testsuite/gdb.ada/finish-large.exp @@ -0,0 +1,30 @@ +# 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 . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile p + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} { + return -1 +} + +clean_restart ${testfile} +runto "pck.create_large" + +set value "= (i => 1, j => 2, k => 3, l => 4, m => 5, n => 6, o => 7, p => 8, q => 9, r => 10, s => 11, t => 12)" +gdb_test "finish" [string_to_regexp $value] diff --git a/gdb/testsuite/gdb.ada/finish-large/p.adb b/gdb/testsuite/gdb.ada/finish-large/p.adb new file mode 100644 index 00000000000..ce7631e5cbd --- /dev/null +++ b/gdb/testsuite/gdb.ada/finish-large/p.adb @@ -0,0 +1,24 @@ +-- 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 . + +with Pck; use Pck; + +procedure P is + Large : Data_Large; +begin + Large := Create_Large; + Large.P := 42; + Break_Me; +end P; diff --git a/gdb/testsuite/gdb.ada/finish-large/pck.adb b/gdb/testsuite/gdb.ada/finish-large/pck.adb new file mode 100644 index 00000000000..18ed031db12 --- /dev/null +++ b/gdb/testsuite/gdb.ada/finish-large/pck.adb @@ -0,0 +1,28 @@ +-- 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 . + +package body Pck is + + function Create_Large return Data_Large is + begin + return (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); + end Create_Large; + + procedure Break_Me is + begin + null; + end Break_Me; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/finish-large/pck.ads b/gdb/testsuite/gdb.ada/finish-large/pck.ads new file mode 100644 index 00000000000..0ed49a71241 --- /dev/null +++ b/gdb/testsuite/gdb.ada/finish-large/pck.ads @@ -0,0 +1,37 @@ +-- 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 . + +package Pck is + + type Data_Large is record + I : Integer; + J : Integer; + K : Integer; + L : Integer; + M : Integer; + N : Integer; + O : Integer; + P : Integer; + Q : Integer; + R : Integer; + S : Integer; + T : Integer; + end record; + + function Create_Large return Data_Large; + + procedure Break_Me; + +end Pck; From patchwork Tue Mar 14 13:37:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66369 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 B5D5B385B515 for ; Tue, 14 Mar 2023 13:37:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5D5B385B515 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678801074; bh=XcIR2Da5Vx+plEXsWHZFqfgeKqIrDOL+pKZ4JFX3++w=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jrs1TT0od5qv+qchG6FVevUi97HYS/4jTK3vqO1QFps3HwCOp8+YcR/Kd/BChvmfQ UPNzD1MLkNhhKRfZFcyNdy4cQmDKee52dw43gyXkjKeqvw3yxZh+6NyRTPY+bBniTs UHRU11u+9j1CTb1hdWLp4+9snLJC+zqNHxXNgVXM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id B8D353858C5E for ; Tue, 14 Mar 2023 13:37:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8D353858C5E Received: by mail-il1-x136.google.com with SMTP id y12so4428058ilq.4 for ; Tue, 14 Mar 2023 06:37:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678801040; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XcIR2Da5Vx+plEXsWHZFqfgeKqIrDOL+pKZ4JFX3++w=; b=6wQgkzEbNoLuzqnX0OqMYnfdhW+6wyAb8boUrtNewAdMDMOi98S+CEal9tQV8YFvz0 j3t8cnvPUFWAbXSm5aiHwF0oFYDkzL6Vpt8rIKZ76vxM//eho06iUG/qtAUm0T10VtJR KuFxNtK0Jq8jenSdLVGOTvwUOHoN0gQ2McLD7fVYhCV0SSDNz/yJMYGay1vjVInfqIMF Dim2M33Vi83EoK/Qq+mVj+tgcgeiCDkAg+fmErCj0Pp0Vap3CnU74mf7aZclGBOK/Yxg pld1YuWc0n2gtChDUjMKEXXD6Dt4G8M/1P93hdejcycvJ1UwSD5LXr1jyiJ6BtC2ie/9 94Eg== X-Gm-Message-State: AO0yUKXmmk4P0g58pCiNVM2c07LNiw4rc39r/yvf2zsn+uMXS+UcXbnI k1oncsbSLZSGftGuO5Ncj2y5Ui3OkR7ZlWgCFR8= X-Google-Smtp-Source: AK7set9WRpyYUeoijWUAKtbCYKYx+m2qrxHukIWe4oBC1ql+fqQ72g8e5TD4wUfD9kn056tKcllpxQ== X-Received: by 2002:a92:3f13:0:b0:318:ab40:4e9b with SMTP id m19-20020a923f13000000b00318ab404e9bmr2114693ila.2.1678801039885; Tue, 14 Mar 2023 06:37:19 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id d7-20020a6b7d47000000b0071664d0a4d7sm809045ioq.49.2023.03.14.06.37.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 06:37:19 -0700 (PDT) Date: Tue, 14 Mar 2023 07:37:17 -0600 Subject: [PATCH 2/3] Handle erroneous DW_AT_call_return_pc MIME-Version: 1.0 Message-Id: <20230314-submit-ppc-finish-fixes-v1-2-5f2f461b52f8@adacore.com> References: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> In-Reply-To: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" On PPC64, with the test case included in an earlier patch, we found that "finish" would still not correctly find the return value via entry values. The issue is simple. The compiler emits: 0x00000000100032b8 <+28>: bl 0x1000320c 0x00000000100032bc <+32>: nop 0x00000000100032c0 <+36>: li r9,42 ... but the DWARF says: <162a> DW_AT_call_return_pc: 0x100032c0 That is, the declared return PC is one instruction past the actual return PC. This patch adds a new arch hook to handle this scenario, and implements it for PPC64. Some care is taken so that GDB will continue to work if this compiler bug is fixed. A GCC patch is here: https://gcc.gnu.org/pipermail/gcc-patches/2023-March/613336.html I'm not completely sure that the nop check in the new arch hook is correct; but if it is incorrect it just means that some invocations of 'finish' won't find a value -- which is what happens without the patch. --- gdb/arch-utils.c | 6 ++++++ gdb/gdbarch-gen.h | 13 +++++++++++++ gdb/gdbarch.c | 22 ++++++++++++++++++++++ gdb/gdbarch_components.py | 17 +++++++++++++++++ gdb/rs6000-tdep.c | 22 ++++++++++++++++++++++ gdb/symtab.c | 13 +++++++++++++ 6 files changed, 93 insertions(+) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index e3af9ce2dbc..f9d0e73a362 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1098,6 +1098,12 @@ default_get_return_buf_addr (struct type *val_type, frame_info_ptr cur_frame) return 0; } +static CORE_ADDR +default_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + return pc; +} + /* Non-zero if we want to trace architecture code. */ #ifndef GDBARCH_DEBUG diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 76d12a15317..bec3221202c 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -468,6 +468,19 @@ typedef CORE_ADDR (gdbarch_get_return_buf_addr_ftype) (struct type *val_type, fr extern CORE_ADDR gdbarch_get_return_buf_addr (struct gdbarch *gdbarch, struct type *val_type, frame_info_ptr cur_frame); extern void set_gdbarch_get_return_buf_addr (struct gdbarch *gdbarch, gdbarch_get_return_buf_addr_ftype *get_return_buf_addr); +/* Update PC when trying to find a call site. This is useful on + architectures where the call site PC, as reported in the DWARF, can be + incorrect for some reason. + + The passed-in PC will be an address in the inferior. GDB will have + already failed to find a call site at this PC. This function may + simply return its parameter if it thinks that should be the correct + address. */ + +typedef CORE_ADDR (gdbarch_update_call_site_pc_ftype) (struct gdbarch *gdbarch, CORE_ADDR pc); +extern CORE_ADDR gdbarch_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc); +extern void set_gdbarch_update_call_site_pc (struct gdbarch *gdbarch, gdbarch_update_call_site_pc_ftype *update_call_site_pc); + /* Return true if the return value of function is stored in the first hidden parameter. In theory, this feature should be language-dependent, specified by language and its ABI, such as C++. Unfortunately, compiler may diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index b4763aa6bf4..b4ee88b61cb 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -114,6 +114,7 @@ struct gdbarch gdbarch_return_value_ftype *return_value = nullptr; gdbarch_return_value_as_value_ftype *return_value_as_value = default_gdbarch_return_value; gdbarch_get_return_buf_addr_ftype *get_return_buf_addr = default_get_return_buf_addr; + gdbarch_update_call_site_pc_ftype *update_call_site_pc = default_update_call_site_pc; gdbarch_return_in_first_hidden_param_p_ftype *return_in_first_hidden_param_p = default_return_in_first_hidden_param_p; gdbarch_skip_prologue_ftype *skip_prologue = nullptr; gdbarch_skip_main_prologue_ftype *skip_main_prologue = nullptr; @@ -370,6 +371,7 @@ verify_gdbarch (struct gdbarch *gdbarch) if ((gdbarch->return_value_as_value == default_gdbarch_return_value) == (gdbarch->return_value == nullptr)) log.puts ("\n\treturn_value_as_value"); /* Skip verify of get_return_buf_addr, invalid_p == 0 */ + /* Skip verify of update_call_site_pc, invalid_p == 0 */ /* Skip verify of return_in_first_hidden_param_p, invalid_p == 0 */ if (gdbarch->skip_prologue == 0) log.puts ("\n\tskip_prologue"); @@ -787,6 +789,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) gdb_printf (file, "gdbarch_dump: get_return_buf_addr = <%s>\n", host_address_to_string (gdbarch->get_return_buf_addr)); + gdb_printf (file, + "gdbarch_dump: update_call_site_pc = <%s>\n", + host_address_to_string (gdbarch->update_call_site_pc)); gdb_printf (file, "gdbarch_dump: return_in_first_hidden_param_p = <%s>\n", host_address_to_string (gdbarch->return_in_first_hidden_param_p)); @@ -2619,6 +2624,23 @@ set_gdbarch_get_return_buf_addr (struct gdbarch *gdbarch, gdbarch->get_return_buf_addr = get_return_buf_addr; } +CORE_ADDR +gdbarch_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->update_call_site_pc != NULL); + if (gdbarch_debug >= 2) + gdb_printf (gdb_stdlog, "gdbarch_update_call_site_pc called\n"); + return gdbarch->update_call_site_pc (gdbarch, pc); +} + +void +set_gdbarch_update_call_site_pc (struct gdbarch *gdbarch, + gdbarch_update_call_site_pc_ftype update_call_site_pc) +{ + gdbarch->update_call_site_pc = update_call_site_pc; +} + int gdbarch_return_in_first_hidden_param_p (struct gdbarch *gdbarch, struct type *type) { diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 92c501d2a72..8b5512c647e 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -901,6 +901,23 @@ May return 0 when unable to determine that address.""", invalid=False, ) +Method( + comment=""" +Update PC when trying to find a call site. This is useful on +architectures where the call site PC, as reported in the DWARF, can be +incorrect for some reason. + +The passed-in PC will be an address in the inferior. GDB will have +already failed to find a call site at this PC. This function may +simply return its parameter if it thinks that should be the correct +address.""", + type="CORE_ADDR", + name="update_call_site_pc", + params=[("CORE_ADDR", "pc")], + predefault="default_update_call_site_pc", + invalid=False, +) + Method( comment=""" Return true if the return value of function is stored in the first hidden diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index 9859a7d8b85..d1a16b3430b 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -7460,6 +7460,27 @@ rs6000_program_breakpoint_here_p (gdbarch *gdbarch, CORE_ADDR address) return false; } +/* Implement the update_call_site_pc arch hook. */ + +static CORE_ADDR +ppc64_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + /* Some versions of GCC emit: + + . bl function + . nop + . ... + + but emit DWARF where the DW_AT_call_return_pc points to + instruction after the 'nop'. If PC points to a nop, return the + following instruction instead. */ + + unsigned long op = rs6000_fetch_instruction (gdbarch, pc); + if (op == 0x60000000) + pc += 4; + return pc; +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of architectures already created during this debugging session. @@ -8246,6 +8267,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value); set_gdbarch_get_return_buf_addr (gdbarch, ppc64_sysv_get_return_buf_addr); + set_gdbarch_update_call_site_pc (gdbarch, ppc64_update_call_site_pc); } else set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value); diff --git a/gdb/symtab.c b/gdb/symtab.c index e11f9262a22..219a1fd4671 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -349,6 +349,19 @@ compunit_symtab::find_call_site (CORE_ADDR pc) const struct call_site call_site_local (unrelocated_pc, nullptr, nullptr); void **slot = htab_find_slot (m_call_site_htab, &call_site_local, NO_INSERT); + if (slot != nullptr) + return (call_site *) *slot; + + /* See if the arch knows another PC we should try. On some + platforms, GCC emits a DWARF call site that is offset from the + actual return location. */ + struct gdbarch *arch = objfile ()->arch (); + CORE_ADDR new_pc = gdbarch_update_call_site_pc (arch, pc); + if (pc == new_pc) + return nullptr; + + call_site new_call_site_local (new_pc - delta, nullptr, nullptr); + slot = htab_find_slot (m_call_site_htab, &new_call_site_local, NO_INSERT); if (slot == nullptr) return nullptr; From patchwork Tue Mar 14 13:37:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66371 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 5981A3858C1F for ; Tue, 14 Mar 2023 13:38:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5981A3858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678801094; bh=Ozjleg4kg166A8i3X2otuDgHzI/3dkz+DwSB2bI9FQc=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=G6itg0uhUQ8BpyZMYewAostjOUsQRTSJA2W8EtgrcIvbNT3P4MY/8C5TjP6aYphm/ FWOp2maGLcF/AZWzs/ZEPccbkR4f3P5DC5vve5xm+4sowfrGAB1ias62VI8XiGB+qk vkQ7Y/TV0hwxbbq61OFV9V+9xhCMclrfHO4RGlto= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 373E03858C5F for ; Tue, 14 Mar 2023 13:37:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 373E03858C5F Received: by mail-io1-xd2e.google.com with SMTP id m22so6403771ioy.4 for ; Tue, 14 Mar 2023 06:37:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678801040; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ozjleg4kg166A8i3X2otuDgHzI/3dkz+DwSB2bI9FQc=; b=2oPmRcYImxve5gdPgpUuBkhkOF4IuiOYDqhOqksgTWi1uruTt79nVcdOl3CoBrGXQX p2tOeNpUiT/A0lVVxaV2r9Ob0pVPb0ER+GJicjWIbfBbH2JRbCzp3W4Jnzh5nCY6zCkq XlO5hTo4Ciup/qjLWzN0brNnh6IrCbHItptjMCmTOLAsa9Y6TxjyRT2sM7f5vG62T/cb zMcIAiBXizegIpd6MTRgwiWwfNFWiEEWFngEZv5nHWuixFHVJOkj+MSobY4ru+jptFvn oBsHm79mWnbn4wMo7sQyFNTHT94HTP4ncSlX0J6wjQvTz6eo7cyPUW2Av1LDT89WYZ6o rcZA== X-Gm-Message-State: AO0yUKVJTSzv/rO5sUOPSP8aNRMS2qgVwU930b+3+LwtT7USINkotuTd dJhhRiD4nwrZCiM8brgMo3LP2hkeMlXeyBKxEco= X-Google-Smtp-Source: AK7set/k77oYBWL/j+tlAaCGj2BEy8pgatZdq7qR03c7HoiFyiaqx8w/M9EhJYAbeypmdVtBco11ZQ== X-Received: by 2002:a6b:da17:0:b0:74c:8f71:dde7 with SMTP id x23-20020a6bda17000000b0074c8f71dde7mr23106159iob.19.1678801040423; Tue, 14 Mar 2023 06:37:20 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id d7-20020a6b7d47000000b0071664d0a4d7sm809045ioq.49.2023.03.14.06.37.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 06:37:20 -0700 (PDT) Date: Tue, 14 Mar 2023 07:37:18 -0600 Subject: [PATCH 3/3] Use entry values for 32-bit PPC struct return MIME-Version: 1.0 Message-Id: <20230314-submit-ppc-finish-fixes-v1-3-5f2f461b52f8@adacore.com> References: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> In-Reply-To: <20230314-submit-ppc-finish-fixes-v1-0-5f2f461b52f8@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.5 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 Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" AdaCore has a local patch for PPC "finish", but last year, Ulrich Weigand pointed out that this patch was incorrect. It may work for simple functions like the one in the internal test, but nothing guarantees that r3 will be preserved by the callee, so checking r3 on exit is not always correct. This patch fixes the problem using the same approach as PPC64: use the entry value of r3, if available. Ulrich confirmed this matches the PPC32 ABI. --- gdb/ppc-sysv-tdep.c | 3 +-- gdb/ppc-tdep.h | 4 +++- gdb/rs6000-tdep.c | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index ab859fbe143..66630793e86 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -2159,8 +2159,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, } CORE_ADDR -ppc64_sysv_get_return_buf_addr (struct type *val_type, - frame_info_ptr cur_frame) +ppc_sysv_get_return_buf_addr (struct type *val_type, frame_info_ptr cur_frame) { /* The PowerPC ABI specifies aggregates that are not returned by value are returned in a storage buffer provided by the caller. The diff --git a/gdb/ppc-tdep.h b/gdb/ppc-tdep.h index fe41baef149..3c7948cc4ba 100644 --- a/gdb/ppc-tdep.h +++ b/gdb/ppc-tdep.h @@ -175,7 +175,9 @@ extern void ppc_collect_vsxregset (const struct regset *regset, const struct regcache *regcache, int regnum, void *vsxregs, size_t len); -extern CORE_ADDR ppc64_sysv_get_return_buf_addr (type*, frame_info_ptr); +/* Implementation of the gdbarch get_return_buf_addr hook. */ + +extern CORE_ADDR ppc_sysv_get_return_buf_addr (type*, frame_info_ptr); /* Private data that this module attaches to struct gdbarch. */ diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index d1a16b3430b..16adefb9f9b 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -8265,12 +8265,11 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (wordsize == 8) { set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value); - set_gdbarch_get_return_buf_addr (gdbarch, - ppc64_sysv_get_return_buf_addr); set_gdbarch_update_call_site_pc (gdbarch, ppc64_update_call_site_pc); } else set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value); + set_gdbarch_get_return_buf_addr (gdbarch, ppc_sysv_get_return_buf_addr); /* Set lr_frame_offset. */ if (wordsize == 8)