DebugInfo: Partial implementation of DWARF type units.

Emit DW_TAG_type_units into the debug_info section using compile unit
headers. This is bogus/unusable by debuggers, but testable and provides
more isolated review.

Subsequent patches will include support for type unit headers and
emission into the debug_types section, as well as comdat grouping the
types based on their hash. Also the CompileUnit type will be renamed
'Unit' and relevant portions pulled out into respective CompileUnit and
TypeUnit types.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195166 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2013-11-19 23:08:21 +00:00
parent d4010998b0
commit 6fe6dc19f8
8 changed files with 151 additions and 54 deletions

View File

@@ -29,18 +29,30 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
static cl::opt<bool> GenerateTypeUnits("generate-type-units", cl::Hidden,
cl::desc("Generate DWARF4 type units."),
cl::init(false));
/// CompileUnit - Compile unit constructor.
CompileUnit::CompileUnit(unsigned UID, DIE *D, DICompileUnit Node,
AsmPrinter *A, DwarfDebug *DW, DwarfUnits *DWU)
: UniqueID(UID), Node(Node), CUDie(D), Asm(A), DD(DW), DU(DWU),
IndexTyDie(0), DebugInfoOffset(0) {
IndexTyDie(0), Language(Node.getLanguage()) {
DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
insertDIE(Node, D);
}
CompileUnit::CompileUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
DwarfDebug *DD, DwarfUnits *DU)
: UniqueID(UID), Node(NULL), CUDie(D), Asm(A), DD(DD), DU(DU),
IndexTyDie(0), Language(Language) {
DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
}
/// ~CompileUnit - Destructor for compile unit.
CompileUnit::~CompileUnit() {
for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
@@ -102,7 +114,9 @@ int64_t CompileUnit::getDefaultLowerBound() const {
static bool isShareableAcrossCUs(DIDescriptor D) {
// When the MDNode can be part of the type system, the DIE can be
// shared across CUs.
return D.isType() || (D.isSubprogram() && !DISubprogram(D).isDefinition());
return (D.isType() ||
(D.isSubprogram() && !DISubprogram(D).isDefinition())) &&
!GenerateTypeUnits;
}
/// getDIE - Returns the debug information entry map slot for the
@@ -281,8 +295,8 @@ void CompileUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute,
void CompileUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute,
DIEEntry *Entry) {
const DIE *DieCU = Die->getCompileUnitOrNull();
const DIE *EntryCU = Entry->getEntry()->getCompileUnitOrNull();
const DIE *DieCU = Die->getUnitOrNull();
const DIE *EntryCU = Entry->getEntry()->getUnitOrNull();
if (!DieCU)
// We assume that Die belongs to this CU, if it is not linked to any CU yet.
DieCU = getCUDie();
@@ -871,6 +885,22 @@ DIE *CompileUnit::getOrCreateContextDIE(DIScope Context) {
return getDIE(Context);
}
DIE *CompileUnit::createTypeDIE(DICompositeType Ty) {
DIE *ContextDIE = getOrCreateContextDIE(resolve(Ty.getContext()));
DIE *TyDIE = getDIE(Ty);
if (TyDIE)
return TyDIE;
// Create new type.
TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
constructTypeDIEImpl(*TyDIE, Ty);
updateAcceleratorTables(Ty, TyDIE);
return TyDIE;
}
/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
/// given DIType.
DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
@@ -1112,6 +1142,9 @@ static bool isTypeUnitScoped(DIType Ty, const DwarfDebug *DD) {
/// Return true if the type should be split out into a type unit.
static bool shouldCreateTypeUnit(DICompositeType CTy, const DwarfDebug *DD) {
if (!GenerateTypeUnits)
return false;
uint16_t Tag = CTy.getTag();
switch (Tag) {
@@ -1130,7 +1163,16 @@ static bool shouldCreateTypeUnit(DICompositeType CTy, const DwarfDebug *DD) {
/// constructTypeDIE - Construct type DIE from DICompositeType.
void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
// Get core information.
// If this is a type applicable to a type unit it then add it to the
// list of types we'll compute a hash for later.
if (shouldCreateTypeUnit(CTy, DD))
DD->addTypeUnitType(&Buffer, CTy);
else
constructTypeDIEImpl(Buffer, CTy);
}
void CompileUnit::constructTypeDIEImpl(DIE &Buffer, DICompositeType CTy) {
// Add name if not anonymous or intermediate type.
StringRef Name = CTy.getName();
uint64_t Size = CTy.getSizeInBits() >> 3;
@@ -1296,10 +1338,6 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
RLang);
}
// If this is a type applicable to a type unit it then add it to the
// list of types we'll compute a hash for later.
if (shouldCreateTypeUnit(CTy, DD))
DD->addTypeUnitType(&Buffer);
}
/// constructTemplateTypeParameterDIE - Construct new DIE for the given
@@ -1510,7 +1548,6 @@ static const ConstantExpr *getMergedGlobalExpr(const Value *V) {
/// createGlobalVariableDIE - create global variable DIE.
void CompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) {
// Check for pre-existence.
if (getDIE(GV))
return;