public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH][gdb/symtab] Fix "file index out of range" complaint
Date: Sat, 17 Sep 2022 08:32:06 +0200	[thread overview]
Message-ID: <86e30d24-4cbd-c617-23f6-17b2c0a23f9d@suse.de> (raw)
In-Reply-To: <20220909065059.GA19794@delia.home>

On 9/9/22 08:51, Tom de Vries wrote:
> 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?
> 

Committed.

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 <http://www.gnu.org/licenses/>.  */
> +
> +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 <http://www.gnu.org/licenses/>.
> +
> +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"
> +}

      reply	other threads:[~2022-09-17  6:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09  6:51 Tom de Vries
2022-09-17  6:32 ` Tom de Vries [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86e30d24-4cbd-c617-23f6-17b2c0a23f9d@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).