#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/LEB128.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Timer.h"
return Entry.second;
}
-unsigned DwarfFile::getAddrPoolIndex(const MCSymbol *Sym) {
- return getAddrPoolIndex(MCSymbolRefExpr::Create(Sym, Asm->OutContext));
-}
-
-unsigned DwarfFile::getAddrPoolIndex(const MCExpr *Sym) {
- std::pair<DenseMap<const MCExpr *, unsigned>::iterator, bool> P =
- AddressPool.insert(std::make_pair(Sym, NextAddrPoolNumber));
+unsigned DwarfFile::getAddrPoolIndex(const MCSymbol *Sym, bool TLS) {
+ std::pair<AddrPool::iterator, bool> P = AddressPool.insert(
+ std::make_pair(Sym, AddressPoolEntry(NextAddrPoolNumber, TLS)));
if (P.second)
++NextAddrPoolNumber;
- return P.first->second;
+ return P.first->second.Number;
}
// Define a unique number for the abbreviation.
DIArray Args = SPTy.getTypeArray();
uint16_t SPTag = SPTy.getTag();
if (SPTag == dwarf::DW_TAG_subroutine_type)
- for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
- DIE *Arg =
- SPCU->createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
- DIType ATy(Args.getElement(i));
- SPCU->addType(Arg, ATy);
- if (ATy.isArtificial())
- SPCU->addFlag(Arg, dwarf::DW_AT_artificial);
- if (ATy.isObjectPointer())
- SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, Arg);
- }
+ SPCU->constructSubprogramArguments(*SPDie, Args);
DIE *SPDeclDie = SPDie;
SPDie = SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
*SPCU->getUnitDie());
RI != RE; ++RI) {
RangeSpan Span(getLabelBeforeInsn(RI->first),
getLabelAfterInsn(RI->second));
- List.addRange(llvm_move(Span));
+ List.addRange(std::move(Span));
}
// Add the range list to the set of ranges to be emitted.
- TheCU->addRangeList(llvm_move(List));
+ TheCU->addRangeList(std::move(List));
}
// Construct new DW_TAG_lexical_block for this scope and attach
DIE *ObjectPointer = NULL;
// Collect arguments for current function.
- if (LScopes.isCurrentFunctionScope(Scope))
+ if (LScopes.isCurrentFunctionScope(Scope)) {
for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
if (DbgVariable *ArgDV = CurrentFnArguments[i])
if (DIE *Arg =
ObjectPointer = Arg;
}
+ // If this is a variadic function, add an unspecified parameter.
+ DISubprogram SP(Scope->getScopeNode());
+ DIArray FnArgs = SP.getType().getTypeArray();
+ if (FnArgs.getElement(FnArgs.getNumElements() - 1)
+ .isUnspecifiedParameter()) {
+ DIE *Ellipsis = new DIE(dwarf::DW_TAG_unspecified_parameters);
+ Children.push_back(Ellipsis);
+ }
+ }
+
// Collect lexical scope children first.
const SmallVectorImpl<DbgVariable *> &Variables =
ScopeVariables.lookup(Scope);
DIUnit.getLanguage());
NewCU->addString(Die, dwarf::DW_AT_name, FN);
-
if (!useSplitDwarf()) {
NewCU->initStmtList(DwarfLineSectionSym);
// This should be a unique identifier when we want to build .dwp files.
uint64_t ID = 0;
if (GenerateCUHash) {
- DIEHash CUHash;
+ DIEHash CUHash(Asm);
ID = CUHash.computeCUSignature(*TheU->getUnitDie());
}
TheU->addUInt(TheU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
// Add the range of this function to the list of ranges for the CU.
RangeSpan Span(FunctionBeginSym, FunctionEndSym);
- TheCU->addRange(llvm_move(Span));
+ TheCU->addRange(std::move(Span));
// Clear debug info
for (ScopeVariablesMap::iterator I = ScopeVariables.begin(),
Die->setOffset(Offset);
// Start the size with the size of abbreviation code.
- Offset += MCAsmInfo::getULEB128Size(Die->getAbbrevNumber());
+ Offset += getULEB128Size(Die->getAbbrevNumber());
const SmallVectorImpl<DIEValue *> &Values = Die->getValues();
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
if (useSplitDwarf())
DwarfAbbrevDWOSectionSym = emitSectionSym(
Asm, TLOF.getDwarfAbbrevDWOSection(), "section_abbrev_dwo");
- emitSectionSym(Asm, TLOF.getDwarfARangesSection());
-
- if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection())
- emitSectionSym(Asm, MacroInfo);
+ if (GenerateARangeSection)
+ emitSectionSym(Asm, TLOF.getDwarfARangesSection());
DwarfLineSectionSym =
emitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
// Order the address pool entries by ID
SmallVector<const MCExpr *, 64> Entries(AddressPool.size());
- for (DenseMap<const MCExpr *, unsigned>::iterator I = AddressPool.begin(),
- E = AddressPool.end();
+ for (AddrPool::iterator I = AddressPool.begin(), E = AddressPool.end();
I != E; ++I)
- Entries[I->second] = I->first;
+ Entries[I->second.Number] =
+ I->second.TLS
+ ? Asm->getObjFileLowering().getDebugThreadLocalSymbol(I->first)
+ : MCSymbolRefExpr::Create(I->first, Asm->OutContext);
- for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
- // Emit an expression for reference from debug information entries.
- if (const MCExpr *Expr = Entries[i])
- Asm->OutStreamer.EmitValue(Expr, Asm->getDataLayout().getPointerSize());
- else
- Asm->OutStreamer.EmitIntValue(0, Asm->getDataLayout().getPointerSize());
- }
+ for (unsigned i = 0, e = Entries.size(); i != e; ++i)
+ Asm->OutStreamer.EmitValue(Entries[i],
+ Asm->getDataLayout().getPointerSize());
}
// Emit visible names into a debug str section.
}
// Now emit a range for the CU itself.
- if (useCURanges()) {
+ if (useCURanges() && TheCU->getRanges().size()) {
Asm->OutStreamer.EmitLabel(
Asm->GetTempSymbol("cu_ranges", TheCU->getUniqueID()));
const SmallVectorImpl<RangeSpan> &Ranges = TheCU->getRanges();
// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_dwo_name,
// DW_AT_addr_base.
DwarfTypeUnit *DwarfDebug::constructSkeletonTU(DwarfTypeUnit *TU) {
+ DwarfCompileUnit &CU = static_cast<DwarfCompileUnit &>(
+ *SkeletonHolder.getUnits()[TU->getCU().getUniqueID()]);
DIE *Die = new DIE(dwarf::DW_TAG_type_unit);
- DwarfTypeUnit *NewTU = new DwarfTypeUnit(TU->getUniqueID(), Die, TU->getCU(),
- Asm, this, &SkeletonHolder);
+ DwarfTypeUnit *NewTU =
+ new DwarfTypeUnit(TU->getUniqueID(), Die, CU, Asm, this, &SkeletonHolder);
NewTU->setTypeSignature(TU->getTypeSignature());
NewTU->setType(NULL);
NewTU->initSection(
Asm->getObjFileLowering().getDwarfTypesSection(TU->getTypeSignature()));
+ CU.applyStmtList(*Die);
initSkeletonUnit(TU, Die, NewTU);
return NewTU;
NewTU->setTypeSignature(Signature);
if (useSplitDwarf())
NewTU->setSkeleton(constructSkeletonTU(NewTU));
+ else
+ CU.applyStmtList(*UnitDie);
NewTU->setType(NewTU->createTypeDIE(CTy));