2010-07-28 20:55:35 +00:00
|
|
|
//===- MCDwarf.h - Machine Code Dwarf support -------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the MCDwarfFile to support the dwarf
|
2010-09-30 17:16:09 +00:00
|
|
|
// .file directive and the .loc directive.
|
2010-07-28 20:55:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCDWARF_H
|
|
|
|
#define LLVM_MC_MCDWARF_H
|
|
|
|
|
2014-03-18 02:13:23 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-03-12 22:28:56 +00:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2015-01-14 11:23:27 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-08-29 06:28:46 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-02-05 21:52:47 +00:00
|
|
|
#include <map>
|
2014-03-13 19:05:33 +00:00
|
|
|
#include <string>
|
2014-03-13 21:47:12 +00:00
|
|
|
#include <utility>
|
2015-01-14 11:23:27 +00:00
|
|
|
#include <vector>
|
2010-07-28 20:55:35 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2013-09-09 19:48:37 +00:00
|
|
|
class MCAsmBackend;
|
2013-09-03 22:16:52 +00:00
|
|
|
class MCContext;
|
2014-05-12 14:28:48 +00:00
|
|
|
class MCObjectStreamer;
|
2013-09-03 22:16:52 +00:00
|
|
|
class MCSection;
|
|
|
|
class MCStreamer;
|
|
|
|
class MCSymbol;
|
|
|
|
class SourceMgr;
|
|
|
|
class SMLoc;
|
|
|
|
|
|
|
|
/// MCDwarfFile - Instances of this class represent the name of the dwarf
|
|
|
|
/// .file directive and its associated dwarf file number in the MC file,
|
|
|
|
/// and MCDwarfFile's are created and unique'd by the MCContext class where
|
|
|
|
/// the file number for each is its index into the vector of DwarfFiles (note
|
|
|
|
/// index 0 is not used and not a valid dwarf file number).
|
2014-03-13 18:21:24 +00:00
|
|
|
struct MCDwarfFile {
|
2013-09-03 22:16:52 +00:00
|
|
|
// Name - the base name of the file without its directory path.
|
|
|
|
// The StringRef references memory allocated in the MCContext.
|
2014-03-13 18:55:04 +00:00
|
|
|
std::string Name;
|
2013-09-03 22:16:52 +00:00
|
|
|
|
|
|
|
// DirIndex - the index into the list of directory names for this file name.
|
|
|
|
unsigned DirIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// MCDwarfLoc - Instances of this class represent the information from a
|
|
|
|
/// dwarf .loc directive.
|
|
|
|
class MCDwarfLoc {
|
|
|
|
// FileNum - the file number.
|
|
|
|
unsigned FileNum;
|
|
|
|
// Line - the line number.
|
|
|
|
unsigned Line;
|
|
|
|
// Column - the column position.
|
|
|
|
unsigned Column;
|
|
|
|
// Flags (see #define's below)
|
|
|
|
unsigned Flags;
|
|
|
|
// Isa
|
|
|
|
unsigned Isa;
|
|
|
|
// Discriminator
|
|
|
|
unsigned Discriminator;
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2010-09-30 17:16:09 +00:00
|
|
|
// Flag that indicates the initial value of the is_stmt_start flag.
|
2013-09-03 22:16:52 +00:00
|
|
|
#define DWARF2_LINE_DEFAULT_IS_STMT 1
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
#define DWARF2_FLAG_IS_STMT (1 << 0)
|
|
|
|
#define DWARF2_FLAG_BASIC_BLOCK (1 << 1)
|
|
|
|
#define DWARF2_FLAG_PROLOGUE_END (1 << 2)
|
2010-08-24 20:32:42 +00:00
|
|
|
#define DWARF2_FLAG_EPILOGUE_BEGIN (1 << 3)
|
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
private: // MCContext manages these
|
|
|
|
friend class MCContext;
|
|
|
|
friend class MCLineEntry;
|
|
|
|
MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
|
|
|
|
unsigned isa, unsigned discriminator)
|
2010-11-13 03:18:27 +00:00
|
|
|
: FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa),
|
|
|
|
Discriminator(discriminator) {}
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
// Allow the default copy constructor and assignment operator to be used
|
|
|
|
// for an MCDwarfLoc object.
|
2010-08-31 22:55:11 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
public:
|
|
|
|
/// getFileNum - Get the FileNum of this MCDwarfLoc.
|
|
|
|
unsigned getFileNum() const { return FileNum; }
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// getLine - Get the Line of this MCDwarfLoc.
|
|
|
|
unsigned getLine() const { return Line; }
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// getColumn - Get the Column of this MCDwarfLoc.
|
|
|
|
unsigned getColumn() const { return Column; }
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// getFlags - Get the Flags of this MCDwarfLoc.
|
|
|
|
unsigned getFlags() const { return Flags; }
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// getIsa - Get the Isa of this MCDwarfLoc.
|
|
|
|
unsigned getIsa() const { return Isa; }
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// getDiscriminator - Get the Discriminator of this MCDwarfLoc.
|
|
|
|
unsigned getDiscriminator() const { return Discriminator; }
|
2010-11-13 03:18:27 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setFileNum - Set the FileNum of this MCDwarfLoc.
|
|
|
|
void setFileNum(unsigned fileNum) { FileNum = fileNum; }
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setLine - Set the Line of this MCDwarfLoc.
|
|
|
|
void setLine(unsigned line) { Line = line; }
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setColumn - Set the Column of this MCDwarfLoc.
|
|
|
|
void setColumn(unsigned column) { Column = column; }
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setFlags - Set the Flags of this MCDwarfLoc.
|
|
|
|
void setFlags(unsigned flags) { Flags = flags; }
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setIsa - Set the Isa of this MCDwarfLoc.
|
|
|
|
void setIsa(unsigned isa) { Isa = isa; }
|
2010-11-13 03:18:27 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// setDiscriminator - Set the Discriminator of this MCDwarfLoc.
|
|
|
|
void setDiscriminator(unsigned discriminator) {
|
|
|
|
Discriminator = discriminator;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// MCLineEntry - Instances of this class represent the line information for
|
|
|
|
/// the dwarf line table entries. Which is created after a machine
|
|
|
|
/// instruction is assembled and uses an address from a temporary label
|
|
|
|
/// created at the current address in the current section and the info from
|
|
|
|
/// the last .loc directive seen as stored in the context.
|
|
|
|
class MCLineEntry : public MCDwarfLoc {
|
|
|
|
MCSymbol *Label;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Allow the default copy constructor and assignment operator to be used
|
|
|
|
// for an MCLineEntry object.
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Constructor to create an MCLineEntry given a symbol and the dwarf loc.
|
|
|
|
MCLineEntry(MCSymbol *label, const MCDwarfLoc loc)
|
|
|
|
: MCDwarfLoc(loc), Label(label) {}
|
|
|
|
|
|
|
|
MCSymbol *getLabel() const { return Label; }
|
|
|
|
|
|
|
|
// This is called when an instruction is assembled into the specified
|
|
|
|
// section and if there is information from the last .loc directive that
|
|
|
|
// has yet to have a line entry made for it is made.
|
2014-05-12 14:28:48 +00:00
|
|
|
static void Make(MCObjectStreamer *MCOS, const MCSection *Section);
|
2013-09-03 22:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// MCLineSection - Instances of this class represent the line information
|
2014-03-12 22:28:56 +00:00
|
|
|
/// for a compile unit where machine instructions have been assembled after seeing
|
2013-09-03 22:16:52 +00:00
|
|
|
/// .loc directives. This is the information used to build the dwarf line
|
|
|
|
/// table for a section.
|
|
|
|
class MCLineSection {
|
|
|
|
public:
|
|
|
|
// addLineEntry - adds an entry to this MCLineSection's line entries
|
2014-03-12 22:28:56 +00:00
|
|
|
void addLineEntry(const MCLineEntry &LineEntry, const MCSection *Sec) {
|
|
|
|
MCLineDivisions[Sec].push_back(LineEntry);
|
2013-09-03 22:16:52 +00:00
|
|
|
}
|
2010-08-24 20:32:42 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
typedef std::vector<MCLineEntry> MCLineEntryCollection;
|
|
|
|
typedef MCLineEntryCollection::iterator iterator;
|
|
|
|
typedef MCLineEntryCollection::const_iterator const_iterator;
|
2014-03-12 22:28:56 +00:00
|
|
|
typedef MapVector<const MCSection *, MCLineEntryCollection> MCLineDivisionMap;
|
2013-09-03 22:16:52 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-12 22:28:56 +00:00
|
|
|
// A collection of MCLineEntry for each section.
|
2013-09-03 22:16:52 +00:00
|
|
|
MCLineDivisionMap MCLineDivisions;
|
2010-08-31 22:55:11 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
public:
|
|
|
|
// Returns the collection of MCLineEntry for a given Compile Unit ID.
|
2014-03-12 22:28:56 +00:00
|
|
|
const MCLineDivisionMap &getMCLineEntries() const {
|
|
|
|
return MCLineDivisions;
|
2013-09-03 22:16:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-13 21:47:12 +00:00
|
|
|
struct MCDwarfLineTableHeader {
|
2014-03-13 17:55:28 +00:00
|
|
|
MCSymbol *Label;
|
2014-03-13 19:05:33 +00:00
|
|
|
SmallVector<std::string, 3> MCDwarfDirs;
|
2014-03-13 18:55:04 +00:00
|
|
|
SmallVector<MCDwarfFile, 3> MCDwarfFiles;
|
2014-03-17 01:52:11 +00:00
|
|
|
StringMap<unsigned> SourceIdMap;
|
2014-03-17 23:29:40 +00:00
|
|
|
StringRef CompilationDir;
|
|
|
|
|
2014-03-14 20:36:44 +00:00
|
|
|
MCDwarfLineTableHeader() : Label(nullptr) {}
|
2014-03-17 18:13:58 +00:00
|
|
|
unsigned getFile(StringRef &Directory, StringRef &FileName,
|
|
|
|
unsigned FileNumber = 0);
|
2014-03-13 21:47:12 +00:00
|
|
|
std::pair<MCSymbol *, MCSymbol *> Emit(MCStreamer *MCOS) const;
|
2014-03-18 02:13:23 +00:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
|
|
|
Emit(MCStreamer *MCOS, ArrayRef<char> SpecialOpcodeLengths) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfDwoLineTable {
|
|
|
|
MCDwarfLineTableHeader Header;
|
|
|
|
public:
|
2014-03-19 00:11:28 +00:00
|
|
|
void setCompilationDir(StringRef CompilationDir) {
|
|
|
|
Header.CompilationDir = CompilationDir;
|
|
|
|
}
|
2014-03-18 02:13:23 +00:00
|
|
|
unsigned getFile(StringRef Directory, StringRef FileName) {
|
|
|
|
return Header.getFile(Directory, FileName);
|
|
|
|
}
|
|
|
|
void Emit(MCStreamer &MCOS) const;
|
2014-03-13 21:47:12 +00:00
|
|
|
};
|
|
|
|
|
2014-03-13 21:59:51 +00:00
|
|
|
class MCDwarfLineTable {
|
2014-03-13 21:47:12 +00:00
|
|
|
MCDwarfLineTableHeader Header;
|
2014-03-13 17:55:28 +00:00
|
|
|
MCLineSection MCLineSections;
|
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
public:
|
|
|
|
// This emits the Dwarf file and the line tables for all Compile Units.
|
2014-05-12 14:28:48 +00:00
|
|
|
static void Emit(MCObjectStreamer *MCOS);
|
2014-03-13 21:47:12 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
// This emits the Dwarf file and the line tables for a given Compile Unit.
|
2014-05-12 14:28:48 +00:00
|
|
|
void EmitCU(MCObjectStreamer *MCOS) const;
|
2014-03-13 17:55:28 +00:00
|
|
|
|
2014-03-17 18:13:58 +00:00
|
|
|
unsigned getFile(StringRef &Directory, StringRef &FileName,
|
|
|
|
unsigned FileNumber = 0);
|
2014-03-13 19:15:04 +00:00
|
|
|
|
2014-03-13 21:47:12 +00:00
|
|
|
MCSymbol *getLabel() const {
|
|
|
|
return Header.Label;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLabel(MCSymbol *Label) {
|
|
|
|
Header.Label = Label;
|
|
|
|
}
|
|
|
|
|
2014-03-17 23:29:40 +00:00
|
|
|
void setCompilationDir(StringRef CompilationDir) {
|
|
|
|
Header.CompilationDir = CompilationDir;
|
|
|
|
}
|
|
|
|
|
2014-03-13 19:05:33 +00:00
|
|
|
const SmallVectorImpl<std::string> &getMCDwarfDirs() const {
|
2014-03-13 21:47:12 +00:00
|
|
|
return Header.MCDwarfDirs;
|
2014-03-13 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 19:05:33 +00:00
|
|
|
SmallVectorImpl<std::string> &getMCDwarfDirs() {
|
2014-03-13 21:47:12 +00:00
|
|
|
return Header.MCDwarfDirs;
|
2014-03-13 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:55:04 +00:00
|
|
|
const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() const {
|
2014-03-13 21:47:12 +00:00
|
|
|
return Header.MCDwarfFiles;
|
2014-03-13 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:55:04 +00:00
|
|
|
SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() {
|
2014-03-13 21:47:12 +00:00
|
|
|
return Header.MCDwarfFiles;
|
2014-03-13 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MCLineSection &getMCLineSections() const {
|
|
|
|
return MCLineSections;
|
|
|
|
}
|
|
|
|
MCLineSection &getMCLineSections() {
|
|
|
|
return MCLineSections;
|
|
|
|
}
|
2013-09-03 22:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfLineAddr {
|
|
|
|
public:
|
|
|
|
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
|
|
|
|
static void Encode(MCContext &Context, int64_t LineDelta, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS);
|
|
|
|
|
|
|
|
/// Utility function to emit the encoding to a streamer.
|
|
|
|
static void Emit(MCStreamer *MCOS, int64_t LineDelta, uint64_t AddrDelta);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MCGenDwarfInfo {
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// When generating dwarf for assembly source files this emits the Dwarf
|
|
|
|
// sections.
|
|
|
|
//
|
2014-04-01 07:35:52 +00:00
|
|
|
static void Emit(MCStreamer *MCOS);
|
2013-09-03 22:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// When generating dwarf for assembly source files this is the info that is
|
|
|
|
// needed to be gathered for each symbol that will have a dwarf label.
|
|
|
|
class MCGenDwarfLabelEntry {
|
|
|
|
private:
|
|
|
|
// Name of the symbol without a leading underbar, if any.
|
|
|
|
StringRef Name;
|
|
|
|
// The dwarf file number this symbol is in.
|
|
|
|
unsigned FileNumber;
|
|
|
|
// The line number this symbol is at.
|
|
|
|
unsigned LineNumber;
|
|
|
|
// The low_pc for the dwarf label is taken from this symbol.
|
|
|
|
MCSymbol *Label;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber,
|
|
|
|
MCSymbol *label)
|
|
|
|
: Name(name), FileNumber(fileNumber), LineNumber(lineNumber),
|
|
|
|
Label(label) {}
|
|
|
|
|
|
|
|
StringRef getName() const { return Name; }
|
|
|
|
unsigned getFileNumber() const { return FileNumber; }
|
|
|
|
unsigned getLineNumber() const { return LineNumber; }
|
|
|
|
MCSymbol *getLabel() const { return Label; }
|
|
|
|
|
|
|
|
// This is called when label is created when we are generating dwarf for
|
|
|
|
// assembly source files.
|
|
|
|
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr,
|
|
|
|
SMLoc &Loc);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MCCFIInstruction {
|
|
|
|
public:
|
|
|
|
enum OpType {
|
|
|
|
OpSameValue,
|
|
|
|
OpRememberState,
|
|
|
|
OpRestoreState,
|
|
|
|
OpOffset,
|
|
|
|
OpDefCfaRegister,
|
|
|
|
OpDefCfaOffset,
|
|
|
|
OpDefCfa,
|
|
|
|
OpRelOffset,
|
|
|
|
OpAdjustCfaOffset,
|
|
|
|
OpEscape,
|
|
|
|
OpRestore,
|
|
|
|
OpUndefined,
|
2013-09-26 14:49:40 +00:00
|
|
|
OpRegister,
|
|
|
|
OpWindowSave
|
2010-09-30 17:16:09 +00:00
|
|
|
};
|
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
private:
|
|
|
|
OpType Operation;
|
|
|
|
MCSymbol *Label;
|
|
|
|
unsigned Register;
|
|
|
|
union {
|
|
|
|
int Offset;
|
|
|
|
unsigned Register2;
|
2010-08-31 22:55:11 +00:00
|
|
|
};
|
2013-09-03 22:16:52 +00:00
|
|
|
std::vector<char> Values;
|
2010-08-31 22:55:11 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, StringRef V)
|
|
|
|
: Operation(Op), Label(L), Register(R), Offset(O),
|
|
|
|
Values(V.begin(), V.end()) {
|
|
|
|
assert(Op != OpRegister);
|
|
|
|
}
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2)
|
|
|
|
: Operation(Op), Label(L), Register(R1), Register2(R2) {
|
|
|
|
assert(Op == OpRegister);
|
|
|
|
}
|
2010-12-10 07:39:47 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
public:
|
|
|
|
/// \brief .cfi_def_cfa defines a rule for computing CFA as: take address from
|
2013-09-04 18:48:12 +00:00
|
|
|
/// Register and add Offset to it.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpDefCfa, L, Register, -Offset, "");
|
|
|
|
}
|
2011-12-09 18:09:40 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// \brief .cfi_def_cfa_register modifies a rule for computing CFA. From now
|
2013-09-04 18:48:12 +00:00
|
|
|
/// on Register will be used instead of the old one. Offset remains the same.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpDefCfaRegister, L, Register, 0, "");
|
|
|
|
}
|
2011-12-09 18:09:40 +00:00
|
|
|
|
2013-09-03 22:16:52 +00:00
|
|
|
/// \brief .cfi_def_cfa_offset modifies a rule for computing CFA. Register
|
|
|
|
/// remains the same, but offset is new. Note that it is the absolute offset
|
|
|
|
/// that will be added to a defined register to the compute CFA address.
|
|
|
|
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset) {
|
|
|
|
return MCCFIInstruction(OpDefCfaOffset, L, 0, -Offset, "");
|
|
|
|
}
|
2010-12-28 18:36:23 +00:00
|
|
|
|
2013-09-04 02:10:32 +00:00
|
|
|
/// \brief .cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but
|
2013-09-03 22:16:52 +00:00
|
|
|
/// Offset is a relative value that is added/subtracted from the previous
|
|
|
|
/// offset.
|
|
|
|
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment) {
|
|
|
|
return MCCFIInstruction(OpAdjustCfaOffset, L, 0, Adjustment, "");
|
|
|
|
}
|
2010-12-10 07:39:47 +00:00
|
|
|
|
2013-09-04 18:48:12 +00:00
|
|
|
/// \brief .cfi_offset Previous value of Register is saved at offset Offset
|
|
|
|
/// from CFA.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpOffset, L, Register, Offset, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:48:12 +00:00
|
|
|
/// \brief .cfi_rel_offset Previous value of Register is saved at offset
|
|
|
|
/// Offset from the current CFA register. This is transformed to .cfi_offset
|
|
|
|
/// using the known displacement of the CFA register from the CFA.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpRelOffset, L, Register, Offset, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 02:10:32 +00:00
|
|
|
/// \brief .cfi_register Previous value of Register1 is saved in
|
|
|
|
/// register Register2.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1,
|
|
|
|
unsigned Register2) {
|
|
|
|
return MCCFIInstruction(OpRegister, L, Register1, Register2);
|
|
|
|
}
|
|
|
|
|
2013-09-26 14:49:40 +00:00
|
|
|
/// \brief .cfi_window_save SPARC register window is saved.
|
|
|
|
static MCCFIInstruction createWindowSave(MCSymbol *L) {
|
|
|
|
return MCCFIInstruction(OpWindowSave, L, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:48:12 +00:00
|
|
|
/// \brief .cfi_restore says that the rule for Register is now the same as it
|
|
|
|
/// was at the beginning of the function, after all initial instructions added
|
|
|
|
/// by .cfi_startproc were executed.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpRestore, L, Register, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:48:12 +00:00
|
|
|
/// \brief .cfi_undefined From now on the previous value of Register can't be
|
|
|
|
/// restored anymore.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpUndefined, L, Register, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:48:12 +00:00
|
|
|
/// \brief .cfi_same_value Current value of Register is the same as in the
|
|
|
|
/// previous frame. I.e., no restoration is needed.
|
2013-09-03 22:16:52 +00:00
|
|
|
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpSameValue, L, Register, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief .cfi_remember_state Save all current rules for all registers.
|
|
|
|
static MCCFIInstruction createRememberState(MCSymbol *L) {
|
|
|
|
return MCCFIInstruction(OpRememberState, L, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief .cfi_restore_state Restore the previously saved state.
|
|
|
|
static MCCFIInstruction createRestoreState(MCSymbol *L) {
|
|
|
|
return MCCFIInstruction(OpRestoreState, L, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief .cfi_escape Allows the user to add arbitrary bytes to the unwind
|
|
|
|
/// info.
|
|
|
|
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals) {
|
|
|
|
return MCCFIInstruction(OpEscape, L, 0, 0, Vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
OpType getOperation() const { return Operation; }
|
|
|
|
MCSymbol *getLabel() const { return Label; }
|
|
|
|
|
|
|
|
unsigned getRegister() const {
|
|
|
|
assert(Operation == OpDefCfa || Operation == OpOffset ||
|
|
|
|
Operation == OpRestore || Operation == OpUndefined ||
|
|
|
|
Operation == OpSameValue || Operation == OpDefCfaRegister ||
|
|
|
|
Operation == OpRelOffset || Operation == OpRegister);
|
|
|
|
return Register;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getRegister2() const {
|
|
|
|
assert(Operation == OpRegister);
|
|
|
|
return Register2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getOffset() const {
|
|
|
|
assert(Operation == OpDefCfa || Operation == OpOffset ||
|
|
|
|
Operation == OpRelOffset || Operation == OpDefCfaOffset ||
|
|
|
|
Operation == OpAdjustCfaOffset);
|
|
|
|
return Offset;
|
|
|
|
}
|
|
|
|
|
2014-08-30 16:48:02 +00:00
|
|
|
StringRef getValues() const {
|
2013-09-03 22:16:52 +00:00
|
|
|
assert(Operation == OpEscape);
|
|
|
|
return StringRef(&Values[0], Values.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MCDwarfFrameInfo {
|
|
|
|
MCDwarfFrameInfo()
|
2014-06-23 15:17:34 +00:00
|
|
|
: Begin(nullptr), End(nullptr), Personality(nullptr), Lsda(nullptr),
|
2014-10-07 11:03:09 +00:00
|
|
|
Instructions(), CurrentCfaRegister(0), PersonalityEncoding(),
|
|
|
|
LsdaEncoding(0), CompactUnwindEncoding(0), IsSignalFrame(false),
|
|
|
|
IsSimple(false) {}
|
2013-09-03 22:16:52 +00:00
|
|
|
MCSymbol *Begin;
|
|
|
|
MCSymbol *End;
|
|
|
|
const MCSymbol *Personality;
|
|
|
|
const MCSymbol *Lsda;
|
|
|
|
std::vector<MCCFIInstruction> Instructions;
|
2014-10-07 11:03:09 +00:00
|
|
|
unsigned CurrentCfaRegister;
|
2013-09-03 22:16:52 +00:00
|
|
|
unsigned PersonalityEncoding;
|
|
|
|
unsigned LsdaEncoding;
|
|
|
|
uint32_t CompactUnwindEncoding;
|
|
|
|
bool IsSignalFrame;
|
2014-01-27 17:20:25 +00:00
|
|
|
bool IsSimple;
|
2013-09-03 22:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfFrameEmitter {
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// This emits the frame info section.
|
|
|
|
//
|
2014-05-12 14:28:48 +00:00
|
|
|
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH);
|
|
|
|
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta);
|
2013-09-03 22:16:52 +00:00
|
|
|
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS);
|
|
|
|
};
|
2010-07-28 20:55:35 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|