llvm.org GIT mirror llvm / d2e0f7e
DebugInfo: Support imported modules in lexical blocks git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181271 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
4 changed file(s) with 133 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
9292 /// getLowerBoundDefault - Return the default lower bound for an array. If the
9393 /// DWARF version doesn't handle the language, return -1.
9494 int64_t getDefaultLowerBound() const;
95
96 /// getOrCreateContextDIE - Get context owner's DIE.
97 DIE *getOrCreateContextDIE(DIDescriptor Context);
9895
9996 public:
10097 CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, DwarfDebug *DW,
371368 /// createStaticMemberDIE - Create new static data member DIE.
372369 DIE *createStaticMemberDIE(DIDerivedType DT);
373370
371 /// getOrCreateContextDIE - Get context owner's DIE.
372 DIE *getOrCreateContextDIE(DIDescriptor Context);
373
374374 private:
375375
376376 // DIEValueAllocator - All DIEValues are allocated through this allocator.
9393 namespace {
9494 const char *DWARFGroupName = "DWARF Emission";
9595 const char *DbgTimerName = "DWARF Debug Writer";
96
97 struct CompareFirst {
98 template bool operator()(const T &lhs, const T &rhs) const {
99 return lhs.first < rhs.first;
100 }
101 };
96102 } // end anonymous namespace
97103
98104 //===----------------------------------------------------------------------===//
596602 }
597603 else {
598604 // There is no need to emit empty lexical block DIE.
599 if (Children.empty())
605 std::pair
606 ImportedEntityMap::const_iterator> Range = std::equal_range(
607 ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
608 std::pair(DS, 0), CompareFirst());
609 if (Children.empty() && Range.first == Range.second)
600610 return NULL;
601611 ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
612 for (ImportedEntityMap::const_iterator i = Range.first; i != Range.second; ++i)
613 constructImportedModuleDIE(TheCU, i->second, ScopeDIE);
602614 }
603615
604616 if (!ScopeDIE) return NULL;
767779 DIImportedModule Module(N);
768780 if (!Module.Verify())
769781 return;
782 if (DIE *D = TheCU->getOrCreateContextDIE(Module.getContext()))
783 constructImportedModuleDIE(TheCU, Module, D);
784 }
785
786 void DwarfDebug::constructImportedModuleDIE(CompileUnit *TheCU, const MDNode *N,
787 DIE *Context) {
788 DIImportedModule Module(N);
789 if (!Module.Verify())
790 return;
791 return constructImportedModuleDIE(TheCU, Module, Context);
792 }
793
794 void DwarfDebug::constructImportedModuleDIE(CompileUnit *TheCU,
795 const DIImportedModule &Module,
796 DIE *Context) {
797 assert(Module.Verify() &&
798 "Use one of the MDNode * overloads to handle invalid metadata");
799 assert(Context && "Should always have a context for an imported_module");
770800 DIE *IMDie = new DIE(dwarf::DW_TAG_imported_module);
771801 TheCU->insertDIE(Module, IMDie);
772802 DIE *NSDie = TheCU->getOrCreateNameSpace(Module.getNameSpace());
776806 TheCU->addUInt(IMDie, dwarf::DW_AT_decl_file, 0, FileID);
777807 TheCU->addUInt(IMDie, dwarf::DW_AT_decl_line, 0, Module.getLineNumber());
778808 TheCU->addDIEEntry(IMDie, dwarf::DW_AT_import, dwarf::DW_FORM_ref4, NSDie);
779 TheCU->addToContextOwner(IMDie, Module.getContext());
809 Context->addChild(IMDie);
780810 }
781811
782812 // Emit all Dwarf sections that should come prior to the content. Create
800830 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
801831 DICompileUnit CUNode(CU_Nodes->getOperand(i));
802832 CompileUnit *CU = constructCompileUnit(CUNode);
833 DIArray ImportedModules = CUNode.getImportedModules();
834 for (unsigned i = 0, e = ImportedModules.getNumElements(); i != e; ++i)
835 ScopesWithImportedEntities.push_back(std::make_pair(
836 DIImportedModule(ImportedModules.getElement(i)).getContext(),
837 ImportedModules.getElement(i)));
838 std::sort(ScopesWithImportedEntities.begin(),
839 ScopesWithImportedEntities.end(), CompareFirst());
803840 DIArray GVs = CUNode.getGlobalVariables();
804841 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
805842 CU->createGlobalVariableDIE(GVs.getElement(i));
814851 CU->getOrCreateTypeDIE(RetainedTypes.getElement(i));
815852 // Emit imported_modules last so that the relevant context is already
816853 // available.
817 DIArray ImportedModules = CUNode.getImportedModules();
818854 for (unsigned i = 0, e = ImportedModules.getNumElements(); i != e; ++i)
819855 constructImportedModuleDIE(CU, ImportedModules.getElement(i));
820856 // If we're splitting the dwarf out now that we've got the entire
432432 // Holder for the skeleton information.
433433 DwarfUnits SkeletonHolder;
434434
435 typedef SmallVector, 32>
436 ImportedEntityMap;
437 ImportedEntityMap ScopesWithImportedEntities;
438
435439 private:
436440
437441 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
556560
557561 /// \brief Construct import_module DIE.
558562 void constructImportedModuleDIE(CompileUnit *TheCU, const MDNode *N);
563
564 /// \brief Construct import_module DIE.
565 void constructImportedModuleDIE(CompileUnit *TheCU, const MDNode *N,
566 DIE *Context);
567
568 /// \brief Construct import_module DIE.
569 void constructImportedModuleDIE(CompileUnit *TheCU,
570 const DIImportedModule &Module,
571 DIE *Context);
559572
560573 /// \brief Register a source line with debug info. Returns the unique
561574 /// label that was emitted and which provides correspondence to the
22 ; RUN: llc -O0 -filetype=obj < %s > %t
33 ; RUN: llvm-dwarfdump %t | FileCheck %s
44 ; CHECK: debug_info contents
5 ; CHECK: DW_TAG_namespace
5 ; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace
66 ; CHECK-NEXT: DW_AT_name{{.*}} = "A"
77 ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F1:[0-9]]])
88 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x03)
1414 ; CHECK-NOT: NULL
1515 ; CHECK: DW_TAG_variable
1616 ; CHECK-NEXT: DW_AT_name{{.*}}= "i"
17 ; CHECK: NULL
18 ; CHECK-NOT: NULL
19 ; CHECK: DW_TAG_imported_module
20 ; This is a bug, it should be in F2 but it inherits the file from its
21 ; enclosing scope
22 ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F1]])
23 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x04)
24 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]})
25
1726 ; CHECK: DW_TAG_subprogram
1827 ; CHECK-NEXT: DW_AT_MIPS_linkage_name
1928 ; CHECK-NEXT: DW_AT_name{{.*}}= "func"
2029 ; CHECK-NOT: NULL
2130 ; CHECK: DW_TAG_imported_module
2231 ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]])
23 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x07)
32 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0e)
33 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]})
34 ; CHECK-NOT: NULL
35 ; CHECK: DW_TAG_lexical_block
36 ; CHECK-NOT: NULL
37 ; CHECK: DW_TAG_imported_module
38 ; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]])
39 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x0b)
2440 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]})
41
2542 ; CHECK: file_names[ [[F1]]]{{.*}}debug-info-namespace.cpp
2643 ; CHECK: file_names[ [[F2]]]{{.*}}foo.cpp
2744
3249 ; namespace B {
3350 ; int i;
3451 ; }
52 ; using namespace B;
3553 ; }
3654 ;
37 ; int func() {
38 ; using namespace A::B;
39 ; return i;
55 ; using namespace A;
56 ;
57 ; int func(bool b) {
58 ; if (b) {
59 ; using namespace A::B;
60 ; return i;
61 ; }
62 ; using namespace A;
63 ; return B::i;
4064 ; }
4165
4266 @_ZN1A1B1iE = global i32 0, align 4
4367
44 ; Function Attrs: nounwind uwtable
45 define i32 @_Z4funcv() #0 {
68 ; Function Attrs: nounwind uwtable
69 define i32 @_Z4funcb(i1 zeroext %b) #0 {
4670 entry:
47 %0 = load i32* @_ZN1A1B1iE, align 4, !dbg !16
48 ret i32 %0, !dbg !16
71 %retval = alloca i32, align 4
72 %b.addr = alloca i8, align 1
73 %frombool = zext i1 %b to i8
74 store i8 %frombool, i8* %b.addr, align 1
75 call void @llvm.dbg.declare(metadata !{i8* %b.addr}, metadata !21), !dbg !22
76 %0 = load i8* %b.addr, align 1, !dbg !23
77 %tobool = trunc i8 %0 to i1, !dbg !23
78 br i1 %tobool, label %if.then, label %if.end, !dbg !23
79
80 if.then: ; preds = %entry
81 %1 = load i32* @_ZN1A1B1iE, align 4, !dbg !24
82 store i32 %1, i32* %retval, !dbg !24
83 br label %return, !dbg !24
84
85 if.end: ; preds = %entry
86 %2 = load i32* @_ZN1A1B1iE, align 4, !dbg !25
87 store i32 %2, i32* %retval, !dbg !25
88 br label %return, !dbg !25
89
90 return: ; preds = %if.end, %if.then
91 %3 = load i32* %retval, !dbg !26
92 ret i32 %3, !dbg !26
4993 }
5094
95 ; Function Attrs: nounwind readnone
96 declare void @llvm.dbg.declare(metadata, metadata) #1
97
5198 attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
99 attributes #1 = { nounwind readnone }
52100
53101 !llvm.dbg.cu = !{!0}
54102
55 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.3 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !10, metadata !14, metadata !""} ; [ DW_TAG_compile_unit ] [/usr/local/google/home/blaikie/dev/llvm/src/tools/clang//usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp] [DW_LANG_C_plus_plus]
103 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.3 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !11, metadata !15, metadata !""} ; [ DW_TAG_compile_unit ] [/usr/local/google/home/blaikie/dev/llvm/src/tools/clang//usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp] [DW_LANG_C_plus_plus]
56104 !1 = metadata !{metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/test/CodeGenCXX/debug-info-namespace.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang"}
57105 !2 = metadata !{i32 0}
58106 !3 = metadata !{metadata !4}
59 !4 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"func", metadata !"func", metadata !"_Z4funcv", i32 6, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z4funcv, null, null, metadata !2, i32 6} ; [ DW_TAG_subprogram ] [line 6] [def] [func]
107 !4 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"func", metadata !"func", metadata !"_Z4funcb", i32 9, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i1)* @_Z4funcb, null, null, metadata !2, i32 9} ; [ DW_TAG_subprogram ] [line 9] [def] [func]
60108 !5 = metadata !{metadata !"foo.cpp", metadata !"/usr/local/google/home/blaikie/dev/llvm/src/tools/clang"}
61 !6 = metadata !{i32 786473, metadata !5} ; [ DW_TAG_file_type ] [/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/foo.cpp]
109 !6 = metadata !{i32 786473, metadata !5} ; [ DW_TAG_file_type ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp]
62110 !7 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
63 !8 = metadata !{metadata !9}
111 !8 = metadata !{metadata !9, metadata !10}
64112 !9 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
65 !10 = metadata !{metadata !11}
66 !11 = metadata !{i32 786484, i32 0, metadata !12, metadata !"i", metadata !"i", metadata !"_ZN1A1B1iE", metadata !6, i32 2, metadata !9, i32 0, i32 1, i32* @_ZN1A1B1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def]
67 !12 = metadata !{i32 786489, metadata !5, metadata !13, metadata !"B", i32 1} ; [ DW_TAG_namespace ] [B] [line 1]
68 !13 = metadata !{i32 786489, metadata !1, null, metadata !"A", i32 3} ; [ DW_TAG_namespace ] [A] [line 3]
69 !14 = metadata !{metadata !15}
70 !15 = metadata !{i32 786490, metadata !4, metadata !12, i32 7} ; [ DW_TAG_imported_module ]
71 !16 = metadata !{i32 8, i32 0, metadata !4, null}
113 !10 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean]
114 !11 = metadata !{metadata !12}
115 !12 = metadata !{i32 786484, i32 0, metadata !13, metadata !"i", metadata !"i", metadata !"_ZN1A1B1iE", metadata !6, i32 2, metadata !9, i32 0, i32 1, i32* @_ZN1A1B1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def]
116 !13 = metadata !{i32 786489, metadata !5, metadata !14, metadata !"B", i32 1} ; [ DW_TAG_namespace ] [B] [line 1]
117 !14 = metadata !{i32 786489, metadata !1, null, metadata !"A", i32 3} ; [ DW_TAG_namespace ] [A] [line 3]
118 !15 = metadata !{metadata !16, metadata !17, metadata !18, metadata !20}
119 !16 = metadata !{i32 786490, metadata !14, metadata !13, i32 4} ; [ DW_TAG_imported_module ]
120 !17 = metadata !{i32 786490, metadata !0, metadata !14, i32 7} ; [ DW_TAG_imported_module ]
121 !18 = metadata !{i32 786490, metadata !19, metadata !13, i32 11} ; [ DW_TAG_imported_module ]
122 !19 = metadata !{i32 786443, metadata !5, metadata !4, i32 10, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/usr/local/google/home/blaikie/dev/llvm/build/clang/debug/foo.cpp]
123 !20 = metadata !{i32 786490, metadata !4, metadata !14, i32 14} ; [ DW_TAG_imported_module ]
124 !21 = metadata !{i32 786689, metadata !4, metadata !"b", metadata !6, i32 16777225, metadata !10, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [b] [line 9]
125 !22 = metadata !{i32 9, i32 0, metadata !4, null}
126 !23 = metadata !{i32 10, i32 0, metadata !4, null}
127 !24 = metadata !{i32 12, i32 0, metadata !19, null}
128 !25 = metadata !{i32 15, i32 0, metadata !4, null}
129 !26 = metadata !{i32 16, i32 0, metadata !4, null}