#ifndef LLVM_DEBUGINFO_DWARFDEBUGLINE_H
#define LLVM_DEBUGINFO_DWARFDEBUGLINE_H
#include "llvm/Support/DataExtractor.h"
#include <map>
#include <string>
#include <vector>
namespace llvm {
class raw_ostream;
class DWARFDebugLine {
public:
struct FileNameEntry {
FileNameEntry() : DirIdx(0), ModTime(0), Length(0) {}
std::string Name;
uint64_t DirIdx;
uint64_t ModTime;
uint64_t Length;
};
struct Prologue {
Prologue()
: TotalLength(0), Version(0), PrologueLength(0), MinInstLength(0),
DefaultIsStmt(0), LineBase(0), LineRange(0), OpcodeBase(0) {}
uint32_t TotalLength;
uint16_t Version;
uint32_t PrologueLength;
uint8_t MinInstLength;
uint8_t DefaultIsStmt;
int8_t LineBase;
uint8_t LineRange;
uint8_t OpcodeBase;
std::vector<uint8_t> StandardOpcodeLengths;
std::vector<std::string> IncludeDirectories;
std::vector<FileNameEntry> FileNames;
uint32_t getLength() const {
return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
sizeof(PrologueLength);
}
uint32_t getStatementTableLength() const {
return TotalLength + sizeof(TotalLength) - getLength();
}
int32_t getMaxLineIncrementForSpecialOpcode() const {
return LineBase + (int8_t)LineRange - 1;
}
void dump(raw_ostream &OS) const;
void clear() {
TotalLength = Version = PrologueLength = 0;
MinInstLength = LineBase = LineRange = OpcodeBase = 0;
StandardOpcodeLengths.clear();
IncludeDirectories.clear();
FileNames.clear();
}
};
struct Row {
Row(bool default_is_stmt = false) { reset(default_is_stmt); }
void postAppend();
void reset(bool default_is_stmt);
void dump(raw_ostream &OS) const;
uint64_t Address;
uint32_t Line;
uint16_t Column;
uint16_t File;
uint8_t Isa;
uint8_t IsStmt:1,
BasicBlock:1,
EndSequence:1,
PrologueEnd:1,
EpilogueBegin:1;
};
struct LineTable {
void appendRow(const DWARFDebugLine::Row &state) { Rows.push_back(state); }
void clear() {
Prologue.clear();
Rows.clear();
}
uint32_t lookupAddress(uint64_t address, uint64_t cu_high_pc) const;
void dump(raw_ostream &OS) const;
struct Prologue Prologue;
std::vector<Row> Rows;
};
struct State : public Row, public LineTable {
enum {
StartParsingLineTable = 0,
DoneParsingLineTable = -1
};
State() : row(StartParsingLineTable) {}
virtual ~State();
virtual void appendRowToMatrix(uint32_t offset);
virtual void finalize(uint32_t offset) { row = DoneParsingLineTable; }
virtual void reset() { Row::reset(Prologue.DefaultIsStmt); }
unsigned row;
};
struct DumpingState : public State {
DumpingState(raw_ostream &OS) : OS(OS) {}
virtual ~DumpingState();
virtual void finalize(uint32_t offset);
private:
raw_ostream &OS;
};
static bool parsePrologue(DataExtractor debug_line_data, uint32_t *offset_ptr,
Prologue *prologue);
static bool parseStatementTable(DataExtractor debug_line_data,
uint32_t *offset_ptr, State &state);
const LineTable *getLineTable(uint32_t offset) const;
const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
uint32_t offset);
private:
typedef std::map<uint32_t, LineTable> LineTableMapTy;
typedef LineTableMapTy::iterator LineTableIter;
typedef LineTableMapTy::const_iterator LineTableConstIter;
LineTableMapTy LineTableMap;
};
}
#endif