Skip to content

[LLVM][DWARF] Add compilation directory and dwo name to TU in dwo section #74909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,16 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
Ins.first->second = Signature;

if (useSplitDwarf()) {
// Although multiple type units can have the same signature, they are not
// guranteed to be bit identical. When LLDB uses .debug_names it needs to
// know from which CU a type unit came from. These two attrbutes help it to
// figure that out.
if (getDwarfVersion() >= 5) {
if (!CompilationDir.empty())
NewTU.addString(UnitDie, dwarf::DW_AT_comp_dir, CompilationDir);
NewTU.addString(UnitDie, dwarf::DW_AT_dwo_name,
Asm->TM.Options.MCOptions.SplitDwarfFile);
}
MCSection *Section =
getDwarfVersion() <= 4
? Asm->getObjFileLowering().getDwarfTypesDWOSection()
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/X86/dwarf-headers.ll
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
; O-5: .debug_info contents:
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
; O-5: 0x00000014: DW_TAG_skeleton_unit
; O-5: 0x00000014: DW_TAG_skeleton_unit
;
; DWO-5: .debug_info.dwo contents:
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
; DWO-5: 0x00000018: DW_TAG_type_unit
; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
; DWO-5: 0x00000047: DW_TAG_compile_unit
; DWO-5: 0x00000049: DW_TAG_compile_unit


; ModuleID = 't.cpp'
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/DebugInfo/WebAssembly/dwarf-headers.ll
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
; O-5: .debug_info contents:
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
; O-5: 0x00000014: DW_TAG_skeleton_unit
; O-5: 0x00000014: DW_TAG_skeleton_unit
;
; DWO-5: .debug_info.dwo contents:
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
; DWO-5: 0x00000018: DW_TAG_type_unit
; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
; DWO-5: 0x00000047: DW_TAG_compile_unit
; DWO-5: 0x00000049: DW_TAG_compile_unit


; ModuleID = 't.cpp'
Expand Down
27 changes: 25 additions & 2 deletions llvm/test/DebugInfo/X86/debug-names-types.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; UNSUPPORTED: system-windows
; This checks that .debug_names can be generated with monolithic, and split-dwarf, when -fdebug-type-sections is enabled.
; It also checks that TU in .debug_info.dwo has correct DW_AT_comp_dir and DW_AT_dwo_name.
; Generated with: clang++ main.cpp -g2 -gdwarf-5 -gpubnames -fdebug-types-section

; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t
Expand Down Expand Up @@ -171,7 +172,7 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV1]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001f
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000021
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: Entry @ 0xae {
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]]
Expand Down Expand Up @@ -199,13 +200,35 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV4]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000034
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000036
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: ]
; CHECK-SPLIT-NEXT: }



; RUN: llvm-dwarfdump -debug-info -r 0 %t > %tdebugInfo.txt
; RUN: llvm-dwarfdump -debug-info -r 0 %t.mainTypes.dwo >> %tdebugInfo.txt
; RUN: cat %tdebugInfo.txt | FileCheck %s --check-prefixes=CHECK-TYPE

; CHECK-TYPE: DW_TAG_skeleton_unit
; CHECK-TYPE-NEXT: DW_AT_stmt_list
; CHECK-TYPE-NEXT: DW_AT_str_offsets_base
; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
; CHECK-TYPE-NEXT: DW_AT_dwo_name
; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
; CHECK-TYPE-NEXT: DW_AT_low_pc
; CHECK-TYPE-NEXT: DW_AT_high_pc
; CHECK-TYPE-NEXT: DW_AT_addr_base

; CHECK-TYPE: DW_TAG_type_unit
; CHECK-TYPE-NOT: DW_TAG
; CHECK-TYPE: DW_AT_comp_dir ("/typeSmall")
; CHECK-TYPE-NOT: DW_TAG
; CHECK-TYPE: DW_AT_dwo_name
; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo

; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Expand Down