2005-12-21 19:44:40 +00:00
|
|
|
//===-- llvm/CodeGen/DwarfWriter.h - Dwarf Framework ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by James M. Laskey and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-01-17 17:31:53 +00:00
|
|
|
// This file contains support for writing Dwarf debug info into asm files. For
|
|
|
|
// Details on the Dwarf 3 specfication see DWARF Debugging Information Format
|
|
|
|
// V.3 reference manual http://dwarf.freestandards.org ,
|
2005-12-21 19:44:40 +00:00
|
|
|
//
|
2006-01-17 17:31:53 +00:00
|
|
|
// The role of the Dwarf Writer class is to extract debug information from the
|
|
|
|
// MachineDebugInfo object, organize it in Dwarf form and then emit it into asm
|
|
|
|
// the current asm file using data and high level Dwarf directives.
|
|
|
|
//
|
2005-12-21 19:44:40 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-01-17 19:12:24 +00:00
|
|
|
#ifndef LLVM_CODEGEN_DWARFWRITER_H
|
|
|
|
#define LLVM_CODEGEN_DWARFWRITER_H
|
2005-12-21 19:44:40 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
#include "llvm/ADT/UniqueVector.h"
|
2006-01-27 18:32:41 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
#include <iosfwd>
|
2006-01-17 17:31:53 +00:00
|
|
|
#include <string>
|
|
|
|
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2005-12-21 19:46:32 +00:00
|
|
|
namespace llvm {
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Forward declarations.
|
|
|
|
//
|
|
|
|
class AsmPrinter;
|
2006-02-06 15:33:21 +00:00
|
|
|
class CompileUnitDesc;
|
2006-02-22 19:02:11 +00:00
|
|
|
class DebugInfoDesc;
|
2006-01-20 20:34:06 +00:00
|
|
|
class DIE;
|
2006-02-22 19:02:11 +00:00
|
|
|
class DwarfWriter;
|
|
|
|
class GlobalVariableDesc;
|
2006-01-20 20:34:06 +00:00
|
|
|
class MachineDebugInfo;
|
2006-01-24 00:49:18 +00:00
|
|
|
class MachineFunction;
|
|
|
|
class Module;
|
2006-02-22 19:02:11 +00:00
|
|
|
class SubprogramDesc;
|
2006-01-24 00:49:18 +00:00
|
|
|
class Type;
|
2006-02-23 16:58:18 +00:00
|
|
|
class TypeDesc;
|
2006-01-20 20:34:06 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DWLabel - Labels are used to track locations in the assembler file.
|
|
|
|
// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
|
|
|
|
// category of label (Ex. location) and number is a value unique in that
|
|
|
|
// category.
|
2006-01-24 00:49:18 +00:00
|
|
|
class DWLabel {
|
|
|
|
public:
|
2006-01-17 17:31:53 +00:00
|
|
|
const char *Tag; // Label category tag. Should always be
|
|
|
|
// a staticly declared C string.
|
2006-01-20 20:34:06 +00:00
|
|
|
unsigned Number; // Unique number.
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
|
|
|
|
};
|
2006-01-20 20:34:06 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
|
|
|
|
// Dwarf abbreviation.
|
|
|
|
class DIEAbbrevData {
|
|
|
|
private:
|
|
|
|
unsigned Attribute; // Dwarf attribute code.
|
|
|
|
unsigned Form; // Dwarf form code.
|
|
|
|
|
|
|
|
public:
|
|
|
|
DIEAbbrevData(unsigned A, unsigned F)
|
|
|
|
: Attribute(A)
|
|
|
|
, Form(F)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
unsigned getAttribute() const { return Attribute; }
|
|
|
|
unsigned getForm() const { return Form; }
|
2006-01-21 01:13:18 +00:00
|
|
|
|
|
|
|
/// operator== - Used by DIEAbbrev to locate entry.
|
|
|
|
///
|
|
|
|
bool operator==(const DIEAbbrevData &DAD) const {
|
|
|
|
return Attribute == DAD.Attribute && Form == DAD.Form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// operator!= - Used by DIEAbbrev to locate entry.
|
|
|
|
///
|
|
|
|
bool operator!=(const DIEAbbrevData &DAD) const {
|
|
|
|
return Attribute != DAD.Attribute || Form != DAD.Form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// operator< - Used by DIEAbbrev to locate entry.
|
|
|
|
///
|
|
|
|
bool operator<(const DIEAbbrevData &DAD) const {
|
|
|
|
return Attribute < DAD.Attribute ||
|
|
|
|
(Attribute == DAD.Attribute && Form < DAD.Form);
|
|
|
|
}
|
2006-01-20 20:34:06 +00:00
|
|
|
};
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
|
|
|
|
// information object.
|
|
|
|
class DIEAbbrev {
|
|
|
|
private:
|
2006-01-20 20:34:06 +00:00
|
|
|
unsigned Tag; // Dwarf tag code.
|
|
|
|
unsigned ChildrenFlag; // Dwarf children flag.
|
|
|
|
std::vector<DIEAbbrevData> Data; // Raw data bytes for abbreviation.
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
DIEAbbrev(unsigned T, unsigned C)
|
|
|
|
: Tag(T)
|
|
|
|
, ChildrenFlag(C)
|
|
|
|
, Data()
|
2006-01-17 17:31:53 +00:00
|
|
|
{}
|
2006-01-20 20:34:06 +00:00
|
|
|
~DIEAbbrev() {}
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
// Accessors
|
|
|
|
unsigned getTag() const { return Tag; }
|
|
|
|
unsigned getChildrenFlag() const { return ChildrenFlag; }
|
|
|
|
const std::vector<DIEAbbrevData> &getData() const { return Data; }
|
2006-02-22 19:02:11 +00:00
|
|
|
void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
|
2006-01-20 20:34:06 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// operator== - Used by UniqueVector to locate entry.
|
|
|
|
///
|
2006-01-20 20:34:06 +00:00
|
|
|
bool operator==(const DIEAbbrev &DA) const;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// operator< - Used by UniqueVector to locate entry.
|
|
|
|
///
|
2006-01-20 20:34:06 +00:00
|
|
|
bool operator<(const DIEAbbrev &DA) const;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
/// AddAttribute - Adds another set of attribute information to the
|
|
|
|
/// abbreviation.
|
|
|
|
void AddAttribute(unsigned Attribute, unsigned Form) {
|
|
|
|
Data.push_back(DIEAbbrevData(Attribute, Form));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit - Print the abbreviation using the specified Dwarf writer.
|
|
|
|
///
|
|
|
|
void Emit(const DwarfWriter &DW) const;
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
void print(std::ostream &O);
|
|
|
|
void dump();
|
|
|
|
#endif
|
2006-01-17 17:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEValue - A debug information entry value.
|
|
|
|
//
|
|
|
|
class DIEValue {
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
isInteger,
|
|
|
|
isString,
|
|
|
|
isLabel,
|
2006-01-20 20:34:06 +00:00
|
|
|
isAsIsLabel,
|
|
|
|
isDelta,
|
|
|
|
isEntry
|
2006-01-17 17:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
unsigned Type; // Type of the value
|
|
|
|
|
|
|
|
DIEValue(unsigned T) : Type(T) {}
|
|
|
|
virtual ~DIEValue() {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
|
|
|
static bool classof(const DIEValue *) { return true; }
|
|
|
|
|
|
|
|
/// EmitValue - Emit value via the Dwarf writer.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const = 0;
|
|
|
|
|
|
|
|
/// SizeOf - Return the size of a value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DWInteger - An integer value DIE.
|
|
|
|
//
|
|
|
|
class DIEInteger : public DIEValue {
|
|
|
|
private:
|
2006-01-27 15:20:54 +00:00
|
|
|
uint64_t Integer;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
public:
|
2006-01-27 15:20:54 +00:00
|
|
|
DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
|
|
|
static bool classof(const DIEInteger *) { return true; }
|
2006-01-20 20:34:06 +00:00
|
|
|
static bool classof(const DIEValue *I) { return I->Type == isInteger; }
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// EmitValue - Emit integer of appropriate size.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of integer value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEString - A string value DIE.
|
|
|
|
//
|
|
|
|
struct DIEString : public DIEValue {
|
2006-01-20 20:34:06 +00:00
|
|
|
const std::string String;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
DIEString(const std::string &S) : DIEValue(isString), String(S) {}
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
|
|
|
static bool classof(const DIEString *) { return true; }
|
2006-01-20 20:34:06 +00:00
|
|
|
static bool classof(const DIEValue *S) { return S->Type == isString; }
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// EmitValue - Emit string value.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of string value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2006-01-24 00:49:18 +00:00
|
|
|
// DIEDwarfLabel - A Dwarf internal label expression DIE.
|
2006-01-17 17:31:53 +00:00
|
|
|
//
|
2006-01-24 00:49:18 +00:00
|
|
|
struct DIEDwarfLabel : public DIEValue {
|
2006-01-20 20:34:06 +00:00
|
|
|
const DWLabel Label;
|
|
|
|
|
2006-01-24 00:49:18 +00:00
|
|
|
DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
|
2006-01-20 20:34:06 +00:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
2006-01-24 00:49:18 +00:00
|
|
|
static bool classof(const DIEDwarfLabel *) { return true; }
|
2006-01-20 20:34:06 +00:00
|
|
|
static bool classof(const DIEValue *L) { return L->Type == isLabel; }
|
|
|
|
|
|
|
|
/// EmitValue - Emit label value.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of label value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2006-01-24 00:49:18 +00:00
|
|
|
// DIEObjectLabel - A label to an object in code or data.
|
2006-01-20 20:34:06 +00:00
|
|
|
//
|
2006-01-24 00:49:18 +00:00
|
|
|
struct DIEObjectLabel : public DIEValue {
|
2006-01-20 20:34:06 +00:00
|
|
|
const std::string Label;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-24 00:49:18 +00:00
|
|
|
DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
2006-01-24 00:49:18 +00:00
|
|
|
static bool classof(const DIEObjectLabel *) { return true; }
|
2006-01-20 20:34:06 +00:00
|
|
|
static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// EmitValue - Emit label value.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of label value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEDelta - A simple label difference DIE.
|
|
|
|
//
|
|
|
|
struct DIEDelta : public DIEValue {
|
2006-01-20 20:34:06 +00:00
|
|
|
const DWLabel LabelHi;
|
|
|
|
const DWLabel LabelLo;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
|
|
|
|
: DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
|
|
|
static bool classof(const DIEDelta *) { return true; }
|
2006-01-20 20:34:06 +00:00
|
|
|
static bool classof(const DIEValue *D) { return D->Type == isDelta; }
|
|
|
|
|
|
|
|
/// EmitValue - Emit delta value.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of delta value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIEntry - A pointer to a debug information entry.
|
|
|
|
//
|
|
|
|
struct DIEntry : public DIEValue {
|
|
|
|
DIE *Entry;
|
|
|
|
|
|
|
|
DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast.
|
|
|
|
static bool classof(const DIEntry *) { return true; }
|
|
|
|
static bool classof(const DIEValue *E) { return E->Type == isEntry; }
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// EmitValue - Emit delta value.
|
|
|
|
///
|
|
|
|
virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
|
|
|
|
/// SizeOf - Determine size of delta value in bytes.
|
|
|
|
///
|
|
|
|
virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DIE - A structured debug information entry. Has an abbreviation which
|
|
|
|
// describes it's organization.
|
|
|
|
class DIE {
|
|
|
|
private:
|
2006-01-20 20:34:06 +00:00
|
|
|
DIEAbbrev *Abbrev; // Temporary buffer for abbreviation.
|
2006-01-17 17:31:53 +00:00
|
|
|
unsigned AbbrevID; // Decribing abbreviation ID.
|
2006-01-20 20:34:06 +00:00
|
|
|
unsigned Offset; // Offset in debug info section.
|
|
|
|
unsigned Size; // Size of instance + children.
|
|
|
|
std::vector<DIE *> Children; // Children DIEs.
|
|
|
|
std::vector<DIEValue *> Values; // Attributes values.
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
public:
|
2006-02-22 19:02:11 +00:00
|
|
|
DIE(unsigned Tag);
|
2006-01-20 20:34:06 +00:00
|
|
|
~DIE();
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
// Accessors
|
2006-01-20 20:34:06 +00:00
|
|
|
unsigned getAbbrevID() const { return AbbrevID; }
|
|
|
|
unsigned getOffset() const { return Offset; }
|
|
|
|
unsigned getSize() const { return Size; }
|
2006-01-17 17:31:53 +00:00
|
|
|
const std::vector<DIE *> &getChildren() const { return Children; }
|
|
|
|
const std::vector<DIEValue *> &getValues() const { return Values; }
|
|
|
|
void setOffset(unsigned O) { Offset = O; }
|
|
|
|
void setSize(unsigned S) { Size = S; }
|
|
|
|
|
|
|
|
/// SiblingOffset - Return the offset of the debug information entry's
|
|
|
|
/// sibling.
|
|
|
|
unsigned SiblingOffset() const { return Offset + Size; }
|
|
|
|
|
2006-01-27 15:20:54 +00:00
|
|
|
/// AddUInt - Add an unsigned integer attribute data and value.
|
2006-01-20 20:34:06 +00:00
|
|
|
///
|
2006-01-27 15:20:54 +00:00
|
|
|
void AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer);
|
|
|
|
|
|
|
|
/// AddSInt - Add an signed integer attribute data and value.
|
|
|
|
///
|
|
|
|
void AddSInt(unsigned Attribute, unsigned Form, int64_t Integer);
|
2006-01-20 20:34:06 +00:00
|
|
|
|
|
|
|
/// AddString - Add a std::string attribute data and value.
|
|
|
|
///
|
|
|
|
void AddString(unsigned Attribute, unsigned Form,
|
|
|
|
const std::string &String);
|
|
|
|
|
|
|
|
/// AddLabel - Add a Dwarf label attribute data and value.
|
|
|
|
///
|
|
|
|
void AddLabel(unsigned Attribute, unsigned Form, const DWLabel &Label);
|
|
|
|
|
2006-01-24 00:49:18 +00:00
|
|
|
/// AddObjectLabel - Add a non-Dwarf label attribute data and value.
|
2006-01-20 20:34:06 +00:00
|
|
|
///
|
2006-01-24 00:49:18 +00:00
|
|
|
void AddObjectLabel(unsigned Attribute, unsigned Form,
|
|
|
|
const std::string &Label);
|
2006-01-20 20:34:06 +00:00
|
|
|
|
|
|
|
/// AddDelta - Add a label delta attribute data and value.
|
|
|
|
///
|
|
|
|
void AddDelta(unsigned Attribute, unsigned Form,
|
|
|
|
const DWLabel &Hi, const DWLabel &Lo);
|
|
|
|
|
|
|
|
/// AddDIEntry - Add a DIE attribute data and value.
|
|
|
|
///
|
|
|
|
void AddDIEntry(unsigned Attribute, unsigned Form, DIE *Entry);
|
|
|
|
|
|
|
|
/// Complete - Indicate that all attributes have been added and
|
|
|
|
/// ready to get an abbreviation ID.
|
|
|
|
///
|
|
|
|
void Complete(DwarfWriter &DW);
|
|
|
|
|
|
|
|
/// AddChild - Add a child to the DIE.
|
|
|
|
void AddChild(DIE *Child);
|
|
|
|
};
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DwarfWriter - Emits Dwarf debug and exception handling directives.
|
2006-01-04 13:52:30 +00:00
|
|
|
//
|
|
|
|
class DwarfWriter {
|
|
|
|
protected:
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Core attributes used by the Dwarf writer.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
2006-01-04 13:52:30 +00:00
|
|
|
/// O - Stream to .s file.
|
|
|
|
///
|
|
|
|
std::ostream &O;
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// Asm - Target of Dwarf emission.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
|
|
|
AsmPrinter *Asm;
|
|
|
|
|
|
|
|
/// DebugInfo - Collected debug information.
|
|
|
|
///
|
2006-01-04 22:28:25 +00:00
|
|
|
MachineDebugInfo *DebugInfo;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
/// didInitial - Flag to indicate if initial emission has been done.
|
|
|
|
///
|
|
|
|
bool didInitial;
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Attributes used to construct specific Dwarf sections.
|
|
|
|
//
|
|
|
|
|
|
|
|
/// CompileUnits - All the compile units involved in this build. The index
|
|
|
|
/// of each entry in this vector corresponds to the sources in DebugInfo.
|
|
|
|
std::vector<DIE *> CompileUnits;
|
|
|
|
|
|
|
|
/// Abbreviations - A UniqueVector of TAG structure abbreviations.
|
|
|
|
///
|
|
|
|
UniqueVector<DIEAbbrev> Abbreviations;
|
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
/// GlobalTypes - A map of globally visible named types.
|
|
|
|
///
|
|
|
|
std::map<std::string, DIE *> GlobalTypes;
|
|
|
|
|
|
|
|
/// GlobalEntities - A map of globally visible named entities.
|
|
|
|
///
|
|
|
|
std::map<std::string, DIE *> GlobalEntities;
|
|
|
|
|
|
|
|
/// StringPool - A UniqueVector of strings used by indirect references.
|
|
|
|
///
|
|
|
|
UniqueVector<std::string> StringPool;
|
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// DescToDieMap - Tracks the mapping of debug informaton descriptors to
|
|
|
|
/// DIES.
|
|
|
|
std::map<DebugInfoDesc *, DIE *> DescToDieMap;
|
|
|
|
|
|
|
|
/// TypeToDieMap - Type to DIEType map.
|
|
|
|
///
|
|
|
|
// FIXME - Should not be needed.
|
|
|
|
std::map<Type *, DIE *> TypeToDieMap;
|
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Properties to be set by the derived class ctor, used to configure the
|
2006-01-17 17:31:53 +00:00
|
|
|
// Dwarf writer.
|
|
|
|
//
|
|
|
|
|
|
|
|
/// AddressSize - Size of addresses used in file.
|
|
|
|
///
|
|
|
|
unsigned AddressSize;
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-04 13:52:30 +00:00
|
|
|
/// hasLEB128 - True if target asm supports leb128 directives.
|
|
|
|
///
|
|
|
|
bool hasLEB128; /// Defaults to false.
|
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
/// hasDotLoc - True if target asm supports .loc directives.
|
|
|
|
///
|
|
|
|
bool hasDotLoc; /// Defaults to false.
|
|
|
|
|
|
|
|
/// hasDotFile - True if target asm supports .file directives.
|
|
|
|
///
|
|
|
|
bool hasDotFile; /// Defaults to false.
|
|
|
|
|
2006-01-04 13:52:30 +00:00
|
|
|
/// needsSet - True if target asm can't compute addresses on data
|
|
|
|
/// directives.
|
|
|
|
bool needsSet; /// Defaults to false.
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// DwarfAbbrevSection - Section directive for Dwarf abbrev.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
|
|
|
const char *DwarfAbbrevSection; /// Defaults to ".debug_abbrev".
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// DwarfInfoSection - Section directive for Dwarf info.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
|
|
|
const char *DwarfInfoSection; /// Defaults to ".debug_info".
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// DwarfLineSection - Section directive for Dwarf info.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
|
|
|
const char *DwarfLineSection; /// Defaults to ".debug_line".
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-17 20:41:40 +00:00
|
|
|
/// DwarfFrameSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfFrameSection; /// Defaults to ".debug_frame".
|
|
|
|
|
|
|
|
/// DwarfPubNamesSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfPubNamesSection; /// Defaults to ".debug_pubnames".
|
|
|
|
|
|
|
|
/// DwarfPubTypesSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfPubTypesSection; /// Defaults to ".debug_pubtypes".
|
|
|
|
|
|
|
|
/// DwarfStrSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfStrSection; /// Defaults to ".debug_str".
|
|
|
|
|
|
|
|
/// DwarfLocSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfLocSection; /// Defaults to ".debug_loc".
|
|
|
|
|
|
|
|
/// DwarfARangesSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfARangesSection; /// Defaults to ".debug_aranges".
|
|
|
|
|
|
|
|
/// DwarfRangesSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfRangesSection; /// Defaults to ".debug_ranges".
|
|
|
|
|
|
|
|
/// DwarfMacInfoSection - Section directive for Dwarf info.
|
|
|
|
///
|
|
|
|
const char *DwarfMacInfoSection; /// Defaults to ".debug_macinfo".
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// TextSection - Section directive for standard text.
|
|
|
|
///
|
|
|
|
const char *TextSection; /// Defaults to ".text".
|
|
|
|
|
|
|
|
/// DataSection - Section directive for standard data.
|
|
|
|
///
|
|
|
|
const char *DataSection; /// Defaults to ".data".
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
2006-01-17 17:31:53 +00:00
|
|
|
// Emission and print routines
|
|
|
|
//
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
public:
|
|
|
|
/// getAddressSize - Return the size of a target address in bytes.
|
|
|
|
///
|
|
|
|
unsigned getAddressSize() const { return AddressSize; }
|
|
|
|
|
|
|
|
/// PrintHex - Print a value as a hexidecimal value.
|
|
|
|
///
|
|
|
|
void PrintHex(int Value) const;
|
|
|
|
|
|
|
|
/// EOL - Print a newline character to asm stream. If a comment is present
|
|
|
|
/// then it will be printed first. Comments should not contain '\n'.
|
|
|
|
void EOL(const std::string &Comment) const;
|
|
|
|
|
|
|
|
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
|
|
|
|
/// unsigned leb128 value.
|
|
|
|
void EmitULEB128Bytes(unsigned Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
|
|
|
|
/// signed leb128 value.
|
|
|
|
void EmitSLEB128Bytes(int Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// PrintULEB128 - Print a series of hexidecimal values (separated by
|
|
|
|
/// commas) representing an unsigned leb128 value.
|
|
|
|
void PrintULEB128(unsigned Value) const;
|
|
|
|
|
|
|
|
/// SizeULEB128 - Compute the number of bytes required for an unsigned
|
|
|
|
/// leb128 value.
|
|
|
|
static unsigned SizeULEB128(unsigned Value);
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// PrintSLEB128 - Print a series of hexidecimal values (separated by
|
|
|
|
/// commas) representing a signed leb128 value.
|
|
|
|
void PrintSLEB128(int Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// SizeSLEB128 - Compute the number of bytes required for a signed leb128
|
|
|
|
/// value.
|
|
|
|
static unsigned SizeSLEB128(int Value);
|
|
|
|
|
2006-01-27 20:31:25 +00:00
|
|
|
/// EmitInt8 - Emit a byte directive and value.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
2006-01-27 20:31:25 +00:00
|
|
|
void EmitInt8(int Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-27 20:31:25 +00:00
|
|
|
/// EmitInt16 - Emit a short directive and value.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
2006-01-27 20:31:25 +00:00
|
|
|
void EmitInt16(int Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-27 20:31:25 +00:00
|
|
|
/// EmitInt32 - Emit a long directive and value.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
2006-01-27 20:31:25 +00:00
|
|
|
void EmitInt32(int Value) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-27 20:31:25 +00:00
|
|
|
/// EmitInt64 - Emit a long long directive and value.
|
2006-01-27 15:20:54 +00:00
|
|
|
///
|
2006-01-27 20:31:25 +00:00
|
|
|
void EmitInt64(uint64_t Value) const;
|
2006-01-27 15:20:54 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitString - Emit a string with quotes and a null terminator.
|
|
|
|
/// Special characters are emitted properly. (Eg. '\t')
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitString(const std::string &String) const;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// PrintLabelName - Print label name in form used by Dwarf writer.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
void PrintLabelName(DWLabel Label) const {
|
|
|
|
PrintLabelName(Label.Tag, Label.Number);
|
|
|
|
}
|
|
|
|
void PrintLabelName(const char *Tag, unsigned Number) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitLabel - Emit location label for internal use by Dwarf.
|
2006-01-04 13:52:30 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
void EmitLabel(DWLabel Label) const {
|
|
|
|
EmitLabel(Label.Tag, Label.Number);
|
|
|
|
}
|
|
|
|
void EmitLabel(const char *Tag, unsigned Number) const;
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-18 16:54:26 +00:00
|
|
|
/// EmitReference - Emit a reference to a label.
|
2006-01-17 17:31:53 +00:00
|
|
|
///
|
2006-01-18 16:54:26 +00:00
|
|
|
void EmitReference(DWLabel Label) const {
|
|
|
|
EmitReference(Label.Tag, Label.Number);
|
2006-01-17 17:31:53 +00:00
|
|
|
}
|
2006-01-18 16:54:26 +00:00
|
|
|
void EmitReference(const char *Tag, unsigned Number) const;
|
2006-01-21 00:59:54 +00:00
|
|
|
void EmitReference(const std::string &Name) const;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// EmitDifference - Emit the difference between two labels. Some
|
|
|
|
/// assemblers do not behave with absolute expressions with data directives,
|
|
|
|
/// so there is an option (needsSet) to use an intermediary set expression.
|
2006-01-20 20:34:06 +00:00
|
|
|
void EmitDifference(DWLabel LabelHi, DWLabel LabelLo) const {
|
|
|
|
EmitDifference(LabelHi.Tag, LabelHi.Number, LabelLo.Tag, LabelLo.Number);
|
2006-01-17 17:31:53 +00:00
|
|
|
}
|
2006-01-20 20:34:06 +00:00
|
|
|
void EmitDifference(const char *TagHi, unsigned NumberHi,
|
|
|
|
const char *TagLo, unsigned NumberLo) const;
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
/// NewAbbreviation - Add the abbreviation to the Abbreviation vector.
|
2006-01-17 17:31:53 +00:00
|
|
|
///
|
2006-01-20 20:34:06 +00:00
|
|
|
unsigned NewAbbreviation(DIEAbbrev *Abbrev);
|
|
|
|
|
|
|
|
/// NewString - Add a string to the constant pool and returns a label.
|
|
|
|
///
|
|
|
|
DWLabel NewString(const std::string &String);
|
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// NewBasicType - Creates a new basic type if necessary, then adds to the
|
|
|
|
/// owner.
|
|
|
|
/// FIXME - Should never be needed.
|
|
|
|
DIE *NewBasicType(DIE *Owner, Type *Ty);
|
|
|
|
|
2006-01-20 20:34:06 +00:00
|
|
|
/// NewGlobalType - Make the type visible globally using the given name.
|
|
|
|
///
|
|
|
|
void NewGlobalType(const std::string &Name, DIE *Type);
|
|
|
|
|
|
|
|
/// NewGlobalEntity - Make the entity visible globally using the given name.
|
|
|
|
///
|
|
|
|
void NewGlobalEntity(const std::string &Name, DIE *Entity);
|
2006-02-22 19:02:11 +00:00
|
|
|
|
|
|
|
private:
|
2006-02-23 16:58:18 +00:00
|
|
|
|
|
|
|
/// NewType - Create a new type DIE.
|
|
|
|
///
|
|
|
|
DIE *NewType(DIE *Unit, TypeDesc *TyDesc);
|
|
|
|
|
|
|
|
/// NewCompileUnit - Create new compile unit DIE.
|
|
|
|
///
|
|
|
|
DIE *NewCompileUnit(CompileUnitDesc *CompileUnit);
|
2006-01-24 00:49:18 +00:00
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// NewGlobalVariable - Make a new global variable DIE.
|
2006-01-24 00:49:18 +00:00
|
|
|
///
|
2006-02-22 19:02:11 +00:00
|
|
|
DIE *NewGlobalVariable(GlobalVariableDesc *GVD);
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// NewSubprogram - Add a new subprogram DIE.
|
|
|
|
///
|
|
|
|
DIE *NewSubprogram(SubprogramDesc *SPD);
|
2006-01-26 21:22:49 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitInitial - Emit initial Dwarf declarations.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
void EmitInitial() const;
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitDIE - Recusively Emits a debug information entry.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
void EmitDIE(DIE *Die) const;
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// SizeAndOffsetDie - Compute the size and offset of a DIE.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-02-22 19:02:11 +00:00
|
|
|
unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset);
|
2006-01-17 17:31:53 +00:00
|
|
|
|
|
|
|
/// SizeAndOffsets - Compute the size and offset of all the DIEs.
|
|
|
|
///
|
|
|
|
void SizeAndOffsets();
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EmitDebugInfo - Emit the debug info section.
|
|
|
|
///
|
|
|
|
void EmitDebugInfo() const;
|
|
|
|
|
|
|
|
/// EmitAbbreviations - Emit the abbreviation section.
|
|
|
|
///
|
|
|
|
void EmitAbbreviations() const;
|
|
|
|
|
|
|
|
/// EmitDebugLines - Emit source line information.
|
|
|
|
///
|
|
|
|
void EmitDebugLines() const;
|
|
|
|
|
2006-01-17 20:41:40 +00:00
|
|
|
/// EmitDebugFrame - Emit info into a debug frame section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugFrame();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugPubNames - Emit info into a debug pubnames section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugPubNames();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugPubTypes - Emit info into a debug pubtypes section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugPubTypes();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugStr - Emit info into a debug str section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugStr();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugLoc - Emit info into a debug loc section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugLoc();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugARanges - Emit info into a debug aranges section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugARanges();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugRanges - Emit info into a debug ranges section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugRanges();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
|
|
|
/// EmitDebugMacInfo - Emit info into a debug macinfo section.
|
|
|
|
///
|
2006-01-17 21:39:39 +00:00
|
|
|
void EmitDebugMacInfo();
|
2006-01-17 20:41:40 +00:00
|
|
|
|
2006-01-24 00:49:18 +00:00
|
|
|
/// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
|
|
|
|
/// header file.
|
|
|
|
void ConstructCompileUnitDIEs();
|
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// ConstructGlobalDIEs - Create DIEs for each of the externally visible
|
|
|
|
/// global variables.
|
2006-01-24 00:49:18 +00:00
|
|
|
void ConstructGlobalDIEs(Module &M);
|
|
|
|
|
2006-02-22 19:02:11 +00:00
|
|
|
/// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
|
|
|
|
/// subprograms.
|
|
|
|
void ConstructSubprogramDIEs(Module &M);
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
|
2006-01-05 01:25:28 +00:00
|
|
|
/// When called it also checks to see if debug info is newly available. if
|
2006-01-17 17:31:53 +00:00
|
|
|
/// so the initial Dwarf headers are emitted.
|
2006-01-04 22:28:25 +00:00
|
|
|
bool ShouldEmitDwarf();
|
2006-01-24 00:49:18 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
public:
|
|
|
|
|
2006-01-24 00:49:18 +00:00
|
|
|
DwarfWriter(std::ostream &OS, AsmPrinter *A);
|
2006-01-17 17:31:53 +00:00
|
|
|
virtual ~DwarfWriter();
|
|
|
|
|
|
|
|
/// SetDebugInfo - Set DebugInfo when it's known that pass manager has
|
|
|
|
/// created it. Set by the target AsmPrinter.
|
2006-01-24 00:49:18 +00:00
|
|
|
void SetDebugInfo(MachineDebugInfo *DI) { DebugInfo = DI; }
|
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
2006-01-20 20:34:06 +00:00
|
|
|
// Main entry points.
|
2006-01-17 17:31:53 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
/// BeginModule - Emit all Dwarf sections that should come prior to the
|
2006-01-04 22:28:25 +00:00
|
|
|
/// content.
|
2006-01-24 00:49:18 +00:00
|
|
|
void BeginModule(Module &M);
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-17 17:31:53 +00:00
|
|
|
/// EndModule - Emit all Dwarf sections that should come after the content.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-01-24 00:49:18 +00:00
|
|
|
void EndModule(Module &M);
|
2006-01-04 13:52:30 +00:00
|
|
|
|
2006-01-18 16:54:26 +00:00
|
|
|
/// BeginFunction - Gather pre-function debug information.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-01-24 00:49:18 +00:00
|
|
|
void BeginFunction(MachineFunction &MF);
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-01-18 16:54:26 +00:00
|
|
|
/// EndFunction - Gather and emit post-function debug information.
|
2006-01-04 22:28:25 +00:00
|
|
|
///
|
2006-01-24 00:49:18 +00:00
|
|
|
void EndFunction(MachineFunction &MF);
|
2006-01-04 13:52:30 +00:00
|
|
|
};
|
2005-12-21 19:44:40 +00:00
|
|
|
|
2005-12-21 19:46:32 +00:00
|
|
|
} // end llvm namespace
|
2005-12-21 19:44:40 +00:00
|
|
|
|
2005-12-22 01:40:06 +00:00
|
|
|
#endif
|