summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFContext.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFContext.cpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 3a0f52753b0..a29c9c2f160 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -25,6 +25,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
@@ -267,31 +268,26 @@ static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,
}
}
-// Dump a section that contains a sequence of tables of lists, such as range
-// or location list tables. In DWARF v5 we expect to find properly formatted
-// tables with headers. In DWARF v4 and earlier we simply expect a sequence of
-// lists, which we treat, mutatis mutandis, like DWARF v5 tables.
-template <typename ListTable>
+// Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).
static void
-dumpListSection(raw_ostream &OS, DWARFContext *C, StringRef SectionName,
- uint16_t MaxVersion, DWARFDataExtractor &ListData,
- llvm::function_ref<Optional<SectionedAddress>(uint32_t)>
- LookupPooledAddress,
- DIDumpOptions DumpOpts, bool isDWO = false) {
+dumpRnglistsSection(raw_ostream &OS, DWARFDataExtractor &rnglistData,
+ llvm::function_ref<Optional<SectionedAddress>(uint32_t)>
+ LookupPooledAddress,
+ DIDumpOptions DumpOpts) {
uint32_t Offset = 0;
- while (ListData.isValidOffset(Offset)) {
- ListTable Table(C, SectionName, isDWO);
- if (Error Err = Table.extract(ListData, MaxVersion, &Offset)) {
+ while (rnglistData.isValidOffset(Offset)) {
+ llvm::DWARFDebugRnglistTable Rnglists;
+ uint32_t TableOffset = Offset;
+ if (Error Err = Rnglists.extract(rnglistData, &Offset)) {
WithColor::error() << toString(std::move(Err)) << '\n';
- // If table extraction set Offset to 0, it indicates that we cannot
- // continue to read the section.
- if (Offset == 0)
+ uint64_t Length = Rnglists.length();
+ // Keep going after an error, if we can, assuming that the length field
+ // could be read. If it couldn't, stop reading the section.
+ if (Length == 0)
break;
- // In DWARF v4 and earlier, dump as much of the lists as we can.
- if (MaxVersion < 5)
- Table.dump(OS, LookupPooledAddress, DumpOpts);
+ Offset = TableOffset + Length;
} else {
- Table.dump(OS, LookupPooledAddress, DumpOpts);
+ Rnglists.dump(OS, LookupPooledAddress, DumpOpts);
}
}
}
@@ -512,6 +508,22 @@ void DWARFContext::dump(
dumpAddrSection(OS, AddrData, DumpOpts, getMaxVersion(), getCUAddrSize());
}
+ if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,
+ DObj->getRangeSection().Data)) {
+ uint8_t savedAddressByteSize = getCUAddrSize();
+ DWARFDataExtractor rangesData(*DObj, DObj->getRangeSection(),
+ isLittleEndian(), savedAddressByteSize);
+ uint32_t offset = 0;
+ DWARFDebugRangeList rangeList;
+ while (rangesData.isValidOffset(offset)) {
+ if (Error E = rangeList.extract(rangesData, &offset)) {
+ WithColor::error() << toString(std::move(E)) << '\n';
+ break;
+ }
+ rangeList.dump(OS);
+ }
+ }
+
auto LookupPooledAddress = [&](uint32_t Index) -> Optional<SectionedAddress> {
const auto &CUs = compile_units();
auto I = CUs.begin();
@@ -520,32 +532,18 @@ void DWARFContext::dump(
return (*I)->getAddrOffsetSectionItem(Index);
};
- if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,
- DObj->getRangeSection().Data)) {
- uint8_t savedAddressByteSize = getCUAddrSize();
- DWARFDataExtractor rangesData(*DObj, DObj->getRangeSection(),
- isLittleEndian(), savedAddressByteSize);
- dumpListSection<DWARFDebugRnglistTable>(OS, this, ".debug_ranges",
- /* MaxVersion = */ 4, rangesData,
- LookupPooledAddress, DumpOpts);
- }
-
if (shouldDump(Explicit, ".debug_rnglists", DIDT_ID_DebugRnglists,
DObj->getRnglistsSection().Data)) {
DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsSection(),
- isLittleEndian(), getCUAddrSize());
- dumpListSection<DWARFDebugRnglistTable>(OS, this, ".debug_rnglists",
- getMaxVersion(5), RnglistData,
- LookupPooledAddress, DumpOpts);
+ isLittleEndian(), 0);
+ dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
}
if (shouldDump(ExplicitDWO, ".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
DObj->getRnglistsDWOSection().Data)) {
DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsDWOSection(),
- isLittleEndian(), getCUAddrSize());
- dumpListSection<DWARFDebugRnglistTable>(OS, this, ".debug_rnglists.dwo",
- getMaxVersion(5), RnglistData,
- LookupPooledAddress, DumpOpts);
+ isLittleEndian(), 0);
+ dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
}
if (shouldDump(Explicit, ".debug_pubnames", DIDT_ID_DebugPubnames,
OpenPOWER on IntegriCloud