From 3f7d1658c90577bb62019eec9792e00c56380c29 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 30 Sep 2016 20:52:12 +0000 Subject: [PATCH] Do not pass a superblock to PDBFileBuilder. When we create a PDB file using PDBFileBuilder, the information in the superblock, such as the size of the resulting file, is not available. Previously, PDBFileBuilder::initialize took a superblock assuming that all the members of the struct are correct. That is useful when you want to restore the exact information from a YAML file, but that's probably the only use case in which that is useful. When we are creating a PDB file on the fly, we have to backfill the members. This patch redefines PDBFileBuilder::initialize to take only a block size. Now all the other members are left as default values, so that they'll be updated when commit() is called. Differential Revision: https://reviews.llvm.org/D25108 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282944 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/MSF/MSFBuilder.h | 2 +- include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h | 2 +- lib/DebugInfo/MSF/MSFBuilder.cpp | 4 +++- lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp | 13 +++---------- test/DebugInfo/PDB/pdbdump-readwrite.test | 4 ++-- tools/llvm-pdbdump/llvm-pdbdump.cpp | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/llvm/DebugInfo/MSF/MSFBuilder.h b/include/llvm/DebugInfo/MSF/MSFBuilder.h index 540050ca6af..6d067cc1c23 100644 --- a/include/llvm/DebugInfo/MSF/MSFBuilder.h +++ b/include/llvm/DebugInfo/MSF/MSFBuilder.h @@ -128,7 +128,7 @@ private: bool IsGrowable; uint32_t FreePageMap; - uint32_t Unknown1; + uint32_t Unknown1 = 0; uint32_t BlockSize; uint32_t MininumBlocks; uint32_t BlockMapAddr; diff --git a/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h b/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h index 843ea97aa5f..ce5e3ff1da4 100644 --- a/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h +++ b/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h @@ -36,7 +36,7 @@ public: PDBFileBuilder(const PDBFileBuilder &) = delete; PDBFileBuilder &operator=(const PDBFileBuilder &) = delete; - Error initialize(const msf::SuperBlock &Super); + Error initialize(uint32_t BlockSize); msf::MSFBuilder &getMsfBuilder(); InfoStreamBuilder &getInfoBuilder(); diff --git a/lib/DebugInfo/MSF/MSFBuilder.cpp b/lib/DebugInfo/MSF/MSFBuilder.cpp index 0b378db51ff..5b1b5d8dc4d 100644 --- a/lib/DebugInfo/MSF/MSFBuilder.cpp +++ b/lib/DebugInfo/MSF/MSFBuilder.cpp @@ -19,12 +19,14 @@ const uint32_t kFreePageMap0Block = 1; const uint32_t kFreePageMap1Block = 2; const uint32_t kNumReservedPages = 3; +const uint32_t kDefaultFreePageMap = kFreePageMap0Block; const uint32_t kDefaultBlockMapAddr = kNumReservedPages; } MSFBuilder::MSFBuilder(uint32_t BlockSize, uint32_t MinBlockCount, bool CanGrow, BumpPtrAllocator &Allocator) - : Allocator(Allocator), IsGrowable(CanGrow), BlockSize(BlockSize), + : Allocator(Allocator), IsGrowable(CanGrow), + FreePageMap(kDefaultFreePageMap), BlockSize(BlockSize), MininumBlocks(MinBlockCount), BlockMapAddr(kDefaultBlockMapAddr), FreeBlocks(MinBlockCount, true) { FreeBlocks[kSuperBlockBlock] = false; diff --git a/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp b/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp index 5b9f9461608..dcd8662913c 100644 --- a/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ b/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -32,18 +32,11 @@ using namespace llvm::support; PDBFileBuilder::PDBFileBuilder(BumpPtrAllocator &Allocator) : Allocator(Allocator) {} -Error PDBFileBuilder::initialize(const msf::SuperBlock &Super) { - auto ExpectedMsf = - MSFBuilder::create(Allocator, Super.BlockSize, Super.NumBlocks); +Error PDBFileBuilder::initialize(uint32_t BlockSize) { + auto ExpectedMsf = MSFBuilder::create(Allocator, BlockSize); if (!ExpectedMsf) return ExpectedMsf.takeError(); - - auto &MsfResult = *ExpectedMsf; - if (auto EC = MsfResult.setBlockMapAddr(Super.BlockMapAddr)) - return EC; - Msf = llvm::make_unique(std::move(MsfResult)); - Msf->setFreePageMap(Super.FreeBlockMapBlock); - Msf->setUnknown1(Super.Unknown1); + Msf = llvm::make_unique(std::move(*ExpectedMsf)); return Error::success(); } diff --git a/test/DebugInfo/PDB/pdbdump-readwrite.test b/test/DebugInfo/PDB/pdbdump-readwrite.test index d378ffa5d01..b2f1debd533 100644 --- a/test/DebugInfo/PDB/pdbdump-readwrite.test +++ b/test/DebugInfo/PDB/pdbdump-readwrite.test @@ -8,8 +8,8 @@ RUN: llvm-pdbdump raw -headers -tpi-records %t.2 | FileCheck %s CHECK: FileHeaders { CHECK-NEXT: BlockSize: 4096 -CHECK-NEXT: FreeBlockMap: 2 -CHECK-NEXT: NumBlocks: 25 +CHECK-NEXT: FreeBlockMap: +CHECK-NEXT: NumBlocks: CHECK-NEXT: NumDirectoryBytes: CHECK-NEXT: Unknown1: 0 CHECK-NEXT: BlockMapAddr: diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp index bfd9058627f..14c6f40b50f 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -323,7 +323,7 @@ static void yamlToPdb(StringRef Path) { PDBFileBuilder Builder(Allocator); - ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock)); + ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock.BlockSize)); // Add each of the reserved streams. We ignore stream metadata in the // yaml, because we will reconstruct our own view of the streams. For // example, the YAML may say that there were 20 streams in the original -- 2.11.0