index 81dbfc505ac9257b15e497e47babf783de6048d0..0b72e969d4bf62a05c3e237347584dfab189d8df 100644 (file)
#include "DwarfAccelTable.h"
#include "DwarfDebug.h"
#include "llvm/ADT/APFloat.h"
-#include "llvm/DIBuilder.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
Die->addValue((dwarf::Attribute)0, Form, Value);
}
+/// addLocationList - Add a Dwarf loclistptr attribute data and value.
+///
+void DwarfUnit::addLocationList(DIE *Die, dwarf::Attribute Attribute,
+ unsigned Index) {
+ DIEValue *Value = new (DIEValueAllocator) DIELocList(Index);
+ dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
+ : dwarf::DW_FORM_data4;
+ Die->addValue(Attribute, Form, Value);
+}
+
/// addLabel - Add a Dwarf label attribute data and value.
///
void DwarfUnit::addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
Die->addValue(Attribute, dwarf::DW_FORM_data4, Value);
}
+void DwarfUnit::addLabelDelta(DIE *Die, dwarf::Attribute Attribute,
+ const MCSymbol *Hi, const MCSymbol *Lo) {
+ DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
+ Die->addValue(Attribute, dwarf::DW_FORM_data4, Value);
+}
+
/// addDIEEntry - Add a DIE attribute data and value.
///
void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry) {
/// addBlock - Add block data.
///
void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Loc) {
- Loc->setSize(Loc->ComputeSize(Asm));
+ Loc->ComputeSize(Asm);
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
Die->addValue(Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
}
void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute,
DIEBlock *Block) {
- Block->setSize(Block->ComputeSize(Asm));
+ Block->ComputeSize(Asm);
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
Die->addValue(Attribute, Block->BestForm(), Block);
}
}
if (DWReg < 0) {
- DEBUG(llvm::dbgs() << "Invalid Dwarf register number.\n");
+ DEBUG(dbgs() << "Invalid Dwarf register number.\n");
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_nop);
return;
}
DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom());
- // If this type is not derived from any type then take conservative approach.
- if (!BaseType.isValid())
+ // If this type is not derived from any type or the type is a declaration then
+ // take conservative approach.
+ if (!BaseType.isValid() || BaseType.isForwardDecl())
return Ty.getSizeInBits();
// If this is a derived type, go ahead and get the base type, unless it's a
DIE *ContextDIE = getOrCreateContextDIE(Context);
assert(ContextDIE);
+ // Unique the type. This is a noop if the type has no unique identifier.
+ Ty = DIType(resolve(Ty.getRef()));
+
DIE *TyDIE = getDIE(Ty);
if (TyDIE)
return TyDIE;
// Create new type.
TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
+ updateAcceleratorTables(Context, Ty, TyDIE);
+
if (Ty.isBasicType())
constructTypeDIE(*TyDIE, DIBasicType(Ty));
else if (Ty.isCompositeType()) {
if (GenerateDwarfTypeUnits && !Ty.isForwardDecl())
if (MDString *TypeId = CTy.getIdentifier()) {
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
- // Skip updating the accellerator tables since this is not the full type
+ // Skip updating the accelerator tables since this is not the full type.
return TyDIE;
}
constructTypeDIE(*TyDIE, CTy);
constructTypeDIE(*TyDIE, DIDerivedType(Ty));
}
- updateAcceleratorTables(Context, Ty, TyDIE);
-
return TyDIE;
}
unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags));
- if (!Context || Context.isCompileUnit() || Context.isFile() ||
- Context.isNameSpace())
+ if ((!Context || Context.isCompileUnit() || Context.isFile() ||
+ Context.isNameSpace()) &&
+ getCUNode().getEmissionKind() != DIBuilder::LineTablesOnly)
GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = TyDIE;
}
}
/// addGlobalName - Add a new global name to the compile unit.
void DwarfUnit::addGlobalName(StringRef Name, DIE *Die, DIScope Context) {
+ if (getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly)
+ return;
std::string FullName = getParentContextString(Context) + Name.str();
GlobalNames[FullName] = Die;
}
addSourceLine(&Buffer, DTy);
}
+/// constructSubprogramArguments - Construct function argument DIEs.
+void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DIArray Args) {
+ for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
+ DIDescriptor Ty = Args.getElement(i);
+ if (Ty.isUnspecifiedParameter()) {
+ assert(i == N-1 && "Unspecified parameter must be the last argument");
+ createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
+ } else {
+ DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
+ addType(Arg, DIType(Ty));
+ if (DIType(Ty).isArtificial())
+ addFlag(Arg, dwarf::DW_AT_artificial);
+ }
+ }
+}
+
/// constructTypeDIE - Construct type DIE from DICompositeType.
void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
// Add name if not anonymous or intermediate type.
addType(&Buffer, RTy);
bool isPrototyped = true;
- // Add arguments.
- for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
- DIDescriptor Ty = Elements.getElement(i);
- if (Ty.isUnspecifiedParameter()) {
- createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
- isPrototyped = false;
- } else {
- DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
- addType(Arg, DIType(Ty));
- if (DIType(Ty).isArtificial())
- addFlag(Arg, dwarf::DW_AT_artificial);
- }
- }
+ if (Elements.getNumElements() == 2 &&
+ Elements.getElement(1).isUnspecifiedParameter())
+ isPrototyped = false;
+
+ constructSubprogramArguments(Buffer, Elements);
+
// Add prototype flag if we're dealing with a C language and the
// function has been prototyped.
uint16_t Language = getLanguage();
return NDie;
}
+/// Unique C++ member function declarations based on their
+/// context and mangled name.
+DISubprogram
+DwarfUnit::getOdrUniqueSubprogram(DIScope Context, DISubprogram SP) const {
+ if (!hasODR() ||
+ !Context.isCompositeType() ||
+ SP.getLinkageName().empty() ||
+ SP.isDefinition())
+ return SP;
+ // Create a key with the UID of the parent class and this SP's name.
+ Twine Key = SP.getContext().getName() + SP.getLinkageName();
+ const MDNode *&Entry = DD->getOrCreateOdrMember(Key.str());
+ if (!Entry)
+ Entry = &*SP;
+
+ return DISubprogram(Entry);
+}
+
/// getOrCreateSubprogramDIE - Create new DIE using SP.
DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) {
// Construct the context before querying for the existence of the DIE in case
// such construction creates the DIE (as is the case for member function
// declarations).
- DIE *ContextDIE = getOrCreateContextDIE(resolve(SP.getContext()));
+ DIScope Context = resolve(SP.getContext());
+ DIE *ContextDIE = getOrCreateContextDIE(Context);
+ // Unique declarations based on the ODR, where applicable.
+ SP = getOdrUniqueSubprogram(Context, SP);
DIE *SPDie = getDIE(SP);
if (SPDie)
// Add arguments. Do not add arguments for subprogram definition. They will
// be handled while processing variables.
- for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
- DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
- DIType ATy(Args.getElement(i));
- addType(Arg, ATy);
- if (ATy.isArtificial())
- addFlag(Arg, dwarf::DW_AT_artificial);
- }
+ constructSubprogramArguments(*SPDie, Args);
}
if (SP.isArtificial())
// TAG_variable.
addString(IsStaticMember && VariableSpecDIE ? VariableSpecDIE
: VariableDIE,
- dwarf::DW_AT_MIPS_linkage_name,
+ DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
+ : dwarf::DW_AT_MIPS_linkage_name,
GlobalValue::getRealLinkageName(LinkageName));
} else if (const ConstantInt *CI =
dyn_cast_or_null<ConstantInt>(GV.getConstant())) {
unsigned Offset = DV.getDotDebugLocOffset();
if (Offset != ~0U) {
- addSectionLabel(VariableDie, dwarf::DW_AT_location,
- Asm->GetTempSymbol("debug_loc", Offset));
+ addLocationList(VariableDie, dwarf::DW_AT_location, Offset);
DV.setDIE(VariableDie);
return VariableDie;
}
uint64_t OffsetInBytes;
if (Size != FieldSize) {
- // Handle bitfield.
- addUInt(MemberDie, dwarf::DW_AT_byte_size, None,
- getBaseTypeSize(DD, DT) >> 3);
- addUInt(MemberDie, dwarf::DW_AT_bit_size, None, DT.getSizeInBits());
+ // Handle bitfield, assume bytes are 8 bits.
+ addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
+ addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
uint64_t Offset = DT.getOffsetInBits();
uint64_t AlignMask = ~(DT.getAlignInBits() - 1);