2018-02-02 20:45:57 +08:00
|
|
|
//===- DWARFDebugRnglists.cpp ---------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2018-05-19 04:12:54 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
#include "llvm/Support/Errc.h"
|
2018-02-02 20:45:57 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2018-07-24 06:37:17 +08:00
|
|
|
Error RangeListEntry::extract(DWARFDataExtractor Data, uint32_t End,
|
2018-10-31 09:12:58 +08:00
|
|
|
uint32_t *OffsetPtr) {
|
2018-04-06 05:01:49 +08:00
|
|
|
Offset = *OffsetPtr;
|
2018-05-19 04:12:54 +08:00
|
|
|
SectionIndex = -1ULL;
|
2018-10-31 09:12:58 +08:00
|
|
|
// The caller should guarantee that we have at least 1 byte available, so
|
|
|
|
// we just assert instead of revalidate.
|
|
|
|
assert(*OffsetPtr < End &&
|
|
|
|
"not enough space to extract a rangelist encoding");
|
|
|
|
uint8_t Encoding = Data.getU8(OffsetPtr);
|
2018-04-06 05:01:49 +08:00
|
|
|
|
|
|
|
switch (Encoding) {
|
|
|
|
case dwarf::DW_RLE_end_of_list:
|
|
|
|
Value0 = Value1 = 0;
|
|
|
|
break;
|
|
|
|
// TODO: Support other encodings.
|
2018-10-20 14:16:25 +08:00
|
|
|
case dwarf::DW_RLE_base_addressx: {
|
|
|
|
uint32_t PreviousOffset = *OffsetPtr - 1;
|
|
|
|
Value0 = Data.getULEB128(OffsetPtr);
|
|
|
|
if (End < *OffsetPtr)
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"read past end of table when reading "
|
|
|
|
"DW_RLE_base_addressx encoding at offset 0x%" PRIx32,
|
|
|
|
PreviousOffset);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-06 05:01:49 +08:00
|
|
|
case dwarf::DW_RLE_startx_endx:
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::not_supported,
|
|
|
|
"unsupported rnglists encoding DW_RLE_startx_endx at "
|
2018-04-06 05:01:49 +08:00
|
|
|
"offset 0x%" PRIx32,
|
|
|
|
*OffsetPtr - 1);
|
2018-10-20 14:16:25 +08:00
|
|
|
case dwarf::DW_RLE_startx_length: {
|
|
|
|
uint32_t PreviousOffset = *OffsetPtr - 1;
|
|
|
|
Value0 = Data.getULEB128(OffsetPtr);
|
|
|
|
Value1 = Data.getULEB128(OffsetPtr);
|
|
|
|
if (End < *OffsetPtr)
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"read past end of table when reading "
|
|
|
|
"DW_RLE_startx_length encoding at offset 0x%" PRIx32,
|
|
|
|
PreviousOffset);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-06 05:01:49 +08:00
|
|
|
case dwarf::DW_RLE_offset_pair: {
|
|
|
|
uint32_t PreviousOffset = *OffsetPtr - 1;
|
|
|
|
Value0 = Data.getULEB128(OffsetPtr);
|
|
|
|
Value1 = Data.getULEB128(OffsetPtr);
|
|
|
|
if (End < *OffsetPtr)
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"read past end of table when reading "
|
2018-04-06 05:01:49 +08:00
|
|
|
"DW_RLE_offset_pair encoding at offset 0x%" PRIx32,
|
|
|
|
PreviousOffset);
|
|
|
|
break;
|
|
|
|
}
|
2018-10-31 09:12:58 +08:00
|
|
|
case dwarf::DW_RLE_base_address: {
|
2018-04-06 05:01:49 +08:00
|
|
|
if ((End - *OffsetPtr) < Data.getAddressSize())
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"insufficient space remaining in table for "
|
2018-04-06 05:01:49 +08:00
|
|
|
"DW_RLE_base_address encoding at offset 0x%" PRIx32,
|
2018-02-02 20:45:57 +08:00
|
|
|
*OffsetPtr - 1);
|
2018-05-19 04:12:54 +08:00
|
|
|
Value0 = Data.getRelocatedAddress(OffsetPtr, &SectionIndex);
|
2018-04-06 05:01:49 +08:00
|
|
|
break;
|
2018-10-31 09:12:58 +08:00
|
|
|
}
|
|
|
|
case dwarf::DW_RLE_start_end: {
|
2018-04-06 05:01:49 +08:00
|
|
|
if ((End - *OffsetPtr) < unsigned(Data.getAddressSize() * 2))
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"insufficient space remaining in table for "
|
2018-04-06 05:01:49 +08:00
|
|
|
"DW_RLE_start_end encoding "
|
2018-02-02 20:45:57 +08:00
|
|
|
"at offset 0x%" PRIx32,
|
|
|
|
*OffsetPtr - 1);
|
2018-10-31 09:12:58 +08:00
|
|
|
Value0 = Data.getRelocatedAddress(OffsetPtr, &SectionIndex);
|
|
|
|
Value1 = Data.getRelocatedAddress(OffsetPtr);
|
2018-04-06 05:01:49 +08:00
|
|
|
break;
|
2018-10-31 09:12:58 +08:00
|
|
|
}
|
2018-04-06 05:01:49 +08:00
|
|
|
case dwarf::DW_RLE_start_length: {
|
|
|
|
uint32_t PreviousOffset = *OffsetPtr - 1;
|
2018-05-19 04:12:54 +08:00
|
|
|
Value0 = Data.getRelocatedAddress(OffsetPtr, &SectionIndex);
|
2018-04-06 05:01:49 +08:00
|
|
|
Value1 = Data.getULEB128(OffsetPtr);
|
|
|
|
if (End < *OffsetPtr)
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"read past end of table when reading "
|
2018-04-06 05:01:49 +08:00
|
|
|
"DW_RLE_start_length encoding at offset 0x%" PRIx32,
|
|
|
|
PreviousOffset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
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());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::not_supported,
|
|
|
|
"unknown rnglists encoding 0x%" PRIx32
|
2018-04-06 05:01:49 +08:00
|
|
|
" at offset 0x%" PRIx32,
|
|
|
|
uint32_t(Encoding), *OffsetPtr - 1);
|
2018-02-02 20:45:57 +08:00
|
|
|
}
|
|
|
|
|
2018-04-06 05:01:49 +08:00
|
|
|
EntryKind = Encoding;
|
|
|
|
return Error::success();
|
|
|
|
}
|
2018-02-02 20:45:57 +08:00
|
|
|
|
2018-10-20 14:16:25 +08:00
|
|
|
DWARFAddressRangesVector
|
|
|
|
DWARFDebugRnglist::getAbsoluteRanges(llvm::Optional<SectionedAddress> BaseAddr,
|
|
|
|
DWARFUnit &U) const {
|
2018-05-19 04:12:54 +08:00
|
|
|
DWARFAddressRangesVector Res;
|
|
|
|
for (const RangeListEntry &RLE : Entries) {
|
|
|
|
if (RLE.EntryKind == dwarf::DW_RLE_end_of_list)
|
|
|
|
break;
|
2018-10-20 14:16:25 +08:00
|
|
|
if (RLE.EntryKind == dwarf::DW_RLE_base_addressx) {
|
|
|
|
BaseAddr = U.getAddrOffsetSectionItem(RLE.Value0);
|
|
|
|
if (!BaseAddr)
|
|
|
|
BaseAddr = {RLE.Value0, 0};
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-19 04:12:54 +08:00
|
|
|
if (RLE.EntryKind == dwarf::DW_RLE_base_address) {
|
|
|
|
BaseAddr = {RLE.Value0, RLE.SectionIndex};
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWARFAddressRange E;
|
|
|
|
E.SectionIndex = RLE.SectionIndex;
|
|
|
|
if (BaseAddr && E.SectionIndex == -1ULL)
|
|
|
|
E.SectionIndex = BaseAddr->SectionIndex;
|
|
|
|
|
|
|
|
switch (RLE.EntryKind) {
|
|
|
|
case dwarf::DW_RLE_offset_pair:
|
|
|
|
E.LowPC = RLE.Value0;
|
|
|
|
E.HighPC = RLE.Value1;
|
|
|
|
if (BaseAddr) {
|
|
|
|
E.LowPC += BaseAddr->Address;
|
|
|
|
E.HighPC += BaseAddr->Address;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_RLE_start_end:
|
|
|
|
E.LowPC = RLE.Value0;
|
|
|
|
E.HighPC = RLE.Value1;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_RLE_start_length:
|
|
|
|
E.LowPC = RLE.Value0;
|
|
|
|
E.HighPC = E.LowPC + RLE.Value1;
|
|
|
|
break;
|
2018-10-20 14:16:25 +08:00
|
|
|
case dwarf::DW_RLE_startx_length: {
|
|
|
|
auto Start = U.getAddrOffsetSectionItem(RLE.Value0);
|
|
|
|
if (!Start)
|
|
|
|
Start = {0, 0};
|
|
|
|
E.SectionIndex = Start->SectionIndex;
|
|
|
|
E.LowPC = Start->Address;
|
|
|
|
E.HighPC = E.LowPC + RLE.Value1;
|
|
|
|
break;
|
|
|
|
}
|
2018-05-19 04:12:54 +08:00
|
|
|
default:
|
|
|
|
// Unsupported encodings should have been reported during extraction,
|
|
|
|
// so we should not run into any here.
|
|
|
|
llvm_unreachable("Unsupported range list encoding");
|
|
|
|
}
|
|
|
|
Res.push_back(E);
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2018-10-20 14:16:25 +08:00
|
|
|
void RangeListEntry::dump(
|
2018-10-31 09:12:58 +08:00
|
|
|
raw_ostream &OS, uint8_t AddrSize, uint8_t MaxEncodingStringLength,
|
|
|
|
uint64_t &CurrentBase, DIDumpOptions DumpOpts,
|
2018-10-20 14:16:25 +08:00
|
|
|
llvm::function_ref<Optional<SectionedAddress>(uint32_t)>
|
|
|
|
LookupPooledAddress) const {
|
2018-07-24 06:37:17 +08:00
|
|
|
auto PrintRawEntry = [](raw_ostream &OS, const RangeListEntry &Entry,
|
2018-03-28 04:27:36 +08:00
|
|
|
uint8_t AddrSize, DIDumpOptions DumpOpts) {
|
|
|
|
if (DumpOpts.Verbose) {
|
|
|
|
DumpOpts.DisplayRawContents = true;
|
|
|
|
DWARFAddressRange(Entry.Value0, Entry.Value1)
|
|
|
|
.dump(OS, AddrSize, DumpOpts);
|
|
|
|
OS << " => ";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-09 04:52:35 +08:00
|
|
|
if (DumpOpts.Verbose) {
|
|
|
|
// Print the section offset in verbose mode.
|
2018-07-24 06:37:17 +08:00
|
|
|
OS << format("0x%8.8" PRIx32 ":", Offset);
|
2018-10-31 09:12:58 +08:00
|
|
|
auto EncodingString = dwarf::RangeListEncodingString(EntryKind);
|
|
|
|
// Unsupported encodings should have been reported during parsing.
|
|
|
|
assert(!EncodingString.empty() && "Unknown range entry encoding");
|
|
|
|
OS << format(" [%s%*c", EncodingString.data(),
|
|
|
|
MaxEncodingStringLength - EncodingString.size() + 1, ']');
|
|
|
|
if (EntryKind != dwarf::DW_RLE_end_of_list)
|
|
|
|
OS << ": ";
|
2018-03-09 04:52:35 +08:00
|
|
|
}
|
|
|
|
|
2018-07-24 06:37:17 +08:00
|
|
|
switch (EntryKind) {
|
2018-03-09 04:52:35 +08:00
|
|
|
case dwarf::DW_RLE_end_of_list:
|
2018-10-31 09:12:58 +08:00
|
|
|
OS << (DumpOpts.Verbose ? "" : "<End of list>");
|
2018-03-09 04:52:35 +08:00
|
|
|
break;
|
2018-10-20 14:16:25 +08:00
|
|
|
// case dwarf::DW_RLE_base_addressx:
|
|
|
|
case dwarf::DW_RLE_base_addressx: {
|
|
|
|
if (auto SA = LookupPooledAddress(Value0))
|
|
|
|
CurrentBase = SA->Address;
|
|
|
|
else
|
|
|
|
CurrentBase = Value0;
|
|
|
|
if (!DumpOpts.Verbose)
|
|
|
|
return;
|
|
|
|
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
|
|
|
|
break;
|
|
|
|
}
|
2018-03-28 04:27:36 +08:00
|
|
|
case dwarf::DW_RLE_base_address:
|
2018-09-17 23:40:01 +08:00
|
|
|
// In non-verbose mode we do not print anything for this entry.
|
2018-07-24 06:37:17 +08:00
|
|
|
CurrentBase = Value0;
|
2018-03-28 04:27:36 +08:00
|
|
|
if (!DumpOpts.Verbose)
|
|
|
|
return;
|
2018-07-24 06:37:17 +08:00
|
|
|
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
|
2018-03-28 04:27:36 +08:00
|
|
|
break;
|
2018-03-09 04:52:35 +08:00
|
|
|
case dwarf::DW_RLE_start_length:
|
2018-07-24 06:37:17 +08:00
|
|
|
PrintRawEntry(OS, *this, AddrSize, DumpOpts);
|
|
|
|
DWARFAddressRange(Value0, Value0 + Value1).dump(OS, AddrSize, DumpOpts);
|
2018-03-09 04:52:35 +08:00
|
|
|
break;
|
2018-03-28 04:27:36 +08:00
|
|
|
case dwarf::DW_RLE_offset_pair:
|
2018-07-24 06:37:17 +08:00
|
|
|
PrintRawEntry(OS, *this, AddrSize, DumpOpts);
|
|
|
|
DWARFAddressRange(Value0 + CurrentBase, Value1 + CurrentBase)
|
2018-03-28 04:27:36 +08:00
|
|
|
.dump(OS, AddrSize, DumpOpts);
|
|
|
|
break;
|
2018-03-09 04:52:35 +08:00
|
|
|
case dwarf::DW_RLE_start_end:
|
2018-07-24 06:37:17 +08:00
|
|
|
DWARFAddressRange(Value0, Value1).dump(OS, AddrSize, DumpOpts);
|
2018-03-09 04:52:35 +08:00
|
|
|
break;
|
2018-10-20 14:16:25 +08:00
|
|
|
case dwarf::DW_RLE_startx_length: {
|
|
|
|
PrintRawEntry(OS, *this, AddrSize, DumpOpts);
|
|
|
|
uint64_t Start = 0;
|
|
|
|
if (auto SA = LookupPooledAddress(Value0))
|
|
|
|
Start = SA->Address;
|
|
|
|
DWARFAddressRange(Start, Start + Value1).dump(OS, AddrSize, DumpOpts);
|
|
|
|
break;
|
|
|
|
} break;
|
2018-03-09 04:52:35 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported range list encoding");
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
}
|