2014-03-06 00:46:21 +00:00
|
|
|
//===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
|
2008-11-10 02:56:27 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a bunch of datatypes that are useful for creating and
|
2009-05-14 18:26:15 +00:00
|
|
|
// walking debug info in LLVM IR form. They essentially provide wrappers around
|
|
|
|
// the information in the global variables that's needed when constructing the
|
|
|
|
// DWARF information.
|
2008-11-10 02:56:27 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-06 00:46:21 +00:00
|
|
|
#ifndef LLVM_IR_DEBUGINFO_H
|
|
|
|
#define LLVM_IR_DEBUGINFO_H
|
2008-11-10 02:56:27 +00:00
|
|
|
|
2013-09-05 18:48:31 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-07-28 19:55:13 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-12-31 03:02:08 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-01-14 11:23:27 +00:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2015-02-02 18:53:21 +00:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Support/Casting.h"
|
2009-12-31 03:02:42 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2014-10-03 20:01:09 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <iterator>
|
2008-11-10 02:56:27 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2013-10-04 23:15:52 +00:00
|
|
|
class Module;
|
|
|
|
class DbgDeclareInst;
|
|
|
|
class DbgValueInst;
|
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Maps from type identifier to the actual MDNode.
|
2015-04-29 16:38:44 +00:00
|
|
|
typedef DenseMap<const MDString *, DIType *> DITypeIdentifierMap;
|
2013-10-04 23:15:52 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Find subprogram that is enclosing this scope.
|
2015-04-29 16:38:44 +00:00
|
|
|
DISubprogram *getDISubprogram(const MDNode *Scope);
|
2013-10-04 23:15:52 +00:00
|
|
|
|
2014-10-23 23:46:28 +00:00
|
|
|
/// \brief Find debug info for a given function.
|
2015-04-20 22:10:08 +00:00
|
|
|
///
|
|
|
|
/// \returns a valid subprogram, if found. Otherwise, return \c nullptr.
|
2015-04-29 16:38:44 +00:00
|
|
|
DISubprogram *getDISubprogram(const Function *F);
|
2014-10-23 23:46:28 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Find underlying composite type.
|
2015-04-29 16:38:44 +00:00
|
|
|
DICompositeTypeBase *getDICompositeType(DIType *T);
|
2013-10-04 23:15:52 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Generate map by visiting all retained types.
|
2013-10-04 23:15:52 +00:00
|
|
|
DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
|
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Strip debug info in the module if it exists.
|
2014-10-15 16:15:15 +00:00
|
|
|
///
|
2013-11-22 22:06:31 +00:00
|
|
|
/// To do this, we remove all calls to the debugger intrinsics and any named
|
|
|
|
/// metadata for debugging. We also remove debug locations for instructions.
|
|
|
|
/// Return true if module is modified.
|
|
|
|
bool StripDebugInfo(Module &M);
|
2015-03-30 21:36:43 +00:00
|
|
|
bool stripDebugInfo(Function &F);
|
2013-11-22 22:06:31 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Return Debug Info Metadata Version by checking module flags.
|
2013-12-03 00:12:14 +00:00
|
|
|
unsigned getDebugMetadataVersionFromModule(const Module &M);
|
2013-12-02 21:29:56 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Utility to find all debug info in a module.
|
|
|
|
///
|
2013-10-04 23:15:52 +00:00
|
|
|
/// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
|
|
|
|
/// list debug info MDNodes used by an instruction, DebugInfoFinder uses
|
|
|
|
/// processDeclare, processValue and processLocation to handle DbgDeclareInst,
|
|
|
|
/// DbgValueInst and DbgLoc attached to instructions. processModule will go
|
|
|
|
/// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
|
|
|
|
/// used by the CUs.
|
|
|
|
class DebugInfoFinder {
|
|
|
|
public:
|
2013-11-18 11:06:01 +00:00
|
|
|
DebugInfoFinder() : TypeMapInitialized(false) {}
|
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Process entire module and collect debug info anchors.
|
2013-10-04 23:15:52 +00:00
|
|
|
void processModule(const Module &M);
|
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Process DbgDeclareInst.
|
2013-11-17 18:42:37 +00:00
|
|
|
void processDeclare(const Module &M, const DbgDeclareInst *DDI);
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Process DbgValueInst.
|
2013-11-17 18:42:37 +00:00
|
|
|
void processValue(const Module &M, const DbgValueInst *DVI);
|
2015-04-21 18:44:06 +00:00
|
|
|
/// \brief Process debug info location.
|
2015-04-29 16:38:44 +00:00
|
|
|
void processLocation(const Module &M, const DILocation *Loc);
|
2013-10-04 23:15:52 +00:00
|
|
|
|
2014-10-15 17:01:28 +00:00
|
|
|
/// \brief Clear all lists.
|
2013-10-04 23:15:52 +00:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
2013-11-17 19:35:03 +00:00
|
|
|
void InitializeTypeMap(const Module &M);
|
2013-11-17 18:42:37 +00:00
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
void processType(DIType *DT);
|
|
|
|
void processSubprogram(DISubprogram *SP);
|
|
|
|
void processScope(DIScope *Scope);
|
|
|
|
bool addCompileUnit(DICompileUnit *CU);
|
|
|
|
bool addGlobalVariable(DIGlobalVariable *DIG);
|
|
|
|
bool addSubprogram(DISubprogram *SP);
|
|
|
|
bool addType(DIType *DT);
|
|
|
|
bool addScope(DIScope *Scope);
|
2013-10-04 23:15:52 +00:00
|
|
|
|
|
|
|
public:
|
2015-04-29 16:38:44 +00:00
|
|
|
typedef SmallVectorImpl<DICompileUnit *>::const_iterator
|
2015-04-17 23:20:10 +00:00
|
|
|
compile_unit_iterator;
|
2015-04-29 16:38:44 +00:00
|
|
|
typedef SmallVectorImpl<DISubprogram *>::const_iterator subprogram_iterator;
|
|
|
|
typedef SmallVectorImpl<DIGlobalVariable *>::const_iterator
|
2015-01-22 16:55:27 +00:00
|
|
|
global_variable_iterator;
|
2015-04-29 16:38:44 +00:00
|
|
|
typedef SmallVectorImpl<DIType *>::const_iterator type_iterator;
|
|
|
|
typedef SmallVectorImpl<DIScope *>::const_iterator scope_iterator;
|
2014-03-18 09:41:07 +00:00
|
|
|
|
|
|
|
iterator_range<compile_unit_iterator> compile_units() const {
|
|
|
|
return iterator_range<compile_unit_iterator>(CUs.begin(), CUs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<subprogram_iterator> subprograms() const {
|
|
|
|
return iterator_range<subprogram_iterator>(SPs.begin(), SPs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<global_variable_iterator> global_variables() const {
|
|
|
|
return iterator_range<global_variable_iterator>(GVs.begin(), GVs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<type_iterator> types() const {
|
|
|
|
return iterator_range<type_iterator>(TYs.begin(), TYs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<scope_iterator> scopes() const {
|
|
|
|
return iterator_range<scope_iterator>(Scopes.begin(), Scopes.end());
|
|
|
|
}
|
2013-10-04 23:15:52 +00:00
|
|
|
|
|
|
|
unsigned compile_unit_count() const { return CUs.size(); }
|
|
|
|
unsigned global_variable_count() const { return GVs.size(); }
|
|
|
|
unsigned subprogram_count() const { return SPs.size(); }
|
|
|
|
unsigned type_count() const { return TYs.size(); }
|
|
|
|
unsigned scope_count() const { return Scopes.size(); }
|
|
|
|
|
|
|
|
private:
|
2015-04-29 16:38:44 +00:00
|
|
|
SmallVector<DICompileUnit *, 8> CUs;
|
|
|
|
SmallVector<DISubprogram *, 8> SPs;
|
|
|
|
SmallVector<DIGlobalVariable *, 8> GVs;
|
|
|
|
SmallVector<DIType *, 8> TYs;
|
|
|
|
SmallVector<DIScope *, 8> Scopes;
|
2015-04-17 23:20:10 +00:00
|
|
|
SmallPtrSet<const MDNode *, 64> NodesSeen;
|
2013-10-04 23:15:52 +00:00
|
|
|
DITypeIdentifierMap TypeIdentifierMap;
|
2014-10-15 17:01:28 +00:00
|
|
|
|
|
|
|
/// \brief Specify if TypeIdentifierMap is initialized.
|
2013-11-17 18:42:37 +00:00
|
|
|
bool TypeMapInitialized;
|
2013-10-04 23:15:52 +00:00
|
|
|
};
|
2014-07-01 20:05:26 +00:00
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
DenseMap<const Function *, DISubprogram *> makeSubprogramMap(const Module &M);
|
2014-07-01 20:05:26 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|