aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
diff options
context:
space:
mode:
authorJames Henderson <james.henderson@sony.com>2020-02-12 14:37:10 +0000
committerJames Henderson <james.henderson@sony.com>2020-02-12 14:49:22 +0000
commitbf4d8f29524449c4114b457875cc6a8031c46092 (patch)
treed96b22ce18e5bfa0163919b87651231dbd5336e8 /llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
parent23cf0a30b1528cf268ffdf13e04a5baa7eddfe0a (diff)
downloadllvm-bf4d8f29524449c4114b457875cc6a8031c46092.zip
llvm-bf4d8f29524449c4114b457875cc6a8031c46092.tar.gz
llvm-bf4d8f29524449c4114b457875cc6a8031c46092.tar.bz2
[DebugInfo] Add checks for v2 directory and file name table terminators
The DWARFv2-4 specification for the line table header states that the include directories and file name tables both end with a single null byte. Prior to this change, the parser did not detect if this byte was missing, because it also stopped reading the tables once it reached the prologue end, as claimed by the header_length field. This change adds a check that the terminator has been seen at the end of each table. Reviewed by: dblaikie, MaskRay Differential Revision: https://reviews.llvm.org/D74413
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp')
-rw-r--r--llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
index 795b9b4..d6d9691 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
@@ -449,12 +449,7 @@ TEST_P(DebugLineParameterisedFixture, ErrorForTooShortPrologueLength) {
LineTable &LT = Gen->addLineTable(Format);
DWARFDebugLine::Prologue Prologue = LT.createBasicPrologue();
- // FIXME: Ideally, we'd test for 1 less than expected, but the code does not
- // currently fail if missing only the terminator of a v2-4 file table.
- if (Version < 5)
- Prologue.PrologueLength -= 2;
- else
- Prologue.PrologueLength -= 1;
+ Prologue.PrologueLength -= 2;
LT.setPrologue(Prologue);
generate();
@@ -465,23 +460,34 @@ TEST_P(DebugLineParameterisedFixture, ErrorForTooShortPrologueLength) {
DWARFDebugLine::LineTable Result(**ExpectedLineTable);
// Undo the earlier modification so that it can be compared against a
// "default" prologue.
- if (Version < 5)
- Result.Prologue.PrologueLength += 2;
- else
- Result.Prologue.PrologueLength += 1;
+ Result.Prologue.PrologueLength += 2;
checkDefaultPrologue(Version, Format, Result.Prologue, 0);
uint64_t ExpectedEnd =
- Prologue.TotalLength - 1 + Prologue.sizeofTotalLength();
- if (Version < 5)
- --ExpectedEnd;
- checkError(
+ Prologue.TotalLength - 2 + Prologue.sizeofTotalLength();
+ std::vector<std::string> Errs;
+ // Parsing of a DWARFv2-4 file table stops at the end of an entry once the
+ // prologue end has been reached, whether or not the trailing null terminator
+ // has been found. As such, the expected error message will be slightly
+ // different.
+ uint64_t ActualEnd = Version == 5 ? ExpectedEnd + 2 : ExpectedEnd + 1;
+ 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(ActualEnd))
+ .str());
+ Errs.emplace_back("file names table was not null terminated before the end "
+ "of the prologue");
+ }
+ 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 + 1))
- .str(),
- std::move(Recoverable));
+ Twine::utohexstr(ActualEnd))
+ .str());
+ std::vector<StringRef> ErrRefs(Errs.begin(), Errs.end());
+ checkError(ErrRefs, std::move(Recoverable));
}
INSTANTIATE_TEST_CASE_P(