2014-03-06 01:46:21 +01:00
|
|
|
//===- DebugInfo.h - Debug Information Helpers ------------------*- C++ -*-===//
|
2008-11-10 03:56:27 +01: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 20:26:15 +02: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 03:56:27 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-06 01:46:21 +01:00
|
|
|
#ifndef LLVM_IR_DEBUGINFO_H
|
|
|
|
#define LLVM_IR_DEBUGINFO_H
|
2008-11-10 03:56:27 +01:00
|
|
|
|
2009-07-28 21:55:13 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2015-02-02 19:53:21 +01:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2014-01-07 12:48:04 +01:00
|
|
|
#include "llvm/Support/Casting.h"
|
2009-12-31 04:02:42 +01:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2014-10-03 22:01:09 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <iterator>
|
2008-11-10 03:56:27 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2013-10-05 01:15:52 +02:00
|
|
|
class Module;
|
|
|
|
class DbgDeclareInst;
|
|
|
|
class DbgValueInst;
|
2016-04-16 09:51:28 +02:00
|
|
|
template <typename K, typename V, typename KeyInfoT, typename BucketT>
|
|
|
|
class DenseMap;
|
2013-10-05 01:15:52 +02:00
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Find subprogram that is enclosing this scope.
|
2015-04-29 18:38:44 +02:00
|
|
|
DISubprogram *getDISubprogram(const MDNode *Scope);
|
2013-10-05 01:15:52 +02:00
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Strip debug info in the module if it exists.
|
2014-10-15 18:15:15 +02:00
|
|
|
///
|
2013-11-22 23:06:31 +01: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 23:36:43 +02:00
|
|
|
bool stripDebugInfo(Function &F);
|
2013-11-22 23:06:31 +01:00
|
|
|
|
2016-10-25 20:44:13 +02:00
|
|
|
/// Downgrade the debug info in a module to contain only line table information.
|
|
|
|
///
|
|
|
|
/// In order to convert debug info to what -gline-tables-only would have
|
|
|
|
/// created, this does the following:
|
|
|
|
/// 1) Delete all debug intrinsics.
|
|
|
|
/// 2) Delete all non-CU named metadata debug info nodes.
|
|
|
|
/// 3) Create new DebugLocs for each instruction.
|
|
|
|
/// 4) Create a new CU debug info, and similarly for every metadata node
|
|
|
|
/// that's reachable from the CU debug info.
|
|
|
|
/// All debug type metadata nodes are unreachable and garbage collected.
|
|
|
|
bool stripNonLineTableDebugInfo(Module &M);
|
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Return Debug Info Metadata Version by checking module flags.
|
2013-12-03 01:12:14 +01:00
|
|
|
unsigned getDebugMetadataVersionFromModule(const Module &M);
|
2013-12-02 22:29:56 +01:00
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Utility to find all debug info in a module.
|
|
|
|
///
|
2013-10-05 01:15:52 +02: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:
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Process entire module and collect debug info anchors.
|
2013-10-05 01:15:52 +02:00
|
|
|
void processModule(const Module &M);
|
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Process DbgDeclareInst.
|
2013-11-17 19:42:37 +01:00
|
|
|
void processDeclare(const Module &M, const DbgDeclareInst *DDI);
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Process DbgValueInst.
|
2013-11-17 19:42:37 +01:00
|
|
|
void processValue(const Module &M, const DbgValueInst *DVI);
|
2015-04-21 20:44:06 +02:00
|
|
|
/// \brief Process debug info location.
|
2015-04-29 18:38:44 +02:00
|
|
|
void processLocation(const Module &M, const DILocation *Loc);
|
2013-10-05 01:15:52 +02:00
|
|
|
|
2014-10-15 19:01:28 +02:00
|
|
|
/// \brief Clear all lists.
|
2013-10-05 01:15:52 +02:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
2013-11-17 20:35:03 +01:00
|
|
|
void InitializeTypeMap(const Module &M);
|
2013-11-17 19:42:37 +01:00
|
|
|
|
2015-04-29 18:38:44 +02:00
|
|
|
void processType(DIType *DT);
|
|
|
|
void processSubprogram(DISubprogram *SP);
|
|
|
|
void processScope(DIScope *Scope);
|
|
|
|
bool addCompileUnit(DICompileUnit *CU);
|
2016-12-20 03:09:43 +01:00
|
|
|
bool addGlobalVariable(DIGlobalVariableExpression *DIG);
|
2015-04-29 18:38:44 +02:00
|
|
|
bool addSubprogram(DISubprogram *SP);
|
|
|
|
bool addType(DIType *DT);
|
|
|
|
bool addScope(DIScope *Scope);
|
2013-10-05 01:15:52 +02:00
|
|
|
|
|
|
|
public:
|
2015-04-29 18:38:44 +02:00
|
|
|
typedef SmallVectorImpl<DICompileUnit *>::const_iterator
|
2015-04-18 01:20:10 +02:00
|
|
|
compile_unit_iterator;
|
2015-04-29 18:38:44 +02:00
|
|
|
typedef SmallVectorImpl<DISubprogram *>::const_iterator subprogram_iterator;
|
2016-12-20 03:09:43 +01:00
|
|
|
typedef SmallVectorImpl<DIGlobalVariableExpression *>::const_iterator
|
|
|
|
global_variable_expression_iterator;
|
2015-04-29 18:38:44 +02:00
|
|
|
typedef SmallVectorImpl<DIType *>::const_iterator type_iterator;
|
|
|
|
typedef SmallVectorImpl<DIScope *>::const_iterator scope_iterator;
|
2014-03-18 10:41:07 +01:00
|
|
|
|
|
|
|
iterator_range<compile_unit_iterator> compile_units() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(CUs.begin(), CUs.end());
|
2014-03-18 10:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<subprogram_iterator> subprograms() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(SPs.begin(), SPs.end());
|
2014-03-18 10:41:07 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 03:09:43 +01:00
|
|
|
iterator_range<global_variable_expression_iterator> global_variables() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(GVs.begin(), GVs.end());
|
2014-03-18 10:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<type_iterator> types() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(TYs.begin(), TYs.end());
|
2014-03-18 10:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<scope_iterator> scopes() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(Scopes.begin(), Scopes.end());
|
2014-03-18 10:41:07 +01:00
|
|
|
}
|
2013-10-05 01:15:52 +02: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 18:38:44 +02:00
|
|
|
SmallVector<DICompileUnit *, 8> CUs;
|
|
|
|
SmallVector<DISubprogram *, 8> SPs;
|
2016-12-20 03:09:43 +01:00
|
|
|
SmallVector<DIGlobalVariableExpression *, 8> GVs;
|
2015-04-29 18:38:44 +02:00
|
|
|
SmallVector<DIType *, 8> TYs;
|
|
|
|
SmallVector<DIScope *, 8> Scopes;
|
2016-01-30 02:24:31 +01:00
|
|
|
SmallPtrSet<const MDNode *, 32> NodesSeen;
|
2013-10-05 01:15:52 +02:00
|
|
|
};
|
2014-07-01 22:05:26 +02:00
|
|
|
|
2008-11-10 03:56:27 +01:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|