2013-12-03 03:33:10 +08:00
|
|
|
//===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===//
|
2011-04-13 07:21:44 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-08-14 13:13:29 +08:00
|
|
|
// This file contains support for constructing a dwarf compile unit.
|
2011-04-13 07:21:44 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-12-03 03:33:15 +08:00
|
|
|
#include "DwarfUnit.h"
|
2014-10-04 23:49:50 +08:00
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "DwarfAccelTable.h"
|
2014-10-04 23:49:50 +08:00
|
|
|
#include "DwarfCompileUnit.h"
|
2011-04-13 07:21:44 +08:00
|
|
|
#include "DwarfDebug.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 08:22:06 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-12-28 09:39:17 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2014-02-12 06:22:15 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2013-10-31 04:42:41 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-04-13 07:21:44 +08:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2013-06-29 04:05:11 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2011-04-13 07:21:44 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2013-12-10 07:57:44 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
|
|
|
|
cl::desc("Generate DWARF4 type units."),
|
|
|
|
cl::init(false));
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2013-12-03 06:09:48 +08:00
|
|
|
/// Unit - Unit constructor.
|
2014-04-29 05:14:27 +08:00
|
|
|
DwarfUnit::DwarfUnit(unsigned UID, dwarf::Tag UnitTag, DICompileUnit Node,
|
2014-04-29 05:04:29 +08:00
|
|
|
AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
|
2014-04-29 05:14:27 +08:00
|
|
|
: UniqueID(UID), CUNode(Node), UnitDie(UnitTag), DebugInfoOffset(0), Asm(A),
|
2014-11-02 02:18:07 +08:00
|
|
|
DD(DW), DU(DWU), IndexTyDie(nullptr), Section(nullptr) {
|
2014-04-29 05:14:27 +08:00
|
|
|
assert(UnitTag == dwarf::DW_TAG_compile_unit ||
|
|
|
|
UnitTag == dwarf::DW_TAG_type_unit);
|
2013-12-03 03:33:10 +08:00
|
|
|
DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
|
|
|
|
}
|
|
|
|
|
2014-04-29 05:14:27 +08:00
|
|
|
DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A,
|
2014-04-29 05:04:29 +08:00
|
|
|
DwarfDebug *DW, DwarfFile *DWU,
|
2014-03-18 10:13:23 +08:00
|
|
|
MCDwarfDwoLineTable *SplitLineTable)
|
2014-04-29 05:14:27 +08:00
|
|
|
: DwarfUnit(UID, dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU),
|
|
|
|
CU(CU), SplitLineTable(SplitLineTable) {
|
2014-03-18 09:17:26 +08:00
|
|
|
if (SplitLineTable)
|
2014-04-29 05:14:27 +08:00
|
|
|
addSectionOffset(UnitDie, dwarf::DW_AT_stmt_list, 0);
|
2014-03-18 09:17:26 +08:00
|
|
|
}
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2013-12-03 03:33:10 +08:00
|
|
|
/// ~Unit - Destructor for compile unit.
|
2013-12-10 07:32:48 +08:00
|
|
|
DwarfUnit::~DwarfUnit() {
|
2011-04-13 07:21:44 +08:00
|
|
|
for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
|
|
|
|
DIEBlocks[j]->~DIEBlock();
|
2014-02-16 16:46:55 +08:00
|
|
|
for (unsigned j = 0, M = DIELocs.size(); j < M; ++j)
|
|
|
|
DIELocs[j]->~DIELoc();
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
|
|
|
|
/// information entry.
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry *DwarfUnit::createDIEEntry(DIE &Entry) {
|
2011-04-13 07:21:44 +08:00
|
|
|
DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2012-12-06 15:55:19 +08:00
|
|
|
/// getDefaultLowerBound - Return the default lower bound for an array. If the
|
2012-12-06 15:38:10 +08:00
|
|
|
/// DWARF version doesn't handle the language, return -1.
|
2013-12-10 07:32:48 +08:00
|
|
|
int64_t DwarfUnit::getDefaultLowerBound() const {
|
2013-11-16 07:50:53 +08:00
|
|
|
switch (getLanguage()) {
|
2012-12-06 15:38:10 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dwarf::DW_LANG_C89:
|
|
|
|
case dwarf::DW_LANG_C99:
|
|
|
|
case dwarf::DW_LANG_C:
|
|
|
|
case dwarf::DW_LANG_C_plus_plus:
|
|
|
|
case dwarf::DW_LANG_ObjC:
|
|
|
|
case dwarf::DW_LANG_ObjC_plus_plus:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case dwarf::DW_LANG_Fortran77:
|
|
|
|
case dwarf::DW_LANG_Fortran90:
|
|
|
|
case dwarf::DW_LANG_Fortran95:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// The languages below have valid values only if the DWARF version >= 4.
|
|
|
|
case dwarf::DW_LANG_Java:
|
|
|
|
case dwarf::DW_LANG_Python:
|
|
|
|
case dwarf::DW_LANG_UPC:
|
|
|
|
case dwarf::DW_LANG_D:
|
|
|
|
if (dwarf::DWARF_VERSION >= 4)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dwarf::DW_LANG_Ada83:
|
|
|
|
case dwarf::DW_LANG_Ada95:
|
|
|
|
case dwarf::DW_LANG_Cobol74:
|
|
|
|
case dwarf::DW_LANG_Cobol85:
|
|
|
|
case dwarf::DW_LANG_Modula2:
|
|
|
|
case dwarf::DW_LANG_Pascal83:
|
|
|
|
case dwarf::DW_LANG_PLI:
|
|
|
|
if (dwarf::DWARF_VERSION >= 4)
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-01 01:54:35 +08:00
|
|
|
/// Check whether the DIE for this MDNode can be shared across CUs.
|
2013-11-16 06:59:36 +08:00
|
|
|
static bool isShareableAcrossCUs(DIDescriptor D) {
|
2013-11-21 02:40:16 +08:00
|
|
|
// When the MDNode can be part of the type system, the DIE can be shared
|
|
|
|
// across CUs.
|
|
|
|
// Combining type units and cross-CU DIE sharing is lower value (since
|
|
|
|
// cross-CU DIE sharing is used in LTO and removes type redundancy at that
|
|
|
|
// level already) but may be implementable for some value in projects
|
|
|
|
// building multiple independent libraries with LTO and then linking those
|
|
|
|
// together.
|
2013-11-20 07:08:21 +08:00
|
|
|
return (D.isType() ||
|
|
|
|
(D.isSubprogram() && !DISubprogram(D).isDefinition())) &&
|
2013-12-10 07:57:44 +08:00
|
|
|
!GenerateDwarfTypeUnits;
|
2013-11-01 01:54:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getDIE - Returns the debug information entry map slot for the
|
|
|
|
/// specified debug variable. We delegate the request to DwarfDebug
|
|
|
|
/// when the DIE for this MDNode can be shared across CUs. The mappings
|
|
|
|
/// will be kept in DwarfDebug for shareable DIEs.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getDIE(DIDescriptor D) const {
|
2013-11-16 07:09:13 +08:00
|
|
|
if (isShareableAcrossCUs(D))
|
|
|
|
return DD->getDIE(D);
|
|
|
|
return MDNodeToDieMap.lookup(D);
|
2013-11-01 01:54:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
|
|
|
|
/// when the DIE for this MDNode can be shared across CUs. The mappings
|
|
|
|
/// will be kept in DwarfDebug for shareable DIEs.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::insertDIE(DIDescriptor Desc, DIE *D) {
|
2013-11-16 07:09:13 +08:00
|
|
|
if (isShareableAcrossCUs(Desc)) {
|
|
|
|
DD->insertDIE(Desc, D);
|
2013-11-01 01:54:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-11-16 07:09:13 +08:00
|
|
|
MDNodeToDieMap.insert(std::make_pair(Desc, D));
|
2013-11-01 01:54:35 +08:00
|
|
|
}
|
|
|
|
|
2012-08-24 09:14:27 +08:00
|
|
|
/// addFlag - Add a flag that is true.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) {
|
2013-09-04 12:39:38 +08:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, dwarf::DW_FORM_flag_present, DIEIntegerOne);
|
2012-08-24 09:14:27 +08:00
|
|
|
else
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, dwarf::DW_FORM_flag, DIEIntegerOne);
|
2012-08-24 09:14:27 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addUInt - Add an unsigned integer attribute data and value.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addUInt(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
Optional<dwarf::Form> Form, uint64_t Integer) {
|
2013-10-19 09:04:47 +08:00
|
|
|
if (!Form)
|
|
|
|
Form = DIEInteger::BestForm(false, Integer);
|
|
|
|
DIEValue *Value = Integer == 1 ? DIEIntegerOne : new (DIEValueAllocator)
|
|
|
|
DIEInteger(Integer);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, *Form, Value);
|
2013-10-22 01:28:37 +08:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer) {
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(Block, (dwarf::Attribute)0, Form, Integer);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSInt - Add an signed integer attribute data and value.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSInt(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
Optional<dwarf::Form> Form, int64_t Integer) {
|
2013-10-19 09:04:47 +08:00
|
|
|
if (!Form)
|
|
|
|
Form = DIEInteger::BestForm(true, Integer);
|
2011-04-13 07:21:44 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, *Form, Value);
|
2013-10-22 01:28:37 +08:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSInt(DIELoc &Die, Optional<dwarf::Form> Form,
|
2013-12-10 07:32:48 +08:00
|
|
|
int64_t Integer) {
|
2013-10-22 01:28:37 +08:00
|
|
|
addSInt(Die, (dwarf::Attribute)0, Form, Integer);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2011-10-28 13:29:47 +08:00
|
|
|
/// addString - Add a string attribute data and value. We always emit a
|
|
|
|
/// reference to the string pool instead of immediate strings so that DIEs have
|
2013-01-08 03:32:45 +08:00
|
|
|
/// more predictable sizes. In the case of split dwarf we emit an index
|
|
|
|
/// into another table which gets us the static offset into the string
|
|
|
|
/// table.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
StringRef String) {
|
2013-12-31 02:32:31 +08:00
|
|
|
|
|
|
|
if (!DD->useSplitDwarf())
|
|
|
|
return addLocalString(Die, Attribute, String);
|
|
|
|
|
2014-04-26 05:34:35 +08:00
|
|
|
unsigned idx = DU->getStringPool().getIndex(*Asm, String);
|
2013-12-31 02:32:31 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx);
|
2013-07-27 01:02:41 +08:00
|
|
|
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Str);
|
2013-01-08 03:32:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addLocalString - Add a string attribute data and value. This is guaranteed
|
|
|
|
/// to be in the local string pool instead of indirected.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addLocalString(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
StringRef String) {
|
2014-04-26 05:34:35 +08:00
|
|
|
MCSymbol *Symb = DU->getStringPool().getSymbol(*Asm, String);
|
2011-10-28 13:29:47 +08:00
|
|
|
DIEValue *Value;
|
2013-12-28 09:39:17 +08:00
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
2013-07-03 02:46:26 +08:00
|
|
|
Value = new (DIEValueAllocator) DIELabel(Symb);
|
2014-09-12 05:12:48 +08:00
|
|
|
else
|
|
|
|
Value = new (DIEValueAllocator) DIEDelta(Symb, DD->getDebugStrSym());
|
2013-12-31 02:32:31 +08:00
|
|
|
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, dwarf::DW_FORM_strp, Str);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-07-03 02:46:26 +08:00
|
|
|
/// addExpr - Add a Dwarf expression attribute data and value.
|
2011-04-13 07:21:44 +08:00
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr) {
|
2013-07-03 02:46:26 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEExpr(Expr);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue((dwarf::Attribute)0, Form, Value);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2014-03-06 06:41:20 +08:00
|
|
|
/// addLocationList - Add a Dwarf loclistptr attribute data and value.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute,
|
2014-03-06 06:41:20 +08:00
|
|
|
unsigned Index) {
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELocList(Index);
|
|
|
|
dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
|
|
|
|
: dwarf::DW_FORM_data4;
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, Form, Value);
|
2014-03-06 06:41:20 +08:00
|
|
|
}
|
|
|
|
|
2013-07-03 02:46:26 +08:00
|
|
|
/// addLabel - Add a Dwarf label attribute data and value.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
|
2013-12-10 07:32:48 +08:00
|
|
|
const MCSymbol *Label) {
|
2013-07-03 02:46:26 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, Form, Value);
|
2013-06-29 04:05:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) {
|
2013-10-22 01:28:37 +08:00
|
|
|
addLabel(Die, (dwarf::Attribute)0, Form, Label);
|
|
|
|
}
|
|
|
|
|
2013-11-22 07:46:41 +08:00
|
|
|
/// addSectionOffset - Add an offset into a section attribute data and value.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
uint64_t Integer) {
|
2013-11-22 07:46:41 +08:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
|
|
|
addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
|
|
|
|
else
|
|
|
|
addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:17:26 +08:00
|
|
|
unsigned DwarfTypeUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) {
|
|
|
|
return SplitLineTable ? SplitLineTable->getFile(DirName, FileName)
|
|
|
|
: getCU().getOrCreateSourceID(FileName, DirName);
|
|
|
|
}
|
|
|
|
|
2013-01-19 06:11:33 +08:00
|
|
|
/// addOpAddress - Add a dwarf op address data and value using the
|
|
|
|
/// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
|
2013-01-19 06:11:33 +08:00
|
|
|
if (!DD->useSplitDwarf()) {
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
|
|
|
|
addLabel(Die, dwarf::DW_FORM_udata, Sym);
|
2013-01-19 06:11:33 +08:00
|
|
|
} else {
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
|
2014-04-24 05:04:59 +08:00
|
|
|
addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
|
2014-04-24 05:20:10 +08:00
|
|
|
DD->getAddressPool().getIndex(Sym));
|
2013-01-19 06:11:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addLabelDelta(DIE &Die, dwarf::Attribute Attribute,
|
2014-03-07 09:30:55 +08:00
|
|
|
const MCSymbol *Hi, const MCSymbol *Lo) {
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, dwarf::DW_FORM_data4, Value);
|
2014-03-07 09:30:55 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addDIEEntry - Add a DIE attribute data and value.
|
|
|
|
///
|
2014-04-26 03:33:43 +08:00
|
|
|
void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry) {
|
2013-11-01 01:54:35 +08:00
|
|
|
addDIEEntry(Die, Attribute, createDIEEntry(Entry));
|
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type) {
|
2014-04-27 00:26:41 +08: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.
|
|
|
|
addFlag(Die, dwarf::DW_AT_declaration);
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
|
|
|
|
new (DIEValueAllocator) DIETypeSignature(Type));
|
2013-12-18 07:32:35 +08:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
DIEEntry *Entry) {
|
2014-04-26 02:26:14 +08:00
|
|
|
const DIE *DieCU = Die.getUnitOrNull();
|
2014-04-26 03:33:43 +08:00
|
|
|
const DIE *EntryCU = Entry->getEntry().getUnitOrNull();
|
2013-11-01 01:54:35 +08:00
|
|
|
if (!DieCU)
|
|
|
|
// We assume that Die belongs to this CU, if it is not linked to any CU yet.
|
2014-04-26 02:35:57 +08:00
|
|
|
DieCU = &getUnitDie();
|
2013-11-01 01:54:35 +08:00
|
|
|
if (!EntryCU)
|
2014-04-26 02:35:57 +08:00
|
|
|
EntryCU = &getUnitDie();
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute,
|
|
|
|
EntryCU == DieCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
|
|
|
|
Entry);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-10-29 08:53:03 +08:00
|
|
|
/// Create a DIE with the given Tag, add the DIE to its parent, and
|
|
|
|
/// call insertDIE if MD is not null.
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) {
|
2014-04-12 10:24:04 +08:00
|
|
|
assert(Tag != dwarf::DW_TAG_auto_variable &&
|
|
|
|
Tag != dwarf::DW_TAG_arg_variable);
|
2014-04-26 04:00:34 +08:00
|
|
|
Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag));
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &Die = *Parent.getChildren().back();
|
2013-11-16 08:29:01 +08:00
|
|
|
if (N)
|
2014-04-26 02:52:29 +08:00
|
|
|
insertDIE(N, &Die);
|
2013-10-29 08:53:03 +08:00
|
|
|
return Die;
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addBlock - Add block data.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) {
|
2014-02-28 02:36:10 +08:00
|
|
|
Loc->ComputeSize(Asm);
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
|
2014-02-16 16:46:55 +08:00
|
|
|
}
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
DIEBlock *Block) {
|
2014-02-28 02:36:10 +08:00
|
|
|
Block->ComputeSize(Asm);
|
2011-04-13 07:21:44 +08:00
|
|
|
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
|
2014-04-26 02:26:14 +08:00
|
|
|
Die.addValue(Attribute, Block->BestForm(), Block);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, StringRef File,
|
2014-02-12 08:11:25 +08:00
|
|
|
StringRef Directory) {
|
2011-04-13 07:21:44 +08:00
|
|
|
if (Line == 0)
|
|
|
|
return;
|
2014-02-12 08:11:25 +08:00
|
|
|
|
2014-03-18 09:17:26 +08:00
|
|
|
unsigned FileID = getOrCreateSourceID(File, Directory);
|
2011-04-13 07:21:44 +08:00
|
|
|
assert(FileID && "Invalid file id");
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2014-02-12 08:11:25 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) {
|
2014-02-12 08:11:25 +08:00
|
|
|
assert(V.isVariable());
|
|
|
|
|
2014-02-13 06:38:04 +08:00
|
|
|
addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(),
|
|
|
|
V.getContext().getDirectory());
|
2014-02-12 08:11:25 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) {
|
2014-02-12 07:57:03 +08:00
|
|
|
assert(G.isGlobalVariable());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2014-02-12 08:11:25 +08:00
|
|
|
addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DISubprogram SP) {
|
2014-02-12 07:57:03 +08:00
|
|
|
assert(SP.isSubprogram());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2014-02-12 08:11:25 +08:00
|
|
|
addSourceLine(Die, SP.getLineNumber(), SP.getFilename(), SP.getDirectory());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DIType Ty) {
|
2014-02-12 07:57:03 +08:00
|
|
|
assert(Ty.isType());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2014-02-12 08:11:25 +08:00
|
|
|
addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2012-03-29 16:42:56 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) {
|
2014-02-12 07:57:03 +08:00
|
|
|
assert(Ty.isObjCProperty());
|
2012-03-29 16:42:56 +08:00
|
|
|
|
|
|
|
DIFile File = Ty.getFile();
|
2014-02-12 08:11:25 +08:00
|
|
|
addSourceLine(Die, Ty.getLineNumber(), File.getFilename(),
|
|
|
|
File.getDirectory());
|
2012-03-29 16:42:56 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addSourceLine(DIE &Die, DINameSpace NS) {
|
2014-02-12 07:57:03 +08:00
|
|
|
assert(NS.Verify());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2014-02-12 08:11:25 +08:00
|
|
|
addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2012-11-21 08:34:38 +08:00
|
|
|
/// addVariableAddress - Add DW_AT_location attribute for a
|
2011-04-28 06:45:24 +08:00
|
|
|
/// DbgVariable based on provided MachineLocation.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addVariableAddress(const DbgVariable &DV, DIE &Die,
|
2013-12-10 07:32:48 +08:00
|
|
|
MachineLocation Location) {
|
2013-06-25 05:07:27 +08:00
|
|
|
if (DV.variableHasComplexAddress())
|
2011-04-13 07:21:44 +08:00
|
|
|
addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
|
2013-06-25 05:07:27 +08:00
|
|
|
else if (DV.isBlockByrefVariable())
|
2011-04-13 07:21:44 +08:00
|
|
|
addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location);
|
|
|
|
else
|
2013-06-20 08:25:24 +08:00
|
|
|
addAddress(Die, dwarf::DW_AT_location, Location,
|
2013-06-25 05:07:27 +08:00
|
|
|
DV.getVariable().isIndirect());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:06:18 +08:00
|
|
|
/// addRegisterOp - Add register operand.
|
2014-08-02 06:11:58 +08:00
|
|
|
// FIXME: Ideally, this would share the implementation with
|
|
|
|
// AsmPrinter::EmitDwarfRegOpPiece.
|
|
|
|
void DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
|
|
|
|
unsigned SizeInBits, unsigned OffsetInBits) {
|
2014-08-05 05:25:23 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getSubtargetImpl()->getRegisterInfo();
|
2014-02-12 06:22:15 +08:00
|
|
|
int DWReg = RI->getDwarfRegNum(Reg, false);
|
|
|
|
bool isSubRegister = DWReg < 0;
|
|
|
|
|
|
|
|
unsigned Idx = 0;
|
|
|
|
|
|
|
|
// Go up the super-register chain until we hit a valid dwarf register number.
|
|
|
|
for (MCSuperRegIterator SR(Reg, RI); SR.isValid() && DWReg < 0; ++SR) {
|
|
|
|
DWReg = RI->getDwarfRegNum(*SR, false);
|
|
|
|
if (DWReg >= 0)
|
|
|
|
Idx = RI->getSubRegIndex(*SR, Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DWReg < 0) {
|
2014-02-27 07:27:16 +08:00
|
|
|
DEBUG(dbgs() << "Invalid Dwarf register number.\n");
|
2014-02-12 06:22:15 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_nop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
// Emit register.
|
2011-04-27 03:06:18 +08:00
|
|
|
if (DWReg < 32)
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + DWReg);
|
2011-04-27 03:06:18 +08:00
|
|
|
else {
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_regx);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_udata, DWReg);
|
2011-04-27 03:06:18 +08:00
|
|
|
}
|
2014-02-12 06:22:15 +08:00
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
// Emit mask.
|
|
|
|
bool isPiece = SizeInBits > 0;
|
|
|
|
if (isSubRegister || isPiece) {
|
|
|
|
const unsigned SizeOfByte = 8;
|
|
|
|
unsigned RegSizeInBits = RI->getSubRegIdxSize(Idx);
|
|
|
|
unsigned RegOffsetInBits = RI->getSubRegIdxOffset(Idx);
|
|
|
|
unsigned PieceSizeInBits = std::max(SizeInBits, RegSizeInBits);
|
|
|
|
unsigned PieceOffsetInBits = OffsetInBits ? OffsetInBits : RegOffsetInBits;
|
|
|
|
assert(RegSizeInBits >= SizeInBits && "register smaller than value");
|
|
|
|
|
|
|
|
if (RegOffsetInBits != PieceOffsetInBits) {
|
|
|
|
// Manually shift the value into place, since the DW_OP_piece
|
|
|
|
// describes the part of the variable, not the position of the
|
|
|
|
// subregister.
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, RegOffsetInBits);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_shr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PieceOffsetInBits > 0 || PieceSizeInBits % SizeOfByte) {
|
|
|
|
assert(PieceSizeInBits > 0 && "piece has zero size");
|
2014-02-12 06:22:15 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece);
|
2014-08-02 06:11:58 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, PieceSizeInBits);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, PieceOffsetInBits);
|
|
|
|
} else {
|
|
|
|
assert(PieceSizeInBits > 0 && "piece has zero size");
|
2014-02-12 06:22:15 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_piece);
|
2014-08-02 06:11:58 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, PieceSizeInBits/SizeOfByte);
|
2014-02-12 06:22:15 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 03:06:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addRegisterOffset - Add register offset.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addRegisterOffset(DIELoc &TheDie, unsigned Reg,
|
2013-12-10 07:32:48 +08:00
|
|
|
int64_t Offset) {
|
2014-08-05 05:25:23 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getSubtargetImpl()->getRegisterInfo();
|
2011-04-27 03:06:18 +08:00
|
|
|
unsigned DWReg = RI->getDwarfRegNum(Reg, false);
|
2014-08-05 05:25:23 +08:00
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getSubtargetImpl()->getRegisterInfo();
|
2011-04-27 03:06:18 +08:00
|
|
|
if (Reg == TRI->getFrameRegister(*Asm->MF))
|
|
|
|
// If variable offset is based in frame register then use fbreg.
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg);
|
2011-04-27 03:06:18 +08:00
|
|
|
else if (DWReg < 32)
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DWReg);
|
2011-04-27 03:06:18 +08:00
|
|
|
else {
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_udata, DWReg);
|
2011-04-27 03:06:18 +08:00
|
|
|
}
|
2013-10-22 01:28:37 +08:00
|
|
|
addSInt(TheDie, dwarf::DW_FORM_sdata, Offset);
|
2011-04-27 03:06:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addAddress - Add an address attribute to a die based on the location
|
|
|
|
/// provided.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addAddress(DIE &Die, dwarf::Attribute Attribute,
|
2013-12-10 07:32:48 +08:00
|
|
|
const MachineLocation &Location, bool Indirect) {
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2011-04-27 03:06:18 +08:00
|
|
|
|
2013-06-20 08:25:24 +08:00
|
|
|
if (Location.isReg() && !Indirect)
|
2014-08-02 06:11:58 +08:00
|
|
|
addRegisterOpPiece(*Loc, Location.getReg());
|
2013-06-20 08:25:24 +08:00
|
|
|
else {
|
2014-04-26 02:26:14 +08:00
|
|
|
addRegisterOffset(*Loc, Location.getReg(), Location.getOffset());
|
2013-06-20 08:25:24 +08:00
|
|
|
if (Indirect && !Location.isReg()) {
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2013-06-20 08:25:24 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 03:06:18 +08:00
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 16:46:55 +08:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-27 03:06:18 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addComplexAddress - Start with the address based on the location provided,
|
|
|
|
/// and generate the DWARF information necessary to find the actual variable
|
2013-12-05 08:13:15 +08:00
|
|
|
/// given the extra address information encoded in the DbgVariable, starting
|
|
|
|
/// from the starting location. Add the DWARF information to the die.
|
2011-04-13 07:21:44 +08:00
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addComplexAddress(const DbgVariable &DV, DIE &Die,
|
2013-12-10 07:32:48 +08:00
|
|
|
dwarf::Attribute Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2013-06-25 05:07:27 +08:00
|
|
|
unsigned N = DV.getNumAddrElements();
|
2011-04-28 10:22:40 +08:00
|
|
|
unsigned i = 0;
|
|
|
|
if (Location.isReg()) {
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
if (N >= 2 && DV.getAddrElement(0) == dwarf::DW_OP_plus) {
|
|
|
|
assert(!DV.getVariable().isIndirect() &&
|
|
|
|
"double indirection not handled");
|
2011-04-28 10:22:40 +08:00
|
|
|
// If first address element is OpPlus then emit
|
|
|
|
// DW_OP_breg + Offset instead of DW_OP_reg + Offset.
|
2014-04-26 02:26:14 +08:00
|
|
|
addRegisterOffset(*Loc, Location.getReg(), DV.getAddrElement(1));
|
2011-04-28 10:22:40 +08:00
|
|
|
i = 2;
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
} else if (N >= 2 && DV.getAddrElement(0) == dwarf::DW_OP_deref) {
|
|
|
|
assert(!DV.getVariable().isIndirect() &&
|
|
|
|
"double indirection not handled");
|
|
|
|
addRegisterOpPiece(*Loc, Location.getReg(),
|
|
|
|
DV.getExpression().getPieceSize(),
|
|
|
|
DV.getExpression().getPieceOffset());
|
|
|
|
i = 3;
|
2011-04-28 10:22:40 +08:00
|
|
|
} else
|
2014-08-02 06:11:58 +08:00
|
|
|
addRegisterOpPiece(*Loc, Location.getReg());
|
2013-10-19 09:04:47 +08:00
|
|
|
} else
|
2014-04-26 02:26:14 +08:00
|
|
|
addRegisterOffset(*Loc, Location.getReg(), Location.getOffset());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-10-19 09:04:47 +08:00
|
|
|
for (; i < N; ++i) {
|
2013-06-25 05:07:27 +08:00
|
|
|
uint64_t Element = DV.getAddrElement(i);
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
if (Element == dwarf::DW_OP_plus) {
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_udata, DV.getAddrElement(++i));
|
2014-08-02 06:11:58 +08:00
|
|
|
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
} else if (Element == dwarf::DW_OP_deref) {
|
2012-05-09 02:56:00 +08:00
|
|
|
if (!Location.isReg())
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2014-08-02 06:11:58 +08:00
|
|
|
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
} else if (Element == dwarf::DW_OP_piece) {
|
2014-08-02 06:11:58 +08:00
|
|
|
const unsigned SizeOfByte = 8;
|
|
|
|
unsigned PieceOffsetInBits = DV.getAddrElement(++i)*SizeOfByte;
|
|
|
|
unsigned PieceSizeInBits = DV.getAddrElement(++i)*SizeOfByte;
|
|
|
|
// Emit DW_OP_bit_piece Size Offset.
|
|
|
|
assert(PieceSizeInBits > 0 && "piece has zero size");
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece);
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_udata, PieceSizeInBits);
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_udata, PieceOffsetInBits);
|
|
|
|
|
2013-10-19 09:04:47 +08:00
|
|
|
} else
|
|
|
|
llvm_unreachable("unknown DIBuilder Opcode");
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 16:46:55 +08:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-13 07:21:44 +08: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.
|
|
|
|
|
|
|
|
However, as far as the original *programmer* is concerned, the variable
|
|
|
|
should still have type 'SomeType', as originally declared.
|
|
|
|
|
|
|
|
The function getBlockByrefType dives into the __Block_byref_x_VarName
|
|
|
|
struct to find the original type of the variable, which is then assigned to
|
|
|
|
the variable's Debug Information Entry as its real type. So far, so good.
|
|
|
|
However now the debugger will expect the variable VarName to have the type
|
|
|
|
SomeType. So we need the location attribute for the variable to be an
|
|
|
|
expression that explains to the debugger how to navigate through the
|
|
|
|
pointers and struct to find the actual variable of type SomeType.
|
|
|
|
|
|
|
|
The following function does just that. We start by getting
|
|
|
|
the "normal" location for the variable. This will be the location
|
|
|
|
of either the struct __Block_byref_x_VarName or the pointer to the
|
|
|
|
struct __Block_byref_x_VarName.
|
|
|
|
|
|
|
|
The struct will look something like:
|
|
|
|
|
|
|
|
struct __Block_byref_x_VarName {
|
|
|
|
... <various fields>
|
|
|
|
struct __Block_byref_x_VarName *forwarding;
|
|
|
|
... <various other fields>
|
|
|
|
SomeType VarName;
|
|
|
|
... <maybe more fields>
|
|
|
|
};
|
|
|
|
|
|
|
|
If we are given the struct directly (as our starting point) we
|
|
|
|
need to tell the debugger to:
|
|
|
|
|
|
|
|
1). Add the offset of the forwarding field.
|
|
|
|
|
|
|
|
2). Follow that pointer to get the real __Block_byref_x_VarName
|
|
|
|
struct to use (the real one may have been copied onto the heap).
|
|
|
|
|
|
|
|
3). Add the offset for the field VarName, to find the actual variable.
|
|
|
|
|
|
|
|
If we started with a pointer to the struct, then we need to
|
|
|
|
dereference that pointer first, before the other steps.
|
|
|
|
Translating this into DWARF ops, we will need to append the following
|
|
|
|
to the current location description for the variable:
|
|
|
|
|
|
|
|
DW_OP_deref -- optional, if we start with a pointer
|
|
|
|
DW_OP_plus_uconst <forward_fld_offset>
|
|
|
|
DW_OP_deref
|
|
|
|
DW_OP_plus_uconst <varName_fld_offset>
|
|
|
|
|
|
|
|
That is what this function does. */
|
|
|
|
|
|
|
|
/// addBlockByrefAddress - Start with the address based on the location
|
|
|
|
/// provided, and generate the DWARF information necessary to find the
|
|
|
|
/// actual Block variable (navigating the Block struct) based on the
|
|
|
|
/// starting location. Add the DWARF information to the die. For
|
|
|
|
/// more information, read large comment just above here.
|
|
|
|
///
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
|
2013-12-10 07:32:48 +08:00
|
|
|
dwarf::Attribute Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2013-06-25 05:07:27 +08:00
|
|
|
DIType Ty = DV.getType();
|
2011-04-13 07:21:44 +08:00
|
|
|
DIType TmpTy = Ty;
|
2013-08-08 09:41:00 +08:00
|
|
|
uint16_t Tag = Ty.getTag();
|
2011-04-13 07:21:44 +08:00
|
|
|
bool isPointer = false;
|
|
|
|
|
2013-06-25 05:07:27 +08:00
|
|
|
StringRef varName = DV.getName();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
if (Tag == dwarf::DW_TAG_pointer_type) {
|
2013-11-19 07:33:32 +08:00
|
|
|
DIDerivedType DTy(Ty);
|
2013-10-09 02:42:58 +08:00
|
|
|
TmpTy = resolve(DTy.getTypeDerivedFrom());
|
2011-04-13 07:21:44 +08:00
|
|
|
isPointer = true;
|
|
|
|
}
|
|
|
|
|
2013-11-19 07:33:32 +08:00
|
|
|
DICompositeType blockStruct(TmpTy);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Find the __forwarding field and the variable field in the __Block_byref
|
|
|
|
// struct.
|
2014-07-29 03:14:13 +08:00
|
|
|
DIArray Fields = blockStruct.getElements();
|
2013-11-19 07:33:32 +08:00
|
|
|
DIDerivedType varField;
|
|
|
|
DIDerivedType forwardingField;
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
|
2013-11-19 07:33:32 +08:00
|
|
|
DIDerivedType DT(Fields.getElement(i));
|
2011-04-13 07:21:44 +08:00
|
|
|
StringRef fieldName = DT.getName();
|
|
|
|
if (fieldName == "__forwarding")
|
2013-11-19 07:33:32 +08:00
|
|
|
forwardingField = DT;
|
2011-04-13 07:21:44 +08:00
|
|
|
else if (fieldName == varName)
|
2013-11-19 07:33:32 +08:00
|
|
|
varField = DT;
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the offsets for the forwarding field and the variable field.
|
2013-11-19 07:33:32 +08:00
|
|
|
unsigned forwardingFieldOffset = forwardingField.getOffsetInBits() >> 3;
|
|
|
|
unsigned varFieldOffset = varField.getOffsetInBits() >> 2;
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Decode the original location, and use that as the start of the byref
|
|
|
|
// variable's location.
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2012-07-04 10:02:18 +08:00
|
|
|
if (Location.isReg())
|
2014-08-02 06:11:58 +08:00
|
|
|
addRegisterOpPiece(*Loc, Location.getReg());
|
2012-07-04 10:02:18 +08:00
|
|
|
else
|
2014-04-26 02:26:14 +08:00
|
|
|
addRegisterOffset(*Loc, Location.getReg(), Location.getOffset());
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// If we started with a pointer to the __Block_byref... struct, then
|
|
|
|
// the first thing we need to do is dereference the pointer (DW_OP_deref).
|
|
|
|
if (isPointer)
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Next add the offset for the '__forwarding' field:
|
|
|
|
// DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in
|
|
|
|
// adding the offset if it's 0.
|
|
|
|
if (forwardingFieldOffset > 0) {
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_udata, forwardingFieldOffset);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now dereference the __forwarding field to get to the real __Block_byref
|
|
|
|
// struct: DW_OP_deref.
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Now that we've got the real __Block_byref... struct, add the offset
|
|
|
|
// for the variable's field to get to the location of the actual variable:
|
|
|
|
// DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0.
|
|
|
|
if (varFieldOffset > 0) {
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(*Loc, dwarf::DW_FORM_udata, varFieldOffset);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 16:46:55 +08:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-10-05 09:43:03 +08:00
|
|
|
/// Return true if type encoding is unsigned.
|
|
|
|
static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
|
|
|
|
DIDerivedType DTy(Ty);
|
2014-05-12 01:04:05 +08:00
|
|
|
if (DTy.isDerivedType()) {
|
2014-05-21 02:21:51 +08:00
|
|
|
dwarf::Tag T = (dwarf::Tag)Ty.getTag();
|
|
|
|
// Encode pointer constants as unsigned bytes. This is used at least for
|
2014-05-21 05:40:13 +08:00
|
|
|
// null pointer constant emission.
|
|
|
|
// FIXME: reference and rvalue_reference /probably/ shouldn't be allowed
|
|
|
|
// here, but accept them for now due to a bug in SROA producing bogus
|
|
|
|
// dbg.values.
|
2014-05-21 02:21:51 +08:00
|
|
|
if (T == dwarf::DW_TAG_pointer_type ||
|
2014-05-21 05:40:13 +08:00
|
|
|
T == dwarf::DW_TAG_ptr_to_member_type ||
|
|
|
|
T == dwarf::DW_TAG_reference_type ||
|
|
|
|
T == dwarf::DW_TAG_rvalue_reference_type)
|
2014-05-21 02:21:51 +08:00
|
|
|
return true;
|
|
|
|
assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
|
|
|
|
T == dwarf::DW_TAG_volatile_type ||
|
2014-05-21 02:36:35 +08:00
|
|
|
T == dwarf::DW_TAG_restrict_type ||
|
|
|
|
T == dwarf::DW_TAG_enumeration_type);
|
2014-05-21 02:21:51 +08:00
|
|
|
if (DITypeRef Deriv = DTy.getTypeDerivedFrom())
|
|
|
|
return isUnsignedDIType(DD, DD->resolve(Deriv));
|
2014-05-12 01:04:05 +08:00
|
|
|
// FIXME: Enums without a fixed underlying type have unknown signedness
|
|
|
|
// here, leading to incorrectly emitted constants.
|
|
|
|
assert(DTy.getTag() == dwarf::DW_TAG_enumeration_type);
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-05 09:43:03 +08:00
|
|
|
|
|
|
|
DIBasicType BTy(Ty);
|
2014-05-12 01:04:05 +08:00
|
|
|
assert(BTy.isBasicType());
|
2014-05-12 00:08:41 +08:00
|
|
|
unsigned Encoding = BTy.getEncoding();
|
2014-05-12 14:08:18 +08:00
|
|
|
assert((Encoding == dwarf::DW_ATE_unsigned ||
|
|
|
|
Encoding == dwarf::DW_ATE_unsigned_char ||
|
|
|
|
Encoding == dwarf::DW_ATE_signed ||
|
|
|
|
Encoding == dwarf::DW_ATE_signed_char ||
|
2014-05-17 05:53:09 +08:00
|
|
|
Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean) &&
|
|
|
|
"Unsupported encoding");
|
2014-05-12 00:08:41 +08:00
|
|
|
return (Encoding == dwarf::DW_ATE_unsigned ||
|
|
|
|
Encoding == dwarf::DW_ATE_unsigned_char ||
|
2014-05-17 05:53:09 +08:00
|
|
|
Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean);
|
2013-10-05 09:43:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If this type is derived from a base type then return base type size.
|
2013-10-09 02:46:58 +08:00
|
|
|
static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
|
2013-10-05 09:43:03 +08:00
|
|
|
unsigned Tag = Ty.getTag();
|
|
|
|
|
|
|
|
if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
|
|
|
|
Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
|
|
|
|
Tag != dwarf::DW_TAG_restrict_type)
|
|
|
|
return Ty.getSizeInBits();
|
|
|
|
|
|
|
|
DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom());
|
|
|
|
|
2014-03-13 02:18:05 +08:00
|
|
|
// If this type is not derived from any type or the type is a declaration then
|
|
|
|
// take conservative approach.
|
|
|
|
if (!BaseType.isValid() || BaseType.isForwardDecl())
|
2013-10-05 09:43:03 +08:00
|
|
|
return Ty.getSizeInBits();
|
|
|
|
|
|
|
|
// If this is a derived type, go ahead and get the base type, unless it's a
|
|
|
|
// reference then it's just the size of the field. Pointer types have no need
|
|
|
|
// of this since they're a different type of qualification on the type.
|
|
|
|
if (BaseType.getTag() == dwarf::DW_TAG_reference_type ||
|
|
|
|
BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
|
|
|
|
return Ty.getSizeInBits();
|
|
|
|
|
|
|
|
if (BaseType.isDerivedType())
|
2013-10-09 02:46:58 +08:00
|
|
|
return getBaseTypeSize(DD, DIDerivedType(BaseType));
|
2013-10-05 09:43:03 +08:00
|
|
|
|
|
|
|
return BaseType.getSizeInBits();
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addConstantFPValue - Add constant value entry in variable DIE.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addConstantFPValue(DIE &Die, const MachineOperand &MO) {
|
2013-10-19 09:04:47 +08:00
|
|
|
assert(MO.isFPImm() && "Invalid machine operand!");
|
2011-04-13 07:21:44 +08:00
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
APFloat FPImm = MO.getFPImm()->getValueAPF();
|
|
|
|
|
|
|
|
// Get the raw data form of the floating point.
|
|
|
|
const APInt FltVal = FPImm.bitcastToAPInt();
|
2013-10-19 09:04:47 +08:00
|
|
|
const char *FltPtr = (const char *)FltVal.getRawData();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
|
2012-10-09 00:38:25 +08:00
|
|
|
bool LittleEndian = Asm->getDataLayout().isLittleEndian();
|
2011-04-13 07:21:44 +08:00
|
|
|
int Incr = (LittleEndian ? 1 : -1);
|
|
|
|
int Start = (LittleEndian ? 0 : NumBytes - 1);
|
|
|
|
int Stop = (LittleEndian ? NumBytes : -1);
|
|
|
|
|
|
|
|
// Output the constant to DWARF one byte at a time.
|
|
|
|
for (; Start != Stop; Start += Incr)
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Block, dwarf::DW_FORM_data1, (unsigned char)0xFF & FltPtr[Start]);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-10-22 01:28:37 +08:00
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, Block);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-01-20 09:18:01 +08:00
|
|
|
/// addConstantFPValue - Add constant value entry in variable DIE.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addConstantFPValue(DIE &Die, const ConstantFP *CFP) {
|
2013-08-28 07:49:04 +08:00
|
|
|
// Pass this down to addConstantValue as an unsigned bag of bits.
|
|
|
|
addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
|
2013-01-20 09:18:01 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// addConstantValue - Add constant value entry in variable DIE.
|
2014-05-11 23:56:59 +08:00
|
|
|
void DwarfUnit::addConstantValue(DIE &Die, const ConstantInt *CI, DIType Ty) {
|
|
|
|
addConstantValue(Die, CI->getValue(), Ty);
|
2013-01-20 09:18:01 +08:00
|
|
|
}
|
|
|
|
|
2014-05-11 23:47:39 +08:00
|
|
|
/// addConstantValue - Add constant value entry in variable DIE.
|
|
|
|
void DwarfUnit::addConstantValue(DIE &Die, const MachineOperand &MO,
|
|
|
|
DIType Ty) {
|
|
|
|
assert(MO.isImm() && "Invalid machine operand!");
|
|
|
|
|
2014-05-12 00:08:41 +08:00
|
|
|
addConstantValue(Die, isUnsignedDIType(DD, Ty), MO.getImm());
|
2014-05-11 23:47:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-12 00:08:41 +08:00
|
|
|
void DwarfUnit::addConstantValue(DIE &Die, bool Unsigned, uint64_t Val) {
|
2014-05-11 23:47:39 +08:00
|
|
|
// FIXME: This is a bit conservative/simple - it emits negative values always
|
|
|
|
// sign extended to 64 bits rather than minimizing the number of bytes.
|
|
|
|
addUInt(Die, dwarf::DW_AT_const_value,
|
2014-05-12 00:08:41 +08:00
|
|
|
Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
|
2014-05-11 23:47:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-11 23:56:59 +08:00
|
|
|
void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, DIType Ty) {
|
|
|
|
addConstantValue(Die, Val, isUnsignedDIType(DD, Ty));
|
|
|
|
}
|
|
|
|
|
2013-01-20 09:18:01 +08:00
|
|
|
// addConstantValue - Add constant value entry in variable DIE.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
|
2013-01-20 09:18:01 +08:00
|
|
|
unsigned CIBitWidth = Val.getBitWidth();
|
2011-05-28 08:39:18 +08:00
|
|
|
if (CIBitWidth <= 64) {
|
2014-05-12 00:08:41 +08:00
|
|
|
addConstantValue(Die, Unsigned,
|
|
|
|
Unsigned ? Val.getZExtValue() : Val.getSExtValue());
|
2013-07-03 09:08:30 +08:00
|
|
|
return;
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
|
|
|
|
// Get the raw data form of the large APInt.
|
2011-10-28 22:12:22 +08:00
|
|
|
const uint64_t *Ptr64 = Val.getRawData();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
|
2012-10-09 00:38:25 +08:00
|
|
|
bool LittleEndian = Asm->getDataLayout().isLittleEndian();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Output the constant to DWARF one byte at a time.
|
2011-10-28 22:12:22 +08:00
|
|
|
for (int i = 0; i < NumBytes; i++) {
|
|
|
|
uint8_t c;
|
|
|
|
if (LittleEndian)
|
|
|
|
c = Ptr64[i / 8] >> (8 * (i & 7));
|
|
|
|
else
|
|
|
|
c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Block, dwarf::DW_FORM_data1, c);
|
2011-10-28 22:12:22 +08:00
|
|
|
}
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-10-22 01:28:37 +08:00
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, Block);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-04-22 15:47:40 +08:00
|
|
|
/// addTemplateParams - Add template parameters into buffer.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) {
|
2011-04-13 07:21:44 +08:00
|
|
|
// Add template parameters.
|
|
|
|
for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) {
|
|
|
|
DIDescriptor Element = TParams.getElement(i);
|
|
|
|
if (Element.isTemplateTypeParameter())
|
2013-10-24 07:05:28 +08:00
|
|
|
constructTemplateTypeParameterDIE(Buffer,
|
|
|
|
DITemplateTypeParameter(Element));
|
2011-04-13 07:21:44 +08:00
|
|
|
else if (Element.isTemplateValueParameter())
|
2013-10-24 07:05:28 +08:00
|
|
|
constructTemplateValueParameterDIE(Buffer,
|
|
|
|
DITemplateValueParameter(Element));
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-27 06:55:33 +08:00
|
|
|
|
2013-01-16 09:22:23 +08:00
|
|
|
/// getOrCreateContextDIE - Get context owner's DIE.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) {
|
2013-11-15 05:24:34 +08:00
|
|
|
if (!Context || Context.isFile())
|
2014-04-26 02:35:57 +08:00
|
|
|
return &getUnitDie();
|
2013-01-16 09:22:23 +08:00
|
|
|
if (Context.isType())
|
|
|
|
return getOrCreateTypeDIE(DIType(Context));
|
2013-11-15 03:37:56 +08:00
|
|
|
if (Context.isNameSpace())
|
2013-01-16 09:22:23 +08:00
|
|
|
return getOrCreateNameSpace(DINameSpace(Context));
|
2013-11-15 03:37:56 +08:00
|
|
|
if (Context.isSubprogram())
|
2013-01-16 09:22:23 +08:00
|
|
|
return getOrCreateSubprogramDIE(DISubprogram(Context));
|
2013-11-16 05:05:09 +08:00
|
|
|
return getDIE(Context);
|
2013-01-16 09:22:23 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
|
2013-11-26 08:15:27 +08:00
|
|
|
DIScope Context = resolve(Ty.getContext());
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(Context);
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
if (DIE *TyDIE = getDIE(Ty))
|
2013-11-20 07:08:21 +08:00
|
|
|
return TyDIE;
|
|
|
|
|
|
|
|
// Create new type.
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
constructTypeDIE(TyDIE, Ty);
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2013-11-26 08:15:27 +08:00
|
|
|
updateAcceleratorTables(Context, Ty, TyDIE);
|
2014-04-26 02:52:29 +08:00
|
|
|
return &TyDIE;
|
2013-11-20 07:08:21 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
|
|
|
|
/// given DIType.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
|
2013-11-15 06:25:02 +08:00
|
|
|
if (!TyNode)
|
2014-04-24 14:44:33 +08:00
|
|
|
return nullptr;
|
2013-10-30 06:49:29 +08:00
|
|
|
|
2013-11-15 06:25:02 +08:00
|
|
|
DIType Ty(TyNode);
|
|
|
|
assert(Ty.isType());
|
2014-03-25 05:33:01 +08:00
|
|
|
assert(Ty == resolve(Ty.getRef()) &&
|
2014-03-18 10:35:03 +08:00
|
|
|
"type was not uniqued, possible ODR violation.");
|
2013-11-15 06:25:02 +08:00
|
|
|
|
2014-04-12 13:35:59 +08:00
|
|
|
// DW_TAG_restrict_type is not supported in DWARF2
|
|
|
|
if (Ty.getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
|
|
|
|
return getOrCreateTypeDIE(resolve(DIDerivedType(Ty).getTypeDerivedFrom()));
|
|
|
|
|
2013-10-30 06:49:29 +08:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE.
|
2013-11-26 08:15:27 +08:00
|
|
|
DIScope Context = resolve(Ty.getContext());
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(Context);
|
2013-11-16 07:21:39 +08:00
|
|
|
assert(ContextDIE);
|
2013-10-30 06:49:29 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
if (DIE *TyDIE = getDIE(Ty))
|
2011-04-13 07:21:44 +08:00
|
|
|
return TyDIE;
|
|
|
|
|
|
|
|
// Create new type.
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
|
2013-10-30 06:49:29 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
updateAcceleratorTables(Context, Ty, TyDIE);
|
2014-03-06 09:42:00 +08:00
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
if (Ty.isBasicType())
|
2014-04-26 02:26:14 +08:00
|
|
|
constructTypeDIE(TyDIE, DIBasicType(Ty));
|
2013-11-26 08:22:37 +08:00
|
|
|
else if (Ty.isCompositeType()) {
|
|
|
|
DICompositeType CTy(Ty);
|
2014-01-04 02:59:42 +08:00
|
|
|
if (GenerateDwarfTypeUnits && !Ty.isForwardDecl())
|
|
|
|
if (MDString *TypeId = CTy.getIdentifier()) {
|
2014-02-12 08:31:30 +08:00
|
|
|
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
|
2014-03-15 07:08:17 +08:00
|
|
|
// Skip updating the accelerator tables since this is not the full type.
|
2014-04-26 02:26:14 +08:00
|
|
|
return &TyDIE;
|
2014-01-04 02:59:42 +08:00
|
|
|
}
|
2014-04-26 02:26:14 +08:00
|
|
|
constructTypeDIE(TyDIE, CTy);
|
2013-11-26 08:22:37 +08:00
|
|
|
} else {
|
2011-04-13 07:21:44 +08:00
|
|
|
assert(Ty.isDerivedType() && "Unknown kind of DIType");
|
2014-04-26 02:26:14 +08:00
|
|
|
constructTypeDIE(TyDIE, DIDerivedType(Ty));
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
2013-11-20 06:51:04 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
return &TyDIE;
|
2013-11-20 06:51:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
|
2014-04-26 02:52:29 +08:00
|
|
|
const DIE &TyDIE) {
|
2012-01-06 12:35:23 +08:00
|
|
|
if (!Ty.getName().empty() && !Ty.isForwardDecl()) {
|
|
|
|
bool IsImplementation = 0;
|
|
|
|
if (Ty.isCompositeType()) {
|
|
|
|
DICompositeType CT(Ty);
|
2012-01-07 07:03:37 +08:00
|
|
|
// A runtime language of 0 actually means C/C++ and that any
|
|
|
|
// non-negative value is some version of Objective-C/C++.
|
2013-10-19 09:04:47 +08:00
|
|
|
IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete();
|
2012-01-06 12:35:23 +08:00
|
|
|
}
|
2013-09-06 02:20:16 +08:00
|
|
|
unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
|
2014-04-24 09:23:49 +08:00
|
|
|
DD->addAccelType(Ty.getName(), TyDIE, Flags);
|
2013-11-26 08:15:27 +08:00
|
|
|
|
2014-03-12 11:34:38 +08:00
|
|
|
if ((!Context || Context.isCompileUnit() || Context.isFile() ||
|
|
|
|
Context.isNameSpace()) &&
|
|
|
|
getCUNode().getEmissionKind() != DIBuilder::LineTablesOnly)
|
2014-04-26 02:52:29 +08:00
|
|
|
GlobalTypes[getParentContextString(Context) + Ty.getName().str()] =
|
|
|
|
&TyDIE;
|
2012-01-06 12:35:23 +08:00
|
|
|
}
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addType - Add a new type attribute to the specified entity.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addType(DIE &Entity, DIType Ty, dwarf::Attribute Attribute) {
|
2013-08-08 15:40:37 +08:00
|
|
|
assert(Ty && "Trying to add a type that doesn't exist?");
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Check for pre-existence.
|
|
|
|
DIEEntry *Entry = getDIEEntry(Ty);
|
|
|
|
// If it exists then use the existing value.
|
|
|
|
if (Entry) {
|
2013-11-01 01:54:35 +08:00
|
|
|
addDIEEntry(Entity, Attribute, Entry);
|
2011-04-13 07:21:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct type.
|
|
|
|
DIE *Buffer = getOrCreateTypeDIE(Ty);
|
|
|
|
|
|
|
|
// Set up proxy.
|
2014-04-26 03:33:43 +08:00
|
|
|
Entry = createDIEEntry(*Buffer);
|
2011-04-13 07:21:44 +08:00
|
|
|
insertDIEEntry(Ty, Entry);
|
2013-11-01 01:54:35 +08:00
|
|
|
addDIEEntry(Entity, Attribute, Entry);
|
2011-06-01 07:30:30 +08:00
|
|
|
}
|
|
|
|
|
2013-09-21 06:20:55 +08:00
|
|
|
/// addGlobalName - Add a new global name to the compile unit.
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfUnit::addGlobalName(StringRef Name, DIE &Die, DIScope Context) {
|
2014-03-12 11:34:38 +08:00
|
|
|
if (getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly)
|
|
|
|
return;
|
2013-10-19 09:04:42 +08:00
|
|
|
std::string FullName = getParentContextString(Context) + Name.str();
|
2014-04-26 02:26:14 +08:00
|
|
|
GlobalNames[FullName] = &Die;
|
2013-09-21 06:20:55 +08:00
|
|
|
}
|
|
|
|
|
2013-10-17 10:06:06 +08:00
|
|
|
/// getParentContextString - Walks the metadata parent chain in a language
|
|
|
|
/// specific manner (using the compile unit language) and returns
|
|
|
|
/// it as a string. This is done at the metadata level because DIEs may
|
|
|
|
/// not currently have been added to the parent context and walking the
|
|
|
|
/// DIEs looking for names is more expensive than walking the metadata.
|
2013-12-10 07:32:48 +08:00
|
|
|
std::string DwarfUnit::getParentContextString(DIScope Context) const {
|
2013-10-17 10:06:06 +08:00
|
|
|
if (!Context)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// FIXME: Decide whether to implement this for non-C++ languages.
|
|
|
|
if (getLanguage() != dwarf::DW_LANG_C_plus_plus)
|
|
|
|
return "";
|
|
|
|
|
2013-10-19 09:04:42 +08:00
|
|
|
std::string CS;
|
2013-10-17 10:06:06 +08:00
|
|
|
SmallVector<DIScope, 1> Parents;
|
|
|
|
while (!Context.isCompileUnit()) {
|
|
|
|
Parents.push_back(Context);
|
|
|
|
if (Context.getContext())
|
|
|
|
Context = resolve(Context.getContext());
|
|
|
|
else
|
|
|
|
// Structure, etc types will have a NULL context if they're at the top
|
|
|
|
// level.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reverse iterate over our list to go from the outermost construct to the
|
|
|
|
// innermost.
|
|
|
|
for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(),
|
|
|
|
E = Parents.rend();
|
|
|
|
I != E; ++I) {
|
|
|
|
DIScope Ctx = *I;
|
|
|
|
StringRef Name = Ctx.getName();
|
2014-06-07 06:16:56 +08:00
|
|
|
if (Name.empty() && Ctx.isNameSpace())
|
|
|
|
Name = "(anonymous namespace)";
|
2013-10-19 09:04:42 +08:00
|
|
|
if (!Name.empty()) {
|
2013-10-17 10:06:06 +08:00
|
|
|
CS += Name;
|
|
|
|
CS += "::";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CS;
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructTypeDIE - Construct basic type die from DIBasicType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
|
2011-04-13 07:21:44 +08:00
|
|
|
// Get core information.
|
|
|
|
StringRef Name = BTy.getName();
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2014-04-26 02:26:14 +08:00
|
|
|
addString(Buffer, dwarf::DW_AT_name, Name);
|
2011-09-15 07:13:28 +08:00
|
|
|
|
2013-10-05 07:21:16 +08:00
|
|
|
// An unspecified type only has a name attribute.
|
|
|
|
if (BTy.getTag() == dwarf::DW_TAG_unspecified_type)
|
2011-09-15 07:13:28 +08:00
|
|
|
return;
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2012-02-08 07:33:58 +08:00
|
|
|
BTy.getEncoding());
|
2011-09-15 07:13:28 +08:00
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
uint64_t Size = BTy.getSizeInBits() >> 3;
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructTypeDIE - Construct derived type die from DIDerivedType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
|
2011-04-13 07:21:44 +08:00
|
|
|
// Get core information.
|
|
|
|
StringRef Name = DTy.getName();
|
|
|
|
uint64_t Size = DTy.getSizeInBits() >> 3;
|
2013-10-05 07:21:16 +08:00
|
|
|
uint16_t Tag = Buffer.getTag();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Map to main type, void will not have a type.
|
2013-10-09 02:42:58 +08:00
|
|
|
DIType FromTy = resolve(DTy.getTypeDerivedFrom());
|
2013-08-08 15:40:37 +08:00
|
|
|
if (FromTy)
|
2014-04-26 02:26:14 +08:00
|
|
|
addType(Buffer, FromTy);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2014-04-26 02:26:14 +08:00
|
|
|
addString(Buffer, dwarf::DW_AT_name, Name);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
2012-02-22 06:25:53 +08:00
|
|
|
if (Size && Tag != dwarf::DW_TAG_pointer_type)
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-01-07 13:51:15 +08:00
|
|
|
if (Tag == dwarf::DW_TAG_ptr_to_member_type)
|
2014-04-26 02:26:14 +08:00
|
|
|
addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
|
2014-04-26 03:33:43 +08:00
|
|
|
*getOrCreateTypeDIE(resolve(DTy.getClassType())));
|
2011-04-13 07:21:44 +08:00
|
|
|
// Add source line info if available and TyDesc is not a forward declaration.
|
|
|
|
if (!DTy.isForwardDecl())
|
2014-04-26 02:26:14 +08:00
|
|
|
addSourceLine(Buffer, DTy);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2014-02-26 03:57:42 +08:00
|
|
|
/// constructSubprogramArguments - Construct function argument DIEs.
|
2014-07-29 06:24:06 +08:00
|
|
|
void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeArray Args) {
|
2014-02-26 06:27:14 +08:00
|
|
|
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
|
2014-07-29 06:24:06 +08:00
|
|
|
DIType Ty = resolve(Args.getElement(i));
|
2014-07-30 02:20:39 +08:00
|
|
|
if (!Ty) {
|
2014-02-26 06:27:14 +08:00
|
|
|
assert(i == N-1 && "Unspecified parameter must be the last argument");
|
|
|
|
createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
|
|
|
|
} else {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
|
2014-10-27 07:37:04 +08:00
|
|
|
addType(Arg, Ty);
|
|
|
|
if (Ty.isArtificial())
|
2014-04-26 02:52:29 +08:00
|
|
|
addFlag(Arg, dwarf::DW_AT_artificial);
|
2014-02-26 03:57:42 +08:00
|
|
|
}
|
2014-02-26 06:27:14 +08:00
|
|
|
}
|
2014-02-26 03:57:42 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// constructTypeDIE - Construct type DIE from DICompositeType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2013-11-20 07:08:21 +08:00
|
|
|
// Add name if not anonymous or intermediate type.
|
2011-04-13 07:21:44 +08:00
|
|
|
StringRef Name = CTy.getName();
|
|
|
|
|
|
|
|
uint64_t Size = CTy.getSizeInBits() >> 3;
|
2013-10-05 07:21:16 +08:00
|
|
|
uint16_t Tag = Buffer.getTag();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
switch (Tag) {
|
|
|
|
case dwarf::DW_TAG_array_type:
|
2013-11-12 02:52:31 +08:00
|
|
|
constructArrayTypeDIE(Buffer, CTy);
|
2011-04-13 07:21:44 +08:00
|
|
|
break;
|
2013-11-12 02:52:39 +08:00
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
|
|
|
constructEnumTypeDIE(Buffer, CTy);
|
|
|
|
break;
|
2011-04-13 07:21:44 +08:00
|
|
|
case dwarf::DW_TAG_subroutine_type: {
|
2013-08-08 15:40:37 +08:00
|
|
|
// Add return type. A void return won't have a type.
|
2014-07-29 06:24:06 +08:00
|
|
|
DITypeArray Elements = DISubroutineType(CTy).getTypeArray();
|
|
|
|
DIType RTy(resolve(Elements.getElement(0)));
|
2013-08-08 15:40:37 +08:00
|
|
|
if (RTy)
|
2014-04-26 02:26:14 +08:00
|
|
|
addType(Buffer, RTy);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
bool isPrototyped = true;
|
2014-02-26 03:57:42 +08:00
|
|
|
if (Elements.getNumElements() == 2 &&
|
2014-07-30 06:58:13 +08:00
|
|
|
!Elements.getElement(1))
|
2014-02-26 03:57:42 +08:00
|
|
|
isPrototyped = false;
|
|
|
|
|
|
|
|
constructSubprogramArguments(Buffer, Elements);
|
|
|
|
|
2012-02-22 16:46:21 +08:00
|
|
|
// Add prototype flag if we're dealing with a C language and the
|
|
|
|
// function has been prototyped.
|
2013-11-16 07:50:53 +08:00
|
|
|
uint16_t Language = getLanguage();
|
2012-02-22 16:46:21 +08:00
|
|
|
if (isPrototyped &&
|
2013-10-19 09:04:47 +08:00
|
|
|
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
|
2012-05-23 02:45:24 +08:00
|
|
|
Language == dwarf::DW_LANG_ObjC))
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_prototyped);
|
2013-12-19 05:48:19 +08:00
|
|
|
|
|
|
|
if (CTy.isLValueReference())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_reference);
|
2013-12-19 05:48:19 +08:00
|
|
|
|
|
|
|
if (CTy.isRValueReference())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
|
2013-10-19 09:04:47 +08:00
|
|
|
} break;
|
2011-04-13 07:21:44 +08:00
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_class_type: {
|
|
|
|
// Add elements to structure type.
|
2014-07-29 03:14:13 +08:00
|
|
|
DIArray Elements = CTy.getElements();
|
2013-08-02 04:30:22 +08:00
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
2011-04-13 07:21:44 +08:00
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
2014-01-18 10:12:00 +08:00
|
|
|
if (Element.isSubprogram())
|
2014-04-26 02:26:14 +08:00
|
|
|
getOrCreateSubprogramDIE(DISubprogram(Element));
|
2014-01-18 10:12:00 +08:00
|
|
|
else if (Element.isDerivedType()) {
|
2012-05-23 02:45:24 +08:00
|
|
|
DIDerivedType DDTy(Element);
|
|
|
|
if (DDTy.getTag() == dwarf::DW_TAG_friend) {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
|
2013-10-09 02:42:58 +08:00
|
|
|
addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()),
|
2013-10-05 09:43:03 +08:00
|
|
|
dwarf::DW_AT_friend);
|
2013-10-15 04:33:57 +08:00
|
|
|
} else if (DDTy.isStaticMember()) {
|
2013-10-24 06:57:12 +08:00
|
|
|
getOrCreateStaticMemberDIE(DDTy);
|
2013-10-15 04:33:57 +08:00
|
|
|
} else {
|
2013-10-24 07:00:44 +08:00
|
|
|
constructMemberDIE(Buffer, DDTy);
|
2013-10-15 04:33:57 +08:00
|
|
|
}
|
2012-03-28 15:34:31 +08:00
|
|
|
} else if (Element.isObjCProperty()) {
|
2012-02-08 07:33:58 +08:00
|
|
|
DIObjCProperty Property(Element);
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &ElemDie = createAndAddDIE(Property.getTag(), Buffer);
|
2012-02-08 07:33:58 +08:00
|
|
|
StringRef PropertyName = Property.getObjCPropertyName();
|
|
|
|
addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
|
2014-01-24 03:16:28 +08:00
|
|
|
if (Property.getType())
|
|
|
|
addType(ElemDie, Property.getType());
|
2012-05-23 02:45:24 +08:00
|
|
|
addSourceLine(ElemDie, Property);
|
2012-02-08 07:33:58 +08:00
|
|
|
StringRef GetterName = Property.getObjCPropertyGetterName();
|
|
|
|
if (!GetterName.empty())
|
|
|
|
addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
|
|
|
|
StringRef SetterName = Property.getObjCPropertySetterName();
|
|
|
|
if (!SetterName.empty())
|
|
|
|
addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
|
|
|
|
unsigned PropertyAttributes = 0;
|
2012-02-04 09:30:32 +08:00
|
|
|
if (Property.isReadOnlyObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly;
|
|
|
|
if (Property.isReadWriteObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite;
|
|
|
|
if (Property.isAssignObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign;
|
|
|
|
if (Property.isRetainObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain;
|
|
|
|
if (Property.isCopyObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy;
|
|
|
|
if (Property.isNonAtomicObjCProperty())
|
|
|
|
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic;
|
|
|
|
if (PropertyAttributes)
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, None,
|
2013-10-19 09:04:47 +08:00
|
|
|
PropertyAttributes);
|
2012-02-07 01:49:43 +08:00
|
|
|
|
2012-02-08 07:33:58 +08:00
|
|
|
DIEEntry *Entry = getDIEEntry(Element);
|
|
|
|
if (!Entry) {
|
2014-04-26 03:33:43 +08:00
|
|
|
Entry = createDIEEntry(ElemDie);
|
2012-02-08 07:33:58 +08:00
|
|
|
insertDIEEntry(Element, Entry);
|
|
|
|
}
|
2012-02-04 09:30:32 +08:00
|
|
|
} else
|
2011-04-13 07:21:44 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CTy.isAppleBlockExtension())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_APPLE_block);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-10-05 08:27:02 +08:00
|
|
|
DICompositeType ContainingType(resolve(CTy.getContainingType()));
|
2013-11-19 07:33:32 +08:00
|
|
|
if (ContainingType)
|
2014-04-26 02:26:14 +08:00
|
|
|
addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
|
2014-04-26 03:33:43 +08:00
|
|
|
*getOrCreateTypeDIE(ContainingType));
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2011-05-13 05:29:42 +08:00
|
|
|
if (CTy.isObjcClassComplete())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
|
2011-05-13 03:06:16 +08:00
|
|
|
|
2011-12-17 07:42:42 +08:00
|
|
|
// Add template parameters to a class, structure or union types.
|
|
|
|
// FIXME: The support isn't in the metadata for this yet.
|
|
|
|
if (Tag == dwarf::DW_TAG_class_type ||
|
2013-10-19 09:04:47 +08:00
|
|
|
Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
|
2011-04-13 07:21:44 +08:00
|
|
|
addTemplateParams(Buffer, CTy.getTemplateParams());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2014-04-26 02:26:14 +08:00
|
|
|
addString(Buffer, dwarf::DW_AT_name, Name);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2012-05-23 02:45:18 +08:00
|
|
|
if (Tag == dwarf::DW_TAG_enumeration_type ||
|
2013-10-19 09:04:47 +08:00
|
|
|
Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
|
2012-05-23 02:45:18 +08:00
|
|
|
Tag == dwarf::DW_TAG_union_type) {
|
2011-04-13 07:21:44 +08:00
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
2012-06-01 08:22:32 +08:00
|
|
|
// TODO: Do we care about size for enum forward declarations?
|
2011-04-13 07:21:44 +08:00
|
|
|
if (Size)
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2012-06-01 08:22:32 +08:00
|
|
|
else if (!CTy.isForwardDecl())
|
2011-04-13 07:21:44 +08:00
|
|
|
// Add zero size if it is not a forward declaration.
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_byte_size, None, 0);
|
2012-06-01 08:22:32 +08:00
|
|
|
|
|
|
|
// If we're a forward decl, say so.
|
|
|
|
if (CTy.isForwardDecl())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_declaration);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Add source line info if available.
|
|
|
|
if (!CTy.isForwardDecl())
|
2014-04-26 02:26:14 +08:00
|
|
|
addSourceLine(Buffer, CTy);
|
2012-03-07 08:15:19 +08:00
|
|
|
|
|
|
|
// No harm in adding the runtime language to the declaration.
|
|
|
|
unsigned RLang = CTy.getRunTimeLang();
|
|
|
|
if (RLang)
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
|
2013-10-19 09:04:47 +08:00
|
|
|
RLang);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 07:05:28 +08:00
|
|
|
/// constructTemplateTypeParameterDIE - Construct new DIE for the given
|
|
|
|
/// DITemplateTypeParameter.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer,
|
|
|
|
DITemplateTypeParameter TP) {
|
2014-04-26 02:26:14 +08:00
|
|
|
DIE &ParamDIE =
|
2014-04-26 02:52:29 +08:00
|
|
|
createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
|
2013-08-08 16:09:43 +08:00
|
|
|
// Add the type if it exists, it could be void and therefore no type.
|
|
|
|
if (TP.getType())
|
2013-10-10 03:46:28 +08:00
|
|
|
addType(ParamDIE, resolve(TP.getType()));
|
2013-06-23 02:59:11 +08:00
|
|
|
if (!TP.getName().empty())
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_name, TP.getName());
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2013-10-24 07:05:28 +08:00
|
|
|
/// constructTemplateValueParameterDIE - Construct new DIE for the given
|
|
|
|
/// DITemplateValueParameter.
|
2013-12-10 07:32:48 +08:00
|
|
|
void
|
|
|
|
DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer,
|
2013-12-03 03:33:10 +08:00
|
|
|
DITemplateValueParameter VP) {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &ParamDIE = createAndAddDIE(VP.getTag(), Buffer);
|
2013-08-08 15:40:37 +08:00
|
|
|
|
|
|
|
// Add the type if there is one, template template and template parameter
|
|
|
|
// packs will not have a type.
|
2013-10-22 01:48:51 +08:00
|
|
|
if (VP.getTag() == dwarf::DW_TAG_template_value_parameter)
|
2013-10-10 03:46:28 +08:00
|
|
|
addType(ParamDIE, resolve(VP.getType()));
|
2013-08-08 15:40:31 +08:00
|
|
|
if (!VP.getName().empty())
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_name, VP.getName());
|
|
|
|
if (Value *Val = VP.getValue()) {
|
2013-05-11 05:52:07 +08:00
|
|
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val))
|
2014-05-11 23:56:59 +08:00
|
|
|
addConstantValue(ParamDIE, CI, resolve(VP.getType()));
|
2013-05-11 05:52:07 +08:00
|
|
|
else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) {
|
|
|
|
// For declaration non-type template parameters (such as global values and
|
|
|
|
// functions)
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2014-04-26 02:26:14 +08:00
|
|
|
addOpAddress(*Loc, Asm->getSymbol(GV));
|
2013-05-11 05:52:07 +08:00
|
|
|
// Emit DW_OP_stack_value to use the address as the immediate value of the
|
|
|
|
// parameter, rather than a pointer to it.
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
|
2014-02-16 16:46:55 +08:00
|
|
|
addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
|
2013-08-08 15:40:31 +08:00
|
|
|
} else if (VP.getTag() == dwarf::DW_TAG_GNU_template_template_param) {
|
2013-06-23 02:59:11 +08:00
|
|
|
assert(isa<MDString>(Val));
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
|
|
|
|
cast<MDString>(Val)->getString());
|
2013-08-08 15:40:31 +08:00
|
|
|
} else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
|
2013-06-23 02:59:11 +08:00
|
|
|
assert(isa<MDNode>(Val));
|
|
|
|
DIArray A(cast<MDNode>(Val));
|
2014-04-26 02:26:14 +08:00
|
|
|
addTemplateParams(ParamDIE, A);
|
2013-05-11 05:52:07 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:57:54 +08:00
|
|
|
/// getOrCreateNameSpace - Create a DIE for DINameSpace.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) {
|
2013-10-29 13:49:41 +08:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE.
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(NS.getContext());
|
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
if (DIE *NDie = getDIE(NS))
|
2011-05-07 00:57:54 +08:00
|
|
|
return NDie;
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
|
2013-10-29 13:49:41 +08:00
|
|
|
|
2014-06-07 06:16:56 +08:00
|
|
|
StringRef Name = NS.getName();
|
|
|
|
if (!Name.empty())
|
2011-10-27 14:44:11 +08:00
|
|
|
addString(NDie, dwarf::DW_AT_name, NS.getName());
|
2014-06-07 06:16:56 +08:00
|
|
|
else
|
|
|
|
Name = "(anonymous namespace)";
|
|
|
|
DD->addAccelNamespace(Name, NDie);
|
|
|
|
addGlobalName(Name, NDie, NS.getContext());
|
2011-05-07 00:57:54 +08:00
|
|
|
addSourceLine(NDie, NS);
|
2014-04-26 02:26:14 +08:00
|
|
|
return &NDie;
|
2011-05-07 00:57:54 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
/// getOrCreateSubprogramDIE - Create new DIE using SP.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) {
|
2013-10-04 09:39:59 +08:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE (as is the case for member function
|
|
|
|
// declarations).
|
2014-05-28 02:37:38 +08:00
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(resolve(SP.getContext()));
|
2014-03-19 01:41:15 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
if (DIE *SPDie = getDIE(SP))
|
2011-08-16 01:24:54 +08:00
|
|
|
return SPDie;
|
|
|
|
|
2014-05-22 02:04:33 +08:00
|
|
|
if (DISubprogram SPDecl = SP.getFunctionDeclaration()) {
|
2013-10-29 08:58:04 +08:00
|
|
|
// Add subprogram definitions to the CU die directly.
|
2014-04-29 05:14:27 +08:00
|
|
|
ContextDIE = &getUnitDie();
|
2014-06-01 05:26:28 +08:00
|
|
|
// Build the decl now to ensure it precedes the definition.
|
2014-05-28 02:37:38 +08:00
|
|
|
getOrCreateSubprogramDIE(SPDecl);
|
2014-05-22 02:04:33 +08:00
|
|
|
}
|
2012-05-28 02:36:44 +08:00
|
|
|
|
|
|
|
// DW_TAG_inlined_subroutine may refer to this DIE.
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
|
2012-05-28 02:36:44 +08:00
|
|
|
|
2014-06-05 08:25:26 +08:00
|
|
|
// Stop here and fill this in later, depending on whether or not this
|
DebugInfo: Lazily attach definition attributes to definitions.
This is a precursor to fixing inlined debug info where the concrete,
out-of-line definition may preceed any inlined usage. To cope with this,
the attributes that may appear on the concrete definition or the
abstract definition are delayed until the end of the module. Then, if an
abstract definition was created, it is referenced (and no other
attributes are added to the out-of-line definition), otherwise the
attributes are added directly to the out-of-line definition.
In a couple of cases this causes not just reordering of attributes, but
reordering of types. When the creation of the attribute is delayed, if
that creation would create a type (such as for a DW_AT_type attribute)
then other top level DIEs may've been constructed during the delay,
causing the referenced type to be created and added after those
intervening DIEs. In the extreme case, in cross-cu-inlining.ll, this
actually causes the DW_TAG_basic_type for "int" to move from one CU to
another.
llvm-svn: 209674
2014-05-28 02:37:43 +08:00
|
|
|
// subprogram turns out to have inlined instances or not.
|
|
|
|
if (SP.isDefinition())
|
|
|
|
return &SPDie;
|
|
|
|
|
2014-05-28 02:37:38 +08:00
|
|
|
applySubprogramAttributes(SP, SPDie);
|
|
|
|
return &SPDie;
|
|
|
|
}
|
|
|
|
|
2014-06-07 06:29:05 +08:00
|
|
|
void DwarfUnit::applySubprogramAttributesToDefinition(DISubprogram SP, DIE &SPDie) {
|
|
|
|
DISubprogram SPDecl = SP.getFunctionDeclaration();
|
|
|
|
DIScope Context = resolve(SPDecl ? SPDecl.getContext() : SP.getContext());
|
|
|
|
applySubprogramAttributes(SP, SPDie);
|
|
|
|
addGlobalName(SP.getName(), SPDie, Context);
|
|
|
|
}
|
|
|
|
|
2014-05-28 02:37:38 +08:00
|
|
|
void DwarfUnit::applySubprogramAttributes(DISubprogram SP, DIE &SPDie) {
|
|
|
|
DIE *DeclDie = nullptr;
|
|
|
|
StringRef DeclLinkageName;
|
|
|
|
if (DISubprogram SPDecl = SP.getFunctionDeclaration()) {
|
DebugInfo: Lazily attach definition attributes to definitions.
This is a precursor to fixing inlined debug info where the concrete,
out-of-line definition may preceed any inlined usage. To cope with this,
the attributes that may appear on the concrete definition or the
abstract definition are delayed until the end of the module. Then, if an
abstract definition was created, it is referenced (and no other
attributes are added to the out-of-line definition), otherwise the
attributes are added directly to the out-of-line definition.
In a couple of cases this causes not just reordering of attributes, but
reordering of types. When the creation of the attribute is delayed, if
that creation would create a type (such as for a DW_AT_type attribute)
then other top level DIEs may've been constructed during the delay,
causing the referenced type to be created and added after those
intervening DIEs. In the extreme case, in cross-cu-inlining.ll, this
actually causes the DW_TAG_basic_type for "int" to move from one CU to
another.
llvm-svn: 209674
2014-05-28 02:37:43 +08:00
|
|
|
DeclDie = getDIE(SPDecl);
|
2014-06-05 08:25:26 +08:00
|
|
|
assert(DeclDie && "This DIE should've already been constructed when the "
|
2014-06-08 05:23:09 +08:00
|
|
|
"definition DIE was created in "
|
2014-06-05 08:25:26 +08:00
|
|
|
"getOrCreateSubprogramDIE");
|
2014-05-28 02:37:38 +08:00
|
|
|
DeclLinkageName = SPDecl.getLinkageName();
|
|
|
|
}
|
2011-11-11 06:34:29 +08:00
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
// Add function template parameters.
|
2014-04-26 02:26:14 +08:00
|
|
|
addTemplateParams(SPDie, SP.getTemplateParams());
|
2011-08-16 01:24:54 +08:00
|
|
|
|
2014-04-15 05:16:04 +08:00
|
|
|
// Add the linkage name if we have one and it isn't in the Decl.
|
|
|
|
StringRef LinkageName = SP.getLinkageName();
|
2014-05-22 02:04:33 +08:00
|
|
|
assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
|
|
|
|
LinkageName == DeclLinkageName) &&
|
|
|
|
"decl has a linkage name and it is different");
|
|
|
|
if (!LinkageName.empty() && DeclLinkageName.empty())
|
|
|
|
addString(SPDie, dwarf::DW_AT_MIPS_linkage_name,
|
|
|
|
GlobalValue::getRealLinkageName(LinkageName));
|
|
|
|
|
|
|
|
if (DeclDie) {
|
|
|
|
// Refer to the function declaration where all the other attributes will be
|
|
|
|
// found.
|
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
|
2014-05-28 02:37:38 +08:00
|
|
|
return;
|
2014-05-22 02:04:33 +08:00
|
|
|
}
|
2012-08-24 06:52:55 +08:00
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
// Constructors and operators for anonymous aggregates do not have names.
|
|
|
|
if (!SP.getName().empty())
|
2011-10-27 14:44:11 +08:00
|
|
|
addString(SPDie, dwarf::DW_AT_name, SP.getName());
|
2011-08-16 01:24:54 +08:00
|
|
|
|
2014-09-19 12:47:46 +08:00
|
|
|
// Skip the rest of the attributes under -gmlt to save space.
|
2014-09-19 12:30:36 +08:00
|
|
|
if(getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly)
|
|
|
|
return;
|
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
addSourceLine(SPDie, SP);
|
|
|
|
|
2012-02-22 16:46:21 +08:00
|
|
|
// Add the prototype if we have a prototype and we have a C like
|
|
|
|
// language.
|
2013-11-16 07:50:53 +08:00
|
|
|
uint16_t Language = getLanguage();
|
2012-02-22 16:46:21 +08:00
|
|
|
if (SP.isPrototyped() &&
|
2013-10-19 09:04:47 +08:00
|
|
|
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
|
2012-02-22 16:46:21 +08:00
|
|
|
Language == dwarf::DW_LANG_ObjC))
|
2012-08-24 09:14:27 +08:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_prototyped);
|
2011-08-16 01:24:54 +08:00
|
|
|
|
2014-07-29 06:24:06 +08:00
|
|
|
DISubroutineType SPTy = SP.getType();
|
2013-05-23 07:22:18 +08:00
|
|
|
assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type &&
|
|
|
|
"the type of a subprogram should be a subroutine");
|
2011-08-16 01:24:54 +08:00
|
|
|
|
2014-07-29 06:24:06 +08:00
|
|
|
DITypeArray Args = SPTy.getTypeArray();
|
2013-10-22 01:48:51 +08:00
|
|
|
// Add a return type. If this is a type like a C/C++ void type we don't add a
|
|
|
|
// return type.
|
2014-07-29 06:24:06 +08:00
|
|
|
if (resolve(Args.getElement(0)))
|
|
|
|
addType(SPDie, DIType(resolve(Args.getElement(0))));
|
2011-08-16 01:24:54 +08:00
|
|
|
|
|
|
|
unsigned VK = SP.getVirtuality();
|
|
|
|
if (VK) {
|
2011-12-14 08:56:07 +08:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *Block = getDIELoc();
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(*Block, dwarf::DW_FORM_udata, SP.getVirtualIndex());
|
2013-10-22 01:28:37 +08:00
|
|
|
addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
|
2013-11-12 02:52:36 +08:00
|
|
|
ContainingTypeMap.insert(
|
2014-04-26 02:26:14 +08:00
|
|
|
std::make_pair(&SPDie, resolve(SP.getContainingType())));
|
2011-08-16 01:24:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!SP.isDefinition()) {
|
2012-08-24 09:14:27 +08:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_declaration);
|
2012-11-21 08:34:38 +08:00
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
// Add arguments. Do not add arguments for subprogram definition. They will
|
|
|
|
// be handled while processing variables.
|
2014-05-01 06:58:19 +08:00
|
|
|
constructSubprogramArguments(SPDie, Args);
|
2011-08-16 01:24:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SP.isArtificial())
|
2012-08-24 09:14:27 +08:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_artificial);
|
2011-08-16 01:24:54 +08:00
|
|
|
|
|
|
|
if (!SP.isLocalToUnit())
|
2012-08-24 09:14:27 +08:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_external);
|
2011-08-16 01:24:54 +08:00
|
|
|
|
|
|
|
if (SP.isOptimized())
|
2012-08-24 09:14:27 +08:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
|
2011-08-16 01:24:54 +08:00
|
|
|
|
|
|
|
if (unsigned isa = Asm->getISAEncoding()) {
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:48:19 +08:00
|
|
|
if (SP.isLValueReference())
|
|
|
|
addFlag(SPDie, dwarf::DW_AT_reference);
|
|
|
|
|
|
|
|
if (SP.isRValueReference())
|
|
|
|
addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
|
|
|
|
|
2014-01-18 10:12:00 +08:00
|
|
|
if (SP.isProtected())
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (SP.isPrivate())
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_private);
|
2014-08-30 06:44:07 +08:00
|
|
|
else if (SP.isPublic())
|
2014-01-18 10:12:00 +08:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_public);
|
|
|
|
|
|
|
|
if (SP.isExplicit())
|
|
|
|
addFlag(SPDie, dwarf::DW_AT_explicit);
|
2011-08-16 01:24:54 +08:00
|
|
|
}
|
|
|
|
|
2014-06-14 06:18:23 +08:00
|
|
|
void DwarfUnit::applyVariableAttributes(const DbgVariable &Var,
|
|
|
|
DIE &VariableDie) {
|
|
|
|
StringRef Name = Var.getName();
|
|
|
|
if (!Name.empty())
|
|
|
|
addString(VariableDie, dwarf::DW_AT_name, Name);
|
|
|
|
addSourceLine(VariableDie, Var.getVariable());
|
|
|
|
addType(VariableDie, Var.getType());
|
|
|
|
if (Var.isArtificial())
|
|
|
|
addFlag(VariableDie, dwarf::DW_AT_artificial);
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:21:44 +08:00
|
|
|
/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
|
2014-04-26 03:33:43 +08:00
|
|
|
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
|
2012-12-05 05:34:03 +08:00
|
|
|
|
2012-12-06 15:38:10 +08:00
|
|
|
// The LowerBound value defines the lower bounds which is typically zero for
|
|
|
|
// C/C++. The Count value is the number of elements. Values are 64 bit. If
|
|
|
|
// Count == -1 then the array is unbounded and we do not emit
|
2014-10-01 08:56:55 +08:00
|
|
|
// DW_AT_lower_bound and DW_AT_count attributes.
|
2012-12-06 15:38:10 +08:00
|
|
|
int64_t LowerBound = SR.getLo();
|
2012-12-06 15:55:19 +08:00
|
|
|
int64_t DefaultLowerBound = getDefaultLowerBound();
|
2012-12-04 14:20:49 +08:00
|
|
|
int64_t Count = SR.getCount();
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2012-12-06 15:55:19 +08:00
|
|
|
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
|
2013-10-22 01:28:37 +08:00
|
|
|
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
|
2012-12-06 15:38:10 +08:00
|
|
|
|
2014-10-01 08:56:55 +08:00
|
|
|
if (Count != -1)
|
2012-12-05 05:34:03 +08:00
|
|
|
// FIXME: An unbounded array should reference the expression that defines
|
|
|
|
// the array.
|
2014-10-01 08:56:55 +08:00
|
|
|
addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2013-11-12 02:52:31 +08:00
|
|
|
if (CTy.isVector())
|
2014-04-26 02:26:14 +08:00
|
|
|
addFlag(Buffer, dwarf::DW_AT_GNU_vector);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-08-08 15:40:37 +08:00
|
|
|
// Emit the element type.
|
2014-04-26 02:26:14 +08:00
|
|
|
addType(Buffer, resolve(CTy.getTypeDerivedFrom()));
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// Get an anonymous type for index type.
|
2013-01-05 05:51:53 +08:00
|
|
|
// FIXME: This type should be passed down from the front end
|
|
|
|
// as different languages may have different sizes for indexes.
|
2011-04-13 07:21:44 +08:00
|
|
|
DIE *IdxTy = getIndexTyDie();
|
|
|
|
if (!IdxTy) {
|
2014-04-03 14:28:20 +08:00
|
|
|
// Construct an integer type to use for indexes.
|
2014-04-29 05:14:27 +08:00
|
|
|
IdxTy = &createAndAddDIE(dwarf::DW_TAG_base_type, UnitDie);
|
2014-04-26 02:26:14 +08:00
|
|
|
addString(*IdxTy, dwarf::DW_AT_name, "sizetype");
|
|
|
|
addUInt(*IdxTy, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
|
|
|
|
addUInt(*IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2014-04-03 14:28:20 +08:00
|
|
|
dwarf::DW_ATE_unsigned);
|
2011-04-13 07:21:44 +08:00
|
|
|
setIndexTyDie(IdxTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add subranges to array type.
|
2014-07-29 03:14:13 +08:00
|
|
|
DIArray Elements = CTy.getElements();
|
2011-04-13 07:21:44 +08:00
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
if (Element.getTag() == dwarf::DW_TAG_subrange_type)
|
|
|
|
constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 02:52:39 +08:00
|
|
|
/// constructEnumTypeDIE - Construct an enum type DIE from DICompositeType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2014-07-29 03:14:13 +08:00
|
|
|
DIArray Elements = CTy.getElements();
|
2013-11-12 02:52:39 +08:00
|
|
|
|
|
|
|
// Add enumerators to enumeration type.
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
2013-11-19 07:33:32 +08:00
|
|
|
DIEnumerator Enum(Elements.getElement(i));
|
2013-11-12 02:52:39 +08:00
|
|
|
if (Enum.isEnumerator()) {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
|
2013-11-19 07:33:32 +08:00
|
|
|
StringRef Name = Enum.getName();
|
2013-11-12 02:52:39 +08:00
|
|
|
addString(Enumerator, dwarf::DW_AT_name, Name);
|
2013-11-19 07:33:32 +08:00
|
|
|
int64_t Value = Enum.getEnumValue();
|
2013-11-19 17:28:34 +08:00
|
|
|
addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
|
|
|
Value);
|
2013-11-12 02:52:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DIType DTy = resolve(CTy.getTypeDerivedFrom());
|
|
|
|
if (DTy) {
|
2014-04-26 02:26:14 +08:00
|
|
|
addType(Buffer, DTy);
|
|
|
|
addFlag(Buffer, dwarf::DW_AT_enum_class);
|
2013-11-12 02:52:39 +08:00
|
|
|
}
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 01:24:54 +08:00
|
|
|
/// constructContainingTypeDIEs - Construct DIEs for types that contain
|
|
|
|
/// vtables.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructContainingTypeDIEs() {
|
2011-08-16 01:24:54 +08:00
|
|
|
for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(),
|
2013-10-19 09:04:47 +08:00
|
|
|
CE = ContainingTypeMap.end();
|
|
|
|
CI != CE; ++CI) {
|
2014-04-26 02:26:14 +08:00
|
|
|
DIE &SPDie = *CI->first;
|
2013-11-16 07:09:13 +08:00
|
|
|
DIDescriptor D(CI->second);
|
|
|
|
if (!D)
|
2013-10-19 09:04:47 +08:00
|
|
|
continue;
|
2013-11-16 07:09:13 +08:00
|
|
|
DIE *NDie = getDIE(D);
|
2013-10-19 09:04:47 +08:00
|
|
|
if (!NDie)
|
|
|
|
continue;
|
2014-04-26 03:33:43 +08:00
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
|
2011-08-16 01:24:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 07:00:44 +08:00
|
|
|
/// constructMemberDIE - Construct member DIE from DIDerivedType.
|
2013-12-10 07:32:48 +08:00
|
|
|
void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) {
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &MemberDie = createAndAddDIE(DT.getTag(), Buffer);
|
2011-04-13 07:21:44 +08:00
|
|
|
StringRef Name = DT.getName();
|
|
|
|
if (!Name.empty())
|
2011-10-27 14:44:11 +08:00
|
|
|
addString(MemberDie, dwarf::DW_AT_name, Name);
|
2011-04-13 07:21:44 +08:00
|
|
|
|
2013-10-09 02:42:58 +08:00
|
|
|
addType(MemberDie, resolve(DT.getTypeDerivedFrom()));
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
addSourceLine(MemberDie, DT);
|
|
|
|
|
2013-10-19 09:04:47 +08:00
|
|
|
if (DT.getTag() == dwarf::DW_TAG_inheritance && DT.isVirtual()) {
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
// For C++, virtual base classes are not at fixed offset. Use following
|
|
|
|
// expression to extract appropriate offset from vtable.
|
|
|
|
// BaseAddr = ObAddr + *((*ObAddr) - Offset)
|
|
|
|
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc();
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT.getOffsetInBits());
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
|
|
|
addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
2013-10-22 01:28:37 +08:00
|
|
|
|
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
|
2013-11-01 08:25:45 +08:00
|
|
|
} else {
|
|
|
|
uint64_t Size = DT.getSizeInBits();
|
|
|
|
uint64_t FieldSize = getBaseTypeSize(DD, DT);
|
|
|
|
uint64_t OffsetInBytes;
|
|
|
|
|
|
|
|
if (Size != FieldSize) {
|
2014-03-13 01:14:46 +08:00
|
|
|
// Handle bitfield, assume bytes are 8 bits.
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
|
2013-11-01 08:25:45 +08:00
|
|
|
|
|
|
|
uint64_t Offset = DT.getOffsetInBits();
|
|
|
|
uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
|
|
|
|
uint64_t HiMark = (Offset + FieldSize) & AlignMask;
|
|
|
|
uint64_t FieldOffset = (HiMark - FieldSize);
|
|
|
|
Offset -= FieldOffset;
|
|
|
|
|
|
|
|
// Maybe we need to work from the other end.
|
|
|
|
if (Asm->getDataLayout().isLittleEndian())
|
|
|
|
Offset = FieldSize - (Offset + Size);
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
|
|
|
|
|
2014-01-29 02:13:47 +08:00
|
|
|
// Here DW_AT_data_member_location points to the anonymous
|
2013-11-01 08:25:45 +08:00
|
|
|
// field that includes this bit field.
|
|
|
|
OffsetInBytes = FieldOffset >> 3;
|
|
|
|
} else
|
|
|
|
// This is not a bitfield.
|
|
|
|
OffsetInBytes = DT.getOffsetInBits() >> 3;
|
2014-01-03 08:48:38 +08:00
|
|
|
|
2014-01-03 09:30:05 +08:00
|
|
|
if (DD->getDwarfVersion() <= 2) {
|
2014-02-16 16:46:55 +08:00
|
|
|
DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc();
|
2014-04-26 02:26:14 +08:00
|
|
|
addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
|
2014-01-03 09:30:05 +08:00
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
|
|
|
|
} else
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
|
|
|
|
OffsetInBytes);
|
2013-11-01 08:25:45 +08:00
|
|
|
}
|
2011-04-13 07:21:44 +08:00
|
|
|
|
|
|
|
if (DT.isProtected())
|
2011-12-13 13:09:11 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-13 07:21:44 +08:00
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (DT.isPrivate())
|
2011-12-13 13:09:11 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-13 07:21:44 +08:00
|
|
|
dwarf::DW_ACCESS_private);
|
|
|
|
// Otherwise C++ member and base classes are considered public.
|
2014-08-30 06:44:07 +08:00
|
|
|
else if (DT.isPublic())
|
2011-12-13 13:09:11 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-13 07:21:44 +08:00
|
|
|
dwarf::DW_ACCESS_public);
|
|
|
|
if (DT.isVirtual())
|
2011-12-14 08:56:07 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
|
2011-04-13 07:21:44 +08:00
|
|
|
dwarf::DW_VIRTUALITY_virtual);
|
2011-04-16 08:11:51 +08:00
|
|
|
|
|
|
|
// Objective-C properties.
|
2012-02-07 01:49:43 +08:00
|
|
|
if (MDNode *PNode = DT.getObjCProperty())
|
|
|
|
if (DIEEntry *PropertyDie = getDIEEntry(PNode))
|
2014-04-26 02:26:14 +08:00
|
|
|
MemberDie.addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4,
|
|
|
|
PropertyDie);
|
2012-02-07 01:49:43 +08:00
|
|
|
|
2012-12-14 06:43:07 +08:00
|
|
|
if (DT.isArtificial())
|
|
|
|
addFlag(MemberDie, dwarf::DW_AT_artificial);
|
2011-04-13 07:21:44 +08:00
|
|
|
}
|
2013-01-16 09:22:23 +08:00
|
|
|
|
2013-10-15 04:33:57 +08:00
|
|
|
/// getOrCreateStaticMemberDIE - Create new DIE for C++ static member.
|
2013-12-10 07:32:48 +08:00
|
|
|
DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) {
|
2013-01-16 09:22:23 +08:00
|
|
|
if (!DT.Verify())
|
2014-04-24 14:44:33 +08:00
|
|
|
return nullptr;
|
2013-01-16 09:22:23 +08:00
|
|
|
|
2013-10-15 04:33:57 +08:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE.
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(resolve(DT.getContext()));
|
2013-11-15 05:24:34 +08:00
|
|
|
assert(dwarf::isType(ContextDIE->getTag()) &&
|
|
|
|
"Static member should belong to a type.");
|
2013-10-15 04:33:57 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
if (DIE *StaticMemberDIE = getDIE(DT))
|
2013-10-15 04:33:57 +08:00
|
|
|
return StaticMemberDIE;
|
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
DIE &StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT);
|
2013-10-15 04:33:57 +08:00
|
|
|
|
2013-10-09 02:42:58 +08:00
|
|
|
DIType Ty = resolve(DT.getTypeDerivedFrom());
|
2013-01-16 09:22:23 +08:00
|
|
|
|
|
|
|
addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName());
|
|
|
|
addType(StaticMemberDIE, Ty);
|
|
|
|
addSourceLine(StaticMemberDIE, DT);
|
|
|
|
addFlag(StaticMemberDIE, dwarf::DW_AT_external);
|
|
|
|
addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
|
|
|
|
|
|
|
|
// FIXME: We could omit private if the parent is a class_type, and
|
|
|
|
// public if the parent is something else.
|
|
|
|
if (DT.isProtected())
|
|
|
|
addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (DT.isPrivate())
|
|
|
|
addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_private);
|
2014-08-30 06:44:07 +08:00
|
|
|
else if (DT.isPublic())
|
2013-01-16 09:22:23 +08:00
|
|
|
addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
|
|
|
dwarf::DW_ACCESS_public);
|
|
|
|
|
|
|
|
if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT.getConstant()))
|
2014-05-11 23:56:59 +08:00
|
|
|
addConstantValue(StaticMemberDIE, CI, Ty);
|
2013-01-20 09:18:01 +08:00
|
|
|
if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant()))
|
|
|
|
addConstantFPValue(StaticMemberDIE, CFP);
|
2013-01-16 09:22:23 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
return &StaticMemberDIE;
|
2013-01-16 09:22:23 +08:00
|
|
|
}
|
2013-10-31 04:42:41 +08:00
|
|
|
|
2014-03-25 04:28:10 +08:00
|
|
|
void DwarfUnit::emitHeader(const MCSymbol *ASectionSym) const {
|
2013-10-31 04:42:41 +08:00
|
|
|
Asm->OutStreamer.AddComment("DWARF version number");
|
|
|
|
Asm->EmitInt16(DD->getDwarfVersion());
|
|
|
|
Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
|
2013-12-05 07:39:02 +08:00
|
|
|
// We share one abbreviations table across all units so it's always at the
|
|
|
|
// start of the section. Use a relocatable offset where needed to ensure
|
|
|
|
// linking doesn't invalidate that offset.
|
2014-03-25 04:53:02 +08:00
|
|
|
if (ASectionSym)
|
|
|
|
Asm->EmitSectionOffset(ASectionSym, ASectionSym);
|
|
|
|
else
|
2014-04-02 10:04:51 +08:00
|
|
|
// Use a constant value when no symbol is provided.
|
2014-03-25 04:53:02 +08:00
|
|
|
Asm->EmitInt32(0);
|
2013-10-31 04:42:41 +08:00
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
|
|
|
Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
|
|
|
|
}
|
2013-12-14 05:33:40 +08:00
|
|
|
|
2014-03-25 04:28:10 +08:00
|
|
|
void DwarfTypeUnit::emitHeader(const MCSymbol *ASectionSym) const {
|
|
|
|
DwarfUnit::emitHeader(ASectionSym);
|
2013-12-14 05:33:40 +08:00
|
|
|
Asm->OutStreamer.AddComment("Type Signature");
|
|
|
|
Asm->OutStreamer.EmitIntValue(TypeSignature, sizeof(TypeSignature));
|
|
|
|
Asm->OutStreamer.AddComment("Type DIE Offset");
|
2014-01-10 09:38:41 +08:00
|
|
|
// In a skeleton type unit there is no type DIE so emit a zero offset.
|
|
|
|
Asm->OutStreamer.EmitIntValue(Ty ? Ty->getOffset() : 0,
|
|
|
|
sizeof(Ty->getOffset()));
|
2013-12-14 05:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfTypeUnit::initSection(const MCSection *Section) {
|
|
|
|
assert(!this->Section);
|
|
|
|
this->Section = Section;
|
|
|
|
// Since each type unit is contained in its own COMDAT section, the begin
|
|
|
|
// label and the section label are the same. Using the begin label emission in
|
|
|
|
// DwarfDebug to emit the section label as well is slightly subtle/sneaky, but
|
|
|
|
// the only other alternative of lazily constructing start-of-section labels
|
|
|
|
// and storing a mapping in DwarfDebug (or AsmPrinter).
|
|
|
|
this->SectionSym = this->LabelBegin =
|
|
|
|
Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
|
|
|
|
this->LabelEnd =
|
|
|
|
Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
|
|
|
|
}
|