[DWARF] Don't attempt to parse line tables at invalid offsets
authorJames Henderson <jh7370@my.bristol.ac.uk>
Thu, 8 Mar 2018 10:53:34 +0000 (10:53 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Thu, 8 Mar 2018 10:53:34 +0000 (10:53 +0000)
commit667026297da3f188ca78f4c6b0d767000b4c5d90
tree7d8e1c3fa45369838e102f2c54ecef2c79f483f1
parent2902a21ef327df697f23355271041bbc43f59ee7
[DWARF] Don't attempt to parse line tables at invalid offsets

Whilst working on improvements to the error handling of the debug line
parsing code, I noticed that if an invalid offset were to be specified
in a call to getOrParseLineTable(), an entry in the LineTableMap would
still be created, even if the offset was not within the section range.
The immediate parsing attempt afterwards would fail (it would end up
getting a version of 0), and thereafter, any subsequent calls to
getOrParseLineTable or getLineTable would return the default-
constructed, invalid line table. In reality, we shouldn't even attempt
to parse this table, and we should always return a nullptr from these
two functions for this situation.

I have tested this via a unit test, which required some new framework
for unit testing debug line. My plan is to add quite a few more unit
tests for the new error reporting mechanism that will follow shortly,
hence the reason why the supporting code for the tests are written the
way they are - I intend to extend the DwarfGenerator class to support
generating debug line. At that point, I'll make sure that there are a
few positive test cases for this and the parsing code too.

Differential Revision: https://reviews.llvm.org/D44200

Reviewers: JDevlieghere, aprantl
llvm-svn: 326995
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp [new file with mode: 0644]
llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp [new file with mode: 0644]
llvm/unittests/DebugInfo/DWARF/DwarfUtils.h [new file with mode: 0644]