2013-12-02 19:33:10 +00:00
|
|
|
//===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===//
|
2011-04-12 23:21:44 +00: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 05:13:29 +00:00
|
|
|
// This file contains support for constructing a dwarf compile unit.
|
2011-04-12 23:21:44 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2013-12-02 19:33:15 +00:00
|
|
|
#include "DwarfUnit.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "DwarfAccelTable.h"
|
2011-04-12 23:21:44 +00:00
|
|
|
#include "DwarfDebug.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 00:22:06 +00:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2014-01-07 21:19:40 +00:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-12-28 01:39:17 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2014-02-11 22:22:15 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2013-10-30 20:42:41 +00:00
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-04-12 23:21:44 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2013-06-28 20:05:11 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2011-04-12 23:21:44 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
|
|
|
|
cl::desc("Generate DWARF4 type units."),
|
|
|
|
cl::init(false));
|
2013-11-19 23:08:21 +00:00
|
|
|
|
2013-12-02 22:09:48 +00:00
|
|
|
/// Unit - Unit constructor.
|
2014-01-09 03:03:27 +00:00
|
|
|
DwarfUnit::DwarfUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
|
|
|
|
DwarfDebug *DW, DwarfFile *DWU)
|
2014-01-09 03:23:41 +00:00
|
|
|
: UniqueID(UID), CUNode(Node), UnitDie(D), DebugInfoOffset(0), Asm(A),
|
|
|
|
DD(DW), DU(DWU), IndexTyDie(0), Section(0), Skeleton(0) {
|
2013-12-02 19:33:10 +00:00
|
|
|
DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:57:44 +00:00
|
|
|
DwarfCompileUnit::DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node,
|
|
|
|
AsmPrinter *A, DwarfDebug *DW,
|
|
|
|
DwarfFile *DWU)
|
2014-01-09 03:03:27 +00:00
|
|
|
: DwarfUnit(UID, D, Node, A, DW, DWU) {
|
2013-11-15 23:52:02 +00:00
|
|
|
insertDIE(Node, D);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 00:31:30 +00:00
|
|
|
DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU,
|
2014-03-18 01:17:26 +00:00
|
|
|
AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU,
|
2014-03-18 02:13:23 +00:00
|
|
|
MCDwarfDwoLineTable *SplitLineTable)
|
2014-03-18 01:17:26 +00:00
|
|
|
: DwarfUnit(UID, D, CU.getCUNode(), A, DW, DWU), CU(CU),
|
|
|
|
SplitLineTable(SplitLineTable) {
|
|
|
|
if (SplitLineTable)
|
|
|
|
addSectionOffset(UnitDie.get(), dwarf::DW_AT_stmt_list, 0);
|
|
|
|
}
|
2013-11-19 23:08:21 +00:00
|
|
|
|
2013-12-02 19:33:10 +00:00
|
|
|
/// ~Unit - Destructor for compile unit.
|
2013-12-09 23:32:48 +00:00
|
|
|
DwarfUnit::~DwarfUnit() {
|
2011-04-12 23:21:44 +00:00
|
|
|
for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
|
|
|
|
DIEBlocks[j]->~DIEBlock();
|
2014-02-16 08:46:55 +00:00
|
|
|
for (unsigned j = 0, M = DIELocs.size(); j < M; ++j)
|
|
|
|
DIELocs[j]->~DIELoc();
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
|
|
|
|
/// information entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIEEntry *DwarfUnit::createDIEEntry(DIE *Entry) {
|
2011-04-12 23:21:44 +00:00
|
|
|
DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:55:19 +00:00
|
|
|
/// getDefaultLowerBound - Return the default lower bound for an array. If the
|
2012-12-06 07:38:10 +00:00
|
|
|
/// DWARF version doesn't handle the language, return -1.
|
2013-12-09 23:32:48 +00:00
|
|
|
int64_t DwarfUnit::getDefaultLowerBound() const {
|
2013-11-15 23:50:53 +00:00
|
|
|
switch (getLanguage()) {
|
2012-12-06 07:38:10 +00: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-10-31 17:54:35 +00:00
|
|
|
/// Check whether the DIE for this MDNode can be shared across CUs.
|
2013-11-15 22:59:36 +00:00
|
|
|
static bool isShareableAcrossCUs(DIDescriptor D) {
|
2013-11-20 18:40:16 +00: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-19 23:08:21 +00:00
|
|
|
return (D.isType() ||
|
|
|
|
(D.isSubprogram() && !DISubprogram(D).isDefinition())) &&
|
2013-12-09 23:57:44 +00:00
|
|
|
!GenerateDwarfTypeUnits;
|
2013-10-31 17:54:35 +00: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-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getDIE(DIDescriptor D) const {
|
2013-11-15 23:09:13 +00:00
|
|
|
if (isShareableAcrossCUs(D))
|
|
|
|
return DD->getDIE(D);
|
|
|
|
return MDNodeToDieMap.lookup(D);
|
2013-10-31 17:54:35 +00: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-09 23:32:48 +00:00
|
|
|
void DwarfUnit::insertDIE(DIDescriptor Desc, DIE *D) {
|
2013-11-15 23:09:13 +00:00
|
|
|
if (isShareableAcrossCUs(Desc)) {
|
|
|
|
DD->insertDIE(Desc, D);
|
2013-10-31 17:54:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-11-15 23:09:13 +00:00
|
|
|
MDNodeToDieMap.insert(std::make_pair(Desc, D));
|
2013-10-31 17:54:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 01:14:27 +00:00
|
|
|
/// addFlag - Add a flag that is true.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addFlag(DIE *Die, dwarf::Attribute Attribute) {
|
2013-09-04 04:39:38 +00:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
2013-10-04 22:40:05 +00:00
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_flag_present, DIEIntegerOne);
|
2012-08-24 01:14:27 +00:00
|
|
|
else
|
2013-10-04 22:40:05 +00:00
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_flag, DIEIntegerOne);
|
2012-08-24 01:14:27 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addUInt - Add an unsigned integer attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addUInt(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
Optional<dwarf::Form> Form, uint64_t Integer) {
|
2013-10-19 01:04:47 +00:00
|
|
|
if (!Form)
|
|
|
|
Form = DIEInteger::BestForm(false, Integer);
|
|
|
|
DIEValue *Value = Integer == 1 ? DIEIntegerOne : new (DIEValueAllocator)
|
|
|
|
DIEInteger(Integer);
|
2013-10-21 17:28:37 +00:00
|
|
|
Die->addValue(Attribute, *Form, Value);
|
|
|
|
}
|
|
|
|
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addUInt(DIE *Block, dwarf::Form Form, uint64_t Integer) {
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Block, (dwarf::Attribute)0, Form, Integer);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSInt - Add an signed integer attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSInt(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
Optional<dwarf::Form> Form, int64_t Integer) {
|
2013-10-19 01:04:47 +00:00
|
|
|
if (!Form)
|
|
|
|
Form = DIEInteger::BestForm(true, Integer);
|
2011-04-12 23:21:44 +00:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
|
2013-10-21 17:28:37 +00:00
|
|
|
Die->addValue(Attribute, *Form, Value);
|
|
|
|
}
|
|
|
|
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addSInt(DIELoc *Die, Optional<dwarf::Form> Form,
|
2013-12-09 23:32:48 +00:00
|
|
|
int64_t Integer) {
|
2013-10-21 17:28:37 +00:00
|
|
|
addSInt(Die, (dwarf::Attribute)0, Form, Integer);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 05:29:47 +00: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-07 19:32:45 +00: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.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addString(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
StringRef String) {
|
2013-12-30 18:32:31 +00:00
|
|
|
|
|
|
|
if (!DD->useSplitDwarf())
|
|
|
|
return addLocalString(Die, Attribute, String);
|
|
|
|
|
|
|
|
unsigned idx = DU->getStringPoolIndex(String);
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx);
|
2013-07-26 17:02:41 +00:00
|
|
|
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
|
2013-12-30 18:32:31 +00:00
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Str);
|
2013-01-07 19:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addLocalString - Add a string attribute data and value. This is guaranteed
|
|
|
|
/// to be in the local string pool instead of indirected.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addLocalString(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
StringRef String) {
|
2012-12-20 21:58:36 +00:00
|
|
|
MCSymbol *Symb = DU->getStringPoolEntry(String);
|
2011-10-28 05:29:47 +00:00
|
|
|
DIEValue *Value;
|
2013-12-28 01:39:17 +00:00
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
2013-07-02 18:46:26 +00:00
|
|
|
Value = new (DIEValueAllocator) DIELabel(Symb);
|
2011-10-28 05:29:47 +00:00
|
|
|
else {
|
2012-12-20 21:58:36 +00:00
|
|
|
MCSymbol *StringPool = DU->getStringPoolSym();
|
2011-10-28 05:29:47 +00:00
|
|
|
Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool);
|
2011-10-27 06:44:11 +00:00
|
|
|
}
|
2013-12-30 18:32:31 +00:00
|
|
|
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_strp, Str);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 18:46:26 +00:00
|
|
|
/// addExpr - Add a Dwarf expression attribute data and value.
|
2011-04-12 23:21:44 +00:00
|
|
|
///
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addExpr(DIELoc *Die, dwarf::Form Form, const MCExpr *Expr) {
|
2013-07-02 18:46:26 +00:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEExpr(Expr);
|
2013-10-21 17:28:37 +00:00
|
|
|
Die->addValue((dwarf::Attribute)0, Form, Value);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 22:41:20 +00:00
|
|
|
/// addLocationList - Add a Dwarf loclistptr attribute data and value.
|
|
|
|
///
|
|
|
|
void DwarfUnit::addLocationList(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
unsigned Index) {
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELocList(Index);
|
|
|
|
dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
|
|
|
|
: dwarf::DW_FORM_data4;
|
|
|
|
Die->addValue(Attribute, Form, Value);
|
|
|
|
}
|
|
|
|
|
2013-07-02 18:46:26 +00:00
|
|
|
/// addLabel - Add a Dwarf label attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
|
|
|
|
const MCSymbol *Label) {
|
2013-07-02 18:46:26 +00:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
|
|
|
|
Die->addValue(Attribute, Form, Value);
|
2013-06-28 20:05:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addLabel(DIELoc *Die, dwarf::Form Form, const MCSymbol *Label) {
|
2013-10-21 17:28:37 +00:00
|
|
|
addLabel(Die, (dwarf::Attribute)0, Form, Label);
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:46:41 +00:00
|
|
|
/// addSectionLabel - Add a Dwarf section label attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
const MCSymbol *Label) {
|
2013-11-21 23:46:41 +00:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
|
|
|
addLabel(Die, Attribute, dwarf::DW_FORM_sec_offset, Label);
|
|
|
|
else
|
|
|
|
addLabel(Die, Attribute, dwarf::DW_FORM_data4, Label);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addSectionOffset - Add an offset into a section attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSectionOffset(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
uint64_t Integer) {
|
2013-11-21 23:46:41 +00:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
|
|
|
addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
|
|
|
|
else
|
|
|
|
addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:56:56 +00:00
|
|
|
/// addLabelAddress - Add a dwarf label attribute data and value using
|
|
|
|
/// DW_FORM_addr or DW_FORM_GNU_addr_index.
|
|
|
|
///
|
2013-12-09 23:57:44 +00:00
|
|
|
void DwarfCompileUnit::addLabelAddress(DIE *Die, dwarf::Attribute Attribute,
|
2014-03-20 19:16:16 +00:00
|
|
|
const MCSymbol *Label) {
|
|
|
|
|
|
|
|
if (!DD->useSplitDwarf())
|
|
|
|
return addLocalLabelAddress(Die, Attribute, Label);
|
|
|
|
|
2014-03-19 22:42:36 +00:00
|
|
|
if (Label)
|
|
|
|
DD->addArangeLabel(SymbolCU(this, Label));
|
|
|
|
|
2014-03-20 19:16:16 +00:00
|
|
|
unsigned idx = DU->getAddrPoolIndex(Label);
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx);
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_GNU_addr_index, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfCompileUnit::addLocalLabelAddress(DIE *Die,
|
|
|
|
dwarf::Attribute Attribute,
|
|
|
|
const MCSymbol *Label) {
|
|
|
|
if (Label)
|
|
|
|
DD->addArangeLabel(SymbolCU(this, Label));
|
|
|
|
|
|
|
|
if (Label) {
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_addr, Value);
|
2013-01-15 23:56:56 +00:00
|
|
|
} else {
|
2014-03-20 19:16:16 +00:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(0);
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_addr, Value);
|
2013-01-15 23:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 23:53:25 +00:00
|
|
|
unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) {
|
|
|
|
// If we print assembly, we can't separate .file entries according to
|
|
|
|
// compile units. Thus all files will belong to the default compile unit.
|
|
|
|
|
|
|
|
// FIXME: add a better feature test than hasRawTextSupport. Even better,
|
|
|
|
// extend .file to support this.
|
|
|
|
return Asm->OutStreamer.EmitDwarfFileDirective(
|
|
|
|
0, DirName, FileName,
|
|
|
|
Asm->OutStreamer.hasRawTextSupport() ? 0 : getUniqueID());
|
|
|
|
}
|
|
|
|
|
2014-03-18 01:17:26 +00:00
|
|
|
unsigned DwarfTypeUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) {
|
|
|
|
return SplitLineTable ? SplitLineTable->getFile(DirName, FileName)
|
|
|
|
: getCU().getOrCreateSourceID(FileName, DirName);
|
|
|
|
}
|
|
|
|
|
2013-01-18 22:11:33 +00: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-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addOpAddress(DIELoc *Die, const MCSymbol *Sym) {
|
2013-01-18 22:11:33 +00:00
|
|
|
if (!DD->useSplitDwarf()) {
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
|
|
|
|
addLabel(Die, dwarf::DW_FORM_udata, Sym);
|
2013-01-18 22:11:33 +00:00
|
|
|
} else {
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
|
|
|
|
addUInt(Die, dwarf::DW_FORM_GNU_addr_index, DU->getAddrPoolIndex(Sym));
|
2013-01-18 22:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:46:41 +00:00
|
|
|
/// addSectionDelta - Add a section label delta attribute data and value.
|
2011-04-12 23:21:44 +00:00
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSectionDelta(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
const MCSymbol *Hi, const MCSymbol *Lo) {
|
2011-04-12 23:21:44 +00:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
|
2013-11-21 23:46:41 +00:00
|
|
|
if (DD->getDwarfVersion() >= 4)
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_sec_offset, Value);
|
|
|
|
else
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_data4, Value);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 01:30:55 +00:00
|
|
|
void DwarfUnit::addLabelDelta(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
const MCSymbol *Hi, const MCSymbol *Lo) {
|
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
|
|
|
|
Die->addValue(Attribute, dwarf::DW_FORM_data4, Value);
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addDIEEntry - Add a DIE attribute data and value.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry) {
|
2013-10-31 17:54:35 +00:00
|
|
|
addDIEEntry(Die, Attribute, createDIEEntry(Entry));
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:32:35 +00:00
|
|
|
void DwarfUnit::addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type) {
|
|
|
|
Die->addValue(dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
|
|
|
|
new (DIEValueAllocator) DIETypeSignature(Type));
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
DIEEntry *Entry) {
|
2013-11-19 23:08:21 +00:00
|
|
|
const DIE *DieCU = Die->getUnitOrNull();
|
|
|
|
const DIE *EntryCU = Entry->getEntry()->getUnitOrNull();
|
2013-10-31 17:54:35 +00:00
|
|
|
if (!DieCU)
|
|
|
|
// We assume that Die belongs to this CU, if it is not linked to any CU yet.
|
2013-12-02 22:09:48 +00:00
|
|
|
DieCU = getUnitDie();
|
2013-10-31 17:54:35 +00:00
|
|
|
if (!EntryCU)
|
2013-12-02 22:09:48 +00:00
|
|
|
EntryCU = getUnitDie();
|
2013-10-31 17:54:35 +00:00
|
|
|
Die->addValue(Attribute, EntryCU == DieCU ? dwarf::DW_FORM_ref4
|
|
|
|
: dwarf::DW_FORM_ref_addr,
|
|
|
|
Entry);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 00:53:03 +00:00
|
|
|
/// Create a DIE with the given Tag, add the DIE to its parent, and
|
|
|
|
/// call insertDIE if MD is not null.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) {
|
2014-04-12 02:24:04 +00:00
|
|
|
assert(Tag != dwarf::DW_TAG_auto_variable &&
|
|
|
|
Tag != dwarf::DW_TAG_arg_variable);
|
|
|
|
DIE *Die = new DIE((dwarf::Tag)Tag);
|
2013-10-29 00:53:03 +00:00
|
|
|
Parent.addChild(Die);
|
2013-11-16 00:29:01 +00:00
|
|
|
if (N)
|
|
|
|
insertDIE(N, Die);
|
2013-10-29 00:53:03 +00:00
|
|
|
return Die;
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addBlock - Add block data.
|
|
|
|
///
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Loc) {
|
2014-02-27 18:36:10 +00:00
|
|
|
Loc->ComputeSize(Asm);
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
|
|
|
|
Die->addValue(Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
DIEBlock *Block) {
|
2014-02-27 18:36:10 +00:00
|
|
|
Block->ComputeSize(Asm);
|
2011-04-12 23:21:44 +00:00
|
|
|
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
|
|
|
|
Die->addValue(Attribute, Block->BestForm(), Block);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2014-02-12 00:11:25 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, unsigned Line, StringRef File,
|
|
|
|
StringRef Directory) {
|
2011-04-12 23:21:44 +00:00
|
|
|
if (Line == 0)
|
|
|
|
return;
|
2014-02-12 00:11:25 +00:00
|
|
|
|
2014-03-18 01:17:26 +00:00
|
|
|
unsigned FileID = getOrCreateSourceID(File, Directory);
|
2011-04-12 23:21:44 +00:00
|
|
|
assert(FileID && "Invalid file id");
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 00:11:25 +00:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DIVariable V) {
|
|
|
|
assert(V.isVariable());
|
|
|
|
|
2014-02-12 22:38:04 +00:00
|
|
|
addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(),
|
|
|
|
V.getContext().getDirectory());
|
2014-02-12 00:11:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DIGlobalVariable G) {
|
2014-02-11 23:57:03 +00:00
|
|
|
assert(G.isGlobalVariable());
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2014-02-12 00:11:25 +00:00
|
|
|
addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DISubprogram SP) {
|
2014-02-11 23:57:03 +00:00
|
|
|
assert(SP.isSubprogram());
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2014-02-12 00:11:25 +00:00
|
|
|
addSourceLine(Die, SP.getLineNumber(), SP.getFilename(), SP.getDirectory());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DIType Ty) {
|
2014-02-11 23:57:03 +00:00
|
|
|
assert(Ty.isType());
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2014-02-12 00:11:25 +00:00
|
|
|
addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 08:42:56 +00:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DIObjCProperty Ty) {
|
2014-02-11 23:57:03 +00:00
|
|
|
assert(Ty.isObjCProperty());
|
2012-03-29 08:42:56 +00:00
|
|
|
|
|
|
|
DIFile File = Ty.getFile();
|
2014-02-12 00:11:25 +00:00
|
|
|
addSourceLine(Die, Ty.getLineNumber(), File.getFilename(),
|
|
|
|
File.getDirectory());
|
2012-03-29 08:42:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addSourceLine(DIE *Die, DINameSpace NS) {
|
2014-02-11 23:57:03 +00:00
|
|
|
assert(NS.Verify());
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2014-02-12 00:11:25 +00:00
|
|
|
addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 00:34:38 +00:00
|
|
|
/// addVariableAddress - Add DW_AT_location attribute for a
|
2011-04-27 22:45:24 +00:00
|
|
|
/// DbgVariable based on provided MachineLocation.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addVariableAddress(const DbgVariable &DV, DIE *Die,
|
|
|
|
MachineLocation Location) {
|
2013-06-24 21:07:27 +00:00
|
|
|
if (DV.variableHasComplexAddress())
|
2011-04-12 23:21:44 +00:00
|
|
|
addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
|
2013-06-24 21:07:27 +00:00
|
|
|
else if (DV.isBlockByrefVariable())
|
2011-04-12 23:21:44 +00:00
|
|
|
addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location);
|
|
|
|
else
|
2013-06-20 00:25:24 +00:00
|
|
|
addAddress(Die, dwarf::DW_AT_location, Location,
|
2013-06-24 21:07:27 +00:00
|
|
|
DV.getVariable().isIndirect());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-04-26 19:06:18 +00:00
|
|
|
/// addRegisterOp - Add register operand.
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addRegisterOp(DIELoc *TheDie, unsigned Reg) {
|
2011-04-26 19:06:18 +00:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
2014-02-11 22:22:15 +00: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-26 23:27:16 +00:00
|
|
|
DEBUG(dbgs() << "Invalid Dwarf register number.\n");
|
2014-02-11 22:22:15 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_nop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit register
|
2011-04-26 19:06:18 +00:00
|
|
|
if (DWReg < 32)
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + DWReg);
|
2011-04-26 19:06:18 +00:00
|
|
|
else {
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_regx);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_udata, DWReg);
|
2011-04-26 19:06:18 +00:00
|
|
|
}
|
2014-02-11 22:22:15 +00:00
|
|
|
|
|
|
|
// Emit Mask
|
|
|
|
if (isSubRegister) {
|
|
|
|
unsigned Size = RI->getSubRegIdxSize(Idx);
|
|
|
|
unsigned Offset = RI->getSubRegIdxOffset(Idx);
|
|
|
|
if (Offset > 0) {
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, Size);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, Offset);
|
|
|
|
} else {
|
2014-02-12 19:34:44 +00:00
|
|
|
unsigned ByteSize = Size / 8; // Assuming 8 bits per byte.
|
2014-02-11 22:22:15 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_piece);
|
2014-02-12 19:34:44 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, ByteSize);
|
2014-02-11 22:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-26 19:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addRegisterOffset - Add register offset.
|
2014-02-16 08:46:55 +00:00
|
|
|
void DwarfUnit::addRegisterOffset(DIELoc *TheDie, unsigned Reg,
|
2013-12-09 23:32:48 +00:00
|
|
|
int64_t Offset) {
|
2011-04-26 19:06:18 +00:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
unsigned DWReg = RI->getDwarfRegNum(Reg, false);
|
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
|
|
|
|
if (Reg == TRI->getFrameRegister(*Asm->MF))
|
|
|
|
// If variable offset is based in frame register then use fbreg.
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg);
|
2011-04-26 19:06:18 +00:00
|
|
|
else if (DWReg < 32)
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DWReg);
|
2011-04-26 19:06:18 +00:00
|
|
|
else {
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
|
|
|
|
addUInt(TheDie, dwarf::DW_FORM_udata, DWReg);
|
2011-04-26 19:06:18 +00:00
|
|
|
}
|
2013-10-21 17:28:37 +00:00
|
|
|
addSInt(TheDie, dwarf::DW_FORM_sdata, Offset);
|
2011-04-26 19:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addAddress - Add an address attribute to a die based on the location
|
|
|
|
/// provided.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addAddress(DIE *Die, dwarf::Attribute Attribute,
|
|
|
|
const MachineLocation &Location, bool Indirect) {
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2011-04-26 19:06:18 +00:00
|
|
|
|
2013-06-20 00:25:24 +00:00
|
|
|
if (Location.isReg() && !Indirect)
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOp(Loc, Location.getReg());
|
2013-06-20 00:25:24 +00:00
|
|
|
else {
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOffset(Loc, Location.getReg(), Location.getOffset());
|
2013-06-20 00:25:24 +00:00
|
|
|
if (Indirect && !Location.isReg()) {
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2013-06-20 00:25:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-26 19:06:18 +00:00
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 08:46:55 +00:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-26 19:06:18 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00: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 00:13:15 +00:00
|
|
|
/// given the extra address information encoded in the DbgVariable, starting
|
|
|
|
/// from the starting location. Add the DWARF information to the die.
|
2011-04-12 23:21:44 +00:00
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addComplexAddress(const DbgVariable &DV, DIE *Die,
|
|
|
|
dwarf::Attribute Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2013-06-24 21:07:27 +00:00
|
|
|
unsigned N = DV.getNumAddrElements();
|
2011-04-28 02:22:40 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
if (Location.isReg()) {
|
2013-06-24 21:07:27 +00:00
|
|
|
if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) {
|
2011-04-28 02:22:40 +00:00
|
|
|
// If first address element is OpPlus then emit
|
|
|
|
// DW_OP_breg + Offset instead of DW_OP_reg + Offset.
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOffset(Loc, Location.getReg(), DV.getAddrElement(1));
|
2011-04-28 02:22:40 +00:00
|
|
|
i = 2;
|
|
|
|
} else
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOp(Loc, Location.getReg());
|
2013-10-19 01:04:47 +00:00
|
|
|
} else
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOffset(Loc, Location.getReg(), Location.getOffset());
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-10-19 01:04:47 +00:00
|
|
|
for (; i < N; ++i) {
|
2013-06-24 21:07:27 +00:00
|
|
|
uint64_t Element = DV.getAddrElement(i);
|
2011-04-12 23:21:44 +00:00
|
|
|
if (Element == DIBuilder::OpPlus) {
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(Loc, dwarf::DW_FORM_udata, DV.getAddrElement(++i));
|
2011-04-12 23:21:44 +00:00
|
|
|
} else if (Element == DIBuilder::OpDeref) {
|
2012-05-08 18:56:00 +00:00
|
|
|
if (!Location.isReg())
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2013-10-19 01:04:47 +00:00
|
|
|
} else
|
|
|
|
llvm_unreachable("unknown DIBuilder Opcode");
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 08:46:55 +00:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as "SomeType
|
|
|
|
VarName;", but the compiler creates a __Block_byref_x_VarName struct, and
|
|
|
|
gives the variable VarName either the struct, or a pointer to the struct, as
|
|
|
|
its type. This is necessary for various behind-the-scenes things the
|
|
|
|
compiler needs to do with by-reference variables in Blocks.
|
|
|
|
|
|
|
|
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.
|
|
|
|
///
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
|
|
|
|
dwarf::Attribute Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2013-06-24 21:07:27 +00:00
|
|
|
DIType Ty = DV.getType();
|
2011-04-12 23:21:44 +00:00
|
|
|
DIType TmpTy = Ty;
|
2013-08-08 01:41:00 +00:00
|
|
|
uint16_t Tag = Ty.getTag();
|
2011-04-12 23:21:44 +00:00
|
|
|
bool isPointer = false;
|
|
|
|
|
2013-06-24 21:07:27 +00:00
|
|
|
StringRef varName = DV.getName();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
if (Tag == dwarf::DW_TAG_pointer_type) {
|
2013-11-18 23:33:32 +00:00
|
|
|
DIDerivedType DTy(Ty);
|
2013-10-08 18:42:58 +00:00
|
|
|
TmpTy = resolve(DTy.getTypeDerivedFrom());
|
2011-04-12 23:21:44 +00:00
|
|
|
isPointer = true;
|
|
|
|
}
|
|
|
|
|
2013-11-18 23:33:32 +00:00
|
|
|
DICompositeType blockStruct(TmpTy);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Find the __forwarding field and the variable field in the __Block_byref
|
|
|
|
// struct.
|
|
|
|
DIArray Fields = blockStruct.getTypeArray();
|
2013-11-18 23:33:32 +00:00
|
|
|
DIDerivedType varField;
|
|
|
|
DIDerivedType forwardingField;
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
|
2013-11-18 23:33:32 +00:00
|
|
|
DIDerivedType DT(Fields.getElement(i));
|
2011-04-12 23:21:44 +00:00
|
|
|
StringRef fieldName = DT.getName();
|
|
|
|
if (fieldName == "__forwarding")
|
2013-11-18 23:33:32 +00:00
|
|
|
forwardingField = DT;
|
2011-04-12 23:21:44 +00:00
|
|
|
else if (fieldName == varName)
|
2013-11-18 23:33:32 +00:00
|
|
|
varField = DT;
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the offsets for the forwarding field and the variable field.
|
2013-11-18 23:33:32 +00:00
|
|
|
unsigned forwardingFieldOffset = forwardingField.getOffsetInBits() >> 3;
|
|
|
|
unsigned varFieldOffset = varField.getOffsetInBits() >> 2;
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Decode the original location, and use that as the start of the byref
|
|
|
|
// variable's location.
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2012-07-04 02:02:18 +00:00
|
|
|
if (Location.isReg())
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOp(Loc, Location.getReg());
|
2012-07-04 02:02:18 +00:00
|
|
|
else
|
2014-02-16 08:46:55 +00:00
|
|
|
addRegisterOffset(Loc, Location.getReg(), Location.getOffset());
|
2011-04-12 23:21:44 +00: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-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2011-04-12 23:21:44 +00: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-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(Loc, dwarf::DW_FORM_udata, forwardingFieldOffset);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now dereference the __forwarding field to get to the real __Block_byref
|
|
|
|
// struct: DW_OP_deref.
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2011-04-12 23:21:44 +00: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-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(Loc, dwarf::DW_FORM_udata, varFieldOffset);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2014-02-16 08:46:55 +00:00
|
|
|
addBlock(Die, Attribute, Loc);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 21:57:04 +00:00
|
|
|
/// isTypeSigned - Return true if the type is signed.
|
2013-10-05 01:43:03 +00:00
|
|
|
static bool isTypeSigned(DwarfDebug *DD, DIType Ty, int *SizeInBits) {
|
2011-07-20 21:57:04 +00:00
|
|
|
if (Ty.isDerivedType())
|
2013-10-05 01:43:03 +00:00
|
|
|
return isTypeSigned(DD, DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()),
|
|
|
|
SizeInBits);
|
2011-07-20 21:57:04 +00:00
|
|
|
if (Ty.isBasicType())
|
2013-10-19 01:04:47 +00:00
|
|
|
if (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed ||
|
|
|
|
DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char) {
|
2011-07-20 21:57:04 +00:00
|
|
|
*SizeInBits = Ty.getSizeInBits();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-05 01:43:03 +00:00
|
|
|
/// Return true if type encoding is unsigned.
|
|
|
|
static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
|
|
|
|
DIDerivedType DTy(Ty);
|
|
|
|
if (DTy.isDerivedType())
|
|
|
|
return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom()));
|
|
|
|
|
|
|
|
DIBasicType BTy(Ty);
|
|
|
|
if (BTy.isBasicType()) {
|
|
|
|
unsigned Encoding = BTy.getEncoding();
|
|
|
|
if (Encoding == dwarf::DW_ATE_unsigned ||
|
|
|
|
Encoding == dwarf::DW_ATE_unsigned_char ||
|
|
|
|
Encoding == dwarf::DW_ATE_boolean)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If this type is derived from a base type then return base type size.
|
2013-10-08 18:46:58 +00:00
|
|
|
static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
|
2013-10-05 01:43:03 +00: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-12 18:18:05 +00: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 01:43:03 +00: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-08 18:46:58 +00:00
|
|
|
return getBaseTypeSize(DD, DIDerivedType(BaseType));
|
2013-10-05 01:43:03 +00:00
|
|
|
|
|
|
|
return BaseType.getSizeInBits();
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addConstantValue - Add constant value entry in variable DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addConstantValue(DIE *Die, const MachineOperand &MO,
|
|
|
|
DIType Ty) {
|
2013-05-10 21:52:07 +00:00
|
|
|
// FIXME: This is a bit conservative/simple - it emits negative values at
|
|
|
|
// their maximum bit width which is a bit unfortunate (& doesn't prefer
|
|
|
|
// udata/sdata over dataN as suggested by the DWARF spec)
|
2011-10-26 22:55:33 +00:00
|
|
|
assert(MO.isImm() && "Invalid machine operand!");
|
2011-07-20 21:57:04 +00:00
|
|
|
int SizeInBits = -1;
|
2013-10-05 01:43:03 +00:00
|
|
|
bool SignedConstant = isTypeSigned(DD, Ty, &SizeInBits);
|
2013-10-21 17:28:37 +00:00
|
|
|
dwarf::Form Form;
|
2013-08-27 23:49:04 +00:00
|
|
|
|
|
|
|
// If we're a signed constant definitely use sdata.
|
|
|
|
if (SignedConstant) {
|
|
|
|
addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, MO.getImm());
|
|
|
|
return;
|
2011-05-27 19:13:26 +00:00
|
|
|
}
|
2011-05-27 18:15:52 +00:00
|
|
|
|
2013-08-27 23:49:04 +00:00
|
|
|
// Else use data for now unless it's larger than we can deal with.
|
|
|
|
switch (SizeInBits) {
|
|
|
|
case 8:
|
|
|
|
Form = dwarf::DW_FORM_data1;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
Form = dwarf::DW_FORM_data2;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
Form = dwarf::DW_FORM_data4;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
Form = dwarf::DW_FORM_data8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Form = dwarf::DW_FORM_udata;
|
|
|
|
addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addConstantFPValue - Add constant value entry in variable DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addConstantFPValue(DIE *Die, const MachineOperand &MO) {
|
2013-10-19 01:04:47 +00:00
|
|
|
assert(MO.isFPImm() && "Invalid machine operand!");
|
2011-04-12 23:21:44 +00: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 01:04:47 +00:00
|
|
|
const char *FltPtr = (const char *)FltVal.getRawData();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
|
2012-10-08 16:38:25 +00:00
|
|
|
bool LittleEndian = Asm->getDataLayout().isLittleEndian();
|
2011-04-12 23:21:44 +00: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)
|
2013-11-11 18:52:36 +00:00
|
|
|
addUInt(Block, dwarf::DW_FORM_data1, (unsigned char)0xFF & FltPtr[Start]);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-10-21 17:28:37 +00:00
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, Block);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 01:18:01 +00:00
|
|
|
/// addConstantFPValue - Add constant value entry in variable DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addConstantFPValue(DIE *Die, const ConstantFP *CFP) {
|
2013-08-27 23:49:04 +00:00
|
|
|
// Pass this down to addConstantValue as an unsigned bag of bits.
|
|
|
|
addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
|
2013-01-20 01:18:01 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// addConstantValue - Add constant value entry in variable DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addConstantValue(DIE *Die, const ConstantInt *CI,
|
|
|
|
bool Unsigned) {
|
2013-07-03 01:08:30 +00:00
|
|
|
addConstantValue(Die, CI->getValue(), Unsigned);
|
2013-01-20 01:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// addConstantValue - Add constant value entry in variable DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addConstantValue(DIE *Die, const APInt &Val, bool Unsigned) {
|
2013-01-20 01:18:01 +00:00
|
|
|
unsigned CIBitWidth = Val.getBitWidth();
|
2011-05-28 00:39:18 +00:00
|
|
|
if (CIBitWidth <= 64) {
|
2013-08-27 23:49:04 +00:00
|
|
|
// If we're a signed constant definitely use sdata.
|
|
|
|
if (!Unsigned) {
|
|
|
|
addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
|
|
|
Val.getSExtValue());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Else use data for now unless it's larger than we can deal with.
|
2013-10-21 17:28:37 +00:00
|
|
|
dwarf::Form Form;
|
2011-05-28 00:39:18 +00:00
|
|
|
switch (CIBitWidth) {
|
2013-08-27 23:49:04 +00:00
|
|
|
case 8:
|
|
|
|
Form = dwarf::DW_FORM_data1;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
Form = dwarf::DW_FORM_data2;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
Form = dwarf::DW_FORM_data4;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
Form = dwarf::DW_FORM_data8;
|
|
|
|
break;
|
2012-11-21 00:34:38 +00:00
|
|
|
default:
|
2013-08-27 23:49:04 +00:00
|
|
|
addUInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
|
|
|
|
Val.getZExtValue());
|
|
|
|
return;
|
2011-05-28 00:39:18 +00:00
|
|
|
}
|
2013-08-27 23:49:04 +00:00
|
|
|
addUInt(Die, dwarf::DW_AT_const_value, Form, Val.getZExtValue());
|
2013-07-03 01:08:30 +00:00
|
|
|
return;
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
|
|
|
|
// Get the raw data form of the large APInt.
|
2011-10-28 14:12:22 +00:00
|
|
|
const uint64_t *Ptr64 = Val.getRawData();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
|
2012-10-08 16:38:25 +00:00
|
|
|
bool LittleEndian = Asm->getDataLayout().isLittleEndian();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Output the constant to DWARF one byte at a time.
|
2011-10-28 14:12:22 +00: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));
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Block, dwarf::DW_FORM_data1, c);
|
2011-10-28 14:12:22 +00:00
|
|
|
}
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-10-21 17:28:37 +00:00
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, Block);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 07:47:40 +00:00
|
|
|
/// addTemplateParams - Add template parameters into buffer.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) {
|
2011-04-12 23:21:44 +00:00
|
|
|
// Add template parameters.
|
|
|
|
for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) {
|
|
|
|
DIDescriptor Element = TParams.getElement(i);
|
|
|
|
if (Element.isTemplateTypeParameter())
|
2013-10-23 23:05:28 +00:00
|
|
|
constructTemplateTypeParameterDIE(Buffer,
|
|
|
|
DITemplateTypeParameter(Element));
|
2011-04-12 23:21:44 +00:00
|
|
|
else if (Element.isTemplateValueParameter())
|
2013-10-23 23:05:28 +00:00
|
|
|
constructTemplateValueParameterDIE(Buffer,
|
|
|
|
DITemplateValueParameter(Element));
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-26 22:55:33 +00:00
|
|
|
|
2013-01-16 01:22:23 +00:00
|
|
|
/// getOrCreateContextDIE - Get context owner's DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) {
|
2013-11-14 21:24:34 +00:00
|
|
|
if (!Context || Context.isFile())
|
2013-12-02 22:09:48 +00:00
|
|
|
return getUnitDie();
|
2013-01-16 01:22:23 +00:00
|
|
|
if (Context.isType())
|
|
|
|
return getOrCreateTypeDIE(DIType(Context));
|
2013-11-14 19:37:56 +00:00
|
|
|
if (Context.isNameSpace())
|
2013-01-16 01:22:23 +00:00
|
|
|
return getOrCreateNameSpace(DINameSpace(Context));
|
2013-11-14 19:37:56 +00:00
|
|
|
if (Context.isSubprogram())
|
2013-01-16 01:22:23 +00:00
|
|
|
return getOrCreateSubprogramDIE(DISubprogram(Context));
|
2013-11-15 21:05:09 +00:00
|
|
|
return getDIE(Context);
|
2013-01-16 01:22:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
|
2013-11-26 00:15:27 +00:00
|
|
|
DIScope Context = resolve(Ty.getContext());
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(Context);
|
2013-11-19 23:08:21 +00:00
|
|
|
|
|
|
|
DIE *TyDIE = getDIE(Ty);
|
|
|
|
if (TyDIE)
|
|
|
|
return TyDIE;
|
|
|
|
|
|
|
|
// Create new type.
|
|
|
|
TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
|
|
|
|
|
2013-11-26 00:35:04 +00:00
|
|
|
constructTypeDIE(*TyDIE, Ty);
|
2013-11-19 23:08:21 +00:00
|
|
|
|
2013-11-26 00:15:27 +00:00
|
|
|
updateAcceleratorTables(Context, Ty, TyDIE);
|
2013-11-19 23:08:21 +00:00
|
|
|
return TyDIE;
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
|
|
|
|
/// given DIType.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
|
2013-11-14 22:25:02 +00:00
|
|
|
if (!TyNode)
|
2011-08-16 22:09:43 +00:00
|
|
|
return NULL;
|
2013-10-29 22:49:29 +00:00
|
|
|
|
2013-11-14 22:25:02 +00:00
|
|
|
DIType Ty(TyNode);
|
|
|
|
assert(Ty.isType());
|
2014-03-24 21:33:01 +00:00
|
|
|
assert(Ty == resolve(Ty.getRef()) &&
|
2014-03-18 02:35:03 +00:00
|
|
|
"type was not uniqued, possible ODR violation.");
|
2013-11-14 22:25:02 +00:00
|
|
|
|
2013-10-29 22:49:29 +00:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE.
|
2013-11-26 00:15:27 +00:00
|
|
|
DIScope Context = resolve(Ty.getContext());
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(Context);
|
2013-11-15 23:21:39 +00:00
|
|
|
assert(ContextDIE);
|
2013-10-29 22:49:29 +00:00
|
|
|
|
2013-10-04 17:08:38 +00:00
|
|
|
DIE *TyDIE = getDIE(Ty);
|
2011-04-12 23:21:44 +00:00
|
|
|
if (TyDIE)
|
|
|
|
return TyDIE;
|
|
|
|
|
|
|
|
// Create new type.
|
2013-10-29 22:49:29 +00:00
|
|
|
TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
|
|
|
|
|
2014-03-06 01:42:00 +00:00
|
|
|
updateAcceleratorTables(Context, Ty, TyDIE);
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
if (Ty.isBasicType())
|
|
|
|
constructTypeDIE(*TyDIE, DIBasicType(Ty));
|
2013-11-26 00:22:37 +00:00
|
|
|
else if (Ty.isCompositeType()) {
|
|
|
|
DICompositeType CTy(Ty);
|
2014-01-03 18:59:42 +00:00
|
|
|
if (GenerateDwarfTypeUnits && !Ty.isForwardDecl())
|
|
|
|
if (MDString *TypeId = CTy.getIdentifier()) {
|
2014-02-12 00:31:30 +00:00
|
|
|
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
|
2014-03-14 23:08:17 +00:00
|
|
|
// Skip updating the accelerator tables since this is not the full type.
|
2014-01-03 18:59:42 +00:00
|
|
|
return TyDIE;
|
|
|
|
}
|
2013-11-26 00:35:04 +00:00
|
|
|
constructTypeDIE(*TyDIE, CTy);
|
2013-11-26 00:22:37 +00:00
|
|
|
} else {
|
2011-04-12 23:21:44 +00:00
|
|
|
assert(Ty.isDerivedType() && "Unknown kind of DIType");
|
|
|
|
constructTypeDIE(*TyDIE, DIDerivedType(Ty));
|
|
|
|
}
|
2013-11-19 22:51:04 +00:00
|
|
|
|
|
|
|
return TyDIE;
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
|
|
|
|
const DIE *TyDIE) {
|
2012-01-06 04:35:23 +00:00
|
|
|
if (!Ty.getName().empty() && !Ty.isForwardDecl()) {
|
|
|
|
bool IsImplementation = 0;
|
|
|
|
if (Ty.isCompositeType()) {
|
|
|
|
DICompositeType CT(Ty);
|
2012-01-06 23:03:37 +00: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 01:04:47 +00:00
|
|
|
IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete();
|
2012-01-06 04:35:23 +00:00
|
|
|
}
|
2013-09-05 18:20:16 +00:00
|
|
|
unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
|
2012-01-06 23:03:37 +00:00
|
|
|
addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags));
|
2013-11-26 00:15:27 +00:00
|
|
|
|
2014-03-12 03:34:38 +00:00
|
|
|
if ((!Context || Context.isCompileUnit() || Context.isFile() ||
|
|
|
|
Context.isNameSpace()) &&
|
|
|
|
getCUNode().getEmissionKind() != DIBuilder::LineTablesOnly)
|
2013-11-26 00:15:27 +00:00
|
|
|
GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = TyDIE;
|
2012-01-06 04:35:23 +00:00
|
|
|
}
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addType - Add a new type attribute to the specified entity.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addType(DIE *Entity, DIType Ty, dwarf::Attribute Attribute) {
|
2013-08-08 07:40:37 +00:00
|
|
|
assert(Ty && "Trying to add a type that doesn't exist?");
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Check for pre-existence.
|
|
|
|
DIEEntry *Entry = getDIEEntry(Ty);
|
|
|
|
// If it exists then use the existing value.
|
|
|
|
if (Entry) {
|
2013-10-31 17:54:35 +00:00
|
|
|
addDIEEntry(Entity, Attribute, Entry);
|
2011-04-12 23:21:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct type.
|
|
|
|
DIE *Buffer = getOrCreateTypeDIE(Ty);
|
|
|
|
|
|
|
|
// Set up proxy.
|
|
|
|
Entry = createDIEEntry(Buffer);
|
|
|
|
insertDIEEntry(Ty, Entry);
|
2013-10-31 17:54:35 +00:00
|
|
|
addDIEEntry(Entity, Attribute, Entry);
|
2011-05-31 23:30:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 23:22:52 +00:00
|
|
|
// Accelerator table mutators - add each name along with its companion
|
|
|
|
// DIE to the proper table while ensuring that the name that we're going
|
|
|
|
// to reference is in the string table. We do this since the names we
|
|
|
|
// add may not only be identical to the names in the DIE.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addAccelName(StringRef Name, const DIE *Die) {
|
2014-02-12 22:47:09 +00:00
|
|
|
if (!DD->useDwarfAccelTables())
|
|
|
|
return;
|
2013-09-20 23:22:52 +00:00
|
|
|
DU->getStringPoolEntry(Name);
|
2013-11-19 22:51:04 +00:00
|
|
|
std::vector<const DIE *> &DIEs = AccelNames[Name];
|
2013-09-20 23:22:52 +00:00
|
|
|
DIEs.push_back(Die);
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addAccelObjC(StringRef Name, const DIE *Die) {
|
2014-02-12 22:47:09 +00:00
|
|
|
if (!DD->useDwarfAccelTables())
|
|
|
|
return;
|
2013-09-20 23:22:52 +00:00
|
|
|
DU->getStringPoolEntry(Name);
|
2013-11-19 22:51:04 +00:00
|
|
|
std::vector<const DIE *> &DIEs = AccelObjC[Name];
|
2013-09-20 23:22:52 +00:00
|
|
|
DIEs.push_back(Die);
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addAccelNamespace(StringRef Name, const DIE *Die) {
|
2014-02-12 22:47:09 +00:00
|
|
|
if (!DD->useDwarfAccelTables())
|
|
|
|
return;
|
2013-09-20 23:22:52 +00:00
|
|
|
DU->getStringPoolEntry(Name);
|
2013-11-19 22:51:04 +00:00
|
|
|
std::vector<const DIE *> &DIEs = AccelNamespace[Name];
|
2013-09-20 23:22:52 +00:00
|
|
|
DIEs.push_back(Die);
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addAccelType(StringRef Name,
|
|
|
|
std::pair<const DIE *, unsigned> Die) {
|
2014-02-12 22:47:09 +00:00
|
|
|
if (!DD->useDwarfAccelTables())
|
|
|
|
return;
|
2013-09-20 23:22:52 +00:00
|
|
|
DU->getStringPoolEntry(Name);
|
2013-11-19 22:51:04 +00:00
|
|
|
std::vector<std::pair<const DIE *, unsigned> > &DIEs = AccelTypes[Name];
|
2013-09-20 23:22:52 +00:00
|
|
|
DIEs.push_back(Die);
|
|
|
|
}
|
|
|
|
|
2013-09-20 22:20:55 +00:00
|
|
|
/// addGlobalName - Add a new global name to the compile unit.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::addGlobalName(StringRef Name, DIE *Die, DIScope Context) {
|
2014-03-12 03:34:38 +00:00
|
|
|
if (getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly)
|
|
|
|
return;
|
2013-10-19 01:04:42 +00:00
|
|
|
std::string FullName = getParentContextString(Context) + Name.str();
|
2013-10-17 02:06:06 +00:00
|
|
|
GlobalNames[FullName] = Die;
|
2013-09-20 22:20:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 02:06:06 +00: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-09 23:32:48 +00:00
|
|
|
std::string DwarfUnit::getParentContextString(DIScope Context) const {
|
2013-10-17 02:06:06 +00: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 01:04:42 +00:00
|
|
|
std::string CS;
|
2013-10-17 02:06:06 +00: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();
|
2013-10-19 01:04:42 +00:00
|
|
|
if (!Name.empty()) {
|
2013-10-17 02:06:06 +00:00
|
|
|
CS += Name;
|
|
|
|
CS += "::";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CS;
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructTypeDIE - Construct basic type die from DIBasicType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
|
2011-04-12 23:21:44 +00:00
|
|
|
// Get core information.
|
|
|
|
StringRef Name = BTy.getName();
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, Name);
|
2011-09-14 23:13:28 +00:00
|
|
|
|
2013-10-04 23:21:16 +00:00
|
|
|
// An unspecified type only has a name attribute.
|
|
|
|
if (BTy.getTag() == dwarf::DW_TAG_unspecified_type)
|
2011-09-14 23:13:28 +00:00
|
|
|
return;
|
|
|
|
|
2011-10-26 22:55:33 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2012-02-07 23:33:58 +00:00
|
|
|
BTy.getEncoding());
|
2011-09-14 23:13:28 +00:00
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
uint64_t Size = BTy.getSizeInBits() >> 3;
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructTypeDIE - Construct derived type die from DIDerivedType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
|
2011-04-12 23:21:44 +00:00
|
|
|
// Get core information.
|
|
|
|
StringRef Name = DTy.getName();
|
|
|
|
uint64_t Size = DTy.getSizeInBits() >> 3;
|
2013-10-04 23:21:16 +00:00
|
|
|
uint16_t Tag = Buffer.getTag();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Map to main type, void will not have a type.
|
2013-10-08 18:42:58 +00:00
|
|
|
DIType FromTy = resolve(DTy.getTypeDerivedFrom());
|
2013-08-08 07:40:37 +00:00
|
|
|
if (FromTy)
|
|
|
|
addType(&Buffer, FromTy);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, Name);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
2012-02-21 22:25:53 +00:00
|
|
|
if (Size && Tag != dwarf::DW_TAG_pointer_type)
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-01-07 05:51:15 +00:00
|
|
|
if (Tag == dwarf::DW_TAG_ptr_to_member_type)
|
2013-10-19 01:04:47 +00:00
|
|
|
addDIEEntry(&Buffer, dwarf::DW_AT_containing_type,
|
|
|
|
getOrCreateTypeDIE(resolve(DTy.getClassType())));
|
2011-04-12 23:21:44 +00:00
|
|
|
// Add source line info if available and TyDesc is not a forward declaration.
|
|
|
|
if (!DTy.isForwardDecl())
|
|
|
|
addSourceLine(&Buffer, DTy);
|
|
|
|
}
|
|
|
|
|
2014-02-25 19:57:42 +00:00
|
|
|
/// constructSubprogramArguments - Construct function argument DIEs.
|
|
|
|
void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DIArray Args) {
|
2014-02-25 22:27:14 +00:00
|
|
|
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Ty = Args.getElement(i);
|
|
|
|
if (Ty.isUnspecifiedParameter()) {
|
|
|
|
assert(i == N-1 && "Unspecified parameter must be the last argument");
|
|
|
|
createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
|
|
|
|
} else {
|
|
|
|
DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
|
|
|
|
addType(Arg, DIType(Ty));
|
|
|
|
if (DIType(Ty).isArtificial())
|
|
|
|
addFlag(Arg, dwarf::DW_AT_artificial);
|
2014-02-25 19:57:42 +00:00
|
|
|
}
|
2014-02-25 22:27:14 +00:00
|
|
|
}
|
2014-02-25 19:57:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// constructTypeDIE - Construct type DIE from DICompositeType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2013-11-19 23:08:21 +00:00
|
|
|
// Add name if not anonymous or intermediate type.
|
2011-04-12 23:21:44 +00:00
|
|
|
StringRef Name = CTy.getName();
|
|
|
|
|
|
|
|
uint64_t Size = CTy.getSizeInBits() >> 3;
|
2013-10-04 23:21:16 +00:00
|
|
|
uint16_t Tag = Buffer.getTag();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
switch (Tag) {
|
|
|
|
case dwarf::DW_TAG_array_type:
|
2013-11-11 18:52:31 +00:00
|
|
|
constructArrayTypeDIE(Buffer, CTy);
|
2011-04-12 23:21:44 +00:00
|
|
|
break;
|
2013-11-11 18:52:39 +00:00
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
|
|
|
constructEnumTypeDIE(Buffer, CTy);
|
|
|
|
break;
|
2011-04-12 23:21:44 +00:00
|
|
|
case dwarf::DW_TAG_subroutine_type: {
|
2013-08-08 07:40:37 +00:00
|
|
|
// Add return type. A void return won't have a type.
|
2011-04-12 23:21:44 +00:00
|
|
|
DIArray Elements = CTy.getTypeArray();
|
2013-11-18 23:33:32 +00:00
|
|
|
DIType RTy(Elements.getElement(0));
|
2013-08-08 07:40:37 +00:00
|
|
|
if (RTy)
|
2013-11-18 23:33:32 +00:00
|
|
|
addType(&Buffer, RTy);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
bool isPrototyped = true;
|
2014-02-25 19:57:42 +00:00
|
|
|
if (Elements.getNumElements() == 2 &&
|
|
|
|
Elements.getElement(1).isUnspecifiedParameter())
|
|
|
|
isPrototyped = false;
|
|
|
|
|
|
|
|
constructSubprogramArguments(Buffer, Elements);
|
|
|
|
|
2012-02-22 08:46:21 +00:00
|
|
|
// Add prototype flag if we're dealing with a C language and the
|
|
|
|
// function has been prototyped.
|
2013-11-15 23:50:53 +00:00
|
|
|
uint16_t Language = getLanguage();
|
2012-02-22 08:46:21 +00:00
|
|
|
if (isPrototyped &&
|
2013-10-19 01:04:47 +00:00
|
|
|
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
|
2012-05-22 18:45:24 +00:00
|
|
|
Language == dwarf::DW_LANG_ObjC))
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(&Buffer, dwarf::DW_AT_prototyped);
|
2013-12-18 21:48:19 +00:00
|
|
|
|
|
|
|
if (CTy.isLValueReference())
|
|
|
|
addFlag(&Buffer, dwarf::DW_AT_reference);
|
|
|
|
|
|
|
|
if (CTy.isRValueReference())
|
|
|
|
addFlag(&Buffer, dwarf::DW_AT_rvalue_reference);
|
2013-10-19 01:04:47 +00:00
|
|
|
} break;
|
2011-04-12 23:21:44 +00:00
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_class_type: {
|
|
|
|
// Add elements to structure type.
|
2013-08-01 20:30:22 +00:00
|
|
|
DIArray Elements = CTy.getTypeArray();
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
2011-04-12 23:21:44 +00:00
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
DIE *ElemDie = NULL;
|
2014-01-18 02:12:00 +00:00
|
|
|
if (Element.isSubprogram())
|
|
|
|
ElemDie = getOrCreateSubprogramDIE(DISubprogram(Element));
|
|
|
|
else if (Element.isDerivedType()) {
|
2012-05-22 18:45:24 +00:00
|
|
|
DIDerivedType DDTy(Element);
|
|
|
|
if (DDTy.getTag() == dwarf::DW_TAG_friend) {
|
2013-10-29 00:53:03 +00:00
|
|
|
ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
|
2013-10-08 18:42:58 +00:00
|
|
|
addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()),
|
2013-10-05 01:43:03 +00:00
|
|
|
dwarf::DW_AT_friend);
|
2013-10-14 20:33:57 +00:00
|
|
|
} else if (DDTy.isStaticMember()) {
|
2013-10-23 22:57:12 +00:00
|
|
|
getOrCreateStaticMemberDIE(DDTy);
|
2013-10-14 20:33:57 +00:00
|
|
|
} else {
|
2013-10-23 23:00:44 +00:00
|
|
|
constructMemberDIE(Buffer, DDTy);
|
2013-10-14 20:33:57 +00:00
|
|
|
}
|
2012-03-28 07:34:31 +00:00
|
|
|
} else if (Element.isObjCProperty()) {
|
2012-02-07 23:33:58 +00:00
|
|
|
DIObjCProperty Property(Element);
|
2013-10-29 00:53:03 +00:00
|
|
|
ElemDie = createAndAddDIE(Property.getTag(), Buffer);
|
2012-02-07 23:33:58 +00:00
|
|
|
StringRef PropertyName = Property.getObjCPropertyName();
|
|
|
|
addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
|
2014-01-23 19:16:28 +00:00
|
|
|
if (Property.getType())
|
|
|
|
addType(ElemDie, Property.getType());
|
2012-05-22 18:45:24 +00:00
|
|
|
addSourceLine(ElemDie, Property);
|
2012-02-07 23:33:58 +00: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 01:30:32 +00: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-21 17:28:37 +00:00
|
|
|
addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, None,
|
2013-10-19 01:04:47 +00:00
|
|
|
PropertyAttributes);
|
2012-02-06 17:49:43 +00:00
|
|
|
|
2012-02-07 23:33:58 +00:00
|
|
|
DIEEntry *Entry = getDIEEntry(Element);
|
|
|
|
if (!Entry) {
|
|
|
|
Entry = createDIEEntry(ElemDie);
|
|
|
|
insertDIEEntry(Element, Entry);
|
|
|
|
}
|
2012-02-04 01:30:32 +00:00
|
|
|
} else
|
2011-04-12 23:21:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CTy.isAppleBlockExtension())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(&Buffer, dwarf::DW_AT_APPLE_block);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-10-05 00:27:02 +00:00
|
|
|
DICompositeType ContainingType(resolve(CTy.getContainingType()));
|
2013-11-18 23:33:32 +00:00
|
|
|
if (ContainingType)
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(&Buffer, dwarf::DW_AT_containing_type,
|
2013-11-18 23:33:32 +00:00
|
|
|
getOrCreateTypeDIE(ContainingType));
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2011-05-12 21:29:42 +00:00
|
|
|
if (CTy.isObjcClassComplete())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(&Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
|
2011-05-12 19:06:16 +00:00
|
|
|
|
2011-12-16 23:42:42 +00: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 01:04:47 +00:00
|
|
|
Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
|
2011-04-12 23:21:44 +00:00
|
|
|
addTemplateParams(Buffer, CTy.getTemplateParams());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
|
|
|
if (!Name.empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, Name);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2012-05-22 18:45:18 +00:00
|
|
|
if (Tag == dwarf::DW_TAG_enumeration_type ||
|
2013-10-19 01:04:47 +00:00
|
|
|
Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
|
2012-05-22 18:45:18 +00:00
|
|
|
Tag == dwarf::DW_TAG_union_type) {
|
2011-04-12 23:21:44 +00:00
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
2012-06-01 00:22:32 +00:00
|
|
|
// TODO: Do we care about size for enum forward declarations?
|
2011-04-12 23:21:44 +00:00
|
|
|
if (Size)
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
|
2012-06-01 00:22:32 +00:00
|
|
|
else if (!CTy.isForwardDecl())
|
2011-04-12 23:21:44 +00:00
|
|
|
// Add zero size if it is not a forward declaration.
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, 0);
|
2012-06-01 00:22:32 +00:00
|
|
|
|
|
|
|
// If we're a forward decl, say so.
|
|
|
|
if (CTy.isForwardDecl())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(&Buffer, dwarf::DW_AT_declaration);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Add source line info if available.
|
|
|
|
if (!CTy.isForwardDecl())
|
|
|
|
addSourceLine(&Buffer, CTy);
|
2012-03-07 00:15:19 +00:00
|
|
|
|
|
|
|
// No harm in adding the runtime language to the declaration.
|
|
|
|
unsigned RLang = CTy.getRunTimeLang();
|
|
|
|
if (RLang)
|
2013-10-19 01:04:47 +00:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
|
|
|
|
RLang);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 23:05:28 +00:00
|
|
|
/// constructTemplateTypeParameterDIE - Construct new DIE for the given
|
|
|
|
/// DITemplateTypeParameter.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer,
|
|
|
|
DITemplateTypeParameter TP) {
|
2013-10-29 00:53:03 +00:00
|
|
|
DIE *ParamDIE =
|
|
|
|
createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
|
2013-08-08 08:09:43 +00:00
|
|
|
// Add the type if it exists, it could be void and therefore no type.
|
|
|
|
if (TP.getType())
|
2013-10-09 19:46:28 +00:00
|
|
|
addType(ParamDIE, resolve(TP.getType()));
|
2013-06-22 18:59:11 +00:00
|
|
|
if (!TP.getName().empty())
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_name, TP.getName());
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 23:05:28 +00:00
|
|
|
/// constructTemplateValueParameterDIE - Construct new DIE for the given
|
|
|
|
/// DITemplateValueParameter.
|
2013-12-09 23:32:48 +00:00
|
|
|
void
|
|
|
|
DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer,
|
2013-12-02 19:33:10 +00:00
|
|
|
DITemplateValueParameter VP) {
|
2013-10-29 00:53:03 +00:00
|
|
|
DIE *ParamDIE = createAndAddDIE(VP.getTag(), Buffer);
|
2013-08-08 07:40:37 +00:00
|
|
|
|
|
|
|
// Add the type if there is one, template template and template parameter
|
|
|
|
// packs will not have a type.
|
2013-10-21 17:48:51 +00:00
|
|
|
if (VP.getTag() == dwarf::DW_TAG_template_value_parameter)
|
2013-10-09 19:46:28 +00:00
|
|
|
addType(ParamDIE, resolve(VP.getType()));
|
2013-08-08 07:40:31 +00:00
|
|
|
if (!VP.getName().empty())
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_name, VP.getName());
|
|
|
|
if (Value *Val = VP.getValue()) {
|
2013-05-10 21:52:07 +00:00
|
|
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val))
|
2013-10-09 19:46:28 +00:00
|
|
|
addConstantValue(ParamDIE, CI,
|
|
|
|
isUnsignedDIType(DD, resolve(VP.getType())));
|
2013-05-10 21:52:07 +00:00
|
|
|
else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) {
|
|
|
|
// For declaration non-type template parameters (such as global values and
|
|
|
|
// functions)
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
|
|
|
addOpAddress(Loc, Asm->getSymbol(GV));
|
2013-05-10 21:52:07 +00:00
|
|
|
// Emit DW_OP_stack_value to use the address as the immediate value of the
|
|
|
|
// parameter, rather than a pointer to it.
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
|
|
|
|
addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
|
2013-08-08 07:40:31 +00:00
|
|
|
} else if (VP.getTag() == dwarf::DW_TAG_GNU_template_template_param) {
|
2013-06-22 18:59:11 +00:00
|
|
|
assert(isa<MDString>(Val));
|
|
|
|
addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
|
|
|
|
cast<MDString>(Val)->getString());
|
2013-08-08 07:40:31 +00:00
|
|
|
} else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
|
2013-06-22 18:59:11 +00:00
|
|
|
assert(isa<MDNode>(Val));
|
|
|
|
DIArray A(cast<MDNode>(Val));
|
|
|
|
addTemplateParams(*ParamDIE, A);
|
2013-05-10 21:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-05-06 16:57:54 +00:00
|
|
|
/// getOrCreateNameSpace - Create a DIE for DINameSpace.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) {
|
2013-10-29 05:49:41 +00:00
|
|
|
// Construct the context before querying for the existence of the DIE in case
|
|
|
|
// such construction creates the DIE.
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(NS.getContext());
|
|
|
|
|
2011-05-06 16:57:54 +00:00
|
|
|
DIE *NDie = getDIE(NS);
|
|
|
|
if (NDie)
|
|
|
|
return NDie;
|
2013-10-29 05:49:41 +00:00
|
|
|
NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
|
|
|
|
|
2011-11-07 09:24:32 +00:00
|
|
|
if (!NS.getName().empty()) {
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(NDie, dwarf::DW_AT_name, NS.getName());
|
2011-11-07 09:24:32 +00:00
|
|
|
addAccelNamespace(NS.getName(), NDie);
|
2013-10-17 02:06:06 +00:00
|
|
|
addGlobalName(NS.getName(), NDie, NS.getContext());
|
2011-11-07 09:24:32 +00:00
|
|
|
} else
|
|
|
|
addAccelNamespace("(anonymous namespace)", NDie);
|
2011-05-06 16:57:54 +00:00
|
|
|
addSourceLine(NDie, NS);
|
|
|
|
return NDie;
|
|
|
|
}
|
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
/// getOrCreateSubprogramDIE - Create new DIE using SP.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) {
|
2013-10-04 01:39:59 +00: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-03-14 23:08:25 +00:00
|
|
|
DIScope Context = resolve(SP.getContext());
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(Context);
|
2014-03-18 17:41:15 +00:00
|
|
|
|
2014-03-14 23:08:25 +00:00
|
|
|
// Unique declarations based on the ODR, where applicable.
|
2014-03-18 17:41:15 +00:00
|
|
|
SP = DISubprogram(DD->resolve(SP.getRef()));
|
|
|
|
assert(SP.Verify());
|
2013-10-04 01:39:59 +00:00
|
|
|
|
2013-10-04 17:08:38 +00:00
|
|
|
DIE *SPDie = getDIE(SP);
|
2011-08-15 17:24:54 +00:00
|
|
|
if (SPDie)
|
|
|
|
return SPDie;
|
|
|
|
|
2013-10-29 00:58:04 +00:00
|
|
|
DISubprogram SPDecl = SP.getFunctionDeclaration();
|
|
|
|
if (SPDecl.isSubprogram())
|
|
|
|
// Add subprogram definitions to the CU die directly.
|
2013-12-02 22:09:48 +00:00
|
|
|
ContextDIE = UnitDie.get();
|
2012-05-27 18:36:44 +00:00
|
|
|
|
|
|
|
// DW_TAG_inlined_subroutine may refer to this DIE.
|
2013-10-29 00:58:04 +00:00
|
|
|
SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
|
2012-05-27 18:36:44 +00:00
|
|
|
|
2011-11-10 22:34:29 +00:00
|
|
|
DIE *DeclDie = NULL;
|
2013-10-23 22:12:26 +00:00
|
|
|
if (SPDecl.isSubprogram())
|
2011-11-10 22:34:29 +00:00
|
|
|
DeclDie = getOrCreateSubprogramDIE(SPDecl);
|
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
// Add function template parameters.
|
|
|
|
addTemplateParams(*SPDie, SP.getTemplateParams());
|
|
|
|
|
2014-04-12 04:25:02 +00:00
|
|
|
// If this DIE is going to refer declaration info using AT_specification
|
|
|
|
// then there is no need to add other attributes.
|
|
|
|
if (DeclDie) {
|
2011-11-10 22:34:29 +00:00
|
|
|
// Refer function declaration directly.
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_specification, DeclDie);
|
2011-11-10 22:34:29 +00:00
|
|
|
|
2014-04-12 04:25:02 +00:00
|
|
|
return SPDie;
|
2011-11-10 22:34:29 +00:00
|
|
|
}
|
2011-08-15 17:24:54 +00:00
|
|
|
|
2014-04-12 04:25:02 +00:00
|
|
|
// Add the linkage name if we have one.
|
|
|
|
StringRef LinkageName = SP.getLinkageName();
|
|
|
|
if (!LinkageName.empty())
|
|
|
|
addString(SPDie, dwarf::DW_AT_MIPS_linkage_name,
|
|
|
|
GlobalValue::getRealLinkageName(LinkageName));
|
2012-08-23 22:52:55 +00:00
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
// Constructors and operators for anonymous aggregates do not have names.
|
|
|
|
if (!SP.getName().empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(SPDie, dwarf::DW_AT_name, SP.getName());
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
addSourceLine(SPDie, SP);
|
|
|
|
|
2012-02-22 08:46:21 +00:00
|
|
|
// Add the prototype if we have a prototype and we have a C like
|
|
|
|
// language.
|
2013-11-15 23:50:53 +00:00
|
|
|
uint16_t Language = getLanguage();
|
2012-02-22 08:46:21 +00:00
|
|
|
if (SP.isPrototyped() &&
|
2013-10-19 01:04:47 +00:00
|
|
|
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
|
2012-02-22 08:46:21 +00:00
|
|
|
Language == dwarf::DW_LANG_ObjC))
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_prototyped);
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
DICompositeType SPTy = SP.getType();
|
2013-05-22 23:22:18 +00:00
|
|
|
assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type &&
|
|
|
|
"the type of a subprogram should be a subroutine");
|
2011-08-15 17:24:54 +00:00
|
|
|
|
2013-05-22 23:22:18 +00:00
|
|
|
DIArray Args = SPTy.getTypeArray();
|
2013-10-21 17:48:51 +00:00
|
|
|
// Add a return type. If this is a type like a C/C++ void type we don't add a
|
|
|
|
// return type.
|
2013-08-08 07:40:37 +00:00
|
|
|
if (Args.getElement(0))
|
|
|
|
addType(SPDie, DIType(Args.getElement(0)));
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
unsigned VK = SP.getVirtuality();
|
|
|
|
if (VK) {
|
2011-12-14 00:56:07 +00:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Block = getDIELoc();
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(Block, dwarf::DW_FORM_udata, SP.getVirtualIndex());
|
|
|
|
addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
|
2013-11-11 18:52:36 +00:00
|
|
|
ContainingTypeMap.insert(
|
|
|
|
std::make_pair(SPDie, resolve(SP.getContainingType())));
|
2011-08-15 17:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!SP.isDefinition()) {
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_declaration);
|
2012-11-21 00:34:38 +00:00
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
// Add arguments. Do not add arguments for subprogram definition. They will
|
|
|
|
// be handled while processing variables.
|
2014-02-25 19:57:42 +00:00
|
|
|
constructSubprogramArguments(*SPDie, Args);
|
2011-08-15 17:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SP.isArtificial())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_artificial);
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
if (!SP.isLocalToUnit())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_external);
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
if (SP.isOptimized())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
|
2011-08-15 17:24:54 +00:00
|
|
|
|
|
|
|
if (unsigned isa = Asm->getISAEncoding()) {
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
|
|
|
|
}
|
|
|
|
|
2013-12-18 21:48:19 +00:00
|
|
|
if (SP.isLValueReference())
|
|
|
|
addFlag(SPDie, dwarf::DW_AT_reference);
|
|
|
|
|
|
|
|
if (SP.isRValueReference())
|
|
|
|
addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
|
|
|
|
|
2014-01-18 02:12:00 +00: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);
|
|
|
|
else
|
|
|
|
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-15 17:24:54 +00:00
|
|
|
return SPDie;
|
|
|
|
}
|
|
|
|
|
2011-08-15 17:57:41 +00:00
|
|
|
// Return const expression if value is a GEP to access merged global
|
|
|
|
// constant. e.g.
|
|
|
|
// i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0)
|
|
|
|
static const ConstantExpr *getMergedGlobalExpr(const Value *V) {
|
|
|
|
const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V);
|
|
|
|
if (!CE || CE->getNumOperands() != 3 ||
|
|
|
|
CE->getOpcode() != Instruction::GetElementPtr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// First operand points to a global struct.
|
|
|
|
Value *Ptr = CE->getOperand(0);
|
|
|
|
if (!isa<GlobalValue>(Ptr) ||
|
|
|
|
!isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType()))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Second operand is zero.
|
|
|
|
const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1));
|
|
|
|
if (!CI || !CI->isZero())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Third operand is offset.
|
|
|
|
if (!isa<ConstantInt>(CE->getOperand(2)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return CE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// createGlobalVariableDIE - create global variable DIE.
|
2013-12-09 23:57:44 +00:00
|
|
|
void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) {
|
2011-08-15 17:57:41 +00:00
|
|
|
// Check for pre-existence.
|
2013-11-15 23:09:13 +00:00
|
|
|
if (getDIE(GV))
|
2011-08-15 17:57:41 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-04 01:23:52 +00:00
|
|
|
assert(GV.isGlobalVariable());
|
2011-08-18 23:17:55 +00:00
|
|
|
|
2013-10-04 23:49:26 +00:00
|
|
|
DIScope GVContext = GV.getContext();
|
2014-03-18 02:34:58 +00:00
|
|
|
DIType GTy = DD->resolve(GV.getType());
|
2011-08-15 17:57:41 +00:00
|
|
|
|
2013-01-16 01:22:23 +00:00
|
|
|
// If this is a static data member definition, some attributes belong
|
|
|
|
// to the declaration DIE.
|
|
|
|
DIE *VariableDIE = NULL;
|
2013-02-01 23:54:37 +00:00
|
|
|
bool IsStaticMember = false;
|
2013-01-16 01:22:23 +00:00
|
|
|
DIDerivedType SDMDecl = GV.getStaticDataMemberDeclaration();
|
|
|
|
if (SDMDecl.Verify()) {
|
|
|
|
assert(SDMDecl.isStaticMember() && "Expected static member decl");
|
|
|
|
// We need the declaration DIE that is in the static member's class.
|
2013-10-14 20:33:57 +00:00
|
|
|
VariableDIE = getOrCreateStaticMemberDIE(SDMDecl);
|
2013-02-01 23:54:37 +00:00
|
|
|
IsStaticMember = true;
|
2013-01-16 01:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this is not a static data member definition, create the variable
|
|
|
|
// DIE and add the initial set of attributes to it.
|
|
|
|
if (!VariableDIE) {
|
2013-10-29 05:49:41 +00:00
|
|
|
// Construct the context before querying for the existence of the DIE in
|
|
|
|
// case such construction creates the DIE.
|
|
|
|
DIE *ContextDIE = getOrCreateContextDIE(GVContext);
|
|
|
|
|
2013-01-16 01:22:23 +00:00
|
|
|
// Add to map.
|
2013-11-16 00:29:01 +00:00
|
|
|
VariableDIE = createAndAddDIE(GV.getTag(), *ContextDIE, GV);
|
2013-01-16 01:22:23 +00:00
|
|
|
|
|
|
|
// Add name and type.
|
|
|
|
addString(VariableDIE, dwarf::DW_AT_name, GV.getDisplayName());
|
|
|
|
addType(VariableDIE, GTy);
|
|
|
|
|
|
|
|
// Add scoping info.
|
2013-10-16 01:37:49 +00:00
|
|
|
if (!GV.isLocalToUnit())
|
2013-01-16 01:22:23 +00:00
|
|
|
addFlag(VariableDIE, dwarf::DW_AT_external);
|
|
|
|
|
|
|
|
// Add line number info.
|
|
|
|
addSourceLine(VariableDIE, GV);
|
|
|
|
}
|
2011-11-09 05:24:07 +00:00
|
|
|
|
2011-08-15 17:57:41 +00:00
|
|
|
// Add location.
|
2011-11-07 09:24:32 +00:00
|
|
|
bool addToAccelTable = false;
|
2011-11-11 03:16:32 +00:00
|
|
|
DIE *VariableSpecDIE = NULL;
|
2013-01-16 01:22:23 +00:00
|
|
|
bool isGlobalVariable = GV.getGlobal() != NULL;
|
2011-08-15 17:57:41 +00:00
|
|
|
if (isGlobalVariable) {
|
2011-11-07 09:24:32 +00:00
|
|
|
addToAccelTable = true;
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2013-10-29 17:07:16 +00:00
|
|
|
const MCSymbol *Sym = Asm->getSymbol(GV.getGlobal());
|
2013-06-28 20:05:11 +00:00
|
|
|
if (GV.getGlobal()->isThreadLocal()) {
|
|
|
|
// FIXME: Make this work with -gsplit-dwarf.
|
|
|
|
unsigned PointerSize = Asm->getDataLayout().getPointerSize();
|
|
|
|
assert((PointerSize == 4 || PointerSize == 8) &&
|
|
|
|
"Add support for other sizes if necessary");
|
|
|
|
// Based on GCC's support for TLS:
|
2013-07-01 23:55:52 +00:00
|
|
|
if (!DD->useSplitDwarf()) {
|
|
|
|
// 1) Start with a constNu of the appropriate pointer size
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1,
|
2013-07-01 23:55:52 +00:00
|
|
|
PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u);
|
2013-10-07 18:39:18 +00:00
|
|
|
// 2) containing the (relocated) offset of the TLS variable
|
|
|
|
// within the module's TLS block.
|
2014-02-16 08:46:55 +00:00
|
|
|
addExpr(Loc, dwarf::DW_FORM_udata,
|
2014-02-15 19:34:03 +00:00
|
|
|
Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
|
2013-07-01 23:55:52 +00:00
|
|
|
} else {
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
|
|
|
|
addUInt(Loc, dwarf::DW_FORM_udata,
|
2014-02-15 19:34:03 +00:00
|
|
|
DU->getAddrPoolIndex(Sym, /* TLS */ true));
|
2013-07-01 23:55:52 +00:00
|
|
|
}
|
2013-10-07 18:39:18 +00:00
|
|
|
// 3) followed by a custom OP to make the debugger do a TLS lookup.
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_push_tls_address);
|
2013-11-27 23:53:52 +00:00
|
|
|
} else {
|
|
|
|
DD->addArangeLabel(SymbolCU(this, Sym));
|
2014-02-16 08:46:55 +00:00
|
|
|
addOpAddress(Loc, Sym);
|
2013-11-27 23:53:52 +00:00
|
|
|
}
|
2011-08-15 17:57:41 +00:00
|
|
|
// Do not create specification DIE if context is either compile unit
|
|
|
|
// or a subprogram.
|
2011-09-21 23:41:11 +00:00
|
|
|
if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() &&
|
2013-09-09 19:05:21 +00:00
|
|
|
!GVContext.isFile() && !DD->isSubprogramContext(GVContext)) {
|
2011-08-15 17:57:41 +00:00
|
|
|
// Create specification DIE.
|
2013-12-02 22:09:48 +00:00
|
|
|
VariableSpecDIE = createAndAddDIE(dwarf::DW_TAG_variable, *UnitDie);
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, VariableDIE);
|
2014-02-16 08:46:55 +00:00
|
|
|
addBlock(VariableSpecDIE, dwarf::DW_AT_location, Loc);
|
2013-01-16 01:22:23 +00:00
|
|
|
// A static member's declaration is already flagged as such.
|
|
|
|
if (!SDMDecl.Verify())
|
|
|
|
addFlag(VariableDIE, dwarf::DW_AT_declaration);
|
2011-08-15 17:57:41 +00:00
|
|
|
} else {
|
2014-02-16 08:46:55 +00:00
|
|
|
addBlock(VariableDIE, dwarf::DW_AT_location, Loc);
|
2011-11-07 09:24:32 +00:00
|
|
|
}
|
2013-09-04 04:39:38 +00:00
|
|
|
// Add the linkage name.
|
2013-01-16 01:22:23 +00:00
|
|
|
StringRef LinkageName = GV.getLinkageName();
|
2013-09-04 04:39:38 +00:00
|
|
|
if (!LinkageName.empty())
|
2013-02-27 23:49:47 +00:00
|
|
|
// From DWARF4: DIEs to which DW_AT_linkage_name may apply include:
|
|
|
|
// TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and
|
|
|
|
// TAG_variable.
|
2013-10-19 01:04:47 +00:00
|
|
|
addString(IsStaticMember && VariableSpecDIE ? VariableSpecDIE
|
|
|
|
: VariableDIE,
|
2014-03-13 23:26:25 +00:00
|
|
|
DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
|
|
|
|
: dwarf::DW_AT_MIPS_linkage_name,
|
2013-06-01 17:51:14 +00:00
|
|
|
GlobalValue::getRealLinkageName(LinkageName));
|
2012-11-21 00:34:38 +00:00
|
|
|
} else if (const ConstantInt *CI =
|
2013-10-19 01:04:47 +00:00
|
|
|
dyn_cast_or_null<ConstantInt>(GV.getConstant())) {
|
2013-04-04 22:56:49 +00:00
|
|
|
// AT_const_value was added when the static member was created. To avoid
|
2013-02-01 23:54:37 +00:00
|
|
|
// emitting AT_const_value multiple times, we only add AT_const_value when
|
|
|
|
// it is not a static member.
|
|
|
|
if (!IsStaticMember)
|
2013-10-05 01:43:03 +00:00
|
|
|
addConstantValue(VariableDIE, CI, isUnsignedDIType(DD, GTy));
|
2013-11-17 21:55:13 +00:00
|
|
|
} else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getOperand(11))) {
|
2011-11-07 09:24:32 +00:00
|
|
|
addToAccelTable = true;
|
2011-08-15 17:57:41 +00:00
|
|
|
// GV is a merged global.
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
|
2011-08-15 17:57:41 +00:00
|
|
|
Value *Ptr = CE->getOperand(0);
|
2013-11-27 23:53:52 +00:00
|
|
|
MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr));
|
|
|
|
DD->addArangeLabel(SymbolCU(this, Sym));
|
2014-02-16 08:46:55 +00:00
|
|
|
addOpAddress(Loc, Sym);
|
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
2013-10-19 01:04:47 +00:00
|
|
|
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_udata,
|
2013-10-19 01:04:47 +00:00
|
|
|
Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx));
|
2014-02-16 08:46:55 +00:00
|
|
|
addUInt(Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
|
|
|
addBlock(VariableDIE, dwarf::DW_AT_location, Loc);
|
2011-08-15 17:57:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 01:55:22 +00:00
|
|
|
if (addToAccelTable) {
|
|
|
|
DIE *AddrDIE = VariableSpecDIE ? VariableSpecDIE : VariableDIE;
|
|
|
|
addAccelName(GV.getName(), AddrDIE);
|
2011-11-07 09:24:32 +00:00
|
|
|
|
2011-11-11 01:55:22 +00:00
|
|
|
// If the linkage name is different than the name, go ahead and output
|
|
|
|
// that as well into the name table.
|
|
|
|
if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName())
|
|
|
|
addAccelName(GV.getLinkageName(), AddrDIE);
|
|
|
|
}
|
2013-10-16 01:37:49 +00:00
|
|
|
|
|
|
|
if (!GV.isLocalToUnit())
|
2013-10-17 02:06:06 +00:00
|
|
|
addGlobalName(GV.getName(), VariableSpecDIE ? VariableSpecDIE : VariableDIE,
|
|
|
|
GV.getContext());
|
2011-08-15 17:57:41 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:21:44 +00:00
|
|
|
/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
|
2013-10-29 00:53:03 +00:00
|
|
|
DIE *DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, IndexTy);
|
2012-12-04 21:34:03 +00:00
|
|
|
|
2012-12-06 07:38:10 +00: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
|
|
|
|
// DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and
|
|
|
|
// Count == 0, then the array has zero elements in which case we do not emit
|
|
|
|
// an upper bound.
|
|
|
|
int64_t LowerBound = SR.getLo();
|
2012-12-06 07:55:19 +00:00
|
|
|
int64_t DefaultLowerBound = getDefaultLowerBound();
|
2012-12-04 06:20:49 +00:00
|
|
|
int64_t Count = SR.getCount();
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2012-12-06 07:55:19 +00:00
|
|
|
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
|
2013-10-21 17:28:37 +00:00
|
|
|
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
|
2012-12-06 07:38:10 +00:00
|
|
|
|
|
|
|
if (Count != -1 && Count != 0)
|
2012-12-04 21:34:03 +00:00
|
|
|
// FIXME: An unbounded array should reference the expression that defines
|
|
|
|
// the array.
|
2013-11-11 18:52:36 +00:00
|
|
|
addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, None,
|
|
|
|
LowerBound + Count - 1);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2013-11-11 18:52:31 +00:00
|
|
|
if (CTy.isVector())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(&Buffer, dwarf::DW_AT_GNU_vector);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-08-08 07:40:37 +00:00
|
|
|
// Emit the element type.
|
2013-11-11 18:52:31 +00:00
|
|
|
addType(&Buffer, resolve(CTy.getTypeDerivedFrom()));
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
// Get an anonymous type for index type.
|
2013-01-04 21:51:53 +00:00
|
|
|
// FIXME: This type should be passed down from the front end
|
|
|
|
// as different languages may have different sizes for indexes.
|
2011-04-12 23:21:44 +00:00
|
|
|
DIE *IdxTy = getIndexTyDie();
|
|
|
|
if (!IdxTy) {
|
2014-04-03 06:28:20 +00:00
|
|
|
// Construct an integer type to use for indexes.
|
2013-12-02 22:09:48 +00:00
|
|
|
IdxTy = createAndAddDIE(dwarf::DW_TAG_base_type, *UnitDie);
|
2014-04-03 06:28:20 +00:00
|
|
|
addString(IdxTy, dwarf::DW_AT_name, "sizetype");
|
|
|
|
addUInt(IdxTy, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
|
2011-04-12 23:21:44 +00:00
|
|
|
addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2014-04-03 06:28:20 +00:00
|
|
|
dwarf::DW_ATE_unsigned);
|
2011-04-12 23:21:44 +00:00
|
|
|
setIndexTyDie(IdxTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add subranges to array type.
|
2013-11-11 18:52:31 +00:00
|
|
|
DIArray Elements = CTy.getTypeArray();
|
2011-04-12 23:21:44 +00: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-11 18:52:39 +00:00
|
|
|
/// constructEnumTypeDIE - Construct an enum type DIE from DICompositeType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2013-11-11 18:52:39 +00:00
|
|
|
DIArray Elements = CTy.getTypeArray();
|
|
|
|
|
|
|
|
// Add enumerators to enumeration type.
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
2013-11-18 23:33:32 +00:00
|
|
|
DIEnumerator Enum(Elements.getElement(i));
|
2013-11-11 18:52:39 +00:00
|
|
|
if (Enum.isEnumerator()) {
|
|
|
|
DIE *Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
|
2013-11-18 23:33:32 +00:00
|
|
|
StringRef Name = Enum.getName();
|
2013-11-11 18:52:39 +00:00
|
|
|
addString(Enumerator, dwarf::DW_AT_name, Name);
|
2013-11-18 23:33:32 +00:00
|
|
|
int64_t Value = Enum.getEnumValue();
|
2013-11-19 09:28:34 +00:00
|
|
|
addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
|
|
|
Value);
|
2013-11-11 18:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DIType DTy = resolve(CTy.getTypeDerivedFrom());
|
|
|
|
if (DTy) {
|
|
|
|
addType(&Buffer, DTy);
|
|
|
|
addFlag(&Buffer, dwarf::DW_AT_enum_class);
|
|
|
|
}
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-15 17:24:54 +00:00
|
|
|
/// constructContainingTypeDIEs - Construct DIEs for types that contain
|
|
|
|
/// vtables.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructContainingTypeDIEs() {
|
2011-08-15 17:24:54 +00:00
|
|
|
for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(),
|
2013-10-19 01:04:47 +00:00
|
|
|
CE = ContainingTypeMap.end();
|
|
|
|
CI != CE; ++CI) {
|
2011-08-15 17:24:54 +00:00
|
|
|
DIE *SPDie = CI->first;
|
2013-11-15 23:09:13 +00:00
|
|
|
DIDescriptor D(CI->second);
|
|
|
|
if (!D)
|
2013-10-19 01:04:47 +00:00
|
|
|
continue;
|
2013-11-15 23:09:13 +00:00
|
|
|
DIE *NDie = getDIE(D);
|
2013-10-19 01:04:47 +00:00
|
|
|
if (!NDie)
|
|
|
|
continue;
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_containing_type, NDie);
|
2011-08-15 17:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-15 22:04:40 +00:00
|
|
|
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
|
2013-11-15 01:43:19 +00:00
|
|
|
StringRef Name = DV.getName();
|
2011-08-15 22:04:40 +00:00
|
|
|
|
|
|
|
// Define variable debug information entry.
|
2013-11-15 01:43:19 +00:00
|
|
|
DIE *VariableDie = new DIE(DV.getTag());
|
|
|
|
DbgVariable *AbsVar = DV.getAbstractVariable();
|
2011-08-15 22:04:40 +00:00
|
|
|
DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : NULL;
|
2013-05-29 17:16:59 +00:00
|
|
|
if (AbsDIE)
|
2013-10-11 23:58:05 +00:00
|
|
|
addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, AbsDIE);
|
2011-08-15 22:04:40 +00:00
|
|
|
else {
|
2013-08-19 03:34:03 +00:00
|
|
|
if (!Name.empty())
|
|
|
|
addString(VariableDie, dwarf::DW_AT_name, Name);
|
2013-11-15 01:43:19 +00:00
|
|
|
addSourceLine(VariableDie, DV.getVariable());
|
|
|
|
addType(VariableDie, DV.getType());
|
2011-08-15 22:04:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 01:43:19 +00:00
|
|
|
if (DV.isArtificial())
|
2012-08-24 01:14:27 +00:00
|
|
|
addFlag(VariableDie, dwarf::DW_AT_artificial);
|
2011-08-15 22:04:40 +00:00
|
|
|
|
|
|
|
if (isScopeAbstract) {
|
2013-11-15 01:43:19 +00:00
|
|
|
DV.setDIE(VariableDie);
|
2011-08-15 22:04:40 +00:00
|
|
|
return VariableDie;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add variable address.
|
|
|
|
|
2013-11-15 01:43:19 +00:00
|
|
|
unsigned Offset = DV.getDotDebugLocOffset();
|
2011-08-15 22:04:40 +00:00
|
|
|
if (Offset != ~0U) {
|
2014-03-05 22:41:20 +00:00
|
|
|
addLocationList(VariableDie, dwarf::DW_AT_location, Offset);
|
2013-11-15 01:43:19 +00:00
|
|
|
DV.setDIE(VariableDie);
|
2011-08-15 22:04:40 +00:00
|
|
|
return VariableDie;
|
|
|
|
}
|
|
|
|
|
2011-10-03 15:49:20 +00:00
|
|
|
// Check if variable is described by a DBG_VALUE instruction.
|
2013-11-15 01:43:19 +00:00
|
|
|
if (const MachineInstr *DVInsn = DV.getMInsn()) {
|
2013-06-16 20:34:15 +00:00
|
|
|
assert(DVInsn->getNumOperands() == 3);
|
|
|
|
if (DVInsn->getOperand(0).isReg()) {
|
|
|
|
const MachineOperand RegOp = DVInsn->getOperand(0);
|
2013-07-09 21:44:06 +00:00
|
|
|
// If the second operand is an immediate, this is an indirect value.
|
2013-07-09 20:28:37 +00:00
|
|
|
if (DVInsn->getOperand(1).isImm()) {
|
2013-10-19 01:04:47 +00:00
|
|
|
MachineLocation Location(RegOp.getReg(),
|
|
|
|
DVInsn->getOperand(1).getImm());
|
2013-11-15 01:43:19 +00:00
|
|
|
addVariableAddress(DV, VariableDie, Location);
|
2013-06-16 20:34:15 +00:00
|
|
|
} else if (RegOp.getReg())
|
2013-11-15 01:43:19 +00:00
|
|
|
addVariableAddress(DV, VariableDie, MachineLocation(RegOp.getReg()));
|
2013-06-16 20:34:15 +00:00
|
|
|
} else if (DVInsn->getOperand(0).isImm())
|
2013-11-15 01:43:19 +00:00
|
|
|
addConstantValue(VariableDie, DVInsn->getOperand(0), DV.getType());
|
2013-06-16 20:34:15 +00:00
|
|
|
else if (DVInsn->getOperand(0).isFPImm())
|
2013-07-03 01:08:30 +00:00
|
|
|
addConstantFPValue(VariableDie, DVInsn->getOperand(0));
|
2013-06-16 20:34:15 +00:00
|
|
|
else if (DVInsn->getOperand(0).isCImm())
|
2013-07-03 01:08:30 +00:00
|
|
|
addConstantValue(VariableDie, DVInsn->getOperand(0).getCImm(),
|
2013-11-15 01:43:19 +00:00
|
|
|
isUnsignedDIType(DD, DV.getType()));
|
2013-07-03 01:08:30 +00:00
|
|
|
|
2013-11-15 01:43:19 +00:00
|
|
|
DV.setDIE(VariableDie);
|
2011-08-15 22:04:40 +00:00
|
|
|
return VariableDie;
|
|
|
|
} else {
|
|
|
|
// .. else use frame index.
|
2013-11-15 01:43:19 +00:00
|
|
|
int FI = DV.getFrameIndex();
|
2011-08-15 22:04:40 +00:00
|
|
|
if (FI != ~0) {
|
|
|
|
unsigned FrameReg = 0;
|
|
|
|
const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
|
2013-10-19 01:04:47 +00:00
|
|
|
int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg);
|
2011-08-15 22:04:40 +00:00
|
|
|
MachineLocation Location(FrameReg, Offset);
|
2013-11-15 01:43:19 +00:00
|
|
|
addVariableAddress(DV, VariableDie, Location);
|
2011-08-15 22:04:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 01:43:19 +00:00
|
|
|
DV.setDIE(VariableDie);
|
2011-08-15 22:04:40 +00:00
|
|
|
return VariableDie;
|
|
|
|
}
|
|
|
|
|
2013-10-23 23:00:44 +00:00
|
|
|
/// constructMemberDIE - Construct member DIE from DIDerivedType.
|
2013-12-09 23:32:48 +00:00
|
|
|
void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) {
|
2013-10-29 00:53:03 +00:00
|
|
|
DIE *MemberDie = createAndAddDIE(DT.getTag(), Buffer);
|
2011-04-12 23:21:44 +00:00
|
|
|
StringRef Name = DT.getName();
|
|
|
|
if (!Name.empty())
|
2011-10-27 06:44:11 +00:00
|
|
|
addString(MemberDie, dwarf::DW_AT_name, Name);
|
2011-04-12 23:21:44 +00:00
|
|
|
|
2013-10-08 18:42:58 +00:00
|
|
|
addType(MemberDie, resolve(DT.getTypeDerivedFrom()));
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
addSourceLine(MemberDie, DT);
|
|
|
|
|
2013-10-19 01:04:47 +00:00
|
|
|
if (DT.getTag() == dwarf::DW_TAG_inheritance && DT.isVirtual()) {
|
2011-04-12 23:21:44 +00: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 08:46:55 +00:00
|
|
|
DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc();
|
2013-10-21 17:28:37 +00: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);
|
|
|
|
|
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
|
2013-11-01 00:25:45 +00:00
|
|
|
} else {
|
|
|
|
uint64_t Size = DT.getSizeInBits();
|
|
|
|
uint64_t FieldSize = getBaseTypeSize(DD, DT);
|
|
|
|
uint64_t OffsetInBytes;
|
|
|
|
|
|
|
|
if (Size != FieldSize) {
|
2014-03-12 17:14:46 +00: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 00:25:45 +00: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-28 18:13:47 +00:00
|
|
|
// Here DW_AT_data_member_location points to the anonymous
|
2013-11-01 00:25:45 +00:00
|
|
|
// field that includes this bit field.
|
|
|
|
OffsetInBytes = FieldOffset >> 3;
|
|
|
|
} else
|
|
|
|
// This is not a bitfield.
|
|
|
|
OffsetInBytes = DT.getOffsetInBits() >> 3;
|
2014-01-03 00:48:38 +00:00
|
|
|
|
2014-01-03 01:30:05 +00:00
|
|
|
if (DD->getDwarfVersion() <= 2) {
|
2014-02-16 08:46:55 +00:00
|
|
|
DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc();
|
2014-01-03 01:30:05 +00:00
|
|
|
addUInt(MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
|
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
|
|
|
|
} else
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
|
|
|
|
OffsetInBytes);
|
2013-11-01 00:25:45 +00:00
|
|
|
}
|
2011-04-12 23:21:44 +00:00
|
|
|
|
|
|
|
if (DT.isProtected())
|
2011-12-13 05:09:11 +00:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-12 23:21:44 +00:00
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (DT.isPrivate())
|
2011-12-13 05:09:11 +00:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-12 23:21:44 +00:00
|
|
|
dwarf::DW_ACCESS_private);
|
|
|
|
// Otherwise C++ member and base classes are considered public.
|
2012-11-21 00:34:38 +00:00
|
|
|
else
|
2011-12-13 05:09:11 +00:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
|
2011-04-12 23:21:44 +00:00
|
|
|
dwarf::DW_ACCESS_public);
|
|
|
|
if (DT.isVirtual())
|
2011-12-14 00:56:07 +00:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
|
2011-04-12 23:21:44 +00:00
|
|
|
dwarf::DW_VIRTUALITY_virtual);
|
2011-04-16 00:11:51 +00:00
|
|
|
|
|
|
|
// Objective-C properties.
|
2012-02-06 17:49:43 +00:00
|
|
|
if (MDNode *PNode = DT.getObjCProperty())
|
|
|
|
if (DIEEntry *PropertyDie = getDIEEntry(PNode))
|
2012-11-21 00:34:38 +00:00
|
|
|
MemberDie->addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4,
|
2012-02-06 17:49:43 +00:00
|
|
|
PropertyDie);
|
|
|
|
|
2012-12-13 22:43:07 +00:00
|
|
|
if (DT.isArtificial())
|
|
|
|
addFlag(MemberDie, dwarf::DW_AT_artificial);
|
2011-04-12 23:21:44 +00:00
|
|
|
}
|
2013-01-16 01:22:23 +00:00
|
|
|
|
2013-10-14 20:33:57 +00:00
|
|
|
/// getOrCreateStaticMemberDIE - Create new DIE for C++ static member.
|
2013-12-09 23:32:48 +00:00
|
|
|
DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) {
|
2013-01-16 01:22:23 +00:00
|
|
|
if (!DT.Verify())
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-14 20:33:57 +00: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-14 21:24:34 +00:00
|
|
|
assert(dwarf::isType(ContextDIE->getTag()) &&
|
|
|
|
"Static member should belong to a type.");
|
2013-10-14 20:33:57 +00:00
|
|
|
|
|
|
|
DIE *StaticMemberDIE = getDIE(DT);
|
|
|
|
if (StaticMemberDIE)
|
|
|
|
return StaticMemberDIE;
|
|
|
|
|
2013-10-29 00:53:03 +00:00
|
|
|
StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT);
|
2013-10-14 20:33:57 +00:00
|
|
|
|
2013-10-08 18:42:58 +00:00
|
|
|
DIType Ty = resolve(DT.getTypeDerivedFrom());
|
2013-01-16 01:22:23 +00: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);
|
|
|
|
else
|
|
|
|
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()))
|
2013-10-05 01:43:03 +00:00
|
|
|
addConstantValue(StaticMemberDIE, CI, isUnsignedDIType(DD, Ty));
|
2013-01-20 01:18:01 +00:00
|
|
|
if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant()))
|
|
|
|
addConstantFPValue(StaticMemberDIE, CFP);
|
2013-01-16 01:22:23 +00:00
|
|
|
|
|
|
|
return StaticMemberDIE;
|
|
|
|
}
|
2013-10-30 20:42:41 +00:00
|
|
|
|
2014-03-24 20:28:10 +00:00
|
|
|
void DwarfUnit::emitHeader(const MCSymbol *ASectionSym) const {
|
2013-10-30 20:42:41 +00:00
|
|
|
Asm->OutStreamer.AddComment("DWARF version number");
|
|
|
|
Asm->EmitInt16(DD->getDwarfVersion());
|
|
|
|
Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
|
2013-12-04 23:39:02 +00: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-24 20:53:02 +00:00
|
|
|
if (ASectionSym)
|
|
|
|
Asm->EmitSectionOffset(ASectionSym, ASectionSym);
|
|
|
|
else
|
2014-04-02 02:04:51 +00:00
|
|
|
// Use a constant value when no symbol is provided.
|
2014-03-24 20:53:02 +00:00
|
|
|
Asm->EmitInt32(0);
|
2013-10-30 20:42:41 +00:00
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
|
|
|
Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
|
|
|
|
}
|
2013-12-13 21:33:40 +00:00
|
|
|
|
2014-03-20 19:16:16 +00:00
|
|
|
void DwarfUnit::addRange(RangeSpan Range) {
|
|
|
|
// Only add a range for this unit if we're emitting full debug.
|
|
|
|
if (getCUNode().getEmissionKind() == DIBuilder::FullDebug) {
|
|
|
|
// If we have no current ranges just add the range and return, otherwise,
|
|
|
|
// check the current section and CU against the previous section and CU we
|
|
|
|
// emitted into and the subprogram was contained within. If these are the
|
|
|
|
// same then extend our current range, otherwise add this as a new range.
|
|
|
|
if (CURanges.size() == 0 ||
|
|
|
|
this != DD->getPrevCU() ||
|
|
|
|
Asm->getCurrentSection() != DD->getPrevSection()) {
|
|
|
|
CURanges.push_back(Range);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(&(CURanges.back().getEnd()->getSection()) ==
|
|
|
|
&(Range.getEnd()->getSection()) &&
|
|
|
|
"We can only append to a range in the same section!");
|
|
|
|
CURanges.back().setEnd(Range.getEnd());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 22:41:51 +00:00
|
|
|
void DwarfCompileUnit::initStmtList(MCSymbol *DwarfLineSectionSym) {
|
|
|
|
// Define start line table label for each Compile Unit.
|
|
|
|
MCSymbol *LineTableStartSym =
|
2014-04-01 08:07:52 +00:00
|
|
|
Asm->OutStreamer.getDwarfLineTableSymbol(getUniqueID());
|
2014-02-14 22:41:51 +00:00
|
|
|
|
2014-02-14 23:58:13 +00:00
|
|
|
stmtListIndex = UnitDie->getValues().size();
|
|
|
|
|
2014-02-14 22:41:51 +00:00
|
|
|
// DW_AT_stmt_list is a offset of line number information for this
|
|
|
|
// compile unit in debug_line section. For split dwarf this is
|
|
|
|
// left in the skeleton CU and so not included.
|
|
|
|
// The line table entries are not always emitted in assembly, so it
|
|
|
|
// is not okay to use line_table_start here.
|
|
|
|
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
|
2014-04-01 08:07:52 +00:00
|
|
|
addSectionLabel(UnitDie.get(), dwarf::DW_AT_stmt_list, LineTableStartSym);
|
2014-02-14 22:41:51 +00:00
|
|
|
else
|
|
|
|
addSectionDelta(UnitDie.get(), dwarf::DW_AT_stmt_list, LineTableStartSym,
|
|
|
|
DwarfLineSectionSym);
|
|
|
|
}
|
|
|
|
|
2014-02-14 23:58:13 +00:00
|
|
|
void DwarfCompileUnit::applyStmtList(DIE &D) {
|
|
|
|
D.addValue(dwarf::DW_AT_stmt_list,
|
|
|
|
UnitDie->getAbbrev().getData()[stmtListIndex].getForm(),
|
|
|
|
UnitDie->getValues()[stmtListIndex]);
|
|
|
|
}
|
|
|
|
|
2014-03-24 20:28:10 +00:00
|
|
|
void DwarfTypeUnit::emitHeader(const MCSymbol *ASectionSym) const {
|
|
|
|
DwarfUnit::emitHeader(ASectionSym);
|
2013-12-13 21:33:40 +00:00
|
|
|
Asm->OutStreamer.AddComment("Type Signature");
|
|
|
|
Asm->OutStreamer.EmitIntValue(TypeSignature, sizeof(TypeSignature));
|
|
|
|
Asm->OutStreamer.AddComment("Type DIE Offset");
|
2014-01-10 01:38:41 +00: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-13 21:33:40 +00: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());
|
|
|
|
this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
|
|
|
|
}
|