diff options
author | Pavel Labath <pavel@labath.sk> | 2020-04-02 15:32:59 +0200 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2020-06-10 16:12:53 +0200 |
commit | 6f55b5a101d95b1049643f87a6572b36d6b4b44c (patch) | |
tree | 8407f67b770f1996868314ad986fcf71f605be82 /llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp | |
parent | 4e3a44d42eace1924c9cba3b7c1ea9cdbbd6cb48 (diff) | |
download | llvm-6f55b5a101d95b1049643f87a6572b36d6b4b44c.zip llvm-6f55b5a101d95b1049643f87a6572b36d6b4b44c.tar.gz llvm-6f55b5a101d95b1049643f87a6572b36d6b4b44c.tar.bz2 |
[DWARFDebugLine] Use truncating data extractors for prologue parsing
Summary:
This makes the code easier to reason about, as it will behave the same
way regardless of whether there is any more data coming after the
presumed end of the prologue.
Reviewers: jhenderson, dblaikie, probinson, ikudrin
Subscribers: hiraditya, MaskRay, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77557
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp index a7a8f93..d00d4c89 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp @@ -423,12 +423,13 @@ TEST_P(DebugLineParameterisedFixture, ErrorForTooLargePrologueLength) { Prologue.TotalLength + 1 + Prologue.sizeofTotalLength(); EXPECT_THAT_ERROR( std::move(Recoverable), - FailedWithMessage(("parsing line table prologue at 0x00000000 should " - "have ended at 0x000000" + - Twine::utohexstr(ExpectedEnd) + - " but it ended at 0x000000" + - Twine::utohexstr(ExpectedEnd - 1)) - .str())); + FailedWithMessage( + ("unknown data in line table prologue at offset 0x00000000: " + "parsing ended (at offset 0x000000" + + Twine::utohexstr(ExpectedEnd - 1) + + ") before reaching the prologue at offset 0x000000" + + Twine::utohexstr(ExpectedEnd)) + .str())); } TEST_P(DebugLineParameterisedFixture, ErrorForTooShortPrologueLength) { @@ -450,37 +451,28 @@ TEST_P(DebugLineParameterisedFixture, ErrorForTooShortPrologueLength) { ASSERT_THAT_EXPECTED(ExpectedLineTable, Succeeded()); DWARFDebugLine::LineTable Result(**ExpectedLineTable); - if (Version != 5) { - // Parsing will stop before reading a complete file entry. - ASSERT_EQ(Result.Prologue.IncludeDirectories.size(), 1u); - EXPECT_EQ(toStringRef(Result.Prologue.IncludeDirectories[0]), "a dir"); - EXPECT_EQ(Result.Prologue.FileNames.size(), 0u); - } else { - // Parsing will continue past the presumed end of prologue. - ASSERT_EQ(Result.Prologue.FileNames.size(), 1u); - ASSERT_EQ(Result.Prologue.FileNames[0].Name.getForm(), DW_FORM_string); - ASSERT_EQ(Result.Prologue.FileNames[0].DirIdx, 0u); - EXPECT_EQ(toStringRef(Result.Prologue.FileNames[0].Name), "a file"); - } + // Parsing will stop before reading a complete file entry. + ASSERT_EQ(Result.Prologue.IncludeDirectories.size(), 1u); + EXPECT_EQ(toStringRef(Result.Prologue.IncludeDirectories[0]), "a dir"); + EXPECT_EQ(Result.Prologue.FileNames.size(), 0u); - uint64_t ExpectedEnd = - Prologue.TotalLength - 2 + Prologue.sizeofTotalLength(); + // The exact place where the parsing will stop depends on the structure of the + // prologue and the last complete field we are able to read. Before V5 we stop + // before reading the file length. In V5, we stop before the filename. + uint64_t ExpectedEnd = Prologue.TotalLength + Prologue.sizeofTotalLength() - + (Version < 5 ? 2 : 8); std::vector<std::string> Errs; - if (Version != 5) { - Errs.emplace_back( - (Twine("parsing line table prologue at 0x00000000 found an invalid " - "directory or file table description at 0x000000") + - Twine::utohexstr(ExpectedEnd + 1)) - .str()); + Errs.emplace_back( + (Twine("parsing line table prologue at 0x00000000 found an invalid " + "directory or file table description at 0x000000") + + Twine::utohexstr(ExpectedEnd)) + .str()); + if (Version < 5) { Errs.emplace_back("file names table was not null terminated before the end " "of the prologue"); } else { Errs.emplace_back( - (Twine("parsing line table prologue at 0x00000000 should have ended at " - "0x000000") + - Twine::utohexstr(ExpectedEnd) + " but it ended at 0x000000" + - Twine::utohexstr(ExpectedEnd + 2)) - .str()); + "failed to parse file entry because extracting the form value failed."); } EXPECT_THAT_ERROR(std::move(Recoverable), FailedWithMessageArray(testing::ElementsAreArray(Errs))); @@ -1514,6 +1506,7 @@ TEST_F(DebugLineBasicFixture, PrintPathsProperly) { P.FileNames.back().Name = DWARFFormValue::createFromPValue(DW_FORM_string, "b file"); P.FileNames.back().DirIdx = 1; + P.TotalLength += 14; P.PrologueLength += 14; LT.setPrologue(P); generate(); |