LLVM  3.7.0
DebugInfo.h
Go to the documentation of this file.
1 //===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
13 // DWARF information.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_IR_DEBUGINFO_H
18 #define LLVM_IR_DEBUGINFO_H
19 
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Casting.h"
27 #include "llvm/Support/Dwarf.h"
29 #include <iterator>
30 
31 namespace llvm {
32 class Module;
33 class DbgDeclareInst;
35 
36 /// \brief Maps from type identifier to the actual MDNode.
38 
39 /// \brief Find subprogram that is enclosing this scope.
40 DISubprogram *getDISubprogram(const MDNode *Scope);
41 
42 /// \brief Find debug info for a given function.
43 ///
44 /// \returns a valid subprogram, if found. Otherwise, return \c nullptr.
46 
47 /// \brief Find underlying composite type.
49 
50 /// \brief Generate map by visiting all retained types.
52 
53 /// \brief Strip debug info in the module if it exists.
54 ///
55 /// To do this, we remove all calls to the debugger intrinsics and any named
56 /// metadata for debugging. We also remove debug locations for instructions.
57 /// Return true if module is modified.
58 bool StripDebugInfo(Module &M);
60 
61 /// \brief Return Debug Info Metadata Version by checking module flags.
62 unsigned getDebugMetadataVersionFromModule(const Module &M);
63 
64 /// \brief Utility to find all debug info in a module.
65 ///
66 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
67 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
68 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
69 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
70 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
71 /// used by the CUs.
73 public:
74  DebugInfoFinder() : TypeMapInitialized(false) {}
75 
76  /// \brief Process entire module and collect debug info anchors.
77  void processModule(const Module &M);
78 
79  /// \brief Process DbgDeclareInst.
80  void processDeclare(const Module &M, const DbgDeclareInst *DDI);
81  /// \brief Process DbgValueInst.
82  void processValue(const Module &M, const DbgValueInst *DVI);
83  /// \brief Process debug info location.
84  void processLocation(const Module &M, const DILocation *Loc);
85 
86  /// \brief Clear all lists.
87  void reset();
88 
89 private:
90  void InitializeTypeMap(const Module &M);
91 
92  void processType(DIType *DT);
93  void processSubprogram(DISubprogram *SP);
94  void processScope(DIScope *Scope);
95  bool addCompileUnit(DICompileUnit *CU);
96  bool addGlobalVariable(DIGlobalVariable *DIG);
97  bool addSubprogram(DISubprogram *SP);
98  bool addType(DIType *DT);
99  bool addScope(DIScope *Scope);
100 
101 public:
109 
111  return iterator_range<compile_unit_iterator>(CUs.begin(), CUs.end());
112  }
113 
115  return iterator_range<subprogram_iterator>(SPs.begin(), SPs.end());
116  }
117 
119  return iterator_range<global_variable_iterator>(GVs.begin(), GVs.end());
120  }
121 
123  return iterator_range<type_iterator>(TYs.begin(), TYs.end());
124  }
125 
127  return iterator_range<scope_iterator>(Scopes.begin(), Scopes.end());
128  }
129 
130  unsigned compile_unit_count() const { return CUs.size(); }
131  unsigned global_variable_count() const { return GVs.size(); }
132  unsigned subprogram_count() const { return SPs.size(); }
133  unsigned type_count() const { return TYs.size(); }
134  unsigned scope_count() const { return Scopes.size(); }
135 
136 private:
143  DITypeIdentifierMap TypeIdentifierMap;
144 
145  /// \brief Specify if TypeIdentifierMap is initialized.
146  bool TypeMapInitialized;
147 };
148 
149 DenseMap<const Function *, DISubprogram *> makeSubprogramMap(const Module &M);
150 
151 } // end namespace llvm
152 
153 #endif
iterator_range< scope_iterator > scopes() const
Definition: DebugInfo.h:126
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:155
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
unsigned global_variable_count() const
Definition: DebugInfo.h:131
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:369
void reset()
Clear all lists.
Definition: DebugInfo.cpp:103
Metadata node.
Definition: Metadata.h:740
F(f)
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:314
unsigned scope_count() const
Definition: DebugInfo.h:134
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:122
A tuple of MDNodes.
Definition: Metadata.h:1127
Utility to find all debug info in a module.
Definition: DebugInfo.h:72
DICompositeTypeBase * getDICompositeType(DIType *T)
Find underlying composite type.
Definition: DebugInfo.cpp:59
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:36
SmallVectorImpl< DIType * >::const_iterator type_iterator
Definition: DebugInfo.h:107
#define false
Definition: ConvertUTF.c:65
DenseMap< const MDString *, DIType * > DITypeIdentifierMap
Maps from type identifier to the actual MDNode.
Definition: DebugInfo.h:34
Subprogram description.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:327
unsigned subprogram_count() const
Definition: DebugInfo.h:132
iterator_range< compile_unit_iterator > compile_units() const
Definition: DebugInfo.h:110
Debug location.
SmallVectorImpl< DISubprogram * >::const_iterator subprogram_iterator
Definition: DebugInfo.h:104
iterator_range< subprogram_iterator > subprograms() const
Definition: DebugInfo.h:114
void processValue(const Module &M, const DbgValueInst *DVI)
Process DbgValueInst.
Definition: DebugInfo.cpp:242
SmallVectorImpl< DIScope * >::const_iterator scope_iterator
Definition: DebugInfo.h:108
SmallVectorImpl< DICompileUnit * >::const_iterator compile_unit_iterator
Definition: DebugInfo.h:103
unsigned compile_unit_count() const
Definition: DebugInfo.h:130
Base class for scope-like contexts.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:299
Base class for types.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
A range adaptor for a pair of iterators.
Base class for DICompositeType and DISubroutineType.
DbgValueInst - This represents the llvm.dbg.value instruction.
void processDeclare(const Module &M, const DbgDeclareInst *DDI)
Process DbgDeclareInst.
Definition: DebugInfo.cpp:225
SmallVectorImpl< DIGlobalVariable * >::const_iterator global_variable_iterator
Definition: DebugInfo.h:106
unsigned type_count() const
Definition: DebugInfo.h:133
DenseMap< const Function *, DISubprogram * > makeSubprogramMap(const Module &M)
Definition: DebugInfo.cpp:377
iterator_range< type_iterator > types() const
Definition: DebugInfo.h:122
DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes)
Generate map by visiting all retained types.
Definition: DebugInfo.cpp:75
DbgDeclareInst - This represents the llvm.dbg.declare instruction.
Definition: IntrinsicInst.h:82
iterator_range< global_variable_iterator > global_variables() const
Definition: DebugInfo.h:118