LLVM  4.0.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/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/Dwarf.h"
27 #include <iterator>
28 
29 namespace llvm {
30 class Module;
31 class DbgDeclareInst;
32 class DbgValueInst;
33 template <typename K, typename V, typename KeyInfoT, typename BucketT>
34 class DenseMap;
35 
36 /// \brief Find subprogram that is enclosing this scope.
37 DISubprogram *getDISubprogram(const MDNode *Scope);
38 
39 /// \brief Strip debug info in the module if it exists.
40 ///
41 /// To do this, we remove all calls to the debugger intrinsics and any named
42 /// metadata for debugging. We also remove debug locations for instructions.
43 /// Return true if module is modified.
44 bool StripDebugInfo(Module &M);
45 bool stripDebugInfo(Function &F);
46 
47 /// Downgrade the debug info in a module to contain only line table information.
48 ///
49 /// In order to convert debug info to what -gline-tables-only would have
50 /// created, this does the following:
51 /// 1) Delete all debug intrinsics.
52 /// 2) Delete all non-CU named metadata debug info nodes.
53 /// 3) Create new DebugLocs for each instruction.
54 /// 4) Create a new CU debug info, and similarly for every metadata node
55 /// that's reachable from the CU debug info.
56 /// All debug type metadata nodes are unreachable and garbage collected.
57 bool stripNonLineTableDebugInfo(Module &M);
58 
59 /// \brief Return Debug Info Metadata Version by checking module flags.
60 unsigned getDebugMetadataVersionFromModule(const Module &M);
61 
62 /// \brief Utility to find all debug info in a module.
63 ///
64 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
65 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
66 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
67 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
68 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
69 /// used by the CUs.
71 public:
72  /// \brief Process entire module and collect debug info anchors.
73  void processModule(const Module &M);
74 
75  /// \brief Process DbgDeclareInst.
76  void processDeclare(const Module &M, const DbgDeclareInst *DDI);
77  /// \brief Process DbgValueInst.
78  void processValue(const Module &M, const DbgValueInst *DVI);
79  /// \brief Process debug info location.
80  void processLocation(const Module &M, const DILocation *Loc);
81 
82  /// \brief Clear all lists.
83  void reset();
84 
85 private:
86  void InitializeTypeMap(const Module &M);
87 
88  void processType(DIType *DT);
89  void processSubprogram(DISubprogram *SP);
90  void processScope(DIScope *Scope);
91  bool addCompileUnit(DICompileUnit *CU);
92  bool addGlobalVariable(DIGlobalVariableExpression *DIG);
93  bool addSubprogram(DISubprogram *SP);
94  bool addType(DIType *DT);
95  bool addScope(DIScope *Scope);
96 
97 public:
105 
107  return make_range(CUs.begin(), CUs.end());
108  }
109 
111  return make_range(SPs.begin(), SPs.end());
112  }
113 
115  return make_range(GVs.begin(), GVs.end());
116  }
117 
119  return make_range(TYs.begin(), TYs.end());
120  }
121 
123  return make_range(Scopes.begin(), Scopes.end());
124  }
125 
126  unsigned compile_unit_count() const { return CUs.size(); }
127  unsigned global_variable_count() const { return GVs.size(); }
128  unsigned subprogram_count() const { return SPs.size(); }
129  unsigned type_count() const { return TYs.size(); }
130  unsigned scope_count() const { return Scopes.size(); }
131 
132 private:
139 };
140 
141 } // end namespace llvm
142 
143 #endif
iterator_range< scope_iterator > scopes() const
Definition: DebugInfo.h:122
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:87
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
unsigned global_variable_count() const
Definition: DebugInfo.h:127
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:594
void reset()
Clear all lists.
Definition: DebugInfo.cpp:44
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:242
unsigned scope_count() const
Definition: DebugInfo.h:130
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:53
Utility to find all debug info in a module.
Definition: DebugInfo.h:70
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:510
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:34
SmallVectorImpl< DIType * >::const_iterator type_iterator
Definition: DebugInfo.h:103
Subprogram description.
#define F(x, y, z)
Definition: MD5.cpp:51
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:266
iterator_range< global_variable_expression_iterator > global_variables() const
Definition: DebugInfo.h:114
unsigned subprogram_count() const
Definition: DebugInfo.h:128
iterator_range< compile_unit_iterator > compile_units() const
Definition: DebugInfo.h:106
Debug location.
SmallVectorImpl< DISubprogram * >::const_iterator subprogram_iterator
Definition: DebugInfo.h:100
iterator_range< subprogram_iterator > subprograms() const
Definition: DebugInfo.h:110
A pair of DIGlobalVariable and DIExpression.
void processValue(const Module &M, const DbgValueInst *DVI)
Process DbgValueInst.
Definition: DebugInfo.cpp:174
SmallVectorImpl< DIScope * >::const_iterator scope_iterator
Definition: DebugInfo.h:104
SmallVectorImpl< DICompileUnit * >::const_iterator compile_unit_iterator
Definition: DebugInfo.h:99
unsigned compile_unit_count() const
Definition: DebugInfo.h:126
Base class for scope-like contexts.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:425
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:843
A range adaptor for a pair of iterators.
This represents the llvm.dbg.value instruction.
void processDeclare(const Module &M, const DbgDeclareInst *DDI)
Process DbgDeclareInst.
Definition: DebugInfo.cpp:158
SmallVectorImpl< DIGlobalVariableExpression * >::const_iterator global_variable_expression_iterator
Definition: DebugInfo.h:102
unsigned type_count() const
Definition: DebugInfo.h:129
iterator_range< type_iterator > types() const
Definition: DebugInfo.h:118
This represents the llvm.dbg.declare instruction.
Definition: IntrinsicInst.h:89