2009-05-15 09:23:25 +00:00
|
|
|
//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing dwarf debug info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-09 00:39:24 +00:00
|
|
|
|
2009-08-28 23:24:31 +00:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
2009-05-15 09:23:25 +00:00
|
|
|
#include "DwarfDebug.h"
|
2010-04-05 05:24:55 +00:00
|
|
|
#include "DIE.h"
|
2011-11-07 09:24:32 +00:00
|
|
|
#include "DwarfAccelTable.h"
|
2011-04-12 17:40:32 +00:00
|
|
|
#include "DwarfCompileUnit.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2012-06-29 08:32:07 +00:00
|
|
|
#include "llvm/DIBuilder.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/DebugInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2010-03-09 01:58:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-07-31 18:48:30 +00:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2009-08-19 05:49:37 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-03-09 01:58:53 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-04-27 19:46:33 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-10-13 06:47:08 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-22 22:09:00 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/ValueHandle.h"
|
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2009-05-15 09:23:25 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-07-21 21:21:52 +00:00
|
|
|
static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print",
|
2010-07-07 20:12:52 +00:00
|
|
|
cl::Hidden,
|
2010-04-27 19:46:33 +00:00
|
|
|
cl::desc("Disable debug info printing"));
|
|
|
|
|
2010-05-07 01:08:53 +00:00
|
|
|
static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden,
|
2011-04-15 05:18:47 +00:00
|
|
|
cl::desc("Make an absence of debug location information explicit."),
|
2010-05-07 01:08:53 +00:00
|
|
|
cl::init(false));
|
|
|
|
|
2013-02-12 18:00:14 +00:00
|
|
|
static cl::opt<bool> GenerateDwarfPubNamesSection("generate-dwarf-pubnames",
|
2013-04-03 05:26:07 +00:00
|
|
|
cl::Hidden, cl::init(false),
|
2013-02-12 18:00:14 +00:00
|
|
|
cl::desc("Generate DWARF pubnames section"));
|
|
|
|
|
2012-08-23 22:36:40 +00:00
|
|
|
namespace {
|
|
|
|
enum DefaultOnOff {
|
|
|
|
Default, Enable, Disable
|
|
|
|
};
|
|
|
|
}
|
2011-11-07 09:24:32 +00:00
|
|
|
|
2012-08-23 22:36:40 +00:00
|
|
|
static cl::opt<DefaultOnOff> DwarfAccelTables("dwarf-accel-tables", cl::Hidden,
|
|
|
|
cl::desc("Output prototype dwarf accelerator tables."),
|
|
|
|
cl::values(
|
|
|
|
clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled"),
|
|
|
|
clEnumValEnd),
|
|
|
|
cl::init(Default));
|
|
|
|
|
|
|
|
static cl::opt<DefaultOnOff> DarwinGDBCompat("darwin-gdb-compat", cl::Hidden,
|
2012-08-23 07:10:46 +00:00
|
|
|
cl::desc("Compatibility with Darwin gdb."),
|
2012-08-23 22:36:40 +00:00
|
|
|
cl::values(
|
|
|
|
clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled"),
|
|
|
|
clEnumValEnd),
|
|
|
|
cl::init(Default));
|
2012-08-23 07:10:46 +00:00
|
|
|
|
2012-12-10 19:51:21 +00:00
|
|
|
static cl::opt<DefaultOnOff> SplitDwarf("split-dwarf", cl::Hidden,
|
|
|
|
cl::desc("Output prototype dwarf split debug info."),
|
2012-11-12 22:22:20 +00:00
|
|
|
cl::values(
|
|
|
|
clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled"),
|
|
|
|
clEnumValEnd),
|
|
|
|
cl::init(Default));
|
|
|
|
|
2010-04-07 09:28:04 +00:00
|
|
|
namespace {
|
|
|
|
const char *DWARFGroupName = "DWARF Emission";
|
|
|
|
const char *DbgTimerName = "DWARF Debug Writer";
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2009-05-15 09:23:25 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Configuration values for initial hash set sizes (log2).
|
|
|
|
//
|
2009-05-15 09:23:25 +00:00
|
|
|
static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2011-07-29 03:49:23 +00:00
|
|
|
DIType DbgVariable::getType() const {
|
2011-04-12 22:53:02 +00:00
|
|
|
DIType Ty = Var.getType();
|
|
|
|
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
|
|
|
|
// addresses instead.
|
|
|
|
if (Var.isBlockByrefVariable()) {
|
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as
|
|
|
|
"SomeType VarName;", but the compiler creates a
|
|
|
|
__Block_byref_x_VarName struct, and gives the variable VarName
|
|
|
|
either the struct, or a pointer to the struct, as its type. This
|
|
|
|
is necessary for various behind-the-scenes things the compiler
|
|
|
|
needs to do with by-reference variables in blocks.
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
However, as far as the original *programmer* is concerned, the
|
|
|
|
variable should still have type 'SomeType', as originally declared.
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
The following function dives into the __Block_byref_x_VarName
|
|
|
|
struct to find the original type of the variable. This will be
|
|
|
|
passed back to the code generating the type for the Debug
|
|
|
|
Information Entry for the variable 'VarName'. 'VarName' will then
|
|
|
|
have the original type 'SomeType' in its debug information.
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
The original type 'SomeType' will be the type of the field named
|
|
|
|
'VarName' inside the __Block_byref_x_VarName struct.
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
NOTE: In order for this to not completely fail on the debugger
|
|
|
|
side, the Debug Information Entry for the variable VarName needs to
|
|
|
|
have a DW_AT_location that tells the debugger how to unwind through
|
|
|
|
the pointers and __Block_byref_x_VarName struct to find the actual
|
|
|
|
value of the variable. The function addBlockByrefType does this. */
|
|
|
|
DIType subType = Ty;
|
|
|
|
unsigned tag = Ty.getTag();
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
if (tag == dwarf::DW_TAG_pointer_type) {
|
|
|
|
DIDerivedType DTy = DIDerivedType(Ty);
|
|
|
|
subType = DTy.getTypeDerivedFrom();
|
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
DICompositeType blockStruct = DICompositeType(subType);
|
|
|
|
DIArray Elements = blockStruct.getTypeArray();
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-04-12 22:53:02 +00:00
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
DIDerivedType DT = DIDerivedType(Element);
|
|
|
|
if (getName() == DT.getName())
|
|
|
|
return (DT.getTypeDerivedFrom());
|
2010-08-09 21:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-12 22:53:02 +00:00
|
|
|
return Ty;
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-05 04:09:20 +00:00
|
|
|
} // end llvm namespace
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-05 05:11:15 +00:00
|
|
|
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
|
2012-12-10 19:51:13 +00:00
|
|
|
: Asm(A), MMI(Asm->MMI), FirstCU(0),
|
2010-07-21 21:21:52 +00:00
|
|
|
AbbreviationsSet(InitAbbreviationsSetSize),
|
2013-01-08 22:22:06 +00:00
|
|
|
SourceIdMap(DIEValueAllocator),
|
2012-12-10 23:34:43 +00:00
|
|
|
PrevLabel(NULL), GlobalCUIndexCount(0),
|
2013-01-08 22:22:06 +00:00
|
|
|
InfoHolder(A, &AbbreviationsSet, &Abbreviations, "info_string",
|
|
|
|
DIEValueAllocator),
|
2012-12-19 22:02:53 +00:00
|
|
|
SkeletonAbbrevSet(InitAbbreviationsSetSize),
|
2013-01-08 22:22:06 +00:00
|
|
|
SkeletonHolder(A, &SkeletonAbbrevSet, &SkeletonAbbrevs, "skel_string",
|
|
|
|
DIEValueAllocator) {
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-05-06 14:56:22 +00:00
|
|
|
DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
|
2010-04-04 23:10:38 +00:00
|
|
|
DwarfStrSectionSym = TextSectionSym = 0;
|
2013-02-07 21:19:50 +00:00
|
|
|
DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = DwarfLineSectionSym = 0;
|
2013-04-07 03:43:09 +00:00
|
|
|
DwarfAddrSectionSym = 0;
|
2012-12-27 02:14:01 +00:00
|
|
|
DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0;
|
2010-05-25 23:40:22 +00:00
|
|
|
FunctionBeginSym = FunctionEndSym = 0;
|
2012-04-02 17:58:52 +00:00
|
|
|
|
2012-08-23 07:10:46 +00:00
|
|
|
// Turn on accelerator tables and older gdb compatibility
|
|
|
|
// for Darwin.
|
2012-11-21 00:34:35 +00:00
|
|
|
bool IsDarwin = Triple(M->getTargetTriple()).isOSDarwin();
|
2012-08-23 22:36:40 +00:00
|
|
|
if (DarwinGDBCompat == Default) {
|
2012-11-21 00:34:35 +00:00
|
|
|
if (IsDarwin)
|
|
|
|
IsDarwinGDBCompat = true;
|
2012-08-23 22:36:40 +00:00
|
|
|
else
|
2012-11-21 00:34:35 +00:00
|
|
|
IsDarwinGDBCompat = false;
|
2012-08-23 22:36:40 +00:00
|
|
|
} else
|
2012-11-21 00:34:35 +00:00
|
|
|
IsDarwinGDBCompat = DarwinGDBCompat == Enable ? true : false;
|
2012-08-23 22:36:40 +00:00
|
|
|
|
|
|
|
if (DwarfAccelTables == Default) {
|
2012-11-21 00:34:35 +00:00
|
|
|
if (IsDarwin)
|
|
|
|
HasDwarfAccelTables = true;
|
2012-08-23 22:36:40 +00:00
|
|
|
else
|
2012-11-21 00:34:35 +00:00
|
|
|
HasDwarfAccelTables = false;
|
2012-08-23 22:36:40 +00:00
|
|
|
} else
|
2012-11-21 00:34:35 +00:00
|
|
|
HasDwarfAccelTables = DwarfAccelTables == Enable ? true : false;
|
2012-08-23 22:36:36 +00:00
|
|
|
|
2012-12-10 19:51:21 +00:00
|
|
|
if (SplitDwarf == Default)
|
|
|
|
HasSplitDwarf = false;
|
2012-11-12 22:22:20 +00:00
|
|
|
else
|
2012-12-10 19:51:21 +00:00
|
|
|
HasSplitDwarf = SplitDwarf == Enable ? true : false;
|
2012-11-12 22:22:20 +00:00
|
|
|
|
2010-06-18 15:56:31 +00:00
|
|
|
{
|
|
|
|
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
|
2012-11-19 22:42:15 +00:00
|
|
|
beginModule();
|
2010-04-07 10:44:46 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
|
|
|
DwarfDebug::~DwarfDebug() {
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Switch to the specified MCSection and emit an assembler
|
|
|
|
// temporary label to it if SymbolStem is specified.
|
2012-11-21 00:34:35 +00:00
|
|
|
static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section,
|
2011-11-07 09:18:38 +00:00
|
|
|
const char *SymbolStem = 0) {
|
|
|
|
Asm->OutStreamer.SwitchSection(Section);
|
|
|
|
if (!SymbolStem) return 0;
|
|
|
|
|
|
|
|
MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
|
|
|
|
Asm->OutStreamer.EmitLabel(TmpSym);
|
|
|
|
return TmpSym;
|
|
|
|
}
|
|
|
|
|
2012-12-20 21:58:36 +00:00
|
|
|
MCSymbol *DwarfUnits::getStringPoolSym() {
|
2012-12-27 02:14:01 +00:00
|
|
|
return Asm->GetTempSymbol(StringPref);
|
2011-10-27 06:44:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 21:58:36 +00:00
|
|
|
MCSymbol *DwarfUnits::getStringPoolEntry(StringRef Str) {
|
|
|
|
std::pair<MCSymbol*, unsigned> &Entry =
|
2013-01-08 22:22:06 +00:00
|
|
|
StringPool.GetOrCreateValue(Str).getValue();
|
2010-03-13 02:17:42 +00:00
|
|
|
if (Entry.first) return Entry.first;
|
|
|
|
|
|
|
|
Entry.second = NextStringPoolNumber++;
|
2012-12-27 02:14:01 +00:00
|
|
|
return Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
|
2010-03-13 02:17:42 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 19:32:41 +00:00
|
|
|
unsigned DwarfUnits::getStringPoolIndex(StringRef Str) {
|
|
|
|
std::pair<MCSymbol*, unsigned> &Entry =
|
2013-01-08 22:22:06 +00:00
|
|
|
StringPool.GetOrCreateValue(Str).getValue();
|
2013-01-07 19:32:41 +00:00
|
|
|
if (Entry.first) return Entry.second;
|
|
|
|
|
|
|
|
Entry.second = NextStringPoolNumber++;
|
|
|
|
Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
|
|
|
|
return Entry.second;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
unsigned DwarfUnits::getAddrPoolIndex(MCSymbol *Sym) {
|
|
|
|
std::pair<MCSymbol*, unsigned> &Entry = AddressPool[Sym];
|
|
|
|
if (Entry.first) return Entry.second;
|
|
|
|
|
|
|
|
Entry.second = NextAddrPoolNumber++;
|
|
|
|
Entry.first = Sym;
|
|
|
|
return Entry.second;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Define a unique number for the abbreviation.
|
|
|
|
//
|
2012-12-10 23:34:43 +00:00
|
|
|
void DwarfUnits::assignAbbrevNumber(DIEAbbrev &Abbrev) {
|
2009-05-15 09:23:25 +00:00
|
|
|
// Profile the node so that we can make it unique.
|
|
|
|
FoldingSetNodeID ID;
|
|
|
|
Abbrev.Profile(ID);
|
|
|
|
|
|
|
|
// Check the set for priors.
|
2012-12-10 23:34:43 +00:00
|
|
|
DIEAbbrev *InSet = AbbreviationsSet->GetOrInsertNode(&Abbrev);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
|
|
|
// If it's newly added.
|
|
|
|
if (InSet == &Abbrev) {
|
|
|
|
// Add to abbreviation list.
|
2012-12-10 23:34:43 +00:00
|
|
|
Abbreviations->push_back(&Abbrev);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
|
|
|
// Assign the vector position + 1 as its number.
|
2012-12-10 23:34:43 +00:00
|
|
|
Abbrev.setNumber(Abbreviations->size());
|
2009-05-15 09:23:25 +00:00
|
|
|
} else {
|
|
|
|
// Assign existing abbreviation number.
|
|
|
|
Abbrev.setNumber(InSet->getNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// If special LLVM prefix that is used to inform the asm
|
|
|
|
// printer to not emit usual symbol prefix before the symbol name is used then
|
|
|
|
// return linkage name after skipping this special LLVM prefix.
|
2010-01-05 01:46:14 +00:00
|
|
|
static StringRef getRealLinkageName(StringRef LinkageName) {
|
|
|
|
char One = '\1';
|
|
|
|
if (LinkageName.startswith(StringRef(&One, 1)))
|
|
|
|
return LinkageName.substr(1);
|
|
|
|
return LinkageName;
|
|
|
|
}
|
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
static bool isObjCClass(StringRef Name) {
|
|
|
|
return Name.startswith("+") || Name.startswith("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasObjCCategory(StringRef Name) {
|
|
|
|
if (!isObjCClass(Name)) return false;
|
|
|
|
|
|
|
|
size_t pos = Name.find(')');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
if (Name[pos+1] != ' ') return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void getObjCClassCategory(StringRef In, StringRef &Class,
|
|
|
|
StringRef &Category) {
|
|
|
|
if (!hasObjCCategory(In)) {
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
Category = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find('('));
|
|
|
|
Category = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static StringRef getObjCMethodName(StringRef In) {
|
|
|
|
return In.slice(In.find(' ') + 1, In.find(']'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the various names to the Dwarf accelerator table names.
|
|
|
|
static void addSubprogramNames(CompileUnit *TheCU, DISubprogram SP,
|
|
|
|
DIE* Die) {
|
|
|
|
if (!SP.isDefinition()) return;
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
TheCU->addAccelName(SP.getName(), Die);
|
|
|
|
|
|
|
|
// If the linkage name is different than the name, go ahead and output
|
|
|
|
// that as well into the name table.
|
|
|
|
if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
|
|
|
|
TheCU->addAccelName(SP.getLinkageName(), Die);
|
|
|
|
|
|
|
|
// If this is an Objective-C selector name add it to the ObjC accelerator
|
|
|
|
// too.
|
|
|
|
if (isObjCClass(SP.getName())) {
|
|
|
|
StringRef Class, Category;
|
|
|
|
getObjCClassCategory(SP.getName(), Class, Category);
|
|
|
|
TheCU->addAccelObjC(Class, Die);
|
|
|
|
if (Category != "")
|
|
|
|
TheCU->addAccelObjC(Category, Die);
|
|
|
|
// Also add the base method name to the name table.
|
|
|
|
TheCU->addAccelName(getObjCMethodName(SP.getName()), Die);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
|
|
|
|
// and DW_AT_high_pc attributes. If there are global variables in this
|
|
|
|
// scope then create and insert DIEs for these variables.
|
2011-08-15 22:24:32 +00:00
|
|
|
DIE *DwarfDebug::updateSubprogramScopeDIE(CompileUnit *SPCU,
|
|
|
|
const MDNode *SPNode) {
|
2010-05-10 22:49:55 +00:00
|
|
|
DIE *SPDie = SPCU->getDIE(SPNode);
|
2010-07-07 22:20:57 +00:00
|
|
|
|
2010-04-05 00:13:49 +00:00
|
|
|
assert(SPDie && "Unable to find subprogram DIE!");
|
|
|
|
DISubprogram SP(SPNode);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2012-11-07 05:19:04 +00:00
|
|
|
// If we're updating an abstract DIE, then we will be adding the children and
|
|
|
|
// object pointer later on. But what we don't want to do is process the
|
|
|
|
// concrete DIE twice.
|
2013-03-12 18:27:15 +00:00
|
|
|
DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode);
|
|
|
|
if (AbsSPDIE) {
|
|
|
|
bool InSameCU = (AbsSPDIE->getCompileUnit() == SPCU->getCUDie());
|
2012-11-07 05:19:04 +00:00
|
|
|
// Pick up abstract subprogram DIE.
|
2010-07-07 22:20:57 +00:00
|
|
|
SPDie = new DIE(dwarf::DW_TAG_subprogram);
|
2013-03-12 18:27:15 +00:00
|
|
|
// If AbsSPDIE belongs to a different CU, use DW_FORM_ref_addr instead of
|
|
|
|
// DW_FORM_ref4.
|
2011-04-12 22:53:02 +00:00
|
|
|
SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin,
|
2013-03-12 18:27:15 +00:00
|
|
|
InSameCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
|
|
|
|
AbsSPDIE);
|
2010-07-07 22:20:57 +00:00
|
|
|
SPCU->addDie(SPDie);
|
2012-11-07 04:42:18 +00:00
|
|
|
} else {
|
|
|
|
DISubprogram SPDecl = SP.getFunctionDeclaration();
|
|
|
|
if (!SPDecl.isSubprogram()) {
|
|
|
|
// There is not any need to generate specification DIE for a function
|
|
|
|
// defined at compile unit level. If a function is defined inside another
|
|
|
|
// function then gdb prefers the definition at top level and but does not
|
|
|
|
// expect specification DIE in parent function. So avoid creating
|
|
|
|
// specification DIE for a function defined inside a function.
|
|
|
|
if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
|
|
|
|
!SP.getContext().isFile() &&
|
|
|
|
!isSubprogramContext(SP.getContext())) {
|
|
|
|
SPCU->addFlag(SPDie, dwarf::DW_AT_declaration);
|
|
|
|
|
|
|
|
// Add arguments.
|
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
|
|
|
unsigned SPTag = SPTy.getTag();
|
|
|
|
if (SPTag == dwarf::DW_TAG_subroutine_type)
|
|
|
|
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
|
|
|
|
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
|
|
|
|
DIType ATy = DIType(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,
|
|
|
|
dwarf::DW_FORM_ref4, Arg);
|
|
|
|
SPDie->addChild(Arg);
|
|
|
|
}
|
|
|
|
DIE *SPDeclDie = SPDie;
|
|
|
|
SPDie = new DIE(dwarf::DW_TAG_subprogram);
|
2012-11-19 22:42:10 +00:00
|
|
|
SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification,
|
|
|
|
dwarf::DW_FORM_ref4, SPDeclDie);
|
2012-11-07 04:42:18 +00:00
|
|
|
SPCU->addDie(SPDie);
|
|
|
|
}
|
|
|
|
}
|
2010-07-07 22:20:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
SPCU->addLabelAddress(SPDie, dwarf::DW_AT_low_pc,
|
|
|
|
Asm->GetTempSymbol("func_begin",
|
|
|
|
Asm->getFunctionNumber()));
|
|
|
|
SPCU->addLabelAddress(SPDie, dwarf::DW_AT_high_pc,
|
|
|
|
Asm->GetTempSymbol("func_end",
|
|
|
|
Asm->getFunctionNumber()));
|
2010-04-05 00:13:49 +00:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
MachineLocation Location(RI->getFrameRegister(*Asm->MF));
|
2011-04-12 22:53:02 +00:00
|
|
|
SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
|
2010-04-05 00:13:49 +00:00
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
// Add name to the name table, we do this here because we're guaranteed
|
|
|
|
// to have concrete versions of our DW_TAG_subprogram nodes.
|
|
|
|
addSubprogramNames(SPCU, SP, SPDie);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2010-04-05 00:13:49 +00:00
|
|
|
return SPDie;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Construct new DW_TAG_lexical_block for this scope and attach
|
|
|
|
// DW_AT_low_pc/DW_AT_high_pc labels.
|
2012-11-19 22:42:10 +00:00
|
|
|
DIE *DwarfDebug::constructLexicalScopeDIE(CompileUnit *TheCU,
|
2011-08-15 22:24:32 +00:00
|
|
|
LexicalScope *Scope) {
|
2010-04-23 01:18:53 +00:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block);
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return ScopeDIE;
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges();
|
2010-04-27 19:46:33 +00:00
|
|
|
if (Ranges.empty())
|
|
|
|
return 0;
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin();
|
2010-04-27 19:46:33 +00:00
|
|
|
if (Ranges.size() > 1) {
|
|
|
|
// .debug_range section has not been laid out yet. Emit offset in
|
2010-07-21 21:21:52 +00:00
|
|
|
// .debug_range as a uint, size 4, for now. emitDIE will handle
|
2010-04-27 19:46:33 +00:00
|
|
|
// DW_AT_ranges appropriately.
|
2011-04-12 22:53:02 +00:00
|
|
|
TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
|
2012-11-19 22:42:10 +00:00
|
|
|
DebugRangeSymbols.size()
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
* Asm->getDataLayout().getPointerSize());
|
2011-08-10 20:55:27 +00:00
|
|
|
for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
|
2010-04-27 19:46:33 +00:00
|
|
|
RE = Ranges.end(); RI != RE; ++RI) {
|
2010-05-25 23:40:22 +00:00
|
|
|
DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
|
|
|
|
DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
|
2010-04-27 19:46:33 +00:00
|
|
|
}
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
MCSymbol *Start = getLabelBeforeInsn(RI->first);
|
|
|
|
MCSymbol *End = getLabelAfterInsn(RI->second);
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2010-05-25 23:40:22 +00:00
|
|
|
if (End == 0) return 0;
|
2010-04-27 19:46:33 +00:00
|
|
|
|
|
|
|
assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
|
|
|
|
assert(End->isDefined() && "Invalid end label for an inlined scope!");
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_low_pc, Start);
|
|
|
|
TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_high_pc, End);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// This scope represents inlined body of a function. Construct DIE to
|
|
|
|
// represent this concrete inlined copy of the function.
|
2011-08-15 22:24:32 +00:00
|
|
|
DIE *DwarfDebug::constructInlinedScopeDIE(CompileUnit *TheCU,
|
|
|
|
LexicalScope *Scope) {
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<InsnRange, 4> &Ranges = Scope->getRanges();
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(Ranges.empty() == false &&
|
|
|
|
"LexicalScope does not have instruction markers!");
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2011-07-27 00:34:13 +00:00
|
|
|
if (!Scope->getScopeNode())
|
|
|
|
return NULL;
|
|
|
|
DIScope DS(Scope->getScopeNode());
|
|
|
|
DISubprogram InlinedSP = getDISubprogram(DS);
|
|
|
|
DIE *OriginDIE = TheCU->getDIE(InlinedSP);
|
|
|
|
if (!OriginDIE) {
|
2012-10-30 17:51:02 +00:00
|
|
|
DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram.");
|
2011-07-27 00:34:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin();
|
2013-01-15 23:56:56 +00:00
|
|
|
MCSymbol *StartLabel = getLabelBeforeInsn(RI->first);
|
|
|
|
MCSymbol *EndLabel = getLabelAfterInsn(RI->second);
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2010-07-08 22:39:20 +00:00
|
|
|
if (StartLabel == 0 || EndLabel == 0) {
|
2012-10-30 17:51:02 +00:00
|
|
|
llvm_unreachable("Unexpected Start and End labels for an inlined scope!");
|
2010-04-27 19:46:33 +00:00
|
|
|
}
|
2010-03-09 01:58:53 +00:00
|
|
|
assert(StartLabel->isDefined() &&
|
2010-03-09 01:51:43 +00:00
|
|
|
"Invalid starting label for an inlined scope!");
|
2010-03-09 01:58:53 +00:00
|
|
|
assert(EndLabel->isDefined() &&
|
2010-03-09 01:51:43 +00:00
|
|
|
"Invalid end label for an inlined scope!");
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2011-05-05 17:54:26 +00:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
|
2011-04-12 22:53:02 +00:00
|
|
|
TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
|
|
|
|
dwarf::DW_FORM_ref4, OriginDIE);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2011-07-27 00:34:13 +00:00
|
|
|
if (Ranges.size() > 1) {
|
|
|
|
// .debug_range section has not been laid out yet. Emit offset in
|
|
|
|
// .debug_range as a uint, size 4, for now. emitDIE will handle
|
|
|
|
// DW_AT_ranges appropriately.
|
|
|
|
TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
|
2012-11-19 22:42:10 +00:00
|
|
|
DebugRangeSymbols.size()
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
* Asm->getDataLayout().getPointerSize());
|
2011-08-10 20:55:27 +00:00
|
|
|
for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
|
2011-07-27 00:34:13 +00:00
|
|
|
RE = Ranges.end(); RI != RE; ++RI) {
|
|
|
|
DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
|
|
|
|
DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
|
|
|
|
}
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
} else {
|
2013-01-15 23:56:56 +00:00
|
|
|
TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_low_pc, StartLabel);
|
|
|
|
TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_high_pc, EndLabel);
|
2011-07-27 00:34:13 +00:00
|
|
|
}
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
InlinedSubprogramDIEs.insert(OriginDIE);
|
|
|
|
|
|
|
|
// Track the start label for this inlined function.
|
2011-07-27 00:34:13 +00:00
|
|
|
//.debug_inlined section specification does not clearly state how
|
|
|
|
// to emit inlined scope that is split into multiple instruction ranges.
|
|
|
|
// For now, use first instruction range and emit low_pc/high_pc pair and
|
|
|
|
// corresponding .debug_inlined section entry for this pair.
|
2010-05-07 20:54:48 +00:00
|
|
|
DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator
|
2010-05-07 18:11:54 +00:00
|
|
|
I = InlineInfo.find(InlinedSP);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
if (I == InlineInfo.end()) {
|
2011-10-26 22:55:33 +00:00
|
|
|
InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel, ScopeDIE));
|
2010-05-07 18:11:54 +00:00
|
|
|
InlinedSPNodes.push_back(InlinedSP);
|
2009-11-10 23:06:00 +00:00
|
|
|
} else
|
2010-03-09 00:31:02 +00:00
|
|
|
I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
DILocation DL(Scope->getInlinedAt());
|
2012-03-26 21:38:38 +00:00
|
|
|
TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0,
|
2013-03-07 01:42:00 +00:00
|
|
|
getOrCreateSourceID(DL.getFilename(), DL.getDirectory(),
|
|
|
|
TheCU->getUniqueID()));
|
2011-04-12 22:53:02 +00:00
|
|
|
TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber());
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2011-12-04 06:02:38 +00:00
|
|
|
// Add name to the name table, we do this here because we're guaranteed
|
|
|
|
// to have concrete versions of our DW_TAG_inlined_subprogram nodes.
|
|
|
|
addSubprogramNames(TheCU, InlinedSP, ScopeDIE);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Construct a DIE for this scope.
|
2011-08-15 22:04:40 +00:00
|
|
|
DIE *DwarfDebug::constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope) {
|
2010-03-08 20:52:55 +00:00
|
|
|
if (!Scope || !Scope->getScopeNode())
|
|
|
|
return NULL;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2013-01-31 20:05:14 +00:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
|
|
|
// Early return to avoid creating dangling variable|scope DIEs.
|
|
|
|
if (!Scope->getInlinedAt() && DS.isSubprogram() && Scope->isAbstractScope() &&
|
|
|
|
!TheCU->getDIE(DS))
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-26 22:55:33 +00:00
|
|
|
SmallVector<DIE *, 8> Children;
|
2012-09-12 23:36:19 +00:00
|
|
|
DIE *ObjectPointer = NULL;
|
2011-03-01 22:58:55 +00:00
|
|
|
|
|
|
|
// Collect arguments for current function.
|
2011-08-10 20:55:27 +00:00
|
|
|
if (LScopes.isCurrentFunctionScope(Scope))
|
2011-03-01 22:58:55 +00:00
|
|
|
for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
|
|
|
|
if (DbgVariable *ArgDV = CurrentFnArguments[i])
|
2012-11-19 22:42:10 +00:00
|
|
|
if (DIE *Arg =
|
2012-09-12 23:36:19 +00:00
|
|
|
TheCU->constructVariableDIE(ArgDV, Scope->isAbstractScope())) {
|
2011-03-01 22:58:55 +00:00
|
|
|
Children.push_back(Arg);
|
2012-09-12 23:36:19 +00:00
|
|
|
if (ArgDV->isObjectPointer()) ObjectPointer = Arg;
|
|
|
|
}
|
2011-03-01 22:58:55 +00:00
|
|
|
|
2011-10-03 15:49:16 +00:00
|
|
|
// Collect lexical scope children first.
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<DbgVariable *, 8> &Variables = ScopeVariables.lookup(Scope);
|
2011-02-19 01:31:27 +00:00
|
|
|
for (unsigned i = 0, N = Variables.size(); i < N; ++i)
|
2012-11-19 22:42:10 +00:00
|
|
|
if (DIE *Variable =
|
2012-09-21 22:18:52 +00:00
|
|
|
TheCU->constructVariableDIE(Variables[i], Scope->isAbstractScope())) {
|
2011-02-19 01:31:27 +00:00
|
|
|
Children.push_back(Variable);
|
2012-09-21 22:18:52 +00:00
|
|
|
if (Variables[i]->isObjectPointer()) ObjectPointer = Variable;
|
|
|
|
}
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<LexicalScope *, 4> &Scopes = Scope->getChildren();
|
2011-02-19 01:31:27 +00:00
|
|
|
for (unsigned j = 0, M = Scopes.size(); j < M; ++j)
|
2011-08-15 22:04:40 +00:00
|
|
|
if (DIE *Nested = constructScopeDIE(TheCU, Scopes[j]))
|
2011-02-19 01:31:27 +00:00
|
|
|
Children.push_back(Nested);
|
2010-03-08 20:52:55 +00:00
|
|
|
DIE *ScopeDIE = NULL;
|
|
|
|
if (Scope->getInlinedAt())
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);
|
2010-03-08 20:52:55 +00:00
|
|
|
else if (DS.isSubprogram()) {
|
2010-06-28 20:53:04 +00:00
|
|
|
ProcessedSPNodes.insert(DS);
|
2010-07-07 22:20:57 +00:00
|
|
|
if (Scope->isAbstractScope()) {
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = TheCU->getDIE(DS);
|
2010-07-07 22:20:57 +00:00
|
|
|
// Note down abstract DIE.
|
|
|
|
if (ScopeDIE)
|
|
|
|
AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
|
|
|
|
}
|
2010-03-08 20:52:55 +00:00
|
|
|
else
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = updateSubprogramScopeDIE(TheCU, DS);
|
2010-03-08 20:52:55 +00:00
|
|
|
}
|
2011-02-19 01:31:27 +00:00
|
|
|
else {
|
|
|
|
// There is no need to emit empty lexical block DIE.
|
|
|
|
if (Children.empty())
|
|
|
|
return NULL;
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-02-19 01:31:27 +00:00
|
|
|
if (!ScopeDIE) return NULL;
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2011-02-19 01:31:27 +00:00
|
|
|
// Add children
|
|
|
|
for (SmallVector<DIE *, 8>::iterator I = Children.begin(),
|
|
|
|
E = Children.end(); I != E; ++I)
|
|
|
|
ScopeDIE->addChild(*I);
|
2009-11-24 01:14:22 +00:00
|
|
|
|
2012-09-12 23:36:19 +00:00
|
|
|
if (DS.isSubprogram() && ObjectPointer != NULL)
|
|
|
|
TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer,
|
|
|
|
dwarf::DW_FORM_ref4, ObjectPointer);
|
|
|
|
|
2010-07-21 21:21:52 +00:00
|
|
|
if (DS.isSubprogram())
|
2011-11-10 19:25:34 +00:00
|
|
|
TheCU->addPubTypes(DISubprogram(DS));
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
return ScopeDIE;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Look up the source id with the given directory and source file names.
|
|
|
|
// If none currently exists, create a new id and insert it in the
|
|
|
|
// SourceIds map. This can update DirectoryNames and SourceFileNames maps
|
|
|
|
// as well.
|
2012-11-21 00:34:35 +00:00
|
|
|
unsigned DwarfDebug::getOrCreateSourceID(StringRef FileName,
|
2013-03-07 01:42:00 +00:00
|
|
|
StringRef DirName, unsigned CUID) {
|
|
|
|
// If we use .loc in assembly, we can't separate .file entries according to
|
|
|
|
// compile units. Thus all files will belong to the default compile unit.
|
|
|
|
if (Asm->TM.hasMCUseLoc() &&
|
|
|
|
Asm->OutStreamer.getKind() == MCStreamer::SK_AsmStreamer)
|
|
|
|
CUID = 0;
|
|
|
|
|
2010-09-16 20:57:49 +00:00
|
|
|
// If FE did not provide a file name, then assume stdin.
|
|
|
|
if (FileName.empty())
|
2013-03-07 01:42:00 +00:00
|
|
|
return getOrCreateSourceID("<stdin>", StringRef(), CUID);
|
2011-03-24 20:30:50 +00:00
|
|
|
|
2011-11-02 20:55:33 +00:00
|
|
|
// TODO: this might not belong here. See if we can factor this better.
|
|
|
|
if (DirName == CompilationDir)
|
|
|
|
DirName = "";
|
|
|
|
|
2013-03-07 01:42:00 +00:00
|
|
|
// FileIDCUMap stores the current ID for the given compile unit.
|
|
|
|
unsigned SrcId = FileIDCUMap[CUID] + 1;
|
2011-10-17 23:05:28 +00:00
|
|
|
|
2013-03-07 01:42:00 +00:00
|
|
|
// We look up the CUID/file/dir by concatenating them with a zero byte.
|
2012-03-11 14:56:26 +00:00
|
|
|
SmallString<128> NamePair;
|
2013-04-06 01:02:38 +00:00
|
|
|
NamePair += utostr(CUID);
|
2013-03-07 01:42:00 +00:00
|
|
|
NamePair += '\0';
|
2012-03-11 14:56:26 +00:00
|
|
|
NamePair += DirName;
|
|
|
|
NamePair += '\0'; // Zero bytes are not allowed in paths.
|
|
|
|
NamePair += FileName;
|
|
|
|
|
|
|
|
StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue(NamePair, SrcId);
|
|
|
|
if (Ent.getValue() != SrcId)
|
|
|
|
return Ent.getValue();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-03-07 01:42:00 +00:00
|
|
|
FileIDCUMap[CUID] = SrcId;
|
2010-11-18 02:04:25 +00:00
|
|
|
// Print out a .file directive to specify files for .loc directives.
|
2013-03-07 01:42:00 +00:00
|
|
|
Asm->OutStreamer.EmitDwarfFileDirective(SrcId, DirName, FileName, CUID);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
return SrcId;
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-12-20 21:58:40 +00:00
|
|
|
// Create new CompileUnit for the given metadata node with tag
|
|
|
|
// DW_TAG_compile_unit.
|
2011-08-16 22:09:43 +00:00
|
|
|
CompileUnit *DwarfDebug::constructCompileUnit(const MDNode *N) {
|
2009-08-28 23:24:31 +00:00
|
|
|
DICompileUnit DIUnit(N);
|
2009-11-25 17:36:49 +00:00
|
|
|
StringRef FN = DIUnit.getFilename();
|
2011-11-02 20:55:33 +00:00
|
|
|
CompilationDir = DIUnit.getDirectory();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
|
2012-12-03 18:45:45 +00:00
|
|
|
CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++,
|
2012-12-20 21:58:36 +00:00
|
|
|
DIUnit.getLanguage(), Die, Asm,
|
|
|
|
this, &InfoHolder);
|
2013-03-07 01:42:00 +00:00
|
|
|
|
|
|
|
FileIDCUMap[NewCU->getUniqueID()] = 0;
|
|
|
|
// Call this to emit a .file directive if it wasn't emitted for the source
|
|
|
|
// file this CU comes from yet.
|
|
|
|
getOrCreateSourceID(FN, CompilationDir, NewCU->getUniqueID());
|
|
|
|
|
2011-10-27 06:44:11 +00:00
|
|
|
NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
|
2011-04-12 22:53:02 +00:00
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
|
|
|
DIUnit.getLanguage());
|
2011-10-27 06:44:11 +00:00
|
|
|
NewCU->addString(Die, dwarf::DW_AT_name, FN);
|
2013-04-09 19:23:15 +00:00
|
|
|
|
2012-08-01 18:19:01 +00:00
|
|
|
// 2.17.1 requires that we use DW_AT_low_pc for a single entry point
|
2013-04-09 19:23:15 +00:00
|
|
|
// into an entity. We're using 0 (or a NULL label) for this. For
|
|
|
|
// split dwarf it's in the skeleton CU so omit it here.
|
|
|
|
if (!useSplitDwarf())
|
|
|
|
NewCU->addLabelAddress(Die, dwarf::DW_AT_low_pc, NULL);
|
2013-02-05 21:52:47 +00:00
|
|
|
|
|
|
|
// Define start line table label for each Compile Unit.
|
|
|
|
MCSymbol *LineTableStartSym = Asm->GetTempSymbol("line_table_start",
|
|
|
|
NewCU->getUniqueID());
|
|
|
|
Asm->OutStreamer.getContext().setMCLineTableSymbol(LineTableStartSym,
|
|
|
|
NewCU->getUniqueID());
|
|
|
|
|
2010-03-22 23:11:36 +00:00
|
|
|
// DW_AT_stmt_list is a offset of line number information for this
|
2013-04-09 19:23:15 +00:00
|
|
|
// compile unit in debug_line section. For split dwarf this is
|
|
|
|
// left in the skeleton CU and so not included.
|
2013-02-09 00:41:44 +00:00
|
|
|
// The line table entries are not always emitted in assembly, so it
|
|
|
|
// is not okay to use line_table_start here.
|
2013-04-09 19:23:15 +00:00
|
|
|
if (!useSplitDwarf()) {
|
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
|
|
|
NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4,
|
|
|
|
NewCU->getUniqueID() == 0 ?
|
|
|
|
Asm->GetTempSymbol("section_line") : LineTableStartSym);
|
|
|
|
else if (NewCU->getUniqueID() == 0)
|
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0);
|
|
|
|
else
|
|
|
|
NewCU->addDelta(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4,
|
|
|
|
LineTableStartSym, DwarfLineSectionSym);
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-04-09 19:23:15 +00:00
|
|
|
// If we're using split dwarf the compilation dir is going to be in the
|
|
|
|
// skeleton CU and so we don't need to duplicate it here.
|
|
|
|
if (!useSplitDwarf() && !CompilationDir.empty())
|
2011-11-02 20:55:33 +00:00
|
|
|
NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2009-05-20 23:21:38 +00:00
|
|
|
if (DIUnit.isOptimized())
|
2012-08-24 01:14:27 +00:00
|
|
|
NewCU->addFlag(Die, dwarf::DW_AT_APPLE_optimized);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-11-25 17:36:49 +00:00
|
|
|
StringRef Flags = DIUnit.getFlags();
|
|
|
|
if (!Flags.empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-10-17 23:27:36 +00:00
|
|
|
if (unsigned RVer = DIUnit.getRunTimeVersion())
|
2011-04-12 22:53:02 +00:00
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
2009-05-20 23:21:38 +00:00
|
|
|
dwarf::DW_FORM_data1, RVer);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
if (!FirstCU)
|
|
|
|
FirstCU = NewCU;
|
2013-02-05 07:31:55 +00:00
|
|
|
|
2012-12-10 23:34:43 +00:00
|
|
|
InfoHolder.addUnit(NewCU);
|
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
CUMap.insert(std::make_pair(N, NewCU));
|
2011-08-16 22:09:43 +00:00
|
|
|
return NewCU;
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Construct subprogram DIE.
|
2012-11-19 22:42:10 +00:00
|
|
|
void DwarfDebug::constructSubprogramDIE(CompileUnit *TheCU,
|
2011-08-15 23:36:40 +00:00
|
|
|
const MDNode *N) {
|
2011-11-04 19:00:29 +00:00
|
|
|
CompileUnit *&CURef = SPMap[N];
|
|
|
|
if (CURef)
|
|
|
|
return;
|
|
|
|
CURef = TheCU;
|
|
|
|
|
2009-08-28 23:24:31 +00:00
|
|
|
DISubprogram SP(N);
|
2009-05-20 23:21:38 +00:00
|
|
|
if (!SP.isDefinition())
|
|
|
|
// This is a method declaration which will be handled while constructing
|
|
|
|
// class type.
|
2009-06-26 01:49:18 +00:00
|
|
|
return;
|
2009-05-20 23:04:56 +00:00
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
DIE *SubprogramDie = TheCU->getOrCreateSubprogramDIE(SP);
|
2010-04-06 21:38:29 +00:00
|
|
|
|
|
|
|
// Add to map.
|
2010-05-10 22:49:55 +00:00
|
|
|
TheCU->insertDIE(N, SubprogramDie);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Add to context owner.
|
2011-04-12 22:53:02 +00:00
|
|
|
TheCU->addToContextOwner(SubprogramDie, SP.getContext());
|
2009-12-08 23:21:45 +00:00
|
|
|
|
2013-02-12 18:00:14 +00:00
|
|
|
// Expose as global, if requested.
|
|
|
|
if (GenerateDwarfPubNamesSection)
|
|
|
|
TheCU->addGlobalName(SP.getName(), SubprogramDie);
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-04-22 06:12:31 +00:00
|
|
|
void DwarfDebug::constructImportedModuleDIE(CompileUnit *TheCU,
|
|
|
|
const MDNode *N) {
|
|
|
|
DIImportedModule Module(N);
|
|
|
|
if (!Module.Verify())
|
|
|
|
return;
|
|
|
|
DIE *IMDie = new DIE(dwarf::DW_TAG_imported_module);
|
|
|
|
TheCU->insertDIE(Module, IMDie);
|
|
|
|
DIE *NSDie = TheCU->getOrCreateNameSpace(Module.getNameSpace());
|
|
|
|
unsigned FileID = getOrCreateSourceID(Module.getContext().getFilename(),
|
|
|
|
Module.getContext().getDirectory(),
|
|
|
|
TheCU->getUniqueID());
|
|
|
|
TheCU->addUInt(IMDie, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
TheCU->addUInt(IMDie, dwarf::DW_AT_decl_line, 0, Module.getLineNumber());
|
|
|
|
TheCU->addDIEEntry(IMDie, dwarf::DW_AT_import, dwarf::DW_FORM_ref4, NSDie);
|
|
|
|
TheCU->addToContextOwner(IMDie, Module.getContext());
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit all Dwarf sections that should come prior to the content. Create
|
|
|
|
// global DIEs and emit initial debug info sections. This is invoked by
|
|
|
|
// the target AsmPrinter.
|
2012-11-19 22:42:15 +00:00
|
|
|
void DwarfDebug::beginModule() {
|
2010-04-27 19:46:33 +00:00
|
|
|
if (DisableDebugInfoPrinting)
|
|
|
|
return;
|
|
|
|
|
2012-11-19 22:42:15 +00:00
|
|
|
const Module *M = MMI->getModule();
|
|
|
|
|
2011-07-29 03:49:23 +00:00
|
|
|
// If module has named metadata anchors then use them, otherwise scan the
|
|
|
|
// module using debug info finder to collect debug info.
|
2011-05-03 16:45:22 +00:00
|
|
|
NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
|
2013-03-11 23:39:23 +00:00
|
|
|
if (!CU_Nodes)
|
2011-08-15 23:47:24 +00:00
|
|
|
return;
|
2010-04-05 02:19:28 +00:00
|
|
|
|
2013-03-11 23:39:23 +00:00
|
|
|
// Emit initial sections so we can reference labels later.
|
|
|
|
emitSectionLabels();
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
|
|
|
|
DICompileUnit CUNode(CU_Nodes->getOperand(i));
|
|
|
|
CompileUnit *CU = constructCompileUnit(CUNode);
|
|
|
|
DIArray GVs = CUNode.getGlobalVariables();
|
|
|
|
for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
|
|
|
|
CU->createGlobalVariableDIE(GVs.getElement(i));
|
|
|
|
DIArray SPs = CUNode.getSubprograms();
|
|
|
|
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
|
|
|
|
constructSubprogramDIE(CU, SPs.getElement(i));
|
|
|
|
DIArray EnumTypes = CUNode.getEnumTypes();
|
|
|
|
for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
|
|
|
|
CU->getOrCreateTypeDIE(EnumTypes.getElement(i));
|
|
|
|
DIArray RetainedTypes = CUNode.getRetainedTypes();
|
|
|
|
for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
|
|
|
|
CU->getOrCreateTypeDIE(RetainedTypes.getElement(i));
|
2013-04-22 06:12:31 +00:00
|
|
|
// Emit imported_modules last so that the relevant context is already
|
|
|
|
// available.
|
|
|
|
DIArray ImportedModules = CUNode.getImportedModules();
|
|
|
|
for (unsigned i = 0, e = ImportedModules.getNumElements(); i != e; ++i)
|
|
|
|
constructImportedModuleDIE(CU, ImportedModules.getElement(i));
|
2013-03-29 20:23:02 +00:00
|
|
|
// If we're splitting the dwarf out now that we've got the entire
|
|
|
|
// CU then construct a skeleton CU based upon it.
|
|
|
|
if (useSplitDwarf()) {
|
|
|
|
// This should be a unique identifier when we want to build .dwp files.
|
2013-04-22 07:51:08 +00:00
|
|
|
CU->addUInt(CU->getCUDie(), dwarf::DW_AT_GNU_dwo_id,
|
|
|
|
dwarf::DW_FORM_data8, 0);
|
2013-03-29 20:23:02 +00:00
|
|
|
// Now construct the skeleton CU associated.
|
|
|
|
constructSkeletonCU(CUNode);
|
|
|
|
}
|
2013-03-11 23:39:23 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2010-04-05 02:19:28 +00:00
|
|
|
// Tell MMI that we have debug info.
|
|
|
|
MMI->setDebugInfoAvailability(true);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Prime section data.
|
2009-07-28 03:13:23 +00:00
|
|
|
SectionMap.insert(Asm->getObjFileLowering().getTextSection());
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
|
|
|
void DwarfDebug::computeInlinedDIEs() {
|
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
|
|
|
for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
|
2012-11-27 00:13:51 +00:00
|
|
|
AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
|
2012-11-22 00:59:49 +00:00
|
|
|
DIE *ISP = *AI;
|
|
|
|
FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
|
|
|
|
}
|
|
|
|
for (DenseMap<const MDNode *, DIE *>::iterator AI = AbstractSPDies.begin(),
|
2012-11-27 00:13:51 +00:00
|
|
|
AE = AbstractSPDies.end(); AI != AE; ++AI) {
|
2012-11-22 00:59:49 +00:00
|
|
|
DIE *ISP = AI->second;
|
|
|
|
if (InlinedSubprogramDIEs.count(ISP))
|
|
|
|
continue;
|
|
|
|
FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 22:42:15 +00:00
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
void DwarfDebug::collectDeadVariables() {
|
2010-06-28 18:25:03 +00:00
|
|
|
const Module *M = MMI->getModule();
|
2011-08-10 20:55:27 +00:00
|
|
|
DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-08-16 22:09:43 +00:00
|
|
|
if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
|
|
|
|
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
|
|
|
|
DICompileUnit TheCU(CU_Nodes->getOperand(i));
|
|
|
|
DIArray Subprograms = TheCU.getSubprograms();
|
|
|
|
for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
|
2012-11-27 00:13:51 +00:00
|
|
|
DISubprogram SP(Subprograms.getElement(i));
|
|
|
|
if (ProcessedSPNodes.count(SP) != 0) continue;
|
|
|
|
if (!SP.Verify()) continue;
|
|
|
|
if (!SP.isDefinition()) continue;
|
|
|
|
DIArray Variables = SP.getVariables();
|
|
|
|
if (Variables.getNumElements() == 0) continue;
|
|
|
|
|
|
|
|
LexicalScope *Scope =
|
|
|
|
new LexicalScope(NULL, DIDescriptor(SP), NULL, false);
|
|
|
|
DeadFnScopeMap[SP] = Scope;
|
|
|
|
|
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
|
|
|
CompileUnit *SPCU = CUMap.lookup(TheCU);
|
|
|
|
assert(SPCU && "Unable to find Compile Unit!");
|
|
|
|
constructSubprogramDIE(SPCU, SP);
|
|
|
|
DIE *ScopeDIE = SPCU->getDIE(SP);
|
|
|
|
for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
|
|
|
|
DIVariable DV(Variables.getElement(vi));
|
|
|
|
if (!DV.Verify()) continue;
|
|
|
|
DbgVariable *NewVar = new DbgVariable(DV, NULL);
|
|
|
|
if (DIE *VariableDIE =
|
|
|
|
SPCU->constructVariableDIE(NewVar, Scope->isAbstractScope()))
|
|
|
|
ScopeDIE->addChild(VariableDIE);
|
|
|
|
}
|
2010-06-28 18:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 00:59:49 +00:00
|
|
|
DeleteContainerSeconds(DeadFnScopeMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::finalizeModuleInfo() {
|
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
collectDeadVariables();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
2012-11-22 00:59:49 +00:00
|
|
|
computeInlinedDIEs();
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2012-08-01 18:19:01 +00:00
|
|
|
// Emit DW_AT_containing_type attribute to connect types with their
|
|
|
|
// vtable holding type.
|
2011-08-15 17:24:54 +00:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator CUI = CUMap.begin(),
|
2012-11-27 00:13:51 +00:00
|
|
|
CUE = CUMap.end(); CUI != CUE; ++CUI) {
|
2011-08-15 17:24:54 +00:00
|
|
|
CompileUnit *TheCU = CUI->second;
|
|
|
|
TheCU->constructContainingTypeDIEs();
|
2009-12-03 19:11:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Compute DIE offsets and sizes.
|
2012-12-10 23:34:43 +00:00
|
|
|
InfoHolder.computeSizeAndOffsets();
|
|
|
|
if (useSplitDwarf())
|
|
|
|
SkeletonHolder.computeSizeAndOffsets();
|
2012-11-22 00:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::endSections() {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Standard sections final addresses.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
|
2010-04-04 19:25:43 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection());
|
2010-04-04 19:25:43 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end"));
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// End text sections.
|
2012-10-31 13:45:49 +00:00
|
|
|
for (unsigned I = 0, E = SectionMap.size(); I != E; ++I) {
|
|
|
|
Asm->OutStreamer.SwitchSection(SectionMap[I]);
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", I+1));
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2012-11-22 00:59:49 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit all Dwarf sections that should come after the content.
|
2012-11-22 00:59:49 +00:00
|
|
|
void DwarfDebug::endModule() {
|
|
|
|
|
|
|
|
if (!FirstCU) return;
|
|
|
|
|
|
|
|
// End any existing sections.
|
|
|
|
// TODO: Does this need to happen?
|
|
|
|
endSections();
|
|
|
|
|
|
|
|
// Finalize the debug info for the module.
|
|
|
|
finalizeModuleInfo();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-12-10 19:51:21 +00:00
|
|
|
if (!useSplitDwarf()) {
|
2012-11-27 22:43:42 +00:00
|
|
|
// Emit all the DIEs into a debug info section.
|
|
|
|
emitDebugInfo();
|
2012-11-27 00:41:54 +00:00
|
|
|
|
2012-11-27 22:43:42 +00:00
|
|
|
// Corresponding abbreviations into a abbrev section.
|
|
|
|
emitAbbreviations();
|
|
|
|
|
|
|
|
// Emit info into a debug loc section.
|
|
|
|
emitDebugLoc();
|
|
|
|
|
|
|
|
// Emit info into a debug aranges section.
|
|
|
|
emitDebugARanges();
|
|
|
|
|
|
|
|
// Emit info into a debug ranges section.
|
|
|
|
emitDebugRanges();
|
|
|
|
|
|
|
|
// Emit info into a debug macinfo section.
|
|
|
|
emitDebugMacInfo();
|
|
|
|
|
|
|
|
// Emit inline info.
|
|
|
|
// TODO: When we don't need the option anymore we
|
|
|
|
// can remove all of the code that this section
|
|
|
|
// depends upon.
|
|
|
|
if (useDarwinGDBCompat())
|
|
|
|
emitDebugInlineInfo();
|
|
|
|
} else {
|
2012-12-11 19:42:09 +00:00
|
|
|
// TODO: Fill this in for separated debug sections and separate
|
2012-11-27 22:43:42 +00:00
|
|
|
// out information into new sections.
|
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
// Emit the debug info section and compile units.
|
2012-11-27 22:43:42 +00:00
|
|
|
emitDebugInfo();
|
2012-11-30 23:59:06 +00:00
|
|
|
emitDebugInfoDWO();
|
2012-11-27 22:43:42 +00:00
|
|
|
|
|
|
|
// Corresponding abbreviations into a abbrev section.
|
|
|
|
emitAbbreviations();
|
2012-12-19 22:02:53 +00:00
|
|
|
emitDebugAbbrevDWO();
|
2012-11-27 22:43:42 +00:00
|
|
|
|
|
|
|
// Emit info into a debug loc section.
|
|
|
|
emitDebugLoc();
|
|
|
|
|
|
|
|
// Emit info into a debug aranges section.
|
|
|
|
emitDebugARanges();
|
|
|
|
|
|
|
|
// Emit info into a debug ranges section.
|
|
|
|
emitDebugRanges();
|
|
|
|
|
|
|
|
// Emit info into a debug macinfo section.
|
|
|
|
emitDebugMacInfo();
|
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
// Emit DWO addresses.
|
|
|
|
InfoHolder.emitAddresses(Asm->getObjFileLowering().getDwarfAddrSection());
|
|
|
|
|
2012-11-27 22:43:42 +00:00
|
|
|
// Emit inline info.
|
|
|
|
// TODO: When we don't need the option anymore we
|
|
|
|
// can remove all of the code that this section
|
|
|
|
// depends upon.
|
|
|
|
if (useDarwinGDBCompat())
|
|
|
|
emitDebugInlineInfo();
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-08-23 07:32:06 +00:00
|
|
|
// Emit info into the dwarf accelerator table sections.
|
2012-08-23 22:36:40 +00:00
|
|
|
if (useDwarfAccelTables()) {
|
2011-11-07 09:24:32 +00:00
|
|
|
emitAccelNames();
|
|
|
|
emitAccelObjC();
|
|
|
|
emitAccelNamespaces();
|
|
|
|
emitAccelTypes();
|
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2013-02-12 18:00:14 +00:00
|
|
|
// Emit info into a debug pubnames section, if requested.
|
|
|
|
if (GenerateDwarfPubNamesSection)
|
|
|
|
emitDebugPubnames();
|
|
|
|
|
2009-11-24 01:14:22 +00:00
|
|
|
// Emit info into a debug pubtypes section.
|
2012-08-23 07:10:56 +00:00
|
|
|
// TODO: When we don't need the option anymore we can
|
|
|
|
// remove all of the code that adds to the table.
|
2012-08-23 22:36:40 +00:00
|
|
|
if (useDarwinGDBCompat())
|
2012-08-23 07:10:56 +00:00
|
|
|
emitDebugPubTypes();
|
2009-11-24 01:14:22 +00:00
|
|
|
|
2012-11-27 22:43:42 +00:00
|
|
|
// Finally emit string information into a string table.
|
2012-11-27 06:49:23 +00:00
|
|
|
emitDebugStr();
|
2012-12-27 02:14:01 +00:00
|
|
|
if (useSplitDwarf())
|
|
|
|
emitDebugStrDWO();
|
2012-11-27 06:49:23 +00:00
|
|
|
|
2010-08-02 17:32:15 +00:00
|
|
|
// clean up.
|
2011-08-16 22:09:43 +00:00
|
|
|
SPMap.clear();
|
2010-05-10 22:49:55 +00:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
2012-12-10 19:51:18 +00:00
|
|
|
|
2013-02-06 21:53:56 +00:00
|
|
|
for (SmallVector<CompileUnit *, 1>::iterator I = SkeletonCUs.begin(),
|
|
|
|
E = SkeletonCUs.end(); I != E; ++I)
|
|
|
|
delete *I;
|
2012-12-10 19:51:18 +00:00
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
// Reset these for the next Module if we have one.
|
|
|
|
FirstCU = NULL;
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Find abstract variable, if any, associated with Var.
|
2011-08-10 21:50:54 +00:00
|
|
|
DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
|
2010-04-02 19:42:39 +00:00
|
|
|
DebugLoc ScopeLoc) {
|
2011-08-10 21:50:54 +00:00
|
|
|
LLVMContext &Ctx = DV->getContext();
|
|
|
|
// More then one inlined variable corresponds to one abstract variable.
|
|
|
|
DIVariable Var = cleanseInlinedVariable(DV, Ctx);
|
2010-05-07 18:11:54 +00:00
|
|
|
DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var);
|
2010-03-15 18:33:46 +00:00
|
|
|
if (AbsDbgVariable)
|
|
|
|
return AbsDbgVariable;
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
LexicalScope *Scope = LScopes.findAbstractScope(ScopeLoc.getScope(Ctx));
|
2010-03-15 18:33:46 +00:00
|
|
|
if (!Scope)
|
|
|
|
return NULL;
|
|
|
|
|
2011-08-15 19:01:20 +00:00
|
|
|
AbsDbgVariable = new DbgVariable(Var, NULL);
|
2011-08-10 20:55:27 +00:00
|
|
|
addScopeVariable(Scope, AbsDbgVariable);
|
2010-05-07 18:11:54 +00:00
|
|
|
AbstractVariables[Var] = AbsDbgVariable;
|
2010-03-15 18:33:46 +00:00
|
|
|
return AbsDbgVariable;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// If Var is a current function argument then add it to CurrentFnArguments list.
|
2011-03-01 22:58:55 +00:00
|
|
|
bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
|
2011-08-10 20:55:27 +00:00
|
|
|
DbgVariable *Var, LexicalScope *Scope) {
|
|
|
|
if (!LScopes.isCurrentFunctionScope(Scope))
|
2011-03-01 22:58:55 +00:00
|
|
|
return false;
|
|
|
|
DIVariable DV = Var->getVariable();
|
|
|
|
if (DV.getTag() != dwarf::DW_TAG_arg_variable)
|
|
|
|
return false;
|
|
|
|
unsigned ArgNo = DV.getArgNumber();
|
2012-11-19 22:42:10 +00:00
|
|
|
if (ArgNo == 0)
|
2011-03-01 22:58:55 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-03 20:02:02 +00:00
|
|
|
size_t Size = CurrentFnArguments.size();
|
|
|
|
if (Size == 0)
|
2011-03-01 22:58:55 +00:00
|
|
|
CurrentFnArguments.resize(MF->getFunction()->arg_size());
|
2011-03-03 21:49:41 +00:00
|
|
|
// llvm::Function argument size is not good indicator of how many
|
2011-03-03 20:08:10 +00:00
|
|
|
// arguments does the function have at source level.
|
|
|
|
if (ArgNo > Size)
|
2011-03-03 20:02:02 +00:00
|
|
|
CurrentFnArguments.resize(ArgNo * 2);
|
2011-03-01 22:58:55 +00:00
|
|
|
CurrentFnArguments[ArgNo - 1] = Var;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Collect variable information from side table maintained by MMI.
|
2010-07-21 21:21:52 +00:00
|
|
|
void
|
2011-07-29 03:49:23 +00:00
|
|
|
DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction *MF,
|
2010-05-20 19:57:06 +00:00
|
|
|
SmallPtrSet<const MDNode *, 16> &Processed) {
|
2009-10-06 01:26:37 +00:00
|
|
|
MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
|
|
|
|
for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
|
|
|
|
VE = VMap.end(); VI != VE; ++VI) {
|
2010-05-07 20:54:48 +00:00
|
|
|
const MDNode *Var = VI->first;
|
2009-11-10 23:06:00 +00:00
|
|
|
if (!Var) continue;
|
2010-05-14 21:01:35 +00:00
|
|
|
Processed.insert(Var);
|
2010-04-02 19:42:39 +00:00
|
|
|
DIVariable DV(Var);
|
|
|
|
const std::pair<unsigned, DebugLoc> &VP = VI->second;
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
LexicalScope *Scope = LScopes.findLexicalScope(VP.second);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2009-11-10 23:20:04 +00:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-04-02 19:42:39 +00:00
|
|
|
if (Scope == 0)
|
2009-11-10 23:20:04 +00:00
|
|
|
continue;
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2010-05-20 16:36:41 +00:00
|
|
|
DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
|
2011-08-15 19:01:20 +00:00
|
|
|
DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable);
|
2011-08-15 21:24:36 +00:00
|
|
|
RegVar->setFrameIndex(VP.first);
|
2011-03-01 22:58:55 +00:00
|
|
|
if (!addCurrentFnArgument(MF, RegVar, Scope))
|
2011-08-10 20:55:27 +00:00
|
|
|
addScopeVariable(Scope, RegVar);
|
2011-08-15 19:01:20 +00:00
|
|
|
if (AbsDbgVariable)
|
2011-08-15 21:24:36 +00:00
|
|
|
AbsDbgVariable->setFrameIndex(VP.first);
|
2009-10-06 01:26:37 +00:00
|
|
|
}
|
2010-05-20 19:57:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Return true if debug value, encoded by DBG_VALUE instruction, is in a
|
|
|
|
// defined reg.
|
2010-05-25 23:40:22 +00:00
|
|
|
static bool isDbgValueInDefinedReg(const MachineInstr *MI) {
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!");
|
2011-03-22 22:33:08 +00:00
|
|
|
return MI->getNumOperands() == 3 &&
|
|
|
|
MI->getOperand(0).isReg() && MI->getOperand(0).getReg() &&
|
|
|
|
MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0;
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Get .debug_loc entry for the instruction range starting at MI.
|
2012-11-19 22:42:10 +00:00
|
|
|
static DotDebugLocEntry getDebugLocEntry(AsmPrinter *Asm,
|
|
|
|
const MCSymbol *FLabel,
|
2011-07-08 17:09:57 +00:00
|
|
|
const MCSymbol *SLabel,
|
|
|
|
const MachineInstr *MI) {
|
|
|
|
const MDNode *Var = MI->getOperand(MI->getNumOperands() - 1).getMetadata();
|
|
|
|
|
|
|
|
if (MI->getNumOperands() != 3) {
|
|
|
|
MachineLocation MLoc = Asm->getDebugValueLocation(MI);
|
|
|
|
return DotDebugLocEntry(FLabel, SLabel, MLoc, Var);
|
|
|
|
}
|
|
|
|
if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) {
|
|
|
|
MachineLocation MLoc;
|
|
|
|
MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
|
|
|
|
return DotDebugLocEntry(FLabel, SLabel, MLoc, Var);
|
|
|
|
}
|
|
|
|
if (MI->getOperand(0).isImm())
|
|
|
|
return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getImm());
|
|
|
|
if (MI->getOperand(0).isFPImm())
|
|
|
|
return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getFPImm());
|
|
|
|
if (MI->getOperand(0).isCImm())
|
|
|
|
return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getCImm());
|
|
|
|
|
2012-02-05 08:31:47 +00:00
|
|
|
llvm_unreachable("Unexpected 3 operand DBG_VALUE instruction!");
|
2011-07-08 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Find variables for each lexical scope.
|
2010-07-21 21:21:52 +00:00
|
|
|
void
|
2010-06-25 22:07:34 +00:00
|
|
|
DwarfDebug::collectVariableInfo(const MachineFunction *MF,
|
|
|
|
SmallPtrSet<const MDNode *, 16> &Processed) {
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// collection info from MMI table.
|
2010-05-20 19:57:06 +00:00
|
|
|
collectVariableInfoFromMMITable(MF, Processed);
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
for (SmallVectorImpl<const MDNode*>::const_iterator
|
|
|
|
UVI = UserVariables.begin(), UVE = UserVariables.end(); UVI != UVE;
|
|
|
|
++UVI) {
|
|
|
|
const MDNode *Var = *UVI;
|
|
|
|
if (Processed.count(Var))
|
2010-05-20 19:57:06 +00:00
|
|
|
continue;
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// History contains relevant DBG_VALUE instructions for Var and instructions
|
|
|
|
// clobbering it.
|
|
|
|
SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var];
|
|
|
|
if (History.empty())
|
|
|
|
continue;
|
|
|
|
const MachineInstr *MInsn = History.front();
|
2010-05-25 23:40:22 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
DIVariable DV(Var);
|
2011-08-10 20:55:27 +00:00
|
|
|
LexicalScope *Scope = NULL;
|
2010-05-27 20:25:04 +00:00
|
|
|
if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
|
|
|
DISubprogram(DV.getContext()).describes(MF->getFunction()))
|
2011-08-10 20:55:27 +00:00
|
|
|
Scope = LScopes.getCurrentFunctionScope();
|
2013-03-11 23:39:23 +00:00
|
|
|
else if (MDNode *IA = DV.getInlinedAt())
|
|
|
|
Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
|
|
|
|
else
|
|
|
|
Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1)));
|
2010-05-20 19:57:06 +00:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-05-21 00:10:20 +00:00
|
|
|
if (!Scope)
|
2010-05-20 19:57:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Processed.insert(DV);
|
2011-03-26 02:19:36 +00:00
|
|
|
assert(MInsn->isDebugValue() && "History must begin with debug value");
|
2011-08-15 19:01:20 +00:00
|
|
|
DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
|
|
|
|
DbgVariable *RegVar = new DbgVariable(DV, AbsVar);
|
2011-03-01 22:58:55 +00:00
|
|
|
if (!addCurrentFnArgument(MF, RegVar, Scope))
|
2011-08-10 20:55:27 +00:00
|
|
|
addScopeVariable(Scope, RegVar);
|
2011-08-15 19:01:20 +00:00
|
|
|
if (AbsVar)
|
2011-08-15 21:24:36 +00:00
|
|
|
AbsVar->setMInsn(MInsn);
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2012-10-08 20:48:54 +00:00
|
|
|
// Simplify ranges that are fully coalesced.
|
2011-03-26 02:19:36 +00:00
|
|
|
if (History.size() <= 1 || (History.size() == 2 &&
|
|
|
|
MInsn->isIdenticalTo(History.back()))) {
|
2011-08-15 21:24:36 +00:00
|
|
|
RegVar->setMInsn(MInsn);
|
2010-05-25 23:40:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-28 17:33:26 +00:00
|
|
|
// Handle multiple DBG_VALUE instructions describing one variable.
|
2011-03-26 02:19:36 +00:00
|
|
|
RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
for (SmallVectorImpl<const MachineInstr*>::const_iterator
|
|
|
|
HI = History.begin(), HE = History.end(); HI != HE; ++HI) {
|
|
|
|
const MachineInstr *Begin = *HI;
|
|
|
|
assert(Begin->isDebugValue() && "Invalid History entry");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-06-01 23:00:17 +00:00
|
|
|
// Check if DBG_VALUE is truncating a range.
|
|
|
|
if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg()
|
|
|
|
&& !Begin->getOperand(0).getReg())
|
|
|
|
continue;
|
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
// Compute the range for a register location.
|
2010-05-26 17:29:32 +00:00
|
|
|
const MCSymbol *FLabel = getLabelBeforeInsn(Begin);
|
2011-03-22 22:33:08 +00:00
|
|
|
const MCSymbol *SLabel = 0;
|
2010-08-04 22:07:27 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
if (HI + 1 == HE)
|
|
|
|
// If Begin is the last instruction in History then its value is valid
|
2011-04-15 05:18:47 +00:00
|
|
|
// until the end of the function.
|
2011-03-22 22:33:08 +00:00
|
|
|
SLabel = FunctionEndSym;
|
2011-03-26 02:19:36 +00:00
|
|
|
else {
|
|
|
|
const MachineInstr *End = HI[1];
|
2012-11-19 22:42:10 +00:00
|
|
|
DEBUG(dbgs() << "DotDebugLoc Pair:\n"
|
2011-07-07 21:44:42 +00:00
|
|
|
<< "\t" << *Begin << "\t" << *End << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
if (End->isDebugValue())
|
|
|
|
SLabel = getLabelBeforeInsn(End);
|
|
|
|
else {
|
|
|
|
// End is a normal instruction clobbering the range.
|
|
|
|
SLabel = getLabelAfterInsn(End);
|
|
|
|
assert(SLabel && "Forgot label after clobber instruction");
|
|
|
|
++HI;
|
|
|
|
}
|
|
|
|
}
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// The value is valid until the next DBG_VALUE or clobber.
|
2011-12-16 23:42:31 +00:00
|
|
|
DotDebugLocEntries.push_back(getDebugLocEntry(Asm, FLabel, SLabel,
|
|
|
|
Begin));
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
|
|
|
DotDebugLocEntries.push_back(DotDebugLocEntry());
|
2010-03-15 18:33:46 +00:00
|
|
|
}
|
2010-05-14 21:01:35 +00:00
|
|
|
|
|
|
|
// Collect info for variables that were optimized out.
|
2011-08-19 23:28:12 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
|
|
|
DIArray Variables = DISubprogram(FnScope->getScopeNode()).getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
|
|
|
if (!DV || !DV.Verify() || !Processed.insert(DV))
|
|
|
|
continue;
|
|
|
|
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext()))
|
|
|
|
addScopeVariable(Scope, new DbgVariable(DV, NULL));
|
2010-05-14 21:01:35 +00:00
|
|
|
}
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Return Label preceding the instruction.
|
2013-01-15 23:56:56 +00:00
|
|
|
MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
|
2011-03-26 02:19:36 +00:00
|
|
|
MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
|
|
|
|
assert(Label && "Didn't insert label before instruction");
|
|
|
|
return Label;
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
2010-05-14 21:01:35 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Return Label immediately following the instruction.
|
2013-01-15 23:56:56 +00:00
|
|
|
MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
|
2011-03-26 02:19:36 +00:00
|
|
|
return LabelsAfterInsn.lookup(MI);
|
2009-10-06 01:26:37 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Process beginning of an instruction.
|
2010-10-26 17:49:02 +00:00
|
|
|
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
|
2011-03-25 17:20:59 +00:00
|
|
|
// Check if source location changes, but ignore DBG_VALUE locations.
|
|
|
|
if (!MI->isDebugValue()) {
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
|
|
|
if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) {
|
2012-04-05 20:39:05 +00:00
|
|
|
unsigned Flags = 0;
|
2011-03-25 17:20:59 +00:00
|
|
|
PrevInstLoc = DL;
|
2011-05-11 19:22:19 +00:00
|
|
|
if (DL == PrologEndLoc) {
|
|
|
|
Flags |= DWARF2_FLAG_PROLOGUE_END;
|
|
|
|
PrologEndLoc = DebugLoc();
|
|
|
|
}
|
2012-04-05 20:39:05 +00:00
|
|
|
if (PrologEndLoc.isUnknown())
|
|
|
|
Flags |= DWARF2_FLAG_IS_STMT;
|
|
|
|
|
2011-03-25 17:20:59 +00:00
|
|
|
if (!DL.isUnknown()) {
|
|
|
|
const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
|
2011-05-11 19:22:19 +00:00
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
|
2011-03-25 17:20:59 +00:00
|
|
|
} else
|
2011-05-11 19:22:19 +00:00
|
|
|
recordSourceLine(0, 0, 0, 0);
|
2011-03-25 17:20:59 +00:00
|
|
|
}
|
2010-05-26 19:37:24 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 17:20:59 +00:00
|
|
|
// Insert labels where requested.
|
2011-03-26 02:19:36 +00:00
|
|
|
DenseMap<const MachineInstr*, MCSymbol*>::iterator I =
|
|
|
|
LabelsBeforeInsn.find(MI);
|
|
|
|
|
|
|
|
// No label needed.
|
|
|
|
if (I == LabelsBeforeInsn.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Label already assigned.
|
|
|
|
if (I->second)
|
2010-03-29 17:20:31 +00:00
|
|
|
return;
|
2010-05-26 19:37:24 +00:00
|
|
|
|
2011-03-25 17:20:59 +00:00
|
|
|
if (!PrevLabel) {
|
2010-05-26 21:23:46 +00:00
|
|
|
PrevLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
Asm->OutStreamer.EmitLabel(PrevLabel);
|
2010-04-27 19:46:33 +00:00
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
I->second = PrevLabel;
|
2009-10-06 01:50:42 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Process end of an instruction.
|
2010-10-26 17:49:02 +00:00
|
|
|
void DwarfDebug::endInstruction(const MachineInstr *MI) {
|
2011-03-25 17:20:59 +00:00
|
|
|
// Don't create a new label after DBG_VALUE instructions.
|
|
|
|
// They don't generate code.
|
|
|
|
if (!MI->isDebugValue())
|
|
|
|
PrevLabel = 0;
|
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
DenseMap<const MachineInstr*, MCSymbol*>::iterator I =
|
|
|
|
LabelsAfterInsn.find(MI);
|
|
|
|
|
|
|
|
// No label needed.
|
|
|
|
if (I == LabelsAfterInsn.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Label already assigned.
|
|
|
|
if (I->second)
|
2011-03-25 17:20:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// We need a label after this instruction.
|
|
|
|
if (!PrevLabel) {
|
|
|
|
PrevLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
Asm->OutStreamer.EmitLabel(PrevLabel);
|
2010-04-08 16:50:29 +00:00
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
I->second = PrevLabel;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Each LexicalScope has first instruction and last instruction to mark
|
|
|
|
// beginning and end of a scope respectively. Create an inverse map that list
|
|
|
|
// scopes starts (and ends) with an instruction. One instruction may start (or
|
|
|
|
// end) multiple scopes. Ignore scopes that are not reachable.
|
2010-04-08 18:43:56 +00:00
|
|
|
void DwarfDebug::identifyScopeMarkers() {
|
2011-08-10 20:55:27 +00:00
|
|
|
SmallVector<LexicalScope *, 4> WorkList;
|
|
|
|
WorkList.push_back(LScopes.getCurrentFunctionScope());
|
2010-01-20 02:05:23 +00:00
|
|
|
while (!WorkList.empty()) {
|
2011-08-10 20:55:27 +00:00
|
|
|
LexicalScope *S = WorkList.pop_back_val();
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<LexicalScope *, 4> &Children = S->getChildren();
|
2010-07-21 21:21:52 +00:00
|
|
|
if (!Children.empty())
|
2011-08-10 20:55:27 +00:00
|
|
|
for (SmallVector<LexicalScope *, 4>::const_iterator SI = Children.begin(),
|
2010-01-20 02:05:23 +00:00
|
|
|
SE = Children.end(); SI != SE; ++SI)
|
|
|
|
WorkList.push_back(*SI);
|
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
if (S->isAbstractScope())
|
|
|
|
continue;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
const SmallVector<InsnRange, 4> &Ranges = S->getRanges();
|
2010-04-27 19:46:33 +00:00
|
|
|
if (Ranges.empty())
|
|
|
|
continue;
|
2011-08-10 20:55:27 +00:00
|
|
|
for (SmallVector<InsnRange, 4>::const_iterator RI = Ranges.begin(),
|
2010-04-27 19:46:33 +00:00
|
|
|
RE = Ranges.end(); RI != RE; ++RI) {
|
2011-08-10 20:55:27 +00:00
|
|
|
assert(RI->first && "InsnRange does not have first instruction!");
|
|
|
|
assert(RI->second && "InsnRange does not have second instruction!");
|
2011-03-26 02:19:36 +00:00
|
|
|
requestLabelBeforeInsn(RI->first);
|
|
|
|
requestLabelAfterInsn(RI->second);
|
2010-04-27 19:46:33 +00:00
|
|
|
}
|
2009-10-01 20:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Get MDNode for DebugLoc's scope.
|
2011-05-09 22:14:49 +00:00
|
|
|
static MDNode *getScopeNode(DebugLoc DL, const LLVMContext &Ctx) {
|
|
|
|
if (MDNode *InlinedAt = DL.getInlinedAt(Ctx))
|
|
|
|
return getScopeNode(DebugLoc::getFromDILocation(InlinedAt), Ctx);
|
|
|
|
return DL.getScope(Ctx);
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Walk up the scope chain of given debug loc and find line number info
|
|
|
|
// for the function.
|
2011-05-11 19:22:19 +00:00
|
|
|
static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) {
|
|
|
|
const MDNode *Scope = getScopeNode(DL, Ctx);
|
|
|
|
DISubprogram SP = getDISubprogram(Scope);
|
2012-04-03 00:43:49 +00:00
|
|
|
if (SP.Verify()) {
|
|
|
|
// Check for number of operands since the compatibility is
|
|
|
|
// cheap here.
|
2012-04-03 17:55:42 +00:00
|
|
|
if (SP->getNumOperands() > 19)
|
2012-04-03 00:43:49 +00:00
|
|
|
return DebugLoc::get(SP.getScopeLineNumber(), 0, SP);
|
|
|
|
else
|
|
|
|
return DebugLoc::get(SP.getLineNumber(), 0, SP);
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:22:19 +00:00
|
|
|
return DebugLoc();
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Gather pre-function debug information. Assumes being called immediately
|
|
|
|
// after the function entry point has been emitted.
|
2010-01-26 23:18:02 +00:00
|
|
|
void DwarfDebug::beginFunction(const MachineFunction *MF) {
|
2010-04-05 03:52:55 +00:00
|
|
|
if (!MMI->hasDebugInfo()) return;
|
2011-08-10 20:55:27 +00:00
|
|
|
LScopes.initialize(*MF);
|
|
|
|
if (LScopes.empty()) return;
|
|
|
|
identifyScopeMarkers();
|
2009-10-06 18:37:31 +00:00
|
|
|
|
2013-02-05 21:52:47 +00:00
|
|
|
// Set DwarfCompileUnitID in MCContext to the Compile Unit this function
|
|
|
|
// belongs to.
|
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
|
|
|
CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
|
|
|
assert(TheCU && "Unable to find compile unit!");
|
|
|
|
Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
|
|
|
|
|
2010-04-27 19:46:33 +00:00
|
|
|
FunctionBeginSym = Asm->GetTempSymbol("func_begin",
|
|
|
|
Asm->getFunctionNumber());
|
2009-05-20 23:21:38 +00:00
|
|
|
// Assumes in correct section after the entry point.
|
2010-04-27 19:46:33 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(FunctionBeginSym);
|
2009-05-20 23:21:38 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
|
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
|
2012-11-27 22:43:45 +00:00
|
|
|
// LiveUserVar - Map physreg numbers to the MDNode they contain.
|
2011-03-22 22:33:08 +00:00
|
|
|
std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs());
|
|
|
|
|
2010-05-26 19:37:24 +00:00
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
2011-03-26 02:19:36 +00:00
|
|
|
I != E; ++I) {
|
|
|
|
bool AtBlockEntry = true;
|
2010-05-26 19:37:24 +00:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MI = II;
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2010-05-26 19:37:24 +00:00
|
|
|
if (MI->isDebugValue()) {
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(MI->getNumOperands() > 1 && "Invalid machine instruction!");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// Keep track of user variables.
|
2011-03-22 22:33:08 +00:00
|
|
|
const MDNode *Var =
|
|
|
|
MI->getOperand(MI->getNumOperands() - 1).getMetadata();
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// Variable is in a register, we need to check for clobbers.
|
2011-03-22 22:33:08 +00:00
|
|
|
if (isDbgValueInDefinedReg(MI))
|
|
|
|
LiveUserVar[MI->getOperand(0).getReg()] = Var;
|
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// Check the history of this variable.
|
|
|
|
SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var];
|
|
|
|
if (History.empty()) {
|
|
|
|
UserVariables.push_back(Var);
|
|
|
|
// The first mention of a function argument gets the FunctionBeginSym
|
|
|
|
// label, so arguments are visible when breaking at function entry.
|
|
|
|
DIVariable DV(Var);
|
|
|
|
if (DV.Verify() && DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
|
|
|
DISubprogram(getDISubprogram(DV.getContext()))
|
|
|
|
.describes(MF->getFunction()))
|
|
|
|
LabelsBeforeInsn[MI] = FunctionBeginSym;
|
|
|
|
} else {
|
|
|
|
// We have seen this variable before. Try to coalesce DBG_VALUEs.
|
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
if (Prev->isDebugValue()) {
|
|
|
|
// Coalesce identical entries at the end of History.
|
|
|
|
if (History.size() >= 2 &&
|
2011-07-07 00:14:27 +00:00
|
|
|
Prev->isIdenticalTo(History[History.size() - 2])) {
|
2012-10-08 20:48:49 +00:00
|
|
|
DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
|
2012-11-19 22:42:10 +00:00
|
|
|
<< "\t" << *Prev
|
2011-07-07 00:14:27 +00:00
|
|
|
<< "\t" << *History[History.size() - 2] << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
History.pop_back();
|
2011-07-07 00:14:27 +00:00
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// Terminate old register assignments that don't reach MI;
|
|
|
|
MachineFunction::const_iterator PrevMBB = Prev->getParent();
|
|
|
|
if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) &&
|
|
|
|
isDbgValueInDefinedReg(Prev)) {
|
|
|
|
// Previous register assignment needs to terminate at the end of
|
|
|
|
// its basic block.
|
|
|
|
MachineBasicBlock::const_iterator LastMI =
|
|
|
|
PrevMBB->getLastNonDebugInstr();
|
2011-07-07 00:14:27 +00:00
|
|
|
if (LastMI == PrevMBB->end()) {
|
2011-03-26 02:19:36 +00:00
|
|
|
// Drop DBG_VALUE for empty range.
|
2012-10-08 20:48:49 +00:00
|
|
|
DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n"
|
2011-07-07 00:14:27 +00:00
|
|
|
<< "\t" << *Prev << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
History.pop_back();
|
2011-07-07 00:14:27 +00:00
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
else {
|
|
|
|
// Terminate after LastMI.
|
|
|
|
History.push_back(LastMI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
History.push_back(MI);
|
2010-05-26 19:37:24 +00:00
|
|
|
} else {
|
2011-03-26 02:19:36 +00:00
|
|
|
// Not a DBG_VALUE instruction.
|
|
|
|
if (!MI->isLabel())
|
|
|
|
AtBlockEntry = false;
|
|
|
|
|
2012-10-04 20:46:14 +00:00
|
|
|
// First known non-DBG_VALUE and non-frame setup location marks
|
|
|
|
// the beginning of the function body.
|
|
|
|
if (!MI->getFlag(MachineInstr::FrameSetup) &&
|
|
|
|
(PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown()))
|
2011-05-11 19:22:19 +00:00
|
|
|
PrologEndLoc = MI->getDebugLoc();
|
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
// Check if the instruction clobbers any registers with debug vars.
|
|
|
|
for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
|
|
|
|
MOE = MI->operands_end(); MOI != MOE; ++MOI) {
|
|
|
|
if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg())
|
|
|
|
continue;
|
2012-06-01 23:28:30 +00:00
|
|
|
for (MCRegAliasIterator AI(MOI->getReg(), TRI, true);
|
|
|
|
AI.isValid(); ++AI) {
|
|
|
|
unsigned Reg = *AI;
|
2011-03-22 22:33:08 +00:00
|
|
|
const MDNode *Var = LiveUserVar[Reg];
|
|
|
|
if (!Var)
|
|
|
|
continue;
|
|
|
|
// Reg is now clobbered.
|
|
|
|
LiveUserVar[Reg] = 0;
|
|
|
|
|
|
|
|
// Was MD last defined by a DBG_VALUE referring to Reg?
|
2011-03-26 02:19:36 +00:00
|
|
|
DbgValueHistoryMap::iterator HistI = DbgValues.find(Var);
|
|
|
|
if (HistI == DbgValues.end())
|
|
|
|
continue;
|
|
|
|
SmallVectorImpl<const MachineInstr*> &History = HistI->second;
|
|
|
|
if (History.empty())
|
2011-03-22 22:33:08 +00:00
|
|
|
continue;
|
2011-03-26 02:19:36 +00:00
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
// Sanity-check: Register assignments are terminated at the end of
|
|
|
|
// their block.
|
|
|
|
if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent())
|
2011-03-22 22:33:08 +00:00
|
|
|
continue;
|
2011-03-26 02:19:36 +00:00
|
|
|
// Is the variable still in Reg?
|
|
|
|
if (!isDbgValueInDefinedReg(Prev) ||
|
|
|
|
Prev->getOperand(0).getReg() != Reg)
|
|
|
|
continue;
|
|
|
|
// Var is clobbered. Make sure the next instruction gets a label.
|
|
|
|
History.push_back(MI);
|
2011-03-22 22:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 19:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
SmallVectorImpl<const MachineInstr*> &History = I->second;
|
|
|
|
if (History.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Make sure the final register assignments are terminated.
|
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) {
|
|
|
|
const MachineBasicBlock *PrevMBB = Prev->getParent();
|
2012-11-19 22:42:10 +00:00
|
|
|
MachineBasicBlock::const_iterator LastMI =
|
2011-08-10 23:58:09 +00:00
|
|
|
PrevMBB->getLastNonDebugInstr();
|
2011-03-26 02:19:36 +00:00
|
|
|
if (LastMI == PrevMBB->end())
|
|
|
|
// Drop DBG_VALUE for empty range.
|
|
|
|
History.pop_back();
|
|
|
|
else {
|
|
|
|
// Terminate after LastMI.
|
|
|
|
History.push_back(LastMI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Request labels for the full history.
|
|
|
|
for (unsigned i = 0, e = History.size(); i != e; ++i) {
|
|
|
|
const MachineInstr *MI = History[i];
|
|
|
|
if (MI->isDebugValue())
|
|
|
|
requestLabelBeforeInsn(MI);
|
|
|
|
else
|
|
|
|
requestLabelAfterInsn(MI);
|
|
|
|
}
|
|
|
|
}
|
2010-05-26 19:37:24 +00:00
|
|
|
|
2011-03-25 17:20:59 +00:00
|
|
|
PrevInstLoc = DebugLoc();
|
2010-05-26 19:37:24 +00:00
|
|
|
PrevLabel = FunctionBeginSym;
|
2011-05-11 19:22:19 +00:00
|
|
|
|
|
|
|
// Record beginning of function.
|
|
|
|
if (!PrologEndLoc.isUnknown()) {
|
|
|
|
DebugLoc FnStartDL = getFnDebugLoc(PrologEndLoc,
|
|
|
|
MF->getFunction()->getContext());
|
|
|
|
recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(),
|
|
|
|
FnStartDL.getScope(MF->getFunction()->getContext()),
|
2012-12-04 22:02:33 +00:00
|
|
|
// We'd like to list the prologue as "not statements" but GDB behaves
|
|
|
|
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
|
2012-12-04 21:05:36 +00:00
|
|
|
DWARF2_FLAG_IS_STMT);
|
2011-05-11 19:22:19 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
|
|
|
|
// SmallVector<DbgVariable *, 8> &Vars = ScopeVariables.lookup(LS);
|
|
|
|
ScopeVariables[LS].push_back(Var);
|
|
|
|
// Vars.push_back(Var);
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Gather and emit post-function debug information.
|
2010-01-26 23:18:02 +00:00
|
|
|
void DwarfDebug::endFunction(const MachineFunction *MF) {
|
2011-08-10 20:55:27 +00:00
|
|
|
if (!MMI->hasDebugInfo() || LScopes.empty()) return;
|
2010-05-22 00:04:14 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
// Define end label for subprogram.
|
|
|
|
FunctionEndSym = Asm->GetTempSymbol("func_end",
|
|
|
|
Asm->getFunctionNumber());
|
|
|
|
// Assumes in correct section after the entry point.
|
|
|
|
Asm->OutStreamer.EmitLabel(FunctionEndSym);
|
2013-02-05 21:52:47 +00:00
|
|
|
// Set DwarfCompileUnitID in MCContext to default value.
|
|
|
|
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
SmallPtrSet<const MDNode *, 16> ProcessedVars;
|
|
|
|
collectVariableInfo(MF, ProcessedVars);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-08-15 22:04:40 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
2011-08-16 22:09:43 +00:00
|
|
|
CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(TheCU && "Unable to find compile unit!");
|
2011-08-15 22:04:40 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
// Construct abstract scopes.
|
2011-08-12 18:10:19 +00:00
|
|
|
ArrayRef<LexicalScope *> AList = LScopes.getAbstractScopesList();
|
|
|
|
for (unsigned i = 0, e = AList.size(); i != e; ++i) {
|
|
|
|
LexicalScope *AScope = AList[i];
|
|
|
|
DISubprogram SP(AScope->getScopeNode());
|
2011-08-10 20:55:27 +00:00
|
|
|
if (SP.Verify()) {
|
|
|
|
// Collect info for variables that were optimized out.
|
2011-08-19 23:28:12 +00:00
|
|
|
DIArray Variables = SP.getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
|
|
|
if (!DV || !DV.Verify() || !ProcessedVars.insert(DV))
|
|
|
|
continue;
|
2012-07-06 08:45:08 +00:00
|
|
|
// Check that DbgVariable for DV wasn't created earlier, when
|
|
|
|
// findAbstractVariable() was called for inlined instance of DV.
|
|
|
|
LLVMContext &Ctx = DV->getContext();
|
|
|
|
DIVariable CleanDV = cleanseInlinedVariable(DV, Ctx);
|
|
|
|
if (AbstractVariables.lookup(CleanDV))
|
|
|
|
continue;
|
2011-08-19 23:28:12 +00:00
|
|
|
if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext()))
|
|
|
|
addScopeVariable(Scope, new DbgVariable(DV, NULL));
|
2010-06-25 22:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-12 18:10:19 +00:00
|
|
|
if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0)
|
2011-08-15 22:04:40 +00:00
|
|
|
constructScopeDIE(TheCU, AScope);
|
2011-08-10 20:55:27 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-08-15 22:04:40 +00:00
|
|
|
DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-12-02 22:16:29 +00:00
|
|
|
if (!MF->getTarget().Options.DisableFramePointerElim(*MF))
|
2012-08-24 01:14:27 +00:00
|
|
|
TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
|
2011-08-15 22:04:40 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(),
|
|
|
|
MMI->getFrameMoves()));
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Clear debug info
|
2011-08-10 20:55:27 +00:00
|
|
|
for (DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >::iterator
|
|
|
|
I = ScopeVariables.begin(), E = ScopeVariables.end(); I != E; ++I)
|
|
|
|
DeleteContainerPointers(I->second);
|
|
|
|
ScopeVariables.clear();
|
2011-04-22 18:09:57 +00:00
|
|
|
DeleteContainerPointers(CurrentFnArguments);
|
2011-03-26 02:19:36 +00:00
|
|
|
UserVariables.clear();
|
|
|
|
DbgValues.clear();
|
2010-03-12 17:45:06 +00:00
|
|
|
AbstractVariables.clear();
|
2010-04-27 19:46:33 +00:00
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.clear();
|
2010-04-16 23:33:45 +00:00
|
|
|
PrevLabel = NULL;
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Register a source line with debug info. Returns the unique label that was
|
|
|
|
// emitted and which provides correspondence to the source line list.
|
2011-05-11 19:22:19 +00:00
|
|
|
void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
|
|
|
|
unsigned Flags) {
|
2009-11-25 17:36:49 +00:00
|
|
|
StringRef Fn;
|
2011-03-24 20:30:50 +00:00
|
|
|
StringRef Dir;
|
2010-05-05 23:41:32 +00:00
|
|
|
unsigned Src = 1;
|
|
|
|
if (S) {
|
|
|
|
DIDescriptor Scope(S);
|
|
|
|
|
|
|
|
if (Scope.isCompileUnit()) {
|
|
|
|
DICompileUnit CU(S);
|
|
|
|
Fn = CU.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = CU.getDirectory();
|
2010-10-28 17:30:52 +00:00
|
|
|
} else if (Scope.isFile()) {
|
|
|
|
DIFile F(S);
|
|
|
|
Fn = F.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = F.getDirectory();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else if (Scope.isSubprogram()) {
|
|
|
|
DISubprogram SP(S);
|
|
|
|
Fn = SP.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = SP.getDirectory();
|
2011-10-11 22:59:11 +00:00
|
|
|
} else if (Scope.isLexicalBlockFile()) {
|
|
|
|
DILexicalBlockFile DBF(S);
|
|
|
|
Fn = DBF.getFilename();
|
|
|
|
Dir = DBF.getDirectory();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else if (Scope.isLexicalBlock()) {
|
|
|
|
DILexicalBlock DB(S);
|
|
|
|
Fn = DB.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = DB.getDirectory();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else
|
2012-02-05 08:31:47 +00:00
|
|
|
llvm_unreachable("Unexpected scope info");
|
2010-05-05 23:41:32 +00:00
|
|
|
|
2013-03-07 01:42:00 +00:00
|
|
|
Src = getOrCreateSourceID(Fn, Dir,
|
|
|
|
Asm->OutStreamer.getContext().getDwarfCompileUnitID());
|
2010-05-05 23:41:32 +00:00
|
|
|
}
|
2011-07-29 03:49:23 +00:00
|
|
|
Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, 0, Fn);
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 23:22:40 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Emit Methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Compute the size and offset of a DIE.
|
2009-11-22 19:20:36 +00:00
|
|
|
unsigned
|
2012-12-10 23:34:43 +00:00
|
|
|
DwarfUnits::computeSizeAndOffset(DIE *Die, unsigned Offset) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Get the children.
|
|
|
|
const std::vector<DIE *> &Children = Die->getChildren();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Record the abbreviation.
|
2009-11-21 02:48:08 +00:00
|
|
|
assignAbbrevNumber(Die->getAbbrev());
|
2009-05-20 23:21:38 +00:00
|
|
|
|
|
|
|
// Get the abbreviation for this DIE.
|
|
|
|
unsigned AbbrevNumber = Die->getAbbrevNumber();
|
2012-12-10 23:34:43 +00:00
|
|
|
const DIEAbbrev *Abbrev = Abbreviations->at(AbbrevNumber - 1);
|
2009-05-20 23:21:38 +00:00
|
|
|
|
|
|
|
// Set DIE offset
|
|
|
|
Die->setOffset(Offset);
|
|
|
|
|
|
|
|
// Start the size with the size of abbreviation code.
|
2009-08-22 20:48:53 +00:00
|
|
|
Offset += MCAsmInfo::getULEB128Size(AbbrevNumber);
|
2009-05-20 23:21:38 +00:00
|
|
|
|
2013-03-29 23:34:06 +00:00
|
|
|
const SmallVectorImpl<DIEValue*> &Values = Die->getValues();
|
|
|
|
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev->getData();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Size the DIE attribute values.
|
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
|
|
|
// Size attribute value.
|
2010-04-05 00:18:22 +00:00
|
|
|
Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Size the DIE children if any.
|
|
|
|
if (!Children.empty()) {
|
|
|
|
assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes &&
|
|
|
|
"Children flag not set");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
for (unsigned j = 0, M = Children.size(); j < M; ++j)
|
2012-11-20 22:14:13 +00:00
|
|
|
Offset = computeSizeAndOffset(Children[j], Offset);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// End of children marker.
|
|
|
|
Offset += sizeof(int8_t);
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
Die->setSize(Offset - Die->getOffset());
|
|
|
|
return Offset;
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Compute the size and offset of all the DIEs.
|
2012-12-10 23:34:43 +00:00
|
|
|
void DwarfUnits::computeSizeAndOffsets() {
|
2013-03-12 18:27:15 +00:00
|
|
|
// Offset from the beginning of debug info section.
|
|
|
|
unsigned AccuOffset = 0;
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(),
|
2012-12-10 23:34:43 +00:00
|
|
|
E = CUs.end(); I != E; ++I) {
|
2013-03-12 18:27:15 +00:00
|
|
|
(*I)->setDebugInfoOffset(AccuOffset);
|
2012-11-30 23:59:06 +00:00
|
|
|
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)
|
|
|
|
|
2013-03-12 18:27:15 +00:00
|
|
|
unsigned EndOffset = computeSizeAndOffset((*I)->getCUDie(), Offset);
|
|
|
|
AccuOffset += EndOffset;
|
2010-05-10 22:49:55 +00:00
|
|
|
}
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit initial Dwarf sections with a label at the start of each one.
|
2012-11-21 00:34:35 +00:00
|
|
|
void DwarfDebug::emitSectionLabels() {
|
2009-08-19 05:49:37 +00:00
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
2009-09-19 20:40:05 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Dwarf sections base addresses.
|
2010-07-21 21:21:52 +00:00
|
|
|
DwarfInfoSectionSym =
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
|
2010-07-21 21:21:52 +00:00
|
|
|
DwarfAbbrevSectionSym =
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
|
2012-12-19 22:02:53 +00:00
|
|
|
if (useSplitDwarf())
|
|
|
|
DwarfAbbrevDWOSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfAbbrevDWOSection(),
|
|
|
|
"section_abbrev_dwo");
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfARangesSection());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-04-04 22:59:04 +00:00
|
|
|
if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection())
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, MacroInfo);
|
2010-04-04 22:59:04 +00:00
|
|
|
|
2013-02-07 21:19:50 +00:00
|
|
|
DwarfLineSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfLocSection());
|
2013-02-12 18:00:14 +00:00
|
|
|
if (GenerateDwarfPubNamesSection)
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
|
2012-11-21 00:34:35 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
|
2010-07-21 21:21:52 +00:00
|
|
|
DwarfStrSectionSym =
|
2012-12-27 02:14:01 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfStrSection(), "info_string");
|
2013-04-07 03:43:09 +00:00
|
|
|
if (useSplitDwarf()) {
|
2012-12-27 02:14:01 +00:00
|
|
|
DwarfStrDWOSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfStrDWOSection(), "skel_string");
|
2013-04-07 03:43:09 +00:00
|
|
|
DwarfAddrSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfAddrSection(), "addr_sec");
|
|
|
|
}
|
2012-11-21 00:34:35 +00:00
|
|
|
DwarfDebugRangeSectionSym = emitSectionSym(Asm, TLOF.getDwarfRangesSection(),
|
2010-04-16 23:33:45 +00:00
|
|
|
"debug_range");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-21 00:34:35 +00:00
|
|
|
DwarfDebugLocSectionSym = emitSectionSym(Asm, TLOF.getDwarfLocSection(),
|
2010-05-25 23:40:22 +00:00
|
|
|
"section_debug_loc");
|
|
|
|
|
2012-11-21 00:34:35 +00:00
|
|
|
TextSectionSym = emitSectionSym(Asm, TLOF.getTextSection(), "text_begin");
|
|
|
|
emitSectionSym(Asm, TLOF.getDataSection());
|
2009-05-20 23:04:56 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Recursively emits a debug information entry.
|
2012-12-19 22:02:53 +00:00
|
|
|
void DwarfDebug::emitDIE(DIE *Die, std::vector<DIEAbbrev *> *Abbrevs) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Get the abbreviation for this DIE.
|
|
|
|
unsigned AbbrevNumber = Die->getAbbrevNumber();
|
2012-12-19 22:02:53 +00:00
|
|
|
const DIEAbbrev *Abbrev = Abbrevs->at(AbbrevNumber - 1);
|
2009-05-20 23:04:56 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the code (index) for the abbreviation.
|
2010-04-04 18:52:31 +00:00
|
|
|
if (Asm->isVerbose())
|
2010-01-22 23:18:42 +00:00
|
|
|
Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" +
|
|
|
|
Twine::utohexstr(Die->getOffset()) + ":0x" +
|
|
|
|
Twine::utohexstr(Die->getSize()) + " " +
|
|
|
|
dwarf::TagString(Abbrev->getTag()));
|
2010-04-04 19:09:29 +00:00
|
|
|
Asm->EmitULEB128(AbbrevNumber);
|
2009-05-20 23:04:56 +00:00
|
|
|
|
2013-03-29 23:34:06 +00:00
|
|
|
const SmallVectorImpl<DIEValue*> &Values = Die->getValues();
|
|
|
|
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev->getData();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the DIE attribute values.
|
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i) {
|
|
|
|
unsigned Attr = AbbrevData[i].getAttribute();
|
|
|
|
unsigned Form = AbbrevData[i].getForm();
|
|
|
|
assert(Form && "Too many attributes for DIE (check abbreviation)");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-04 18:52:31 +00:00
|
|
|
if (Asm->isVerbose())
|
2010-01-24 18:54:17 +00:00
|
|
|
Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
switch (Attr) {
|
|
|
|
case dwarf::DW_AT_abstract_origin: {
|
|
|
|
DIEEntry *E = cast<DIEEntry>(Values[i]);
|
|
|
|
DIE *Origin = E->getEntry();
|
2009-11-10 23:06:00 +00:00
|
|
|
unsigned Addr = Origin->getOffset();
|
2013-03-12 18:27:15 +00:00
|
|
|
if (Form == dwarf::DW_FORM_ref_addr) {
|
|
|
|
// For DW_FORM_ref_addr, output the offset from beginning of debug info
|
|
|
|
// section. Origin->getOffset() returns the offset from start of the
|
|
|
|
// compile unit.
|
|
|
|
DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
|
|
|
Addr += Holder.getCUOffset(Origin->getCompileUnit());
|
|
|
|
}
|
2013-04-04 23:13:11 +00:00
|
|
|
Asm->EmitInt32(Addr);
|
2009-05-20 23:21:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-16 23:33:45 +00:00
|
|
|
case dwarf::DW_AT_ranges: {
|
|
|
|
// DW_AT_range Value encodes offset in debug_range section.
|
|
|
|
DIEInteger *V = cast<DIEInteger>(Values[i]);
|
2010-09-02 16:43:44 +00:00
|
|
|
|
2012-06-22 01:25:12 +00:00
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) {
|
2010-09-02 16:43:44 +00:00
|
|
|
Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym,
|
|
|
|
V->getValue(),
|
|
|
|
4);
|
|
|
|
} else {
|
|
|
|
Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym,
|
|
|
|
V->getValue(),
|
|
|
|
DwarfDebugRangeSectionSym,
|
|
|
|
4);
|
|
|
|
}
|
2010-04-16 23:33:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-25 23:40:22 +00:00
|
|
|
case dwarf::DW_AT_location: {
|
2012-06-22 01:25:12 +00:00
|
|
|
if (DIELabel *L = dyn_cast<DIELabel>(Values[i])) {
|
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
|
|
|
Asm->EmitLabelReference(L->getValue(), 4);
|
|
|
|
else
|
|
|
|
Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4);
|
|
|
|
} else {
|
2010-05-25 23:40:22 +00:00
|
|
|
Values[i]->EmitValue(Asm, Form);
|
2012-06-22 01:25:12 +00:00
|
|
|
}
|
2010-05-25 23:40:22 +00:00
|
|
|
break;
|
2010-09-29 19:08:08 +00:00
|
|
|
}
|
|
|
|
case dwarf::DW_AT_accessibility: {
|
|
|
|
if (Asm->isVerbose()) {
|
|
|
|
DIEInteger *V = cast<DIEInteger>(Values[i]);
|
|
|
|
Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue()));
|
|
|
|
}
|
|
|
|
Values[i]->EmitValue(Asm, Form);
|
|
|
|
break;
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
default:
|
|
|
|
// Emit an attribute using the defined form.
|
2010-04-05 00:13:49 +00:00
|
|
|
Values[i]->EmitValue(Asm, Form);
|
2009-05-20 23:21:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the DIE children if any.
|
|
|
|
if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) {
|
|
|
|
const std::vector<DIE *> &Children = Die->getChildren();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
for (unsigned j = 0, M = Children.size(); j < M; ++j)
|
2012-12-19 22:02:53 +00:00
|
|
|
emitDIE(Children[j], Abbrevs);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-04 18:52:31 +00:00
|
|
|
if (Asm->isVerbose())
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("End Of Children Mark");
|
|
|
|
Asm->EmitInt8(0);
|
2009-05-20 23:19:06 +00:00
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-12-15 00:04:07 +00:00
|
|
|
// Emit the various dwarf units to the unit section USection with
|
|
|
|
// the abbreviations going into ASection.
|
|
|
|
void DwarfUnits::emitUnits(DwarfDebug *DD,
|
|
|
|
const MCSection *USection,
|
|
|
|
const MCSection *ASection,
|
|
|
|
const MCSymbol *ASectionSym) {
|
|
|
|
Asm->OutStreamer.SwitchSection(USection);
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(),
|
2012-12-15 00:04:07 +00:00
|
|
|
E = CUs.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = *I;
|
2010-05-10 22:49:55 +00:00
|
|
|
DIE *Die = TheCU->getCUDie();
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
// Emit the compile units header.
|
2012-12-15 00:04:07 +00:00
|
|
|
Asm->OutStreamer
|
|
|
|
.EmitLabel(Asm->GetTempSymbol(USection->getLabelBeginName(),
|
|
|
|
TheCU->getUniqueID()));
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
// Emit size of content not including length itself
|
|
|
|
unsigned ContentSize = Die->getSize() +
|
|
|
|
sizeof(int16_t) + // DWARF version number
|
|
|
|
sizeof(int32_t) + // Offset Into Abbrev. Section
|
2011-04-13 19:41:17 +00:00
|
|
|
sizeof(int8_t); // Pointer Size (in bytes)
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
|
|
|
|
Asm->EmitInt32(ContentSize);
|
|
|
|
Asm->OutStreamer.AddComment("DWARF version number");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
|
2012-12-15 00:04:07 +00:00
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol(ASection->getLabelBeginName()),
|
|
|
|
ASectionSym);
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2012-12-19 22:02:53 +00:00
|
|
|
DD->emitDIE(Die, Abbreviations);
|
2012-12-15 00:04:07 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol(USection->getLabelEndName(),
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()));
|
2010-05-10 22:49:55 +00:00
|
|
|
}
|
2009-05-20 23:04:56 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-03-12 18:27:15 +00:00
|
|
|
/// For a given compile unit DIE, returns offset from beginning of debug info.
|
|
|
|
unsigned DwarfUnits::getCUOffset(DIE *Die) {
|
2013-03-13 18:41:27 +00:00
|
|
|
assert(Die->getTag() == dwarf::DW_TAG_compile_unit &&
|
|
|
|
"Input DIE should be compile unit in getCUOffset.");
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(),
|
2013-03-12 18:27:15 +00:00
|
|
|
E = CUs.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = *I;
|
|
|
|
if (TheCU->getCUDie() == Die)
|
|
|
|
return TheCU->getDebugInfoOffset();
|
|
|
|
}
|
2013-03-13 18:41:27 +00:00
|
|
|
llvm_unreachable("The compile unit DIE should belong to CUs in DwarfUnits.");
|
2013-03-12 18:27:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
// Emit the debug info section.
|
|
|
|
void DwarfDebug::emitDebugInfo() {
|
2012-12-15 00:04:07 +00:00
|
|
|
DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
|
|
|
|
|
|
|
Holder.emitUnits(this, Asm->getObjFileLowering().getDwarfInfoSection(),
|
|
|
|
Asm->getObjFileLowering().getDwarfAbbrevSection(),
|
|
|
|
DwarfAbbrevSectionSym);
|
2012-11-30 23:59:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit the abbreviation section.
|
2012-11-20 23:30:11 +00:00
|
|
|
void DwarfDebug::emitAbbreviations() {
|
2012-12-19 22:02:53 +00:00
|
|
|
if (!useSplitDwarf())
|
|
|
|
emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection(),
|
|
|
|
&Abbreviations);
|
|
|
|
else
|
|
|
|
emitSkeletonAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitAbbrevs(const MCSection *Section,
|
|
|
|
std::vector<DIEAbbrev *> *Abbrevs) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Check to see if it is worth the effort.
|
2012-12-19 22:02:53 +00:00
|
|
|
if (!Abbrevs->empty()) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Start the debug abbrev section.
|
2012-12-19 22:02:53 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(Section);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-12-19 22:02:53 +00:00
|
|
|
MCSymbol *Begin = Asm->GetTempSymbol(Section->getLabelBeginName());
|
2012-12-13 03:00:38 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Begin);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// For each abbrevation.
|
2012-12-19 22:02:53 +00:00
|
|
|
for (unsigned i = 0, N = Abbrevs->size(); i < N; ++i) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Get abbreviation data
|
2012-12-19 22:02:53 +00:00
|
|
|
const DIEAbbrev *Abbrev = Abbrevs->at(i);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the abbrevations code (base 1 index.)
|
2010-04-04 19:09:29 +00:00
|
|
|
Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the abbreviations data.
|
2010-04-05 00:13:49 +00:00
|
|
|
Abbrev->Emit(Asm);
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Mark end of abbreviations.
|
2010-04-04 19:09:29 +00:00
|
|
|
Asm->EmitULEB128(0, "EOM(3)");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-12-19 22:02:53 +00:00
|
|
|
MCSymbol *End = Asm->GetTempSymbol(Section->getLabelEndName());
|
2012-12-13 03:00:38 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(End);
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit the last address of the section and the end of the line matrix.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Define last address of section.
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("Extended Op");
|
|
|
|
Asm->EmitInt8(0);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("Op size");
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1);
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNE_set_address");
|
|
|
|
Asm->EmitInt8(dwarf::DW_LNE_set_address);
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Section end label");
|
2010-03-10 01:17:49 +00:00
|
|
|
|
2010-04-04 19:25:43 +00:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
|
2013-01-09 01:35:34 +00:00
|
|
|
Asm->getDataLayout().getPointerSize());
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Mark end of matrix.
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNE_end_sequence");
|
|
|
|
Asm->EmitInt8(0);
|
2010-01-22 22:09:00 +00:00
|
|
|
Asm->EmitInt8(1);
|
2010-01-22 23:18:42 +00:00
|
|
|
Asm->EmitInt8(1);
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit visible names into a hashed accelerator table section.
|
2011-11-07 09:24:32 +00:00
|
|
|
void DwarfDebug::emitAccelNames() {
|
|
|
|
DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset,
|
|
|
|
dwarf::DW_FORM_data4));
|
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
2011-11-10 19:25:34 +00:00
|
|
|
const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelNames();
|
|
|
|
for (StringMap<std::vector<DIE*> >::const_iterator
|
2011-11-07 09:24:32 +00:00
|
|
|
GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
2012-01-06 23:03:34 +00:00
|
|
|
const std::vector<DIE *> &Entities = GI->second;
|
2011-11-10 19:25:34 +00:00
|
|
|
for (std::vector<DIE *>::const_iterator DI = Entities.begin(),
|
|
|
|
DE = Entities.end(); DI != DE; ++DI)
|
|
|
|
AT.AddName(Name, (*DI));
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AT.FinalizeTable(Asm, "Names");
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelNamesSection());
|
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("names_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2012-12-20 21:58:36 +00:00
|
|
|
AT.Emit(Asm, SectionBegin, &InfoHolder);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 21:58:40 +00:00
|
|
|
// Emit objective C classes and categories into a hashed accelerator table
|
|
|
|
// section.
|
2011-11-07 09:24:32 +00:00
|
|
|
void DwarfDebug::emitAccelObjC() {
|
|
|
|
DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset,
|
|
|
|
dwarf::DW_FORM_data4));
|
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
|
|
|
const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelObjC();
|
|
|
|
for (StringMap<std::vector<DIE*> >::const_iterator
|
|
|
|
GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
2012-01-06 23:03:34 +00:00
|
|
|
const std::vector<DIE *> &Entities = GI->second;
|
2011-11-07 09:24:32 +00:00
|
|
|
for (std::vector<DIE *>::const_iterator DI = Entities.begin(),
|
|
|
|
DE = Entities.end(); DI != DE; ++DI)
|
|
|
|
AT.AddName(Name, (*DI));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AT.FinalizeTable(Asm, "ObjC");
|
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering()
|
|
|
|
.getDwarfAccelObjCSection());
|
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("objc_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2012-12-20 21:58:36 +00:00
|
|
|
AT.Emit(Asm, SectionBegin, &InfoHolder);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit namespace dies into a hashed accelerator table.
|
2011-11-07 09:24:32 +00:00
|
|
|
void DwarfDebug::emitAccelNamespaces() {
|
|
|
|
DwarfAccelTable AT(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset,
|
|
|
|
dwarf::DW_FORM_data4));
|
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
2011-11-10 21:47:55 +00:00
|
|
|
const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelNamespace();
|
|
|
|
for (StringMap<std::vector<DIE*> >::const_iterator
|
2011-11-07 09:24:32 +00:00
|
|
|
GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
2012-01-06 23:03:34 +00:00
|
|
|
const std::vector<DIE *> &Entities = GI->second;
|
2011-11-10 21:47:55 +00:00
|
|
|
for (std::vector<DIE *>::const_iterator DI = Entities.begin(),
|
|
|
|
DE = Entities.end(); DI != DE; ++DI)
|
|
|
|
AT.AddName(Name, (*DI));
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AT.FinalizeTable(Asm, "namespac");
|
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering()
|
|
|
|
.getDwarfAccelNamespaceSection());
|
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("namespac_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2012-12-20 21:58:36 +00:00
|
|
|
AT.Emit(Asm, SectionBegin, &InfoHolder);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit type dies into a hashed accelerator table.
|
2011-11-07 09:24:32 +00:00
|
|
|
void DwarfDebug::emitAccelTypes() {
|
2012-01-06 04:35:23 +00:00
|
|
|
std::vector<DwarfAccelTable::Atom> Atoms;
|
|
|
|
Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeDIEOffset,
|
|
|
|
dwarf::DW_FORM_data4));
|
|
|
|
Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeTag,
|
|
|
|
dwarf::DW_FORM_data2));
|
|
|
|
Atoms.push_back(DwarfAccelTable::Atom(DwarfAccelTable::eAtomTypeTypeFlags,
|
|
|
|
dwarf::DW_FORM_data1));
|
|
|
|
DwarfAccelTable AT(Atoms);
|
2011-11-07 09:24:32 +00:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
2012-01-06 04:35:23 +00:00
|
|
|
const StringMap<std::vector<std::pair<DIE*, unsigned > > > &Names
|
|
|
|
= TheCU->getAccelTypes();
|
|
|
|
for (StringMap<std::vector<std::pair<DIE*, unsigned> > >::const_iterator
|
2011-11-07 09:24:32 +00:00
|
|
|
GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
2012-01-06 23:03:34 +00:00
|
|
|
const std::vector<std::pair<DIE *, unsigned> > &Entities = GI->second;
|
2012-01-06 04:35:23 +00:00
|
|
|
for (std::vector<std::pair<DIE *, unsigned> >::const_iterator DI
|
|
|
|
= Entities.begin(), DE = Entities.end(); DI !=DE; ++DI)
|
|
|
|
AT.AddName(Name, (*DI).first, (*DI).second);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AT.FinalizeTable(Asm, "types");
|
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering()
|
|
|
|
.getDwarfAccelTypesSection());
|
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("types_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2012-12-20 21:58:36 +00:00
|
|
|
AT.Emit(Asm, SectionBegin, &InfoHolder);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 18:00:14 +00:00
|
|
|
/// emitDebugPubnames - Emit visible names into a debug pubnames section.
|
|
|
|
///
|
|
|
|
void DwarfDebug::emitDebugPubnames() {
|
|
|
|
const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
|
|
|
|
|
|
|
|
typedef DenseMap<const MDNode*, CompileUnit*> CUMapType;
|
|
|
|
for (CUMapType::iterator I = CUMap.begin(), E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
|
|
|
unsigned ID = TheCU->getUniqueID();
|
|
|
|
|
|
|
|
if (TheCU->getGlobalNames().empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Start the dwarf pubnames section.
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfPubNamesSection());
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Length of Public Names Info");
|
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("pubnames_end", ID),
|
|
|
|
Asm->GetTempSymbol("pubnames_begin", ID), 4);
|
|
|
|
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", ID));
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("DWARF Version");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
|
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(), ID),
|
|
|
|
DwarfInfoSectionSym);
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Compilation Unit Length");
|
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol(ISec->getLabelEndName(), ID),
|
|
|
|
Asm->GetTempSymbol(ISec->getLabelBeginName(), ID),
|
|
|
|
4);
|
|
|
|
|
|
|
|
const StringMap<DIE*> &Globals = TheCU->getGlobalNames();
|
|
|
|
for (StringMap<DIE*>::const_iterator
|
|
|
|
GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
|
|
|
const DIE *Entity = GI->second;
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("DIE offset");
|
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
|
|
|
|
|
|
|
if (Asm->isVerbose())
|
|
|
|
Asm->OutStreamer.AddComment("External Name");
|
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("End Mark");
|
|
|
|
Asm->EmitInt32(0);
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end", ID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 01:14:22 +00:00
|
|
|
void DwarfDebug::emitDebugPubTypes() {
|
2010-05-10 22:49:55 +00:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
2011-11-07 09:18:35 +00:00
|
|
|
// Start the dwarf pubtypes section.
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfPubTypesSection());
|
|
|
|
Asm->OutStreamer.AddComment("Length of Public Types Info");
|
|
|
|
Asm->EmitLabelDifference(
|
2012-12-03 18:45:45 +00:00
|
|
|
Asm->GetTempSymbol("pubtypes_end", TheCU->getUniqueID()),
|
|
|
|
Asm->GetTempSymbol("pubtypes_begin", TheCU->getUniqueID()), 4);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()));
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
|
2012-12-15 00:04:04 +00:00
|
|
|
const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
|
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(),
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()),
|
2010-05-10 22:49:55 +00:00
|
|
|
DwarfInfoSectionSym);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.AddComment("Compilation Unit Length");
|
2012-12-15 00:04:04 +00:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol(ISec->getLabelEndName(),
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()),
|
2012-12-15 00:04:04 +00:00
|
|
|
Asm->GetTempSymbol(ISec->getLabelBeginName(),
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()),
|
2010-05-10 22:49:55 +00:00
|
|
|
4);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
const StringMap<DIE*> &Globals = TheCU->getGlobalTypes();
|
|
|
|
for (StringMap<DIE*>::const_iterator
|
|
|
|
GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
2011-07-29 03:49:23 +00:00
|
|
|
DIE *Entity = GI->second;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
|
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
|
2011-11-09 18:16:11 +00:00
|
|
|
// Emit the name with a terminating null byte.
|
2013-01-09 01:57:54 +00:00
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1));
|
2010-05-10 22:49:55 +00:00
|
|
|
}
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.AddComment("End Mark");
|
2010-07-21 21:21:52 +00:00
|
|
|
Asm->EmitInt32(0);
|
2010-05-10 22:49:55 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
|
2012-12-03 18:45:45 +00:00
|
|
|
TheCU->getUniqueID()));
|
2009-11-24 01:14:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:14:01 +00:00
|
|
|
// Emit strings into a string section.
|
2013-01-07 19:32:41 +00:00
|
|
|
void DwarfUnits::emitStrings(const MCSection *StrSection,
|
|
|
|
const MCSection *OffsetSection = NULL,
|
|
|
|
const MCSymbol *StrSecSym = NULL) {
|
2012-12-27 02:14:01 +00:00
|
|
|
|
2013-01-08 22:22:06 +00:00
|
|
|
if (StringPool.empty()) return;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-03-09 23:38:23 +00:00
|
|
|
// Start the dwarf str section.
|
2013-01-07 19:32:41 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(StrSection);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-03-13 02:17:42 +00:00
|
|
|
// Get all of the string pool entries and put them in an array by their ID so
|
|
|
|
// we can sort them.
|
2010-07-21 21:21:52 +00:00
|
|
|
SmallVector<std::pair<unsigned,
|
2013-01-07 22:40:45 +00:00
|
|
|
StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-03-13 02:17:42 +00:00
|
|
|
for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator
|
2013-01-08 22:22:06 +00:00
|
|
|
I = StringPool.begin(), E = StringPool.end();
|
2012-12-20 21:58:40 +00:00
|
|
|
I != E; ++I)
|
2010-03-13 02:17:42 +00:00
|
|
|
Entries.push_back(std::make_pair(I->second.second, &*I));
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-03-13 02:17:42 +00:00
|
|
|
array_pod_sort(Entries.begin(), Entries.end());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2010-03-13 02:17:42 +00:00
|
|
|
for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
|
2010-03-09 23:38:23 +00:00
|
|
|
// Emit a label for reference from debug information entries.
|
2010-03-13 02:17:42 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first);
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2011-11-09 18:16:11 +00:00
|
|
|
// Emit the string itself with a terminating null byte.
|
2011-11-09 12:12:04 +00:00
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Entries[i].second->getKeyData(),
|
2013-01-09 01:35:34 +00:00
|
|
|
Entries[i].second->getKeyLength()+1));
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2013-01-07 19:32:41 +00:00
|
|
|
|
|
|
|
// If we've got an offset section go ahead and emit that now as well.
|
|
|
|
if (OffsetSection) {
|
|
|
|
Asm->OutStreamer.SwitchSection(OffsetSection);
|
|
|
|
unsigned offset = 0;
|
2013-01-15 23:56:56 +00:00
|
|
|
unsigned size = 4; // FIXME: DWARF64 is 8.
|
2013-01-07 19:32:41 +00:00
|
|
|
for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
|
2013-01-09 03:52:05 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(offset, size);
|
2013-01-07 19:32:41 +00:00
|
|
|
offset += Entries[i].second->getKeyLength() + 1;
|
|
|
|
}
|
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
// Emit strings into a string section.
|
|
|
|
void DwarfUnits::emitAddresses(const MCSection *AddrSection) {
|
|
|
|
|
|
|
|
if (AddressPool.empty()) return;
|
|
|
|
|
|
|
|
// Start the dwarf addr section.
|
|
|
|
Asm->OutStreamer.SwitchSection(AddrSection);
|
|
|
|
|
|
|
|
// Get all of the string pool entries and put them in an array by their ID so
|
|
|
|
// we can sort them.
|
|
|
|
SmallVector<std::pair<unsigned,
|
|
|
|
std::pair<MCSymbol*, unsigned>* >, 64> Entries;
|
|
|
|
|
|
|
|
for (DenseMap<MCSymbol*, std::pair<MCSymbol*, unsigned> >::iterator
|
|
|
|
I = AddressPool.begin(), E = AddressPool.end();
|
|
|
|
I != E; ++I)
|
|
|
|
Entries.push_back(std::make_pair(I->second.second, &(I->second)));
|
|
|
|
|
|
|
|
array_pod_sort(Entries.begin(), Entries.end());
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
|
|
|
|
// Emit a label for reference from debug information entries.
|
|
|
|
MCSymbol *Sym = Entries[i].second->first;
|
|
|
|
if (Sym)
|
|
|
|
Asm->EmitLabelReference(Entries[i].second->first,
|
|
|
|
Asm->getDataLayout().getPointerSize());
|
|
|
|
else
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Asm->getDataLayout().getPointerSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-27 02:14:01 +00:00
|
|
|
// Emit visible names into a debug str section.
|
|
|
|
void DwarfDebug::emitDebugStr() {
|
|
|
|
DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
|
|
|
Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection());
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit visible names into a debug loc section.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitDebugLoc() {
|
2010-05-26 23:55:23 +00:00
|
|
|
if (DotDebugLocEntries.empty())
|
|
|
|
return;
|
|
|
|
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<DotDebugLocEntry>::iterator
|
2011-02-04 22:57:18 +00:00
|
|
|
I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
DotDebugLocEntry &Entry = *I;
|
|
|
|
if (I + 1 != DotDebugLocEntries.end())
|
|
|
|
Entry.Merge(I+1);
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:16:39 +00:00
|
|
|
// Start the dwarf loc section.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2010-05-25 23:40:22 +00:00
|
|
|
Asm->getObjFileLowering().getDwarfLocSection());
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
unsigned char Size = Asm->getDataLayout().getPointerSize();
|
2010-05-26 23:55:23 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0));
|
|
|
|
unsigned index = 1;
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<DotDebugLocEntry>::iterator
|
2010-07-21 21:21:52 +00:00
|
|
|
I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end();
|
2010-07-07 20:12:52 +00:00
|
|
|
I != E; ++I, ++index) {
|
2011-02-04 22:57:18 +00:00
|
|
|
DotDebugLocEntry &Entry = *I;
|
|
|
|
if (Entry.isMerged()) continue;
|
2010-05-25 23:40:22 +00:00
|
|
|
if (Entry.isEmpty()) {
|
2013-01-09 01:35:34 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
2010-05-26 23:55:23 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index));
|
2010-05-25 23:40:22 +00:00
|
|
|
} else {
|
2013-01-09 03:52:05 +00:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size);
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.End, Size);
|
2011-04-28 02:22:40 +00:00
|
|
|
DIVariable DV(Entry.Variable);
|
2011-05-27 22:05:41 +00:00
|
|
|
Asm->OutStreamer.AddComment("Loc expr size");
|
|
|
|
MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol();
|
|
|
|
MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol();
|
|
|
|
Asm->EmitLabelDifference(end, begin, 2);
|
|
|
|
Asm->OutStreamer.EmitLabel(begin);
|
2011-07-08 16:49:43 +00:00
|
|
|
if (Entry.isInt()) {
|
2011-06-01 22:03:25 +00:00
|
|
|
DIBasicType BTy(DV.getType());
|
|
|
|
if (BTy.Verify() &&
|
2012-11-19 22:42:10 +00:00
|
|
|
(BTy.getEncoding() == dwarf::DW_ATE_signed
|
2011-06-01 22:03:25 +00:00
|
|
|
|| BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
|
|
|
|
Asm->OutStreamer.AddComment("DW_OP_consts");
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_consts);
|
2011-07-08 16:49:43 +00:00
|
|
|
Asm->EmitSLEB128(Entry.getInt());
|
2011-06-01 22:03:25 +00:00
|
|
|
} else {
|
|
|
|
Asm->OutStreamer.AddComment("DW_OP_constu");
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_constu);
|
2011-07-08 16:49:43 +00:00
|
|
|
Asm->EmitULEB128(Entry.getInt());
|
2011-06-01 22:03:25 +00:00
|
|
|
}
|
2011-07-08 16:49:43 +00:00
|
|
|
} else if (Entry.isLocation()) {
|
2012-11-19 22:42:10 +00:00
|
|
|
if (!DV.hasComplexAddress())
|
2011-07-08 16:49:43 +00:00
|
|
|
// Regular entry.
|
|
|
|
Asm->EmitDwarfRegOp(Entry.Loc);
|
|
|
|
else {
|
|
|
|
// Complex address entry.
|
|
|
|
unsigned N = DV.getNumAddrElements();
|
|
|
|
unsigned i = 0;
|
|
|
|
if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) {
|
|
|
|
if (Entry.Loc.getOffset()) {
|
|
|
|
i = 2;
|
|
|
|
Asm->EmitDwarfRegOp(Entry.Loc);
|
|
|
|
Asm->OutStreamer.AddComment("DW_OP_deref");
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_deref);
|
|
|
|
Asm->OutStreamer.AddComment("DW_OP_plus_uconst");
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_plus_uconst);
|
|
|
|
Asm->EmitSLEB128(DV.getAddrElement(1));
|
|
|
|
} else {
|
|
|
|
// If first address element is OpPlus then emit
|
|
|
|
// DW_OP_breg + Offset instead of DW_OP_reg + Offset.
|
|
|
|
MachineLocation Loc(Entry.Loc.getReg(), DV.getAddrElement(1));
|
|
|
|
Asm->EmitDwarfRegOp(Loc);
|
|
|
|
i = 2;
|
|
|
|
}
|
2011-05-24 00:22:25 +00:00
|
|
|
} else {
|
2011-07-08 16:49:43 +00:00
|
|
|
Asm->EmitDwarfRegOp(Entry.Loc);
|
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-07-08 16:49:43 +00:00
|
|
|
// Emit remaining complex address elements.
|
|
|
|
for (; i < N; ++i) {
|
|
|
|
uint64_t Element = DV.getAddrElement(i);
|
|
|
|
if (Element == DIBuilder::OpPlus) {
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_plus_uconst);
|
|
|
|
Asm->EmitULEB128(DV.getAddrElement(++i));
|
2012-05-08 18:56:00 +00:00
|
|
|
} else if (Element == DIBuilder::OpDeref) {
|
2012-05-08 21:24:39 +00:00
|
|
|
if (!Entry.Loc.isReg())
|
2012-05-08 18:56:00 +00:00
|
|
|
Asm->EmitInt8(dwarf::DW_OP_deref);
|
|
|
|
} else
|
|
|
|
llvm_unreachable("unknown Opcode found in complex address");
|
2011-05-24 00:22:25 +00:00
|
|
|
}
|
2011-04-28 02:22:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 16:49:43 +00:00
|
|
|
// else ... ignore constant fp. There is not any good way to
|
|
|
|
// to represent them here in dwarf.
|
2011-05-27 22:05:41 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(end);
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit visible names into a debug aranges section.
|
2012-11-21 00:34:35 +00:00
|
|
|
void DwarfDebug::emitDebugARanges() {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Start the dwarf aranges section.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfARangesSection());
|
2009-05-20 23:04:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit visible names into a debug ranges section.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitDebugRanges() {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Start the dwarf ranges section.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2010-04-16 23:33:45 +00:00
|
|
|
Asm->getObjFileLowering().getDwarfRangesSection());
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
unsigned char Size = Asm->getDataLayout().getPointerSize();
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<const MCSymbol *>::iterator
|
2010-07-21 21:21:52 +00:00
|
|
|
I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
|
2010-04-27 19:46:33 +00:00
|
|
|
I != E; ++I) {
|
|
|
|
if (*I)
|
2013-01-09 03:52:05 +00:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size);
|
2010-04-16 23:33:45 +00:00
|
|
|
else
|
2013-01-09 01:35:34 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
2010-04-16 23:33:45 +00:00
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit visible names into a debug macinfo section.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitDebugMacInfo() {
|
2009-09-19 20:40:05 +00:00
|
|
|
if (const MCSection *LineInfo =
|
2009-08-02 07:24:22 +00:00
|
|
|
Asm->getObjFileLowering().getDwarfMacroInfoSection()) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Start the dwarf macinfo section.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(LineInfo);
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Emit inline info using following format.
|
|
|
|
// Section Header:
|
|
|
|
// 1. length of section
|
|
|
|
// 2. Dwarf version number
|
|
|
|
// 3. address size.
|
|
|
|
//
|
|
|
|
// Entries (one "entry" for each function that was inlined):
|
|
|
|
//
|
|
|
|
// 1. offset into __debug_str section for MIPS linkage name, if exists;
|
|
|
|
// otherwise offset into __debug_str for regular function name.
|
|
|
|
// 2. offset into __debug_str section for regular function name.
|
|
|
|
// 3. an unsigned LEB128 number indicating the number of distinct inlining
|
|
|
|
// instances for the function.
|
|
|
|
//
|
|
|
|
// The rest of the entry consists of a {die_offset, low_pc} pair for each
|
|
|
|
// inlined instance; the die_offset points to the inlined_subroutine die in the
|
|
|
|
// __debug_info section, and the low_pc is the starting address for the
|
|
|
|
// inlining instance.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitDebugInlineInfo() {
|
2012-03-02 02:11:47 +00:00
|
|
|
if (!Asm->MAI->doesDwarfUseInlineInfoSection())
|
2009-05-20 23:21:38 +00:00
|
|
|
return;
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-05-10 22:49:55 +00:00
|
|
|
if (!FirstCU)
|
2009-05-20 23:21:38 +00:00
|
|
|
return;
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfDebugInlineSection());
|
2010-01-22 22:09:00 +00:00
|
|
|
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry");
|
2010-04-04 19:58:12 +00:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1),
|
|
|
|
Asm->GetTempSymbol("debug_inlined_begin", 1), 4);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-04 19:25:43 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1));
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("Dwarf Version");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-01 09:14:31 +00:00
|
|
|
Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<const MDNode *>::iterator I = InlinedSPNodes.begin(),
|
2009-11-10 23:06:00 +00:00
|
|
|
E = InlinedSPNodes.end(); I != E; ++I) {
|
2009-11-21 23:12:12 +00:00
|
|
|
|
2010-05-07 20:54:48 +00:00
|
|
|
const MDNode *Node = *I;
|
|
|
|
DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II
|
2009-11-22 19:20:36 +00:00
|
|
|
= InlineInfo.find(Node);
|
2013-03-29 23:34:06 +00:00
|
|
|
SmallVectorImpl<InlineInfoLabels> &Labels = II->second;
|
2009-08-28 23:24:31 +00:00
|
|
|
DISubprogram SP(Node);
|
2009-11-25 17:36:49 +00:00
|
|
|
StringRef LName = SP.getLinkageName();
|
|
|
|
StringRef Name = SP.getName();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("MIPS linkage name");
|
2012-03-02 01:57:52 +00:00
|
|
|
if (LName.empty())
|
2012-12-20 21:58:36 +00:00
|
|
|
Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name),
|
|
|
|
DwarfStrSectionSym);
|
2012-03-02 01:57:52 +00:00
|
|
|
else
|
2012-12-20 21:58:36 +00:00
|
|
|
Asm->EmitSectionOffset(InfoHolder
|
|
|
|
.getStringPoolEntry(getRealLinkageName(LName)),
|
2010-04-04 23:25:33 +00:00
|
|
|
DwarfStrSectionSym);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2010-03-09 23:52:58 +00:00
|
|
|
Asm->OutStreamer.AddComment("Function name");
|
2012-12-20 21:58:36 +00:00
|
|
|
Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name),
|
|
|
|
DwarfStrSectionSym);
|
2010-04-04 19:09:29 +00:00
|
|
|
Asm->EmitULEB128(Labels.size(), "Inline count");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-03-29 23:34:06 +00:00
|
|
|
for (SmallVectorImpl<InlineInfoLabels>::iterator LI = Labels.begin(),
|
2009-05-20 23:21:38 +00:00
|
|
|
LE = Labels.end(); LI != LE; ++LI) {
|
2010-04-04 18:52:31 +00:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
|
2010-03-09 00:31:02 +00:00
|
|
|
Asm->EmitInt32(LI->second->getOffset());
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2010-04-04 18:52:31 +00:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
|
2010-04-05 00:13:49 +00:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(LI->first,
|
2013-01-09 03:52:05 +00:00
|
|
|
Asm->getDataLayout().getPointerSize());
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-20 23:19:06 +00:00
|
|
|
|
2010-04-04 19:25:43 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1));
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2012-12-11 19:42:09 +00:00
|
|
|
// DWARF5 Experimental Separate Dwarf emitters.
|
2012-11-30 23:59:06 +00:00
|
|
|
|
|
|
|
// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
|
|
|
|
// DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
|
|
|
|
// DW_AT_ranges_base, DW_AT_addr_base. If DW_AT_ranges is present,
|
|
|
|
// DW_AT_low_pc and DW_AT_high_pc are not used, and vice versa.
|
2012-12-10 19:51:21 +00:00
|
|
|
CompileUnit *DwarfDebug::constructSkeletonCU(const MDNode *N) {
|
2012-11-30 23:59:06 +00:00
|
|
|
DICompileUnit DIUnit(N);
|
|
|
|
CompilationDir = DIUnit.getDirectory();
|
|
|
|
|
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
|
2012-12-03 18:45:45 +00:00
|
|
|
CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++,
|
2012-12-20 21:58:36 +00:00
|
|
|
DIUnit.getLanguage(), Die, Asm,
|
2012-12-27 02:14:01 +00:00
|
|
|
this, &SkeletonHolder);
|
2013-01-17 03:00:04 +00:00
|
|
|
|
2013-02-22 23:50:08 +00:00
|
|
|
NewCU->addLocalString(Die, dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
DIUnit.getSplitDebugFilename());
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2013-02-05 07:31:55 +00:00
|
|
|
// This should be a unique identifier when we want to build .dwp files.
|
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_GNU_dwo_id, dwarf::DW_FORM_data8, 0);
|
2013-01-17 02:59:59 +00:00
|
|
|
|
2013-04-22 07:51:08 +00:00
|
|
|
// Relocate to the beginning of the addr_base section, else 0 for the
|
|
|
|
// beginning of the one for this compile unit.
|
2013-04-07 03:43:09 +00:00
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
|
|
|
NewCU->addLabel(Die, dwarf::DW_AT_GNU_addr_base, dwarf::DW_FORM_sec_offset,
|
|
|
|
DwarfAddrSectionSym);
|
|
|
|
else
|
2013-04-22 07:51:08 +00:00
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_GNU_addr_base,
|
|
|
|
dwarf::DW_FORM_sec_offset, 0);
|
2012-11-30 23:59:06 +00:00
|
|
|
|
|
|
|
// 2.17.1 requires that we use DW_AT_low_pc for a single entry point
|
2013-01-15 23:56:56 +00:00
|
|
|
// into an entity. We're using 0, or a NULL label for this.
|
2012-11-30 23:59:06 +00:00
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
|
2013-01-15 23:56:56 +00:00
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
// DW_AT_stmt_list is a offset of line number information for this
|
|
|
|
// compile unit in debug_line section.
|
2013-04-07 03:43:09 +00:00
|
|
|
// FIXME: Should handle multiple compile units.
|
2012-11-30 23:59:06 +00:00
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
2013-01-17 03:00:04 +00:00
|
|
|
NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_sec_offset,
|
2013-02-07 21:19:50 +00:00
|
|
|
DwarfLineSectionSym);
|
2012-11-30 23:59:06 +00:00
|
|
|
else
|
2013-01-17 03:00:04 +00:00
|
|
|
NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_sec_offset, 0);
|
2012-11-30 23:59:06 +00:00
|
|
|
|
|
|
|
if (!CompilationDir.empty())
|
2013-01-07 19:32:41 +00:00
|
|
|
NewCU->addLocalString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2012-12-10 23:34:43 +00:00
|
|
|
SkeletonHolder.addUnit(NewCU);
|
2013-02-06 21:53:56 +00:00
|
|
|
SkeletonCUs.push_back(NewCU);
|
2012-12-10 23:34:43 +00:00
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
return NewCU;
|
|
|
|
}
|
|
|
|
|
2012-12-19 22:02:53 +00:00
|
|
|
void DwarfDebug::emitSkeletonAbbrevs(const MCSection *Section) {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf debug info?");
|
|
|
|
emitAbbrevs(Section, &SkeletonAbbrevs);
|
2012-11-30 23:59:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 19:42:09 +00:00
|
|
|
// Emit the .debug_info.dwo section for separated dwarf. This contains the
|
|
|
|
// compile units that would normally be in debug_info.
|
2012-11-30 23:59:06 +00:00
|
|
|
void DwarfDebug::emitDebugInfoDWO() {
|
2012-12-10 19:51:21 +00:00
|
|
|
assert(useSplitDwarf() && "No split dwarf debug info?");
|
2012-12-15 00:04:07 +00:00
|
|
|
InfoHolder.emitUnits(this, Asm->getObjFileLowering().getDwarfInfoDWOSection(),
|
2012-12-19 22:02:53 +00:00
|
|
|
Asm->getObjFileLowering().getDwarfAbbrevDWOSection(),
|
|
|
|
DwarfAbbrevDWOSectionSym);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the .debug_abbrev.dwo section for separated dwarf. This contains the
|
|
|
|
// abbreviations for the .debug_info.dwo section.
|
|
|
|
void DwarfDebug::emitDebugAbbrevDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2012-12-20 21:58:40 +00:00
|
|
|
emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection(),
|
|
|
|
&Abbreviations);
|
2012-11-30 23:59:06 +00:00
|
|
|
}
|
2012-12-27 02:14:01 +00:00
|
|
|
|
|
|
|
// Emit the .debug_str.dwo section for separated dwarf. This contains the
|
|
|
|
// string section and is identical in format to traditional .debug_str
|
|
|
|
// sections.
|
|
|
|
void DwarfDebug::emitDebugStrDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2013-01-07 22:40:45 +00:00
|
|
|
const MCSection *OffSec = Asm->getObjFileLowering()
|
|
|
|
.getDwarfStrOffDWOSection();
|
2013-01-07 19:32:41 +00:00
|
|
|
const MCSymbol *StrSym = DwarfStrSectionSym;
|
|
|
|
InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
|
|
|
|
OffSec, StrSym);
|
2012-12-27 02:14:01 +00:00
|
|
|
}
|