[gdb/symtab] Fix "file index out of range" complaint
authorTom de Vries <tdevries@suse.de>
Sat, 17 Sep 2022 06:22:32 +0000 (08:22 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 17 Sep 2022 06:22:32 +0000 (08:22 +0200)
commit99d679e7b30ea9a0b6ffcd64e9ba35e43166151b
tree5055a9044da2cdf85d999d3c3d5298bae9af5bd1
parent5e3cecb21acfbdc16f65efc276733efe89f5aa25
[gdb/symtab] Fix "file index out of range" complaint

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
gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.c [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/dw2-no-code-cu.exp [new file with mode: 0644]