[llvm] r328808 - [PDB] Print some more details when explaining MSF fields.

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


Author: zturner
Date: Thu Mar 29 10:45:34 2018
New Revision: 328808

URL: http://llvm.org/viewvc/llvm-project?rev=328808&view=rev
Log:
[PDB] Print some more details when explaining MSF fields.

When we determine that a field belongs to an MSF super block or
the free page map, we wouldn't print any additional information.

With this patch, we now print the value of the field (for super
block fields) or the allocation status of the specified byte (in
the case of offsets in the FPM).

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=328808&r1=328807&r2=328808&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-pdbdump/explain.test (original)
+++ llvm/trunk/test/tools/llvm-pdbdump/explain.test Thu Mar 29 10:45:34 2018
@@ -40,6 +40,7 @@ FORTY:      Block:Offset = 0:0028.
 FORTY-NEXT: Address is in block 0 (allocated).
 FORTY-NEXT:   This corresponds to offset 40 of the MSF super block,
 FORTY-NEXT:   which contains the number of blocks in the file.
+FORTY-NEXT:   The current value is 29.
 
 SIXTY:      Block:Offset = 0:003C.
 SIXTY-NEXT: Address is in block 0 (allocated).
@@ -50,6 +51,7 @@ FPM1:      Block:Offset = 1:0000.
 FPM1-NEXT: Address is in block 1 (allocated).
 FPM1-NEXT:   Address is in FPM1 (Alt FPM)
 FPM1-NEXT:   Address describes the allocation status of blocks [0,8)
+FPM1-NEXT:   Status = 00000011 (Note: 0 = allocated, 1 = free)
 
 EXTRANEOUSFPM:      Block:Offset = 1:0100.
 EXTRANEOUSFPM-NEXT: Address is in block 1 (allocated).
@@ -60,6 +62,7 @@ FPM2:      Block:Offset = 2:0000.
 FPM2-NEXT: Address is in block 2 (allocated).
 FPM2-NEXT:   Address is in FPM2 (Main FPM)
 FPM2-NEXT:   Address describes the allocation status of blocks [0,8)
+FPM2-NEXT:   Status = 00011100 (Note: 0 = allocated, 1 = free)
 
 UNALLOCATED:      Block:Offset = 3:0000.
 UNALLOCATED-NEXT: Address is in block 3 (unallocated).

Modified: llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp?rev=328808&r1=328807&r2=328808&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/ExplainOutputStyle.cpp Thu Mar 29 10:45:34 2018
@@ -103,25 +103,47 @@ void ExplainOutputStyle::explainSuperBlo
                OffsetInBlock);
   if (OffsetInBlock < endof(SuperBlock, MagicBytes))
     P.printLine("which is part of the MSF file magic.");
-  else if (OffsetInBlock < endof(SuperBlock, BlockSize))
+  else if (OffsetInBlock < endof(SuperBlock, BlockSize)) {
     P.printLine("which contains the block size of the file.");
-  else if (OffsetInBlock < endof(SuperBlock, FreeBlockMapBlock))
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->BlockSize));
+  } else if (OffsetInBlock < endof(SuperBlock, FreeBlockMapBlock)) {
     P.printLine("which contains the index of the FPM block (e.g. 1 or 2).");
-  else if (OffsetInBlock < endof(SuperBlock, NumBlocks))
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->FreeBlockMapBlock));
+  } else if (OffsetInBlock < endof(SuperBlock, NumBlocks)) {
     P.printLine("which contains the number of blocks in the file.");
-  else if (OffsetInBlock < endof(SuperBlock, NumDirectoryBytes))
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->NumBlocks));
+  } else if (OffsetInBlock < endof(SuperBlock, NumDirectoryBytes)) {
     P.printLine("which contains the number of bytes in the stream directory.");
-  else if (OffsetInBlock < endof(SuperBlock, Unknown1))
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->NumDirectoryBytes));
+  } else if (OffsetInBlock < endof(SuperBlock, Unknown1)) {
     P.printLine("whose purpose is unknown.");
-  else if (OffsetInBlock < endof(SuperBlock, BlockMapAddr))
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->Unknown1));
+  } else if (OffsetInBlock < endof(SuperBlock, BlockMapAddr)) {
     P.printLine("which contains the file offset of the block map.");
-  else {
+    P.formatLine("The current value is {0}.",
+                 uint32_t(File.getMsfLayout().SB->BlockMapAddr));
+  } else {
     assert(OffsetInBlock > sizeof(SuperBlock));
     P.printLine(
         "which is outside the range of valid data for the super block.");
   }
 }
 
+static std::string toBinaryString(uint8_t Byte) {
+  char Result[9] = {0};
+  for (int I = 0; I < 8; ++I) {
+    char C = (Byte & 1) ? '1' : '0';
+    Result[I] = C;
+    Byte >>= 1;
+  }
+  return std::string(Result);
+}
+
 void ExplainOutputStyle::explainFpmBlockOffset() {
   const MSFLayout &Layout = File.getMsfLayout();
   uint32_t MainFpm = Layout.mainFpmBlock();
@@ -143,6 +165,10 @@ void ExplainOutputStyle::explainFpmBlock
 
   P.formatLine("Address describes the allocation status of blocks [{0},{1})",
                DescribedBlockStart, DescribedBlockStart + 8);
+  ArrayRef<uint8_t> Bytes;
+  cantFail(File.getMsfBuffer().readBytes(FileOffset, 1, Bytes));
+  P.formatLine("Status = {0} (Note: 0 = allocated, 1 = free)",
+               toBinaryString(Bytes[0]));
 }
 
 void ExplainOutputStyle::explainBlockMapOffset() {




More information about the llvm-commits mailing list