Skip to content

Commit 26ca2f4

Browse files
[DebugInfo] Parse StrOffsets section if needed
Querying the debug_str_offsets section requires parsing the top level DIE of the CU (as well as the section itself); the current getter, however, assumes this is done elsewhere. This patch changes the getter behavior to match what is done in other getter methods (e.g. `getCompilationDir` or `getVariableForAddress`), in other words, `extractDIEsIfNeeded` is now called prior to returning the debug_str_offsets contributions for the Unit. One way in which this bug manifested is when `dwarfdump --debug-str-offsets` is invoked: because the DIEs are never parsed, we incorrectly print an empty section (with no warnings or errors). Differential Revision: https://reviews.llvm.org/D159484
1 parent d9c9c9f commit 26ca2f4

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ class DWARFUnit {
400400
void clear();
401401

402402
const std::optional<StrOffsetsContributionDescriptor> &
403-
getStringOffsetsTableContribution() const {
403+
getStringOffsetsTableContribution() {
404+
extractDIEsIfNeeded(true /*CUDIeOnly*/);
404405
return StringOffsetsTableContribution;
405406
}
406407

llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o
2-
# RUN: llvm-dwarfdump -v %t.o 2> %t.err | FileCheck --check-prefix=COMMON --check-prefix=SPLIT %s
2+
# RUN: llvm-dwarfdump -v %t.o 2> %t.err | FileCheck --check-prefixes=COMMON,SPLIT,OFFSETS %s
33
# RUN: llvm-dwarfdump -verify %t.o | FileCheck --check-prefix=VERIFY %s
4+
# RUN: llvm-dwarfdump -debug-str-offsets %t.o | FileCheck --check-prefix=OFFSETS %s
45
#
56
# Check that we don't report an error on a non-existent range list table.
67
# RUN: FileCheck -allow-empty --check-prefix ERR %s < %t.err
@@ -403,31 +404,31 @@ TU_split_5_end:
403404
# SPLIT-NEXT: DW_AT_name [DW_FORM_strx] (indexed (00000004) string = "V5_split_Mystruct")
404405
#
405406
# The .debug_str_offsets section
406-
# COMMON: .debug_str_offsets contents:
407-
# COMMON-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
408-
# COMMON-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
409-
# COMMON-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
410-
# COMMON-NEXT: 0x00000010: 00000027 "/home/test/CU1"
411-
# COMMON-NEXT: 0x00000014: 00000067 "MyFunc"
412-
# COMMON-NEXT: 0x00000018: 0000006e "MyVar1"
413-
# COMMON-NEXT: 0x0000001c: 00000075 "MyVar2"
414-
# COMMON-NEXT: 0x00000020: 0000007c "MyVar3"
415-
# COMMON-NEXT: Gap, length = 4
416-
# COMMON-NEXT: 0x00000028: Contribution size = 28, Format = DWARF64, Version = 5
417-
# COMMON-NEXT: 0x00000038: 0000000000000000 "Handmade DWARF producer"
418-
# COMMON-NEXT: 0x00000040: 0000000000000036 "Compile_Unit_2"
419-
# COMMON-NEXT: 0x00000048: 0000000000000045 "/home/test/CU2"
420-
# COMMON-NEXT: 0x00000050: Contribution size = 12, Format = DWARF32, Version = 5
421-
# COMMON-NEXT: 0x00000058: 00000054 "Type_Unit"
422-
# COMMON-NEXT: 0x0000005c: 0000005e "MyStruct"
407+
# OFFSETS: .debug_str_offsets contents:
408+
# OFFSETS-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
409+
# OFFSETS-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
410+
# OFFSETS-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
411+
# OFFSETS-NEXT: 0x00000010: 00000027 "/home/test/CU1"
412+
# OFFSETS-NEXT: 0x00000014: 00000067 "MyFunc"
413+
# OFFSETS-NEXT: 0x00000018: 0000006e "MyVar1"
414+
# OFFSETS-NEXT: 0x0000001c: 00000075 "MyVar2"
415+
# OFFSETS-NEXT: 0x00000020: 0000007c "MyVar3"
416+
# OFFSETS-NEXT: Gap, length = 4
417+
# OFFSETS-NEXT: 0x00000028: Contribution size = 28, Format = DWARF64, Version = 5
418+
# OFFSETS-NEXT: 0x00000038: 0000000000000000 "Handmade DWARF producer"
419+
# OFFSETS-NEXT: 0x00000040: 0000000000000036 "Compile_Unit_2"
420+
# OFFSETS-NEXT: 0x00000048: 0000000000000045 "/home/test/CU2"
421+
# OFFSETS-NEXT: 0x00000050: Contribution size = 12, Format = DWARF32, Version = 5
422+
# OFFSETS-NEXT: 0x00000058: 00000054 "Type_Unit"
423+
# OFFSETS-NEXT: 0x0000005c: 0000005e "MyStruct"
423424
#
424-
# SPLIT: .debug_str_offsets.dwo contents:
425-
# SPLIT-NEXT: 0x00000000: Contribution size = 24, Format = DWARF32, Version = 5
426-
# SPLIT-NEXT: 0x00000008: 00000000 "Handmade split DWARF producer"
427-
# SPLIT-NEXT: 0x0000000c: 0000001e "V5_split_compile_unit"
428-
# SPLIT-NEXT: 0x00000010: 00000034 "/home/test/splitCU"
429-
# SPLIT-NEXT: 0x00000014: 00000047 "V5_split_type_unit"
430-
# SPLIT-NEXT: 0x00000018: 0000005a "V5_split_Mystruct"
425+
# OFFSETS: .debug_str_offsets.dwo contents:
426+
# OFFSETS-NEXT: 0x00000000: Contribution size = 24, Format = DWARF32, Version = 5
427+
# OFFSETS-NEXT: 0x00000008: 00000000 "Handmade split DWARF producer"
428+
# OFFSETS-NEXT: 0x0000000c: 0000001e "V5_split_compile_unit"
429+
# OFFSETS-NEXT: 0x00000010: 00000034 "/home/test/splitCU"
430+
# OFFSETS-NEXT: 0x00000014: 00000047 "V5_split_type_unit"
431+
# OFFSETS-NEXT: 0x00000018: 0000005a "V5_split_Mystruct"
431432

432433
# VERIFY: No errors.
433434

0 commit comments

Comments
 (0)