Skip to content

Commit e8e9a33

Browse files
authored
[LLVM][DWARF] Add compilation directory and dwo name to TU in dwo section (#74909)
This adds support to help LLDB when binary is built with split dwarf, has .debug_names accelerator table and DWP file. Final linked binary might have Type Units (TUs) with the same type signature in multiple compilation units. Although the signature is the same, TUs are not guranted to be bit identical. This is not a problem when they are in .o/.dwo files as LLDB can find them by looking at the right one based on DW_AT_comp_dir/DW_AT_name in skeleton CU. Once DWP is created, TUs are de-duplicated, and we need to know from which CU remaining one came from. This approach allows LLDB to figure it out, with minimal changes to the rest of the tooling. As would have been the case if .debug_tu_index section in DWP was modified.
1 parent d9671bb commit e8e9a33

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,16 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
34783478
Ins.first->second = Signature;
34793479

34803480
if (useSplitDwarf()) {
3481+
// Although multiple type units can have the same signature, they are not
3482+
// guranteed to be bit identical. When LLDB uses .debug_names it needs to
3483+
// know from which CU a type unit came from. These two attrbutes help it to
3484+
// figure that out.
3485+
if (getDwarfVersion() >= 5) {
3486+
if (!CompilationDir.empty())
3487+
NewTU.addString(UnitDie, dwarf::DW_AT_comp_dir, CompilationDir);
3488+
NewTU.addString(UnitDie, dwarf::DW_AT_dwo_name,
3489+
Asm->TM.Options.MCOptions.SplitDwarfFile);
3490+
}
34813491
MCSection *Section =
34823492
getDwarfVersion() <= 4
34833493
? Asm->getObjFileLowering().getDwarfTypesDWOSection()

llvm/test/CodeGen/X86/dwarf-headers.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575
; O-5: .debug_info contents:
7676
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
7777
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
78-
; O-5: 0x00000014: DW_TAG_skeleton_unit
78+
; O-5: 0x00000014: DW_TAG_skeleton_unit
7979
;
8080
; DWO-5: .debug_info.dwo contents:
8181
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
8282
; DWO-5: 0x00000018: DW_TAG_type_unit
83-
; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
83+
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
8484
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
85-
; DWO-5: 0x00000047: DW_TAG_compile_unit
85+
; DWO-5: 0x00000049: DW_TAG_compile_unit
8686

8787

8888
; ModuleID = 't.cpp'

llvm/test/DebugInfo/WebAssembly/dwarf-headers.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@
7777
; O-5: .debug_info contents:
7878
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
7979
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
80-
; O-5: 0x00000014: DW_TAG_skeleton_unit
80+
; O-5: 0x00000014: DW_TAG_skeleton_unit
8181
;
8282
; DWO-5: .debug_info.dwo contents:
8383
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
8484
; DWO-5: 0x00000018: DW_TAG_type_unit
85-
; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
85+
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
8686
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
87-
; DWO-5: 0x00000047: DW_TAG_compile_unit
87+
; DWO-5: 0x00000049: DW_TAG_compile_unit
8888

8989

9090
; ModuleID = 't.cpp'

llvm/test/DebugInfo/X86/debug-names-types.ll

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; UNSUPPORTED: system-windows
22
; This checks that .debug_names can be generated with monolithic, and split-dwarf, when -fdebug-type-sections is enabled.
3+
; It also checks that TU in .debug_info.dwo has correct DW_AT_comp_dir and DW_AT_dwo_name.
34
; Generated with: clang++ main.cpp -g2 -gdwarf-5 -gpubnames -fdebug-types-section
45

56
; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t
@@ -171,7 +172,7 @@
171172
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV1]]
172173
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
173174
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
174-
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001f
175+
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000021
175176
; CHECK-SPLIT-NEXT: }
176177
; CHECK-SPLIT-NEXT: Entry @ 0xae {
177178
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]]
@@ -199,13 +200,35 @@
199200
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV4]]
200201
; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type
201202
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
202-
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000034
203+
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000036
203204
; CHECK-SPLIT-NEXT: }
204205
; CHECK-SPLIT-NEXT: }
205206
; CHECK-SPLIT-NEXT: ]
206207
; CHECK-SPLIT-NEXT: }
207208

208209

210+
211+
; RUN: llvm-dwarfdump -debug-info -r 0 %t > %tdebugInfo.txt
212+
; RUN: llvm-dwarfdump -debug-info -r 0 %t.mainTypes.dwo >> %tdebugInfo.txt
213+
; RUN: cat %tdebugInfo.txt | FileCheck %s --check-prefixes=CHECK-TYPE
214+
215+
; CHECK-TYPE: DW_TAG_skeleton_unit
216+
; CHECK-TYPE-NEXT: DW_AT_stmt_list
217+
; CHECK-TYPE-NEXT: DW_AT_str_offsets_base
218+
; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
219+
; CHECK-TYPE-NEXT: DW_AT_dwo_name
220+
; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
221+
; CHECK-TYPE-NEXT: DW_AT_low_pc
222+
; CHECK-TYPE-NEXT: DW_AT_high_pc
223+
; CHECK-TYPE-NEXT: DW_AT_addr_base
224+
225+
; CHECK-TYPE: DW_TAG_type_unit
226+
; CHECK-TYPE-NOT: DW_TAG
227+
; CHECK-TYPE: DW_AT_comp_dir ("/typeSmall")
228+
; CHECK-TYPE-NOT: DW_TAG
229+
; CHECK-TYPE: DW_AT_dwo_name
230+
; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
231+
209232
; ModuleID = 'main.cpp'
210233
source_filename = "main.cpp"
211234
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

0 commit comments

Comments
 (0)