[llvm] r328804 - [PDB] Fix a bug in the explain subcommand.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 10:11:14 PDT 2018


Author: zturner
Date: Thu Mar 29 10:11:14 2018
New Revision: 328804

URL: http://llvm.org/viewvc/llvm-project?rev=328804&view=rev
Log:
[PDB] Fix a bug in the explain subcommand.

We were trying to dig into the super block fields and print a
description of the field at the specified offset, but we were
printing the wrong field due to an off-by-one-field-error.

Modified:
    llvm/trunk/test/tools/llvm-pdbdump/explain.test
    llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp

Modified: llvm/trunk/test/tools/llvm-pdbdump/explain.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-pdbdump/explain.test?rev=328804&r1=328803&r2=328804&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-pdbdump/explain.test (original)
+++ llvm/trunk/test/tools/llvm-pdbdump/explain.test Thu Mar 29 10:11:14 2018
@@ -33,17 +33,17 @@
 
 ZERO:      Block:Offset = 0:0000.
 ZERO-NEXT: Address is in block 0 (allocated).
-ZERO-NEXT:   This corresponds to offset 0 of MSF super block,
+ZERO-NEXT:   This corresponds to offset 0 of the MSF super block,
 ZERO-NEXT:   which is part of the MSF file magic.
 
 FORTY:      Block:Offset = 0:0028.
 FORTY-NEXT: Address is in block 0 (allocated).
-FORTY-NEXT:   This corresponds to offset 40 of MSF super block,
-FORTY-NEXT:   which contains the number of bytes in the stream directory.
+FORTY-NEXT:   This corresponds to offset 40 of the MSF super block,
+FORTY-NEXT:   which contains the number of blocks in the file.
 
 SIXTY:      Block:Offset = 0:003C.
 SIXTY-NEXT: Address is in block 0 (allocated).
-SIXTY-NEXT:   This corresponds to offset 60 of MSF super block,
+SIXTY-NEXT:   This corresponds to offset 60 of the MSF super block,
 SIXTY-NEXT:   which is outside the range of valid data for the super block.
 
 FPM1:      Block:Offset = 1:0000.

Modified: llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp?rev=328804&r1=328803&r2=328804&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp Thu Mar 29 10:11:14 2018
@@ -96,22 +96,24 @@ bool ExplainOutputStyle::explainBlockSta
   return !IsFree;
 }
 
+#define endof(Class, Field) (offsetof(Class, Field) + sizeof(Class::Field))
+
 void ExplainOutputStyle::explainSuperBlockOffset() {
-  P.formatLine("This corresponds to offset {0} of MSF super block, ",
+  P.formatLine("This corresponds to offset {0} of the MSF super block, ",
                OffsetInBlock);
-  if (OffsetInBlock < sizeof(msf::Magic))
+  if (OffsetInBlock < endof(SuperBlock, MagicBytes))
     P.printLine("which is part of the MSF file magic.");
-  else if (OffsetInBlock < offsetof(SuperBlock, BlockSize))
+  else if (OffsetInBlock < endof(SuperBlock, BlockSize))
     P.printLine("which contains the block size of the file.");
-  else if (OffsetInBlock < offsetof(SuperBlock, FreeBlockMapBlock))
+  else if (OffsetInBlock < endof(SuperBlock, FreeBlockMapBlock))
     P.printLine("which contains the index of the FPM block (e.g. 1 or 2).");
-  else if (OffsetInBlock < offsetof(SuperBlock, NumBlocks))
+  else if (OffsetInBlock < endof(SuperBlock, NumBlocks))
     P.printLine("which contains the number of blocks in the file.");
-  else if (OffsetInBlock < offsetof(SuperBlock, NumDirectoryBytes))
+  else if (OffsetInBlock < endof(SuperBlock, NumDirectoryBytes))
     P.printLine("which contains the number of bytes in the stream directory.");
-  else if (OffsetInBlock < offsetof(SuperBlock, Unknown1))
+  else if (OffsetInBlock < endof(SuperBlock, Unknown1))
     P.printLine("whose purpose is unknown.");
-  else if (OffsetInBlock < offsetof(SuperBlock, BlockMapAddr))
+  else if (OffsetInBlock < endof(SuperBlock, BlockMapAddr))
     P.printLine("which contains the file offset of the block map.");
   else {
     assert(OffsetInBlock > sizeof(SuperBlock));




More information about the llvm-commits mailing list