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-11-21 23:46:41 +00:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
DwarfVersionNumber("dwarf-version", cl::Hidden,
|
2013-12-09 23:32:48 +00:00
|
|
|
cl::desc("Generate DWARF for dwarf version."), cl::init(0));
|
2013-11-21 23:46:41 +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-01-11 00:28:12 +00:00
|
|
|
DwarfVersion = DwarfVersionNumber
|
|
|
|
? DwarfVersionNumber
|
2014-04-17 22:33:50 +00:00
|
|
|
: MMI->getModule()->getDwarfVersion();
|
2013-07-02 23:40:10 +00:00
|
|
|
|
2010-06-18 15:56:31 +00:00
|
|
|
{
|
|
|
|
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
|
2012-11-19 22:42:15 +00:00
|
|
|
beginModule();
|
2010-04-07 10:44:46 +00:00
|
|
|
}
|
2009-05-15 09:23:25 +00:00
|
|
|
}
|
|
|
|
|
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-24 01:25:10 +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-22 22:39:41 +00:00
|
|
|
DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU,
|
2013-12-09 23:57:44 +00:00
|
|
|
DISubprogram SP) {
|
2014-04-22 22:39:41 +00:00
|
|
|
DIE *SPDie = SPCU.getDIE(SP);
|
2010-07-07 22:20:57 +00:00
|
|
|
|
2010-04-05 00:13:49 +00:00
|
|
|
assert(SPDie && "Unable to find subprogram DIE!");
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2012-11-07 05:19:04 +00:00
|
|
|
// If we're updating an abstract DIE, then we will be adding the children and
|
|
|
|
// object pointer later on. But what we don't want to do is process the
|
|
|
|
// concrete DIE twice.
|
2013-11-15 23:13:08 +00:00
|
|
|
if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) {
|
2012-11-07 05:19:04 +00:00
|
|
|
// Pick up abstract subprogram DIE.
|
2014-04-22 23:09:36 +00:00
|
|
|
SPDie = SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU.getUnitDie());
|
2014-04-22 22:39:41 +00:00
|
|
|
SPCU.addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE);
|
2012-11-07 04:42:18 +00:00
|
|
|
} else {
|
|
|
|
DISubprogram SPDecl = SP.getFunctionDeclaration();
|
|
|
|
if (!SPDecl.isSubprogram()) {
|
|
|
|
// There is not any need to generate specification DIE for a function
|
|
|
|
// defined at compile unit level. If a function is defined inside another
|
|
|
|
// function then gdb prefers the definition at top level and but does not
|
|
|
|
// expect specification DIE in parent function. So avoid creating
|
|
|
|
// specification DIE for a function defined inside a function.
|
2013-10-10 18:40:01 +00:00
|
|
|
DIScope SPContext = resolve(SP.getContext());
|
|
|
|
if (SP.isDefinition() && !SPContext.isCompileUnit() &&
|
2013-11-19 09:04:36 +00:00
|
|
|
!SPContext.isFile() && !isSubprogramContext(SPContext)) {
|
2014-04-22 22:39:41 +00:00
|
|
|
SPCU.addFlag(SPDie, dwarf::DW_AT_declaration);
|
2012-11-07 04:42:18 +00:00
|
|
|
|
|
|
|
// Add arguments.
|
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
2013-08-08 01:41:00 +00:00
|
|
|
uint16_t SPTag = SPTy.getTag();
|
2012-11-07 04:42:18 +00:00
|
|
|
if (SPTag == dwarf::DW_TAG_subroutine_type)
|
2014-04-22 22:39:41 +00:00
|
|
|
SPCU.constructSubprogramArguments(*SPDie, Args);
|
2012-11-07 04:42:18 +00:00
|
|
|
DIE *SPDeclDie = SPDie;
|
2014-04-22 23:09:36 +00:00
|
|
|
SPDie =
|
|
|
|
SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU.getUnitDie());
|
2014-04-22 22:39:41 +00:00
|
|
|
SPCU.addDIEEntry(SPDie, dwarf::DW_AT_specification, SPDeclDie);
|
2012-11-07 04:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-07 22:20:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 18:49:45 +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-22 22:39:41 +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-24 01:25:10 +00:00
|
|
|
addSubprogramNames(SP, SPDie);
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2010-04-05 00:13:49 +00:00
|
|
|
return SPDie;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
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-22 22:39:41 +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-22 22:39:41 +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
|
|
|
}
|
|
|
|
|
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-22 22:39:41 +00:00
|
|
|
DIE *DwarfDebug::constructLexicalScopeDIE(DwarfCompileUnit &TheCU,
|
2011-08-15 22:24:32 +00:00
|
|
|
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
|
|
|
|
2010-04-23 01:18:53 +00:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block);
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return ScopeDIE;
|
|
|
|
|
2013-12-03 00:45:45 +00:00
|
|
|
const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
|
2013-12-03 00:45:59 +00:00
|
|
|
|
2013-07-03 01:57:28 +00:00
|
|
|
// If we have multiple ranges, emit them into the range section.
|
2013-12-03 00:45:45 +00:00
|
|
|
if (ScopeRanges.size() > 1) {
|
2013-12-03 00:45:59 +00:00
|
|
|
addScopeRangeList(TheCU, ScopeDIE, ScopeRanges);
|
2010-04-27 19:46:33 +00:00
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:57:28 +00:00
|
|
|
// Construct the address range for this DIE.
|
2013-12-03 00:45:45 +00:00
|
|
|
SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin();
|
2013-01-15 23:56:56 +00:00
|
|
|
MCSymbol *Start = getLabelBeforeInsn(RI->first);
|
|
|
|
MCSymbol *End = getLabelAfterInsn(RI->second);
|
2013-09-10 18:40:41 +00:00
|
|
|
assert(End && "End label should not be null!");
|
2010-04-27 19:46:33 +00:00
|
|
|
|
|
|
|
assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
|
|
|
|
assert(End->isDefined() && "Invalid end label for an inlined scope!");
|
2010-07-21 21:21:52 +00:00
|
|
|
|
2014-03-08 00:58:20 +00:00
|
|
|
attachLowHighPC(TheCU, ScopeDIE, Start, End);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// This scope represents inlined body of a function. Construct DIE to
|
|
|
|
// represent this concrete inlined copy of the function.
|
2014-04-22 22:39:41 +00:00
|
|
|
DIE *DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
|
2011-08-15 22:24:32 +00:00
|
|
|
LexicalScope *Scope) {
|
2013-12-03 00:45:45 +00:00
|
|
|
const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
|
2013-12-04 21:20:15 +00:00
|
|
|
assert(!ScopeRanges.empty() &&
|
2011-10-26 22:55:33 +00:00
|
|
|
"LexicalScope does not have instruction markers!");
|
2010-04-27 19:46:33 +00:00
|
|
|
|
2011-07-27 00:34:13 +00:00
|
|
|
if (!Scope->getScopeNode())
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2011-07-27 00:34:13 +00:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
|
|
|
DISubprogram InlinedSP = getDISubprogram(DS);
|
2014-04-22 22:39:41 +00:00
|
|
|
DIE *OriginDIE = TheCU.getDIE(InlinedSP);
|
2011-07-27 00:34:13 +00:00
|
|
|
if (!OriginDIE) {
|
2012-10-30 17:51:02 +00:00
|
|
|
DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram.");
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2011-07-27 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
2011-05-05 17:54:26 +00:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2013-12-03 00:45:59 +00:00
|
|
|
// If we have multiple ranges, emit them into the range section.
|
|
|
|
if (ScopeRanges.size() > 1)
|
|
|
|
addScopeRangeList(TheCU, ScopeDIE, ScopeRanges);
|
|
|
|
else {
|
2013-12-03 00:45:45 +00:00
|
|
|
SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin();
|
2013-07-03 02:23:53 +00:00
|
|
|
MCSymbol *StartLabel = getLabelBeforeInsn(RI->first);
|
|
|
|
MCSymbol *EndLabel = getLabelAfterInsn(RI->second);
|
|
|
|
|
2014-04-24 06:44:33 +00:00
|
|
|
if (!StartLabel || !EndLabel)
|
2013-07-03 02:23:53 +00:00
|
|
|
llvm_unreachable("Unexpected Start and End labels for an inlined scope!");
|
|
|
|
|
|
|
|
assert(StartLabel->isDefined() &&
|
|
|
|
"Invalid starting label for an inlined scope!");
|
|
|
|
assert(EndLabel->isDefined() && "Invalid end label for an inlined scope!");
|
|
|
|
|
2014-03-07 22:00:56 +00:00
|
|
|
attachLowHighPC(TheCU, ScopeDIE, StartLabel, EndLabel);
|
2011-07-27 00:34:13 +00:00
|
|
|
}
|
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-22 23:09:36 +00:00
|
|
|
TheCU.addUInt(ScopeDIE, dwarf::DW_AT_call_file, None,
|
|
|
|
TheCU.getOrCreateSourceID(DL.getFilename(), DL.getDirectory()));
|
2014-04-22 22:39:41 +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-24 01:25:10 +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-22 22:39:41 +00:00
|
|
|
DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit &TheCU,
|
2013-12-09 23:57:44 +00:00
|
|
|
LexicalScope *Scope,
|
2013-11-19 09:04:36 +00:00
|
|
|
SmallVectorImpl<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)
|
|
|
|
if (ArgDV)
|
|
|
|
if (DIE *Arg =
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.constructVariableDIE(*ArgDV, Scope->isAbstractScope())) {
|
2014-04-22 05:41:06 +00:00
|
|
|
Children.push_back(Arg);
|
|
|
|
if (ArgDV->isObjectPointer())
|
|
|
|
ObjectPointer = Arg;
|
|
|
|
}
|
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-02-25 19:57:42 +00:00
|
|
|
DIE *Ellipsis = new DIE(dwarf::DW_TAG_unspecified_parameters);
|
|
|
|
Children.push_back(Ellipsis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 15:49:16 +00:00
|
|
|
// Collect lexical scope children first.
|
2014-04-22 05:41:06 +00:00
|
|
|
for (DbgVariable *DV : ScopeVariables.lookup(Scope))
|
2014-04-22 23:09:36 +00:00
|
|
|
if (DIE *Variable =
|
|
|
|
TheCU.constructVariableDIE(*DV, Scope->isAbstractScope())) {
|
2011-02-19 01:31:27 +00:00
|
|
|
Children.push_back(Variable);
|
2014-04-22 05:41:06 +00:00
|
|
|
if (DV->isObjectPointer())
|
2013-11-19 09:04:36 +00:00
|
|
|
ObjectPointer = Variable;
|
2012-09-21 22:18:52 +00:00
|
|
|
}
|
2014-03-07 19:09:39 +00:00
|
|
|
for (LexicalScope *LS : Scope->getChildren())
|
|
|
|
if (DIE *Nested = constructScopeDIE(TheCU, LS))
|
2011-02-19 01:31:27 +00:00
|
|
|
Children.push_back(Nested);
|
2013-09-10 18:40:41 +00:00
|
|
|
return ObjectPointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a DIE for this scope.
|
2014-04-22 22:39:41 +00:00
|
|
|
DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
|
2013-12-09 23:57:44 +00:00
|
|
|
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
|
|
|
|
|
|
|
SmallVector<DIE *, 8> Children;
|
2014-04-24 06:44:33 +00:00
|
|
|
DIE *ObjectPointer = nullptr;
|
2013-09-10 18:40:41 +00:00
|
|
|
bool ChildrenCreated = false;
|
|
|
|
|
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-24 06:44:33 +00:00
|
|
|
DIE *ScopeDIE = nullptr;
|
2010-03-08 20:52:55 +00:00
|
|
|
if (Scope->getInlinedAt())
|
2011-08-15 22:24:32 +00:00
|
|
|
ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);
|
2010-03-08 20:52:55 +00:00
|
|
|
else if (DS.isSubprogram()) {
|
2010-06-28 20:53:04 +00:00
|
|
|
ProcessedSPNodes.insert(DS);
|
2010-07-07 22:20:57 +00:00
|
|
|
if (Scope->isAbstractScope()) {
|
2014-04-22 22:39:41 +00:00
|
|
|
ScopeDIE = TheCU.getDIE(DS);
|
2010-07-07 22:20:57 +00:00
|
|
|
// Note down abstract DIE.
|
|
|
|
if (ScopeDIE)
|
|
|
|
AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
|
2013-11-18 23:59:04 +00:00
|
|
|
} else
|
2013-11-15 23:13:08 +00:00
|
|
|
ScopeDIE = updateSubprogramScopeDIE(TheCU, DISubprogram(DS));
|
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.
|
2013-09-10 18:40:41 +00:00
|
|
|
ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children);
|
|
|
|
ChildrenCreated = true;
|
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 =
|
|
|
|
std::equal_range(
|
|
|
|
ScopesWithImportedEntities.begin(),
|
|
|
|
ScopesWithImportedEntities.end(),
|
2014-04-24 06:44:33 +00:00
|
|
|
std::pair<const MDNode *, const MDNode *>(DS, nullptr),
|
2013-11-19 09:04:36 +00:00
|
|
|
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)
|
2013-05-08 06:01:38 +00:00
|
|
|
constructImportedEntityDIE(TheCU, i->second, ScopeDIE);
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2013-08-24 11:55:49 +00:00
|
|
|
if (!ScopeDIE) {
|
2013-09-10 18:40:41 +00:00
|
|
|
assert(Children.empty() &&
|
|
|
|
"We create children only when the scope DIE is not null.");
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2013-08-24 11:55:49 +00:00
|
|
|
}
|
2013-09-10 18:40:41 +00:00
|
|
|
if (!ChildrenCreated)
|
2013-09-11 19:40:28 +00:00
|
|
|
// We create children when the scope DIE is not null.
|
2013-09-10 18:40:41 +00:00
|
|
|
ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children);
|
2009-11-10 23:06:00 +00:00
|
|
|
|
2011-02-19 01:31:27 +00:00
|
|
|
// Add children
|
2014-03-07 19:09:39 +00:00
|
|
|
for (DIE *I : Children)
|
|
|
|
ScopeDIE->addChild(I);
|
2009-11-24 01:14:22 +00:00
|
|
|
|
2014-04-24 06:44:33 +00:00
|
|
|
if (DS.isSubprogram() && ObjectPointer != nullptr)
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer);
|
2012-09-12 23:36:19 +00:00
|
|
|
|
2011-11-10 19:25:34 +00:00
|
|
|
return ScopeDIE;
|
2009-11-10 23:06:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 22:39:41 +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
|
|
|
|
2009-05-20 23:21:38 +00:00
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
2013-12-09 23:57:44 +00:00
|
|
|
InfoHolder.getUnits().size(), Die, DIUnit, Asm, this, &InfoHolder);
|
2014-04-22 22:39:41 +00:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
|
|
|
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-22 22:39:41 +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-22 22:39:41 +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-22 22:39:41 +00:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2013-09-13 00:35:05 +00:00
|
|
|
|
2013-12-04 21:31:26 +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-22 22:39:41 +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-22 22:39:41 +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-22 22:39:41 +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));
|
|
|
|
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
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Construct subprogram DIE.
|
2014-04-22 22:39:41 +00:00
|
|
|
void DwarfDebug::constructSubprogramDIE(DwarfCompileUnit &TheCU,
|
2013-12-09 23:57:44 +00:00
|
|
|
const MDNode *N) {
|
2013-10-18 01:57:30 +00:00
|
|
|
// FIXME: We should only call this routine once, however, during LTO if a
|
|
|
|
// program is defined in multiple CUs we could end up calling it out of
|
|
|
|
// beginModule as we walk the CUs.
|
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
DwarfCompileUnit *&CURef = SPMap[N];
|
2013-10-18 01:57:30 +00:00
|
|
|
if (CURef)
|
|
|
|
return;
|
2014-04-22 22:39:41 +00:00
|
|
|
CURef = &TheCU;
|
2011-11-04 19:00:29 +00:00
|
|
|
|
2009-08-28 23:24:31 +00:00
|
|
|
DISubprogram SP(N);
|
2009-05-20 23:21:38 +00:00
|
|
|
if (!SP.isDefinition())
|
|
|
|
// This is a method declaration which will be handled while constructing
|
|
|
|
// class type.
|
2009-06-26 01:49:18 +00:00
|
|
|
return;
|
2009-05-20 23:04:56 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
DIE *SubprogramDie = TheCU.getOrCreateSubprogramDIE(SP);
|
2010-04-06 21:38:29 +00:00
|
|
|
|
2013-09-09 20:03:20 +00:00
|
|
|
// Expose as a global name.
|
2014-04-22 22:39:41 +00:00
|
|
|
TheCU.addGlobalName(SP.getName(), SubprogramDie, resolve(SP.getContext()));
|
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()))
|
2013-05-08 06:01:38 +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,
|
2013-12-09 23:57:44 +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,
|
2013-05-06 23:33:07 +00:00
|
|
|
DIE *Context) {
|
|
|
|
assert(Module.Verify() &&
|
|
|
|
"Use one of the MDNode * overloads to handle invalid metadata");
|
|
|
|
assert(Context && "Should always have a context for an imported_module");
|
2014-04-22 22:39:41 +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-22 22:39:41 +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)
|
|
|
|
constructSubprogramDIE(CU, SPs.getElement(i));
|
|
|
|
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
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
|
|
|
void DwarfDebug::computeInlinedDIEs() {
|
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (DIE *ISP : InlinedSubprogramDIEs)
|
2013-10-21 17:28:37 +00:00
|
|
|
FirstCU->addUInt(ISP, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
|
2014-03-07 19:09:39 +00:00
|
|
|
|
|
|
|
for (const auto &AI : AbstractSPDies) {
|
|
|
|
DIE *ISP = AI.second;
|
2012-11-22 00:59:49 +00:00
|
|
|
if (InlinedSubprogramDIEs.count(ISP))
|
|
|
|
continue;
|
2013-10-21 17:28:37 +00:00
|
|
|
FirstCU->addUInt(ISP, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
|
2012-11-22 00:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-19 22:42:15 +00:00
|
|
|
|
2012-11-22 00:59:49 +00:00
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
void DwarfDebug::collectDeadVariables() {
|
2010-06-28 18:25:03 +00:00
|
|
|
const Module *M = MMI->getModule();
|
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);
|
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;
|
|
|
|
if (!SP.isSubprogram())
|
|
|
|
continue;
|
|
|
|
if (!SP.isDefinition())
|
|
|
|
continue;
|
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
|
|
|
|
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
2013-12-09 23:57:44 +00:00
|
|
|
DwarfCompileUnit *SPCU =
|
|
|
|
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
|
2012-11-27 00:13:51 +00:00
|
|
|
assert(SPCU && "Unable to find Compile Unit!");
|
2013-10-22 00:22:39 +00:00
|
|
|
// FIXME: See the comment in constructSubprogramDIE about duplicate
|
|
|
|
// subprogram DIEs.
|
2014-04-22 22:39:41 +00:00
|
|
|
constructSubprogramDIE(*SPCU, SP);
|
2013-10-22 00:22:39 +00:00
|
|
|
DIE *SPDIE = SPCU->getDIE(SP);
|
2012-11-27 00:13:51 +00:00
|
|
|
for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
|
|
|
|
DIVariable DV(Variables.getElement(vi));
|
2013-10-15 23:31:38 +00:00
|
|
|
if (!DV.isVariable())
|
|
|
|
continue;
|
2014-04-24 06:44:33 +00:00
|
|
|
DbgVariable NewVar(DV, nullptr, this);
|
2013-11-19 09:04:36 +00:00
|
|
|
if (DIE *VariableDIE = SPCU->constructVariableDIE(NewVar, false))
|
2013-10-15 23:31:38 +00:00
|
|
|
SPDIE->addChild(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() {
|
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
collectDeadVariables();
|
2009-05-15 09:23:25 +00:00
|
|
|
|
2009-11-10 23:06:00 +00:00
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
2012-11-22 00:59:49 +00:00
|
|
|
computeInlinedDIEs();
|
2009-11-10 23:06:00 +00:00
|
|
|
|
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.
|
|
|
|
if (TheU->getUnitDie()->getTag() == dwarf::DW_TAG_compile_unit) {
|
|
|
|
// 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.
|
|
|
|
uint64_t ID = DIEHash(Asm).computeCUSignature(*TheU->getUnitDie());
|
2013-12-20 04:16:18 +00:00
|
|
|
TheU->addUInt(TheU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
|
|
|
dwarf::DW_FORM_data8, ID);
|
|
|
|
SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
|
|
|
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-22 22:39:41 +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-22 22:39:41 +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-22 22:39:41 +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-22 21:27:37 +00:00
|
|
|
U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
|
|
|
|
0);
|
2014-03-20 19:16:16 +00:00
|
|
|
} else {
|
|
|
|
RangeSpan &Range = TheU->getRanges().back();
|
2014-04-22 21:27:37 +00:00
|
|
|
U.addLocalLabelAddress(U.getUnitDie(), dwarf::DW_AT_low_pc,
|
|
|
|
Range.getStart());
|
|
|
|
U.addLabelDelta(U.getUnitDie(), dwarf::DW_AT_high_pc, Range.getEnd(),
|
|
|
|
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() {
|
2013-12-03 15:10:23 +00:00
|
|
|
assert(CurFn == 0);
|
|
|
|
assert(CurMI == 0);
|
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();
|
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
|
|
|
emitDebugLocDWO();
|
|
|
|
} 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();
|
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.
|
2011-08-10 21:50:54 +00:00
|
|
|
DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
|
2010-04-02 19:42:39 +00:00
|
|
|
DebugLoc ScopeLoc) {
|
2011-08-10 21:50:54 +00:00
|
|
|
LLVMContext &Ctx = DV->getContext();
|
|
|
|
// More then one inlined variable corresponds to one abstract variable.
|
|
|
|
DIVariable Var = cleanseInlinedVariable(DV, Ctx);
|
2010-05-07 18:11:54 +00:00
|
|
|
DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var);
|
2010-03-15 18:33:46 +00:00
|
|
|
if (AbsDbgVariable)
|
|
|
|
return AbsDbgVariable;
|
|
|
|
|
2011-08-10 20:55:27 +00:00
|
|
|
LexicalScope *Scope = LScopes.findAbstractScope(ScopeLoc.getScope(Ctx));
|
2010-03-15 18:33:46 +00:00
|
|
|
if (!Scope)
|
2014-04-24 06:44:33 +00:00
|
|
|
return nullptr;
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2014-04-24 06:44:33 +00:00
|
|
|
AbsDbgVariable = new DbgVariable(Var, nullptr, this);
|
2014-04-22 05:41:06 +00:00
|
|
|
addScopeVariable(Scope, AbsDbgVariable);
|
2010-05-07 18:11:54 +00:00
|
|
|
AbstractVariables[Var] = AbsDbgVariable;
|
2010-03-15 18:33:46 +00:00
|
|
|
return AbsDbgVariable;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// If Var is a current function argument then add it to CurrentFnArguments list.
|
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-03-09 15:44:39 +00:00
|
|
|
DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VI.Loc);
|
2014-04-22 05:41:06 +00:00
|
|
|
DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
|
|
|
|
RegVar->setFrameIndex(VI.Slot);
|
|
|
|
if (!addCurrentFnArgument(RegVar, Scope))
|
|
|
|
addScopeVariable(Scope, RegVar);
|
2011-08-15 19:01:20 +00:00
|
|
|
if (AbsDbgVariable)
|
2014-03-09 15:44:39 +00:00
|
|
|
AbsDbgVariable->setFrameIndex(VI.Slot);
|
2009-10-06 01:26:37 +00:00
|
|
|
}
|
2010-05-20 19:57:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Return true if debug value, encoded by DBG_VALUE instruction, is in a
|
|
|
|
// defined reg.
|
2010-05-25 23:40:22 +00:00
|
|
|
static bool isDbgValueInDefinedReg(const MachineInstr *MI) {
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!");
|
2013-11-19 09:04:36 +00:00
|
|
|
return MI->getNumOperands() == 3 && MI->getOperand(0).isReg() &&
|
|
|
|
MI->getOperand(0).getReg() &&
|
2013-07-09 20:28:37 +00:00
|
|
|
(MI->getOperand(1).isImm() ||
|
|
|
|
(MI->getOperand(1).isReg() && MI->getOperand(1).getReg() == 0U));
|
2010-05-25 23:40:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:45 +00:00
|
|
|
// Get .debug_loc entry for the instruction range starting at MI.
|
2014-03-18 02:18:24 +00:00
|
|
|
static DebugLocEntry getDebugLocEntry(AsmPrinter *Asm,
|
2014-03-20 19:16:16 +00:00
|
|
|
const MCSymbol *FLabel,
|
|
|
|
const MCSymbol *SLabel,
|
|
|
|
const MachineInstr *MI,
|
|
|
|
DwarfCompileUnit *Unit) {
|
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-03-20 19:16:16 +00:00
|
|
|
return DebugLocEntry(FLabel, SLabel, MLoc, Var, Unit);
|
2011-07-08 17:09:57 +00:00
|
|
|
}
|
|
|
|
if (MI->getOperand(0).isImm())
|
2014-04-11 17:49:47 +00:00
|
|
|
return DebugLocEntry(FLabel, SLabel, MI->getOperand(0).getImm(), Var, Unit);
|
2011-07-08 17:09:57 +00:00
|
|
|
if (MI->getOperand(0).isFPImm())
|
2014-04-11 17:49:47 +00:00
|
|
|
return DebugLocEntry(FLabel, SLabel, MI->getOperand(0).getFPImm(),
|
|
|
|
Var, Unit);
|
2011-07-08 17:09:57 +00:00
|
|
|
if (MI->getOperand(0).isCImm())
|
2014-04-11 17:49:47 +00:00
|
|
|
return DebugLocEntry(FLabel, SLabel, MI->getOperand(0).getCImm(),
|
|
|
|
Var, Unit);
|
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) {
|
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-03-07 19:09:39 +00:00
|
|
|
for (const MDNode *Var : UserVariables) {
|
2011-03-26 02:19:36 +00:00
|
|
|
if (Processed.count(Var))
|
2010-05-20 19:57:06 +00:00
|
|
|
continue;
|
2010-03-15 18:33:46 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// History contains relevant DBG_VALUE instructions for Var and instructions
|
|
|
|
// clobbering it.
|
2013-11-19 09:04:36 +00:00
|
|
|
SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var];
|
2011-03-26 02:19:36 +00:00
|
|
|
if (History.empty())
|
|
|
|
continue;
|
|
|
|
const MachineInstr *MInsn = History.front();
|
2010-05-25 23:40:22 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
DIVariable DV(Var);
|
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();
|
2013-03-11 23:39:23 +00:00
|
|
|
else if (MDNode *IA = DV.getInlinedAt())
|
|
|
|
Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
|
|
|
|
else
|
|
|
|
Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1)));
|
2010-05-20 19:57:06 +00:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-05-21 00:10:20 +00:00
|
|
|
if (!Scope)
|
2010-05-20 19:57:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Processed.insert(DV);
|
2011-03-26 02:19:36 +00:00
|
|
|
assert(MInsn->isDebugValue() && "History must begin with debug value");
|
2011-08-15 19:01:20 +00:00
|
|
|
DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
|
2014-04-22 05:41:06 +00:00
|
|
|
DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
|
|
|
|
if (!addCurrentFnArgument(RegVar, Scope))
|
|
|
|
addScopeVariable(Scope, RegVar);
|
2011-08-15 19:01:20 +00:00
|
|
|
if (AbsVar)
|
2011-08-15 21:24:36 +00:00
|
|
|
AbsVar->setMInsn(MInsn);
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2012-10-08 20:48:54 +00:00
|
|
|
// Simplify ranges that are fully coalesced.
|
2013-11-19 09:04:36 +00:00
|
|
|
if (History.size() <= 1 ||
|
|
|
|
(History.size() == 2 && MInsn->isIdenticalTo(History.back()))) {
|
2014-04-22 05:41:06 +00:00
|
|
|
RegVar->setMInsn(MInsn);
|
2010-05-25 23:40:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-28 17:33:26 +00:00
|
|
|
// Handle multiple DBG_VALUE instructions describing one variable.
|
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;
|
2013-11-19 09:04:36 +00:00
|
|
|
for (SmallVectorImpl<const MachineInstr *>::const_iterator
|
|
|
|
HI = History.begin(),
|
|
|
|
HE = History.end();
|
|
|
|
HI != HE; ++HI) {
|
2011-03-26 02:19:36 +00:00
|
|
|
const MachineInstr *Begin = *HI;
|
|
|
|
assert(Begin->isDebugValue() && "Invalid History entry");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-06-01 23:00:17 +00:00
|
|
|
// Check if DBG_VALUE is truncating a range.
|
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;
|
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
// Compute the range for a register location.
|
2010-05-26 17:29:32 +00:00
|
|
|
const MCSymbol *FLabel = getLabelBeforeInsn(Begin);
|
2014-04-24 06:44:33 +00:00
|
|
|
const MCSymbol *SLabel = nullptr;
|
2010-08-04 22:07:27 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
if (HI + 1 == HE)
|
|
|
|
// If Begin is the last instruction in History then its value is valid
|
2011-04-15 05:18:47 +00:00
|
|
|
// until the end of the function.
|
2011-03-22 22:33:08 +00:00
|
|
|
SLabel = FunctionEndSym;
|
2011-03-26 02:19:36 +00:00
|
|
|
else {
|
|
|
|
const MachineInstr *End = HI[1];
|
2012-11-19 22:42:10 +00:00
|
|
|
DEBUG(dbgs() << "DotDebugLoc Pair:\n"
|
2013-11-19 09:04:36 +00:00
|
|
|
<< "\t" << *Begin << "\t" << *End << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
if (End->isDebugValue())
|
|
|
|
SLabel = getLabelBeforeInsn(End);
|
|
|
|
else {
|
|
|
|
// End is a normal instruction clobbering the range.
|
|
|
|
SLabel = getLabelAfterInsn(End);
|
|
|
|
assert(SLabel && "Forgot label after clobber instruction");
|
|
|
|
++HI;
|
|
|
|
}
|
|
|
|
}
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// The value is valid until the next DBG_VALUE or clobber.
|
2014-03-20 19:16:16 +00:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
|
|
|
DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
2014-03-24 22:27:06 +00:00
|
|
|
DebugLocEntry Loc = getDebugLocEntry(Asm, FLabel, SLabel, 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
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
|
|
|
DIArray Variables = DISubprogram(FnScope->getScopeNode()).getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
2013-07-08 18:33:29 +00:00
|
|
|
if (!DV || !DV.isVariable() || !Processed.insert(DV))
|
2011-08-19 23:28:12 +00:00
|
|
|
continue;
|
|
|
|
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext()))
|
2014-04-24 06:44:33 +00:00
|
|
|
addScopeVariable(Scope, new DbgVariable(DV, nullptr, this));
|
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) {
|
2013-12-03 15:10:23 +00:00
|
|
|
assert(CurMI == 0);
|
|
|
|
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() {
|
|
|
|
assert(CurMI != 0);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
|
2012-11-27 22:43:45 +00:00
|
|
|
// LiveUserVar - Map physreg numbers to the MDNode they contain.
|
2013-11-01 23:14:17 +00:00
|
|
|
std::vector<const MDNode *> LiveUserVar(TRI->getNumRegs());
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2013-11-01 23:14:17 +00:00
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
|
|
|
|
++I) {
|
2011-03-26 02:19:36 +00:00
|
|
|
bool AtBlockEntry = true;
|
2010-05-26 19:37:24 +00:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MI = II;
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2010-05-26 19:37:24 +00:00
|
|
|
if (MI->isDebugValue()) {
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(MI->getNumOperands() > 1 && "Invalid machine instruction!");
|
2011-03-22 22:33:08 +00:00
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// Keep track of user variables.
|
2014-04-10 17:39:48 +00:00
|
|
|
const MDNode *Var = MI->getDebugVariable();
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// Variable is in a register, we need to check for clobbers.
|
2011-03-22 22:33:08 +00:00
|
|
|
if (isDbgValueInDefinedReg(MI))
|
|
|
|
LiveUserVar[MI->getOperand(0).getReg()] = Var;
|
|
|
|
|
2011-03-26 02:19:36 +00:00
|
|
|
// Check the history of this variable.
|
2013-11-01 23:14:17 +00:00
|
|
|
SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var];
|
2011-03-26 02:19:36 +00:00
|
|
|
if (History.empty()) {
|
|
|
|
UserVariables.push_back(Var);
|
|
|
|
// The first mention of a function argument gets the FunctionBeginSym
|
|
|
|
// label, so arguments are visible when breaking at function entry.
|
|
|
|
DIVariable DV(Var);
|
2013-07-08 18:33:29 +00:00
|
|
|
if (DV.isVariable() && DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
2013-11-18 23:57:26 +00:00
|
|
|
getDISubprogram(DV.getContext()).describes(MF->getFunction()))
|
2011-03-26 02:19:36 +00:00
|
|
|
LabelsBeforeInsn[MI] = FunctionBeginSym;
|
|
|
|
} else {
|
|
|
|
// We have seen this variable before. Try to coalesce DBG_VALUEs.
|
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
if (Prev->isDebugValue()) {
|
|
|
|
// Coalesce identical entries at the end of History.
|
|
|
|
if (History.size() >= 2 &&
|
2011-07-07 00:14:27 +00:00
|
|
|
Prev->isIdenticalTo(History[History.size() - 2])) {
|
2012-10-08 20:48:49 +00:00
|
|
|
DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
|
2013-11-01 23:14:17 +00:00
|
|
|
<< "\t" << *Prev << "\t"
|
|
|
|
<< *History[History.size() - 2] << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
History.pop_back();
|
2011-07-07 00:14:27 +00:00
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
|
|
|
|
// Terminate old register assignments that don't reach MI;
|
|
|
|
MachineFunction::const_iterator PrevMBB = Prev->getParent();
|
2014-03-02 12:27:27 +00:00
|
|
|
if (PrevMBB != I && (!AtBlockEntry || std::next(PrevMBB) != I) &&
|
2011-03-26 02:19:36 +00:00
|
|
|
isDbgValueInDefinedReg(Prev)) {
|
|
|
|
// Previous register assignment needs to terminate at the end of
|
|
|
|
// its basic block.
|
|
|
|
MachineBasicBlock::const_iterator LastMI =
|
2013-11-01 23:14:17 +00:00
|
|
|
PrevMBB->getLastNonDebugInstr();
|
2011-07-07 00:14:27 +00:00
|
|
|
if (LastMI == PrevMBB->end()) {
|
2011-03-26 02:19:36 +00:00
|
|
|
// Drop DBG_VALUE for empty range.
|
2012-10-08 20:48:49 +00:00
|
|
|
DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n"
|
2013-11-01 23:14:17 +00:00
|
|
|
<< "\t" << *Prev << "\n");
|
2011-03-26 02:19:36 +00:00
|
|
|
History.pop_back();
|
2014-03-02 12:27:27 +00:00
|
|
|
} else if (std::next(PrevMBB) != PrevMBB->getParent()->end())
|
2011-03-26 02:19:36 +00:00
|
|
|
// Terminate after LastMI.
|
|
|
|
History.push_back(LastMI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
History.push_back(MI);
|
2010-05-26 19:37:24 +00:00
|
|
|
} else {
|
2011-03-26 02:19:36 +00:00
|
|
|
// Not a DBG_VALUE instruction.
|
2014-03-07 06:08:31 +00:00
|
|
|
if (!MI->isPosition())
|
2011-03-26 02:19:36 +00:00
|
|
|
AtBlockEntry = false;
|
|
|
|
|
2012-10-04 20:46:14 +00:00
|
|
|
// First known non-DBG_VALUE and non-frame setup location marks
|
|
|
|
// the beginning of the function body.
|
|
|
|
if (!MI->getFlag(MachineInstr::FrameSetup) &&
|
|
|
|
(PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown()))
|
2011-05-11 19:22:19 +00:00
|
|
|
PrologEndLoc = MI->getDebugLoc();
|
|
|
|
|
2011-03-22 22:33:08 +00:00
|
|
|
// Check if the instruction clobbers any registers with debug vars.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const MachineOperand &MO : MI->operands()) {
|
|
|
|
if (!MO.isReg() || !MO.isDef() || !MO.getReg())
|
2011-03-22 22:33:08 +00:00
|
|
|
continue;
|
2014-03-07 19:09:39 +00:00
|
|
|
for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
|
2013-11-01 23:14:17 +00:00
|
|
|
++AI) {
|
2012-06-01 23:28:30 +00:00
|
|
|
unsigned Reg = *AI;
|
2011-03-22 22:33:08 +00:00
|
|
|
const MDNode *Var = LiveUserVar[Reg];
|
|
|
|
if (!Var)
|
|
|
|
continue;
|
|
|
|
// Reg is now clobbered.
|
2014-04-24 06:44:33 +00:00
|
|
|
LiveUserVar[Reg] = nullptr;
|
2011-03-22 22:33:08 +00:00
|
|
|
|
|
|
|
// Was MD last defined by a DBG_VALUE referring to Reg?
|
2011-03-26 02:19:36 +00:00
|
|
|
DbgValueHistoryMap::iterator HistI = DbgValues.find(Var);
|
|
|
|
if (HistI == DbgValues.end())
|
|
|
|
continue;
|
2013-11-01 23:14:17 +00:00
|
|
|
SmallVectorImpl<const MachineInstr *> &History = HistI->second;
|
2011-03-26 02:19:36 +00:00
|
|
|
if (History.empty())
|
2011-03-22 22:33:08 +00:00
|
|
|
continue;
|
2011-03-26 02:19:36 +00:00
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
// Sanity-check: Register assignments are terminated at the end of
|
|
|
|
// their block.
|
|
|
|
if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent())
|
2011-03-22 22:33:08 +00:00
|
|
|
continue;
|
2011-03-26 02:19:36 +00:00
|
|
|
// Is the variable still in Reg?
|
|
|
|
if (!isDbgValueInDefinedReg(Prev) ||
|
|
|
|
Prev->getOperand(0).getReg() != Reg)
|
|
|
|
continue;
|
|
|
|
// Var is clobbered. Make sure the next instruction gets a label.
|
|
|
|
History.push_back(MI);
|
2011-03-22 22:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 19:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-26 02:19:36 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 19:09:39 +00:00
|
|
|
for (auto &I : DbgValues) {
|
|
|
|
SmallVectorImpl<const MachineInstr *> &History = I.second;
|
2011-03-26 02:19:36 +00:00
|
|
|
if (History.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Make sure the final register assignments are terminated.
|
|
|
|
const MachineInstr *Prev = History.back();
|
|
|
|
if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) {
|
|
|
|
const MachineBasicBlock *PrevMBB = Prev->getParent();
|
2012-11-19 22:42:10 +00:00
|
|
|
MachineBasicBlock::const_iterator LastMI =
|
2013-11-01 23:14:17 +00:00
|
|
|
PrevMBB->getLastNonDebugInstr();
|
2011-03-26 02:19:36 +00:00
|
|
|
if (LastMI == PrevMBB->end())
|
|
|
|
// Drop DBG_VALUE for empty range.
|
|
|
|
History.pop_back();
|
2013-06-20 00:25:24 +00:00
|
|
|
else if (PrevMBB != &PrevMBB->getParent()->back()) {
|
2011-03-26 02:19:36 +00:00
|
|
|
// Terminate after LastMI.
|
|
|
|
History.push_back(LastMI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Request labels for the full history.
|
2014-03-07 19:09:39 +00:00
|
|
|
for (const MachineInstr *MI : History) {
|
2011-03-26 02:19:36 +00:00
|
|
|
if (MI->isDebugValue())
|
|
|
|
requestLabelBeforeInsn(MI);
|
|
|
|
else
|
|
|
|
requestLabelAfterInsn(MI);
|
|
|
|
}
|
|
|
|
}
|
2010-05-26 19:37:24 +00:00
|
|
|
|
2011-03-25 17:20:59 +00:00
|
|
|
PrevInstLoc = DebugLoc();
|
2010-05-26 19:37:24 +00:00
|
|
|
PrevLabel = FunctionBeginSym;
|
2011-05-11 19:22:19 +00:00
|
|
|
|
|
|
|
// Record beginning of function.
|
|
|
|
if (!PrologEndLoc.isUnknown()) {
|
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) {
|
|
|
|
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);
|
|
|
|
assert(CurFn != 0);
|
|
|
|
|
|
|
|
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());
|
2013-07-08 18:33:29 +00:00
|
|
|
if (SP.isSubprogram()) {
|
2011-08-10 20:55:27 +00:00
|
|
|
// Collect info for variables that were optimized out.
|
2011-08-19 23:28:12 +00:00
|
|
|
DIArray Variables = SP.getVariables();
|
|
|
|
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
|
|
|
|
DIVariable DV(Variables.getElement(i));
|
2013-07-08 18:33:29 +00:00
|
|
|
if (!DV || !DV.isVariable() || !ProcessedVars.insert(DV))
|
2011-08-19 23:28:12 +00:00
|
|
|
continue;
|
2012-07-06 08:45:08 +00:00
|
|
|
// Check that DbgVariable for DV wasn't created earlier, when
|
|
|
|
// findAbstractVariable() was called for inlined instance of DV.
|
|
|
|
LLVMContext &Ctx = DV->getContext();
|
|
|
|
DIVariable CleanDV = cleanseInlinedVariable(DV, Ctx);
|
|
|
|
if (AbstractVariables.lookup(CleanDV))
|
|
|
|
continue;
|
2011-08-19 23:28:12 +00:00
|
|
|
if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext()))
|
2014-04-24 06:44:33 +00:00
|
|
|
addScopeVariable(Scope, new DbgVariable(DV, nullptr, this));
|
2010-06-25 22:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-12 18:10:19 +00:00
|
|
|
if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0)
|
2013-05-29 17:16:59 +00:00
|
|
|
constructScopeDIE(TheCU, AScope);
|
2011-08-10 20:55:27 +00:00
|
|
|
}
|
2012-11-19 22:42:10 +00:00
|
|
|
|
2011-08-15 22:04:40 +00:00
|
|
|
DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
|
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-04-22 05:41:06 +00:00
|
|
|
for (auto &I : ScopeVariables)
|
|
|
|
DeleteContainerPointers(I.second);
|
2011-08-10 20:55:27 +00:00
|
|
|
ScopeVariables.clear();
|
2014-04-22 05:41:06 +00:00
|
|
|
DeleteContainerPointers(CurrentFnArguments);
|
2011-03-26 02:19:36 +00:00
|
|
|
UserVariables.clear();
|
|
|
|
DbgValues.clear();
|
2010-03-12 17:45:06 +00:00
|
|
|
AbstractVariables.clear();
|
2010-04-27 19:46:33 +00:00
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.clear();
|
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;
|
2010-05-05 23:41:32 +00:00
|
|
|
if (S) {
|
|
|
|
DIDescriptor Scope(S);
|
|
|
|
|
|
|
|
if (Scope.isCompileUnit()) {
|
|
|
|
DICompileUnit CU(S);
|
|
|
|
Fn = CU.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = CU.getDirectory();
|
2010-10-28 17:30:52 +00:00
|
|
|
} else if (Scope.isFile()) {
|
|
|
|
DIFile F(S);
|
|
|
|
Fn = F.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = F.getDirectory();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else if (Scope.isSubprogram()) {
|
|
|
|
DISubprogram SP(S);
|
|
|
|
Fn = SP.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = SP.getDirectory();
|
2011-10-11 22:59:11 +00:00
|
|
|
} else if (Scope.isLexicalBlockFile()) {
|
|
|
|
DILexicalBlockFile DBF(S);
|
|
|
|
Fn = DBF.getFilename();
|
|
|
|
Dir = DBF.getDirectory();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else if (Scope.isLexicalBlock()) {
|
|
|
|
DILexicalBlock DB(S);
|
|
|
|
Fn = DB.getFilename();
|
2011-03-24 20:30:50 +00:00
|
|
|
Dir = DB.getDirectory();
|
2014-03-03 18:53:17 +00:00
|
|
|
Discriminator = DB.getDiscriminator();
|
2010-05-05 23:41:32 +00:00
|
|
|
} else
|
2012-02-05 08:31:47 +00:00
|
|
|
llvm_unreachable("Unexpected scope info");
|
2010-05-05 23:41:32 +00:00
|
|
|
|
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");
|
2013-12-30 17:22:27 +00:00
|
|
|
if (useSplitDwarf())
|
|
|
|
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) {
|
|
|
|
DIE *SpecDIE = cast<DIEEntry>(SpecVal)->getEntry();
|
|
|
|
if (SpecDIE->findAttribute(dwarf::DW_AT_external))
|
|
|
|
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-03-07 22:40:37 +00:00
|
|
|
DIVariable DV(Entry.getVariable());
|
|
|
|
if (Entry.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");
|
|
|
|
Streamer.EmitSLEB128(Entry.getInt());
|
|
|
|
} else {
|
|
|
|
Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
|
|
|
|
Streamer.EmitULEB128(Entry.getInt());
|
|
|
|
}
|
|
|
|
} else if (Entry.isLocation()) {
|
|
|
|
MachineLocation Loc = Entry.getLoc();
|
|
|
|
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
|
|
|
|
2013-12-09 23:57:44 +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
|
|
|
|
|
|
|
// Emit a symbol so we can find the beginning of our ranges.
|
2013-12-09 17:51:30 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(TheCU->getLabelRange());
|
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?");
|
|
|
|
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-22 22:39:41 +00:00
|
|
|
void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE *Die,
|
|
|
|
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
|
|
|
|
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
|
|
|
CU.getUniqueID(), Die, CU.getCUNode(), Asm, this, &SkeletonHolder);
|
|
|
|
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-22 22:39:41 +00:00
|
|
|
initSkeletonUnit(CU, Die, 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
|
|
|
|
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_type_unit);
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit = make_unique<DwarfTypeUnit>(TU.getUniqueID(), Die, CU, Asm,
|
|
|
|
this, &SkeletonHolder);
|
|
|
|
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()));
|
|
|
|
|
|
|
|
initSkeletonUnit(TU, Die, 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.
|
|
|
|
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-02-12 00:31:30 +00:00
|
|
|
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
|
2014-01-09 03:23:41 +00:00
|
|
|
StringRef Identifier, DIE *RefDie,
|
|
|
|
DICompositeType CTy) {
|
2014-01-31 19:52:26 +00:00
|
|
|
// Flag the type unit reference as a declaration so that if it contains
|
|
|
|
// members (implicit special members, static data member definitions, member
|
|
|
|
// declarations for definitions in this CU, etc) consumers don't get confused
|
|
|
|
// and think this is a full definition.
|
2014-02-12 00:31:30 +00:00
|
|
|
CU.addFlag(RefDie, dwarf::DW_AT_declaration);
|
2014-01-20 08:07:07 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
|
2014-04-22 22:39:41 +00:00
|
|
|
auto OwnedUnit =
|
|
|
|
make_unique<DwarfTypeUnit>(InfoHolder.getUnits().size(), UnitDie, CU, Asm,
|
|
|
|
this, &InfoHolder, getDwoLineTable(CU));
|
|
|
|
DwarfTypeUnit &NewTU = *OwnedUnit;
|
|
|
|
TU = &NewTU;
|
|
|
|
InfoHolder.addUnit(std::move(OwnedUnit));
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
uint64_t Signature = *reinterpret_cast<support::ulittle64_t *>(Result + 8);
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.setTypeSignature(Signature);
|
2014-01-20 08:07:07 +00:00
|
|
|
if (useSplitDwarf())
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.setSkeleton(constructSkeletonTU(NewTU));
|
2014-02-14 23:58:13 +00:00
|
|
|
else
|
|
|
|
CU.applyStmtList(*UnitDie);
|
2014-01-20 08:07:07 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.setType(NewTU.createTypeDIE(CTy));
|
2014-01-20 08:07:07 +00:00
|
|
|
|
2014-04-22 22:39:41 +00:00
|
|
|
NewTU.initSection(
|
2014-01-20 08:07:07 +00:00
|
|
|
useSplitDwarf()
|
|
|
|
? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
|
|
|
|
: Asm->getObjFileLowering().getDwarfTypesSection(Signature));
|
|
|
|
|
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-22 22:39:41 +00:00
|
|
|
void DwarfDebug::attachLowHighPC(DwarfCompileUnit &Unit, DIE *D,
|
2014-03-07 18:49:45 +00:00
|
|
|
MCSymbol *Begin, MCSymbol *End) {
|
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.
|
|
|
|
void DwarfDebug::addAccelName(StringRef Name, const DIE *Die) {
|
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
|
|
|
InfoHolder.getStringPoolEntry(Name);
|
|
|
|
AccelNames.AddName(Name, Die);
|
|
|
|
}
|
2014-04-24 00:53:32 +00:00
|
|
|
|
|
|
|
void DwarfDebug::addAccelObjC(StringRef Name, const DIE *Die) {
|
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
|
|
|
InfoHolder.getStringPoolEntry(Name);
|
|
|
|
AccelObjC.AddName(Name, Die);
|
|
|
|
}
|
2014-04-24 01:02:42 +00:00
|
|
|
|
|
|
|
void DwarfDebug::addAccelNamespace(StringRef Name, const DIE *Die) {
|
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
|
|
|
InfoHolder.getStringPoolEntry(Name);
|
|
|
|
AccelNamespace.AddName(Name, Die);
|
|
|
|
}
|
2014-04-24 01:23:49 +00:00
|
|
|
|
|
|
|
void DwarfDebug::addAccelType(StringRef Name, const DIE *Die, char Flags) {
|
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
|
|
|
InfoHolder.getStringPoolEntry(Name);
|
|
|
|
AccelTypes.AddName(Name, Die, Flags);
|
|
|
|
}
|