2010-07-28 22:55:35 +02: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 19:16:09 +02:00
|
|
|
// .file directive and the .loc directive.
|
2010-07-28 22:55:35 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCDWARF_H
|
|
|
|
#define LLVM_MC_MCDWARF_H
|
|
|
|
|
2014-03-12 23:28:56 +01:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-12-29 10:06:16 +01:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2014-03-13 20:05:33 +01:00
|
|
|
#include <string>
|
2014-03-13 22:47:12 +01:00
|
|
|
#include <utility>
|
2015-01-14 12:23:27 +01:00
|
|
|
#include <vector>
|
2010-07-28 22:55:35 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2016-04-18 11:17:29 +02:00
|
|
|
template <typename T> class ArrayRef;
|
2013-09-09 21:48:37 +02:00
|
|
|
class MCAsmBackend;
|
2013-09-04 00:16:52 +02:00
|
|
|
class MCContext;
|
2014-05-12 16:28:48 +02:00
|
|
|
class MCObjectStreamer;
|
2013-09-04 00:16:52 +02:00
|
|
|
class MCStreamer;
|
|
|
|
class MCSymbol;
|
2017-02-14 01:33:36 +01:00
|
|
|
class raw_ostream;
|
2013-09-04 00:16:52 +02:00
|
|
|
class SMLoc;
|
2017-02-14 01:33:36 +01:00
|
|
|
class SourceMgr;
|
2013-09-04 00:16:52 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Instances of this class represent the name of the dwarf
|
2013-09-04 00:16:52 +02:00
|
|
|
/// .file directive and its associated dwarf file number in the MC file,
|
2015-05-02 02:44:07 +02:00
|
|
|
/// and MCDwarfFile's are created and uniqued by the MCContext class where
|
2013-09-04 00:16:52 +02:00
|
|
|
/// 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 19:21:24 +01:00
|
|
|
struct MCDwarfFile {
|
2015-05-02 02:44:14 +02:00
|
|
|
// \brief The base name of the file without its directory path.
|
2013-09-04 00:16:52 +02:00
|
|
|
// The StringRef references memory allocated in the MCContext.
|
2014-03-13 19:55:04 +01:00
|
|
|
std::string Name;
|
2013-09-04 00:16:52 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
// \brief The index into the list of directory names for this file name.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned DirIndex;
|
|
|
|
};
|
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Instances of this class represent the information from a
|
2013-09-04 00:16:52 +02:00
|
|
|
/// dwarf .loc directive.
|
|
|
|
class MCDwarfLoc {
|
2015-07-11 01:55:34 +02:00
|
|
|
uint32_t FileNum;
|
|
|
|
uint32_t Line;
|
|
|
|
uint16_t Column;
|
2013-09-04 00:16:52 +02:00
|
|
|
// Flags (see #define's below)
|
2015-07-11 01:55:34 +02:00
|
|
|
uint8_t Flags;
|
|
|
|
uint8_t Isa;
|
|
|
|
uint32_t Discriminator;
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2010-09-30 19:16:09 +02:00
|
|
|
// Flag that indicates the initial value of the is_stmt_start flag.
|
2013-09-04 00:16:52 +02:00
|
|
|
#define DWARF2_LINE_DEFAULT_IS_STMT 1
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2013-09-04 00:16:52 +02: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 22:32:42 +02:00
|
|
|
#define DWARF2_FLAG_EPILOGUE_BEGIN (1 << 3)
|
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
private: // MCContext manages these
|
|
|
|
friend class MCContext;
|
2016-01-21 02:59:03 +01:00
|
|
|
friend class MCDwarfLineEntry;
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
|
|
|
|
unsigned isa, unsigned discriminator)
|
2010-11-13 04:18:27 +01:00
|
|
|
: FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa),
|
|
|
|
Discriminator(discriminator) {}
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
// Allow the default copy constructor and assignment operator to be used
|
|
|
|
// for an MCDwarfLoc object.
|
2010-09-01 00:55:11 +02:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
public:
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the FileNum of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getFileNum() const { return FileNum; }
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the Line of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getLine() const { return Line; }
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the Column of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getColumn() const { return Column; }
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the Flags of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getFlags() const { return Flags; }
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the Isa of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getIsa() const { return Isa; }
|
2010-09-30 19:16:09 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Get the Discriminator of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
unsigned getDiscriminator() const { return Discriminator; }
|
2010-11-13 04:18:27 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the FileNum of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
void setFileNum(unsigned fileNum) { FileNum = fileNum; }
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the Line of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
void setLine(unsigned line) { Line = line; }
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the Column of this MCDwarfLoc.
|
2015-07-11 01:55:34 +02:00
|
|
|
void setColumn(unsigned column) {
|
|
|
|
assert(column <= UINT16_MAX);
|
|
|
|
Column = column;
|
|
|
|
}
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the Flags of this MCDwarfLoc.
|
2015-07-11 01:55:34 +02:00
|
|
|
void setFlags(unsigned flags) {
|
|
|
|
assert(flags <= UINT8_MAX);
|
|
|
|
Flags = flags;
|
|
|
|
}
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the Isa of this MCDwarfLoc.
|
2015-07-11 01:55:34 +02:00
|
|
|
void setIsa(unsigned isa) {
|
|
|
|
assert(isa <= UINT8_MAX);
|
|
|
|
Isa = isa;
|
|
|
|
}
|
2010-11-13 04:18:27 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Set the Discriminator of this MCDwarfLoc.
|
2013-09-04 00:16:52 +02:00
|
|
|
void setDiscriminator(unsigned discriminator) {
|
|
|
|
Discriminator = discriminator;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Instances of this class represent the line information for
|
2013-09-04 00:16:52 +02:00
|
|
|
/// 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.
|
2016-01-21 02:59:03 +01:00
|
|
|
class MCDwarfLineEntry : public MCDwarfLoc {
|
2013-09-04 00:16:52 +02:00
|
|
|
MCSymbol *Label;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Allow the default copy constructor and assignment operator to be used
|
2016-01-21 02:59:03 +01:00
|
|
|
// for an MCDwarfLineEntry object.
|
2013-09-04 00:16:52 +02:00
|
|
|
|
|
|
|
public:
|
2016-01-21 02:59:03 +01:00
|
|
|
// Constructor to create an MCDwarfLineEntry given a symbol and the dwarf loc.
|
|
|
|
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc)
|
2013-09-04 00:16:52 +02:00
|
|
|
: 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.
|
2015-05-21 21:20:38 +02:00
|
|
|
static void Make(MCObjectStreamer *MCOS, MCSection *Section);
|
2013-09-04 00:16:52 +02:00
|
|
|
};
|
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Instances of this class represent the line information for a compile
|
|
|
|
/// unit where machine instructions have been assembled after seeing .loc
|
|
|
|
/// directives. This is the information used to build the dwarf line
|
2013-09-04 00:16:52 +02:00
|
|
|
/// table for a section.
|
|
|
|
class MCLineSection {
|
|
|
|
public:
|
2015-05-02 02:44:14 +02:00
|
|
|
// \brief Add an entry to this MCLineSection's line entries.
|
2016-01-21 02:59:03 +01:00
|
|
|
void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec) {
|
2014-03-12 23:28:56 +01:00
|
|
|
MCLineDivisions[Sec].push_back(LineEntry);
|
2013-09-04 00:16:52 +02:00
|
|
|
}
|
2010-08-24 22:32:42 +02:00
|
|
|
|
2016-01-21 02:59:03 +01:00
|
|
|
typedef std::vector<MCDwarfLineEntry> MCDwarfLineEntryCollection;
|
|
|
|
typedef MCDwarfLineEntryCollection::iterator iterator;
|
|
|
|
typedef MCDwarfLineEntryCollection::const_iterator const_iterator;
|
|
|
|
typedef MapVector<MCSection *, MCDwarfLineEntryCollection> MCLineDivisionMap;
|
2013-09-04 00:16:52 +02:00
|
|
|
|
|
|
|
private:
|
2016-01-21 02:59:03 +01:00
|
|
|
// A collection of MCDwarfLineEntry for each section.
|
2013-09-04 00:16:52 +02:00
|
|
|
MCLineDivisionMap MCLineDivisions;
|
2010-09-01 00:55:11 +02:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
public:
|
2016-01-21 02:59:03 +01:00
|
|
|
// Returns the collection of MCDwarfLineEntry for a given Compile Unit ID.
|
2014-03-12 23:28:56 +01:00
|
|
|
const MCLineDivisionMap &getMCLineEntries() const {
|
|
|
|
return MCLineDivisions;
|
2013-09-04 00:16:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-07 17:14:08 +02:00
|
|
|
struct MCDwarfLineTableParams {
|
|
|
|
/// First special line opcode - leave room for the standard opcodes.
|
|
|
|
/// Note: If you want to change this, you'll have to update the
|
|
|
|
/// "StandardOpcodeLengths" table that is emitted in
|
|
|
|
/// \c Emit().
|
2015-08-07 21:19:44 +02:00
|
|
|
uint8_t DWARF2LineOpcodeBase = 13;
|
2015-08-07 17:14:08 +02:00
|
|
|
/// Minimum line offset in a special line info. opcode. The value
|
|
|
|
/// -5 was chosen to give a reasonable range of values.
|
2015-08-07 21:19:44 +02:00
|
|
|
int8_t DWARF2LineBase = -5;
|
2015-08-07 17:14:08 +02:00
|
|
|
/// Range of line offsets in a special line info. opcode.
|
2015-08-07 21:19:44 +02:00
|
|
|
uint8_t DWARF2LineRange = 14;
|
2015-08-07 17:14:08 +02:00
|
|
|
};
|
|
|
|
|
2014-03-13 22:47:12 +01:00
|
|
|
struct MCDwarfLineTableHeader {
|
2017-02-14 01:33:36 +01:00
|
|
|
MCSymbol *Label = nullptr;
|
2014-03-13 20:05:33 +01:00
|
|
|
SmallVector<std::string, 3> MCDwarfDirs;
|
2014-03-13 19:55:04 +01:00
|
|
|
SmallVector<MCDwarfFile, 3> MCDwarfFiles;
|
2014-03-17 02:52:11 +01:00
|
|
|
StringMap<unsigned> SourceIdMap;
|
2014-03-18 00:29:40 +01:00
|
|
|
StringRef CompilationDir;
|
|
|
|
|
2017-02-14 01:33:36 +01:00
|
|
|
MCDwarfLineTableHeader() = default;
|
|
|
|
|
2014-03-17 19:13:58 +01:00
|
|
|
unsigned getFile(StringRef &Directory, StringRef &FileName,
|
|
|
|
unsigned FileNumber = 0);
|
2015-08-07 17:14:08 +02:00
|
|
|
std::pair<MCSymbol *, MCSymbol *> Emit(MCStreamer *MCOS,
|
|
|
|
MCDwarfLineTableParams Params) const;
|
2014-03-18 03:13:23 +01:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
2015-08-07 17:14:08 +02:00
|
|
|
Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
ArrayRef<char> SpecialOpcodeLengths) const;
|
2014-03-18 03:13:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfDwoLineTable {
|
|
|
|
MCDwarfLineTableHeader Header;
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2014-03-18 03:13:23 +01:00
|
|
|
public:
|
2014-03-19 01:11:28 +01:00
|
|
|
void setCompilationDir(StringRef CompilationDir) {
|
|
|
|
Header.CompilationDir = CompilationDir;
|
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2014-03-18 03:13:23 +01:00
|
|
|
unsigned getFile(StringRef Directory, StringRef FileName) {
|
|
|
|
return Header.getFile(Directory, FileName);
|
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-08-07 17:14:08 +02:00
|
|
|
void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params) const;
|
2014-03-13 22:47:12 +01:00
|
|
|
};
|
|
|
|
|
2014-03-13 22:59:51 +01:00
|
|
|
class MCDwarfLineTable {
|
2014-03-13 22:47:12 +01:00
|
|
|
MCDwarfLineTableHeader Header;
|
2014-03-13 18:55:28 +01:00
|
|
|
MCLineSection MCLineSections;
|
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
public:
|
|
|
|
// This emits the Dwarf file and the line tables for all Compile Units.
|
2015-08-07 17:14:08 +02:00
|
|
|
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params);
|
2014-03-13 22:47:12 +01:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
// This emits the Dwarf file and the line tables for a given Compile Unit.
|
2015-08-07 17:14:08 +02:00
|
|
|
void EmitCU(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params) const;
|
2014-03-13 18:55:28 +01:00
|
|
|
|
2014-03-17 19:13:58 +01:00
|
|
|
unsigned getFile(StringRef &Directory, StringRef &FileName,
|
|
|
|
unsigned FileNumber = 0);
|
2014-03-13 20:15:04 +01:00
|
|
|
|
2014-03-13 22:47:12 +01:00
|
|
|
MCSymbol *getLabel() const {
|
|
|
|
return Header.Label;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLabel(MCSymbol *Label) {
|
|
|
|
Header.Label = Label;
|
|
|
|
}
|
|
|
|
|
2014-03-18 00:29:40 +01:00
|
|
|
void setCompilationDir(StringRef CompilationDir) {
|
|
|
|
Header.CompilationDir = CompilationDir;
|
|
|
|
}
|
|
|
|
|
2014-03-13 20:05:33 +01:00
|
|
|
const SmallVectorImpl<std::string> &getMCDwarfDirs() const {
|
2014-03-13 22:47:12 +01:00
|
|
|
return Header.MCDwarfDirs;
|
2014-03-13 18:55:28 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 20:05:33 +01:00
|
|
|
SmallVectorImpl<std::string> &getMCDwarfDirs() {
|
2014-03-13 22:47:12 +01:00
|
|
|
return Header.MCDwarfDirs;
|
2014-03-13 18:55:28 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 19:55:04 +01:00
|
|
|
const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() const {
|
2014-03-13 22:47:12 +01:00
|
|
|
return Header.MCDwarfFiles;
|
2014-03-13 18:55:28 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 19:55:04 +01:00
|
|
|
SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() {
|
2014-03-13 22:47:12 +01:00
|
|
|
return Header.MCDwarfFiles;
|
2014-03-13 18:55:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const MCLineSection &getMCLineSections() const {
|
|
|
|
return MCLineSections;
|
|
|
|
}
|
|
|
|
MCLineSection &getMCLineSections() {
|
|
|
|
return MCLineSections;
|
|
|
|
}
|
2013-09-04 00:16:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfLineAddr {
|
|
|
|
public:
|
|
|
|
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
|
2015-08-07 17:14:08 +02:00
|
|
|
static void Encode(MCContext &Context, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS);
|
2013-09-04 00:16:52 +02:00
|
|
|
|
|
|
|
/// Utility function to emit the encoding to a streamer.
|
2015-08-07 17:14:08 +02:00
|
|
|
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta);
|
2013-09-04 00:16:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCGenDwarfInfo {
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// When generating dwarf for assembly source files this emits the Dwarf
|
|
|
|
// sections.
|
|
|
|
//
|
2014-04-01 09:35:52 +02:00
|
|
|
static void Emit(MCStreamer *MCOS);
|
2013-09-04 00:16:52 +02: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 16:49:40 +02:00
|
|
|
OpRegister,
|
2015-10-07 09:01:31 +02:00
|
|
|
OpWindowSave,
|
|
|
|
OpGnuArgsSize
|
2010-09-30 19:16:09 +02:00
|
|
|
};
|
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
private:
|
|
|
|
OpType Operation;
|
|
|
|
MCSymbol *Label;
|
|
|
|
unsigned Register;
|
|
|
|
union {
|
|
|
|
int Offset;
|
|
|
|
unsigned Register2;
|
2010-09-01 00:55:11 +02:00
|
|
|
};
|
2013-09-04 00:16:52 +02:00
|
|
|
std::vector<char> Values;
|
2010-09-01 00:55:11 +02:00
|
|
|
|
2013-09-04 00:16:52 +02: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 19:16:09 +02:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2)
|
|
|
|
: Operation(Op), Label(L), Register(R1), Register2(R2) {
|
|
|
|
assert(Op == OpRegister);
|
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
public:
|
|
|
|
/// \brief .cfi_def_cfa defines a rule for computing CFA as: take address from
|
2013-09-04 20:48:12 +02:00
|
|
|
/// Register and add Offset to it.
|
2013-09-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpDefCfa, L, Register, -Offset, "");
|
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
/// \brief .cfi_def_cfa_register modifies a rule for computing CFA. From now
|
2013-09-04 20:48:12 +02:00
|
|
|
/// on Register will be used instead of the old one. Offset remains the same.
|
2013-09-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpDefCfaRegister, L, Register, 0, "");
|
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2013-09-04 00:16:52 +02: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 19:36:23 +01:00
|
|
|
|
2013-09-04 04:10:32 +02:00
|
|
|
/// \brief .cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but
|
2013-09-04 00:16:52 +02: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 08:39:47 +01:00
|
|
|
|
2013-09-04 20:48:12 +02:00
|
|
|
/// \brief .cfi_offset Previous value of Register is saved at offset Offset
|
|
|
|
/// from CFA.
|
2013-09-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpOffset, L, Register, Offset, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 20:48:12 +02: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-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register,
|
|
|
|
int Offset) {
|
|
|
|
return MCCFIInstruction(OpRelOffset, L, Register, Offset, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 04:10:32 +02:00
|
|
|
/// \brief .cfi_register Previous value of Register1 is saved in
|
|
|
|
/// register Register2.
|
2013-09-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1,
|
|
|
|
unsigned Register2) {
|
|
|
|
return MCCFIInstruction(OpRegister, L, Register1, Register2);
|
|
|
|
}
|
|
|
|
|
2013-09-26 16:49:40 +02:00
|
|
|
/// \brief .cfi_window_save SPARC register window is saved.
|
|
|
|
static MCCFIInstruction createWindowSave(MCSymbol *L) {
|
|
|
|
return MCCFIInstruction(OpWindowSave, L, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 20:48:12 +02: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-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpRestore, L, Register, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 20:48:12 +02:00
|
|
|
/// \brief .cfi_undefined From now on the previous value of Register can't be
|
|
|
|
/// restored anymore.
|
2013-09-04 00:16:52 +02:00
|
|
|
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register) {
|
|
|
|
return MCCFIInstruction(OpUndefined, L, Register, 0, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 20:48:12 +02: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-04 00:16:52 +02: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);
|
|
|
|
}
|
|
|
|
|
2015-10-07 09:01:31 +02:00
|
|
|
/// \brief A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE
|
|
|
|
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size) {
|
|
|
|
return MCCFIInstruction(OpGnuArgsSize, L, 0, Size, "");
|
|
|
|
}
|
|
|
|
|
2013-09-04 00:16:52 +02:00
|
|
|
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 ||
|
2015-10-07 09:01:31 +02:00
|
|
|
Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize);
|
2013-09-04 00:16:52 +02:00
|
|
|
return Offset;
|
|
|
|
}
|
|
|
|
|
2014-08-30 18:48:02 +02:00
|
|
|
StringRef getValues() const {
|
2013-09-04 00:16:52 +02:00
|
|
|
assert(Operation == OpEscape);
|
|
|
|
return StringRef(&Values[0], Values.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MCDwarfFrameInfo {
|
2017-02-14 01:33:36 +01:00
|
|
|
MCDwarfFrameInfo() = default;
|
|
|
|
|
|
|
|
MCSymbol *Begin = nullptr;
|
|
|
|
MCSymbol *End = nullptr;
|
|
|
|
const MCSymbol *Personality = nullptr;
|
|
|
|
const MCSymbol *Lsda = nullptr;
|
2013-09-04 00:16:52 +02:00
|
|
|
std::vector<MCCFIInstruction> Instructions;
|
2017-02-14 01:33:36 +01:00
|
|
|
unsigned CurrentCfaRegister = 0;
|
2017-02-14 08:10:03 +01:00
|
|
|
unsigned PersonalityEncoding = 0;
|
2017-02-14 01:33:36 +01:00
|
|
|
unsigned LsdaEncoding = 0;
|
|
|
|
uint32_t CompactUnwindEncoding = 0;
|
|
|
|
bool IsSignalFrame = false;
|
|
|
|
bool IsSimple = false;
|
2013-09-04 00:16:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class MCDwarfFrameEmitter {
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// This emits the frame info section.
|
|
|
|
//
|
2014-05-12 16:28:48 +02:00
|
|
|
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH);
|
|
|
|
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta);
|
2013-09-04 00:16:52 +02:00
|
|
|
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS);
|
|
|
|
};
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2010-07-28 22:55:35 +02:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-02-14 01:33:36 +01:00
|
|
|
#endif // LLVM_MC_MCDWARF_H
|