Summary: | Segmentation fault for the 'start' command | ||
---|---|---|---|
Product: | gdb | Reporter: | Anonymous <iamanonymous.cs> |
Component: | symtab | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | critical | CC: | iamanonymous.cs, tromey, vries |
Priority: | P2 | ||
Version: | 13.1 | ||
Target Milestone: | 13.2 | ||
Host: | Target: | ||
Build: | Last reconfirmed: | 2023-04-15 00:00:00 | |
Attachments: |
triggering source code
Tentative patch |
Description
Anonymous
2023-04-15 03:28:04 UTC
Confirmed on openSUSE Tumbleweed, using: ... gcc version 13.0.1 20230314 (experimental) [revision 42630fadbe248717859d61c0244c821c32b4e52c] (SUSE Linux) ... Happens here: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. 0x000000000072cd38 in dwarf2_start_subfile (cu=0x2badc50, fe=..., lh=...) at /data/vries/gdb/src/gdb/dwarf2/read.c:18716 18716 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) ... because: ... (gdb) p filename $1 = 0x0 ... It's probably triggered by an empty file name in the file name table: ... The File Name Table (offset 0x219, lines 2, columns 2): Entry Dir Name 0 0 (indirect line string, offset: 0x3c): 1 0 (indirect line string, offset: 0x14d): test.c ... Fixed by: ... diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 9d74c8fe75b..d59b63588d0 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -51,6 +51,9 @@ line_header::add_file_name (const char *name, file_name_index index = version >= 5 ? file_names_size (): file_names_size () + 1; + if (name == nullptr) + name = ""; + if (dwarf_line_debug >= 2) gdb_printf (gdb_stdlog, "Adding file %d: %s\n", index, name); ... (In reply to Tom de Vries from comment #2) > Fixed by: > ... > diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c > index 9d74c8fe75b..d59b63588d0 100644 > --- a/gdb/dwarf2/line-header.c > +++ b/gdb/dwarf2/line-header.c > @@ -51,6 +51,9 @@ line_header::add_file_name (const char *name, > file_name_index index > = version >= 5 ? file_names_size (): file_names_size () + 1; > > + if (name == nullptr) > + name = ""; > + > if (dwarf_line_debug >= 2) > gdb_printf (gdb_stdlog, "Adding file %d: %s\n", index, name); > ... Thanks. I will update gdb to the latest version. read_direct_string replaces "" with NULL, which seems a little weird. Anyway maybe read_formatted_entries should undo this. Or perhaps there should be a non-transforming variant of read_direct_string. Created attachment 14830 [details]
Tentative patch
Currently testing.
(In reply to Tom Tromey from comment #4) > Anyway maybe read_formatted_entries should undo this. With the tentative patch taking this approach. The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fb12bc1e8e7c5246e4eabcebdb4644c43bc7e6b9 commit fb12bc1e8e7c5246e4eabcebdb4644c43bc7e6b9 Author: Tom de Vries <tdevries@suse.de> Date: Mon Apr 17 18:09:32 2023 +0200 [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 Fixed by commit. The gdb-13-branch branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=69eedc8e312685d9c0055098e9c461b95a2e832f commit 69eedc8e312685d9c0055098e9c461b95a2e832f Author: Tom de Vries <tdevries@suse.de> Date: Tue Apr 18 05:47:21 2023 +0200 [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 |