aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/AsmPrinter/DwarfWriter.cpp')
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfWriter.cpp80
1 files changed, 46 insertions, 34 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index b2a52cabe0..95990cfe67 100644
--- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
@@ -1274,6 +1274,9 @@ private:
/// of each entry in this vector corresponds to the sources in MMI.
DenseMap<Value *, CompileUnit *> DW_CUs;
+ /// MainCU - Some platform prefers one compile unit per .o file. In such
+ /// cases, all dies are inserted in MainCU.
+ CompileUnit *MainCU;
/// AbbreviationsSet - Used to uniquely define abbreviations.
///
FoldingSet<DIEAbbrev> AbbreviationsSet;
@@ -1559,16 +1562,8 @@ private:
void AddSourceLine(DIE *Die, const DIVariable *V) {
unsigned FileID = 0;
unsigned Line = V->getLineNumber();
- if (V->getVersion() <= LLVMDebugVersion6) {
- // Version6 or earlier. Use compile unit info to get file id.
- CompileUnit *Unit = FindCompileUnit(V->getCompileUnit());
- FileID = Unit->getID();
- } else {
- // Version7 or newer, use filename and directory info from DIVariable
- // directly.
- unsigned DID = Directories.idFor(V->getDirectory());
- FileID = SrcFiles.idFor(SrcFileInfo(DID, V->getFilename()));
- }
+ CompileUnit *Unit = FindCompileUnit(V->getCompileUnit());
+ FileID = Unit->getID();
AddUInt(Die, DW_AT_decl_file, 0, FileID);
AddUInt(Die, DW_AT_decl_line, 0, Line);
}
@@ -1578,16 +1573,8 @@ private:
void AddSourceLine(DIE *Die, const DIGlobal *G) {
unsigned FileID = 0;
unsigned Line = G->getLineNumber();
- if (G->getVersion() <= LLVMDebugVersion6) {
- // Version6 or earlier. Use compile unit info to get file id.
- CompileUnit *Unit = FindCompileUnit(G->getCompileUnit());
- FileID = Unit->getID();
- } else {
- // Version7 or newer, use filename and directory info from DIGlobal
- // directly.
- unsigned DID = Directories.idFor(G->getDirectory());
- FileID = SrcFiles.idFor(SrcFileInfo(DID, G->getFilename()));
- }
+ CompileUnit *Unit = FindCompileUnit(G->getCompileUnit());
+ FileID = Unit->getID();
AddUInt(Die, DW_AT_decl_file, 0, FileID);
AddUInt(Die, DW_AT_decl_line, 0, Line);
}
@@ -1595,16 +1582,11 @@ private:
void AddSourceLine(DIE *Die, const DIType *Ty) {
unsigned FileID = 0;
unsigned Line = Ty->getLineNumber();
- if (Ty->getVersion() <= LLVMDebugVersion6) {
- // Version6 or earlier. Use compile unit info to get file id.
- CompileUnit *Unit = FindCompileUnit(Ty->getCompileUnit());
- FileID = Unit->getID();
- } else {
- // Version7 or newer, use filename and directory info from DIType
- // directly.
- unsigned DID = Directories.idFor(Ty->getDirectory());
- FileID = SrcFiles.idFor(SrcFileInfo(DID, Ty->getFilename()));
- }
+ DICompileUnit CU = Ty->getCompileUnit();
+ if (CU.isNull())
+ return;
+ CompileUnit *Unit = FindCompileUnit(CU);
+ FileID = Unit->getID();
AddUInt(Die, DW_AT_decl_file, 0, FileID);
AddUInt(Die, DW_AT_decl_line, 0, Line);
}
@@ -2091,7 +2073,9 @@ private:
DISubprogram SPD(Desc.getGV());
// Get the compile unit context.
- CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit());
+ CompileUnit *Unit = MainCU;
+ if (!Unit)
+ Unit = FindCompileUnit(SPD.getCompileUnit());
// Get the subprogram die.
DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
@@ -2122,7 +2106,9 @@ private:
if (SPD.getName() == MF->getFunction()->getName()) {
// Get the compile unit context.
- CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit());
+ CompileUnit *Unit = MainCU;
+ if (!Unit)
+ Unit = FindCompileUnit(SPD.getCompileUnit());
// Get the subprogram die.
DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
@@ -2294,6 +2280,15 @@ private:
///
void SizeAndOffsets() {
// Process base compile unit.
+ if (MainCU) {
+ // Compute size of compile unit header
+ unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
+ sizeof(int16_t) + // DWARF version number
+ sizeof(int32_t) + // Offset Into Abbrev. Section
+ sizeof(int8_t); // Pointer Size (in bytes)
+ SizeAndOffsetDie(MainCU->getDie(), Offset, true);
+ return;
+ }
for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
CE = DW_CUs.end(); CI != CE; ++CI) {
CompileUnit *Unit = CI->second;
@@ -2315,6 +2310,8 @@ private:
for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
CE = DW_CUs.end(); CI != CE; ++CI) {
CompileUnit *Unit = CI->second;
+ if (MainCU)
+ Unit = MainCU;
DIE *Die = Unit->getDie();
// Emit the compile units header.
EmitLabel("info_begin", Unit->getID());
@@ -2340,6 +2337,8 @@ private:
EmitLabel("info_end", Unit->getID());
Asm->EOL();
+ if (MainCU)
+ return;
}
}
@@ -2639,6 +2638,8 @@ private:
for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
CE = DW_CUs.end(); CI != CE; ++CI) {
CompileUnit *Unit = CI->second;
+ if (MainCU)
+ Unit = MainCU;
EmitDifference("pubnames_end", Unit->getID(),
"pubnames_begin", Unit->getID(), true);
@@ -2672,6 +2673,8 @@ private:
EmitLabel("pubnames_end", Unit->getID());
Asm->EOL();
+ if (MainCU)
+ return;
}
}
@@ -2789,6 +2792,10 @@ private:
AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags);
CompileUnit *Unit = new CompileUnit(ID, Die);
+ if (DIUnit.isMain()) {
+ assert (!MainCU && "Multiple main compile units are found!");
+ MainCU = Unit;
+ }
DW_CUs[DIUnit.getGV()] = Unit;
}
}
@@ -2802,7 +2809,9 @@ private:
for (std::vector<GlobalVariable *>::iterator GVI = Result.begin(),
GVE = Result.end(); GVI != GVE; ++GVI) {
DIGlobalVariable DI_GV(*GVI);
- CompileUnit *DW_Unit = FindCompileUnit(DI_GV.getCompileUnit());
+ CompileUnit *DW_Unit = MainCU;
+ if (!DW_Unit)
+ DW_Unit = FindCompileUnit(DI_GV.getCompileUnit());
// Check for pre-existence.
DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV.getGV());
@@ -2839,7 +2848,9 @@ private:
RE = Result.end(); RI != RE; ++RI) {
DISubprogram SP(*RI);
- CompileUnit *Unit = FindCompileUnit(SP.getCompileUnit());
+ CompileUnit *Unit = MainCU;
+ if (!Unit)
+ Unit = FindCompileUnit(SP.getCompileUnit());
// Check for pre-existence.
DIE *&Slot = Unit->getDieMapSlotFor(SP.getGV());
@@ -2862,6 +2873,7 @@ public:
//
DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
: Dwarf(OS, A, T, "dbg")
+ , MainCU(NULL)
, AbbreviationsSet(InitAbbreviationsSetSize)
, Abbreviations()
, ValuesSet(InitValuesSetSize)