#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
#include "DWARFRelocMap.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/Support/DataExtractor.h"
#include <map>
#include <string>
#include <vector>
namespace llvm {
class raw_ostream;
class DWARFDebugLine {
public:
DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
struct FileNameEntry {
FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
const char *Name;
uint64_t DirIdx;
uint64_t ModTime;
uint64_t Length;
};
struct Prologue {
Prologue();
uint32_t TotalLength;
uint16_t Version;
uint32_t PrologueLength;
uint8_t MinInstLength;
uint8_t MaxOpsPerInst;
uint8_t DefaultIsStmt;
int8_t LineBase;
uint8_t LineRange;
uint8_t OpcodeBase;
std::vector<uint8_t> StandardOpcodeLengths;
std::vector<const char*> 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 clear();
void dump(raw_ostream &OS) const;
bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
};
struct Row {
explicit Row(bool default_is_stmt = false);
void postAppend();
void reset(bool default_is_stmt);
void dump(raw_ostream &OS) const;
static bool orderByAddress(const Row& LHS, const Row& RHS) {
return LHS.Address < RHS.Address;
}
uint64_t Address;
uint32_t Line;
uint16_t Column;
uint16_t File;
uint8_t Isa;
uint32_t Discriminator;
uint8_t IsStmt:1,
BasicBlock:1,
EndSequence:1,
PrologueEnd:1,
EpilogueBegin:1;
};
struct Sequence {
uint64_t LowPC;
uint64_t HighPC;
unsigned FirstRowIndex;
unsigned LastRowIndex;
bool Empty;
Sequence();
void reset();
static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
return LHS.LowPC < RHS.LowPC;
}
bool isValid() const {
return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
}
bool containsPC(uint64_t pc) const {
return (LowPC <= pc && pc < HighPC);
}
};
struct LineTable {
LineTable();
void appendRow(const DWARFDebugLine::Row &R) {
Rows.push_back(R);
}
void appendSequence(const DWARFDebugLine::Sequence &S) {
Sequences.push_back(S);
}
uint32_t lookupAddress(uint64_t address) const;
bool lookupAddressRange(uint64_t address, uint64_t size,
std::vector<uint32_t> &result) const;
bool getFileNameByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind,
std::string &Result) const;
void dump(raw_ostream &OS) const;
void clear();
bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
uint32_t *offset_ptr);
struct Prologue Prologue;
typedef std::vector<Row> RowVector;
typedef RowVector::const_iterator RowIter;
typedef std::vector<Sequence> SequenceVector;
typedef SequenceVector::const_iterator SequenceIter;
RowVector Rows;
SequenceVector Sequences;
};
const LineTable *getLineTable(uint32_t offset) const;
const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
uint32_t offset);
private:
struct ParsingState {
ParsingState(struct LineTable *LT);
void resetRowAndSequence();
void appendRowToMatrix(uint32_t offset);
struct LineTable *LineTable;
unsigned RowNumber;
struct Row Row;
struct Sequence Sequence;
};
typedef std::map<uint32_t, LineTable> LineTableMapTy;
typedef LineTableMapTy::iterator LineTableIter;
typedef LineTableMapTy::const_iterator LineTableConstIter;
const RelocAddrMap *RelocMap;
LineTableMapTy LineTableMap;
};
}
#endif