forked from OSchip/llvm-project
Revert "[DebugInfo] Don't error for zero-length arange entries"
This reverts commit cb3a598c87
.
Breaks build of check-llvm dep obj2yaml everywhere.
This commit is contained in:
parent
dcb8d3b722
commit
bc5d68dd8a
|
@ -60,8 +60,7 @@ public:
|
||||||
DWARFDebugArangeSet() { clear(); }
|
DWARFDebugArangeSet() { clear(); }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
Error extract(DWARFDataExtractor data, uint64_t *offset_ptr,
|
Error extract(DWARFDataExtractor data, uint64_t *offset_ptr);
|
||||||
function_ref<void(Error)> WarningHandler);
|
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
|
|
||||||
uint64_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
|
uint64_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
|
||||||
|
|
|
@ -502,8 +502,7 @@ void DWARFContext::dump(
|
||||||
0);
|
0);
|
||||||
DWARFDebugArangeSet set;
|
DWARFDebugArangeSet set;
|
||||||
while (arangesData.isValidOffset(offset)) {
|
while (arangesData.isValidOffset(offset)) {
|
||||||
if (Error E =
|
if (Error E = set.extract(arangesData, &offset)) {
|
||||||
set.extract(arangesData, &offset, DumpOpts.WarningHandler)) {
|
|
||||||
RecoverableErrorHandler(std::move(E));
|
RecoverableErrorHandler(std::move(E));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,7 @@ void DWARFDebugArangeSet::clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error DWARFDebugArangeSet::extract(DWARFDataExtractor data,
|
Error DWARFDebugArangeSet::extract(DWARFDataExtractor data,
|
||||||
uint64_t *offset_ptr,
|
uint64_t *offset_ptr) {
|
||||||
function_ref<void(Error)> WarningHandler) {
|
|
||||||
assert(data.isValidOffset(*offset_ptr));
|
assert(data.isValidOffset(*offset_ptr));
|
||||||
ArangeDescriptors.clear();
|
ArangeDescriptors.clear();
|
||||||
Offset = *offset_ptr;
|
Offset = *offset_ptr;
|
||||||
|
@ -133,20 +132,19 @@ Error DWARFDebugArangeSet::extract(DWARFDataExtractor data,
|
||||||
|
|
||||||
uint64_t end_offset = Offset + full_length;
|
uint64_t end_offset = Offset + full_length;
|
||||||
while (*offset_ptr < end_offset) {
|
while (*offset_ptr < end_offset) {
|
||||||
uint64_t EntryOffset = *offset_ptr;
|
|
||||||
arangeDescriptor.Address = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
|
arangeDescriptor.Address = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
|
||||||
arangeDescriptor.Length = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
|
arangeDescriptor.Length = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
|
||||||
|
|
||||||
// Each set of tuples is terminated by a 0 for the address and 0
|
if (arangeDescriptor.Length == 0) {
|
||||||
// for the length.
|
// Each set of tuples is terminated by a 0 for the address and 0
|
||||||
if (arangeDescriptor.Length == 0 && arangeDescriptor.Address == 0) {
|
// for the length.
|
||||||
if (*offset_ptr == end_offset)
|
if (arangeDescriptor.Address == 0 && *offset_ptr == end_offset)
|
||||||
return ErrorSuccess();
|
return ErrorSuccess();
|
||||||
WarningHandler(createStringError(
|
return createStringError(
|
||||||
errc::invalid_argument,
|
errc::invalid_argument,
|
||||||
"address range table at offset 0x%" PRIx64
|
"address range table at offset 0x%" PRIx64
|
||||||
" has a premature terminator entry at offset 0x%" PRIx64,
|
" has an invalid tuple (length = 0) at offset 0x%" PRIx64,
|
||||||
Offset, EntryOffset));
|
Offset, *offset_ptr - tuple_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArangeDescriptors.push_back(arangeDescriptor);
|
ArangeDescriptors.push_back(arangeDescriptor);
|
||||||
|
|
|
@ -28,8 +28,7 @@ void DWARFDebugAranges::extract(
|
||||||
DWARFDebugArangeSet Set;
|
DWARFDebugArangeSet Set;
|
||||||
|
|
||||||
while (DebugArangesData.isValidOffset(Offset)) {
|
while (DebugArangesData.isValidOffset(Offset)) {
|
||||||
if (Error E =
|
if (Error E = Set.extract(DebugArangesData, &Offset)) {
|
||||||
Set.extract(DebugArangesData, &Offset, RecoverableErrorHandler)) {
|
|
||||||
RecoverableErrorHandler(std::move(E));
|
RecoverableErrorHandler(std::move(E));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,23 +7,12 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
|
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
|
||||||
#include "llvm/Testing/Support/Error.h"
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct WarningHandler {
|
|
||||||
~WarningHandler() { EXPECT_THAT_ERROR(std::move(Err), Succeeded()); }
|
|
||||||
|
|
||||||
void operator()(Error E) { Err = joinErrors(std::move(Err), std::move(E)); }
|
|
||||||
|
|
||||||
Error getWarning() { return std::move(Err); }
|
|
||||||
|
|
||||||
Error Err = Error::success();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <size_t SecSize>
|
template <size_t SecSize>
|
||||||
void ExpectExtractError(const char (&SecDataRaw)[SecSize],
|
void ExpectExtractError(const char (&SecDataRaw)[SecSize],
|
||||||
const char *ErrorMessage) {
|
const char *ErrorMessage) {
|
||||||
|
@ -32,8 +21,7 @@ void ExpectExtractError(const char (&SecDataRaw)[SecSize],
|
||||||
/* AddressSize = */ 4);
|
/* AddressSize = */ 4);
|
||||||
DWARFDebugArangeSet Set;
|
DWARFDebugArangeSet Set;
|
||||||
uint64_t Offset = 0;
|
uint64_t Offset = 0;
|
||||||
WarningHandler Warnings;
|
Error E = Set.extract(Extractor, &Offset);
|
||||||
Error E = Set.extract(Extractor, &Offset, Warnings);
|
|
||||||
ASSERT_TRUE(E.operator bool());
|
ASSERT_TRUE(E.operator bool());
|
||||||
EXPECT_STREQ(ErrorMessage, toString(std::move(E)).c_str());
|
EXPECT_STREQ(ErrorMessage, toString(std::move(E)).c_str());
|
||||||
}
|
}
|
||||||
|
@ -178,61 +166,7 @@ TEST(DWARFDebugArangeSet, UnevenLength) {
|
||||||
"of the tuple size");
|
"of the tuple size");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DWARFDebugArangeSet, ZeroAddressEntry) {
|
|
||||||
static const char DebugArangesSecRaw[] =
|
|
||||||
"\x1c\x00\x00\x00" // Length
|
|
||||||
"\x02\x00" // Version
|
|
||||||
"\x00\x00\x00\x00" // Debug Info Offset
|
|
||||||
"\x04" // Address Size
|
|
||||||
"\x00" // Segment Selector Size
|
|
||||||
"\x00\x00\x00\x00" // Padding
|
|
||||||
"\x00\x00\x00\x00" // Entry1: Address
|
|
||||||
"\x01\x00\x00\x00" // Length
|
|
||||||
"\x00\x00\x00\x00" // Termination tuple
|
|
||||||
"\x00\x00\x00\x00";
|
|
||||||
DWARFDataExtractor Extractor(
|
|
||||||
StringRef(DebugArangesSecRaw, sizeof(DebugArangesSecRaw) - 1),
|
|
||||||
/*IsLittleEndian=*/true,
|
|
||||||
/*AddressSize=*/4);
|
|
||||||
DWARFDebugArangeSet Set;
|
|
||||||
uint64_t Offset = 0;
|
|
||||||
ASSERT_THAT_ERROR(Set.extract(Extractor, &Offset, WarningHandler()),
|
|
||||||
Succeeded());
|
|
||||||
auto Range = Set.descriptors();
|
|
||||||
auto Iter = Range.begin();
|
|
||||||
ASSERT_EQ(std::distance(Iter, Range.end()), 1u);
|
|
||||||
EXPECT_EQ(Iter->Address, 0u);
|
|
||||||
EXPECT_EQ(Iter->Length, 1u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(DWARFDebugArangeSet, ZeroLengthEntry) {
|
TEST(DWARFDebugArangeSet, ZeroLengthEntry) {
|
||||||
static const char DebugArangesSecRaw[] =
|
|
||||||
"\x1c\x00\x00\x00" // Length
|
|
||||||
"\x02\x00" // Version
|
|
||||||
"\x00\x00\x00\x00" // Debug Info Offset
|
|
||||||
"\x04" // Address Size
|
|
||||||
"\x00" // Segment Selector Size
|
|
||||||
"\x00\x00\x00\x00" // Padding
|
|
||||||
"\x01\x00\x00\x00" // Entry1: Address
|
|
||||||
"\x00\x00\x00\x00" // Length
|
|
||||||
"\x00\x00\x00\x00" // Termination tuple
|
|
||||||
"\x00\x00\x00\x00";
|
|
||||||
DWARFDataExtractor Extractor(
|
|
||||||
StringRef(DebugArangesSecRaw, sizeof(DebugArangesSecRaw) - 1),
|
|
||||||
/*IsLittleEndian=*/true,
|
|
||||||
/*AddressSize=*/4);
|
|
||||||
DWARFDebugArangeSet Set;
|
|
||||||
uint64_t Offset = 0;
|
|
||||||
ASSERT_THAT_ERROR(Set.extract(Extractor, &Offset, WarningHandler()),
|
|
||||||
Succeeded());
|
|
||||||
auto Range = Set.descriptors();
|
|
||||||
auto Iter = Range.begin();
|
|
||||||
ASSERT_EQ(std::distance(Iter, Range.end()), 1u);
|
|
||||||
EXPECT_EQ(Iter->Address, 1u);
|
|
||||||
EXPECT_EQ(Iter->Length, 0u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(DWARFDebugArangesSet, PrematureTerminator) {
|
|
||||||
static const char DebugArangesSecRaw[] =
|
static const char DebugArangesSecRaw[] =
|
||||||
"\x24\x00\x00\x00" // Length
|
"\x24\x00\x00\x00" // Length
|
||||||
"\x02\x00" // Version
|
"\x02\x00" // Version
|
||||||
|
@ -240,32 +174,16 @@ TEST(DWARFDebugArangesSet, PrematureTerminator) {
|
||||||
"\x04" // Address Size
|
"\x04" // Address Size
|
||||||
"\x00" // Segment Selector Size
|
"\x00" // Segment Selector Size
|
||||||
"\x00\x00\x00\x00" // Padding
|
"\x00\x00\x00\x00" // Padding
|
||||||
"\x00\x00\x00\x00" // Entry1: Premature
|
"\x00\x00\x00\x00" // Entry1: Address
|
||||||
"\x00\x00\x00\x00" // terminator
|
|
||||||
"\x01\x00\x00\x00" // Entry2: Address
|
|
||||||
"\x01\x00\x00\x00" // Length
|
"\x01\x00\x00\x00" // Length
|
||||||
|
"\x01\x00\x00\x00" // Entry2: Address
|
||||||
|
"\x00\x00\x00\x00" // Length (invalid)
|
||||||
"\x00\x00\x00\x00" // Termination tuple
|
"\x00\x00\x00\x00" // Termination tuple
|
||||||
"\x00\x00\x00\x00";
|
"\x00\x00\x00\x00";
|
||||||
DWARFDataExtractor Extractor(
|
ExpectExtractError(
|
||||||
StringRef(DebugArangesSecRaw, sizeof(DebugArangesSecRaw) - 1),
|
DebugArangesSecRaw,
|
||||||
/*IsLittleEndian=*/true,
|
"address range table at offset 0x0 has an invalid tuple (length = 0) "
|
||||||
/*AddressSize=*/4);
|
"at offset 0x18");
|
||||||
DWARFDebugArangeSet Set;
|
|
||||||
uint64_t Offset = 0;
|
|
||||||
WarningHandler Warnings;
|
|
||||||
ASSERT_THAT_ERROR(Set.extract(Extractor, &Offset, Warnings), Succeeded());
|
|
||||||
auto Range = Set.descriptors();
|
|
||||||
auto Iter = Range.begin();
|
|
||||||
ASSERT_EQ(std::distance(Iter, Range.end()), 2u);
|
|
||||||
EXPECT_EQ(Iter->Address, 0u);
|
|
||||||
EXPECT_EQ(Iter->Length, 0u);
|
|
||||||
++Iter;
|
|
||||||
EXPECT_EQ(Iter->Address, 1u);
|
|
||||||
EXPECT_EQ(Iter->Length, 1u);
|
|
||||||
EXPECT_THAT_ERROR(
|
|
||||||
Warnings.getWarning(),
|
|
||||||
FailedWithMessage("address range table at offset 0x0 has a premature "
|
|
||||||
"terminator entry at offset 0x10"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
Loading…
Reference in New Issue