diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2018-03-08 10:53:34 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2018-03-08 10:53:34 +0000 |
commit | 667026297da3f188ca78f4c6b0d767000b4c5d90 (patch) | |
tree | 7d8e1c3fa45369838e102f2c54ecef2c79f483f1 /llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | |
parent | 2902a21ef327df697f23355271041bbc43f59ee7 (diff) | |
download | bcm5719-llvm-667026297da3f188ca78f4c6b0d767000b4c5d90.tar.gz bcm5719-llvm-667026297da3f188ca78f4c6b0d767000b4c5d90.zip |
[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
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index cb7bf82d86f..a61ab7d3aff 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -1,4 +1,4 @@ -//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===// +//===- llvm/unittest/DebugInfo/DWARFDebugInfoTest.cpp ---------------------===// // // The LLVM Compiler Infrastructure // @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "DwarfGenerator.h" +#include "DwarfUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" @@ -36,36 +37,10 @@ using namespace llvm; using namespace dwarf; +using namespace utils; namespace { -void initLLVMIfNeeded() { - static bool gInitialized = false; - if (!gInitialized) { - gInitialized = true; - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); - InitializeAllAsmParsers(); - } -} - -Triple getHostTripleForAddrSize(uint8_t AddrSize) { - Triple PT(Triple::normalize(LLVM_HOST_TRIPLE)); - - if (AddrSize == 8 && PT.isArch32Bit()) - return PT.get64BitArchVariant(); - if (AddrSize == 4 && PT.isArch64Bit()) - return PT.get32BitArchVariant(); - return PT; -} - -static bool isConfigurationSupported(Triple &T) { - initLLVMIfNeeded(); - std::string Err; - return TargetRegistry::lookupTarget(T.getTriple(), Err); -} - template <uint16_t Version, class AddrType, class RefAddrType> void TestAllForms() { Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); |