From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 21A9D3858C2D for ; Fri, 13 May 2022 00:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21A9D3858C2D 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 cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 6378E100401B4 for ; Fri, 13 May 2022 00:00:35 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id pIjSnN5rrY8ycpIjSnvbhH; Fri, 13 May 2022 00:00:35 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=df5FYVbe c=1 sm=1 tr=0 ts=627d9fa3 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oZkIemNP1mAA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=T6JZarDOzs2rNDYWVQoA: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=vlcyKUxhqULDNfuGX89AWxfVkwzCLL/3sVJg6anF0ws=; b=aBOFEzkOp3vCd39PaZutuQLQvu S2oMuwgwp6b+G/Vthtnqudl+3T+4SVLZOAmbFHTpfXkZBReDFgyaLtS6753rtyiATrTtSnL4WlAkL 4+ctPfh2chq/db6H1BDWtWc9l; Received: from c-73-181-19-44.hsd1.co.comcast.net ([73.181.19.44]:50522 helo=prentzel.lan) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1npIjS-002rQ3-8w; Thu, 12 May 2022 18:00:34 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix crash in new DWARF indexer Date: Thu, 12 May 2022 18:00:32 -0600 Message-Id: <20220513000032.3056175-1-tom@tromey.com> X-Mailer: git-send-email 2.34.1 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: 73.181.19.44 X-Source-L: No X-Exim-ID: 1npIjS-002rQ3-8w X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: c-73-181-19-44.hsd1.co.comcast.net (prentzel.lan) [73.181.19.44]:50522 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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, 13 May 2022 00:00:39 -0000 PR gdb/29128 points out a crash in the new DWARF index code. This happens if the aranges for a CU claims a PC, but the symtab that is created during CU expansion does not actually contain the PC. This can only occur due to bad debuginfo, but at the same time, gdb should not crash. This patch fixes the bug and further merges some code into dwarf2_base_index_functions. This merger helps prevent the same issue from arising from the other index implementations. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29128 --- gdb/dwarf2/read.c | 72 +++++++++++------------- gdb/testsuite/gdb.dwarf2/cu-no-addrs.exp | 62 ++++++++++++++++++++ 2 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/cu-no-addrs.exp diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d146d525066..6c5edc0d605 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1831,9 +1831,15 @@ struct dwarf2_base_index_functions : public quick_symbol_functions void expand_all_symtabs (struct objfile *objfile) override; + /* A helper function that finds the per-cu object from an "adjusted" + PC -- a PC with the base text offset removed. */ + virtual dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd, + CORE_ADDR adjusted_pc); + struct compunit_symtab *find_pc_sect_compunit_symtab (struct objfile *objfile, struct bound_minimal_symbol msymbol, - CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override; + CORE_ADDR pc, struct obj_section *section, int warn_if_readin) + override final; struct compunit_symtab *find_compunit_symtab_by_address (struct objfile *objfile, CORE_ADDR address) override @@ -4236,6 +4242,16 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, return NULL; } +dwarf2_per_cu_data * +dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd, + CORE_ADDR adjusted_pc) +{ + if (per_bfd->index_addrmap == nullptr) + return nullptr; + return (struct dwarf2_per_cu_data *) addrmap_find (per_bfd->index_addrmap, + adjusted_pc); +} + struct compunit_symtab * dwarf2_base_index_functions::find_pc_sect_compunit_symtab (struct objfile *objfile, @@ -4244,19 +4260,15 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab struct obj_section *section, int warn_if_readin) { - struct dwarf2_per_cu_data *data; struct compunit_symtab *result; dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); - if (per_objfile->per_bfd->index_addrmap == nullptr) - return NULL; CORE_ADDR baseaddr = objfile->text_section_offset (); - data = ((struct dwarf2_per_cu_data *) - addrmap_find (per_objfile->per_bfd->index_addrmap, - pc - baseaddr)); - if (!data) - return NULL; + struct dwarf2_per_cu_data *data = find_per_cu (per_objfile->per_bfd, + pc - baseaddr); + if (data == nullptr) + return nullptr; if (warn_if_readin && per_objfile->symtab_set_p (data)) warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), @@ -4265,7 +4277,10 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab result = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data, per_objfile, false), pc); - gdb_assert (result != NULL); + if (warn_if_readin && result == nullptr) + warning (_("(Error: pc %s in address map, but not in symtab.)"), + paddress (objfile->arch (), pc)); + return result; } @@ -18418,9 +18433,8 @@ cooked_indexer::make_index (cutu_reader *reader) struct cooked_index_functions : public dwarf2_base_index_functions { - struct compunit_symtab *find_pc_sect_compunit_symtab - (struct objfile *objfile, struct bound_minimal_symbol msymbol, - CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override; + dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd, + CORE_ADDR adjusted_pc) override; struct compunit_symtab *find_compunit_symtab_by_address (struct objfile *objfile, CORE_ADDR address) override; @@ -18459,36 +18473,16 @@ struct cooked_index_functions : public dwarf2_base_index_functions } }; -struct compunit_symtab * -cooked_index_functions::find_pc_sect_compunit_symtab - (struct objfile *objfile, - struct bound_minimal_symbol msymbol, - CORE_ADDR pc, - struct obj_section *section, - int warn_if_readin) +dwarf2_per_cu_data * +cooked_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd, + CORE_ADDR adjusted_pc) { - dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); - if (per_objfile->per_bfd->index_table == nullptr) - return nullptr; - - CORE_ADDR baseaddr = objfile->text_section_offset (); cooked_index_vector *table = (static_cast - (per_objfile->per_bfd->index_table.get ())); - dwarf2_per_cu_data *per_cu = table->lookup (pc - baseaddr); - if (per_cu == nullptr) + (per_bfd->index_table.get ())); + if (table == nullptr) return nullptr; - - if (warn_if_readin && per_objfile->symtab_set_p (per_cu)) - warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), - paddress (objfile->arch (), pc)); - - compunit_symtab *result = (recursively_find_pc_sect_compunit_symtab - (dw2_instantiate_symtab (per_cu, per_objfile, - false), - pc)); - gdb_assert (result != nullptr); - return result; + return table->lookup (adjusted_pc); } struct compunit_symtab * diff --git a/gdb/testsuite/gdb.dwarf2/cu-no-addrs.exp b/gdb/testsuite/gdb.dwarf2/cu-no-addrs.exp new file mode 100644 index 00000000000..0c7b80d5f4f --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/cu-no-addrs.exp @@ -0,0 +1,62 @@ +# Copyright (C) 2022 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 . + +# Regression test for the situation where aranges covers an address +# but the CU does not. + +load_lib "dwarf.exp" + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c cu-no-addrs.S + +lassign [function_range main ${srcdir}/${subdir}/${srcfile}] \ + main_start main_length + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global main_start main_length + + cu {label cu_start} { + # The PC range here is intentionally empty -- this was the + # trigger for the bug. + compile_unit { + {language @DW_LANG_C} + {DW_AT_low_pc $main_start DW_FORM_addr} + {DW_AT_high_pc $main_start DW_FORM_addr} + } { + DW_TAG_subprogram { + {DW_AT_name "main"} + {DW_AT_low_pc $main_start DW_FORM_addr} + } + } + } + + aranges {} cu_start { + arange {} $main_start $main_length + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}]} { + return -1 +} + +gdb_test "break *$main_start" ".*Breakpoint $decimal at $hex" \ + "set breakpoint at main address" -- 2.34.1