This is an archive of the discontinued LLVM Phabricator instance.

Define PDBFileBuilder::addStream to add stream.
ClosedPublic

Authored by ruiu on Oct 6 2016, 8:25 PM.

Details

Summary

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.

Event Timeline

ruiu updated this revision to Diff 73877.Oct 6 2016, 8:25 PM
ruiu retitled this revision from to Define PDBFileBuilder::addStream to add stream..
ruiu updated this object.
ruiu added a reviewer: zturner.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 73960.Oct 7 2016, 11:47 AM
  • rename PDBFileBuilder::addStream to addDbgStream
  • make addDbgStream to set the directory entry for a new debug stream.
ruiu updated this revision to Diff 73990.Oct 7 2016, 3:06 PM
  • Move addDbgStream to DbiStreamBuilder.
zturner added inline comments.Oct 7 2016, 5:11 PM
include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
97–98

I believe these should be initialized to kInvalidStreamIndex.

97–99

I wonder if this could just be a llvm::SmallVector<ArrayRef<uint8_t>, DbgHeaderType::Max>. This way you don't need one array which indexes into another array, but rather you just have one array altogether that contains all the data.

lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
239–242

Here you will need to loop through the various optional debug streams and call setStreamSize() on each one.

288–289

Here you should check if Idx == kInvalidStreamIndex, and continue if so.

290

Can you use a different variable name here? This Writer shadows the previous Writer, which could be confusing. Maybe calling it DbgStreamWriter.

ruiu marked an inline comment as done.Oct 10 2016, 11:50 AM
ruiu added inline comments.
include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
97–99

We need to distinguish an empty stream from nonexistent stream, so we need to store the stream number somewhere. I defined a new class for that purpose.

lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
239–242

I don't think so. We create a new stream like this

auto ExpectedIndex = Msf.addStream(Data.size());

and because the size will never change, we don't need to adjust the size afterwards.

ruiu updated this revision to Diff 74155.Oct 10 2016, 11:50 AM
  • Updated as per the review comments.
zturner added inline comments.Oct 10 2016, 2:53 PM
lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
49

I think we shouldn't call addStream here. Suppose someone called addDbgStream more than once for the same value of Type. Then you would end up with unreferenced streams in the file. Maybe instead we can just store the ArrayRef, overwriting any previous value of the ArrayRef that was there before. Then in finalizeMsfLayout we can add all the streams.

This way everything is semantically "atomic". No modification to the underlying file happens until you call finalize(), so you can do whatever you want until then without risk of messing anything up.

239–242

Ahh, I didn't see that before. I will go back and comment up there.

ruiu added inline comments.Oct 10 2016, 3:12 PM
lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
49

How about this? I think this is atomic because we check everything that can fail before calling addStream in this function.

ruiu updated this revision to Diff 74179.Oct 10 2016, 3:12 PM
  • Updated as per the review comments.
zturner accepted this revision.Oct 10 2016, 4:32 PM
zturner edited edge metadata.

Hmm, yea I guess you are right.

This revision is now accepted and ready to land.Oct 10 2016, 4:32 PM
This revision was automatically updated to reflect the committed changes.