X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FDebugInfo%2FDWARFDebugLine.h;h=890477887304000a0a6f5103a83457dc38874b54;hb=be63d589633bbfa068b923c60eaaeee1b27647c5;hp=a8c0669b738b7055d1954294a6d8ac825dec561d;hpb=71d94f805514f28730bf39143ee227648d521d09;p=oota-llvm.git diff --git a/lib/DebugInfo/DWARFDebugLine.h b/lib/DebugInfo/DWARFDebugLine.h index a8c0669b738..89047788730 100644 --- a/lib/DebugInfo/DWARFDebugLine.h +++ b/lib/DebugInfo/DWARFDebugLine.h @@ -7,11 +7,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_DEBUGINFO_DWARFDEBUGLINE_H -#define LLVM_DEBUGINFO_DWARFDEBUGLINE_H +#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 +#include #include namespace llvm { @@ -20,8 +23,9 @@ class raw_ostream; class DWARFDebugLine { public: + DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {} struct FileNameEntry { - FileNameEntry() : Name(0), DirIdx(0), ModTime(0), Length(0) {} + FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {} const char *Name; uint64_t DirIdx; @@ -30,9 +34,7 @@ public: }; struct Prologue { - Prologue() - : TotalLength(0), Version(0), PrologueLength(0), MinInstLength(0), - DefaultIsStmt(0), LineBase(0), LineRange(0), OpcodeBase(0) {} + Prologue(); // The size in bytes of the statement information for this compilation unit // (not including the total_length field itself). @@ -46,6 +48,9 @@ public: // program opcodes that alter the address register first multiply their // operands by this value. uint8_t MinInstLength; + // The maximum number of individual operations that may be encoded in an + // instruction. + uint8_t MaxOpsPerInst; // The initial value of theis_stmtregister. uint8_t DefaultIsStmt; // This parameter affects the meaning of the special opcodes. See below. @@ -70,24 +75,25 @@ public: int32_t getMaxLineIncrementForSpecialOpcode() const { return LineBase + (int8_t)LineRange - 1; } + + void clear(); void dump(raw_ostream &OS) const; - void clear() { - TotalLength = Version = PrologueLength = 0; - MinInstLength = LineBase = LineRange = OpcodeBase = 0; - StandardOpcodeLengths.clear(); - IncludeDirectories.clear(); - FileNames.clear(); - } + bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr); }; // Standard .debug_line state machine structure. struct Row { - Row(bool default_is_stmt = false) { reset(default_is_stmt); } + explicit Row(bool default_is_stmt = false); + /// Called after a row is appended to the matrix. 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; + } + // The program-counter value corresponding to a machine instruction // generated by the compiler. uint64_t Address; @@ -105,6 +111,9 @@ public: // An unsigned integer whose value encodes the applicable instruction set // architecture for the current instruction. uint8_t Isa; + // An unsigned integer representing the DWARF path discriminator value + // for this location. + uint32_t Discriminator; // A boolean indicating that the current instruction is the beginning of a // statement. uint8_t IsStmt:1, @@ -125,62 +134,96 @@ public: EpilogueBegin:1; }; - struct LineTable { - void appendRow(const DWARFDebugLine::Row &state) { Rows.push_back(state); } - void clear() { - Prologue.clear(); - Rows.clear(); + // 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; + + 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); + } + }; - uint32_t lookupAddress(uint64_t address, uint64_t cu_high_pc) const; - void dump(raw_ostream &OS) const; + struct LineTable { + LineTable(); - struct Prologue Prologue; - std::vector Rows; - }; + void appendRow(const DWARFDebugLine::Row &R) { + Rows.push_back(R); + } + void appendSequence(const DWARFDebugLine::Sequence &S) { + Sequences.push_back(S); + } - struct State : public Row, public LineTable { - // Special row codes. - enum { - StartParsingLineTable = 0, - DoneParsingLineTable = -1 - }; + // 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; - State() : row(StartParsingLineTable) {} - virtual ~State(); + bool lookupAddressRange(uint64_t address, uint64_t size, + std::vector &result) const; - virtual void appendRowToMatrix(uint32_t offset); - virtual void finalize(uint32_t offset) { row = DoneParsingLineTable; } - virtual void reset() { Row::reset(Prologue.DefaultIsStmt); } + // Extracts filename by its index in filename table in prologue. + // Returns true on success. + bool getFileNameByIndex(uint64_t FileIndex, + DILineInfoSpecifier::FileLineInfoKind Kind, + std::string &Result) const; - // The row number that starts at zero for the prologue, and increases for - // each row added to the matrix. - unsigned row; - }; + void dump(raw_ostream &OS) const; + void clear(); - struct DumpingState : public State { - DumpingState(raw_ostream &OS) : OS(OS) {} - virtual ~DumpingState(); - virtual void finalize(uint32_t offset); - private: - raw_ostream &OS; - }; + /// Parse prologue and all rows. + bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap, + uint32_t *offset_ptr); - static bool parsePrologue(DataExtractor debug_line_data, uint32_t *offset_ptr, - Prologue *prologue); - /// Parse a single line table (prologue and all rows). - static bool parseStatementTable(DataExtractor debug_line_data, - uint32_t *offset_ptr, State &state); + struct Prologue Prologue; + typedef std::vector RowVector; + typedef RowVector::const_iterator RowIter; + typedef std::vector 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); + + // 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; + }; + typedef std::map LineTableMapTy; typedef LineTableMapTy::iterator LineTableIter; typedef LineTableMapTy::const_iterator LineTableConstIter; + const RelocAddrMap *RelocMap; LineTableMapTy LineTableMap; };