Skip to content

[lldb][llvm] Return an error instead of crashing when parsing a line table prologue. #80769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this path isn't tested? Could you add a test?

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);
}

Expand Down
4 changes: 3 additions & 1 deletion llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test change removed coverage for a different error message, by failing earlier?

This test should probably be restored by modifying it to be reachable, or the original code's error handling should be turned into an assertion if the diagnostic is now an invariant for the code?

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);
Expand Down