llvm.org GIT mirror llvm / 2c9905a
Debug Info: Use DIScopeRef for DIType::getContext. In DIBuilder, the context field of a TAG_member is updated to use the scope reference. Verifier is updated accordingly. DebugInfoFinder now needs to generate a type identifier map to have access to the actual scope. Same applies for BreakpointPrinter. processModule of DebugInfoFinder is called during initialization phase of the verifier to make sure the type identifier map is constructed early enough. We are now able to unique a simple class as demonstrated by the added testing case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190334 91177308-0d34-0410-b5e6-96231b3b80d8 Manman Ren 6 years ago
9 changed file(s) with 170 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
236236 /// Verify - Verify that a type descriptor is well formed.
237237 bool Verify() const;
238238
239 DIScope getContext() const { return getFieldAs>(2); }
239 DIScopeRef getContext() const { return getFieldAs>(2); }
240240 StringRef getName() const { return getStringField(3); }
241241 unsigned getLineNumber() const { return getUnsignedField(4); }
242242 uint64_t getSizeInBits() const { return getUInt64Field(5); }
819819 SmallVector TYs; // Types
820820 SmallVector Scopes; // Scopes
821821 SmallPtrSet NodesSeen;
822 DITypeIdentifierMap TypeIdentifierMap;
822823 };
823824 } // end namespace llvm
824825
799799 addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags));
800800 }
801801
802 addToContextOwner(TyDIE, Ty.getContext());
802 addToContextOwner(TyDIE, DD->resolve(Ty.getContext()));
803803 return TyDIE;
804804 }
805805
831831 /// addGlobalType - Add a new global type to the compile unit.
832832 ///
833833 void CompileUnit::addGlobalType(DIType Ty) {
834 DIDescriptor Context = Ty.getContext();
834 DIDescriptor Context = DD->resolve(Ty.getContext());
835835 if (Ty.isCompositeType() && !Ty.getName().empty() && !Ty.isForwardDecl()
836836 && (!Context || Context.isCompileUnit() || Context.isFile()
837837 || Context.isNameSpace()))
913913 /// Return true if the type is appropriately scoped to be contained inside
914914 /// its own type unit.
915915 static bool isTypeUnitScoped(DIType Ty, const DwarfDebug *DD) {
916 DIScope Parent = Ty.getContext();
916 DIScope Parent = DD->resolve(Ty.getContext());
917917 while (Parent) {
918918 // Don't generate a hash for anything scoped inside a function.
919919 if (Parent.isSubprogram())
10871087 addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
10881088 getOrCreateTypeDIE(DIType(ContainingType)));
10891089 else
1090 addToContextOwner(&Buffer, CTy.getContext());
1090 addToContextOwner(&Buffer, DD->resolve(CTy.getContext()));
10911091
10921092 if (CTy.isObjcClassComplete())
10931093 addFlag(&Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
13721372 // We need the declaration DIE that is in the static member's class.
13731373 // But that class might not exist in the DWARF yet.
13741374 // Creating the class will create the static member decl DIE.
1375 getOrCreateContextDIE(SDMDecl.getContext());
1375 getOrCreateContextDIE(DD->resolve(SDMDecl.getContext()));
13761376 VariableDIE = getDIE(SDMDecl);
13771377 assert(VariableDIE && "Static member decl has no context?");
13781378 IsStaticMember = true;
340340 if (D.isSubprogram())
341341 return true;
342342 if (D.isType())
343 return isSubprogramContext(DIType(Context).getContext());
343 return isSubprogramContext(resolve(DIType(Context).getContext()));
344344 return false;
345345 }
346346
26552655 DIScope DwarfDebug::getScopeContext(DIScope S) const {
26562656
26572657 if (S.isType())
2658 return DIType(S).getContext();
2658 return resolve(DIType(S).getContext());
26592659
26602660 if (S.isSubprogram())
26612661 return DISubprogram(S).getContext();
416416 Value *Elts[] = {
417417 GetTagConstant(VMContext, dwarf::DW_TAG_member),
418418 File.getFileNode(),
419 getNonCompileUnitScope(Scope),
419 DIScope(getNonCompileUnitScope(Scope)).generateRef(),
420420 MDString::get(VMContext, Name),
421421 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
422422 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
445445 (isa(Val) && DIScope(cast(Val)).isScope());
446446 }
447447
448 /// Check if a field at position Elt of a MDNode can be a ScopeRef.
449 static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
450 Value *Fld = getField(DbgNode, Elt);
451 return isScopeRef(Fld);
452 }
453
448454 /// Verify - Verify that a type descriptor is well formed.
449455 bool DIType::Verify() const {
450456 if (!isType())
451457 return false;
452458 // Make sure Context @ field 2 is MDNode.
453 if (!fieldIsMDNode(DbgNode, 2))
459 if (!fieldIsScopeRef(DbgNode, 2))
454460 return false;
455461
456462 // FIXME: Sink this into the various subclass verifies.
955961 TYs.clear();
956962 Scopes.clear();
957963 NodesSeen.clear();
964 TypeIdentifierMap.clear();
958965 }
959966
960967 /// processModule - Process entire module and collect debug info.
961968 void DebugInfoFinder::processModule(const Module &M) {
962969 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
970 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
963971 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
964972 DICompileUnit CU(CU_Nodes->getOperand(i));
965973 addCompileUnit(CU);
10091017 void DebugInfoFinder::processType(DIType DT) {
10101018 if (!addType(DT))
10111019 return;
1012 processScope(DT.getContext());
1020 processScope(DT.getContext().resolve(TypeIdentifierMap));
10131021 if (DT.isCompositeType()) {
10141022 DICompositeType DCT(DT);
10151023 processType(DCT.getTypeDerivedFrom());
169169 Finder.reset();
170170
171171 DL = getAnalysisIfAvailable();
172 if (!DisableDebugInfoVerifier)
173 Finder.processModule(M);
172174
173175 // We must abort before returning back to the pass manager, or else the
174176 // pass manager may try to run other passes on the broken module.
23042306 void Verifier::verifyDebugInfo(Module &M) {
23052307 // Verify Debug Info.
23062308 if (!DisableDebugInfoVerifier) {
2307 Finder.processModule(M);
2308
23092309 for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
23102310 E = Finder.compile_unit_end(); I != E; ++I)
23112311 Assert1(DICompileUnit(*I).Verify(), "DICompileUnit does not Verify!", *I);
0 ; RUN: llvm-link %s %p/type-unique-simple-b.ll -S -o - | FileCheck %s
1
2 ; CHECK: DW_TAG_structure_type
3 ; CHECK-NOT: DW_TAG_structure_type
4 ; Content of header files:
5 ; struct Base {
6 ; int a;
7 ; //Base *b;
8 ; };
9 ; Content of foo.cpp:
10 ;
11 ; #include "a.hpp"
12 ; void f(int a) {
13 ; Base t;
14 ; }
15 ; Content of bar.cpp:
16 ;
17 ; #include "a.hpp"
18 ; void f(int);
19 ; void g(int a) {
20 ; Base t;
21 ; }
22 ; int main() {
23 ; f(0);
24 ; g(1);
25 ; return 0;
26 ; }
27 ; ModuleID = 'foo.cpp'
28 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
29 target triple = "x86_64-apple-macosx10.8.0"
30
31 %struct.Base = type { i32 }
32
33 ; Function Attrs: nounwind ssp uwtable
34 define void @_Z1fi(i32 %a) #0 {
35 entry:
36 %a.addr = alloca i32, align 4
37 %t = alloca %struct.Base, align 4
38 store i32 %a, i32* %a.addr, align 4
39 call void @llvm.dbg.declare(metadata !{i32* %a.addr}, metadata !15), !dbg !16
40 call void @llvm.dbg.declare(metadata !{%struct.Base* %t}, metadata !17), !dbg !18
41 ret void, !dbg !19
42 }
43
44 ; Function Attrs: nounwind readnone
45 declare void @llvm.dbg.declare(metadata, metadata) #1
46
47 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
48 attributes #1 = { nounwind readnone }
49
50 !llvm.dbg.cu = !{!0}
51 !llvm.module.flags = !{!14}
52
53 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 (http://llvm.org/git/clang.git c23b1db6268c8e7ce64026d57d1510c1aac200a0) (http://llvm.org/git/llvm.git 09b98fe3978eddefc2145adc1056cf21580ce945)", i1 false, metadata !"", i32 0, metadata !2, metadata !3, metadata !9, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/Users/mren/c_testing/type_unique_air/simple/foo.cpp] [DW_LANG_C_plus_plus]
54 !1 = metadata !{metadata !"foo.cpp", metadata !"/Users/mren/c_testing/type_unique_air/simple"}
55 !2 = metadata !{i32 0}
56 !3 = metadata !{metadata !4}
57 !4 = metadata !{i32 786451, metadata !5, null, metadata !"Base", i32 1, i64 32, i64 32, i32 0, i32 0, null, metadata !6, i32 0, null, null, metadata !"_ZTS4Base"} ; [ DW_TAG_structure_type ] [Base] [line 1, size 32, align 32, offset 0] [def] [from ]
58 !5 = metadata !{metadata !"./a.hpp", metadata !"/Users/mren/c_testing/type_unique_air/simple"}
59 !6 = metadata !{metadata !7}
60 !7 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"a", i32 2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line 2, size 32, align 32, offset 0] [from int]
61 !8 = 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]
62 !9 = metadata !{metadata !10}
63 !10 = metadata !{i32 786478, metadata !1, metadata !11, metadata !"f", metadata !"f", metadata !"_Z1fi", i32 3, metadata !12, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32)* @_Z1fi, null, null, metadata !2, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [f]
64 !11 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/Users/mren/c_testing/type_unique_air/simple/foo.cpp]
65 !12 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !13, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
66 !13 = metadata !{null, metadata !8}
67 !14 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
68 !15 = metadata !{i32 786689, metadata !10, metadata !"a", metadata !11, i32 16777219, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [a] [line 3]
69 !16 = metadata !{i32 3, i32 0, metadata !10, null}
70 !17 = metadata !{i32 786688, metadata !10, metadata !"t", metadata !11, i32 4, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [t] [line 4]
71 !18 = metadata !{i32 4, i32 0, metadata !10, null}
72 !19 = metadata !{i32 5, i32 0, metadata !10, null}
0 ; RUN: true
1
2 ; ModuleID = 'bar.cpp'
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.8.0"
5
6 %struct.Base = type { i32 }
7
8 ; Function Attrs: nounwind ssp uwtable
9 define void @_Z1gi(i32 %a) #0 {
10 entry:
11 %a.addr = alloca i32, align 4
12 %t = alloca %struct.Base, align 4
13 store i32 %a, i32* %a.addr, align 4
14 call void @llvm.dbg.declare(metadata !{i32* %a.addr}, metadata !18), !dbg !19
15 call void @llvm.dbg.declare(metadata !{%struct.Base* %t}, metadata !20), !dbg !21
16 ret void, !dbg !22
17 }
18
19 ; Function Attrs: nounwind readnone
20 declare void @llvm.dbg.declare(metadata, metadata) #1
21
22 ; Function Attrs: ssp uwtable
23 define i32 @main() #2 {
24 entry:
25 %retval = alloca i32, align 4
26 store i32 0, i32* %retval
27 call void @_Z1fi(i32 0), !dbg !23
28 call void @_Z1gi(i32 1), !dbg !24
29 ret i32 0, !dbg !25
30 }
31
32 declare void @_Z1fi(i32) #3
33
34 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
35 attributes #1 = { nounwind readnone }
36 attributes #2 = { ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
37 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
38
39 !llvm.dbg.cu = !{!0}
40 !llvm.module.flags = !{!17}
41
42 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 (http://llvm.org/git/clang.git c23b1db6268c8e7ce64026d57d1510c1aac200a0) (http://llvm.org/git/llvm.git 09b98fe3978eddefc2145adc1056cf21580ce945)", i1 false, metadata !"", i32 0, metadata !2, metadata !3, metadata !9, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/Users/mren/c_testing/type_unique_air/simple/bar.cpp] [DW_LANG_C_plus_plus]
43 !1 = metadata !{metadata !"bar.cpp", metadata !"/Users/mren/c_testing/type_unique_air/simple"}
44 !2 = metadata !{i32 0}
45 !3 = metadata !{metadata !4}
46 !4 = metadata !{i32 786451, metadata !5, null, metadata !"Base", i32 1, i64 32, i64 32, i32 0, i32 0, null, metadata !6, i32 0, null, null, metadata !"_ZTS4Base"} ; [ DW_TAG_structure_type ] [Base] [line 1, size 32, align 32, offset 0] [def] [from ]
47 !5 = metadata !{metadata !"./a.hpp", metadata !"/Users/mren/c_testing/type_unique_air/simple"}
48 !6 = metadata !{metadata !7}
49 !7 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"a", i32 2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line 2, size 32, align 32, offset 0] [from int]
50 !8 = 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]
51 !9 = metadata !{metadata !10, metadata !14}
52 !10 = metadata !{i32 786478, metadata !1, metadata !11, metadata !"g", metadata !"g", metadata !"_Z1gi", i32 4, metadata !12, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32)* @_Z1gi, null, null, metadata !2, i32 4} ; [ DW_TAG_subprogram ] [line 4] [def] [g]
53 !11 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/Users/mren/c_testing/type_unique_air/simple/bar.cpp]
54 !12 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !13, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
55 !13 = metadata !{null, metadata !8}
56 !14 = metadata !{i32 786478, metadata !1, metadata !11, metadata !"main", metadata !"main", metadata !"", i32 7, metadata !15, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2, i32 7} ; [ DW_TAG_subprogram ] [line 7] [def] [main]
57 !15 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !16, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
58 !16 = metadata !{metadata !8}
59 !17 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
60 !18 = metadata !{i32 786689, metadata !10, metadata !"a", metadata !11, i32 16777220, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [a] [line 4]
61 !19 = metadata !{i32 4, i32 0, metadata !10, null}
62 !20 = metadata !{i32 786688, metadata !10, metadata !"t", metadata !11, i32 5, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [t] [line 5]
63 !21 = metadata !{i32 5, i32 0, metadata !10, null}
64 !22 = metadata !{i32 6, i32 0, metadata !10, null}
65 !23 = metadata !{i32 8, i32 0, metadata !14, null} ; [ DW_TAG_imported_declaration ]
66 !24 = metadata !{i32 9, i32 0, metadata !14, null}
67 !25 = metadata !{i32 10, i32 0, metadata !14, null}
366366 struct BreakpointPrinter : public ModulePass {
367367 raw_ostream &Out;
368368 static char ID;
369 DITypeIdentifierMap TypeIdentifierMap;
369370
370371 BreakpointPrinter(raw_ostream &out)
371372 : ModulePass(ID), Out(out) {
381382 } else if (Context.isType()) {
382383 DIType TY(Context);
383384 if (!TY.getName().empty()) {
384 getContextName(TY.getContext(), N);
385 getContextName(TY.getContext().resolve(TypeIdentifierMap), N);
385386 N = N + TY.getName().str() + "::";
386387 }
387388 }
388389 }
389390
390391 virtual bool runOnModule(Module &M) {
392 TypeIdentifierMap.clear();
393 NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
394 if (CU_Nodes)
395 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
396
391397 StringSet<> Processed;
392398 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
393399 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {