| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 1 | //===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
| Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 11 |  | 
| Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" | 
| Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" | 
| Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" | 
|  | 15 | #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h" | 
|  | 16 | #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" | 
|  | 17 | #include "llvm/DebugInfo/PDB/Native/RawError.h" | 
|  | 18 | #include "llvm/DebugInfo/PDB/Native/RawTypes.h" | 
| Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 19 | #include "llvm/Support/BinaryStreamWriter.h" | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 20 |  | 
|  | 21 | using namespace llvm; | 
|  | 22 | using namespace llvm::codeview; | 
| Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 23 | using namespace llvm::msf; | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 24 | using namespace llvm::pdb; | 
|  | 25 |  | 
| Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 26 | InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf, | 
|  | 27 | NamedStreamMap &NamedStreams) | 
| Zachary Turner | c6a75a6 | 2018-03-01 18:00:29 +0000 | [diff] [blame] | 28 | : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Age(0), | 
|  | 29 | NamedStreams(NamedStreams) { | 
|  | 30 | ::memset(&Guid, 0, sizeof(Guid)); | 
|  | 31 | } | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; } | 
|  | 34 |  | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 35 | void InfoStreamBuilder::setAge(uint32_t A) { Age = A; } | 
|  | 36 |  | 
| Zachary Turner | c6a75a6 | 2018-03-01 18:00:29 +0000 | [diff] [blame] | 37 | void InfoStreamBuilder::setSignature(uint32_t S) { Signature = S; } | 
|  | 38 |  | 
| Reid Kleckner | 67653ee | 2017-07-17 23:59:44 +0000 | [diff] [blame] | 39 | void InfoStreamBuilder::setGuid(GUID G) { Guid = G; } | 
| Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 40 |  | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 41 | void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) { | 
|  | 42 | Features.push_back(Sig); | 
|  | 43 | } | 
|  | 44 |  | 
| Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 45 | Error InfoStreamBuilder::finalizeMsfLayout() { | 
| Zachary Turner | cafd476 | 2018-02-16 20:46:04 +0000 | [diff] [blame] | 46 | uint32_t Length = sizeof(InfoStreamHeader) + | 
|  | 47 | NamedStreams.calculateSerializedLength() + | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 48 | (Features.size() + 1) * sizeof(uint32_t); | 
| Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 49 | if (auto EC = Msf.setStreamSize(StreamPDB, Length)) | 
|  | 50 | return EC; | 
|  | 51 | return Error::success(); | 
|  | 52 | } | 
|  | 53 |  | 
| Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 54 | Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout, | 
| Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 55 | WritableBinaryStreamRef Buffer) const { | 
| Zachary Turner | 5b74ff3 | 2017-06-03 00:33:35 +0000 | [diff] [blame] | 56 | auto InfoS = WritableMappedBlockStream::createIndexedStream( | 
|  | 57 | Layout, Buffer, StreamPDB, Msf.getAllocator()); | 
| Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 58 | BinaryStreamWriter Writer(*InfoS); | 
| Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 59 |  | 
|  | 60 | InfoStreamHeader H; | 
| Zachary Turner | c6a75a6 | 2018-03-01 18:00:29 +0000 | [diff] [blame] | 61 | // Leave the build id fields 0 so they can be set as the last step before | 
|  | 62 | // committing the file to disk. | 
|  | 63 | ::memset(&H, 0, sizeof(H)); | 
| Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 64 | H.Version = Ver; | 
| Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 65 | if (auto EC = Writer.writeObject(H)) | 
|  | 66 | return EC; | 
|  | 67 |  | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 68 | if (auto EC = NamedStreams.commit(Writer)) | 
|  | 69 | return EC; | 
|  | 70 | if (auto EC = Writer.writeInteger(0)) | 
|  | 71 | return EC; | 
|  | 72 | for (auto E : Features) { | 
|  | 73 | if (auto EC = Writer.writeEnum(E)) | 
|  | 74 | return EC; | 
|  | 75 | } | 
| Zachary Turner | a6fb536 | 2018-03-23 18:43:39 +0000 | [diff] [blame] | 76 | assert(Writer.bytesRemaining() == 0); | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 77 | return Error::success(); | 
| Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 78 | } |