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
|
|
|
|
2014-03-07 22:40:37 +00:00
|
|
|
#include "ByteStreamer.h"
|
2009-05-15 09:23:25 +00:00
|
|
|
#include "DwarfDebug.h"
|
2010-04-05 05:24:55 +00:00
|
|
|
#include "DIE.h"
|
2013-08-08 23:45:55 +00:00
|
|
|
#include "DIEHash.h"
|
2013-12-02 19:33:15 +00:00
|
|
|
#include "DwarfUnit.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"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 00:22:06 +00:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-03-06 00:46:21 +00:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2014-03-04 11:17:44 +00:00
|
|
|
#include "llvm/IR/ValueHandle.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"
|
2013-08-21 06:13:34 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2009-10-13 06:47:08 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-22 22:09:00 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2014-02-22 14:00:39 +00:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2013-07-26 17:02:41 +00:00
|
|
|
#include "llvm/Support/MD5.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/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;
|
|
|
|
|
2014-04-22 02:02:50 +00:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2013-07-23 22:16:41 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
|
|
|
|
cl::desc("Disable debug info printing"));
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2013-07-23 22:16:41 +00:00
|
|
|
static cl::opt<bool> UnknownLocations(
|
|
|
|
"use-unknown-locations", cl::Hidden,
|
|
|
|
cl::desc("Make an absence of debug location information explicit."),
|
|
|
|
cl::init(false));
|
2010-05-07 01:08:53 +00:00
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenerateGnuPubSections("generate-gnu-dwarf-pub-sections", cl::Hidden,
|
|
|
|
cl::desc("Generate GNU-style pubnames and pubtypes"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2014-02-14 01:26:55 +00:00
|
|
|
static cl::opt<bool> GenerateARangeSection("generate-arange-section",
|
|
|
|
cl::Hidden,
|
|
|
|
cl::desc("Generate dwarf aranges"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2012-08-23 22:36:40 +00:00
|
|
|
namespace {
|
2014-01-27 23:50:03 +00:00
|
|
|
enum DefaultOnOff { Default, Enable, Disable };
|
2012-08-23 22:36:40 +00:00
|
|
|
}
|
2011-11-07 09:24:32 +00:00
|
|
|
|
2013-07-23 22:16:41 +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));
|
2012-08-23 22:36:40 +00:00
|
|
|
|
2013-07-23 22:16:41 +00:00
|
|
|
static cl::opt<DefaultOnOff>
|
|
|
|
SplitDwarf("split-dwarf", cl::Hidden,
|
2013-12-04 23:24:28 +00:00
|
|
|
cl::desc("Output DWARF5 split debug info."),
|
2013-07-23 22:16:41 +00:00
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
|
|
|
cl::init(Default));
|
2012-11-12 22:22:20 +00:00
|
|
|
|
2013-08-19 21:07:38 +00:00
|
|
|
static cl::opt<DefaultOnOff>
|
2013-08-26 23:24:35 +00:00
|
|
|
DwarfPubSections("generate-dwarf-pub-sections", cl::Hidden,
|
|
|
|
cl::desc("Generate DWARF pubnames and pubtypes sections"),
|
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
|
|
|
cl::init(Default));
|
2013-08-19 21:07:38 +00:00
|
|
|
|
2013-08-24 12:54:27 +00:00
|
|
|
static const char *const DWARFGroupName = "DWARF Emission";
|
|
|
|
static const char *const DbgTimerName = "DWARF Debug Writer";
|
2010-04-07 09:28:04 +00:00
|
|
|
|
2009-05-15 09:23:25 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-10-08 19:07:44 +00:00
|
|
|
/// resolve - Look in the DwarfDebug map for the MDNode that
|
|
|
|
/// corresponds to the reference.
|
2013-11-19 09:04:36 +00:00
|
|
|
template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const {
|
2013-10-08 19:07:44 +00:00
|
|
|
return DD->resolve(Ref);
|
|
|
|
}
|
|
|
|
|
2014-03-18 02:34:58 +00:00
|
|
|
bool DbgVariable::isBlockByrefVariable() const {
|
|
|
|
assert(Var.isVariable() && "Invalid complex DbgVariable!");
|
|
|
|
return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
|
|
|
|
}
|
|
|
|
|
2011-07-29 03:49:23 +00:00
|
|
|
DIType DbgVariable::getType() const {
|
2014-03-18 02:34:58 +00:00
|
|
|
DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap());
|
2011-04-12 22:53:02 +00:00
|
|
|
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
|
|
|
|
// addresses instead.
|
2014-03-18 02:34:58 +00:00
|
|
|
if (Var.isBlockByrefVariable(DD->getTypeIdentifierMap())) {
|
2011-04-12 22:53:02 +00:00
|
|
|
/* 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;
|
2013-08-08 01:41:00 +00:00
|
|
|
uint16_t tag = Ty.getTag();
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2013-09-04 19:53:21 +00:00
|
|
|
if (tag == dwarf::DW_TAG_pointer_type)
|
2013-10-08 19:07:44 +00:00
|
|
|
subType = resolve(DIDerivedType(Ty).getTypeDerivedFrom());
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2013-09-04 19:53:21 +00:00
|
|
|
DIArray Elements = DICompositeType(subType).getTypeArray();
|
2011-04-12 22:53:02 +00:00
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
2013-11-18 23:57:26 +00:00
|
|
|
DIDerivedType DT(Elements.getElement(i));
|
2011-04-12 22:53:02 +00:00
|
|
|
if (getName() == DT.getName())
|
2013-10-08 19:07:44 +00:00
|
|
|
return (resolve(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
|
|
|
|
2014-04-24 01:23:49 +00:00
|
|
|
static LLVM_CONSTEXPR DwarfAccelTable::Atom TypeAtoms[] = {
|
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4),
|
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_tag, dwarf::DW_FORM_data2),
|
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
|
|
|
|
|
2010-04-05 05:11:15 +00:00
|
|
|
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
|
2014-04-24 06:44:33 +00:00
|
|
|
: Asm(A), MMI(Asm->MMI), FirstCU(nullptr), PrevLabel(nullptr),
|
|
|
|
GlobalRangeCount(0), InfoHolder(A, "info_string", DIEValueAllocator),
|
2014-01-28 00:49:26 +00:00
|
|
|
UsedNonDefaultText(false),
|
2014-04-23 23:37:35 +00:00
|
|
|
SkeletonHolder(A, "skel_string", DIEValueAllocator),
|
|
|
|
AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 00:53:32 +00:00
|
|
|
dwarf::DW_FORM_data4)),
|
|
|
|
AccelObjC(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 01:02:42 +00:00
|
|
|
dwarf::DW_FORM_data4)),
|
|
|
|
AccelNamespace(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 01:23:49 +00:00
|
|
|
dwarf::DW_FORM_data4)),
|
|
|
|
AccelTypes(TypeAtoms) {
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2014-04-24 06:44:33 +00:00
|
|
|
DwarfInfoSectionSym = DwarfAbbrevSectionSym = DwarfStrSectionSym = nullptr;
|
|
|
|
DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = nullptr;
|
|
|
|
DwarfLineSectionSym = nullptr;
|
|
|
|
DwarfAddrSectionSym = nullptr;
|
|
|
|
DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = nullptr;
|
|
|
|
FunctionBeginSym = FunctionEndSym = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
CurMI = nullptr;
|
2012-04-02 17:58:52 +00:00
|
|
|
|
2013-10-15 20:26:37 +00:00
|
|
|
// Turn on accelerator tables for Darwin by default, pubnames by
|
|
|
|
// default for non-Darwin, and handle split dwarf.
|
2013-04-27 01:07:52 +00:00
|
|
|
bool IsDarwin = Triple(A->getTargetTriple()).isOSDarwin();
|
2013-08-19 21:41:38 +00:00
|
|
|
|
|
|
|
if (DwarfAccelTables == Default)
|
|
|
|
HasDwarfAccelTables = IsDarwin;
|
|
|
|
else
|
2013-08-26 20:58:35 +00:00
|
|
|
HasDwarfAccelTables = DwarfAccelTables == Enable;
|
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
|
2013-08-19 21:41:38 +00:00
|
|
|
HasSplitDwarf = SplitDwarf == Enable;
|
|
|
|
|
2013-08-26 23:24:35 +00:00
|
|
|
if (DwarfPubSections == Default)
|
|
|
|
HasDwarfPubSections = !IsDarwin;
|
2013-08-19 21:41:38 +00:00
|
|
|
else
|
2013-08-26 23:24:35 +00:00
|
|
|
HasDwarfPubSections = DwarfPubSections == Enable;
|
2013-08-19 21:07:38 +00:00
|
|
|
|
2014-06-19 06:22:08 +00:00
|
|
|
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
|
2014-04-28 20:42:22 +00:00
|
|
|
DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
|
|
|
|
: MMI->getModule()->getDwarfVersion();
|
2013-07-02 23:40:10 +00:00
|
|
|
|
2014-06-19 15:39:33 +00:00
|
|
|
Asm->OutStreamer.getContext().setDwarfVersion(DwarfVersion);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-04-30 20:34:31 +00:00
|
|
|
// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
|
|
|
|
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,
|
2014-04-24 06:44:33 +00:00
|
|
|
const char *SymbolStem = nullptr) {
|
2011-11-07 09:18:38 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(Section);
|
2013-11-19 09:04:36 +00:00
|
|
|
if (!SymbolStem)
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2011-11-07 09:18:38 +00:00
|
|
|
|
|
|
|
MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
|
|
|
|
Asm->OutStreamer.EmitLabel(TmpSym);
|
|
|
|
return TmpSym;
|
|
|
|
}
|
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
static bool isObjCClass(StringRef Name) {
|
|
|
|
return Name.startswith("+") || Name.startswith("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasObjCCategory(StringRef Name) {
|
2013-11-19 09:04:36 +00:00
|
|
|
if (!isObjCClass(Name))
|
|
|
|
return false;
|
2011-11-10 19:25:34 +00:00
|
|
|
|
2013-08-24 12:15:54 +00:00
|
|
|
return Name.find(") ") != StringRef::npos;
|
2011-11-10 19:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(']'));
|
|
|
|
}
|
|
|
|
|
2013-10-03 22:07:08 +00:00
|
|
|
// Helper for sorting sections into a stable output order.
|
|
|
|
static bool SectionSort(const MCSection *A, const MCSection *B) {
|
2013-11-19 09:04:36 +00:00
|
|
|
std::string LA = (A ? A->getLabelBeginName() : "");
|
|
|
|
std::string LB = (B ? B->getLabelBeginName() : "");
|
|
|
|
return LA < LB;
|
2013-10-03 22:07:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
// Add the various names to the Dwarf accelerator table names.
|
2013-09-20 23:22:52 +00:00
|
|
|
// TODO: Determine whether or not we should add names for programs
|
|
|
|
// that do not have a DW_AT_name or DW_AT_linkage_name field - this
|
|
|
|
// is only slightly different than the lookup of non-standard ObjC names.
|
2014-04-25 18:52:29 +00:00
|
|
|
void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) {
|
2013-11-19 09:04:36 +00:00
|
|
|
if (!SP.isDefinition())
|
|
|
|
return;
|
2014-04-23 23:37:35 +00:00
|
|
|
addAccelName(SP.getName(), Die);
|
2011-11-10 19:25:34 +00:00
|
|
|
|
|
|
|
// 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())
|
2014-04-23 23:37:35 +00:00
|
|
|
addAccelName(SP.getLinkageName(), Die);
|
2011-11-10 19:25:34 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-04-24 00:53:32 +00:00
|
|
|
addAccelObjC(Class, Die);
|
2011-11-10 19:25:34 +00:00
|
|
|
if (Category != "")
|
2014-04-24 00:53:32 +00:00
|
|
|
addAccelObjC(Category, Die);
|
2011-11-10 19:25:34 +00:00
|
|
|
// Also add the base method name to the name table.
|
2014-04-23 23:37:35 +00:00
|
|
|
addAccelName(getObjCMethodName(SP.getName()), Die);
|
2011-11-10 19:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 19:05:21 +00:00
|
|
|
/// isSubprogramContext - Return true if Context is either a subprogram
|
|
|
|
/// or another context nested inside a subprogram.
|
|
|
|
bool DwarfDebug::isSubprogramContext(const MDNode *Context) {
|
|
|
|
if (!Context)
|
|
|
|
return false;
|
|
|
|
DIDescriptor D(Context);
|
|
|
|
if (D.isSubprogram())
|
|
|
|
return true;
|
|
|
|
if (D.isType())
|
2013-09-09 19:47:11 +00:00
|
|
|
return isSubprogramContext(resolve(DIType(Context).getContext()));
|
2013-09-09 19:05:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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.
|
2014-04-29 15:58:35 +00:00
|
|
|
DIE &DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU,
|
2013-12-09 23:57:44 +00:00
|
|
|
DISubprogram SP) {
|
2014-05-27 18:37:48 +00:00
|
|
|
DIE *SPDie = SPCU.getOrCreateSubprogramDIE(SP);
|
2010-07-07 22:20:57 +00:00
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
attachLowHighPC(SPCU, *SPDie, FunctionBeginSym, FunctionEndSym);
|
2013-12-03 00:45:45 +00:00
|
|
|
|
2010-04-05 00:13:49 +00:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
MachineLocation Location(RI->getFrameRegister(*Asm->MF));
|
2014-04-25 18:26:14 +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.
|
2014-04-25 18:52:29 +00:00
|
|
|
addSubprogramNames(SP, *SPDie);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2014-04-29 15:58:35 +00:00
|
|
|
return *SPDie;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 19:40:28 +00:00
|
|
|
/// Check whether we should create a DIE for the given Scope, return true
|
|
|
|
/// if we don't create a DIE (the corresponding DIE is null).
|
2013-09-10 18:40:41 +00:00
|
|
|
bool DwarfDebug::isLexicalScopeDIENull(LexicalScope *Scope) {
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return false;
|
|
|
|
|
2013-09-11 19:40:28 +00:00
|
|
|
// We don't create a DIE if there is no Range.
|
2013-09-10 18:40:41 +00:00
|
|
|
const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
|
|
|
|
if (Ranges.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ranges.size() > 1)
|
|
|
|
return false;
|
|
|
|
|
2013-09-11 19:40:28 +00:00
|
|
|
// We don't create a DIE if we have a single Range and the end label
|
|
|
|
// is null.
|
2013-09-10 18:40:41 +00:00
|
|
|
SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin();
|
|
|
|
MCSymbol *End = getLabelAfterInsn(RI->second);
|
|
|
|
return !End;
|
|
|
|
}
|
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
static void addSectionLabel(AsmPrinter &Asm, DwarfUnit &U, DIE &D,
|
2013-12-05 00:36:17 +00:00
|
|
|
dwarf::Attribute A, const MCSymbol *L,
|
|
|
|
const MCSymbol *Sec) {
|
2014-04-22 22:39:41 +00:00
|
|
|
if (Asm.MAI->doesDwarfUseRelocationsAcrossSections())
|
|
|
|
U.addSectionLabel(D, A, L);
|
2013-12-05 00:36:17 +00:00
|
|
|
else
|
2014-04-22 22:39:41 +00:00
|
|
|
U.addSectionDelta(D, A, L, Sec);
|
2013-12-05 00:36:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
void DwarfDebug::addScopeRangeList(DwarfCompileUnit &TheCU, DIE &ScopeDIE,
|
2013-12-03 00:45:59 +00:00
|
|
|
const SmallVectorImpl<InsnRange> &Range) {
|
|
|
|
// Emit offset in .debug_range as a relocatable label. emitDIE will handle
|
|
|
|
// emitting it appropriately.
|
2013-12-04 22:04:50 +00:00
|
|
|
MCSymbol *RangeSym = Asm->GetTempSymbol("debug_ranges", GlobalRangeCount++);
|
2014-03-24 21:07:27 +00:00
|
|
|
|
|
|
|
// Under fission, ranges are specified by constant offsets relative to the
|
|
|
|
// CU's DW_AT_GNU_ranges_base.
|
|
|
|
if (useSplitDwarf())
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
|
2014-04-22 23:09:36 +00:00
|
|
|
DwarfDebugRangeSectionSym);
|
2014-03-24 21:07:27 +00:00
|
|
|
else
|
2014-04-22 22:39:41 +00:00
|
|
|
addSectionLabel(*Asm, TheCU, ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
|
2014-03-24 21:07:27 +00:00
|
|
|
DwarfDebugRangeSectionSym);
|
2013-12-05 00:36:17 +00:00
|
|
|
|
2013-12-04 22:04:50 +00:00
|
|
|
RangeSpanList List(RangeSym);
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const InsnRange &R : Range) {
|
|
|
|
RangeSpan Span(getLabelBeforeInsn(R.first), getLabelAfterInsn(R.second));
|
2014-03-02 04:08:41 +00:00
|
|
|
List.addRange(std::move(Span));
|
2013-12-03 00:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the range list to the set of ranges to be emitted.
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addRangeList(std::move(List));
|
2013-12-03 00:45:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 16:42:40 +00:00
|
|
|
void DwarfDebug::attachRangesOrLowHighPC(DwarfCompileUnit &TheCU, DIE &Die,
|
|
|
|
const SmallVectorImpl<InsnRange> &Ranges) {
|
|
|
|
assert(!Ranges.empty());
|
|
|
|
if (Ranges.size() == 1)
|
|
|
|
attachLowHighPC(TheCU, Die, getLabelBeforeInsn(Ranges.front().first),
|
|
|
|
getLabelAfterInsn(Ranges.front().second));
|
|
|
|
else
|
|
|
|
addScopeRangeList(TheCU, Die, Ranges);
|
|
|
|
}
|
|
|
|
|
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.
|
2014-04-28 20:36:45 +00:00
|
|
|
std::unique_ptr<DIE>
|
|
|
|
DwarfDebug::constructLexicalScopeDIE(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope *Scope) {
|
2013-09-10 18:40:41 +00:00
|
|
|
if (isLexicalScopeDIENull(Scope))
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2013-09-10 18:40:41 +00:00
|
|
|
|
2014-04-28 20:36:45 +00:00
|
|
|
auto ScopeDIE = make_unique<DIE>(dwarf::DW_TAG_lexical_block);
|
2010-04-23 01:18:53 +00:00
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return ScopeDIE;
|
|
|
|
|
2014-05-16 16:42:40 +00:00
|
|
|
attachRangesOrLowHighPC(TheCU, *ScopeDIE, Scope->getRanges());
|
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.
|
2014-04-28 20:36:45 +00:00
|
|
|
std::unique_ptr<DIE>
|
|
|
|
DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope *Scope) {
|
2014-05-14 17:58:53 +00:00
|
|
|
assert(Scope->getScopeNode());
|
2011-07-27 00:34:13 +00:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
|
|
|
DISubprogram InlinedSP = getDISubprogram(DS);
|
2014-05-21 23:14:12 +00:00
|
|
|
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
|
|
|
|
// was inlined from another compile unit.
|
2014-05-27 18:37:51 +00:00
|
|
|
DIE *OriginDIE = AbstractSPDies[InlinedSP];
|
2014-05-21 23:14:12 +00:00
|
|
|
assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
|
2011-07-27 00:34:13 +00:00
|
|
|
|
2014-04-28 20:36:45 +00:00
|
|
|
auto ScopeDIE = make_unique<DIE>(dwarf::DW_TAG_inlined_subroutine);
|
2014-04-25 19:33:43 +00:00
|
|
|
TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2014-05-16 16:42:40 +00:00
|
|
|
attachRangesOrLowHighPC(TheCU, *ScopeDIE, Scope->getRanges());
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
InlinedSubprogramDIEs.insert(OriginDIE);
|
|
|
|
|
2013-07-03 02:23:53 +00:00
|
|
|
// Add the call site information to the DIE.
|
2009-11-10 23:06:00 +00:00
|
|
|
DILocation DL(Scope->getInlinedAt());
|
2014-04-25 18:26:14 +00:00
|
|
|
TheCU.addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None,
|
2014-04-22 23:09:36 +00:00
|
|
|
TheCU.getOrCreateSourceID(DL.getFilename(), DL.getDirectory()));
|
2014-04-25 18:26:14 +00:00
|
|
|
TheCU.addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, 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.
|
2014-04-25 18:52:29 +00:00
|
|
|
addSubprogramNames(InlinedSP, *ScopeDIE);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2014-04-30 22:41:33 +00:00
|
|
|
static std::unique_ptr<DIE> constructVariableDIE(DwarfCompileUnit &TheCU,
|
|
|
|
DbgVariable &DV,
|
|
|
|
const LexicalScope &Scope,
|
|
|
|
DIE *&ObjectPointer) {
|
2014-05-27 19:34:32 +00:00
|
|
|
auto Var = TheCU.constructVariableDIE(DV, Scope.isAbstractScope());
|
2014-04-30 22:41:33 +00:00
|
|
|
if (DV.isObjectPointer())
|
|
|
|
ObjectPointer = Var.get();
|
|
|
|
return Var;
|
|
|
|
}
|
|
|
|
|
2014-04-25 20:00:34 +00:00
|
|
|
DIE *DwarfDebug::createScopeChildrenDIE(
|
|
|
|
DwarfCompileUnit &TheCU, LexicalScope *Scope,
|
|
|
|
SmallVectorImpl<std::unique_ptr<DIE>> &Children) {
|
2014-04-24 06:44:33 +00:00
|
|
|
DIE *ObjectPointer = nullptr;
|
2011-03-01 22:58:55 +00:00
|
|
|
|
|
|
|
// Collect arguments for current function.
|
2014-02-25 19:57:42 +00:00
|
|
|
if (LScopes.isCurrentFunctionScope(Scope)) {
|
2014-04-22 05:41:06 +00:00
|
|
|
for (DbgVariable *ArgDV : CurrentFnArguments)
|
2014-04-30 22:41:33 +00:00
|
|
|
if (ArgDV)
|
2014-04-26 22:37:45 +00:00
|
|
|
Children.push_back(
|
2014-04-30 22:41:33 +00:00
|
|
|
constructVariableDIE(TheCU, *ArgDV, *Scope, ObjectPointer));
|
2011-03-01 22:58:55 +00:00
|
|
|
|
2014-02-25 22:27:14 +00:00
|
|
|
// If this is a variadic function, add an unspecified parameter.
|
2014-02-25 19:57:42 +00:00
|
|
|
DISubprogram SP(Scope->getScopeNode());
|
|
|
|
DIArray FnArgs = SP.getType().getTypeArray();
|
2014-02-26 02:50:56 +00:00
|
|
|
if (FnArgs.getElement(FnArgs.getNumElements() - 1)
|
|
|
|
.isUnspecifiedParameter()) {
|
2014-04-25 20:00:34 +00:00
|
|
|
Children.push_back(
|
|
|
|
make_unique<DIE>(dwarf::DW_TAG_unspecified_parameters));
|
2014-02-25 19:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 15:49:16 +00:00
|
|
|
// Collect lexical scope children first.
|
2014-04-30 22:41:33 +00:00
|
|
|
for (DbgVariable *DV : ScopeVariables.lookup(Scope))
|
|
|
|
Children.push_back(constructVariableDIE(TheCU, *DV, *Scope, ObjectPointer));
|
|
|
|
|
2014-03-07 19:09:39 +00:00
|
|
|
for (LexicalScope *LS : Scope->getChildren())
|
2014-04-28 20:36:45 +00:00
|
|
|
if (std::unique_ptr<DIE> Nested = constructScopeDIE(TheCU, LS))
|
|
|
|
Children.push_back(std::move(Nested));
|
2013-09-10 18:40:41 +00:00
|
|
|
return ObjectPointer;
|
|
|
|
}
|
|
|
|
|
2014-04-29 23:43:06 +00:00
|
|
|
void DwarfDebug::createAndAddScopeChildren(DwarfCompileUnit &TheCU,
|
2014-04-30 22:58:19 +00:00
|
|
|
LexicalScope *Scope, DIE &ScopeDIE) {
|
2014-04-29 15:58:35 +00:00
|
|
|
// We create children when the scope DIE is not null.
|
|
|
|
SmallVector<std::unique_ptr<DIE>, 8> Children;
|
|
|
|
if (DIE *ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children))
|
2014-04-30 22:58:19 +00:00
|
|
|
TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
|
2014-04-29 15:58:35 +00:00
|
|
|
|
|
|
|
// Add children
|
|
|
|
for (auto &I : Children)
|
|
|
|
ScopeDIE.addChild(std::move(I));
|
|
|
|
}
|
|
|
|
|
2014-04-29 23:43:06 +00:00
|
|
|
void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope *Scope) {
|
2014-04-28 20:27:02 +00:00
|
|
|
assert(Scope && Scope->getScopeNode());
|
2014-04-29 15:58:35 +00:00
|
|
|
assert(Scope->isAbstractScope());
|
|
|
|
assert(!Scope->getInlinedAt());
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-05-23 05:03:23 +00:00
|
|
|
DISubprogram SP(Scope->getScopeNode());
|
2014-04-29 15:58:35 +00:00
|
|
|
|
2014-05-27 18:37:55 +00:00
|
|
|
ProcessedSPNodes.insert(SP);
|
|
|
|
|
2014-05-27 18:37:48 +00:00
|
|
|
DIE *&AbsDef = AbstractSPDies[SP];
|
|
|
|
if (AbsDef)
|
2014-05-12 18:23:35 +00:00
|
|
|
return;
|
2014-04-29 15:58:35 +00:00
|
|
|
|
2014-05-21 23:14:12 +00:00
|
|
|
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
|
|
|
|
// was inlined from another compile unit.
|
2014-05-23 05:03:23 +00:00
|
|
|
DwarfCompileUnit &SPCU = *SPMap[SP];
|
2014-05-27 18:37:55 +00:00
|
|
|
DIE *ContextDIE;
|
|
|
|
|
|
|
|
// Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
|
|
|
|
// the important distinction that the DIDescriptor is not associated with the
|
|
|
|
// DIE (since the DIDescriptor will be associated with the concrete DIE, if
|
|
|
|
// any). It could be refactored to some common utility function.
|
|
|
|
if (DISubprogram SPDecl = SP.getFunctionDeclaration()) {
|
|
|
|
ContextDIE = &SPCU.getUnitDie();
|
|
|
|
SPCU.getOrCreateSubprogramDIE(SPDecl);
|
|
|
|
} else
|
|
|
|
ContextDIE = SPCU.getOrCreateContextDIE(resolve(SP.getContext()));
|
2014-05-27 18:37:48 +00:00
|
|
|
|
2014-05-27 18:37:55 +00:00
|
|
|
// Passing null as the associated DIDescriptor because the abstract definition
|
|
|
|
// shouldn't be found by lookup.
|
|
|
|
AbsDef = &SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE,
|
|
|
|
DIDescriptor());
|
2014-06-06 22:29:05 +00:00
|
|
|
SPCU.applySubprogramAttributesToDefinition(SP, *AbsDef);
|
2014-05-27 18:37:48 +00:00
|
|
|
|
2014-05-23 05:03:23 +00:00
|
|
|
SPCU.addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
|
|
|
|
createAndAddScopeChildren(SPCU, Scope, *AbsDef);
|
2014-04-29 15:58:35 +00:00
|
|
|
}
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-04-29 15:58:35 +00:00
|
|
|
DIE &DwarfDebug::constructSubprogramScopeDIE(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope *Scope) {
|
|
|
|
assert(Scope && Scope->getScopeNode());
|
2014-04-28 20:27:02 +00:00
|
|
|
assert(!Scope->getInlinedAt());
|
2014-04-29 15:58:35 +00:00
|
|
|
assert(!Scope->isAbstractScope());
|
|
|
|
DISubprogram Sub(Scope->getScopeNode());
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-05-14 21:52:46 +00:00
|
|
|
assert(Sub.isSubprogram());
|
|
|
|
|
2014-04-29 15:58:35 +00:00
|
|
|
ProcessedSPNodes.insert(Sub);
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-04-29 15:58:35 +00:00
|
|
|
DIE &ScopeDIE = updateSubprogramScopeDIE(TheCU, Sub);
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-04-30 22:58:19 +00:00
|
|
|
createAndAddScopeChildren(TheCU, Scope, ScopeDIE);
|
2014-04-28 20:27:02 +00:00
|
|
|
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2013-09-10 18:40:41 +00:00
|
|
|
// Construct a DIE for this scope.
|
2014-04-28 20:36:45 +00:00
|
|
|
std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope *Scope) {
|
2013-09-10 18:40:41 +00:00
|
|
|
if (!Scope || !Scope->getScopeNode())
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2013-09-10 18:40:41 +00:00
|
|
|
|
2014-03-21 22:16:32 +00:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
2013-09-10 18:40:41 +00:00
|
|
|
|
2014-04-28 22:27:26 +00:00
|
|
|
assert((Scope->getInlinedAt() || !DS.isSubprogram()) &&
|
|
|
|
"Only handle inlined subprograms here, use "
|
|
|
|
"constructSubprogramScopeDIE for non-inlined "
|
|
|
|
"subprograms");
|
2014-04-28 20:27:02 +00:00
|
|
|
|
2014-04-25 20:00:34 +00:00
|
|
|
SmallVector<std::unique_ptr<DIE>, 8> Children;
|
2013-09-10 18:40:41 +00:00
|
|
|
|
2013-09-11 19:40:28 +00:00
|
|
|
// We try to create the scope DIE first, then the children DIEs. This will
|
|
|
|
// avoid creating un-used children then removing them later when we find out
|
|
|
|
// the scope DIE is null.
|
2014-04-28 20:36:45 +00:00
|
|
|
std::unique_ptr<DIE> ScopeDIE;
|
2014-05-19 21:54:31 +00:00
|
|
|
if (Scope->getParent() && DS.isSubprogram()) {
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);
|
2014-04-28 20:27:02 +00:00
|
|
|
if (!ScopeDIE)
|
|
|
|
return nullptr;
|
|
|
|
// We create children when the scope DIE is not null.
|
|
|
|
createScopeChildrenDIE(TheCU, Scope, Children);
|
2013-11-18 23:59:04 +00:00
|
|
|
} else {
|
2013-09-11 19:40:28 +00:00
|
|
|
// Early exit when we know the scope DIE is going to be null.
|
2013-09-10 18:40:41 +00:00
|
|
|
if (isLexicalScopeDIENull(Scope))
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2013-09-11 19:40:28 +00:00
|
|
|
|
|
|
|
// We create children here when we know the scope DIE is not going to be
|
|
|
|
// null and the children will be added to the scope DIE.
|
2014-04-28 20:27:02 +00:00
|
|
|
createScopeChildrenDIE(TheCU, Scope, Children);
|
2013-09-11 19:40:28 +00:00
|
|
|
|
2011-02-19 01:31:27 +00:00
|
|
|
// There is no need to emit empty lexical block DIE.
|
2013-05-06 23:33:07 +00:00
|
|
|
std::pair<ImportedEntityMap::const_iterator,
|
2013-11-19 09:04:36 +00:00
|
|
|
ImportedEntityMap::const_iterator> Range =
|
2014-04-28 20:42:22 +00:00
|
|
|
std::equal_range(ScopesWithImportedEntities.begin(),
|
|
|
|
ScopesWithImportedEntities.end(),
|
|
|
|
std::pair<const MDNode *, const MDNode *>(DS, nullptr),
|
|
|
|
less_first());
|
2013-05-06 23:33:07 +00:00
|
|
|
if (Children.empty() && Range.first == Range.second)
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
|
2013-09-10 18:40:41 +00:00
|
|
|
assert(ScopeDIE && "Scope DIE should not be null.");
|
2013-06-24 23:20:02 +00:00
|
|
|
for (ImportedEntityMap::const_iterator i = Range.first; i != Range.second;
|
|
|
|
++i)
|
2014-04-28 20:36:45 +00:00
|
|
|
constructImportedEntityDIE(TheCU, i->second, *ScopeDIE);
|
2013-08-24 11:55:49 +00:00
|
|
|
}
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2011-02-19 01:31:27 +00:00
|
|
|
// Add children
|
2014-04-25 20:00:34 +00:00
|
|
|
for (auto &I : Children)
|
|
|
|
ScopeDIE->addChild(std::move(I));
|
2009-11-24 01:14:22 +00:00
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
return ScopeDIE;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {
|
2013-12-04 21:31:26 +00:00
|
|
|
if (!GenerateGnuPubSections)
|
|
|
|
return;
|
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
U.addFlag(D, dwarf::DW_AT_GNU_pubnames);
|
2013-12-04 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
// Create new DwarfCompileUnit for the given metadata node with tag
|
2012-12-20 21:58:40 +00:00
|
|
|
// DW_TAG_compile_unit.
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
|
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
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
2014-04-28 21:14:27 +00:00
|
|
|
InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
2014-04-28 21:04:29 +00:00
|
|
|
DIE &Die = NewCU.getUnitDie();
|
2014-04-22 22:39:41 +00:00
|
|
|
InfoHolder.addUnit(std::move(OwnedUnit));
|
|
|
|
|
2014-03-20 17:05:45 +00:00
|
|
|
// LTO with assembly output shares a single line table amongst multiple CUs.
|
|
|
|
// To avoid the compilation directory being ambiguous, let the line table
|
|
|
|
// explicitly describe the directory of all files, never relying on the
|
|
|
|
// compilation directory.
|
2014-03-19 00:11:28 +00:00
|
|
|
if (!Asm->OutStreamer.hasRawTextSupport() || SingleCU)
|
2014-03-18 00:11:48 +00:00
|
|
|
Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.getUniqueID(), CompilationDir);
|
2013-12-06 19:38:46 +00:00
|
|
|
|
2014-04-28 21:04:29 +00:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
|
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
2014-04-22 23:09:36 +00:00
|
|
|
DIUnit.getLanguage());
|
2014-04-28 21:04:29 +00:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_name, FN);
|
2013-04-09 19:23:15 +00:00
|
|
|
|
|
|
|
if (!useSplitDwarf()) {
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.initStmtList(DwarfLineSectionSym);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-09-27 22:50:48 +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 (!CompilationDir.empty())
|
2014-04-28 21:04:29 +00:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2013-09-13 00:35:05 +00:00
|
|
|
|
2014-04-28 21:04:29 +00:00
|
|
|
addGnuPubAttributes(NewCU, Die);
|
2013-09-27 22:50:48 +00:00
|
|
|
}
|
2013-09-13 00:35:05 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
if (DIUnit.isOptimized())
|
2014-04-28 21:04:29 +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())
|
2014-04-28 21:04:29 +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())
|
2014-04-28 21:04:29 +00:00
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
2014-04-22 23:09:36 +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)
|
2014-04-22 22:39:41 +00:00
|
|
|
FirstCU = &NewCU;
|
2013-02-05 07:31:55 +00:00
|
|
|
|
2014-01-02 21:03:28 +00:00
|
|
|
if (useSplitDwarf()) {
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoDWOSection(),
|
2014-04-22 23:09:36 +00:00
|
|
|
DwarfInfoDWOSectionSym);
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.setSkeleton(constructSkeletonCU(NewCU));
|
2014-01-02 21:03:28 +00:00
|
|
|
} else
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
|
2014-04-22 23:09:36 +00:00
|
|
|
DwarfInfoSectionSym);
|
2013-12-30 03:40:32 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
CUMap.insert(std::make_pair(DIUnit, &NewCU));
|
2014-04-28 21:04:29 +00:00
|
|
|
CUDieMap.insert(std::make_pair(&Die, &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
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
|
2013-04-22 06:12:31 +00:00
|
|
|
const MDNode *N) {
|
2013-05-07 21:35:53 +00:00
|
|
|
DIImportedEntity Module(N);
|
2014-02-04 01:23:52 +00:00
|
|
|
assert(Module.Verify());
|
2014-04-22 22:39:41 +00:00
|
|
|
if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
|
2014-04-28 20:36:45 +00:00
|
|
|
constructImportedEntityDIE(TheCU, Module, *D);
|
2013-05-06 23:33:07 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
|
2014-04-28 20:36:45 +00:00
|
|
|
const MDNode *N, DIE &Context) {
|
2013-05-07 21:35:53 +00:00
|
|
|
DIImportedEntity Module(N);
|
2014-02-04 01:23:52 +00:00
|
|
|
assert(Module.Verify());
|
2013-05-08 06:01:38 +00:00
|
|
|
return constructImportedEntityDIE(TheCU, Module, Context);
|
2013-05-06 23:33:07 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
|
2013-05-07 21:35:53 +00:00
|
|
|
const DIImportedEntity &Module,
|
2014-04-28 20:36:45 +00:00
|
|
|
DIE &Context) {
|
2013-05-06 23:33:07 +00:00
|
|
|
assert(Module.Verify() &&
|
|
|
|
"Use one of the MDNode * overloads to handle invalid metadata");
|
2014-04-28 20:36:45 +00:00
|
|
|
DIE &IMDie = TheCU.createAndAddDIE(Module.getTag(), Context, Module);
|
2013-05-07 21:35:53 +00:00
|
|
|
DIE *EntityDie;
|
2014-04-01 03:41:04 +00:00
|
|
|
DIDescriptor Entity = resolve(Module.getEntity());
|
2013-05-07 21:35:53 +00:00
|
|
|
if (Entity.isNameSpace())
|
2014-04-22 22:39:41 +00:00
|
|
|
EntityDie = TheCU.getOrCreateNameSpace(DINameSpace(Entity));
|
2013-05-07 21:35:53 +00:00
|
|
|
else if (Entity.isSubprogram())
|
2014-04-22 22:39:41 +00:00
|
|
|
EntityDie = TheCU.getOrCreateSubprogramDIE(DISubprogram(Entity));
|
2013-05-08 06:01:41 +00:00
|
|
|
else if (Entity.isType())
|
2014-04-22 22:39:41 +00:00
|
|
|
EntityDie = TheCU.getOrCreateTypeDIE(DIType(Entity));
|
2013-05-07 21:35:53 +00:00
|
|
|
else
|
2014-04-22 22:39:41 +00:00
|
|
|
EntityDie = TheCU.getDIE(Entity);
|
|
|
|
TheCU.addSourceLine(IMDie, Module.getLineNumber(),
|
2014-04-22 23:09:36 +00:00
|
|
|
Module.getContext().getFilename(),
|
|
|
|
Module.getContext().getDirectory());
|
2014-04-25 19:33:43 +00:00
|
|
|
TheCU.addDIEEntry(IMDie, dwarf::DW_AT_import, *EntityDie);
|
2013-05-20 22:50:35 +00:00
|
|
|
StringRef Name = Module.getName();
|
|
|
|
if (!Name.empty())
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addString(IMDie, dwarf::DW_AT_name, Name);
|
2013-04-22 06:12:31 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2013-09-05 18:48:31 +00:00
|
|
|
TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
|
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();
|
|
|
|
|
2014-03-19 00:11:28 +00:00
|
|
|
SingleCU = CU_Nodes->getNumOperands() == 1;
|
2014-03-18 00:11:48 +00:00
|
|
|
|
2014-03-19 00:11:28 +00:00
|
|
|
for (MDNode *N : CU_Nodes->operands()) {
|
2014-03-07 19:09:39 +00:00
|
|
|
DICompileUnit CUNode(N);
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
|
2013-05-07 21:35:53 +00:00
|
|
|
DIArray ImportedEntities = CUNode.getImportedEntities();
|
|
|
|
for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
|
2013-05-06 23:33:07 +00:00
|
|
|
ScopesWithImportedEntities.push_back(std::make_pair(
|
2013-05-07 21:35:53 +00:00
|
|
|
DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
|
|
|
|
ImportedEntities.getElement(i)));
|
2013-05-06 23:33:07 +00:00
|
|
|
std::sort(ScopesWithImportedEntities.begin(),
|
2013-08-24 12:54:27 +00:00
|
|
|
ScopesWithImportedEntities.end(), less_first());
|
2013-03-11 23:39:23 +00:00
|
|
|
DIArray GVs = CUNode.getGlobalVariables();
|
|
|
|
for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
|
2014-04-22 22:39:41 +00:00
|
|
|
CU.createGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i)));
|
2013-03-11 23:39:23 +00:00
|
|
|
DIArray SPs = CUNode.getSubprograms();
|
|
|
|
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
|
2014-05-27 18:37:48 +00:00
|
|
|
SPMap.insert(std::make_pair(SPs.getElement(i), &CU));
|
2013-03-11 23:39:23 +00:00
|
|
|
DIArray EnumTypes = CUNode.getEnumTypes();
|
|
|
|
for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
|
2014-04-22 22:39:41 +00:00
|
|
|
CU.getOrCreateTypeDIE(EnumTypes.getElement(i));
|
2013-03-11 23:39:23 +00:00
|
|
|
DIArray RetainedTypes = CUNode.getRetainedTypes();
|
2014-03-18 02:35:03 +00:00
|
|
|
for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
|
|
|
|
DIType Ty(RetainedTypes.getElement(i));
|
|
|
|
// The retained types array by design contains pointers to
|
|
|
|
// MDNodes rather than DIRefs. Unique them here.
|
|
|
|
DIType UniqueTy(resolve(Ty.getRef()));
|
2014-04-22 22:39:41 +00:00
|
|
|
CU.getOrCreateTypeDIE(UniqueTy);
|
2014-03-18 02:35:03 +00:00
|
|
|
}
|
2013-04-22 06:12:31 +00:00
|
|
|
// Emit imported_modules last so that the relevant context is already
|
|
|
|
// available.
|
2013-05-07 21:35:53 +00:00
|
|
|
for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
|
|
|
|
constructImportedEntityDIE(CU, ImportedEntities.getElement(i));
|
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.
|
2013-09-19 23:21:01 +00:00
|
|
|
SectionMap[Asm->getObjFileLowering().getTextSection()];
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2014-06-13 22:18:23 +00:00
|
|
|
void DwarfDebug::finishVariableDefinitions() {
|
|
|
|
for (const auto &Var : ConcreteVariables) {
|
|
|
|
DIE *VariableDie = Var->getDIE();
|
2014-06-15 19:34:26 +00:00
|
|
|
// FIXME: There shouldn't be any variables without DIEs.
|
DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself.
Originally committed in r211723, reverted in r211724 due to failure
cases found and fixed (ArgumentPromotion: r211872, Inlining: r212065),
and I now believe the invariant actually holds for some reasonable
amount of code (but I'll keep an eye on the buildbots and see what
happens... ).
Original commit message:
PR20038: DebugInfo: Inlined call sites where the caller has debug info
but the call itself has no debug location.
This situation does bad things when inlined, so I've fixed Clang not to
produce inlinable call sites without locations when the caller has debug
info (in the one case where I could find that this occurred). This
updates the PR20038 test case to be what clang now produces, and readds
the assertion that had to be removed due to this bug.
I've also beefed up the debug info verifier to help diagnose these
issues in the future, and I hope to add checks to the inliner to just
assert-fail if it encounters this situation. If, in the future, we
decide we have to cope with this situation, the right thing to do is
probably to just remove all the DebugLocs from the inlined instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212085 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-01 03:11:59 +00:00
|
|
|
assert(VariableDie);
|
2014-06-13 22:18:23 +00:00
|
|
|
// FIXME: Consider the time-space tradeoff of just storing the unit pointer
|
|
|
|
// in the ConcreteVariables list, rather than looking it up again here.
|
|
|
|
// DIE::getUnit isn't simple - it walks parent pointers, etc.
|
|
|
|
DwarfCompileUnit *Unit = lookupUnit(VariableDie->getUnit());
|
|
|
|
assert(Unit);
|
2014-06-13 22:35:44 +00:00
|
|
|
DbgVariable *AbsVar = getExistingAbstractVariable(Var->getVariable());
|
2014-06-13 22:18:23 +00:00
|
|
|
if (AbsVar && AbsVar->getDIE()) {
|
|
|
|
Unit->addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,
|
|
|
|
*AbsVar->getDIE());
|
|
|
|
} else
|
|
|
|
Unit->applyVariableAttributes(*Var, *VariableDie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
DebugInfo: Lazily attach definition attributes to definitions.
This is a precursor to fixing inlined debug info where the concrete,
out-of-line definition may preceed any inlined usage. To cope with this,
the attributes that may appear on the concrete definition or the
abstract definition are delayed until the end of the module. Then, if an
abstract definition was created, it is referenced (and no other
attributes are added to the out-of-line definition), otherwise the
attributes are added directly to the out-of-line definition.
In a couple of cases this causes not just reordering of attributes, but
reordering of types. When the creation of the attribute is delayed, if
that creation would create a type (such as for a DW_AT_type attribute)
then other top level DIEs may've been constructed during the delay,
causing the referenced type to be created and added after those
intervening DIEs. In the extreme case, in cross-cu-inlining.ll, this
actually causes the DW_TAG_basic_type for "int" to move from one CU to
another.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209674 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-27 18:37:43 +00:00
|
|
|
void DwarfDebug::finishSubprogramDefinitions() {
|
|
|
|
const Module *M = MMI->getModule();
|
|
|
|
|
|
|
|
NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
|
|
|
|
for (MDNode *N : CU_Nodes->operands()) {
|
|
|
|
DICompileUnit TheCU(N);
|
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
|
|
|
DwarfCompileUnit *SPCU =
|
|
|
|
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
|
|
|
|
DIArray Subprograms = TheCU.getSubprograms();
|
|
|
|
for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
|
|
|
|
DISubprogram SP(Subprograms.getElement(i));
|
2014-05-27 18:37:48 +00:00
|
|
|
// Perhaps the subprogram is in another CU (such as due to comdat
|
|
|
|
// folding, etc), in which case ignore it here.
|
|
|
|
if (SPMap[SP] != SPCU)
|
|
|
|
continue;
|
|
|
|
DIE *D = SPCU->getDIE(SP);
|
2014-05-27 18:37:55 +00:00
|
|
|
if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) {
|
|
|
|
if (D)
|
|
|
|
// If this subprogram has an abstract definition, reference that
|
|
|
|
SPCU->addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
|
|
|
|
} else {
|
|
|
|
if (!D)
|
|
|
|
// Lazily construct the subprogram if we didn't see either concrete or
|
|
|
|
// inlined versions during codegen.
|
|
|
|
D = SPCU->getOrCreateSubprogramDIE(SP);
|
|
|
|
// And attach the attributes
|
2014-06-06 22:29:05 +00:00
|
|
|
SPCU->applySubprogramAttributesToDefinition(SP, *D);
|
2014-05-27 18:37:55 +00:00
|
|
|
}
|
DebugInfo: Lazily attach definition attributes to definitions.
This is a precursor to fixing inlined debug info where the concrete,
out-of-line definition may preceed any inlined usage. To cope with this,
the attributes that may appear on the concrete definition or the
abstract definition are delayed until the end of the module. Then, if an
abstract definition was created, it is referenced (and no other
attributes are added to the out-of-line definition), otherwise the
attributes are added directly to the out-of-line definition.
In a couple of cases this causes not just reordering of attributes, but
reordering of types. When the creation of the attribute is delayed, if
that creation would create a type (such as for a DW_AT_type attribute)
then other top level DIEs may've been constructed during the delay,
causing the referenced type to be created and added after those
intervening DIEs. In the extreme case, in cross-cu-inlining.ll, this
actually causes the DW_TAG_basic_type for "int" to move from one CU to
another.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209674 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-27 18:37:43 +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();
|
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")) {
|
2014-03-07 19:09:39 +00:00
|
|
|
for (MDNode *N : CU_Nodes->operands()) {
|
|
|
|
DICompileUnit TheCU(N);
|
2014-05-14 21:52:46 +00:00
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
|
|
|
DwarfCompileUnit *SPCU =
|
|
|
|
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
|
|
|
|
assert(SPCU && "Unable to find Compile Unit!");
|
2011-08-16 22:09:43 +00:00
|
|
|
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));
|
2013-10-15 23:31:38 +00:00
|
|
|
if (ProcessedSPNodes.count(SP) != 0)
|
|
|
|
continue;
|
2014-05-14 21:52:37 +00:00
|
|
|
assert(SP.isSubprogram() &&
|
|
|
|
"CU's subprogram list contains a non-subprogram");
|
2014-05-16 22:21:45 +00:00
|
|
|
assert(SP.isDefinition() &&
|
|
|
|
"CU's subprogram list contains a subprogram declaration");
|
2012-11-27 00:13:51 +00:00
|
|
|
DIArray Variables = SP.getVariables();
|
2013-10-15 23:31:38 +00:00
|
|
|
if (Variables.getNumElements() == 0)
|
|
|
|
continue;
|
2012-11-27 00:13:51 +00:00
|
|
|
|
2014-05-27 18:37:55 +00:00
|
|
|
DIE *SPDIE = AbstractSPDies.lookup(SP);
|
|
|
|
if (!SPDIE)
|
|
|
|
SPDIE = SPCU->getDIE(SP);
|
2014-05-22 00:48:36 +00:00
|
|
|
assert(SPDIE);
|
2012-11-27 00:13:51 +00:00
|
|
|
for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
|
|
|
|
DIVariable DV(Variables.getElement(vi));
|
2014-05-14 21:52:46 +00:00
|
|
|
assert(DV.isVariable());
|
2014-06-13 23:52:55 +00:00
|
|
|
DbgVariable NewVar(DV, this);
|
2014-06-13 22:18:23 +00:00
|
|
|
auto VariableDie = SPCU->constructVariableDIE(NewVar);
|
|
|
|
SPCU->applyVariableAttributes(NewVar, *VariableDie);
|
|
|
|
SPDIE->addChild(std::move(VariableDie));
|
2012-11-27 00:13:51 +00:00
|
|
|
}
|
2010-06-28 18:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 00:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::finalizeModuleInfo() {
|
2014-05-27 18:37:48 +00:00
|
|
|
finishSubprogramDefinitions();
|
|
|
|
|
2014-06-13 22:18:23 +00:00
|
|
|
finishVariableDefinitions();
|
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
collectDeadVariables();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-12-04 23:24:38 +00:00
|
|
|
// Handle anything that needs to be done on a per-unit basis after
|
|
|
|
// all other generation.
|
2014-04-22 21:27:37 +00:00
|
|
|
for (const auto &TheU : getUnits()) {
|
2013-08-12 20:27:48 +00:00
|
|
|
// Emit DW_AT_containing_type attribute to connect types with their
|
|
|
|
// vtable holding type.
|
2013-12-02 22:09:48 +00:00
|
|
|
TheU->constructContainingTypeDIEs();
|
2013-08-12 20:27:48 +00:00
|
|
|
|
2013-12-20 04:16:18 +00:00
|
|
|
// Add CU specific attributes if we need to add any.
|
2014-04-25 18:35:57 +00:00
|
|
|
if (TheU->getUnitDie().getTag() == dwarf::DW_TAG_compile_unit) {
|
2013-12-20 04:16:18 +00:00
|
|
|
// If we're splitting the dwarf out now that we've got the entire
|
2013-12-30 17:22:27 +00:00
|
|
|
// CU then add the dwo id to it.
|
|
|
|
DwarfCompileUnit *SkCU =
|
|
|
|
static_cast<DwarfCompileUnit *>(TheU->getSkeleton());
|
2013-12-20 04:16:18 +00:00
|
|
|
if (useSplitDwarf()) {
|
2014-03-14 21:20:07 +00:00
|
|
|
// Emit a unique identifier for this CU.
|
2014-04-25 18:35:57 +00:00
|
|
|
uint64_t ID = DIEHash(Asm).computeCUSignature(TheU->getUnitDie());
|
|
|
|
TheU->addUInt(TheU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
2013-12-20 04:16:18 +00:00
|
|
|
dwarf::DW_FORM_data8, ID);
|
2014-04-25 18:35:57 +00:00
|
|
|
SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
2013-12-20 04:16:18 +00:00
|
|
|
dwarf::DW_FORM_data8, ID);
|
2014-03-25 05:34:24 +00:00
|
|
|
|
|
|
|
// We don't keep track of which addresses are used in which CU so this
|
|
|
|
// is a bit pessimistic under LTO.
|
2014-04-23 21:20:10 +00:00
|
|
|
if (!AddrPool.isEmpty())
|
2014-04-25 18:35:57 +00:00
|
|
|
addSectionLabel(*Asm, *SkCU, SkCU->getUnitDie(),
|
2014-03-25 05:34:24 +00:00
|
|
|
dwarf::DW_AT_GNU_addr_base, DwarfAddrSectionSym,
|
|
|
|
DwarfAddrSectionSym);
|
|
|
|
if (!TheU->getRangeLists().empty())
|
2014-04-25 18:35:57 +00:00
|
|
|
addSectionLabel(*Asm, *SkCU, SkCU->getUnitDie(),
|
2014-03-25 05:34:24 +00:00
|
|
|
dwarf::DW_AT_GNU_ranges_base,
|
|
|
|
DwarfDebugRangeSectionSym, DwarfDebugRangeSectionSym);
|
2013-08-13 01:21:55 +00:00
|
|
|
}
|
2013-12-30 17:22:27 +00:00
|
|
|
|
2014-03-20 19:16:16 +00:00
|
|
|
// If we have code split among multiple sections or non-contiguous
|
|
|
|
// ranges of code then emit a DW_AT_ranges attribute on the unit that will
|
|
|
|
// remain in the .o file, otherwise add a DW_AT_low_pc.
|
|
|
|
// FIXME: We should use ranges allow reordering of code ala
|
|
|
|
// .subsections_via_symbols in mach-o. This would mean turning on
|
|
|
|
// ranges for all subprogram DIEs for mach-o.
|
2014-04-22 21:27:37 +00:00
|
|
|
DwarfCompileUnit &U =
|
|
|
|
SkCU ? *SkCU : static_cast<DwarfCompileUnit &>(*TheU);
|
2014-03-20 19:16:16 +00:00
|
|
|
unsigned NumRanges = TheU->getRanges().size();
|
|
|
|
if (NumRanges) {
|
|
|
|
if (NumRanges > 1) {
|
2014-04-25 18:35:57 +00:00
|
|
|
addSectionLabel(*Asm, U, U.getUnitDie(), dwarf::DW_AT_ranges,
|
2014-04-22 21:27:37 +00:00
|
|
|
Asm->GetTempSymbol("cu_ranges", U.getUniqueID()),
|
2014-03-20 19:16:16 +00:00
|
|
|
DwarfDebugRangeSectionSym);
|
|
|
|
|
|
|
|
// A DW_AT_low_pc attribute may also be specified in combination with
|
|
|
|
// DW_AT_ranges to specify the default base address for use in
|
|
|
|
// location lists (see Section 2.6.2) and range lists (see Section
|
|
|
|
// 2.17.3).
|
2014-04-25 18:35:57 +00:00
|
|
|
U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
|
2014-04-22 21:27:37 +00:00
|
|
|
0);
|
2014-03-20 19:16:16 +00:00
|
|
|
} else {
|
|
|
|
RangeSpan &Range = TheU->getRanges().back();
|
2014-04-25 18:35:57 +00:00
|
|
|
U.addLocalLabelAddress(U.getUnitDie(), dwarf::DW_AT_low_pc,
|
2014-04-22 21:27:37 +00:00
|
|
|
Range.getStart());
|
2014-04-25 18:35:57 +00:00
|
|
|
U.addLabelDelta(U.getUnitDie(), dwarf::DW_AT_high_pc, Range.getEnd(),
|
2014-04-22 21:27:37 +00:00
|
|
|
Range.getStart());
|
2014-03-20 19:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-12 20:27:48 +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() {
|
2013-11-19 09:04:36 +00:00
|
|
|
// Filter labels by section.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const SymbolCU &SCU : ArangeLabels) {
|
2013-09-19 23:21:01 +00:00
|
|
|
if (SCU.Sym->isInSection()) {
|
|
|
|
// Make a note of this symbol and it's section.
|
|
|
|
const MCSection *Section = &SCU.Sym->getSection();
|
|
|
|
if (!Section->getKind().isMetadata())
|
|
|
|
SectionMap[Section].push_back(SCU);
|
|
|
|
} else {
|
|
|
|
// Some symbols (e.g. common/bss on mach-o) can have no section but still
|
|
|
|
// appear in the output. This sucks as we rely on sections to build
|
|
|
|
// arange spans. We can do it without, but it's icky.
|
2014-04-24 06:44:33 +00:00
|
|
|
SectionMap[nullptr].push_back(SCU);
|
2013-09-19 23:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 22:07:08 +00:00
|
|
|
// Build a list of sections used.
|
|
|
|
std::vector<const MCSection *> Sections;
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const auto &it : SectionMap) {
|
|
|
|
const MCSection *Section = it.first;
|
2013-10-03 22:07:08 +00:00
|
|
|
Sections.push_back(Section);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the sections into order.
|
|
|
|
// This is only done to ensure consistent output order across different runs.
|
|
|
|
std::sort(Sections.begin(), Sections.end(), SectionSort);
|
|
|
|
|
|
|
|
// Add terminating symbols for each section.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (unsigned ID = 0, E = Sections.size(); ID != E; ID++) {
|
2013-10-03 22:07:08 +00:00
|
|
|
const MCSection *Section = Sections[ID];
|
2014-04-24 06:44:33 +00:00
|
|
|
MCSymbol *Sym = nullptr;
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-09-19 23:21:01 +00:00
|
|
|
if (Section) {
|
2013-10-03 22:07:08 +00:00
|
|
|
// We can't call MCSection::getLabelEndName, as it's only safe to do so
|
2013-11-19 09:04:36 +00:00
|
|
|
// if we know the section name up-front. For user-created sections, the
|
2014-01-29 22:06:21 +00:00
|
|
|
// resulting label may not be valid to use as a label. (section names can
|
|
|
|
// use a greater set of characters on some systems)
|
2013-10-03 22:07:08 +00:00
|
|
|
Sym = Asm->GetTempSymbol("debug_end", ID);
|
2013-09-19 23:21:01 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(Section);
|
|
|
|
Asm->OutStreamer.EmitLabel(Sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert a final terminator.
|
2014-04-24 06:44:33 +00:00
|
|
|
SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
|
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() {
|
2014-04-28 04:05:08 +00:00
|
|
|
assert(CurFn == nullptr);
|
|
|
|
assert(CurMI == nullptr);
|
2012-11-22 00:59:49 +00:00
|
|
|
|
2013-11-19 09:04:36 +00:00
|
|
|
if (!FirstCU)
|
|
|
|
return;
|
2012-11-22 00:59:49 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
emitDebugStr();
|
2013-09-20 23:22:52 +00:00
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
// Emit all the DIEs into a debug info section.
|
|
|
|
emitDebugInfo();
|
2012-11-27 00:41:54 +00:00
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
// Corresponding abbreviations into a abbrev section.
|
|
|
|
emitAbbreviations();
|
2012-11-27 22:43:42 +00:00
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
// Emit info into a debug aranges section.
|
2014-02-14 01:26:55 +00:00
|
|
|
if (GenerateARangeSection)
|
|
|
|
emitDebugARanges();
|
2012-11-27 22:43:42 +00:00
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
// Emit info into a debug ranges section.
|
|
|
|
emitDebugRanges();
|
2012-11-27 22:43:42 +00:00
|
|
|
|
2013-11-19 09:04:50 +00:00
|
|
|
if (useSplitDwarf()) {
|
|
|
|
emitDebugStrDWO();
|
2012-11-30 23:59:06 +00:00
|
|
|
emitDebugInfoDWO();
|
2012-12-19 22:02:53 +00:00
|
|
|
emitDebugAbbrevDWO();
|
2014-03-18 01:17:26 +00:00
|
|
|
emitDebugLineDWO();
|
2014-06-19 17:59:14 +00:00
|
|
|
emitDebugLocDWO();
|
2013-01-15 23:56:56 +00:00
|
|
|
// Emit DWO addresses.
|
2014-04-23 21:20:10 +00:00
|
|
|
AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection());
|
2014-04-02 01:50:20 +00:00
|
|
|
} else
|
|
|
|
// Emit info into a debug loc section.
|
|
|
|
emitDebugLoc();
|
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-08-30 00:40:17 +00:00
|
|
|
// Emit the pubnames and pubtypes sections if requested.
|
|
|
|
if (HasDwarfPubSections) {
|
2013-09-19 17:33:35 +00:00
|
|
|
emitDebugPubNames(GenerateGnuPubSections);
|
|
|
|
emitDebugPubTypes(GenerateGnuPubSections);
|
2013-08-30 00:40:17 +00:00
|
|
|
}
|
2009-11-24 01:14:22 +00:00
|
|
|
|
2010-08-02 17:32:15 +00:00
|
|
|
// clean up.
|
2011-08-16 22:09:43 +00:00
|
|
|
SPMap.clear();
|
2014-05-21 22:41:17 +00:00
|
|
|
AbstractVariables.clear();
|
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.
|
2014-04-24 06:44:33 +00:00
|
|
|
FirstCU = nullptr;
|
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.
|
2014-06-13 22:29:31 +00:00
|
|
|
DbgVariable *DwarfDebug::getExistingAbstractVariable(const DIVariable &DV,
|
2014-06-04 23:50:52 +00:00
|
|
|
DIVariable &Cleansed) {
|
2011-08-10 21:50:54 +00:00
|
|
|
LLVMContext &Ctx = DV->getContext();
|
|
|
|
// More then one inlined variable corresponds to one abstract variable.
|
2014-06-04 23:50:52 +00:00
|
|
|
// FIXME: This duplication of variables when inlining should probably be
|
|
|
|
// removed. It's done to allow each DIVariable to describe its location
|
|
|
|
// because the DebugLoc on the dbg.value/declare isn't accurate. We should
|
|
|
|
// make it accurate then remove this duplication/cleansing stuff.
|
|
|
|
Cleansed = cleanseInlinedVariable(DV, Ctx);
|
|
|
|
auto I = AbstractVariables.find(Cleansed);
|
2014-05-21 22:41:17 +00:00
|
|
|
if (I != AbstractVariables.end())
|
|
|
|
return I->second.get();
|
2014-06-04 23:50:52 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2014-06-13 22:35:44 +00:00
|
|
|
DbgVariable *DwarfDebug::getExistingAbstractVariable(const DIVariable &DV) {
|
|
|
|
DIVariable Cleansed;
|
|
|
|
return getExistingAbstractVariable(DV, Cleansed);
|
|
|
|
}
|
|
|
|
|
2014-06-13 23:52:55 +00:00
|
|
|
void DwarfDebug::createAbstractVariable(const DIVariable &Var,
|
|
|
|
LexicalScope *Scope) {
|
|
|
|
auto AbsDbgVariable = make_unique<DbgVariable>(Var, this);
|
2014-05-21 22:41:17 +00:00
|
|
|
addScopeVariable(Scope, AbsDbgVariable.get());
|
2014-06-13 23:52:55 +00:00
|
|
|
AbstractVariables[Var] = std::move(AbsDbgVariable);
|
2010-03-15 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 23:52:55 +00:00
|
|
|
void DwarfDebug::ensureAbstractVariableIsCreated(const DIVariable &DV,
|
|
|
|
const MDNode *ScopeNode) {
|
2014-06-04 23:50:52 +00:00
|
|
|
DIVariable Cleansed = DV;
|
2014-06-13 23:52:55 +00:00
|
|
|
if (getExistingAbstractVariable(DV, Cleansed))
|
|
|
|
return;
|
2014-06-04 23:50:52 +00:00
|
|
|
|
2014-06-13 23:52:55 +00:00
|
|
|
createAbstractVariable(Cleansed, LScopes.getOrCreateAbstractScope(ScopeNode));
|
2014-06-04 23:50:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 23:52:55 +00:00
|
|
|
void
|
|
|
|
DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(const DIVariable &DV,
|
|
|
|
const MDNode *ScopeNode) {
|
2014-06-04 23:50:52 +00:00
|
|
|
DIVariable Cleansed = DV;
|
2014-06-13 23:52:55 +00:00
|
|
|
if (getExistingAbstractVariable(DV, Cleansed))
|
|
|
|
return;
|
2014-06-04 23:50:52 +00:00
|
|
|
|
|
|
|
if (LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode))
|
2014-06-13 23:52:55 +00:00
|
|
|
createAbstractVariable(Cleansed, Scope);
|
2014-06-04 23:50:52 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// If Var is a current function argument then add it to CurrentFnArguments list.
|
2014-04-22 05:41:06 +00:00
|
|
|
bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
|
2011-08-10 20:55:27 +00:00
|
|
|
if (!LScopes.isCurrentFunctionScope(Scope))
|
2014-04-22 05:41:06 +00:00
|
|
|
return false;
|
|
|
|
DIVariable DV = Var->getVariable();
|
2011-03-01 22:58:55 +00:00
|
|
|
if (DV.getTag() != dwarf::DW_TAG_arg_variable)
|
2014-04-22 05:41:06 +00:00
|
|
|
return false;
|
2011-03-01 22:58:55 +00:00
|
|
|
unsigned ArgNo = DV.getArgNumber();
|
2012-11-19 22:42:10 +00:00
|
|
|
if (ArgNo == 0)
|
2014-04-22 05:41:06 +00:00
|
|
|
return false;
|
2011-03-01 22:58:55 +00:00
|
|
|
|
2014-04-22 05:41:06 +00:00
|
|
|
size_t Size = CurrentFnArguments.size();
|
|
|
|
if (Size == 0)
|
|
|
|
CurrentFnArguments.resize(CurFn->getFunction()->arg_size());
|
|
|
|
// llvm::Function argument size is not good indicator of how many
|
|
|
|
// arguments does the function have at source level.
|
|
|
|
if (ArgNo > Size)
|
|
|
|
CurrentFnArguments.resize(ArgNo * 2);
|
|
|
|
CurrentFnArguments[ArgNo - 1] = Var;
|
|
|
|
return true;
|
2011-03-01 22:58:55 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Collect variable information from side table maintained by MMI.
|
2013-11-19 09:04:36 +00:00
|
|
|
void DwarfDebug::collectVariableInfoFromMMITable(
|
2013-12-03 15:10:23 +00:00
|
|
|
SmallPtrSet<const MDNode *, 16> &Processed) {
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const auto &VI : MMI->getVariableDbgInfo()) {
|
2014-03-09 15:44:39 +00:00
|
|
|
if (!VI.Var)
|
2013-11-19 09:04:36 +00:00
|
|
|
continue;
|
2014-03-09 15:44:39 +00:00
|
|
|
Processed.insert(VI.Var);
|
|
|
|
DIVariable DV(VI.Var);
|
|
|
|
LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc);
|
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.
|
2014-04-24 06:44:33 +00:00
|
|
|
if (!Scope)
|
2009-11-10 23:20:04 +00:00
|
|
|
continue;
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2014-06-13 23:52:55 +00:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
|
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(DV, this));
|
2014-06-13 22:18:23 +00:00
|
|
|
DbgVariable *RegVar = ConcreteVariables.back().get();
|
2014-04-22 05:41:06 +00:00
|
|
|
RegVar->setFrameIndex(VI.Slot);
|
2014-06-05 01:04:20 +00:00
|
|
|
addScopeVariable(Scope, RegVar);
|
2009-10-06 01:26:37 +00:00
|
|
|
}
|
2010-05-20 19:57:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Get .debug_loc entry for the instruction range starting at MI.
|
2014-04-27 18:25:40 +00:00
|
|
|
static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
|
2014-04-10 17:39:48 +00:00
|
|
|
const MDNode *Var = MI->getDebugVariable();
|
2011-07-08 17:09:57 +00:00
|
|
|
|
2013-06-16 20:34:15 +00:00
|
|
|
assert(MI->getNumOperands() == 3);
|
2013-07-09 20:28:37 +00:00
|
|
|
if (MI->getOperand(0).isReg()) {
|
2011-07-08 17:09:57 +00:00
|
|
|
MachineLocation MLoc;
|
2013-07-09 20:28:37 +00:00
|
|
|
// If the second operand is an immediate, this is a
|
|
|
|
// register-indirect address.
|
|
|
|
if (!MI->getOperand(1).isImm())
|
2013-04-26 21:57:17 +00:00
|
|
|
MLoc.set(MI->getOperand(0).getReg());
|
|
|
|
else
|
|
|
|
MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
|
2014-04-27 18:25:40 +00:00
|
|
|
return DebugLocEntry::Value(Var, MLoc);
|
2011-07-08 17:09:57 +00:00
|
|
|
}
|
|
|
|
if (MI->getOperand(0).isImm())
|
2014-04-27 18:25:40 +00:00
|
|
|
return DebugLocEntry::Value(Var, MI->getOperand(0).getImm());
|
2011-07-08 17:09:57 +00:00
|
|
|
if (MI->getOperand(0).isFPImm())
|
2014-04-27 18:25:40 +00:00
|
|
|
return DebugLocEntry::Value(Var, MI->getOperand(0).getFPImm());
|
2011-07-08 17:09:57 +00:00
|
|
|
if (MI->getOperand(0).isCImm())
|
2014-04-27 18:25:40 +00:00
|
|
|
return DebugLocEntry::Value(Var, MI->getOperand(0).getCImm());
|
2011-07-08 17:09:57 +00:00
|
|
|
|
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
|
2013-12-03 15:10:23 +00:00
|
|
|
DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
|
2014-04-27 18:25:40 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
|
|
|
DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2013-07-03 21:37:03 +00:00
|
|
|
// Grab the variable info that was squirreled away in the MMI side-table.
|
2013-12-03 15:10:23 +00:00
|
|
|
collectVariableInfoFromMMITable(Processed);
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2014-04-30 23:02:40 +00:00
|
|
|
for (const auto &I : DbgValues) {
|
|
|
|
DIVariable DV(I.first);
|
|
|
|
if (Processed.count(DV))
|
2010-05-20 19:57:06 +00:00
|
|
|
continue;
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
// Instruction ranges, specifying where DV is accessible.
|
|
|
|
const auto &Ranges = I.second;
|
|
|
|
if (Ranges.empty())
|
2011-03-26 02:19:36 +00:00
|
|
|
continue;
|
2010-05-25 23:40:22 +00:00
|
|
|
|
2014-04-24 06:44:33 +00:00
|
|
|
LexicalScope *Scope = nullptr;
|
2010-05-27 20:25:04 +00:00
|
|
|
if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
2013-12-03 15:10:23 +00:00
|
|
|
DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
|
2011-08-10 20:55:27 +00:00
|
|
|
Scope = LScopes.getCurrentFunctionScope();
|
2014-05-14 01:08:28 +00:00
|
|
|
else if (MDNode *IA = DV.getInlinedAt()) {
|
|
|
|
DebugLoc DL = DebugLoc::getFromDILocation(IA);
|
|
|
|
Scope = LScopes.findInlinedScope(DebugLoc::get(
|
|
|
|
DL.getLine(), DL.getCol(), DV.getContext(), IA));
|
|
|
|
} else
|
|
|
|
Scope = LScopes.findLexicalScope(DV.getContext());
|
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);
|
2014-05-27 23:09:50 +00:00
|
|
|
const MachineInstr *MInsn = Ranges.front().first;
|
2011-03-26 02:19:36 +00:00
|
|
|
assert(MInsn->isDebugValue() && "History must begin with debug value");
|
2014-06-13 23:52:55 +00:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
|
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(MInsn, this));
|
2014-06-13 22:18:23 +00:00
|
|
|
DbgVariable *RegVar = ConcreteVariables.back().get();
|
2014-06-05 01:04:20 +00:00
|
|
|
addScopeVariable(Scope, RegVar);
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
// Check if the first DBG_VALUE is valid for the rest of the function.
|
2014-05-30 21:10:13 +00:00
|
|
|
if (Ranges.size() == 1 && Ranges.front().second == nullptr)
|
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.
|
2014-04-22 05:41:06 +00:00
|
|
|
RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2014-04-02 01:43:18 +00:00
|
|
|
DotDebugLocEntries.resize(DotDebugLocEntries.size() + 1);
|
|
|
|
DebugLocList &LocList = DotDebugLocEntries.back();
|
|
|
|
LocList.Label =
|
|
|
|
Asm->GetTempSymbol("debug_loc", DotDebugLocEntries.size() - 1);
|
|
|
|
SmallVector<DebugLocEntry, 4> &DebugLoc = LocList.List;
|
2014-05-27 23:09:50 +00:00
|
|
|
for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
|
|
|
|
const MachineInstr *Begin = I->first;
|
|
|
|
const MachineInstr *End = I->second;
|
2011-03-26 02:19:36 +00:00
|
|
|
assert(Begin->isDebugValue() && "Invalid History entry");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
// Check if a variable is unaccessible in this range.
|
2013-11-19 09:04:36 +00:00
|
|
|
if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg() &&
|
|
|
|
!Begin->getOperand(0).getReg())
|
2011-06-01 23:00:17 +00:00
|
|
|
continue;
|
2014-06-05 23:10:19 +00:00
|
|
|
DEBUG(dbgs() << "DotDebugLoc Pair:\n" << "\t" << *Begin);
|
|
|
|
if (End != nullptr)
|
|
|
|
DEBUG(dbgs() << "\t" << *End);
|
|
|
|
else
|
|
|
|
DEBUG(dbgs() << "\tNULL\n");
|
2011-06-01 23:00:17 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
const MCSymbol *StartLabel = getLabelBeforeInsn(Begin);
|
|
|
|
assert(StartLabel && "Forgot label before DBG_VALUE starting a range!");
|
|
|
|
|
|
|
|
const MCSymbol *EndLabel;
|
|
|
|
if (End != nullptr)
|
|
|
|
EndLabel = getLabelAfterInsn(End);
|
|
|
|
else if (std::next(I) == Ranges.end())
|
|
|
|
EndLabel = FunctionEndSym;
|
|
|
|
else
|
|
|
|
EndLabel = getLabelBeforeInsn(std::next(I)->first);
|
|
|
|
assert(EndLabel && "Forgot label after instruction ending a range!");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
DebugLocEntry Loc(StartLabel, EndLabel, getDebugLocValue(Begin), TheCU);
|
2014-03-24 22:38:38 +00:00
|
|
|
if (DebugLoc.empty() || !DebugLoc.back().Merge(Loc))
|
|
|
|
DebugLoc.push_back(std::move(Loc));
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
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
|
|
|
DIArray Variables = DISubprogram(FnScope->getScopeNode()).getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
2014-05-14 21:52:46 +00:00
|
|
|
assert(DV.isVariable());
|
|
|
|
if (!Processed.insert(DV))
|
2011-08-19 23:28:12 +00:00
|
|
|
continue;
|
PR19388: DebugInfo: Emit dead arguments in their originally declared order.
Unused arguments were not being added to the argument list, but instead
treated as arbitrary scope variables. This meant they weren't carefully
added in the original argument order.
In this particular example, though, it turns out the argument is only
/mostly/ unused (well, actually it's entirely used, but in a specific
way). It's a struct that, due to ABI reasons, is decomposed into chunks
(exactly one chunk, since it has one member) and then passed. Since only
one of those chunks is used (SROA, etc, kill the original reconstitution
code) we don't have a location to describe the whole variable.
In this particular case, since the struct consists of just the one int,
once we have partial location information, this should have a location
that describes the entire variable (since the piece is the entirety of
the object).
And at some point we'll need to describe the location of even /entirely/
unused arguments so that they can at least be printed on function entry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210231 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-05 00:51:35 +00:00
|
|
|
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext())) {
|
2014-06-13 23:52:55 +00:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
|
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(DV, this));
|
2014-06-13 22:18:23 +00:00
|
|
|
addScopeVariable(Scope, ConcreteVariables.back().get());
|
PR19388: DebugInfo: Emit dead arguments in their originally declared order.
Unused arguments were not being added to the argument list, but instead
treated as arbitrary scope variables. This meant they weren't carefully
added in the original argument order.
In this particular example, though, it turns out the argument is only
/mostly/ unused (well, actually it's entirely used, but in a specific
way). It's a struct that, due to ABI reasons, is decomposed into chunks
(exactly one chunk, since it has one member) and then passed. Since only
one of those chunks is used (SROA, etc, kill the original reconstitution
code) we don't have a location to describe the whole variable.
In this particular case, since the struct consists of just the one int,
once we have partial location information, this should have a location
that describes the entire variable (since the piece is the entirety of
the object).
And at some point we'll need to describe the location of even /entirely/
unused arguments so that they can at least be printed on function entry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210231 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-05 00:51:35 +00:00
|
|
|
}
|
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) {
|
2014-04-28 04:05:08 +00:00
|
|
|
assert(CurMI == nullptr);
|
2013-12-03 15:10:23 +00:00
|
|
|
CurMI = 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
|
2014-04-24 06:44:33 +00:00
|
|
|
recordSourceLine(0, 0, nullptr, 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.
|
2013-11-19 09:04:36 +00:00
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
|
|
|
LabelsBeforeInsn.find(MI);
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// 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.
|
2013-12-03 15:10:23 +00:00
|
|
|
void DwarfDebug::endInstruction() {
|
2014-04-28 04:05:08 +00:00
|
|
|
assert(CurMI != nullptr);
|
2011-03-25 17:20:59 +00:00
|
|
|
// Don't create a new label after DBG_VALUE instructions.
|
|
|
|
// They don't generate code.
|
2013-12-03 15:10:23 +00:00
|
|
|
if (!CurMI->isDebugValue())
|
2014-04-24 06:44:33 +00:00
|
|
|
PrevLabel = nullptr;
|
2011-03-25 17:20:59 +00:00
|
|
|
|
2013-11-19 09:04:36 +00:00
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
2013-12-03 15:10:23 +00:00
|
|
|
LabelsAfterInsn.find(CurMI);
|
2014-04-24 06:44:33 +00:00
|
|
|
CurMI = nullptr;
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-07-03 04:24:43 +00:00
|
|
|
const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
|
2010-07-21 21:21:52 +00:00
|
|
|
if (!Children.empty())
|
2014-03-07 19:09:39 +00:00
|
|
|
WorkList.append(Children.begin(), Children.end());
|
2010-01-20 02:05:23 +00:00
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
if (S->isAbstractScope())
|
|
|
|
continue;
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const InsnRange &R : S->getRanges()) {
|
|
|
|
assert(R.first && "InsnRange does not have first instruction!");
|
|
|
|
assert(R.second && "InsnRange does not have second instruction!");
|
|
|
|
requestLabelBeforeInsn(R.first);
|
|
|
|
requestLabelAfterInsn(R.second);
|
2010-04-27 19:46:33 +00:00
|
|
|
}
|
2009-10-01 20:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 22:47:41 +00:00
|
|
|
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
|
|
|
|
// First known non-DBG_VALUE and non-frame setup location marks
|
|
|
|
// the beginning of the function body.
|
|
|
|
for (const auto &MBB : *MF)
|
|
|
|
for (const auto &MI : MBB)
|
|
|
|
if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) &&
|
|
|
|
!MI.getDebugLoc().isUnknown())
|
|
|
|
return MI.getDebugLoc();
|
|
|
|
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) {
|
2013-12-03 15:10:23 +00:00
|
|
|
CurFn = MF;
|
2013-11-01 23:14:17 +00:00
|
|
|
|
|
|
|
// If there's no debug info for the function we're not going to do anything.
|
|
|
|
if (!MMI->hasDebugInfo())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Grab the lexical scopes for the function, if we don't have any of those
|
|
|
|
// then we're not going to be able to do anything.
|
2011-08-10 20:55:27 +00:00
|
|
|
LScopes.initialize(*MF);
|
2014-03-20 19:16:16 +00:00
|
|
|
if (LScopes.empty())
|
2013-11-01 23:14:17 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-30 23:02:40 +00:00
|
|
|
assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
|
2013-11-01 23:14:17 +00:00
|
|
|
|
|
|
|
// Make sure that each lexical scope will have a begin/end label.
|
2011-08-10 20:55:27 +00:00
|
|
|
identifyScopeMarkers();
|
2009-10-06 18:37:31 +00:00
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
|
2013-11-01 23:14:17 +00:00
|
|
|
// belongs to so that we add to the correct per-cu line table in the
|
|
|
|
// non-asm case.
|
2013-02-05 21:52:47 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
2013-12-09 23:57:44 +00:00
|
|
|
DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
2013-02-05 21:52:47 +00:00
|
|
|
assert(TheCU && "Unable to find compile unit!");
|
2014-02-05 18:00:21 +00:00
|
|
|
if (Asm->OutStreamer.hasRawTextSupport())
|
|
|
|
// Use a single line table if we are generating assembly.
|
2013-05-21 00:57:22 +00:00
|
|
|
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
|
|
|
|
else
|
|
|
|
Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
|
2013-02-05 21:52:47 +00:00
|
|
|
|
2013-11-01 23:14:17 +00:00
|
|
|
// Emit a label for the function so that we have a beginning address.
|
|
|
|
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
|
|
|
|
2014-04-30 21:34:11 +00:00
|
|
|
// Calculate history for local variables.
|
|
|
|
calculateDbgValueHistory(MF, Asm->TM.getRegisterInfo(), DbgValues);
|
|
|
|
|
|
|
|
// Request labels for the full history.
|
2014-05-27 23:09:50 +00:00
|
|
|
for (const auto &I : DbgValues) {
|
|
|
|
const auto &Ranges = I.second;
|
|
|
|
if (Ranges.empty())
|
2011-03-26 02:19:36 +00:00
|
|
|
continue;
|
|
|
|
|
2014-04-30 21:34:11 +00:00
|
|
|
// The first mention of a function argument gets the FunctionBeginSym
|
|
|
|
// label, so arguments are visible when breaking at function entry.
|
|
|
|
DIVariable DV(I.first);
|
|
|
|
if (DV.isVariable() && DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
|
|
|
getDISubprogram(DV.getContext()).describes(MF->getFunction()))
|
2014-05-27 23:09:50 +00:00
|
|
|
LabelsBeforeInsn[Ranges.front().first] = FunctionBeginSym;
|
2014-04-30 21:34:11 +00:00
|
|
|
|
2014-05-27 23:09:50 +00:00
|
|
|
for (const auto &Range : Ranges) {
|
|
|
|
requestLabelBeforeInsn(Range.first);
|
|
|
|
if (Range.second)
|
|
|
|
requestLabelAfterInsn(Range.second);
|
2011-03-26 02:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
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.
|
2014-05-27 22:47:41 +00:00
|
|
|
PrologEndLoc = findPrologueEndLoc(MF);
|
2011-05-11 19:22:19 +00:00
|
|
|
if (!PrologEndLoc.isUnknown()) {
|
2013-11-01 23:14:17 +00:00
|
|
|
DebugLoc FnStartDL =
|
2014-01-30 01:39:17 +00:00
|
|
|
PrologEndLoc.getFnDebugLoc(MF->getFunction()->getContext());
|
2013-11-01 23:14:17 +00:00
|
|
|
recordSourceLine(
|
|
|
|
FnStartDL.getLine(), FnStartDL.getCol(),
|
|
|
|
FnStartDL.getScope(MF->getFunction()->getContext()),
|
|
|
|
// 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.
|
|
|
|
DWARF2_FLAG_IS_STMT);
|
2011-05-11 19:22:19 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 05:41:06 +00:00
|
|
|
void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
|
2014-06-05 01:04:20 +00:00
|
|
|
if (addCurrentFnArgument(Var, LS))
|
|
|
|
return;
|
2014-04-22 05:41:06 +00:00
|
|
|
SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS];
|
|
|
|
DIVariable DV = Var->getVariable();
|
2013-06-06 21:04:51 +00:00
|
|
|
// Variables with positive arg numbers are parameters.
|
|
|
|
if (unsigned ArgNum = DV.getArgNumber()) {
|
|
|
|
// Keep all parameters in order at the start of the variable list to ensure
|
|
|
|
// function types are correct (no out-of-order parameters)
|
|
|
|
//
|
|
|
|
// This could be improved by only doing it for optimized builds (unoptimized
|
|
|
|
// builds have the right order to begin with), searching from the back (this
|
|
|
|
// would catch the unoptimized case quickly), or doing a binary search
|
|
|
|
// rather than linear search.
|
2014-04-22 05:41:06 +00:00
|
|
|
SmallVectorImpl<DbgVariable *>::iterator I = Vars.begin();
|
2013-06-06 21:04:51 +00:00
|
|
|
while (I != Vars.end()) {
|
2014-04-22 05:41:06 +00:00
|
|
|
unsigned CurNum = (*I)->getVariable().getArgNumber();
|
2013-06-06 21:04:51 +00:00
|
|
|
// A local (non-parameter) variable has been found, insert immediately
|
|
|
|
// before it.
|
|
|
|
if (CurNum == 0)
|
|
|
|
break;
|
|
|
|
// A later indexed parameter has been found, insert immediately before it.
|
2013-06-06 22:28:26 +00:00
|
|
|
if (CurNum > ArgNum)
|
2013-06-06 21:04:51 +00:00
|
|
|
break;
|
2013-06-06 22:28:26 +00:00
|
|
|
++I;
|
2013-06-05 05:39:59 +00:00
|
|
|
}
|
2014-04-22 05:41:06 +00:00
|
|
|
Vars.insert(I, Var);
|
|
|
|
return;
|
2013-06-05 05:39:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 05:41:06 +00:00
|
|
|
Vars.push_back(Var);
|
2011-08-10 20:55:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Gather and emit post-function debug information.
|
2013-12-03 13:15:54 +00:00
|
|
|
void DwarfDebug::endFunction(const MachineFunction *MF) {
|
2013-12-03 15:10:23 +00:00
|
|
|
// Every beginFunction(MF) call should be followed by an endFunction(MF) call,
|
|
|
|
// though the beginFunction may not be called at all.
|
|
|
|
// We should handle both cases.
|
2014-04-24 06:44:33 +00:00
|
|
|
if (!CurFn)
|
2013-12-03 15:10:23 +00:00
|
|
|
CurFn = MF;
|
|
|
|
else
|
|
|
|
assert(CurFn == MF);
|
2014-04-28 04:05:08 +00:00
|
|
|
assert(CurFn != nullptr);
|
2013-12-03 15:10:23 +00:00
|
|
|
|
|
|
|
if (!MMI->hasDebugInfo() || LScopes.empty()) {
|
2014-03-20 19:16:16 +00:00
|
|
|
// If we don't have a lexical scope for this function then there will
|
|
|
|
// be a hole in the range information. Keep note of this by setting the
|
|
|
|
// previously used section to nullptr.
|
|
|
|
PrevSection = nullptr;
|
|
|
|
PrevCU = nullptr;
|
2014-04-24 06:44:33 +00:00
|
|
|
CurFn = nullptr;
|
2013-11-19 09:04:36 +00:00
|
|
|
return;
|
2013-12-03 15:10:23 +00:00
|
|
|
}
|
2010-05-22 00:04:14 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
// Define end label for subprogram.
|
2013-11-19 09:04:36 +00:00
|
|
|
FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
|
2011-08-10 20:55:27 +00:00
|
|
|
// Assumes in correct section after the entry point.
|
|
|
|
Asm->OutStreamer.EmitLabel(FunctionEndSym);
|
2014-01-29 23:05:43 +00:00
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to default value.
|
2013-02-05 21:52:47 +00:00
|
|
|
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;
|
2013-12-03 15:10:23 +00:00
|
|
|
collectVariableInfo(ProcessedVars);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-08-15 22:04:40 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &TheCU = *SPMap.lookup(FnScope->getScopeNode());
|
2011-08-15 22:04:40 +00:00
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
// Construct abstract scopes.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
|
2011-08-12 18:10:19 +00:00
|
|
|
DISubprogram SP(AScope->getScopeNode());
|
2014-05-12 18:23:35 +00:00
|
|
|
if (!SP.isSubprogram())
|
|
|
|
continue;
|
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
DIArray Variables = SP.getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
|
|
|
assert(DV && DV.isVariable());
|
|
|
|
if (!ProcessedVars.insert(DV))
|
|
|
|
continue;
|
2014-06-13 23:52:55 +00:00
|
|
|
ensureAbstractVariableIsCreated(DV, DV.getContext());
|
2010-06-25 22:07:34 +00:00
|
|
|
}
|
2014-05-12 18:23:35 +00:00
|
|
|
constructAbstractSubprogramScopeDIE(TheCU, AScope);
|
2011-08-10 20:55:27 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2014-04-29 15:58:35 +00:00
|
|
|
DIE &CurFnDIE = constructSubprogramScopeDIE(TheCU, FnScope);
|
2013-12-03 15:10:23 +00:00
|
|
|
if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
|
2011-08-15 22:04:40 +00:00
|
|
|
|
2014-01-29 23:05:43 +00:00
|
|
|
// Add the range of this function to the list of ranges for the CU.
|
|
|
|
RangeSpan Span(FunctionBeginSym, FunctionEndSym);
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addRange(std::move(Span));
|
2014-03-20 19:16:16 +00:00
|
|
|
PrevSection = Asm->getCurrentSection();
|
2014-04-22 22:39:41 +00:00
|
|
|
PrevCU = &TheCU;
|
2014-01-29 23:05:43 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Clear debug info
|
2014-05-21 22:41:17 +00:00
|
|
|
// Ownership of DbgVariables is a bit subtle - ScopeVariables owns all the
|
|
|
|
// DbgVariables except those that are also in AbstractVariables (since they
|
|
|
|
// can be used cross-function)
|
2011-08-10 20:55:27 +00:00
|
|
|
ScopeVariables.clear();
|
2014-06-13 22:18:23 +00:00
|
|
|
CurrentFnArguments.clear();
|
2011-03-26 02:19:36 +00:00
|
|
|
DbgValues.clear();
|
2010-04-27 19:46:33 +00:00
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.clear();
|
2014-04-24 06:44:33 +00:00
|
|
|
PrevLabel = nullptr;
|
|
|
|
CurFn = nullptr;
|
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;
|
2014-03-03 18:53:17 +00:00
|
|
|
unsigned Discriminator = 0;
|
2014-05-15 20:18:50 +00:00
|
|
|
if (DIScope Scope = DIScope(S)) {
|
|
|
|
assert(Scope.isScope());
|
|
|
|
Fn = Scope.getFilename();
|
|
|
|
Dir = Scope.getDirectory();
|
|
|
|
if (Scope.isLexicalBlock())
|
|
|
|
Discriminator = DILexicalBlock(S).getDiscriminator();
|
2010-05-05 23:41:32 +00:00
|
|
|
|
2014-03-17 23:53:25 +00:00
|
|
|
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
|
2014-04-22 21:27:37 +00:00
|
|
|
Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
|
|
|
|
.getOrCreateSourceID(Fn, Dir);
|
2010-05-05 23:41:32 +00:00
|
|
|
}
|
2014-03-03 18:53:17 +00:00
|
|
|
Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
|
|
|
|
Discriminator, 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
|
|
|
// 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 =
|
2013-11-19 09:04:36 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
|
2014-05-21 23:27:41 +00:00
|
|
|
if (useSplitDwarf())
|
2013-12-30 17:22:27 +00:00
|
|
|
DwarfInfoDWOSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfInfoDWOSection(), "section_info_dwo");
|
2010-07-21 21:21:52 +00:00
|
|
|
DwarfAbbrevSectionSym =
|
2013-11-19 09:04:36 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
|
2012-12-19 22:02:53 +00:00
|
|
|
if (useSplitDwarf())
|
2013-11-19 09:04:36 +00:00
|
|
|
DwarfAbbrevDWOSectionSym = emitSectionSym(
|
|
|
|
Asm, TLOF.getDwarfAbbrevDWOSection(), "section_abbrev_dwo");
|
2014-02-25 22:46:44 +00:00
|
|
|
if (GenerateARangeSection)
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfARangesSection());
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2013-02-07 21:19:50 +00:00
|
|
|
DwarfLineSectionSym =
|
2013-11-19 09:04:36 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
|
2013-09-23 20:55:35 +00:00
|
|
|
if (GenerateGnuPubSections) {
|
2013-09-30 23:14:16 +00:00
|
|
|
DwarfGnuPubNamesSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfGnuPubNamesSection());
|
|
|
|
DwarfGnuPubTypesSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfGnuPubTypesSection());
|
2013-09-23 20:55:35 +00:00
|
|
|
} else if (HasDwarfPubSections) {
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
|
2013-09-04 04:39:38 +00:00
|
|
|
}
|
2013-09-13 00:35:05 +00:00
|
|
|
|
2010-07-21 21:21:52 +00:00
|
|
|
DwarfStrSectionSym =
|
2013-11-19 09:04:36 +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 =
|
2013-11-19 09:04:36 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfStrDWOSection(), "skel_string");
|
2013-04-07 03:43:09 +00:00
|
|
|
DwarfAddrSectionSym =
|
2013-11-19 09:04:36 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfAddrSection(), "addr_sec");
|
2014-04-01 16:09:49 +00:00
|
|
|
DwarfDebugLocSectionSym =
|
2014-03-25 01:44:02 +00:00
|
|
|
emitSectionSym(Asm, TLOF.getDwarfLocDWOSection(), "skel_loc");
|
|
|
|
} else
|
|
|
|
DwarfDebugLocSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfLocSection(), "section_debug_loc");
|
2013-11-19 09:04:36 +00:00
|
|
|
DwarfDebugRangeSectionSym =
|
|
|
|
emitSectionSym(Asm, TLOF.getDwarfRangesSection(), "debug_range");
|
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.
|
2014-04-14 22:45:02 +00:00
|
|
|
void DwarfDebug::emitDIE(DIE &Die) {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Get the abbreviation for this DIE.
|
2014-04-14 22:45:02 +00:00
|
|
|
const DIEAbbrev &Abbrev = Die.getAbbrev();
|
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())
|
2013-12-05 01:01:41 +00:00
|
|
|
Asm->OutStreamer.AddComment("Abbrev [" + Twine(Abbrev.getNumber()) +
|
2014-04-14 22:45:02 +00:00
|
|
|
"] 0x" + Twine::utohexstr(Die.getOffset()) +
|
|
|
|
":0x" + Twine::utohexstr(Die.getSize()) + " " +
|
2013-12-05 01:01:41 +00:00
|
|
|
dwarf::TagString(Abbrev.getTag()));
|
|
|
|
Asm->EmitULEB128(Abbrev.getNumber());
|
2009-05-20 23:04:56 +00:00
|
|
|
|
2014-04-14 22:45:02 +00:00
|
|
|
const SmallVectorImpl<DIEValue *> &Values = Die.getValues();
|
2013-12-05 01:01:41 +00:00
|
|
|
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) {
|
2013-10-21 17:28:37 +00:00
|
|
|
dwarf::Attribute Attr = AbbrevData[i].getAttribute();
|
|
|
|
dwarf::Form Form = AbbrevData[i].getForm();
|
2009-05-20 23:21:38 +00:00
|
|
|
assert(Form && "Too many attributes for DIE (check abbreviation)");
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2014-03-06 00:00:49 +00:00
|
|
|
if (Asm->isVerbose()) {
|
2010-01-24 18:54:17 +00:00
|
|
|
Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
|
2014-03-06 00:00:49 +00:00
|
|
|
if (Attr == dwarf::DW_AT_accessibility)
|
|
|
|
Asm->OutStreamer.AddComment(dwarf::AccessibilityString(
|
|
|
|
cast<DIEInteger>(Values[i])->getValue()));
|
|
|
|
}
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2014-03-06 00:00:56 +00:00
|
|
|
// Emit an attribute using the defined form.
|
|
|
|
Values[i]->EmitValue(Asm, Form);
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
// Emit the DIE children if any.
|
2014-03-05 01:44:58 +00:00
|
|
|
if (Abbrev.hasChildren()) {
|
2014-04-14 22:45:02 +00:00
|
|
|
for (auto &Child : Die.getChildren())
|
|
|
|
emitDIE(*Child);
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-12-04 21:51:05 +00:00
|
|
|
Asm->OutStreamer.AddComment("End Of Children Mark");
|
2010-03-09 23:52:58 +00:00
|
|
|
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-11-30 23:59:06 +00:00
|
|
|
// Emit the debug info section.
|
|
|
|
void DwarfDebug::emitDebugInfo() {
|
2013-12-05 18:06:10 +00:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2012-12-15 00:04:07 +00:00
|
|
|
|
2014-03-24 20:31:01 +00:00
|
|
|
Holder.emitUnits(this, 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() {
|
2013-12-05 18:06:10 +00:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2013-12-05 07:43:55 +00:00
|
|
|
|
|
|
|
Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
|
2012-12-19 22:02:53 +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
|
|
|
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(
|
|
|
|
Asm->GetTempSymbol("section_end", SectionEnd),
|
|
|
|
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() {
|
2014-04-23 23:46:25 +00:00
|
|
|
AccelNames.FinalizeTable(Asm, "Names");
|
2011-11-07 09:24:32 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->getObjFileLowering().getDwarfAccelNamesSection());
|
2011-11-07 09:24:32 +00:00
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("names_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2014-04-23 23:46:25 +00:00
|
|
|
AccelNames.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() {
|
2014-04-24 00:53:32 +00:00
|
|
|
AccelObjC.FinalizeTable(Asm, "ObjC");
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelObjCSection());
|
2011-11-07 09:24:32 +00:00
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("objc_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2014-04-24 00:53:32 +00:00
|
|
|
AccelObjC.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() {
|
2014-04-24 01:02:42 +00:00
|
|
|
AccelNamespace.FinalizeTable(Asm, "namespac");
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelNamespaceSection());
|
2011-11-07 09:24:32 +00:00
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("namespac_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2014-04-24 01:02:42 +00:00
|
|
|
AccelNamespace.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() {
|
|
|
|
|
2014-04-24 01:23:49 +00:00
|
|
|
AccelTypes.FinalizeTable(Asm, "types");
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelTypesSection());
|
2011-11-07 09:24:32 +00:00
|
|
|
MCSymbol *SectionBegin = Asm->GetTempSymbol("types_begin");
|
|
|
|
Asm->OutStreamer.EmitLabel(SectionBegin);
|
|
|
|
|
|
|
|
// Emit the full data.
|
2014-04-24 01:23:49 +00:00
|
|
|
AccelTypes.Emit(Asm, SectionBegin, &InfoHolder);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
// Public name handling.
|
|
|
|
// The format for the various pubnames:
|
|
|
|
//
|
|
|
|
// dwarf pubnames - offset/name pairs where the offset is the offset into the CU
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// gnu pubnames - offset/index value/name tuples where the offset is the offset
|
|
|
|
// into the CU and the index value is computed according to the type of value
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// For type units the offset is the offset of the skeleton DIE. For split dwarf
|
|
|
|
// it's the offset within the debug_info/debug_types dwo section, however, the
|
|
|
|
// reference in the pubname header doesn't change.
|
|
|
|
|
|
|
|
/// computeIndexValue - Compute the gdb index value for the DIE and CU.
|
2013-12-09 23:32:48 +00:00
|
|
|
static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
|
2013-11-21 00:48:22 +00:00
|
|
|
const DIE *Die) {
|
2013-10-16 01:37:49 +00:00
|
|
|
dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC;
|
|
|
|
|
|
|
|
// We could have a specification DIE that has our most of our knowledge,
|
|
|
|
// look for that now.
|
|
|
|
DIEValue *SpecVal = Die->findAttribute(dwarf::DW_AT_specification);
|
|
|
|
if (SpecVal) {
|
2014-04-25 19:33:43 +00:00
|
|
|
DIE &SpecDIE = cast<DIEEntry>(SpecVal)->getEntry();
|
|
|
|
if (SpecDIE.findAttribute(dwarf::DW_AT_external))
|
2013-10-16 01:37:49 +00:00
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
|
|
|
} else if (Die->findAttribute(dwarf::DW_AT_external))
|
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
2013-09-13 00:35:05 +00:00
|
|
|
|
|
|
|
switch (Die->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
2013-09-23 20:55:35 +00:00
|
|
|
return dwarf::PubIndexEntryDescriptor(
|
|
|
|
dwarf::GIEK_TYPE, CU->getLanguage() != dwarf::DW_LANG_C_plus_plus
|
|
|
|
? dwarf::GIEL_STATIC
|
|
|
|
: dwarf::GIEL_EXTERNAL);
|
2013-09-13 00:35:05 +00:00
|
|
|
case dwarf::DW_TAG_typedef:
|
|
|
|
case dwarf::DW_TAG_base_type:
|
|
|
|
case dwarf::DW_TAG_subrange_type:
|
2013-09-19 20:40:26 +00:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC);
|
2013-09-13 00:35:05 +00:00
|
|
|
case dwarf::DW_TAG_namespace:
|
2013-09-19 20:40:26 +00:00
|
|
|
return dwarf::GIEK_TYPE;
|
2013-09-13 00:35:05 +00:00
|
|
|
case dwarf::DW_TAG_subprogram:
|
2013-09-23 22:59:14 +00:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, Linkage);
|
2013-09-13 00:35:05 +00:00
|
|
|
case dwarf::DW_TAG_constant:
|
|
|
|
case dwarf::DW_TAG_variable:
|
2013-09-23 22:59:14 +00:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, Linkage);
|
2013-09-13 00:35:05 +00:00
|
|
|
case dwarf::DW_TAG_enumerator:
|
2013-09-19 20:40:26 +00:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE,
|
|
|
|
dwarf::GIEL_STATIC);
|
2013-09-13 00:35:05 +00:00
|
|
|
default:
|
2013-09-19 20:40:26 +00:00
|
|
|
return dwarf::GIEK_NONE;
|
2013-09-13 00:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:03:17 +00:00
|
|
|
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
|
2013-02-12 18:00:14 +00:00
|
|
|
///
|
2013-09-13 00:35:05 +00:00
|
|
|
void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
|
|
|
|
const MCSection *PSec =
|
|
|
|
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubNamesSection();
|
2013-02-12 18:00:14 +00:00
|
|
|
|
2014-03-11 23:18:15 +00:00
|
|
|
emitDebugPubSection(GnuStyle, PSec, "Names", &DwarfUnit::getGlobalNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitDebugPubSection(
|
|
|
|
bool GnuStyle, const MCSection *PSec, StringRef Name,
|
|
|
|
const StringMap<const DIE *> &(DwarfUnit::*Accessor)() const) {
|
2014-03-06 01:42:00 +00:00
|
|
|
for (const auto &NU : CUMap) {
|
|
|
|
DwarfCompileUnit *TheU = NU.second;
|
2014-03-11 23:23:39 +00:00
|
|
|
|
|
|
|
const auto &Globals = (TheU->*Accessor)();
|
|
|
|
|
2014-03-11 23:35:06 +00:00
|
|
|
if (Globals.empty())
|
|
|
|
continue;
|
|
|
|
|
2014-03-06 01:42:00 +00:00
|
|
|
if (auto Skeleton = static_cast<DwarfCompileUnit *>(TheU->getSkeleton()))
|
|
|
|
TheU = Skeleton;
|
2013-12-02 22:09:48 +00:00
|
|
|
unsigned ID = TheU->getUniqueID();
|
2013-02-12 18:00:14 +00:00
|
|
|
|
|
|
|
// Start the dwarf pubnames section.
|
2013-09-10 21:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(PSec);
|
2013-02-12 18:00:14 +00:00
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
// Emit the header.
|
2014-03-11 23:18:15 +00:00
|
|
|
Asm->OutStreamer.AddComment("Length of Public " + Name + " Info");
|
|
|
|
MCSymbol *BeginLabel = Asm->GetTempSymbol("pub" + Name + "_begin", ID);
|
|
|
|
MCSymbol *EndLabel = Asm->GetTempSymbol("pub" + Name + "_end", ID);
|
2013-12-04 17:55:41 +00:00
|
|
|
Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
|
2013-02-12 18:00:14 +00:00
|
|
|
|
2013-12-04 17:55:41 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(BeginLabel);
|
2013-02-12 18:00:14 +00:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("DWARF Version");
|
2013-08-21 06:13:34 +00:00
|
|
|
Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
|
2013-02-12 18:00:14 +00:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
|
2013-12-06 22:33:05 +00:00
|
|
|
Asm->EmitSectionOffset(TheU->getLabelBegin(), TheU->getSectionSym());
|
2013-02-12 18:00:14 +00:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Compilation Unit Length");
|
2013-12-06 22:33:05 +00:00
|
|
|
Asm->EmitLabelDifference(TheU->getLabelEnd(), TheU->getLabelBegin(), 4);
|
2013-02-12 18:00:14 +00:00
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
// Emit the pubnames for this compilation unit.
|
2014-03-11 23:23:39 +00:00
|
|
|
for (const auto &GI : Globals) {
|
2014-03-07 19:09:39 +00:00
|
|
|
const char *Name = GI.getKeyData();
|
|
|
|
const DIE *Entity = GI.second;
|
2013-02-12 18:00:14 +00:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("DIE offset");
|
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
if (GnuStyle) {
|
2013-12-02 22:09:48 +00:00
|
|
|
dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheU, Entity);
|
2013-09-19 22:19:37 +00:00
|
|
|
Asm->OutStreamer.AddComment(
|
2013-09-20 00:33:15 +00:00
|
|
|
Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " +
|
2013-09-19 23:01:29 +00:00
|
|
|
dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
|
2013-09-19 22:19:37 +00:00
|
|
|
Asm->EmitInt8(Desc.toBits());
|
2013-09-13 00:35:05 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 21:51:05 +00:00
|
|
|
Asm->OutStreamer.AddComment("External Name");
|
2014-03-07 19:09:39 +00:00
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Name, GI.getKeyLength() + 1));
|
2013-02-12 18:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("End Mark");
|
|
|
|
Asm->EmitInt32(0);
|
2013-12-04 17:55:41 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(EndLabel);
|
2013-02-12 18:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 00:35:05 +00:00
|
|
|
void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
|
2013-09-23 20:55:35 +00:00
|
|
|
const MCSection *PSec =
|
|
|
|
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubTypesSection();
|
2013-09-13 00:34:58 +00:00
|
|
|
|
2014-03-11 23:18:15 +00:00
|
|
|
emitDebugPubSection(GnuStyle, PSec, "Types", &DwarfUnit::getGlobalTypes);
|
2009-11-24 01:14:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 02:14:01 +00:00
|
|
|
// Emit visible names into a debug str section.
|
|
|
|
void DwarfDebug::emitDebugStr() {
|
2013-12-05 18:06:10 +00:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2012-12-27 02:14:01 +00:00
|
|
|
Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection());
|
|
|
|
}
|
|
|
|
|
2014-03-07 22:40:37 +00:00
|
|
|
void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
|
2014-03-18 02:18:24 +00:00
|
|
|
const DebugLocEntry &Entry) {
|
2014-04-27 18:25:40 +00:00
|
|
|
assert(Entry.getValues().size() == 1 &&
|
2014-04-28 20:42:22 +00:00
|
|
|
"multi-value entries are not supported yet.");
|
2014-04-27 18:25:40 +00:00
|
|
|
const DebugLocEntry::Value Value = Entry.getValues()[0];
|
|
|
|
DIVariable DV(Value.getVariable());
|
|
|
|
if (Value.isInt()) {
|
2014-03-18 02:34:58 +00:00
|
|
|
DIBasicType BTy(resolve(DV.getType()));
|
2014-03-07 22:40:37 +00:00
|
|
|
if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
|
|
|
|
BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts");
|
2014-04-27 18:25:40 +00:00
|
|
|
Streamer.EmitSLEB128(Value.getInt());
|
2014-03-07 22:40:37 +00:00
|
|
|
} else {
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
|
2014-04-27 18:25:40 +00:00
|
|
|
Streamer.EmitULEB128(Value.getInt());
|
2014-03-07 22:40:37 +00:00
|
|
|
}
|
2014-04-27 18:25:40 +00:00
|
|
|
} else if (Value.isLocation()) {
|
|
|
|
MachineLocation Loc = Value.getLoc();
|
2014-03-07 22:40:37 +00:00
|
|
|
if (!DV.hasComplexAddress())
|
|
|
|
// Regular entry.
|
|
|
|
Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
|
|
|
|
else {
|
|
|
|
// Complex address entry.
|
|
|
|
unsigned N = DV.getNumAddrElements();
|
|
|
|
unsigned i = 0;
|
|
|
|
if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) {
|
|
|
|
if (Loc.getOffset()) {
|
|
|
|
i = 2;
|
|
|
|
Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_plus_uconst, "DW_OP_plus_uconst");
|
|
|
|
Streamer.EmitSLEB128(DV.getAddrElement(1));
|
|
|
|
} else {
|
|
|
|
// If first address element is OpPlus then emit
|
|
|
|
// DW_OP_breg + Offset instead of DW_OP_reg + Offset.
|
|
|
|
MachineLocation TLoc(Loc.getReg(), DV.getAddrElement(1));
|
|
|
|
Asm->EmitDwarfRegOp(Streamer, TLoc, DV.isIndirect());
|
|
|
|
i = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit remaining complex address elements.
|
|
|
|
for (; i < N; ++i) {
|
|
|
|
uint64_t Element = DV.getAddrElement(i);
|
|
|
|
if (Element == DIBuilder::OpPlus) {
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_plus_uconst, "DW_OP_plus_uconst");
|
|
|
|
Streamer.EmitULEB128(DV.getAddrElement(++i));
|
|
|
|
} else if (Element == DIBuilder::OpDeref) {
|
|
|
|
if (!Loc.isReg())
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
|
|
|
|
} else
|
|
|
|
llvm_unreachable("unknown Opcode found in complex address");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else ... ignore constant fp. There is not any good way to
|
|
|
|
// to represent them here in dwarf.
|
|
|
|
// FIXME: ^
|
|
|
|
}
|
|
|
|
|
2014-04-01 16:17:41 +00:00
|
|
|
void DwarfDebug::emitDebugLocEntryLocation(const DebugLocEntry &Entry) {
|
|
|
|
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);
|
|
|
|
// Emit the entry.
|
|
|
|
APByteStreamer Streamer(*Asm);
|
|
|
|
emitDebugLocEntry(Streamer, Entry);
|
|
|
|
// Close the range.
|
|
|
|
Asm->OutStreamer.EmitLabel(end);
|
|
|
|
}
|
|
|
|
|
2013-07-02 21:36:07 +00:00
|
|
|
// Emit locations into the debug loc section.
|
2009-11-21 02:48:08 +00:00
|
|
|
void DwarfDebug::emitDebugLoc() {
|
2011-03-16 22:16:39 +00:00
|
|
|
// Start the dwarf loc section.
|
2009-08-19 05:49:37 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2014-04-02 01:50:20 +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();
|
2014-03-24 22:38:38 +00:00
|
|
|
for (const auto &DebugLoc : DotDebugLocEntries) {
|
2014-04-02 01:43:18 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(DebugLoc.Label);
|
|
|
|
for (const auto &Entry : DebugLoc.List) {
|
2014-03-20 19:16:16 +00:00
|
|
|
// Set up the range. This range is relative to the entry point of the
|
|
|
|
// compile unit. This is a hard coded 0 for low_pc when we're emitting
|
|
|
|
// ranges, or the DW_AT_low_pc on the compile unit otherwise.
|
|
|
|
const DwarfCompileUnit *CU = Entry.getCU();
|
2014-04-02 01:50:20 +00:00
|
|
|
if (CU->getRanges().size() == 1) {
|
2014-03-20 19:16:16 +00:00
|
|
|
// Grab the begin symbol from the first range as our base.
|
|
|
|
const MCSymbol *Base = CU->getRanges()[0].getStart();
|
|
|
|
Asm->EmitLabelDifference(Entry.getBeginSym(), Base, Size);
|
|
|
|
Asm->EmitLabelDifference(Entry.getEndSym(), Base, Size);
|
|
|
|
} else {
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.getBeginSym(), Size);
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.getEndSym(), Size);
|
|
|
|
}
|
2014-04-02 01:50:20 +00:00
|
|
|
|
2014-04-01 16:17:41 +00:00
|
|
|
emitDebugLocEntryLocation(Entry);
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
2014-04-02 01:50:20 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitDebugLocDWO() {
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLocDWOSection());
|
|
|
|
for (const auto &DebugLoc : DotDebugLocEntries) {
|
|
|
|
Asm->OutStreamer.EmitLabel(DebugLoc.Label);
|
|
|
|
for (const auto &Entry : DebugLoc.List) {
|
|
|
|
// Just always use start_length for now - at least that's one address
|
|
|
|
// rather than two. We could get fancier and try to, say, reuse an
|
|
|
|
// address we know we've emitted elsewhere (the start of the function?
|
|
|
|
// The start of the CU or CU subrange that encloses this range?)
|
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_start_length_entry);
|
2014-04-23 21:20:10 +00:00
|
|
|
unsigned idx = AddrPool.getIndex(Entry.getBeginSym());
|
2014-04-02 01:50:20 +00:00
|
|
|
Asm->EmitULEB128(idx);
|
|
|
|
Asm->EmitLabelDifference(Entry.getEndSym(), Entry.getBeginSym(), 4);
|
|
|
|
|
|
|
|
emitDebugLocEntryLocation(Entry);
|
2014-03-25 01:44:02 +00:00
|
|
|
}
|
2014-04-02 01:50:20 +00:00
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_end_of_list_entry);
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2013-09-19 23:21:01 +00:00
|
|
|
struct ArangeSpan {
|
|
|
|
const MCSymbol *Start, *End;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Emit a debug aranges section, containing a CU lookup for any
|
|
|
|
// address we can tie back to a CU.
|
2012-11-21 00:34:35 +00:00
|
|
|
void DwarfDebug::emitDebugARanges() {
|
2009-05-20 23:21:38 +00:00
|
|
|
// Start the dwarf aranges section.
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfARangesSection());
|
2013-09-19 23:21:01 +00:00
|
|
|
|
2014-04-28 20:42:22 +00:00
|
|
|
typedef DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> SpansType;
|
2013-09-19 23:21:01 +00:00
|
|
|
|
|
|
|
SpansType Spans;
|
|
|
|
|
|
|
|
// Build a list of sections used.
|
|
|
|
std::vector<const MCSection *> Sections;
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const auto &it : SectionMap) {
|
|
|
|
const MCSection *Section = it.first;
|
2013-09-19 23:21:01 +00:00
|
|
|
Sections.push_back(Section);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the sections into order.
|
|
|
|
// This is only done to ensure consistent output order across different runs.
|
|
|
|
std::sort(Sections.begin(), Sections.end(), SectionSort);
|
|
|
|
|
|
|
|
// Build a set of address spans, sorted by CU.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const MCSection *Section : Sections) {
|
2014-04-22 05:41:06 +00:00
|
|
|
SmallVector<SymbolCU, 8> &List = SectionMap[Section];
|
2013-09-19 23:21:01 +00:00
|
|
|
if (List.size() < 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Sort the symbols by offset within the section.
|
2014-03-07 19:41:22 +00:00
|
|
|
std::sort(List.begin(), List.end(),
|
|
|
|
[&](const SymbolCU &A, const SymbolCU &B) {
|
|
|
|
unsigned IA = A.Sym ? Asm->OutStreamer.GetSymbolOrder(A.Sym) : 0;
|
|
|
|
unsigned IB = B.Sym ? Asm->OutStreamer.GetSymbolOrder(B.Sym) : 0;
|
|
|
|
|
|
|
|
// Symbols with no order assigned should be placed at the end.
|
|
|
|
// (e.g. section end labels)
|
|
|
|
if (IA == 0)
|
|
|
|
return false;
|
|
|
|
if (IB == 0)
|
|
|
|
return true;
|
|
|
|
return IA < IB;
|
|
|
|
});
|
2013-09-19 23:21:01 +00:00
|
|
|
|
|
|
|
// If we have no section (e.g. common), just write out
|
|
|
|
// individual spans for each symbol.
|
2014-04-24 06:44:33 +00:00
|
|
|
if (!Section) {
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const SymbolCU &Cur : List) {
|
2013-09-19 23:21:01 +00:00
|
|
|
ArangeSpan Span;
|
|
|
|
Span.Start = Cur.Sym;
|
2014-04-24 06:44:33 +00:00
|
|
|
Span.End = nullptr;
|
2013-09-19 23:21:01 +00:00
|
|
|
if (Cur.CU)
|
|
|
|
Spans[Cur.CU].push_back(Span);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Build spans between each label.
|
|
|
|
const MCSymbol *StartSym = List[0].Sym;
|
2014-03-07 19:09:39 +00:00
|
|
|
for (size_t n = 1, e = List.size(); n < e; n++) {
|
2013-09-19 23:21:01 +00:00
|
|
|
const SymbolCU &Prev = List[n - 1];
|
|
|
|
const SymbolCU &Cur = List[n];
|
|
|
|
|
|
|
|
// Try and build the longest span we can within the same CU.
|
|
|
|
if (Cur.CU != Prev.CU) {
|
|
|
|
ArangeSpan Span;
|
|
|
|
Span.Start = StartSym;
|
|
|
|
Span.End = Cur.Sym;
|
|
|
|
Spans[Prev.CU].push_back(Span);
|
|
|
|
StartSym = Cur.Sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PtrSize = Asm->getDataLayout().getPointerSize();
|
|
|
|
|
|
|
|
// Build a list of CUs used.
|
2013-12-09 23:57:44 +00:00
|
|
|
std::vector<DwarfCompileUnit *> CUs;
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const auto &it : Spans) {
|
|
|
|
DwarfCompileUnit *CU = it.first;
|
2013-09-19 23:21:01 +00:00
|
|
|
CUs.push_back(CU);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the CU list (again, to ensure consistent output order).
|
2014-03-07 19:41:22 +00:00
|
|
|
std::sort(CUs.begin(), CUs.end(), [](const DwarfUnit *A, const DwarfUnit *B) {
|
|
|
|
return A->getUniqueID() < B->getUniqueID();
|
|
|
|
});
|
2013-09-19 23:21:01 +00:00
|
|
|
|
|
|
|
// Emit an arange table for each CU we used.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (DwarfCompileUnit *CU : CUs) {
|
2013-09-19 23:21:01 +00:00
|
|
|
std::vector<ArangeSpan> &List = Spans[CU];
|
|
|
|
|
|
|
|
// Emit size of content not including length itself.
|
2013-11-19 09:04:36 +00:00
|
|
|
unsigned ContentSize =
|
|
|
|
sizeof(int16_t) + // DWARF ARange version number
|
|
|
|
sizeof(int32_t) + // Offset of CU in the .debug_info section
|
|
|
|
sizeof(int8_t) + // Pointer Size (in bytes)
|
|
|
|
sizeof(int8_t); // Segment Size (in bytes)
|
2013-09-19 23:21:01 +00:00
|
|
|
|
|
|
|
unsigned TupleSize = PtrSize * 2;
|
|
|
|
|
|
|
|
// 7.20 in the Dwarf specs requires the table to be aligned to a tuple.
|
2014-01-07 19:28:14 +00:00
|
|
|
unsigned Padding =
|
|
|
|
OffsetToAlignment(sizeof(int32_t) + ContentSize, TupleSize);
|
2013-09-19 23:21:01 +00:00
|
|
|
|
|
|
|
ContentSize += Padding;
|
|
|
|
ContentSize += (List.size() + 1) * TupleSize;
|
|
|
|
|
|
|
|
// For each compile unit, write the list of spans it covers.
|
|
|
|
Asm->OutStreamer.AddComment("Length of ARange Set");
|
|
|
|
Asm->EmitInt32(ContentSize);
|
|
|
|
Asm->OutStreamer.AddComment("DWARF Arange version number");
|
|
|
|
Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
|
|
|
|
Asm->OutStreamer.AddComment("Offset Into Debug Info Section");
|
2013-12-30 17:22:27 +00:00
|
|
|
Asm->EmitSectionOffset(CU->getLocalLabelBegin(), CU->getLocalSectionSym());
|
2013-09-19 23:21:01 +00:00
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
|
|
|
Asm->EmitInt8(PtrSize);
|
|
|
|
Asm->OutStreamer.AddComment("Segment Size (in bytes)");
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
|
2014-01-07 19:28:14 +00:00
|
|
|
Asm->OutStreamer.EmitFill(Padding, 0xff);
|
2013-09-19 23:21:01 +00:00
|
|
|
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const ArangeSpan &Span : List) {
|
2013-09-19 23:21:01 +00:00
|
|
|
Asm->EmitLabelReference(Span.Start, PtrSize);
|
|
|
|
|
|
|
|
// Calculate the size as being from the span start to it's end.
|
2013-09-23 17:56:20 +00:00
|
|
|
if (Span.End) {
|
2013-09-19 23:21:01 +00:00
|
|
|
Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize);
|
2013-09-23 17:56:20 +00:00
|
|
|
} else {
|
|
|
|
// For symbols without an end marker (e.g. common), we
|
|
|
|
// write a single arange entry containing just that one symbol.
|
|
|
|
uint64_t Size = SymSize[Span.Start];
|
|
|
|
if (Size == 0)
|
|
|
|
Size = 1;
|
|
|
|
|
|
|
|
Asm->OutStreamer.EmitIntValue(Size, PtrSize);
|
|
|
|
}
|
2013-09-19 23:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("ARange terminator");
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, PtrSize);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, PtrSize);
|
|
|
|
}
|
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.
|
2013-11-19 09:04:36 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfRangesSection());
|
2013-12-03 00:45:45 +00:00
|
|
|
|
|
|
|
// Size for our labels.
|
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-12-03 00:45:45 +00:00
|
|
|
|
|
|
|
// Grab the specific ranges for the compile units in the module.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const auto &I : CUMap) {
|
|
|
|
DwarfCompileUnit *TheCU = I.second;
|
2013-12-03 00:45:45 +00:00
|
|
|
|
|
|
|
// Iterate over the misc ranges for the compile units in the module.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const RangeSpanList &List : TheCU->getRangeLists()) {
|
2013-12-04 22:04:50 +00:00
|
|
|
// Emit our symbol so we can find the beginning of the range.
|
|
|
|
Asm->OutStreamer.EmitLabel(List.getSym());
|
2013-12-03 00:45:45 +00:00
|
|
|
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const RangeSpan &Range : List.getRanges()) {
|
2013-12-03 00:45:45 +00:00
|
|
|
const MCSymbol *Begin = Range.getStart();
|
|
|
|
const MCSymbol *End = Range.getEnd();
|
2013-12-20 04:34:22 +00:00
|
|
|
assert(Begin && "Range without a begin symbol?");
|
|
|
|
assert(End && "Range without an end symbol?");
|
2014-04-25 22:23:54 +00:00
|
|
|
if (TheCU->getRanges().size() == 1) {
|
|
|
|
// Grab the begin symbol from the first range as our base.
|
|
|
|
const MCSymbol *Base = TheCU->getRanges()[0].getStart();
|
|
|
|
Asm->EmitLabelDifference(Begin, Base, Size);
|
|
|
|
Asm->EmitLabelDifference(End, Base, Size);
|
|
|
|
} else {
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Begin, Size);
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(End, Size);
|
|
|
|
}
|
2013-12-03 00:45:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And terminate the list with two 0 values.
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
2013-01-09 01:35:34 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
2013-12-03 00:45:45 +00:00
|
|
|
}
|
2013-12-20 04:16:18 +00:00
|
|
|
|
|
|
|
// Now emit a range for the CU itself.
|
2014-03-20 19:16:16 +00:00
|
|
|
if (TheCU->getRanges().size() > 1) {
|
2013-12-20 04:16:18 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(
|
|
|
|
Asm->GetTempSymbol("cu_ranges", TheCU->getUniqueID()));
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const RangeSpan &Range : TheCU->getRanges()) {
|
2013-12-20 04:16:18 +00:00
|
|
|
const MCSymbol *Begin = Range.getStart();
|
|
|
|
const MCSymbol *End = Range.getEnd();
|
2013-12-20 04:34:22 +00:00
|
|
|
assert(Begin && "Range without a begin symbol?");
|
|
|
|
assert(End && "Range without an end symbol?");
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Begin, Size);
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(End, Size);
|
2013-12-20 04:16:18 +00:00
|
|
|
}
|
|
|
|
// And terminate the list with two 0 values.
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size);
|
|
|
|
}
|
2010-04-16 23:33:45 +00:00
|
|
|
}
|
2009-05-20 23:21:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 19:42:09 +00:00
|
|
|
// DWARF5 Experimental Separate Dwarf emitters.
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
|
2014-04-22 22:39:41 +00:00
|
|
|
std::unique_ptr<DwarfUnit> NewU) {
|
2014-01-09 04:28:46 +00:00
|
|
|
NewU->addLocalString(Die, dwarf::DW_AT_GNU_dwo_name,
|
2014-04-22 22:39:41 +00:00
|
|
|
U.getCUNode().getSplitDebugFilename());
|
2014-01-09 04:28:46 +00:00
|
|
|
|
|
|
|
if (!CompilationDir.empty())
|
|
|
|
NewU->addLocalString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
addGnuPubAttributes(*NewU, Die);
|
2014-01-09 04:28:46 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
SkeletonHolder.addUnit(std::move(NewU));
|
2014-01-09 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2014-03-24 21:31:35 +00:00
|
|
|
// DW_AT_addr_base, DW_AT_ranges_base.
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
2014-04-28 21:14:27 +00:00
|
|
|
CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder);
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
|
|
|
NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
|
2014-04-22 23:09:36 +00:00
|
|
|
DwarfInfoSectionSym);
|
2013-01-17 03:00:04 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
NewCU.initStmtList(DwarfLineSectionSym);
|
2012-11-30 23:59:06 +00:00
|
|
|
|
2014-04-28 21:04:29 +00:00
|
|
|
initSkeletonUnit(CU, NewCU.getUnitDie(), std::move(OwnedUnit));
|
2012-12-10 23:34:43 +00:00
|
|
|
|
2012-11-30 23:59:06 +00:00
|
|
|
return NewCU;
|
|
|
|
}
|
|
|
|
|
2014-01-10 01:38:41 +00:00
|
|
|
// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_dwo_name,
|
|
|
|
// DW_AT_addr_base.
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfTypeUnit &DwarfDebug::constructSkeletonTU(DwarfTypeUnit &TU) {
|
2014-02-14 23:58:13 +00:00
|
|
|
DwarfCompileUnit &CU = static_cast<DwarfCompileUnit &>(
|
2014-04-22 22:39:41 +00:00
|
|
|
*SkeletonHolder.getUnits()[TU.getCU().getUniqueID()]);
|
2014-01-10 01:38:41 +00:00
|
|
|
|
2014-04-28 21:14:27 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfTypeUnit>(TU.getUniqueID(), CU, Asm, this,
|
|
|
|
&SkeletonHolder);
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfTypeUnit &NewTU = *OwnedUnit;
|
|
|
|
NewTU.setTypeSignature(TU.getTypeSignature());
|
2014-04-24 06:44:33 +00:00
|
|
|
NewTU.setType(nullptr);
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.initSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfTypesSection(TU.getTypeSignature()));
|
|
|
|
|
2014-04-28 21:04:29 +00:00
|
|
|
initSkeletonUnit(TU, NewTU.getUnitDie(), std::move(OwnedUnit));
|
2014-01-10 01:38:41 +00:00
|
|
|
return NewTU;
|
|
|
|
}
|
|
|
|
|
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?");
|
2014-04-02 02:04:51 +00:00
|
|
|
// Don't pass an abbrev symbol, using a constant zero instead so as not to
|
|
|
|
// emit relocations into the dwo file.
|
2014-04-28 20:42:22 +00:00
|
|
|
InfoHolder.emitUnits(this, /* AbbrevSymbol */ nullptr);
|
2012-12-19 22:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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?");
|
2013-12-05 07:43:55 +00:00
|
|
|
InfoHolder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection());
|
2012-11-30 23:59:06 +00:00
|
|
|
}
|
2012-12-27 02:14:01 +00:00
|
|
|
|
2014-03-18 01:17:26 +00:00
|
|
|
void DwarfDebug::emitDebugLineDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLineDWOSection());
|
2014-03-18 02:13:23 +00:00
|
|
|
SplitTypeUnitFileTable.Emit(Asm->OutStreamer);
|
2014-03-18 01:17:26 +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-11-19 09:04:36 +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
|
|
|
}
|
2013-11-19 23:08:21 +00:00
|
|
|
|
2014-03-19 00:11:28 +00:00
|
|
|
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
|
|
|
|
if (!useSplitDwarf())
|
|
|
|
return nullptr;
|
|
|
|
if (SingleCU)
|
|
|
|
SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode().getDirectory());
|
|
|
|
return &SplitTypeUnitFileTable;
|
|
|
|
}
|
|
|
|
|
2014-04-26 16:26:41 +00:00
|
|
|
static uint64_t makeTypeSignature(StringRef Identifier) {
|
|
|
|
MD5 Hash;
|
|
|
|
Hash.update(Identifier);
|
|
|
|
// ... take the least significant 8 bytes and return those. Our MD5
|
|
|
|
// implementation always returns its results in little endian, swap bytes
|
|
|
|
// appropriately.
|
|
|
|
MD5::MD5Result Result;
|
|
|
|
Hash.final(Result);
|
|
|
|
return *reinterpret_cast<support::ulittle64_t *>(Result + 8);
|
|
|
|
}
|
|
|
|
|
2014-02-12 00:31:30 +00:00
|
|
|
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
|
2014-04-25 18:26:14 +00:00
|
|
|
StringRef Identifier, DIE &RefDie,
|
2014-01-09 03:23:41 +00:00
|
|
|
DICompositeType CTy) {
|
2014-04-26 17:27:38 +00:00
|
|
|
// Fast path if we're building some type units and one has already used the
|
|
|
|
// address pool we know we're going to throw away all this work anyway, so
|
|
|
|
// don't bother building dependent types.
|
|
|
|
if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
|
|
|
|
return;
|
|
|
|
|
2013-12-17 23:32:35 +00:00
|
|
|
const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
|
2014-01-20 08:07:07 +00:00
|
|
|
if (TU) {
|
2014-02-12 00:31:30 +00:00
|
|
|
CU.addDIETypeSignature(RefDie, *TU);
|
2014-01-20 08:07:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-26 17:27:38 +00:00
|
|
|
bool TopLevelType = TypeUnitsUnderConstruction.empty();
|
|
|
|
AddrPool.resetUsedFlag();
|
|
|
|
|
2014-05-21 23:27:41 +00:00
|
|
|
auto OwnedUnit =
|
|
|
|
make_unique<DwarfTypeUnit>(InfoHolder.getUnits().size(), CU, Asm, this,
|
|
|
|
&InfoHolder, getDwoLineTable(CU));
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfTypeUnit &NewTU = *OwnedUnit;
|
2014-04-28 21:04:29 +00:00
|
|
|
DIE &UnitDie = NewTU.getUnitDie();
|
2014-04-22 22:39:41 +00:00
|
|
|
TU = &NewTU;
|
2014-04-28 20:42:22 +00:00
|
|
|
TypeUnitsUnderConstruction.push_back(
|
|
|
|
std::make_pair(std::move(OwnedUnit), CTy));
|
2014-04-22 22:39:41 +00:00
|
|
|
|
2014-04-28 21:04:29 +00:00
|
|
|
NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
2014-04-22 23:09:36 +00:00
|
|
|
CU.getLanguage());
|
2014-01-20 08:07:07 +00:00
|
|
|
|
2014-04-26 16:26:41 +00:00
|
|
|
uint64_t Signature = makeTypeSignature(Identifier);
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.setTypeSignature(Signature);
|
2014-04-26 16:26:41 +00:00
|
|
|
|
2014-05-21 23:27:41 +00:00
|
|
|
if (!useSplitDwarf())
|
2014-04-28 21:04:29 +00:00
|
|
|
CU.applyStmtList(UnitDie);
|
2014-05-21 23:27:41 +00:00
|
|
|
|
2014-05-23 16:53:14 +00:00
|
|
|
// FIXME: Skip using COMDAT groups for type units in the .dwo file once tools
|
|
|
|
// such as DWP ( http://gcc.gnu.org/wiki/DebugFissionDWP ) can cope with it.
|
2014-05-21 23:27:41 +00:00
|
|
|
NewTU.initSection(
|
|
|
|
useSplitDwarf()
|
|
|
|
? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
|
|
|
|
: Asm->getObjFileLowering().getDwarfTypesSection(Signature));
|
2014-01-20 08:07:07 +00:00
|
|
|
|
2014-04-26 16:26:41 +00:00
|
|
|
NewTU.setType(NewTU.createTypeDIE(CTy));
|
|
|
|
|
2014-04-26 17:27:38 +00:00
|
|
|
if (TopLevelType) {
|
|
|
|
auto TypeUnitsToAdd = std::move(TypeUnitsUnderConstruction);
|
|
|
|
TypeUnitsUnderConstruction.clear();
|
|
|
|
|
|
|
|
// Types referencing entries in the address table cannot be placed in type
|
|
|
|
// units.
|
|
|
|
if (AddrPool.hasBeenUsed()) {
|
|
|
|
|
|
|
|
// Remove all the types built while building this type.
|
|
|
|
// This is pessimistic as some of these types might not be dependent on
|
|
|
|
// the type that used an address.
|
|
|
|
for (const auto &TU : TypeUnitsToAdd)
|
|
|
|
DwarfTypeUnits.erase(TU.second);
|
|
|
|
|
|
|
|
// Construct this type in the CU directly.
|
|
|
|
// This is inefficient because all the dependent types will be rebuilt
|
|
|
|
// from scratch, including building them in type units, discovering that
|
|
|
|
// they depend on addresses, throwing them out and rebuilding them.
|
|
|
|
CU.constructTypeDIE(RefDie, CTy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the type wasn't dependent on fission addresses, finish adding the type
|
|
|
|
// and all its dependent types.
|
|
|
|
for (auto &TU : TypeUnitsToAdd) {
|
|
|
|
if (useSplitDwarf())
|
|
|
|
TU.first->setSkeleton(constructSkeletonTU(*TU.first));
|
|
|
|
InfoHolder.addUnit(std::move(TU.first));
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 22:39:41 +00:00
|
|
|
CU.addDIETypeSignature(RefDie, NewTU);
|
2013-11-19 23:08:21 +00:00
|
|
|
}
|
2014-03-07 18:49:45 +00:00
|
|
|
|
2014-04-25 18:26:14 +00:00
|
|
|
void DwarfDebug::attachLowHighPC(DwarfCompileUnit &Unit, DIE &D,
|
2014-03-07 18:49:45 +00:00
|
|
|
MCSymbol *Begin, MCSymbol *End) {
|
2014-05-16 16:42:40 +00:00
|
|
|
assert(Begin && "Begin label should not be null!");
|
|
|
|
assert(End && "End label should not be null!");
|
|
|
|
assert(Begin->isDefined() && "Invalid starting label");
|
|
|
|
assert(End->isDefined() && "Invalid end label");
|
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
Unit.addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
|
2014-03-07 23:07:21 +00:00
|
|
|
if (DwarfVersion < 4)
|
2014-04-22 22:39:41 +00:00
|
|
|
Unit.addLabelAddress(D, dwarf::DW_AT_high_pc, End);
|
2014-03-07 18:49:45 +00:00
|
|
|
else
|
2014-04-22 22:39:41 +00:00
|
|
|
Unit.addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
|
2014-03-07 18:49:45 +00:00
|
|
|
}
|
2014-04-23 23:37:35 +00:00
|
|
|
|
|
|
|
// Accelerator table mutators - add each name along with its companion
|
|
|
|
// DIE to the proper table while ensuring that the name that we're going
|
|
|
|
// to reference is in the string table. We do this since the names we
|
|
|
|
// add may not only be identical to the names in the DIE.
|
2014-04-25 18:52:29 +00:00
|
|
|
void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
|
2014-04-23 23:37:35 +00:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2014-04-25 22:21:35 +00:00
|
|
|
AccelNames.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
|
|
|
|
&Die);
|
2014-04-23 23:37:35 +00:00
|
|
|
}
|
2014-04-24 00:53:32 +00:00
|
|
|
|
2014-04-25 18:52:29 +00:00
|
|
|
void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
|
2014-04-24 00:53:32 +00:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2014-04-25 22:21:35 +00:00
|
|
|
AccelObjC.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
|
|
|
|
&Die);
|
2014-04-24 00:53:32 +00:00
|
|
|
}
|
2014-04-24 01:02:42 +00:00
|
|
|
|
2014-04-25 18:52:29 +00:00
|
|
|
void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
|
2014-04-24 01:02:42 +00:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2014-04-25 22:21:35 +00:00
|
|
|
AccelNamespace.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
|
|
|
|
&Die);
|
2014-04-24 01:02:42 +00:00
|
|
|
}
|
2014-04-24 01:23:49 +00:00
|
|
|
|
2014-04-25 18:52:29 +00:00
|
|
|
void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
|
2014-04-24 01:23:49 +00:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2014-04-25 22:21:35 +00:00
|
|
|
AccelTypes.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
|
|
|
|
&Die);
|
2014-04-24 01:23:49 +00:00
|
|
|
}
|