From f80d7a791b67ab63822c31a6866fce3c2ee04e27 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 15 Nov 2024 22:48:37 +0100 Subject: [gdb/symtab] Fix segfault with dwp file Consider the following test-case: ... $ cat test.c int main (void) { return 0; } $ clang -g -gsplit-dwarf test.c -o test $ llvm-dwp -e test -o test.dwp ... This runs into a segmentation fault: ... $ gdb -q -batch test Fatal signal: Segmentation fault ... The segmentation fault happens because in read_dwo_str_index this line sets p to nullptr: ... const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer; ... while the following code expects it to point to some data. The section we're trying to read is: ... (gdb) p reader->dwo_file->sections.str_offsets $4 = {s = {section = 0xffffcc00a9d0, containing_section = 0xffffcc00a9d0}, buffer = 0x0, size = 28, virtual_offset = 0, readin = false, is_virtual = true} ... At first glance, the section is not readin, but actually it is. This is a virtual section, meaning part of a containing section: ... (gdb) p *reader->dwo_file->sections.str_offsets.s.containing_section $8 = {s = {section = 0xffffcc00cde8, containing_section = 0xffffcc00cde8}, buffer = 0xffffcc009650 "\030", size = 28, virtual_offset = 0, readin = true, is_virtual = false} ... which is readin. Fix this in create_dwp_v2_or_v5_section by initializing the buffer of the virtual section using the buffer of the containing section: ... result.buffer = section->buffer + offset; ... Unfortunately it's difficult to write a test-case for this. We'll have to teach the dwarf assembler to generate dwp files. Tested on aarch64-linux. This is a partial fix for PR symtab/31497. Approved-By: Tom Tromey Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31497 --- gdb/dwarf2/read.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 5f0b0d4..1c9706d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8615,6 +8615,9 @@ create_dwp_v2_or_v5_section (dwarf2_per_objfile *per_objfile, result.virtual_offset = offset; result.size = size; + gdb_assert (section->readin); + result.readin = true; + result.buffer = section->buffer + offset; return result; } -- cgit v1.1