[lld] r281704 - Use functions in DebugInfoPDB to create dummy PDB file.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 21:32:33 PDT 2016
Author: ruiu
Date: Thu Sep 15 23:32:33 2016
New Revision: 281704
URL: http://llvm.org/viewvc/llvm-project?rev=281704&view=rev
Log:
Use functions in DebugInfoPDB to create dummy PDB file.
I don't think we are creating valid PDB file here,
but it is okay because we have never created valid PDBs before.
Modified:
lld/trunk/COFF/CMakeLists.txt
lld/trunk/COFF/PDB.cpp
lld/trunk/test/COFF/pdb.test
Modified: lld/trunk/COFF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/CMakeLists.txt?rev=281704&r1=281703&r2=281704&view=diff
==============================================================================
--- lld/trunk/COFF/CMakeLists.txt (original)
+++ lld/trunk/COFF/CMakeLists.txt Thu Sep 15 23:32:33 2016
@@ -21,6 +21,7 @@ add_lld_library(lldCOFF
LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Core
+ DebugInfoPDB
LTO
LibDriver
Object
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=281704&r1=281703&r2=281704&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Sep 15 23:32:33 2016
@@ -9,7 +9,16 @@
#include "PDB.h"
#include "Error.h"
+#include "llvm/DebugInfo/MSF/MSFBuilder.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
+#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
+#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
+#include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h"
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h"
+#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
+#include "llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/FileOutputBuffer.h"
#include <memory>
@@ -19,36 +28,45 @@ using namespace llvm;
using namespace llvm::support;
using namespace llvm::support::endian;
+static ExitOnError ExitOnErr;
+
const int BlockSize = 4096;
void coff::createPDB(StringRef Path) {
// Create a file.
- size_t FileSize = BlockSize * 3;
- ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
- FileOutputBuffer::create(Path, FileSize);
+ size_t FileSize = BlockSize * 10;
+ auto BufferOrErr = FileOutputBuffer::create(Path, FileSize);
if (auto EC = BufferOrErr.getError())
fatal(EC, "failed to open " + Path);
- std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
-
- // Write the file header.
- uint8_t *Buf = Buffer->getBufferStart();
- auto *SB = reinterpret_cast<msf::SuperBlock *>(Buf);
- memcpy(SB->MagicBytes, msf::Magic, sizeof(msf::Magic));
- SB->BlockSize = BlockSize;
-
- // FreeBlockMap is a page number containing free page map bitmap.
- // Set a dummy value for now.
- SB->FreeBlockMapBlock = 1;
-
- SB->NumBlocks = FileSize / BlockSize;
-
- // Root directory is empty, containing only the length field.
- SB->NumDirectoryBytes = 4;
+ auto FileByteStream =
+ llvm::make_unique<msf::FileBufferByteStream>(std::move(*BufferOrErr));
- // Root directory is on page 1.
- SB->BlockMapAddr = 1;
+ // Create the superblock.
+ msf::SuperBlock SB;
+ memcpy(SB.MagicBytes, msf::Magic, sizeof(msf::Magic));
+ SB.BlockSize = 4096;
+ SB.FreeBlockMapBlock = 2;
+ SB.NumBlocks = 10;
+ SB.NumDirectoryBytes = 0;
+ SB.Unknown1 = 0;
+ SB.BlockMapAddr = 9;
+
+ BumpPtrAllocator Alloc;
+ pdb::PDBFileBuilder Builder(Alloc);
+ ExitOnErr(Builder.initialize(SB));
+ ExitOnErr(Builder.getMsfBuilder().setDirectoryBlocksHint({8}));
+
+ ExitOnErr(Builder.getMsfBuilder().addStream(1, {4}));
+ ExitOnErr(Builder.getMsfBuilder().addStream(1, {5}));
+ ExitOnErr(Builder.getMsfBuilder().addStream(1, {6}));
+
+ // Add an empty IPI stream.
+ Builder.getInfoBuilder();
+
+ // Add an empty TPI stream.
+ auto &TpiBuilder = Builder.getTpiBuilder();
+ TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
// Write the root directory. Root stream is on page 2.
- write32le(Buf + BlockSize, 2);
- Buffer->commit();
+ ExitOnErr(Builder.commit(*FileByteStream));
}
Modified: lld/trunk/test/COFF/pdb.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb.test?rev=281704&r1=281703&r2=281704&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb.test (original)
+++ lld/trunk/test/COFF/pdb.test Thu Sep 15 23:32:33 2016
@@ -4,18 +4,21 @@
# CHECK: MSF:
# CHECK-NEXT: SuperBlock:
-# CHECK-NEXT: BlockSize: 4096
-# CHECK-NEXT: FreeBlockMap: 1
-# CHECK-NEXT: NumBlocks: 3
-# CHECK-NEXT: NumDirectoryBytes: 4
-# CHECK-NEXT: Unknown1: 0
-# CHECK-NEXT: BlockMapAddr: 1
-# CHECK-NEXT: NumDirectoryBlocks: 1
-# CHECK-NEXT: DirectoryBlocks: [ 2 ]
-# CHECK-NEXT: NumStreams: 0
-# CHECK-NEXT: FileSize: 12288
-# CHECK-NEXT: StreamSizes: [ ]
+# CHECK-NEXT: BlockSize: 4096
+# CHECK-NEXT: FreeBlockMap: 2
+# CHECK-NEXT: NumBlocks: 10
+# CHECK-NEXT: NumDirectoryBytes: 28
+# CHECK-NEXT: Unknown1: 0
+# CHECK-NEXT: BlockMapAddr: 9
+# CHECK-NEXT: NumDirectoryBlocks: 1
+# CHECK-NEXT: DirectoryBlocks: [ 8 ]
+# CHECK-NEXT: NumStreams: 3
+# CHECK-NEXT: FileSize: 40960
+# CHECK-NEXT: StreamSizes: [ 1, 48, 56 ]
# CHECK-NEXT: StreamMap:
+# CHECK-NEXT: - Stream: [ 4 ]
+# CHECK-NEXT: - Stream: [ 5 ]
+# CHECK-NEXT: - Stream: [ 6 ]
--- !COFF
header:
More information about the llvm-commits
mailing list