2011-09-15 10:12:05 +08:00
|
|
|
//===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
|
|
|
|
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
|
2011-09-15 10:12:05 +08:00
|
|
|
|
2013-01-26 06:50:58 +08:00
|
|
|
#include "DWARFRelocMap.h"
|
2014-05-16 05:24:32 +08:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2011-09-15 10:12:05 +08:00
|
|
|
#include "llvm/Support/DataExtractor.h"
|
|
|
|
#include <map>
|
2012-08-30 15:49:50 +08:00
|
|
|
#include <string>
|
2011-09-15 10:12:05 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class raw_ostream;
|
|
|
|
|
|
|
|
class DWARFDebugLine {
|
|
|
|
public:
|
2013-01-26 06:50:58 +08:00
|
|
|
DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
|
2011-09-15 10:12:05 +08:00
|
|
|
struct FileNameEntry {
|
2014-04-28 12:05:08 +08:00
|
|
|
FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
|
2011-09-15 10:12:05 +08:00
|
|
|
|
2012-07-19 15:03:58 +08:00
|
|
|
const char *Name;
|
2011-09-15 10:12:05 +08:00
|
|
|
uint64_t DirIdx;
|
|
|
|
uint64_t ModTime;
|
|
|
|
uint64_t Length;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Prologue {
|
2014-04-30 05:28:13 +08:00
|
|
|
Prologue();
|
2011-09-15 10:12:05 +08:00
|
|
|
|
|
|
|
// The size in bytes of the statement information for this compilation unit
|
|
|
|
// (not including the total_length field itself).
|
|
|
|
uint32_t TotalLength;
|
|
|
|
// Version identifier for the statement information format.
|
|
|
|
uint16_t Version;
|
|
|
|
// The number of bytes following the prologue_length field to the beginning
|
|
|
|
// of the first byte of the statement program itself.
|
|
|
|
uint32_t PrologueLength;
|
|
|
|
// The size in bytes of the smallest target machine instruction. Statement
|
|
|
|
// program opcodes that alter the address register first multiply their
|
|
|
|
// operands by this value.
|
|
|
|
uint8_t MinInstLength;
|
2014-02-25 07:58:54 +08:00
|
|
|
// The maximum number of individual operations that may be encoded in an
|
|
|
|
// instruction.
|
|
|
|
uint8_t MaxOpsPerInst;
|
2011-09-15 10:12:05 +08:00
|
|
|
// The initial value of theis_stmtregister.
|
|
|
|
uint8_t DefaultIsStmt;
|
|
|
|
// This parameter affects the meaning of the special opcodes. See below.
|
|
|
|
int8_t LineBase;
|
|
|
|
// This parameter affects the meaning of the special opcodes. See below.
|
|
|
|
uint8_t LineRange;
|
|
|
|
// The number assigned to the first special opcode.
|
|
|
|
uint8_t OpcodeBase;
|
|
|
|
std::vector<uint8_t> StandardOpcodeLengths;
|
2012-07-19 15:03:58 +08:00
|
|
|
std::vector<const char*> IncludeDirectories;
|
2011-09-15 10:12:05 +08:00
|
|
|
std::vector<FileNameEntry> FileNames;
|
|
|
|
|
|
|
|
// Length of the prologue in bytes.
|
|
|
|
uint32_t getLength() const {
|
|
|
|
return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
|
|
|
|
sizeof(PrologueLength);
|
|
|
|
}
|
|
|
|
// Length of the line table data in bytes (not including the prologue).
|
|
|
|
uint32_t getStatementTableLength() const {
|
|
|
|
return TotalLength + sizeof(TotalLength) - getLength();
|
|
|
|
}
|
|
|
|
int32_t getMaxLineIncrementForSpecialOpcode() const {
|
|
|
|
return LineBase + (int8_t)LineRange - 1;
|
|
|
|
}
|
2014-04-30 05:28:13 +08:00
|
|
|
|
|
|
|
void clear();
|
2011-09-15 10:12:05 +08:00
|
|
|
void dump(raw_ostream &OS) const;
|
2014-04-30 05:28:13 +08:00
|
|
|
bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
|
2011-09-15 10:12:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Standard .debug_line state machine structure.
|
|
|
|
struct Row {
|
2014-04-30 05:28:13 +08:00
|
|
|
explicit Row(bool default_is_stmt = false);
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
/// Called after a row is appended to the matrix.
|
|
|
|
void postAppend();
|
|
|
|
void reset(bool default_is_stmt);
|
|
|
|
void dump(raw_ostream &OS) const;
|
|
|
|
|
2012-08-07 19:46:57 +08:00
|
|
|
static bool orderByAddress(const Row& LHS, const Row& RHS) {
|
|
|
|
return LHS.Address < RHS.Address;
|
|
|
|
}
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
// The program-counter value corresponding to a machine instruction
|
|
|
|
// generated by the compiler.
|
|
|
|
uint64_t Address;
|
|
|
|
// An unsigned integer indicating a source line number. Lines are numbered
|
|
|
|
// beginning at 1. The compiler may emit the value 0 in cases where an
|
|
|
|
// instruction cannot be attributed to any source line.
|
|
|
|
uint32_t Line;
|
|
|
|
// An unsigned integer indicating a column number within a source line.
|
|
|
|
// Columns are numbered beginning at 1. The value 0 is reserved to indicate
|
|
|
|
// that a statement begins at the 'left edge' of the line.
|
|
|
|
uint16_t Column;
|
|
|
|
// An unsigned integer indicating the identity of the source file
|
|
|
|
// corresponding to a machine instruction.
|
|
|
|
uint16_t File;
|
|
|
|
// An unsigned integer whose value encodes the applicable instruction set
|
|
|
|
// architecture for the current instruction.
|
|
|
|
uint8_t Isa;
|
2014-02-15 03:27:53 +08:00
|
|
|
// An unsigned integer representing the DWARF path discriminator value
|
|
|
|
// for this location.
|
|
|
|
uint32_t Discriminator;
|
2011-09-15 10:12:05 +08:00
|
|
|
// A boolean indicating that the current instruction is the beginning of a
|
|
|
|
// statement.
|
|
|
|
uint8_t IsStmt:1,
|
|
|
|
// A boolean indicating that the current instruction is the
|
|
|
|
// beginning of a basic block.
|
|
|
|
BasicBlock:1,
|
|
|
|
// A boolean indicating that the current address is that of the
|
|
|
|
// first byte after the end of a sequence of target machine
|
|
|
|
// instructions.
|
|
|
|
EndSequence:1,
|
|
|
|
// A boolean indicating that the current address is one (of possibly
|
|
|
|
// many) where execution should be suspended for an entry breakpoint
|
|
|
|
// of a function.
|
|
|
|
PrologueEnd:1,
|
|
|
|
// A boolean indicating that the current address is one (of possibly
|
|
|
|
// many) where execution should be suspended for an exit breakpoint
|
|
|
|
// of a function.
|
|
|
|
EpilogueBegin:1;
|
|
|
|
};
|
|
|
|
|
2012-08-07 19:46:57 +08:00
|
|
|
// Represents a series of contiguous machine instructions. Line table for each
|
|
|
|
// compilation unit may consist of multiple sequences, which are not
|
|
|
|
// guaranteed to be in the order of ascending instruction address.
|
|
|
|
struct Sequence {
|
|
|
|
// Sequence describes instructions at address range [LowPC, HighPC)
|
|
|
|
// and is described by line table rows [FirstRowIndex, LastRowIndex).
|
|
|
|
uint64_t LowPC;
|
|
|
|
uint64_t HighPC;
|
|
|
|
unsigned FirstRowIndex;
|
|
|
|
unsigned LastRowIndex;
|
|
|
|
bool Empty;
|
|
|
|
|
2014-04-30 05:28:13 +08:00
|
|
|
Sequence();
|
|
|
|
void reset();
|
|
|
|
|
2012-08-07 19:46:57 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
struct LineTable {
|
2014-04-30 05:28:13 +08:00
|
|
|
LineTable();
|
|
|
|
|
|
|
|
void appendRow(const DWARFDebugLine::Row &R) {
|
|
|
|
Rows.push_back(R);
|
2012-08-07 19:46:57 +08:00
|
|
|
}
|
2014-04-30 05:28:13 +08:00
|
|
|
void appendSequence(const DWARFDebugLine::Sequence &S) {
|
|
|
|
Sequences.push_back(S);
|
2011-09-15 10:12:05 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 19:46:57 +08:00
|
|
|
// Returns the index of the row with file/line info for a given address,
|
|
|
|
// or -1 if there is no such row.
|
|
|
|
uint32_t lookupAddress(uint64_t address) const;
|
2012-08-30 15:49:50 +08:00
|
|
|
|
2014-04-30 05:28:13 +08:00
|
|
|
bool lookupAddressRange(uint64_t address, uint64_t size,
|
|
|
|
std::vector<uint32_t> &result) const;
|
2013-01-26 08:28:05 +08:00
|
|
|
|
2012-08-30 15:49:50 +08:00
|
|
|
// Extracts filename by its index in filename table in prologue.
|
|
|
|
// Returns true on success.
|
2014-09-19 23:11:51 +08:00
|
|
|
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
|
2014-05-16 05:24:32 +08:00
|
|
|
DILineInfoSpecifier::FileLineInfoKind Kind,
|
2012-08-30 15:49:50 +08:00
|
|
|
std::string &Result) const;
|
|
|
|
|
2014-09-19 23:11:51 +08:00
|
|
|
// Fills the Result argument with the file and line information
|
|
|
|
// corresponding to Address. Returns true on success.
|
|
|
|
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
|
|
|
|
DILineInfoSpecifier::FileLineInfoKind Kind,
|
|
|
|
DILineInfo &Result) const;
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
void dump(raw_ostream &OS) const;
|
2014-04-30 05:28:13 +08:00
|
|
|
void clear();
|
2011-09-15 10:12:05 +08:00
|
|
|
|
2014-04-30 08:09:19 +08:00
|
|
|
/// Parse prologue and all rows.
|
|
|
|
bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
|
|
|
|
uint32_t *offset_ptr);
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
struct Prologue Prologue;
|
2012-08-07 19:46:57 +08:00
|
|
|
typedef std::vector<Row> RowVector;
|
|
|
|
typedef RowVector::const_iterator RowIter;
|
|
|
|
typedef std::vector<Sequence> SequenceVector;
|
|
|
|
typedef SequenceVector::const_iterator SequenceIter;
|
|
|
|
RowVector Rows;
|
|
|
|
SequenceVector Sequences;
|
2011-09-15 10:12:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const LineTable *getLineTable(uint32_t offset) const;
|
2011-09-16 04:43:18 +08:00
|
|
|
const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
|
|
|
|
uint32_t offset);
|
2011-09-15 10:12:05 +08:00
|
|
|
|
2011-09-15 11:11:09 +08:00
|
|
|
private:
|
2014-04-30 08:09:19 +08:00
|
|
|
struct ParsingState {
|
|
|
|
ParsingState(struct LineTable *LT);
|
|
|
|
|
|
|
|
void resetRowAndSequence();
|
|
|
|
void appendRowToMatrix(uint32_t offset);
|
|
|
|
|
|
|
|
// Line table we're currently parsing.
|
|
|
|
struct LineTable *LineTable;
|
|
|
|
// The row number that starts at zero for the prologue, and increases for
|
|
|
|
// each row added to the matrix.
|
|
|
|
unsigned RowNumber;
|
|
|
|
struct Row Row;
|
|
|
|
struct Sequence Sequence;
|
|
|
|
};
|
|
|
|
|
2011-09-15 10:12:05 +08:00
|
|
|
typedef std::map<uint32_t, LineTable> LineTableMapTy;
|
|
|
|
typedef LineTableMapTy::iterator LineTableIter;
|
|
|
|
typedef LineTableMapTy::const_iterator LineTableConstIter;
|
|
|
|
|
2013-01-26 06:50:58 +08:00
|
|
|
const RelocAddrMap *RelocMap;
|
2011-09-15 10:12:05 +08:00
|
|
|
LineTableMapTy LineTableMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|