diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2017-09-08 09:48:51 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2017-09-08 09:48:51 +0000 |
commit | f4ed65da04c7e4504e57268cf67ee1c210ce7daf (patch) | |
tree | d07cbac5ac5555572d6462f7fda2bafdc95f9835 /llvm/lib/DebugInfo | |
parent | ab36f33db8ed1cd16277016f834527254c7a3d0f (diff) | |
download | bcm5719-llvm-f4ed65da04c7e4504e57268cf67ee1c210ce7daf.tar.gz bcm5719-llvm-f4ed65da04c7e4504e57268cf67ee1c210ce7daf.zip |
[dwarfdump] Verify line table prologue
This patch adds prologue verification, which is already present in
Apple's dwarfdump. It checks for invalid directory indices and warns
about duplicate file paths.
Differential revision: https://reviews.llvm.org/D37511
llvm-svn: 312782
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp index e5e9054c1c4..438764a8870 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -417,10 +417,50 @@ void DWARFVerifier::verifyDebugLineRows() { // .debug_info verifier or in verifyDebugLineStmtOffsets(). if (!LineTable) continue; + + // Verify prologue. uint32_t MaxFileIndex = LineTable->Prologue.FileNames.size(); + uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size(); + uint32_t FileIndex = 1; + StringMap<uint16_t> FullPathMap; + for (const auto &FileName : LineTable->Prologue.FileNames) { + // Verify directory index. + if (FileName.DirIdx > MaxDirIndex) { + ++NumDebugLineErrors; + OS << "error: .debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "].prologue.file_names[" << FileIndex + << "].dir_idx contains an invalid index: " << FileName.DirIdx + << "\n"; + } + + // Check file paths for duplicates. + std::string FullPath; + const bool HasFullPath = LineTable->getFileNameByIndex( + FileIndex, CU->getCompilationDir(), + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FullPath); + assert(HasFullPath && "Invalid index?"); + (void)HasFullPath; + auto It = FullPathMap.find(FullPath); + if (It == FullPathMap.end()) + FullPathMap[FullPath] = FileIndex; + else if (It->second != FileIndex) { + OS << "warning: .debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "].prologue.file_names[" << FileIndex + << "] is a duplicate of file_names[" << It->second << "]\n"; + } + + FileIndex++; + } + + // Verify rows. uint64_t PrevAddress = 0; uint32_t RowIndex = 0; for (const auto &Row : LineTable->Rows) { + // Verify row address. if (Row.Address < PrevAddress) { ++NumDebugLineErrors; OS << "error: .debug_line[" @@ -436,6 +476,7 @@ void DWARFVerifier::verifyDebugLineRows() { OS << '\n'; } + // Verify file index. if (Row.File > MaxFileIndex) { ++NumDebugLineErrors; OS << "error: .debug_line[" |