[PATCH] D25356: Define PDBFileBuilder::addStream to add stream.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 20:25:21 PDT 2016
ruiu created this revision.
ruiu added a reviewer: zturner.
ruiu added a subscriber: llvm-commits.
Previously, there is no way to create a stream other than
pre-defined special stream such as DBI or IPI. This patch
adds a new method, addStream, to add a stream of arbitrary
bytes to a PDB file. The new function takes a byte array
and returns the index of the new stream.
https://reviews.llvm.org/D25356
Files:
include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
Index: lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
===================================================================
--- lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
+++ lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
@@ -66,6 +66,16 @@
return *Ipi;
}
+Expected<uint32_t> PDBFileBuilder::addStream(ArrayRef<uint8_t> Data) {
+ auto ExpectedIndex = Msf->addStream(Data.size());
+ if (!ExpectedIndex)
+ return ExpectedIndex.takeError();
+ uint32_t Index = std::move(*ExpectedIndex);
+
+ Streams.emplace_back(Data, Index);
+ return *ExpectedIndex;
+}
+
Expected<msf::MSFLayout> PDBFileBuilder::finalizeMsfLayout() const {
if (Info) {
if (auto EC = Info->finalizeMsfLayout())
@@ -189,5 +199,14 @@
return EC;
}
+ for (auto &Pair : Streams) {
+ ArrayRef<uint8_t> Data = Pair.first;
+ uint32_t Idx = Pair.second;
+ auto Stream = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, Idx);
+ StreamWriter Writer(*Stream);
+ if (auto EC = Writer.writeArray(Data))
+ return EC;
+ }
+
return Buffer.commit();
}
Index: lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
===================================================================
--- lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
+++ lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
@@ -44,6 +44,10 @@
void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
+void DbiStreamBuilder::setDebugStreamIndex(DbgHeaderType Type, uint32_t Index) {
+ DbgStreams[(int)Type] = Index;
+}
+
uint32_t DbiStreamBuilder::calculateSerializedLength() const {
// For now we only support serializing the header.
return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
Index: include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
===================================================================
--- include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
+++ include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
@@ -44,6 +44,9 @@
TpiStreamBuilder &getTpiBuilder();
TpiStreamBuilder &getIpiBuilder();
+ // Add given bytes as a new stream. Returns the stream index.
+ Expected<uint32_t> addStream(ArrayRef<uint8_t> Data);
+
Expected<std::unique_ptr<PDBFile>>
build(std::unique_ptr<msf::WritableStream> PdbFileBuffer);
@@ -59,6 +62,7 @@
std::unique_ptr<DbiStreamBuilder> Dbi;
std::unique_ptr<TpiStreamBuilder> Tpi;
std::unique_ptr<TpiStreamBuilder> Ipi;
+ std::vector<std::pair<ArrayRef<uint8_t>, uint32_t>> Streams;
};
}
}
Index: include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
===================================================================
--- include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
+++ include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
@@ -44,6 +44,7 @@
void setPdbDllRbld(uint16_t R);
void setFlags(uint16_t F);
void setMachineType(PDB_Machine M);
+ void setDebugStreamIndex(DbgHeaderType Type, uint32_t Index);
uint32_t calculateSerializedLength() const;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25356.73877.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161007/46b783d6/attachment.bin>
More information about the llvm-commits
mailing list