LLVM  10.0.0svn
DebugInfo.h
Go to the documentation of this file.
1 //===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a bunch of datatypes that are useful for creating and
10 // walking debug info in LLVM IR form. They essentially provide wrappers around
11 // the information in the global variables that's needed when constructing the
12 // DWARF information.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_DEBUGINFO_H
17 #define LLVM_IR_DEBUGINFO_H
18 
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h"
23 
24 namespace llvm {
25 
26 class DbgDeclareInst;
27 class DbgValueInst;
28 class Module;
29 
30 /// Find subprogram that is enclosing this scope.
31 DISubprogram *getDISubprogram(const MDNode *Scope);
32 
33 /// Strip debug info in the module if it exists.
34 ///
35 /// To do this, we remove all calls to the debugger intrinsics and any named
36 /// metadata for debugging. We also remove debug locations for instructions.
37 /// Return true if module is modified.
38 bool StripDebugInfo(Module &M);
39 bool stripDebugInfo(Function &F);
40 
41 /// Downgrade the debug info in a module to contain only line table information.
42 ///
43 /// In order to convert debug info to what -gline-tables-only would have
44 /// created, this does the following:
45 /// 1) Delete all debug intrinsics.
46 /// 2) Delete all non-CU named metadata debug info nodes.
47 /// 3) Create new DebugLocs for each instruction.
48 /// 4) Create a new CU debug info, and similarly for every metadata node
49 /// that's reachable from the CU debug info.
50 /// All debug type metadata nodes are unreachable and garbage collected.
51 bool stripNonLineTableDebugInfo(Module &M);
52 
53 /// Return Debug Info Metadata Version by checking module flags.
54 unsigned getDebugMetadataVersionFromModule(const Module &M);
55 
56 /// Utility to find all debug info in a module.
57 ///
58 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
59 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
60 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
61 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
62 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
63 /// used by the CUs.
65 public:
66  /// Process entire module and collect debug info anchors.
67  void processModule(const Module &M);
68  /// Process a single instruction and collect debug info anchors.
69  void processInstruction(const Module &M, const Instruction &I);
70 
71  /// Process DbgDeclareInst.
72  void processDeclare(const Module &M, const DbgDeclareInst *DDI);
73  /// Process DbgValueInst.
74  void processValue(const Module &M, const DbgValueInst *DVI);
75  /// Process debug info location.
76  void processLocation(const Module &M, const DILocation *Loc);
77 
78  /// Clear all lists.
79  void reset();
80 
81 private:
82  void InitializeTypeMap(const Module &M);
83 
84  void processCompileUnit(DICompileUnit *CU);
85  void processScope(DIScope *Scope);
86  void processSubprogram(DISubprogram *SP);
87  void processType(DIType *DT);
88  bool addCompileUnit(DICompileUnit *CU);
89  bool addGlobalVariable(DIGlobalVariableExpression *DIG);
90  bool addScope(DIScope *Scope);
91  bool addSubprogram(DISubprogram *SP);
92  bool addType(DIType *DT);
93 
94 public:
95  using compile_unit_iterator =
102 
104  return make_range(CUs.begin(), CUs.end());
105  }
106 
108  return make_range(SPs.begin(), SPs.end());
109  }
110 
112  return make_range(GVs.begin(), GVs.end());
113  }
114 
116  return make_range(TYs.begin(), TYs.end());
117  }
118 
120  return make_range(Scopes.begin(), Scopes.end());
121  }
122 
123  unsigned compile_unit_count() const { return CUs.size(); }
124  unsigned global_variable_count() const { return GVs.size(); }
125  unsigned subprogram_count() const { return SPs.size(); }
126  unsigned type_count() const { return TYs.size(); }
127  unsigned scope_count() const { return Scopes.size(); }
128 
129 private:
136 };
137 
138 } // end namespace llvm
139 
140 #endif // LLVM_IR_DEBUGINFO_H
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:117
unsigned global_variable_count() const
Definition: DebugInfo.h:124
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:320
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:53
unsigned subprogram_count() const
Definition: DebugInfo.h:125
F(f)
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:313
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:62
iterator_range< scope_iterator > scopes() const
Definition: DebugInfo.h:119
Utility to find all debug info in a module.
Definition: DebugInfo.h:64
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:43
SmallVectorImpl< DISubprogram * >::const_iterator subprogram_iterator
Definition: DebugInfo.h:97
Subprogram description.
SmallVectorImpl< DIScope * >::const_iterator scope_iterator
Definition: DebugInfo.h:101
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:350
iterator_range< type_iterator > types() const
Definition: DebugInfo.h:115
Debug location.
unsigned compile_unit_count() const
Definition: DebugInfo.h:123
SmallVectorImpl< DICompileUnit * >::const_iterator compile_unit_iterator
Definition: DebugInfo.h:96
A pair of DIGlobalVariable and DIExpression.
SmallVectorImpl< DIType * >::const_iterator type_iterator
Definition: DebugInfo.h:100
void processValue(const Module &M, const DbgValueInst *DVI)
Process DbgValueInst.
Definition: DebugInfo.cpp:213
iterator_range< compile_unit_iterator > compile_units() const
Definition: DebugInfo.h:103
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:106
iterator_range< global_variable_expression_iterator > global_variables() const
Definition: DebugInfo.h:111
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:417
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:837
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:197
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned scope_count() const
Definition: DebugInfo.h:127
unsigned type_count() const
Definition: DebugInfo.h:126
iterator_range< subprogram_iterator > subprograms() const
Definition: DebugInfo.h:107
This represents the llvm.dbg.declare instruction.
SmallVectorImpl< DIGlobalVariableExpression * >::const_iterator global_variable_expression_iterator
Definition: DebugInfo.h:99