From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 6100D385277B; Sat, 17 Sep 2022 06:22:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6100D385277B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663395756; bh=rkPiOKoHJg5IpE8PTGjkLOe0WdWba8DbZSrR032/b9o=; h=From:To:Subject:Date:From; b=VYor325zmE0g3KpGuxpvsGBN2tgkDcs1tkDd1OZyXiKfBJdNNsda4zRz8QeBq3Kya NriHSpoYNpkmaIehXkBnJ0Tdjf9G4uJMIi6sCfBjGDCYDqyQ3PGKbY7YJSm891/uLc H0NOuA3NaBAM8EzENyBMJYbw7PgOYTv2AzKXKszE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Fix "file index out of range" complaint X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 5e3cecb21acfbdc16f65efc276733efe89f5aa25 X-Git-Newrev: 99d679e7b30ea9a0b6ffcd64e9ba35e43166151b Message-Id: <20220917062236.6100D385277B@sourceware.org> Date: Sat, 17 Sep 2022 06:22:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D99d679e7b30e= a9a0b6ffcd64e9ba35e43166151b commit 99d679e7b30ea9a0b6ffcd64e9ba35e43166151b Author: Tom de Vries Date: Sat Sep 17 08:22:32 2022 +0200 [gdb/symtab] Fix "file index out of range" complaint =20 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 =3D 0^M (gdb) FAIL: gdb.dwarf2/dw2-no-code-cu.exp: p var with no complaints ... =20 This is a regression since commit 6d263fe46e0 ("Avoid bad breakpoints w= ith --gc-sections"), which contains this change in read_file_scope: ... - handle_DW_AT_stmt_list (die, cu, fnd, lowpc); + if (lowpc !=3D highpc) + handle_DW_AT_stmt_list (die, cu, fnd, lowpc); ... =20 The change intends to avoid a problem with a check in lnp_state_machine::check_line_address, but also prevents the file and d= ir tables from being read, which causes the complaint. =20 Fix the FAIL by reducing the scope of the "lowpc !=3D highpc" condition= to the call to dwarf_decode_lines in handle_DW_AT_stmt_list. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29561 Diff: --- 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 0a3c29212b4..ceb14511f8b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9498,8 +9498,8 @@ find_file_and_directory (struct die_info *die, struct= dwarf2_cu *cu) =20 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 =3D cu->per_objfile; struct attribute *attr; @@ -9586,7 +9586,12 @@ handle_DW_AT_stmt_list (struct die_info *die, struct= dwarf2_cu *cu, gdb_assert (die->tag !=3D DW_TAG_partial_unit); } decode_mapping =3D (die->tag !=3D 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 excl= ude + an entry that was removed via --gc-sections. */ + if (have_code) + dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping); } =20 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ @@ -9625,13 +9630,8 @@ read_file_scope (struct die_info *die, struct dwarf2= _cu *cu) =20 /* 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 !=3D 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 !=3D highpc); =20 /* Process all dies in compilation unit. */ if (die->child !=3D 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/gd= b.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 =3D 0"] + +with_complaints 5 { + gdb_test $cmd $re "$cmd with no complaints" +}