Skip to content

Commit c4fbb65

Browse files
[llvm-debuginfo-analyzer] Add support for DW_AT_GNU_template_name. (#115724)
For the given C++ code: ``` template <typename T> class Foo { T Member; }; template <template <typename T> class TemplateType> class Bar { TemplateType<int> Int; }; template <template <template <typename> class> class TemplateTemplateType> class Baz { TemplateTemplateType<Foo> Foo; }; typedef Baz<Bar> Example; Example TT; ``` The '--attribute=encoded' option, will produce the logical view: ``` {Class} 'Foo<int>' {Encoded} <int> {Class} 'Bar<Foo>' {Encoded} <> <-- Missing the template argument info (Foo) {Class} 'Baz<Bar>' {Encoded} <> <-- Missing the template argument info (Bar) ``` When the template argument is another template it is not included in the {Encoded} field. The correct output should be: ``` {Class} 'Foo<int>' {Encoded} <int> {Class} 'Bar<Foo>' {Encoded} <Foo> {Class} 'Baz<Bar>' {Encoded} <Bar> ```
1 parent 6cbc373 commit c4fbb65

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
372372
case dwarf::DW_AT_name:
373373
CurrentElement->setName(dwarf::toStringRef(FormValue));
374374
break;
375+
case dwarf::DW_AT_GNU_template_name:
376+
CurrentElement->setValue(dwarf::toStringRef(FormValue));
377+
break;
375378
case dwarf::DW_AT_linkage_name:
376379
case dwarf::DW_AT_MIPS_linkage_name:
377380
CurrentElement->setLinkageName(dwarf::toStringRef(FormValue));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; REQUIRES: x86-registered-target
2+
3+
; For the given test case:
4+
5+
; 1 // Template Template parameters.
6+
; 2 // Simple template class
7+
; 3 template <typename T> class Foo { T Member; };
8+
; 4
9+
; 5 // Template template class
10+
; 6 template <template <typename T> class TemplateType>
11+
; 7 class Bar {
12+
; 8 TemplateType<int> Int;
13+
; 9 };
14+
; 10
15+
; 11 template <template <template <typename> class> class TemplateTemplateType>
16+
; 12 class Baz {
17+
; 13 TemplateTemplateType<Foo> Foo;
18+
; 14 };
19+
; 15
20+
; 16 typedef Baz<Bar> Example;
21+
; 17
22+
; 18 Example TT;
23+
24+
; The llvm-debuginfo-analyzer did not support the DW_AT_GNU_template_name
25+
; attribute. When using '--attribute=encoded' and the template argument is
26+
; another template, it would show:
27+
; {Encoded} <>
28+
29+
; The object file is generated using the following commands:
30+
;
31+
; clang++ -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes
32+
; -fno-discard-value-names -emit-llvm -S -g -O0
33+
; DW_AT_GNU_template_name.cpp -o DW_AT_GNU_template_name.ll
34+
; llc --filetype=obj DW_AT_GNU_template_name.ll -o DW_AT_GNU_template_name.o
35+
;
36+
; llvm-debuginfo-analyzer --attribute=encoded --print=symbols
37+
; DW_AT_GNU_template_name.o
38+
39+
; RUN: llc --filetype=obj \
40+
; RUN: %p/Inputs/DW_AT_GNU_template_name.ll -o %t.DW_AT_GNU_template_name.o
41+
42+
; RUN: llvm-debuginfo-analyzer --attribute=encoded \
43+
; RUN: --print=symbols \
44+
; RUN: %t.DW_AT_GNU_template_name.o 2>&1 | \
45+
; RUN: FileCheck --strict-whitespace %s
46+
47+
; CHECK: Logical View:
48+
; CHECK: {File} '{{.*}}dw_at_gnu_template_name.o'
49+
; CHECK-EMPTY:
50+
; CHECK: {CompileUnit} 'dw_at_gnu_template_name.cpp'
51+
; CHECK: 3 {Class} 'Foo<int>'
52+
; CHECK: {Encoded} <int>
53+
; CHECK: 3 {Member} private 'Member' -> 'int'
54+
; CHECK: 7 {Class} 'Bar<Foo>'
55+
; CHECK: {Encoded} <Foo>
56+
; CHECK: 8 {Member} private 'Int' -> 'Foo<int>'
57+
; CHECK: 12 {Class} 'Baz<Bar>'
58+
; CHECK: {Encoded} <Bar>
59+
; CHECK: 13 {Member} private 'Foo' -> 'Bar<Foo>'
60+
; CHECK: 18 {Variable} extern 'TT' -> 'Example'
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
source_filename = "DW_AT_GNU_template_name.cpp"
2+
target triple = "x86_64-pc-linux-gnu"
3+
4+
%class.Baz = type { %class.Bar }
5+
%class.Bar = type { %class.Foo }
6+
%class.Foo = type { i32 }
7+
8+
@TT = dso_local global %class.Baz zeroinitializer, align 4, !dbg !0
9+
10+
!llvm.dbg.cu = !{!2}
11+
!llvm.module.flags = !{!22, !23}
12+
13+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
14+
!1 = distinct !DIGlobalVariable(name: "TT", scope: !2, file: !3, line: 18, type: !5, isLocal: false, isDefinition: true)
15+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, emissionKind: FullDebug, globals: !4)
16+
!3 = !DIFile(filename: "DW_AT_GNU_template_name.cpp", directory: "")
17+
!4 = !{!0}
18+
!5 = !DIDerivedType(tag: DW_TAG_typedef, name: "Example", file: !3, line: 16, baseType: !6)
19+
!6 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Baz<Bar>", file: !3, line: 12, size: 32, flags: DIFlagTypePassByValue, elements: !7, templateParams: !20, identifier: "_ZTS3BazI3BarE")
20+
!7 = !{!8}
21+
!8 = !DIDerivedType(tag: DW_TAG_member, name: "Foo", scope: !6, file: !3, line: 13, baseType: !9, size: 32)
22+
!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Bar<Foo>", file: !3, line: 7, size: 32, flags: DIFlagTypePassByValue, elements: !10, templateParams: !18, identifier: "_ZTS3BarI3FooE")
23+
!10 = !{!11}
24+
!11 = !DIDerivedType(tag: DW_TAG_member, name: "Int", scope: !9, file: !3, line: 8, baseType: !12, size: 32)
25+
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Foo<int>", file: !3, line: 3, size: 32, flags: DIFlagTypePassByValue, elements: !13, templateParams: !16, identifier: "_ZTS3FooIiE")
26+
!13 = !{!14}
27+
!14 = !DIDerivedType(tag: DW_TAG_member, name: "Member", scope: !12, file: !3, line: 3, baseType: !15, size: 32)
28+
!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
29+
!16 = !{!17}
30+
!17 = !DITemplateTypeParameter(name: "T", type: !15)
31+
!18 = !{!19}
32+
!19 = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "TemplateType", value: !"Foo")
33+
!20 = !{!21}
34+
!21 = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "TemplateTemplateType", value: !"Bar")
35+
!22 = !{i32 7, !"Dwarf Version", i32 5}
36+
!23 = !{i32 2, !"Debug Info Version", i32 3}

0 commit comments

Comments
 (0)