2009-05-15 00:11:17 +00:00
|
|
|
//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Data structures for DWARF info entries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DIE.h"
|
2010-01-17 07:46:39 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-05-15 00:11:17 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-01-20 07:41:15 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-01-16 18:50:28 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2009-05-15 00:11:17 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2010-03-31 19:34:01 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-12-24 00:27:55 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 01:01:17 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
2010-01-22 22:09:00 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2009-05-15 00:11:17 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEAbbrevData Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Profile - Used to gather unique data for the abbreviation folding set.
|
|
|
|
///
|
|
|
|
void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddInteger(Attribute);
|
|
|
|
ID.AddInteger(Form);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEAbbrev Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Profile - Used to gather unique data for the abbreviation folding set.
|
|
|
|
///
|
|
|
|
void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddInteger(Tag);
|
|
|
|
ID.AddInteger(ChildrenFlag);
|
|
|
|
|
|
|
|
// For each attribute description.
|
|
|
|
for (unsigned i = 0, N = Data.size(); i < N; ++i)
|
|
|
|
Data[i].Profile(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit - Print the abbreviation using the specified asm printer.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIEAbbrev::Emit(AsmPrinter *AP) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
// Emit its Dwarf tag type.
|
2010-01-22 23:18:42 +00:00
|
|
|
// FIXME: Doing work even in non-asm-verbose runs.
|
2010-04-05 00:13:49 +00:00
|
|
|
AP->EmitULEB128(Tag, dwarf::TagString(Tag));
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
// Emit whether it has children DIEs.
|
2010-01-22 23:18:42 +00:00
|
|
|
// FIXME: Doing work even in non-asm-verbose runs.
|
2010-04-05 00:13:49 +00:00
|
|
|
AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
// For each attribute description.
|
|
|
|
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
|
|
|
|
const DIEAbbrevData &AttrData = Data[i];
|
|
|
|
|
|
|
|
// Emit attribute type.
|
2010-01-22 23:18:42 +00:00
|
|
|
// FIXME: Doing work even in non-asm-verbose runs.
|
2010-04-05 00:13:49 +00:00
|
|
|
AP->EmitULEB128(AttrData.getAttribute(),
|
2011-07-29 03:49:23 +00:00
|
|
|
dwarf::AttributeString(AttrData.getAttribute()));
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
// Emit form type.
|
2010-01-22 23:18:42 +00:00
|
|
|
// FIXME: Doing work even in non-asm-verbose runs.
|
2010-04-05 00:13:49 +00:00
|
|
|
AP->EmitULEB128(AttrData.getForm(),
|
|
|
|
dwarf::FormEncodingString(AttrData.getForm()));
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark end of abbreviation.
|
2010-04-05 00:13:49 +00:00
|
|
|
AP->EmitULEB128(0, "EOM(1)");
|
|
|
|
AP->EmitULEB128(0, "EOM(2)");
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIEAbbrev::print(raw_ostream &O) {
|
2009-05-15 00:11:17 +00:00
|
|
|
O << "Abbreviation @"
|
2009-08-23 01:01:17 +00:00
|
|
|
<< format("0x%lx", (long)(intptr_t)this)
|
2009-05-15 00:11:17 +00:00
|
|
|
<< " "
|
|
|
|
<< dwarf::TagString(Tag)
|
|
|
|
<< " "
|
|
|
|
<< dwarf::ChildrenString(ChildrenFlag)
|
2009-08-23 01:01:17 +00:00
|
|
|
<< '\n';
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
|
|
|
|
O << " "
|
|
|
|
<< dwarf::AttributeString(Data[i].getAttribute())
|
|
|
|
<< " "
|
|
|
|
<< dwarf::FormEncodingString(Data[i].getForm())
|
2009-08-23 01:01:17 +00:00
|
|
|
<< '\n';
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-24 00:27:55 +00:00
|
|
|
void DIEAbbrev::dump() { print(dbgs()); }
|
2009-05-15 00:11:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIE Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
DIE::~DIE() {
|
|
|
|
for (unsigned i = 0, N = Children.size(); i < N; ++i)
|
|
|
|
delete Children[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIE::print(raw_ostream &O, unsigned IncIndent) {
|
2009-05-15 00:11:17 +00:00
|
|
|
IndentCount += IncIndent;
|
|
|
|
const std::string Indent(IndentCount, ' ');
|
|
|
|
bool isBlock = Abbrev.getTag() == 0;
|
|
|
|
|
|
|
|
if (!isBlock) {
|
|
|
|
O << Indent
|
|
|
|
<< "Die: "
|
2009-08-23 01:01:17 +00:00
|
|
|
<< format("0x%lx", (long)(intptr_t)this)
|
2009-05-15 00:11:17 +00:00
|
|
|
<< ", Offset: " << Offset
|
2010-03-09 23:38:23 +00:00
|
|
|
<< ", Size: " << Size << "\n";
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
O << Indent
|
|
|
|
<< dwarf::TagString(Abbrev.getTag())
|
|
|
|
<< " "
|
2010-03-09 23:38:23 +00:00
|
|
|
<< dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
|
2009-05-15 00:11:17 +00:00
|
|
|
} else {
|
2010-03-09 23:38:23 +00:00
|
|
|
O << "Size: " << Size << "\n";
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SmallVector<DIEAbbrevData, 8> &Data = Abbrev.getData();
|
|
|
|
|
|
|
|
IndentCount += 2;
|
|
|
|
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
|
|
|
|
O << Indent;
|
|
|
|
|
|
|
|
if (!isBlock)
|
|
|
|
O << dwarf::AttributeString(Data[i].getAttribute());
|
|
|
|
else
|
|
|
|
O << "Blk[" << i << "]";
|
|
|
|
|
|
|
|
O << " "
|
|
|
|
<< dwarf::FormEncodingString(Data[i].getForm())
|
|
|
|
<< " ";
|
|
|
|
Values[i]->print(O);
|
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
IndentCount -= 2;
|
|
|
|
|
|
|
|
for (unsigned j = 0, M = Children.size(); j < M; ++j) {
|
|
|
|
Children[j]->print(O, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isBlock) O << "\n";
|
|
|
|
IndentCount -= IncIndent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIE::dump() {
|
2009-12-24 00:27:55 +00:00
|
|
|
print(dbgs());
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void DIEValue::anchor() { }
|
2009-05-15 00:11:17 +00:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
void DIEValue::dump() {
|
2009-12-24 00:27:55 +00:00
|
|
|
print(dbgs());
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEInteger Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// EmitValue - Emit integer of appropriate size.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIEInteger::EmitValue(AsmPrinter *Asm, unsigned Form) const {
|
2010-01-20 07:41:15 +00:00
|
|
|
unsigned Size = ~0U;
|
2009-05-15 00:11:17 +00:00
|
|
|
switch (Form) {
|
2012-08-24 01:14:27 +00:00
|
|
|
case dwarf::DW_FORM_flag_present:
|
|
|
|
// Emit something to keep the lines and comments in sync.
|
|
|
|
// FIXME: Is there a better way to do this?
|
|
|
|
if (Asm->OutStreamer.hasRawTextSupport())
|
|
|
|
Asm->OutStreamer.EmitRawText(StringRef(""));
|
|
|
|
return;
|
2009-05-15 00:11:17 +00:00
|
|
|
case dwarf::DW_FORM_flag: // Fall thru
|
|
|
|
case dwarf::DW_FORM_ref1: // Fall thru
|
2010-01-20 07:41:15 +00:00
|
|
|
case dwarf::DW_FORM_data1: Size = 1; break;
|
2009-05-15 00:11:17 +00:00
|
|
|
case dwarf::DW_FORM_ref2: // Fall thru
|
2010-01-20 07:41:15 +00:00
|
|
|
case dwarf::DW_FORM_data2: Size = 2; break;
|
2009-05-15 00:11:17 +00:00
|
|
|
case dwarf::DW_FORM_ref4: // Fall thru
|
2010-01-20 07:41:15 +00:00
|
|
|
case dwarf::DW_FORM_data4: Size = 4; break;
|
2009-05-15 00:11:17 +00:00
|
|
|
case dwarf::DW_FORM_ref8: // Fall thru
|
2010-01-20 07:41:15 +00:00
|
|
|
case dwarf::DW_FORM_data8: Size = 8; break;
|
2010-04-04 19:09:29 +00:00
|
|
|
case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
|
|
|
|
case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
|
2012-09-10 23:34:03 +00:00
|
|
|
case dwarf::DW_FORM_addr:
|
|
|
|
Size = Asm->getTargetData().getPointerSize(); break;
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("DIE Value form not supported yet");
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
2010-01-20 07:41:15 +00:00
|
|
|
Asm->OutStreamer.EmitIntValue(Integer, Size, 0/*addrspace*/);
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of integer value in bytes.
|
|
|
|
///
|
2010-04-05 00:18:22 +00:00
|
|
|
unsigned DIEInteger::SizeOf(AsmPrinter *AP, unsigned Form) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
switch (Form) {
|
2012-08-29 17:59:32 +00:00
|
|
|
case dwarf::DW_FORM_flag_present: return 0;
|
2009-05-15 00:11:17 +00:00
|
|
|
case dwarf::DW_FORM_flag: // Fall thru
|
|
|
|
case dwarf::DW_FORM_ref1: // Fall thru
|
|
|
|
case dwarf::DW_FORM_data1: return sizeof(int8_t);
|
|
|
|
case dwarf::DW_FORM_ref2: // Fall thru
|
|
|
|
case dwarf::DW_FORM_data2: return sizeof(int16_t);
|
|
|
|
case dwarf::DW_FORM_ref4: // Fall thru
|
|
|
|
case dwarf::DW_FORM_data4: return sizeof(int32_t);
|
|
|
|
case dwarf::DW_FORM_ref8: // Fall thru
|
|
|
|
case dwarf::DW_FORM_data8: return sizeof(int64_t);
|
2009-08-22 20:48:53 +00:00
|
|
|
case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
|
|
|
|
case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
|
2010-06-28 22:22:47 +00:00
|
|
|
case dwarf::DW_FORM_addr: return AP->getTargetData().getPointerSize();
|
2012-01-20 21:51:11 +00:00
|
|
|
default: llvm_unreachable("DIE Value form not supported yet");
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIEInteger::print(raw_ostream &O) {
|
2011-11-05 08:57:40 +00:00
|
|
|
O << "Int: " << (int64_t)Integer << " 0x";
|
|
|
|
O.write_hex(Integer);
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-08 22:31:46 +00:00
|
|
|
// DIELabel Implementation
|
2009-05-15 00:11:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// EmitValue - Emit label value.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIELabel::EmitValue(AsmPrinter *AP, unsigned Form) const {
|
2010-04-05 00:18:22 +00:00
|
|
|
AP->OutStreamer.EmitSymbolValue(Label, SizeOf(AP, Form), 0/*AddrSpace*/);
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of label value in bytes.
|
|
|
|
///
|
2010-04-05 00:18:22 +00:00
|
|
|
unsigned DIELabel::SizeOf(AsmPrinter *AP, unsigned Form) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
if (Form == dwarf::DW_FORM_data4) return 4;
|
2011-10-27 06:44:11 +00:00
|
|
|
if (Form == dwarf::DW_FORM_strp) return 4;
|
2010-04-05 00:18:22 +00:00
|
|
|
return AP->getTargetData().getPointerSize();
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2010-03-08 22:31:46 +00:00
|
|
|
void DIELabel::print(raw_ostream &O) {
|
2010-03-08 22:23:36 +00:00
|
|
|
O << "Lbl: " << Label->getName();
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEDelta Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// EmitValue - Emit delta value.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIEDelta::EmitValue(AsmPrinter *AP, unsigned Form) const {
|
2010-04-05 00:18:22 +00:00
|
|
|
AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of delta value in bytes.
|
|
|
|
///
|
2010-04-05 00:18:22 +00:00
|
|
|
unsigned DIEDelta::SizeOf(AsmPrinter *AP, unsigned Form) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
if (Form == dwarf::DW_FORM_data4) return 4;
|
2011-10-27 06:44:11 +00:00
|
|
|
if (Form == dwarf::DW_FORM_strp) return 4;
|
2010-04-05 00:18:22 +00:00
|
|
|
return AP->getTargetData().getPointerSize();
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIEDelta::print(raw_ostream &O) {
|
2010-03-08 22:23:36 +00:00
|
|
|
O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEEntry Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// EmitValue - Emit debug information entry offset.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIEEntry::EmitValue(AsmPrinter *AP, unsigned Form) const {
|
|
|
|
AP->EmitInt32(Entry->getOffset());
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIEEntry::print(raw_ostream &O) {
|
|
|
|
O << format("Die: 0x%lx", (long)(intptr_t)Entry);
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DIEBlock Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ComputeSize - calculate the size of the block.
|
|
|
|
///
|
2010-04-05 00:18:22 +00:00
|
|
|
unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
|
2009-05-15 00:11:17 +00:00
|
|
|
if (!Size) {
|
|
|
|
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
|
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
2010-04-05 00:18:22 +00:00
|
|
|
Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitValue - Emit block data.
|
|
|
|
///
|
2010-04-05 00:13:49 +00:00
|
|
|
void DIEBlock::EmitValue(AsmPrinter *Asm, unsigned Form) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
switch (Form) {
|
2012-02-05 08:31:47 +00:00
|
|
|
default: llvm_unreachable("Improper form for block");
|
2010-04-04 19:09:29 +00:00
|
|
|
case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
|
|
|
|
case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
|
|
|
|
case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
|
|
|
|
case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
|
2010-03-09 23:38:23 +00:00
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
2010-04-05 00:13:49 +00:00
|
|
|
Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of block data in bytes.
|
|
|
|
///
|
2010-04-05 00:18:22 +00:00
|
|
|
unsigned DIEBlock::SizeOf(AsmPrinter *AP, unsigned Form) const {
|
2009-05-15 00:11:17 +00:00
|
|
|
switch (Form) {
|
|
|
|
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
|
|
|
|
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
|
|
|
|
case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
|
2010-04-04 19:09:29 +00:00
|
|
|
case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
|
2012-01-20 21:51:11 +00:00
|
|
|
default: llvm_unreachable("Improper form for block");
|
2009-05-15 00:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-23 01:01:17 +00:00
|
|
|
void DIEBlock::print(raw_ostream &O) {
|
2009-05-15 00:11:17 +00:00
|
|
|
O << "Blk: ";
|
|
|
|
DIE::print(O, 5);
|
|
|
|
}
|
|
|
|
#endif
|