From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id N51YLHLiGmO+FTYAWB0awg (envelope-from ) for ; Fri, 09 Sep 2022 02:51:30 -0400 Received: by simark.ca (Postfix, from userid 112) id A98861E22A; Fri, 9 Sep 2022 02:51:30 -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=WUDnWqEr; 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 ADAA01E222 for ; Fri, 9 Sep 2022 02:51:29 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C439D3857C4D for ; Fri, 9 Sep 2022 06:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C439D3857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662706288; bh=Whpd3AUYwGK9eIIPxOVwjnp70YT6aiLsH/r3QGrPRdE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WUDnWqErtjoQUZ7K0Rnyu5r7B6XKN5vKs2UxNV4+l9mA7hM9upHOJpcLSHXY98ho1 MHWeAcotn4ZpkvYYoVW+9Q0wC/Nj3Gqp+nbW9Tr6nknWE8Fq5VSULVDwAgBD+GLk+P DZ3WwoPplEhPtyFTicb2oZKdN/qcq4WkBEFTRQho= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A341B3858C2D for ; Fri, 9 Sep 2022 06:51:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A341B3858C2D 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 325DA22495; Fri, 9 Sep 2022 06:51:02 +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 1B15D139D5; Fri, 9 Sep 2022 06:51:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VWdkBVbiGmPJIgAAMHmgww (envelope-from ); Fri, 09 Sep 2022 06:51:02 +0000 Date: Fri, 9 Sep 2022 08:51:00 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix "file index out of range" complaint Message-ID: <20220909065059.GA19794@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: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, With the test-case included in this commit, we run into this FAIL: ... (gdb) p var^M During symbol reading: file index out of range^M $1 = 0^M (gdb) FAIL: gdb.dwarf2/dw2-no-code-cu.exp: p var with no complaints ... This is a regression since commit 6d263fe46e0 ("Avoid bad breakpoints with --gc-sections"), which contains this change in read_file_scope: ... - handle_DW_AT_stmt_list (die, cu, fnd, lowpc); + if (lowpc != highpc) + handle_DW_AT_stmt_list (die, cu, fnd, lowpc); ... The change intends to avoid a problem with a check in lnp_state_machine::check_line_address, but also prevents the file and dir tables from being read, which causes the complaint. Fix the FAIL by reducing the scope of the "lowpc != highpc" condition to the call to dwarf_decode_lines in handle_DW_AT_stmt_list. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29561 Any comments? Thanks, - Tom [gdb/symtab] Fix "file index out of range" complaint --- gdb/dwarf2/read.c | 20 +++++++++---------- gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.c | 18 +++++++++++++++++ gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.exp | 31 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3ca441c4cae..e86cc83b6f1 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9495,8 +9495,8 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) static void handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, - const file_and_directory &fnd, - CORE_ADDR lowpc) /* ARI: editCase function */ + const file_and_directory &fnd, CORE_ADDR lowpc, + bool have_code) /* ARI: editCase function */ { dwarf2_per_objfile *per_objfile = cu->per_objfile; struct attribute *attr; @@ -9583,7 +9583,12 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, gdb_assert (die->tag != DW_TAG_partial_unit); } decode_mapping = (die->tag != DW_TAG_partial_unit); - dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping); + /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0, + then there won't be any interesting code in the CU, but a check later on + (in lnp_state_machine::check_line_address) will fail to properly exclude + an entry that was removed via --gc-sections. */ + if (have_code) + dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping); } /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ @@ -9622,13 +9627,8 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) /* Decode line number information if present. We do this before processing child DIEs, so that the line header table is available - for DW_AT_decl_file. The PC check is here because, if LOWPC and - HIGHPC are both 0x0, then there won't be any interesting code in - the CU, but a check later on (in - lnp_state_machine::check_line_address) will fail to properly - exclude an entry that was removed via --gc-sections. */ - if (lowpc != highpc) - handle_DW_AT_stmt_list (die, cu, fnd, lowpc); + for DW_AT_decl_file. */ + handle_DW_AT_stmt_list (die, cu, fnd, lowpc, lowpc != highpc); /* Process all dies in compilation unit. */ if (die->child != NULL) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.c b/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.c new file mode 100644 index 00000000000..576b1a21442 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.c @@ -0,0 +1,18 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +int var; diff --git a/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.exp b/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.exp new file mode 100644 index 00000000000..911bb7e2a7d --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.exp @@ -0,0 +1,31 @@ +# Copyright 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 . + +standard_testfile .c main.c + +if [prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2"] { + return -1 +} + +set cmd "p var" + +set re \ + [multi_line \ + "$cmd" \ + "\\\$1 = 0"] + +with_complaints 5 { + gdb_test $cmd $re "$cmd with no complaints" +}