2018-07-24 06:37:17 +08:00
|
|
|
//===- DWARFListTable.cpp ---------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-07-24 06:37:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFListTable.h"
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.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-07-24 06:37:17 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
Error DWARFListTableHeader::extract(DWARFDataExtractor Data,
|
2019-08-06 18:49:40 +08:00
|
|
|
uint64_t *OffsetPtr) {
|
2018-07-24 06:37:17 +08:00
|
|
|
HeaderOffset = *OffsetPtr;
|
2020-02-25 22:17:57 +08:00
|
|
|
Error Err = Error::success();
|
|
|
|
|
|
|
|
std::tie(HeaderData.Length, Format) = Data.getInitialLength(OffsetPtr, &Err);
|
|
|
|
if (Err)
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument, "parsing %s table at offset 0x%" PRIx64 ": %s",
|
|
|
|
SectionName.data(), HeaderOffset, toString(std::move(Err)).c_str());
|
|
|
|
|
|
|
|
uint8_t OffsetByteSize = Format == dwarf::DWARF64 ? 8 : 4;
|
2019-09-05 14:49:05 +08:00
|
|
|
uint64_t FullLength =
|
|
|
|
HeaderData.Length + dwarf::getUnitLengthFieldByteSize(Format);
|
|
|
|
if (FullLength < getHeaderSize(Format))
|
2018-09-17 23:40:01 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-08-06 18:49:40 +08:00
|
|
|
"%s table at offset 0x%" PRIx64
|
2019-09-05 14:49:05 +08:00
|
|
|
" has too small length (0x%" PRIx64
|
2018-10-31 09:12:58 +08:00
|
|
|
") to contain a complete header",
|
2019-09-05 14:49:05 +08:00
|
|
|
SectionName.data(), HeaderOffset, FullLength);
|
2020-07-14 16:55:31 +08:00
|
|
|
assert(FullLength == length() && "Inconsistent calculation of length.");
|
2019-09-05 14:49:05 +08:00
|
|
|
uint64_t End = HeaderOffset + FullLength;
|
|
|
|
if (!Data.isValidOffsetForDataOfSize(HeaderOffset, FullLength))
|
2018-10-31 09:12:58 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"section is not large enough to contain a %s table "
|
2019-09-05 14:49:05 +08:00
|
|
|
"of length 0x%" PRIx64 " at offset 0x%" PRIx64,
|
|
|
|
SectionName.data(), FullLength, HeaderOffset);
|
2018-07-24 06:37:17 +08:00
|
|
|
|
|
|
|
HeaderData.Version = Data.getU16(OffsetPtr);
|
|
|
|
HeaderData.AddrSize = Data.getU8(OffsetPtr);
|
|
|
|
HeaderData.SegSize = Data.getU8(OffsetPtr);
|
|
|
|
HeaderData.OffsetEntryCount = Data.getU32(OffsetPtr);
|
|
|
|
|
|
|
|
// Perform basic validation of the remaining header fields.
|
2018-10-31 09:12:58 +08:00
|
|
|
if (HeaderData.Version != 5)
|
[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,
|
2018-10-31 09:12:58 +08:00
|
|
|
"unrecognised %s table version %" PRIu16
|
2019-08-06 18:49:40 +08:00
|
|
|
" in table at offset 0x%" PRIx64,
|
2018-10-31 09:12:58 +08:00
|
|
|
SectionName.data(), HeaderData.Version, HeaderOffset);
|
|
|
|
if (HeaderData.AddrSize != 4 && HeaderData.AddrSize != 8)
|
[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,
|
2019-08-06 18:49:40 +08:00
|
|
|
"%s table at offset 0x%" PRIx64
|
[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
|
|
|
" has unsupported address size %" PRIu8,
|
2018-07-24 06:37:17 +08:00
|
|
|
SectionName.data(), HeaderOffset, HeaderData.AddrSize);
|
2018-10-31 09:12:58 +08:00
|
|
|
if (HeaderData.SegSize != 0)
|
[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,
|
2019-08-06 18:49:40 +08:00
|
|
|
"%s table at offset 0x%" PRIx64
|
2018-07-24 06:37:17 +08:00
|
|
|
" has unsupported segment selector size %" PRIu8,
|
|
|
|
SectionName.data(), HeaderOffset, HeaderData.SegSize);
|
2019-09-05 14:49:05 +08:00
|
|
|
if (End < HeaderOffset + getHeaderSize(Format) +
|
|
|
|
HeaderData.OffsetEntryCount * OffsetByteSize)
|
[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,
|
2019-08-06 18:49:40 +08:00
|
|
|
"%s table at offset 0x%" PRIx64 " has more offset entries (%" PRIu32
|
2018-07-24 06:37:17 +08:00
|
|
|
") than there is space for",
|
|
|
|
SectionName.data(), HeaderOffset, HeaderData.OffsetEntryCount);
|
|
|
|
Data.setAddressSize(HeaderData.AddrSize);
|
[WIP][DebugInfo] Lazily parse debug_loclist offsets
Parsing DWARFv5 debug_loclist offsets when a CU is parsed is weighing
down memory usage of symbolizers that don't need to parse this data at
all. There's not much benefit to caching these anyway - since they are
O(1) lookup and reading once you know where the offset list starts (and
can do bounds checking with the offset list size too).
In general, I think it might be time to start paying down some of the
technical debt of loc/loclist/range/rnglist parsing to try to unify it a
bit more.
eg:
* Currently DWARFUnit has: RangeSection, RangeSectionBase, LocSection,
LocSectionBase, LocTable, RngListTable, LoclistTableHeader (be nice if
these were all wrapped up in two variables - one for loclists, one for
rnglists)
* rnglists and loclists are handled differently (see:
LoclistTableHeader, but no RnglistTableHeader)
* maybe all these types could be less stateful - lazily parse what they
need to, even reparsing rather than caching because it doesn't seem
too expensive, for instance. (though admittedly so long as it's
constantcost/overead per compilatiton that's probably adequate)
* Maybe implementing and using a DWARFDataExtractor that can be
sub-ranged (so we could slice it up to just the single contribution) -
though maybe that's not so useful because loc/ranges need to refer to
it by absolute, not contribution-relative mechanisms
Differential Revision: https://reviews.llvm.org/D86110
2020-08-14 22:56:29 +08:00
|
|
|
*OffsetPtr += HeaderData.OffsetEntryCount * OffsetByteSize;
|
2018-07-24 06:37:17 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
[WIP][DebugInfo] Lazily parse debug_loclist offsets
Parsing DWARFv5 debug_loclist offsets when a CU is parsed is weighing
down memory usage of symbolizers that don't need to parse this data at
all. There's not much benefit to caching these anyway - since they are
O(1) lookup and reading once you know where the offset list starts (and
can do bounds checking with the offset list size too).
In general, I think it might be time to start paying down some of the
technical debt of loc/loclist/range/rnglist parsing to try to unify it a
bit more.
eg:
* Currently DWARFUnit has: RangeSection, RangeSectionBase, LocSection,
LocSectionBase, LocTable, RngListTable, LoclistTableHeader (be nice if
these were all wrapped up in two variables - one for loclists, one for
rnglists)
* rnglists and loclists are handled differently (see:
LoclistTableHeader, but no RnglistTableHeader)
* maybe all these types could be less stateful - lazily parse what they
need to, even reparsing rather than caching because it doesn't seem
too expensive, for instance. (though admittedly so long as it's
constantcost/overead per compilatiton that's probably adequate)
* Maybe implementing and using a DWARFDataExtractor that can be
sub-ranged (so we could slice it up to just the single contribution) -
though maybe that's not so useful because loc/ranges need to refer to
it by absolute, not contribution-relative mechanisms
Differential Revision: https://reviews.llvm.org/D86110
2020-08-14 22:56:29 +08:00
|
|
|
void DWARFListTableHeader::dump(DataExtractor Data, raw_ostream &OS,
|
|
|
|
DIDumpOptions DumpOpts) const {
|
2018-07-24 06:37:17 +08:00
|
|
|
if (DumpOpts.Verbose)
|
2019-08-06 18:49:40 +08:00
|
|
|
OS << format("0x%8.8" PRIx64 ": ", HeaderOffset);
|
2020-05-19 14:35:41 +08:00
|
|
|
int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format);
|
2020-06-02 17:11:02 +08:00
|
|
|
OS << format("%s list header: length = 0x%0*" PRIx64, ListTypeString.data(),
|
|
|
|
OffsetDumpWidth, HeaderData.Length)
|
|
|
|
<< ", format = " << dwarf::FormatString(Format)
|
|
|
|
<< format(", version = 0x%4.4" PRIx16 ", addr_size = 0x%2.2" PRIx8
|
2020-05-19 14:35:41 +08:00
|
|
|
", seg_size = 0x%2.2" PRIx8
|
|
|
|
", offset_entry_count = 0x%8.8" PRIx32 "\n",
|
|
|
|
HeaderData.Version, HeaderData.AddrSize, HeaderData.SegSize,
|
|
|
|
HeaderData.OffsetEntryCount);
|
2018-07-24 06:37:17 +08:00
|
|
|
|
|
|
|
if (HeaderData.OffsetEntryCount > 0) {
|
|
|
|
OS << "offsets: [";
|
[WIP][DebugInfo] Lazily parse debug_loclist offsets
Parsing DWARFv5 debug_loclist offsets when a CU is parsed is weighing
down memory usage of symbolizers that don't need to parse this data at
all. There's not much benefit to caching these anyway - since they are
O(1) lookup and reading once you know where the offset list starts (and
can do bounds checking with the offset list size too).
In general, I think it might be time to start paying down some of the
technical debt of loc/loclist/range/rnglist parsing to try to unify it a
bit more.
eg:
* Currently DWARFUnit has: RangeSection, RangeSectionBase, LocSection,
LocSectionBase, LocTable, RngListTable, LoclistTableHeader (be nice if
these were all wrapped up in two variables - one for loclists, one for
rnglists)
* rnglists and loclists are handled differently (see:
LoclistTableHeader, but no RnglistTableHeader)
* maybe all these types could be less stateful - lazily parse what they
need to, even reparsing rather than caching because it doesn't seem
too expensive, for instance. (though admittedly so long as it's
constantcost/overead per compilatiton that's probably adequate)
* Maybe implementing and using a DWARFDataExtractor that can be
sub-ranged (so we could slice it up to just the single contribution) -
though maybe that's not so useful because loc/ranges need to refer to
it by absolute, not contribution-relative mechanisms
Differential Revision: https://reviews.llvm.org/D86110
2020-08-14 22:56:29 +08:00
|
|
|
for (uint32_t I = 0; I < HeaderData.OffsetEntryCount; ++I) {
|
|
|
|
auto Off = *getOffsetEntry(Data, I);
|
2020-05-19 14:35:41 +08:00
|
|
|
OS << format("\n0x%0*" PRIx64, OffsetDumpWidth, Off);
|
2018-07-24 06:37:17 +08:00
|
|
|
if (DumpOpts.Verbose)
|
2020-05-19 14:35:41 +08:00
|
|
|
OS << format(" => 0x%08" PRIx64,
|
2019-09-05 14:49:05 +08:00
|
|
|
Off + HeaderOffset + getHeaderSize(Format));
|
2018-07-24 06:37:17 +08:00
|
|
|
}
|
|
|
|
OS << "\n]\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 14:49:05 +08:00
|
|
|
uint64_t DWARFListTableHeader::length() const {
|
2018-07-24 06:37:17 +08:00
|
|
|
if (HeaderData.Length == 0)
|
|
|
|
return 0;
|
2019-09-05 14:49:05 +08:00
|
|
|
return HeaderData.Length + dwarf::getUnitLengthFieldByteSize(Format);
|
2018-07-24 06:37:17 +08:00
|
|
|
}
|