[gdb/symtab] Handle empty file name in .debug_line section
authorTom de Vries <tdevries@suse.de>
Mon, 17 Apr 2023 16:09:32 +0000 (18:09 +0200)
committerTom de Vries <tdevries@suse.de>
Mon, 17 Apr 2023 16:09:32 +0000 (18:09 +0200)
commitfb12bc1e8e7c5246e4eabcebdb4644c43bc7e6b9
tree03eec95cd3d3f2ec47719832116c9932a48bf613
parentb29f2fda4f189a008f5f2017d403976c988ad63e
[gdb/symtab] Handle empty file name in .debug_line section

With DWARF 5, it's possible to produce an empty file name in the File Name
Table of the .debug_line section:
...
 The File Name Table (offset 0x112, lines 1, columns 2):
  Entry Dir     Name
  0     1       (indirect line string, offset: 0x2d):
...

Currently, when gdb reads an exec containing such debug info, it segfaults:
...
Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
0x000000000072cd38 in dwarf2_start_subfile (cu=0x2badc50, fe=..., lh=...) at \
  gdb/dwarf2/read.c:18716
18716     if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
...
because read_direct_string transforms "" into a nullptr, and we end up
dereferencing the nullptr.

Note that the behaviour of read_direct_string has been present since repo
creation.

Fix this in read_formatted_entries, by transforming nullptr filenames in to ""
filenames.

Tested on x86_64-linux.

Reviewed-By: Tom Tromey <tom@tromey.com>
PR symtab/30357
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30357
gdb/dwarf2/line-header.c
gdb/testsuite/gdb.dwarf2/dw2-empty-file-name.exp [new file with mode: 0644]