diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-15 20:43:22 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-15 20:43:22 +0000 |
commit | 2602ca67e89b9b9f309ef3b2b4181d65b67acb0f (patch) | |
tree | 1f5352fda8a1cba550bc86ca3eac9ffdbb906d78 /llvm/lib/DebugInfo | |
parent | 679e1752f81e21c40392ff90aaaabbe9596ef07f (diff) | |
download | bcm5719-llvm-2602ca67e89b9b9f309ef3b2b4181d65b67acb0f.tar.gz bcm5719-llvm-2602ca67e89b9b9f309ef3b2b4181d65b67acb0f.zip |
DWARF: Put all the pieces we have together and provide a single accessor to DIContext that provides line information when given an address.
llvm-svn: 139836
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r-- | llvm/lib/DebugInfo/DWARFContext.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARFContext.h | 5 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARFDebugLine.cpp | 4 |
3 files changed, 57 insertions, 1 deletions
diff --git a/llvm/lib/DebugInfo/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARFContext.cpp index 36c6d98ac6d..5fd4280ba7a 100644 --- a/llvm/lib/DebugInfo/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARFContext.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> using namespace llvm; using namespace dwarf; @@ -112,3 +113,51 @@ void DWARFContext::parseCompileUnits() { offset = CUs.back().getNextCompileUnitOffset(); } } + +namespace { + struct OffsetComparator { + bool operator()(const DWARFCompileUnit &LHS, + const DWARFCompileUnit &RHS) const { + return LHS.getOffset() < RHS.getOffset(); + } + bool operator()(const DWARFCompileUnit &LHS, uint32_t RHS) const { + return LHS.getOffset() < RHS; + } + bool operator()(uint32_t LHS, const DWARFCompileUnit &RHS) const { + return LHS < RHS.getOffset(); + } + }; +} + +DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t offset) { + if (CUs.empty()) + parseCompileUnits(); + + DWARFCompileUnit *i = std::lower_bound(CUs.begin(), CUs.end(), offset, + OffsetComparator()); + if (i != CUs.end()) + return &*i; + return 0; +} + +DILineInfo DWARFContext::getLineInfoForAddress(uint64_t address) { + // First, get the index for the arange. + uint32_t arangeIndex = getDebugAranges()->findAddress(address); + // From there, get the offset of the compile unit. + uint32_t cuOffset = getDebugAranges()->offsetAtIndex(arangeIndex); + // Retrieve the compile unit. + DWARFCompileUnit *cu = getCompileUnitForOffset(cuOffset); + // Get the line table for this compile unit. + const DWARFDebugLine::LineTable *lineTable = getLineTableForCompileUnit(cu); + // Get the index of the row we're looking for in the line table. + uint64_t hiPC = + cu->getCompileUnitDIE()->getAttributeValueAsUnsigned(cu, DW_AT_high_pc, + -1ULL); + uint32_t rowIndex = lineTable->lookupAddress(address, hiPC); + + // From here, contruct the DILineInfo. + const DWARFDebugLine::Row &row = lineTable->Rows[rowIndex]; + const std::string &fileName = lineTable->Prologue.FileNames[row.File-1].Name; + + return DILineInfo(fileName.c_str(), row.Line, row.Column); +} diff --git a/llvm/lib/DebugInfo/DWARFContext.h b/llvm/lib/DebugInfo/DWARFContext.h index 687e5facfe5..746a4639f27 100644 --- a/llvm/lib/DebugInfo/DWARFContext.h +++ b/llvm/lib/DebugInfo/DWARFContext.h @@ -53,6 +53,9 @@ public: return &CUs[index]; } + /// Return the compile unit that includes an offset (relative to .debug_info). + DWARFCompileUnit *getCompileUnitForOffset(uint32_t offset); + /// Get a pointer to the parsed DebugAbbrev object. const DWARFDebugAbbrev *getDebugAbbrev(); @@ -63,6 +66,8 @@ public: const DWARFDebugLine::LineTable * getLineTableForCompileUnit(DWARFCompileUnit *cu); + virtual DILineInfo getLineInfoForAddress(uint64_t address); + bool isLittleEndian() const { return IsLittleEndian; } virtual StringRef getInfoSection() = 0; diff --git a/llvm/lib/DebugInfo/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARFDebugLine.cpp index 941d8813d55..94fff6533e4 100644 --- a/llvm/lib/DebugInfo/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARFDebugLine.cpp @@ -122,7 +122,9 @@ DWARFDebugLine::getOrParseLineTable(DataExtractor debug_line_data, State state; if (!parseStatementTable(debug_line_data, &offset, state)) return 0; - pos->second = state; + // FIXME: double lookup. + LineTableMap[offset] = state; + return &LineTableMap[offset]; } return &pos->second; } |