]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/symtab] Bail out for too short line header
authorTom de Vries <tdevries@suse.de>
Wed, 3 Dec 2025 07:58:13 +0000 (08:58 +0100)
committerTom de Vries <tdevries@suse.de>
Wed, 3 Dec 2025 07:58:13 +0000 (08:58 +0100)
commita8ea3fb759651f97e0340c30b200b7389daf436d
tree9c828ab4d753dd3f7d59710470afbc14a1ffcba1
parent3b4a18f4d19569f94148ebf748052a4b9b11cc75
[gdb/symtab] Bail out for too short line header

The Free Pascal Compiler fpc supports generating different versions of DWARF:
...
$ fpc -h
Free Pascal Compiler version 3.2.2 [2025/09/10] for x86_64
  ...
      -gw        Generate DWARFv2 debug information (same as -gw2)
      -gw2       Generate DWARFv2 debug information
      -gw3       Generate DWARFv3 debug information
      -gw4       Generate DWARFv4 debug information (experimental)
...

The v4 support is experimental, and indeed the line number information is
broken (missing maximum_operations_per_instruction field in the .debug_line
header), so setting a breakpoint on a line number is not possible:
...
$ fpc -gw4 hello.pas
  ...
$ gdb -q hello
Reading symbols from hello...
(gdb) b hello.pas:8
No compiled code for line 8 in file "hello.pas".
Make breakpoint pending on future shared library load? (y or [n])
...

The brokenness is detected by llvm-dwarfdump (second warning):
...
$ llvm-dwarfdump -debug-line hello
hello: file format elf64-x86-64

.debug_line contents:
debug_line[0x00000000]
warning: parsing line table prologue at offset 0x0 found opcode base of 0. \
  Assuming no standard opcodes
warning: unknown data in line table prologue at offset 0x0: parsing ended (at \
  offset 0x00000017) before reaching the prologue end at offset 0x2a
...

Likewise, detect the situation the second warning describes in
dwarf_decode_line_header, getting us instead:
...
(gdb) b hello.pas:8
āŒmalformed line number program header, advertised length does not match \
  actual length
(gdb)
...

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/line-header.c
gdb/testsuite/gdb.dwarf2/malformed-line-header.exp [new file with mode: 0644]
gdb/testsuite/lib/dwarf.exp