LLVM  8.0.1
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 
25 namespace llvm {
26 
27 class DbgDeclareInst;
28 class DbgValueInst;
29 class Module;
30 
31 /// Find subprogram that is enclosing this scope.
32 DISubprogram *getDISubprogram(const MDNode *Scope);
33 
34 /// Strip debug info in the module if it exists.
35 ///
36 /// To do this, we remove all calls to the debugger intrinsics and any named
37 /// metadata for debugging. We also remove debug locations for instructions.
38 /// Return true if module is modified.
39 bool StripDebugInfo(Module &M);
40 bool stripDebugInfo(Function &F);
41 
42 /// Downgrade the debug info in a module to contain only line table information.
43 ///
44 /// In order to convert debug info to what -gline-tables-only would have
45 /// created, this does the following:
46 /// 1) Delete all debug intrinsics.
47 /// 2) Delete all non-CU named metadata debug info nodes.
48 /// 3) Create new DebugLocs for each instruction.
49 /// 4) Create a new CU debug info, and similarly for every metadata node
50 /// that's reachable from the CU debug info.
51 /// All debug type metadata nodes are unreachable and garbage collected.
52 bool stripNonLineTableDebugInfo(Module &M);
53 
54 /// Return Debug Info Metadata Version by checking module flags.
55 unsigned getDebugMetadataVersionFromModule(const Module &M);
56 
57 /// Utility to find all debug info in a module.
58 ///
59 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
60 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
61 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
62 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
63 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
64 /// used by the CUs.
66 public:
67  /// Process entire module and collect debug info anchors.
68  void processModule(const Module &M);
69  /// Process a single instruction and collect debug info anchors.
70  void processInstruction(const Module &M, const Instruction &I);
71 
72  /// Process DbgDeclareInst.
73  void processDeclare(const Module &M, const DbgDeclareInst *DDI);
74  /// Process DbgValueInst.
75  void processValue(const Module &M, const DbgValueInst *DVI);
76  /// Process debug info location.
77  void processLocation(const Module &M, const DILocation *Loc);
78 
79  /// Clear all lists.
80  void reset();
81 
82 private:
83  void InitializeTypeMap(const Module &M);
84 
85  void processCompileUnit(DICompileUnit *CU);
86  void processScope(DIScope *Scope);
87  void processSubprogram(DISubprogram *SP);
88  void processType(DIType *DT);
89  bool addCompileUnit(DICompileUnit *CU);
90  bool addGlobalVariable(DIGlobalVariableExpression *DIG);
91  bool addScope(DIScope *Scope);
92  bool addSubprogram(DISubprogram *SP);
93  bool addType(DIType *DT);
94 
95 public:
96  using compile_unit_iterator =
103 
105  return make_range(CUs.begin(), CUs.end());
106  }
107 
109  return make_range(SPs.begin(), SPs.end());
110  }
111 
113  return make_range(GVs.begin(), GVs.end());
114  }
115 
117  return make_range(TYs.begin(), TYs.end());
118  }
119 
121  return make_range(Scopes.begin(), Scopes.end());
122  }
123 
124  unsigned compile_unit_count() const { return CUs.size(); }
125  unsigned global_variable_count() const { return GVs.size(); }
126  unsigned subprogram_count() const { return SPs.size(); }
127  unsigned type_count() const { return TYs.size(); }
128  unsigned scope_count() const { return Scopes.size(); }
129 
130 private:
137 };
138 
139 } // end namespace llvm
140 
141 #endif // LLVM_IR_DEBUGINFO_H
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:118
unsigned global_variable_count() const
Definition: DebugInfo.h:125
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:328
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
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:682
void reset()
Clear all lists.
Definition: DebugInfo.cpp:54
unsigned subprogram_count() const
Definition: DebugInfo.h:126
F(f)
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:314
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:63
iterator_range< scope_iterator > scopes() const
Definition: DebugInfo.h:120
Utility to find all debug info in a module.
Definition: DebugInfo.h:65
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:589
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:44
SmallVectorImpl< DISubprogram * >::const_iterator subprogram_iterator
Definition: DebugInfo.h:98
Subprogram description.
SmallVectorImpl< DIScope * >::const_iterator scope_iterator
Definition: DebugInfo.h:102
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:351
iterator_range< type_iterator > types() const
Definition: DebugInfo.h:116
Debug location.
unsigned compile_unit_count() const
Definition: DebugInfo.h:124
SmallVectorImpl< DICompileUnit * >::const_iterator compile_unit_iterator
Definition: DebugInfo.h:97
A pair of DIGlobalVariable and DIExpression.
SmallVectorImpl< DIType * >::const_iterator type_iterator
Definition: DebugInfo.h:101
void processValue(const Module &M, const DbgValueInst *DVI)
Process DbgValueInst.
Definition: DebugInfo.cpp:214
iterator_range< compile_unit_iterator > compile_units() const
Definition: DebugInfo.h:104
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:107
iterator_range< global_variable_expression_iterator > global_variables() const
Definition: DebugInfo.h:112
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:418
Base class for types.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
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:198
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned scope_count() const
Definition: DebugInfo.h:128
unsigned type_count() const
Definition: DebugInfo.h:127
iterator_range< subprogram_iterator > subprograms() const
Definition: DebugInfo.h:108
This represents the llvm.dbg.declare instruction.
SmallVectorImpl< DIGlobalVariableExpression * >::const_iterator global_variable_expression_iterator
Definition: DebugInfo.h:100