Skip to content

Commit

Permalink
[DWARF] Use getInitialLength in range list parsing
Browse files Browse the repository at this point in the history
Summary:
This could be considered obvious, but I am putting it up to illustrate
the usefulness/impact of the getInitialLength change.

Reviewers: dblaikie, jhenderson, ikudrin

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75117
  • Loading branch information
labath committed Mar 2, 2020
1 parent d978656 commit 164e2c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
28 changes: 9 additions & 19 deletions llvm/lib/DebugInfo/DWARF/DWARFListTable.cpp
Expand Up @@ -18,25 +18,15 @@ using namespace llvm;
Error DWARFListTableHeader::extract(DWARFDataExtractor Data,
uint64_t *OffsetPtr) {
HeaderOffset = *OffsetPtr;
// Read and verify the length field.
if (!Data.isValidOffsetForDataOfSize(*OffsetPtr, sizeof(uint32_t)))
return createStringError(errc::invalid_argument,
"section is not large enough to contain a "
"%s table length at offset 0x%" PRIx64,
SectionName.data(), *OffsetPtr);
Format = dwarf::DwarfFormat::DWARF32;
uint8_t OffsetByteSize = 4;
HeaderData.Length = Data.getRelocatedValue(4, OffsetPtr);
if (HeaderData.Length == dwarf::DW_LENGTH_DWARF64) {
Format = dwarf::DwarfFormat::DWARF64;
OffsetByteSize = 8;
HeaderData.Length = Data.getU64(OffsetPtr);
} else if (HeaderData.Length >= dwarf::DW_LENGTH_lo_reserved) {
return createStringError(errc::invalid_argument,
"%s table at offset 0x%" PRIx64
" has unsupported reserved unit length of value 0x%8.8" PRIx64,
SectionName.data(), HeaderOffset, HeaderData.Length);
}
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;
uint64_t FullLength =
HeaderData.Length + dwarf::getUnitLengthFieldByteSize(Format);
assert(FullLength == length());
Expand Down
Expand Up @@ -2,7 +2,7 @@
# RUN: llvm-dwarfdump --debug-rnglists - 2>&1 | FileCheck %s --check-prefix=SHORT
# SHORT-NOT: error:
# SHORT-NOT: range list header
# SHORT: error: section is not large enough to contain a .debug_rnglists table length at offset 0
# SHORT: error: parsing .debug_rnglists table at offset 0x0: unexpected end of data at offset 0x0
# SHORT-NOT: range list header
# SHORT-NOT: error:

Expand Down
Expand Up @@ -2,7 +2,7 @@
# RUN: llvm-dwarfdump --debug-rnglists - 2>&1 | \
# RUN: FileCheck %s --implicit-check-not=error

# CHECK: error: .debug_rnglists table at offset 0x0 has unsupported reserved unit length of value 0xfffffff0
# CHECK: error: parsing .debug_rnglists table at offset 0x0: unsupported reserved unit length of value 0xfffffff0

.section .debug_rnglists,"",@progbits
.long 0xfffffff0

0 comments on commit 164e2c8

Please sign in to comment.