DWARF: Remove accessors that parse the whole line table section in one go, this can't possibly work.

The address size is specified by the compile unit associated with a line table, there is no global address size.

llvm-svn: 139835
This commit is contained in:
Benjamin Kramer 2011-09-15 20:43:18 +00:00
parent d923eb0d1e
commit 679e1752f8
4 changed files with 37 additions and 56 deletions

View File

@ -77,15 +77,25 @@ const DWARFDebugAranges *DWARFContext::getDebugAranges() {
return Aranges.get(); return Aranges.get();
} }
const DWARFDebugLine *DWARFContext::getDebugLine() { const DWARFDebugLine::LineTable *
if (Line) DWARFContext::getLineTableForCompileUnit(DWARFCompileUnit *cu) {
return Line.get(); if (!Line)
Line.reset(new DWARFDebugLine());
DataExtractor lineData(getLineSection(), isLittleEndian(), 0); unsigned stmtOffset =
cu->getCompileUnitDIE()->getAttributeValueAsUnsigned(cu, DW_AT_stmt_list,
-1U);
if (stmtOffset == -1U)
return 0; // No line table for this compile unit.
Line.reset(new DWARFDebugLine()); // See if the line table is cached.
Line->parse(lineData); if (const DWARFDebugLine::LineTable *lt = Line->getLineTable(stmtOffset))
return Line.get(); return lt;
// We have to parse it first.
DataExtractor lineData(getLineSection(), isLittleEndian(),
cu->getAddressByteSize());
return Line->getOrParseLineTable(lineData, stmtOffset);
} }
void DWARFContext::parseCompileUnits() { void DWARFContext::parseCompileUnits() {

View File

@ -59,8 +59,9 @@ public:
/// Get a pointer to the parsed DebugAranges object. /// Get a pointer to the parsed DebugAranges object.
const DWARFDebugAranges *getDebugAranges(); const DWARFDebugAranges *getDebugAranges();
/// Get a pointer to the parsed DWARFDebugLine object. /// Get a pointer to a parsed line table corresponding to a compile unit.
const DWARFDebugLine *getDebugLine(); const DWARFDebugLine::LineTable *
getLineTableForCompileUnit(DWARFCompileUnit *cu);
bool isLittleEndian() const { return IsLittleEndian; } bool isLittleEndian() const { return IsLittleEndian; }

View File

@ -99,50 +99,12 @@ void DWARFDebugLine::State::appendRowToMatrix(uint32_t offset) {
Row::postAppend(); Row::postAppend();
} }
void DWARFDebugLine::parse(const DataExtractor debug_line_data) {
LineTableMap.clear();
uint32_t offset = 0;
State state;
while (debug_line_data.isValidOffset(offset)) {
const uint32_t debug_line_offset = offset;
if (parseStatementTable(debug_line_data, &offset, state)) {
// Make sure we don't don't loop infinitely
if (offset <= debug_line_offset)
break;
LineTableMap[debug_line_offset] = state;
state.reset();
}
else
++offset; // Try next byte in line table
}
}
DWARFDebugLine::DumpingState::~DumpingState() {} DWARFDebugLine::DumpingState::~DumpingState() {}
void DWARFDebugLine::DumpingState::finalize(uint32_t offset) { void DWARFDebugLine::DumpingState::finalize(uint32_t offset) {
LineTable::dump(OS); LineTable::dump(OS);
} }
void DWARFDebugLine::dump(const DataExtractor debug_line_data, raw_ostream &OS){
uint32_t offset = 0;
DumpingState state(OS);
while (debug_line_data.isValidOffset(offset)) {
const uint32_t debug_line_offset = offset;
if (parseStatementTable(debug_line_data, &offset, state)) {
// Make sure we don't don't loop infinitely
if (offset <= debug_line_offset)
break;
state.reset();
}
else
++offset; // Try next byte in line table
}
}
const DWARFDebugLine::LineTable * const DWARFDebugLine::LineTable *
DWARFDebugLine::getLineTable(uint32_t offset) const { DWARFDebugLine::getLineTable(uint32_t offset) const {
LineTableConstIter pos = LineTableMap.find(offset); LineTableConstIter pos = LineTableMap.find(offset);
@ -151,6 +113,20 @@ DWARFDebugLine::getLineTable(uint32_t offset) const {
return 0; return 0;
} }
const DWARFDebugLine::LineTable *
DWARFDebugLine::getOrParseLineTable(DataExtractor debug_line_data,
uint32_t offset) {
LineTableIter pos = LineTableMap.find(offset);
if (pos == LineTableMap.end()) {
// Parse and cache the line table for at this offset.
State state;
if (!parseStatementTable(debug_line_data, &offset, state))
return 0;
pos->second = state;
}
return &pos->second;
}
bool bool
DWARFDebugLine::parsePrologue(DataExtractor debug_line_data, DWARFDebugLine::parsePrologue(DataExtractor debug_line_data,
uint32_t *offset_ptr, Prologue *prologue) { uint32_t *offset_ptr, Prologue *prologue) {

View File

@ -147,7 +147,7 @@ public:
DoneParsingLineTable = -1 DoneParsingLineTable = -1
}; };
State() : row(0) {} State() : row(StartParsingLineTable) {}
virtual ~State(); virtual ~State();
virtual void appendRowToMatrix(uint32_t offset); virtual void appendRowToMatrix(uint32_t offset);
@ -173,15 +173,9 @@ public:
static bool parseStatementTable(DataExtractor debug_line_data, static bool parseStatementTable(DataExtractor debug_line_data,
uint32_t *offset_ptr, State &state); uint32_t *offset_ptr, State &state);
/// Parse all information in the debug_line_data into an internal
/// representation.
void parse(DataExtractor debug_line_data);
void parseIfNeeded(DataExtractor debug_line_data) {
if (LineTableMap.empty())
parse(debug_line_data);
}
static void dump(DataExtractor debug_line_data, raw_ostream &OS);
const LineTable *getLineTable(uint32_t offset) const; const LineTable *getLineTable(uint32_t offset) const;
const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
uint32_t offset);
private: private:
typedef std::map<uint32_t, LineTable> LineTableMapTy; typedef std::map<uint32_t, LineTable> LineTableMapTy;