binutils-gdb/gdb/dwarf2
Tom de Vries bab31d1451 [gdb/symtab] Support .debug_line with DW_FORM_line_strp
I noticed a new gcc option -gdwarf64 and tried it out (using gcc 11.2.1).

With a test-case hello.c:
...
int
main (void)
{
  printf ("hello\n");
  return 0;
}
...
compiled like this:
...
$ gcc -g -gdwarf64 ~/hello.c
...
I ran into:
...
$ gdb -q -batch a.out
DW_FORM_line_strp pointing outside of .debug_line_str section \
  [in module a.out]
...

Debugging gdb revealed that the string offset is:
...
(gdb) up
    objfile=0x182ab70, str_offset=1378684502312,
    form_name=0xeae9b5 "DW_FORM_line_strp")
    at src/gdb/dwarf2/section.c:208
208         error (_("%s pointing outside of %s section [in module %s]"),
(gdb) p /x str_offset
$1 = 0x14100000128
(gdb)
...
which is read when parsing a .debug_line entry at 0x1e0.

Looking with readelf at the 0x1e0 entry, we have:
...
 The Directory Table (offset 0x202, lines 2, columns 1):
  Entry Name
  0     (indirect line string, offset: 0x128): /data/gdb_versions/devel
  1     (indirect line string, offset: 0x141): /home/vries
...
which in a hexdump looks like:
...
  0x00000200 1f022801 00004101 00000201 1f020f02
...

What happens is the following:
- readelf interprets the DW_FORM_line_strp reference to .debug_line_str as
  a 4 byte value, and sees entries 0x00000128 and 0x00000141.
- gdb instead interprets it as an 8 byte value, and sees as first entry
  0x0000014100000128, which is too big so it bails out.

AFAIU, gdb is wrong.  It assumes DW_FORM_line_strp is 8 bytes on the basis
that the corresponding CU is 64-bit DWARF.  However, the .debug_line
contribution has it's own initial_length field, and encodes there that it's
32-bit DWARF.

Fix this by using the correct offset size for DW_FORM_line_strp references
in .debug_line.

Note: the described test-case does trigger this complaint (both with and
without this patch):
...
$ gdb -q -batch -iex "set complaints 10" a.out
During symbol reading: intermixed 32-bit and 64-bit DWARF sections
...

The reason that the CU has 64-bit dwarf is because -gdwarf64 was passed to
gcc.  The reason that the .debug_line entry has 32-bit dwarf is because that's
what gas generates.  Perhaps this is complaint-worthy, but I don't think it
is wrong.

Tested on x86_64-linux, using native and target board dwarf64.exp.
2021-11-22 09:14:16 +01:00
..
abbrev.c Remove Irix 6 workaround from DWARF abbrev reader 2021-03-13 09:41:05 -07:00
abbrev.h Constify abbrev_table::lookup_abbrev 2021-03-13 09:41:05 -07:00
attribute.c [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const 2021-02-24 23:58:42 +01:00
attribute.h [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const 2021-02-24 23:58:42 +01:00
comp-unit-head.c Rename dwarf2/comp-unit.h 2021-05-17 14:16:07 -06:00
comp-unit-head.h Rename dwarf2/comp-unit.h 2021-05-17 14:16:07 -06:00
cu.c CTF: incorrect underlying type setting for enumeration types 2021-10-18 14:15:21 -04:00
cu.h Remove dwarf2_cu::language 2021-06-25 12:23:05 -06:00
die.h gdb/dwarf: split dwarf2_cu::ranges_base in two 2021-02-02 10:42:11 -05:00
dwz.c gdb: make string-like set show commands use std::string variable 2021-10-03 17:53:16 +01:00
dwz.h Move dwarf2_get_dwz_file to dwarf2/dwz.h 2021-03-06 09:26:40 -07:00
expr.c gdb: change functions returning value contents to use gdb::array_view 2021-10-25 14:51:44 -04:00
expr.h Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
frame-tailcall.c [gdb/symtab] C++-ify call_site 2021-10-04 18:16:40 +02:00
frame-tailcall.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
frame.c Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
frame.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-cache.c gdb: introduce "set index-cache enabled", deprecate "set index-cache on/off" 2021-11-04 15:48:59 -04:00
index-cache.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-common.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-common.h Handle unaligned mapping of .gdb_index 2021-04-17 13:56:36 -06:00
index-write.c gdbsupport: make gdb_mkostemp_cloexec return a scoped_fd 2021-09-30 15:21:48 -04:00
index-write.h Introduce dwarf2/public.h 2021-03-20 17:23:40 -06:00
leb.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
leb.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
line-header.c [gdb/symtab] Support .debug_line with DW_FORM_line_strp 2021-11-22 09:14:16 +01:00
line-header.h Fix file-name handling regression with DWARF index 2021-07-17 11:08:18 -06:00
loc.c Handle PIE in .debug_loclists 2021-11-10 12:16:40 -07:00
loc.h Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
macro.c Include objfiles.h in a few .c files 2021-08-08 08:53:17 -06:00
macro.h gdb: avoid dereferencing empty str_offsets_base optional in dwarf_decode_macros 2021-08-04 15:26:22 -04:00
public.h Simplify DWARF reader initialization 2021-03-28 10:43:15 -06:00
read.c [gdb/symtab] Support .debug_line with DW_FORM_line_strp 2021-11-22 09:14:16 +01:00
read.h [gdb/symtab] Support .debug_line with DW_FORM_line_strp 2021-11-22 09:14:16 +01:00
sect-names.h Move dwarf2_get_dwz_file to dwarf2/dwz.h 2021-03-06 09:26:40 -07:00
section.c gdb: Handle missing .debug_str section 2021-04-07 11:31:30 +01:00
section.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
stringify.c Reimplement dwarf_unit_type_name 2021-03-18 12:08:41 -06:00
stringify.h Fix typo in dwarf2/stringify.h 2021-03-31 09:48:56 -06:00