Index: llvm/include/llvm/DebugInfo/MSF/MSFCommon.h =================================================================== --- llvm/include/llvm/DebugInfo/MSF/MSFCommon.h +++ llvm/include/llvm/DebugInfo/MSF/MSFCommon.h @@ -59,6 +59,23 @@ std::vector> StreamMap; }; +/// \brief Describes the layout of a stream in an MSF layout. A "stream" here +/// is defined as any logical unit of data which may be arranged inside the MSF +/// file as a sequence of (possibly discontiguous) blocks. When we want to read +/// from a particular MSF Stream, we fill out a stream layout structure and the +/// reader uses it to determine which blocks in the underlying MSF file contain +/// the data, so that it can be pieced together in the right order. +class MSFStreamLayout { +public: + uint32_t Length; + std::vector Blocks; +}; + +/// \brief Determine the layout of the FPM stream, given the MSF layout. An FPM +/// stream spans 1 or more blocks, each at equally spaced intervals throughout +/// the file. +MSFStreamLayout getFpmStreamLayout(const MSFLayout &Msf); + inline bool isValidBlockSize(uint32_t Size) { switch (Size) { case 512: Index: llvm/include/llvm/DebugInfo/MSF/MSFStreamLayout.h =================================================================== --- llvm/include/llvm/DebugInfo/MSF/MSFStreamLayout.h +++ /dev/null @@ -1,35 +0,0 @@ -//===- MSFStreamLayout.h - Describes the layout of a stream -----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_MSF_MSFSTREAMLAYOUT_H -#define LLVM_DEBUGINFO_MSF_MSFSTREAMLAYOUT_H - -#include "llvm/Support/Endian.h" - -#include -#include - -namespace llvm { -namespace msf { - -/// \brief Describes the layout of a stream in an MSF layout. A "stream" here -/// is defined as any logical unit of data which may be arranged inside the MSF -/// file as a sequence of (possibly discontiguous) blocks. When we want to read -/// from a particular MSF Stream, we fill out a stream layout structure and the -/// reader uses it to determine which blocks in the underlying MSF file contain -/// the data, so that it can be pieced together in the right order. -class MSFStreamLayout { -public: - uint32_t Length; - std::vector Blocks; -}; -} // namespace msf -} // namespace llvm - -#endif // LLVM_DEBUGINFO_MSF_MSFSTREAMLAYOUT_H Index: llvm/include/llvm/DebugInfo/MSF/MappedBlockStream.h =================================================================== --- llvm/include/llvm/DebugInfo/MSF/MappedBlockStream.h +++ llvm/include/llvm/DebugInfo/MSF/MappedBlockStream.h @@ -12,7 +12,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/DebugInfo/MSF/MSFStreamLayout.h" +#include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryStream.h" #include "llvm/Support/BinaryStreamRef.h" Index: llvm/include/llvm/DebugInfo/PDB/Native/PDBFile.h =================================================================== --- llvm/include/llvm/DebugInfo/PDB/Native/PDBFile.h +++ llvm/include/llvm/DebugInfo/PDB/Native/PDBFile.h @@ -13,7 +13,6 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/DebugInfo/MSF/IMSFFile.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" -#include "llvm/DebugInfo/MSF/MSFStreamLayout.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/Endian.h" @@ -72,8 +71,6 @@ Error setBlockData(uint32_t BlockIndex, uint32_t Offset, ArrayRef Data) const override; - ArrayRef getFpmPages() const { return FpmPages; } - ArrayRef getStreamSizes() const { return ContainerLayout.StreamSizes; } @@ -87,6 +84,7 @@ ArrayRef getDirectoryBlockArray() const; msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const; + msf::MSFStreamLayout getFpmStreamLayout() const; Error parseFileHeaders(); Error parseStreamData(); @@ -124,7 +122,6 @@ std::unique_ptr Buffer; - std::vector FpmPages; msf::MSFLayout ContainerLayout; std::unique_ptr Globals; Index: llvm/lib/DebugInfo/MSF/MSFCommon.cpp =================================================================== --- llvm/lib/DebugInfo/MSF/MSFCommon.cpp +++ llvm/lib/DebugInfo/MSF/MSFCommon.cpp @@ -59,3 +59,18 @@ return Error::success(); } + +MSFStreamLayout llvm::msf::getFpmStreamLayout(const MSFLayout &Msf) { + MSFStreamLayout FL; + uint32_t NumFpmIntervals = getNumFpmIntervals(Msf); + support::ulittle32_t FpmBlock = Msf.SB->FreeBlockMapBlock; + assert(FpmBlock == 1 || FpmBlock == 2); + while (NumFpmIntervals > 0) { + FL.Blocks.push_back(FpmBlock); + FpmBlock += msf::getFpmIntervalLength(Msf); + --NumFpmIntervals; + } + FL.Length = getFullFpmByteSize(Msf); + + return FL; +} Index: llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp =================================================================== --- llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp +++ llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" -#include "llvm/DebugInfo/MSF/MSFStreamLayout.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" #include "llvm/Support/MathExtras.h" @@ -36,19 +35,6 @@ } // end anonymous namespace -static void initializeFpmStreamLayout(const MSFLayout &Layout, - MSFStreamLayout &FpmLayout) { - uint32_t NumFpmIntervals = msf::getNumFpmIntervals(Layout); - support::ulittle32_t FpmBlock = Layout.SB->FreeBlockMapBlock; - assert(FpmBlock == 1 || FpmBlock == 2); - while (NumFpmIntervals > 0) { - FpmLayout.Blocks.push_back(FpmBlock); - FpmBlock += msf::getFpmIntervalLength(Layout); - --NumFpmIntervals; - } - FpmLayout.Length = msf::getFullFpmByteSize(Layout); -} - using Interval = std::pair; static Interval intersect(const Interval &I1, const Interval &I2) { @@ -95,8 +81,7 @@ MappedBlockStream::createFpmStream(const MSFLayout &Layout, BinaryStreamRef MsfData, BumpPtrAllocator &Allocator) { - MSFStreamLayout SL; - initializeFpmStreamLayout(Layout, SL); + MSFStreamLayout SL(getFpmStreamLayout(Layout)); return createStream(Layout.SB->BlockSize, SL, MsfData, Allocator); } @@ -363,8 +348,7 @@ WritableMappedBlockStream::createFpmStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, BumpPtrAllocator &Allocator) { - MSFStreamLayout SL; - initializeFpmStreamLayout(Layout, SL); + MSFStreamLayout SL(getFpmStreamLayout(Layout)); return createStream(Layout.SB->BlockSize, SL, MsfData, Allocator); } Index: llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp +++ llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp @@ -238,6 +238,10 @@ return Result; } +msf::MSFStreamLayout PDBFile::getFpmStreamLayout() const { + return msf::getFpmStreamLayout(ContainerLayout); +} + Expected PDBFile::getPDBGlobalsStream() { if (!Globals) { auto DbiS = getPDBDbiStream(); Index: llvm/test/DebugInfo/PDB/dump-fpm.test =================================================================== --- /dev/null +++ llvm/test/DebugInfo/PDB/dump-fpm.test @@ -0,0 +1,9 @@ +RUN: llvm-pdbutil bytes -fpm %t/Inputs/empty.pdb | FileCheck %s + +CHECK: Free Page Map +CHECK-NEXT: ============================================================ +CHECK-NEXT: Block 2 ( +CHECK-NEXT: 2000: 380300FE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |8...............................| +CHECK-NEXT: 2020: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................................| +CHECK: 2FE0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................................| +CHECK-NEXT: ) Index: llvm/tools/llvm-pdbutil/BytesOutputStyle.h =================================================================== --- llvm/tools/llvm-pdbutil/BytesOutputStyle.h +++ llvm/tools/llvm-pdbutil/BytesOutputStyle.h @@ -35,6 +35,7 @@ void dumpNameMap(); void dumpBlockRanges(uint32_t Min, uint32_t Max); void dumpByteRanges(uint32_t Min, uint32_t Max); + void dumpFpm(); void dumpStreamBytes(); void dumpSectionContributions(); Index: llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/CodeView/Formatters.h" #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" +#include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" @@ -120,6 +121,11 @@ P.NewLine(); } + if (opts::bytes::Fpm) { + dumpFpm(); + P.NewLine(); + } + if (!opts::bytes::DumpStreamData.empty()) { dumpStreamBytes(); P.NewLine(); @@ -480,6 +486,13 @@ return *TypeCollection; } +void BytesOutputStyle::dumpFpm() { + printHeader(P, "Free Page Map"); + + msf::MSFStreamLayout FpmLayout = File.getFpmStreamLayout(); + P.formatMsfStreamBlocks(File, FpmLayout); +} + void BytesOutputStyle::dumpStreamBytes() { if (StreamPurposes.empty()) discoverStreamPurposes(File, StreamPurposes); Index: llvm/tools/llvm-pdbutil/LinePrinter.h =================================================================== --- llvm/tools/llvm-pdbutil/LinePrinter.h +++ llvm/tools/llvm-pdbutil/LinePrinter.h @@ -60,6 +60,7 @@ void formatMsfStreamData(StringRef Label, PDBFile &File, const msf::MSFStreamLayout &Stream, BinarySubstreamRef Substream); + void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream); bool hasColor() const { return UseColor; } raw_ostream &getStream() { return OS; } Index: llvm/tools/llvm-pdbutil/LinePrinter.cpp =================================================================== --- llvm/tools/llvm-pdbutil/LinePrinter.cpp +++ llvm/tools/llvm-pdbutil/LinePrinter.cpp @@ -13,7 +13,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" -#include "llvm/DebugInfo/MSF/MSFStreamLayout.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/UDTLayout.h" @@ -246,6 +245,29 @@ OS << ")"; } +void LinePrinter::formatMsfStreamBlocks( + PDBFile &File, const msf::MSFStreamLayout &StreamLayout) { + NewLine(); + auto Blocks = makeArrayRef(StreamLayout.Blocks); + uint32_t L = StreamLayout.Length; + + while (L > 0) { + assert(!Blocks.empty()); + OS << formatv("Block {0} (\n", uint32_t(Blocks.front())); + uint32_t UsedBytes = std::min(L, File.getBlockSize()); + ArrayRef BlockData = + cantFail(File.getBlockData(Blocks.front(), File.getBlockSize())); + uint64_t BaseOffset = Blocks.front(); + BaseOffset *= File.getBlockSize(); + OS << format_bytes_with_ascii(BlockData, BaseOffset, 32, 4, + CurrentIndent + IndentSpaces, true); + NewLine(); + OS << ")"; + L -= UsedBytes; + Blocks = Blocks.drop_front(); + } +} + bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size) { if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters)) return true; Index: llvm/tools/llvm-pdbutil/llvm-pdbutil.h =================================================================== --- llvm/tools/llvm-pdbutil/llvm-pdbutil.h +++ llvm/tools/llvm-pdbutil/llvm-pdbutil.h @@ -102,6 +102,7 @@ extern llvm::Optional DumpByteRange; extern llvm::cl::list DumpStreamData; extern llvm::cl::opt NameMap; +extern llvm::cl::opt Fpm; extern llvm::cl::opt SectionContributions; extern llvm::cl::opt SectionMap; @@ -123,6 +124,7 @@ namespace dump { extern llvm::cl::opt DumpSummary; +extern llvm::cl::opt DumpFpm; extern llvm::cl::opt DumpStreams; extern llvm::cl::opt DumpStreamBlocks; Index: llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp =================================================================== --- llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -342,6 +342,8 @@ cl::opt NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"), cl::sub(BytesSubcommand), cl::cat(PdbBytes)); +cl::opt Fpm("fpm", cl::desc("Dump free page map"), + cl::sub(BytesSubcommand), cl::cat(MsfBytes)); cl::opt SectionContributions("sc", cl::desc("Dump section contributions"), cl::sub(BytesSubcommand), cl::cat(DbiBytes)); Index: llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp =================================================================== --- llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp +++ llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp @@ -10,7 +10,6 @@ #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/MSF/IMSFFile.h" #include "llvm/DebugInfo/MSF/MSFError.h" -#include "llvm/DebugInfo/MSF/MSFStreamLayout.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/BinaryStreamRef.h"