[llvm] r267955 - [llvm-pdbdump] Restore error messages, handle bad block sizes

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 16:47:28 PDT 2016


Author: majnemer
Date: Thu Apr 28 18:47:27 2016
New Revision: 267955

URL: http://llvm.org/viewvc/llvm-project?rev=267955&view=rev
Log:
[llvm-pdbdump] Restore error messages, handle bad block sizes

We lost the ability to report errors, bring it back.  Also, correctly
validate the block size.

Added:
    llvm/trunk/test/DebugInfo/PDB/Inputs/bad-block-size.pdb
Modified:
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
    llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
    llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=267955&r1=267954&r2=267955&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Thu Apr 28 18:47:27 2016
@@ -127,7 +127,7 @@ std::error_code PDBFile::parseFileHeader
     return std::make_error_code(std::errc::illegal_byte_sequence);
 
   // We don't support blocksizes which aren't a multiple of four bytes.
-  if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)
+  if (SB->BlockSize == 0 || SB->BlockSize % sizeof(support::ulittle32_t) != 0)
     return std::make_error_code(std::errc::not_supported);
 
   // We don't support directories whose sizes aren't a multiple of four bytes.

Added: llvm/trunk/test/DebugInfo/PDB/Inputs/bad-block-size.pdb
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/Inputs/bad-block-size.pdb?rev=267955&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/Inputs/bad-block-size.pdb (added)
+++ llvm/trunk/test/DebugInfo/PDB/Inputs/bad-block-size.pdb Thu Apr 28 18:47:27 2016
@@ -0,0 +1,2 @@
+Microsoft C/C++ MSF 7.00
+DS
\ No newline at end of file

Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test?rev=267955&r1=267954&r2=267955&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test Thu Apr 28 18:47:27 2016
@@ -1,5 +1,6 @@
 ; RUN: llvm-pdbdump --dump-headers %p/Inputs/empty.pdb | FileCheck -check-prefix=EMPTY %s
 ; RUN: llvm-pdbdump --dump-headers %p/Inputs/big-read.pdb | FileCheck -check-prefix=BIG %s
+; RUN: llvm-pdbdump --dump-headers %p/Inputs/bad-block-size.pdb | FileCheck -check-prefix=BAD-BLOCK-SIZE %s
 
 ; EMPTY:      BlockSize: 4096
 ; EMPTY-NEXT: Unknown0: 2
@@ -977,3 +978,5 @@ BIG-NEXT:     Symbol Byte Size: 3080
 BIG-NEXT:     Type Server Index: 0
 BIG-NEXT:     Has EC Info: 0
 BIG-NEXT:     0 Contributing Source Files:
+
+BAD-BLOCK-SIZE: The file has an unrecognized format.

Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=267955&r1=267954&r2=267955&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Thu Apr 28 18:47:27 2016
@@ -308,20 +308,7 @@ static void dumpStructure(RawSession &RS
   }
 }
 
-static void dumpInput(StringRef Path) {
-  std::unique_ptr<IPDBSession> Session;
-  if (opts::DumpHeaders || !opts::DumpStreamData.empty()) {
-    PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::Raw, Path, Session);
-    if (Error == PDB_ErrorCode::Success) {
-      RawSession *RS = static_cast<RawSession *>(Session.get());
-      dumpStructure(*RS);
-    }
-
-    outs().flush();
-    return;
-  }
-
-  PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
+static void reportError(StringRef Path, PDB_ErrorCode Error) {
   switch (Error) {
   case PDB_ErrorCode::Success:
     break;
@@ -347,6 +334,28 @@ static void dumpInput(StringRef Path) {
            << "'.  An unknown error occured.\n";
     return;
   }
+}
+
+static void dumpInput(StringRef Path) {
+  std::unique_ptr<IPDBSession> Session;
+  if (opts::DumpHeaders || !opts::DumpStreamData.empty()) {
+    PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::Raw, Path, Session);
+    if (Error == PDB_ErrorCode::Success) {
+      RawSession *RS = static_cast<RawSession *>(Session.get());
+      dumpStructure(*RS);
+    }
+
+    reportError(Path, Error);
+    outs().flush();
+    return;
+  }
+
+  PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
+  if (Error != PDB_ErrorCode::Success) {
+    reportError(Path, Error);
+    return;
+  }
+
   if (opts::LoadAddress)
     Session->setLoadAddress(opts::LoadAddress);
 




More information about the llvm-commits mailing list