[llvm] eb2b17e - Use DWARFDataExtractor::getInitialLength in debug_aranges
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 04:12:14 PST 2020
Author: Pavel Labath
Date: 2020-03-04T13:01:07+01:00
New Revision: eb2b17eea7785bb790dab11cff1e3365cd3218cc
URL: https://github.com/llvm/llvm-project/commit/eb2b17eea7785bb790dab11cff1e3365cd3218cc
DIFF: https://github.com/llvm/llvm-project/commit/eb2b17eea7785bb790dab11cff1e3365cd3218cc.diff
LOG: Use DWARFDataExtractor::getInitialLength in debug_aranges
Summary:
getInitialLength is a *DWARF*DataExtractor method so I had to "upgrade"
some DataExtractors to be able to make use of it.
Reviewers: ikudrin, jhenderson, probinson
Subscribers: aprantl, hiraditya, llvm-commits, dblaikie
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75535
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
llvm/tools/obj2yaml/dwarf2yaml.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h
index 806ad05b22bb..92c46057fe5c 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h
@@ -10,7 +10,7 @@
#define LLVM_DEBUGINFO_DWARFDEBUGARANGESET_H
#include "llvm/ADT/iterator_range.h"
-#include "llvm/Support/DataExtractor.h"
+#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <vector>
@@ -58,7 +58,7 @@ class DWARFDebugArangeSet {
DWARFDebugArangeSet() { clear(); }
void clear();
- Error extract(DataExtractor data, uint64_t *offset_ptr);
+ Error extract(DWARFDataExtractor data, uint64_t *offset_ptr);
void dump(raw_ostream &OS) const;
uint64_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
index cd04bf1f0369..31a8b462ef71 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
@@ -10,7 +10,7 @@
#define LLVM_DEBUGINFO_DWARFDEBUGARANGES_H
#include "llvm/ADT/DenseSet.h"
-#include "llvm/Support/DataExtractor.h"
+#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include <cstdint>
#include <vector>
@@ -25,7 +25,7 @@ class DWARFDebugAranges {
private:
void clear();
- void extract(DataExtractor DebugArangesData,
+ void extract(DWARFDataExtractor DebugArangesData,
function_ref<void(Error)> RecoverableErrorHandler);
/// Call appendRange multiple times and then call construct.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index d08f1e05bf80..7541bb794c73 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -457,7 +457,8 @@ void DWARFContext::dump(
if (shouldDump(Explicit, ".debug_aranges", DIDT_ID_DebugAranges,
DObj->getArangesSection())) {
uint64_t offset = 0;
- DataExtractor arangesData(DObj->getArangesSection(), isLittleEndian(), 0);
+ DWARFDataExtractor arangesData(DObj->getArangesSection(), isLittleEndian(),
+ 0);
DWARFDebugArangeSet set;
while (arangesData.isValidOffset(offset)) {
if (Error E = set.extract(arangesData, &offset)) {
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
index c4af6cf4d80d..9d640b84b33b 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
@@ -31,7 +31,8 @@ void DWARFDebugArangeSet::clear() {
ArangeDescriptors.clear();
}
-Error DWARFDebugArangeSet::extract(DataExtractor data, uint64_t *offset_ptr) {
+Error DWARFDebugArangeSet::extract(DWARFDataExtractor data,
+ uint64_t *offset_ptr) {
assert(data.isValidOffset(*offset_ptr));
ArangeDescriptors.clear();
Offset = *offset_ptr;
@@ -59,45 +60,20 @@ Error DWARFDebugArangeSet::extract(DataExtractor data, uint64_t *offset_ptr) {
// the segment selectors are omitted from all tuples, including
// the terminating tuple.
- constexpr unsigned CommonFieldsLength = 2 + // Version
- 1 + // Address Size
- 1; // Segment Selector Size
- static const unsigned DWARF32HeaderLength =
- dwarf::getUnitLengthFieldByteSize(dwarf::DWARF32) + CommonFieldsLength +
- dwarf::getDwarfOffsetByteSize(dwarf::DWARF32); // Debug Info Offset
- static const unsigned DWARF64HeaderLength =
- dwarf::getUnitLengthFieldByteSize(dwarf::DWARF64) + CommonFieldsLength +
- dwarf::getDwarfOffsetByteSize(dwarf::DWARF64); // Debug Info Offset
-
- if (!data.isValidOffsetForDataOfSize(Offset, DWARF32HeaderLength))
+ dwarf::DwarfFormat format;
+ Error Err = Error::success();
+ std::tie(HeaderData.Length, format) = data.getInitialLength(offset_ptr, &Err);
+ HeaderData.Version = data.getU16(offset_ptr, &Err);
+ HeaderData.CuOffset =
+ data.getUnsigned(offset_ptr, dwarf::getDwarfOffsetByteSize(format), &Err);
+ HeaderData.AddrSize = data.getU8(offset_ptr, &Err);
+ HeaderData.SegSize = data.getU8(offset_ptr, &Err);
+ if (Err) {
return createStringError(errc::invalid_argument,
- "section is not large enough to contain "
- "an address range table at offset 0x%" PRIx64,
- Offset);
-
- dwarf::DwarfFormat format = dwarf::DWARF32;
- HeaderData.Length = data.getU32(offset_ptr);
- if (HeaderData.Length == dwarf::DW_LENGTH_DWARF64) {
- if (!data.isValidOffsetForDataOfSize(Offset, DWARF64HeaderLength))
- return createStringError(
- errc::invalid_argument,
- "section is not large enough to contain a DWARF64 "
- "address range table at offset 0x%" PRIx64,
- Offset);
- HeaderData.Length = data.getU64(offset_ptr);
- format = dwarf::DWARF64;
- } else if (HeaderData.Length >= dwarf::DW_LENGTH_lo_reserved) {
- return createStringError(
- errc::invalid_argument,
- "address range table at offset 0x%" PRIx64
- " has unsupported reserved unit length of value 0x%8.8" PRIx64,
- Offset, HeaderData.Length);
+ "parsing address ranges table at offset 0x%" PRIx64
+ ": %s",
+ Offset, toString(std::move(Err)).c_str());
}
- HeaderData.Version = data.getU16(offset_ptr);
- HeaderData.CuOffset =
- data.getUnsigned(offset_ptr, dwarf::getDwarfOffsetByteSize(format));
- HeaderData.AddrSize = data.getU8(offset_ptr);
- HeaderData.SegSize = data.getU8(offset_ptr);
// Perform basic validation of the header fields.
uint64_t full_length =
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
index 034484407835..e8ed63075055 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
@@ -20,7 +20,7 @@
using namespace llvm;
void DWARFDebugAranges::extract(
- DataExtractor DebugArangesData,
+ DWARFDataExtractor DebugArangesData,
function_ref<void(Error)> RecoverableErrorHandler) {
if (!DebugArangesData.isValidOffset(0))
return;
@@ -48,8 +48,8 @@ void DWARFDebugAranges::generate(DWARFContext *CTX) {
return;
// Extract aranges from .debug_aranges section.
- DataExtractor ArangesData(CTX->getDWARFObj().getArangesSection(),
- CTX->isLittleEndian(), 0);
+ DWARFDataExtractor ArangesData(CTX->getDWARFObj().getArangesSection(),
+ CTX->isLittleEndian(), 0);
extract(ArangesData, CTX->getRecoverableErrorHandler());
// Generate aranges from DIEs: even if .debug_aranges section is present,
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 524f43e71bd5..edb1b547b0f5 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -57,8 +57,8 @@ void dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) {
}
Error dumpDebugARanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
- DataExtractor ArangesData(DCtx.getDWARFObj().getArangesSection(),
- DCtx.isLittleEndian(), 0);
+ DWARFDataExtractor ArangesData(DCtx.getDWARFObj().getArangesSection(),
+ DCtx.isLittleEndian(), 0);
uint64_t Offset = 0;
DWARFDebugArangeSet Set;
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp
index fb5405bc1837..5629a0d071c7 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugArangeSetTest.cpp
@@ -16,9 +16,9 @@ namespace {
template <size_t SecSize>
void ExpectExtractError(const char (&SecDataRaw)[SecSize],
const char *ErrorMessage) {
- DataExtractor Extractor(StringRef(SecDataRaw, SecSize - 1),
- /* IsLittleEndian = */ true,
- /* AddressSize = */ 4);
+ DWARFDataExtractor Extractor(StringRef(SecDataRaw, SecSize - 1),
+ /* IsLittleEndian = */ true,
+ /* AddressSize = */ 4);
DWARFDebugArangeSet Set;
uint64_t Offset = 0;
Error E = Set.extract(Extractor, &Offset);
@@ -111,29 +111,26 @@ TEST(DWARFDebugArangeSet, ReservedUnitLength) {
// the section. 1 will be automatically subtracted in ExpectExtractError().
static const char DebugArangesSecRaw[12 + 1] =
"\xf0\xff\xff\xff"; // Reserved unit length value
- ExpectExtractError(
- DebugArangesSecRaw,
- "address range table at offset 0x0 has unsupported reserved unit length "
- "of value 0xfffffff0");
+ ExpectExtractError(DebugArangesSecRaw,
+ "parsing address ranges table at offset 0x0: unsupported "
+ "reserved unit length of value 0xfffffff0");
}
TEST(DWARFDebugArangeSet, SectionTooShort) {
// Note: 1 will be automatically subtracted in ExpectExtractError().
static const char DebugArangesSecRaw[11 + 1] = {0};
- ExpectExtractError(
- DebugArangesSecRaw,
- "section is not large enough to contain an address range table "
- "at offset 0x0");
+ ExpectExtractError(DebugArangesSecRaw,
+ "parsing address ranges table at offset 0x0: unexpected "
+ "end of data at offset 0xb");
}
TEST(DWARFDebugArangeSet, SectionTooShortDWARF64) {
// Note: 1 will be automatically subtracted in ExpectExtractError().
static const char DebugArangesSecRaw[23 + 1] =
"\xff\xff\xff\xff"; // DWARF64 mark
- ExpectExtractError(
- DebugArangesSecRaw,
- "section is not large enough to contain a DWARF64 address range table "
- "at offset 0x0");
+ ExpectExtractError(DebugArangesSecRaw,
+ "parsing address ranges table at offset 0x0: unexpected "
+ "end of data at offset 0x17");
}
TEST(DWARFDebugArangeSet, NoSpaceForEntries) {
More information about the llvm-commits
mailing list