aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@fb.com>2024-02-22 10:25:05 -0800
committerGitHub <noreply@github.com>2024-02-22 10:25:05 -0800
commita23d4ceb8866df91334750627827a1724363e755 (patch)
tree5dc41194e8c66cabea2bbc8dfb84a72962475a8e /llvm
parent2e7cacfced573283d5424830f20333e2a6731251 (diff)
downloadllvm-a23d4ceb8866df91334750627827a1724363e755.zip
llvm-a23d4ceb8866df91334750627827a1724363e755.tar.gz
llvm-a23d4ceb8866df91334750627827a1724363e755.tar.bz2
[lldb][llvm] Return an error instead of crashing when parsing a line table prologue. (#80769)
We recently ran into some bad DWARF where the `DW_AT_stmt_list` of many compile units was randomly set to invalid values and was causing LLDB to crash due to an assertion about address sizes not matching. Instead of asserting, we should return an appropriate recoverable `llvm::Error`.
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp22
-rw-r--r--llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp4
2 files changed, 22 insertions, 4 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 28f0564..572628f 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -389,9 +389,25 @@ Error DWARFDebugLine::Prologue::parse(
if (getVersion() >= 5) {
FormParams.AddrSize = DebugLineData.getU8(Cursor);
- assert((!Cursor || DebugLineData.getAddressSize() == 0 ||
- DebugLineData.getAddressSize() == getAddressSize()) &&
- "Line table header and data extractor disagree");
+ const uint8_t DataAddrSize = DebugLineData.getAddressSize();
+ const uint8_t PrologueAddrSize = getAddressSize();
+ if (Cursor) {
+ if (DataAddrSize == 0) {
+ if (PrologueAddrSize != 4 && PrologueAddrSize != 8) {
+ RecoverableErrorHandler(createStringError(
+ errc::not_supported,
+ "parsing line table prologue at offset 0x%8.8" PRIx64
+ ": invalid address size %" PRIu8,
+ PrologueOffset, PrologueAddrSize));
+ }
+ } else if (DataAddrSize != PrologueAddrSize) {
+ RecoverableErrorHandler(createStringError(
+ errc::not_supported,
+ "parsing line table prologue at offset 0x%8.8" PRIx64 ": address "
+ "size %" PRIu8 " doesn't match architecture address size %" PRIu8,
+ PrologueOffset, PrologueAddrSize, DataAddrSize));
+ }
+ }
SegSelectorSize = DebugLineData.getU8(Cursor);
}
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
index d42a626..980b627 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
@@ -823,7 +823,9 @@ TEST_F(DebugLineBasicFixture, ErrorForUnsupportedAddressSizeDefinedInHeader) {
nullptr, RecordRecoverable);
EXPECT_THAT_ERROR(
std::move(Recoverable),
- FailedWithMessage("address size 0x09 of DW_LNE_set_address opcode at "
+ FailedWithMessage("parsing line table prologue at offset 0x00000000: "
+ "invalid address size 9",
+ "address size 0x09 of DW_LNE_set_address opcode at "
"offset 0x00000038 is unsupported"));
ASSERT_THAT_EXPECTED(ExpectedLineTable, Succeeded());
ASSERT_EQ((*ExpectedLineTable)->Rows.size(), 3u);