diff options
Diffstat (limited to 'lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp')
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp index f0b7ec2751de..a565718debd0 100644 --- a/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp @@ -13,13 +13,16 @@ #include "llvm/Support/raw_ostream.h" #include <cinttypes> #include <cstdint> -#include <utility> using namespace llvm; -raw_ostream &llvm::operator<<(raw_ostream &OS, const DWARFAddressRange &R) { - return OS << format("[0x%16.16" PRIx64 ", 0x%16.16" PRIx64 ")", R.LowPC, - R.HighPC); +// FIXME: There are several versions of this. Consolidate them. +template <typename... Ts> +static Error createError(char const *Fmt, const Ts &... Vals) { + std::string Buffer; + raw_string_ostream Stream(Buffer); + Stream << format(Fmt, Vals...); + return make_error<StringError>(Stream.str(), inconvertibleErrorCode()); } void DWARFDebugRangeList::clear() { @@ -28,14 +31,15 @@ void DWARFDebugRangeList::clear() { Entries.clear(); } -bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data, - uint32_t *offset_ptr) { +Error DWARFDebugRangeList::extract(const DWARFDataExtractor &data, + uint32_t *offset_ptr) { clear(); if (!data.isValidOffset(*offset_ptr)) - return false; + return createError("invalid range list offset 0x%" PRIx32, *offset_ptr); + AddressSize = data.getAddressSize(); if (AddressSize != 4 && AddressSize != 8) - return false; + return createError("invalid address size: %d", AddressSize); Offset = *offset_ptr; while (true) { RangeListEntry Entry; @@ -49,13 +53,14 @@ bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data, // Check that both values were extracted correctly. if (*offset_ptr != prev_offset + 2 * AddressSize) { clear(); - return false; + return createError("invalid range list entry at offset 0x%" PRIx32, + prev_offset); } if (Entry.isEndOfListEntry()) break; Entries.push_back(Entry); } - return true; + return Error::success(); } void DWARFDebugRangeList::dump(raw_ostream &OS) const { |