llvm.org GIT mirror llvm / 777bbb5
[llvm-pdbutil] Dump raw bytes of various DBI stream subsections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306160 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
9 changed file(s) with 260 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
6262
6363 PDB_Machine getMachineType() const;
6464
65 BinarySubstreamRef getSectionContributionData() const;
66 BinarySubstreamRef getSecMapSubstreamData() const;
67 BinarySubstreamRef getModiSubstreamData() const;
68 BinarySubstreamRef getFileInfoSubstreamData() const;
69 BinarySubstreamRef getTypeServerMapSubstreamData() const;
70 BinarySubstreamRef getECSubstreamData() const;
71
6572 /// If the given stream type is present, returns its stream index. If it is
6673 /// not present, returns InvalidStreamIndex.
6774 uint32_t getDebugStreamIndex(DbgHeaderType Type) const;
8693
8794 PDBStringTable ECNames;
8895
89 BinaryStreamRef SecContrSubstream;
90 BinaryStreamRef SecMapSubstream;
91 BinaryStreamRef TypeServerMapSubstream;
92 BinaryStreamRef ECSubstream;
96 BinarySubstreamRef SecContrSubstream;
97 BinarySubstreamRef SecMapSubstream;
98 BinarySubstreamRef ModiSubstream;
99 BinarySubstreamRef FileInfoSubstream;
100 BinarySubstreamRef TypeServerMapSubstream;
101 BinarySubstreamRef ECSubstream;
93102
94103 DbiModuleList Modules;
95104
168168 struct BinarySubstreamRef {
169169 uint32_t Offset; // Offset in the parent stream
170170 BinaryStreamRef StreamData; // Stream Data
171
172 uint32_t size() const { return StreamData.getLength(); }
173 bool empty() const { return size() == 0; }
171174 };
172175
173176 class WritableBinaryStreamRef
9898 return make_error(raw_error_code::corrupt_file,
9999 "DBI type server substream not aligned.");
100100
101 BinaryStreamRef ModInfoSubstream;
102 BinaryStreamRef FileInfoSubstream;
101 if (auto EC = Reader.readSubstream(ModiSubstream, Header->ModiSubstreamSize))
102 return EC;
103
104 if (auto EC = Reader.readSubstream(SecContrSubstream,
105 Header->SecContrSubstreamSize))
106 return EC;
107 if (auto EC = Reader.readSubstream(SecMapSubstream, Header->SectionMapSize))
108 return EC;
109 if (auto EC = Reader.readSubstream(FileInfoSubstream, Header->FileInfoSize))
110 return EC;
103111 if (auto EC =
104 Reader.readStreamRef(ModInfoSubstream, Header->ModiSubstreamSize))
105 return EC;
106
107 if (auto EC = Reader.readStreamRef(SecContrSubstream,
108 Header->SecContrSubstreamSize))
109 return EC;
110 if (auto EC = Reader.readStreamRef(SecMapSubstream, Header->SectionMapSize))
111 return EC;
112 if (auto EC = Reader.readStreamRef(FileInfoSubstream, Header->FileInfoSize))
113 return EC;
114 if (auto EC =
115 Reader.readStreamRef(TypeServerMapSubstream, Header->TypeServerSize))
116 return EC;
117 if (auto EC = Reader.readStreamRef(ECSubstream, Header->ECSubstreamSize))
112 Reader.readSubstream(TypeServerMapSubstream, Header->TypeServerSize))
113 return EC;
114 if (auto EC = Reader.readSubstream(ECSubstream, Header->ECSubstreamSize))
118115 return EC;
119116 if (auto EC = Reader.readArray(
120117 DbgStreams, Header->OptionalDbgHdrSize / sizeof(ulittle16_t)))
121118 return EC;
122119
123 if (auto EC = Modules.initialize(ModInfoSubstream, FileInfoSubstream))
120 if (auto EC = Modules.initialize(ModiSubstream.StreamData,
121 FileInfoSubstream.StreamData))
124122 return EC;
125123
126124 if (auto EC = initializeSectionContributionData())
136134 return make_error(raw_error_code::corrupt_file,
137135 "Found unexpected bytes in DBI Stream.");
138136
139 if (ECSubstream.getLength() > 0) {
140 BinaryStreamReader ECReader(ECSubstream);
137 if (!ECSubstream.empty()) {
138 BinaryStreamReader ECReader(ECSubstream.StreamData);
141139 if (auto EC = ECNames.reload(ECReader))
142140 return EC;
143141 }
227225 }
228226
229227 Error DbiStream::initializeSectionContributionData() {
230 if (SecContrSubstream.getLength() == 0)
231 return Error::success();
232
233 BinaryStreamReader SCReader(SecContrSubstream);
228 if (SecContrSubstream.empty())
229 return Error::success();
230
231 BinaryStreamReader SCReader(SecContrSubstream.StreamData);
234232 if (auto EC = SCReader.readEnum(SectionContribVersion))
235233 return EC;
236234
301299 return Error::success();
302300 }
303301
302 BinarySubstreamRef DbiStream::getSectionContributionData() const {
303 return SecContrSubstream;
304 }
305
306 BinarySubstreamRef DbiStream::getSecMapSubstreamData() const {
307 return SecMapSubstream;
308 }
309
310 BinarySubstreamRef DbiStream::getModiSubstreamData() const {
311 return ModiSubstream;
312 }
313
314 BinarySubstreamRef DbiStream::getFileInfoSubstreamData() const {
315 return FileInfoSubstream;
316 }
317
318 BinarySubstreamRef DbiStream::getTypeServerMapSubstreamData() const {
319 return TypeServerMapSubstream;
320 }
321
322 BinarySubstreamRef DbiStream::getECSubstreamData() const { return ECSubstream; }
323
304324 Error DbiStream::initializeSectionMapData() {
305 if (SecMapSubstream.getLength() == 0)
306 return Error::success();
307
308 BinaryStreamReader SMReader(SecMapSubstream);
325 if (SecMapSubstream.empty())
326 return Error::success();
327
328 BinaryStreamReader SMReader(SecMapSubstream.StreamData);
309329 const SecMapHeader *Header;
310330 if (auto EC = SMReader.readObject(Header))
311331 return EC;
0 ; RUN: llvm-pdbutil bytes -ec %p/Inputs/empty.pdb | FileCheck --check-prefix=EC %s
1 ; RUN: llvm-pdbutil bytes -files %p/Inputs/empty.pdb | FileCheck --check-prefix=FILES %s
2 ; RUN: llvm-pdbutil bytes -modi %p/Inputs/empty.pdb | FileCheck --check-prefix=MODI %s
3 ; RUN: llvm-pdbutil bytes -sc %p/Inputs/empty.pdb | FileCheck --check-prefix=SC %s
4 ; RUN: llvm-pdbutil bytes -sm %p/Inputs/empty.pdb | FileCheck --check-prefix=SM %s
5 ; RUN: llvm-pdbutil bytes -type-server %p/Inputs/empty.pdb | FileCheck --check-prefix=TYPE-SERVER %s
6
7 EC: Edit and Continue Data
8 EC-NEXT: ============================================================
9 EC-NEXT: Edit and Continue Data (
10 EC-NEXT: E280: FEEFFEEF 01000000 31000000 00643A5C 7372635C 6C6C766D 5C746573 745C4465 |........1....d:\src\llvm\test\De|
11 EC-NEXT: E2A0: 62756749 6E666F5C 5044425C 496E7075 74735C65 6D707479 2E706462 00020000 |bugInfo\PDB\Inputs\empty.pdb....|
12 EC-NEXT: E2C0: 00010000 00000000 00010000 00 |.............|
13 EC-NEXT: )
14
15 FILES: File Info
16 FILES-NEXT: ============================================================
17 FILES-NEXT: File Info (
18 FILES-NEXT: E240: 02000100 00000100 01000000 00000000 643A5C73 72635C6C 6C766D5C 74657374 |................d:\src\llvm\test|
19 FILES-NEXT: E260: 5C646562 7567696E 666F5C70 64625C69 6E707574 735C656D 7074792E 63707000 |\debuginfo\pdb\inputs\empty.cpp.|
20 FILES-NEXT: )
21
22 MODI: Module Infos
23 MODI-NEXT: ============================================================
24 MODI-NEXT: Module Infos (
25 MODI-NEXT: E040: 00000000 01000000 10000000 0A000000 20005060 00000000 347497D7 00000000 |................ .P`....4t......|
26 MODI-NEXT: E060: 00000C00 D0000000 00000000 58000000 01000000 D035E900 00000000 00000000 |............X........5..........|
27 MODI-NEXT: E080: 643A5C73 72635C6C 6C766D5C 74657374 5C446562 7567496E 666F5C50 44425C49 |d:\src\llvm\test\DebugInfo\PDB\I|
28 MODI-NEXT: E0A0: 6E707574 735C656D 7074792E 6F626A00 643A5C73 72635C6C 6C766D5C 74657374 |nputs\empty.obj.d:\src\llvm\test|
29 MODI-NEXT: E0C0: 5C446562 7567496E 666F5C50 44425C49 6E707574 735C656D 7074792E 6F626A00 |\DebugInfo\PDB\Inputs\empty.obj.|
30 MODI-NEXT: E0E0: 00000000 01000000 00000000 0A000000 20000060 01000000 00000000 00000000 |................ ..`............|
31 MODI-NEXT: E100: 00000E00 04020000 00000000 00000000 00000000 00000000 00000000 01000000 |................................|
32 MODI-NEXT: E120: 2A204C69 6E6B6572 202A0000 |* Linker *..|
33 MODI-NEXT: )
34
35 SC: Section Contributions
36 SC-NEXT: ============================================================
37 SC-NEXT: Section Contributions (
38 SC-NEXT: E12C: 2DBA2EF1 01002511 00000000 0A000000 20000060 01000000 00000000 00000000 |-.....%......... ..`............|
39 SC-NEXT: E14C: 01000000 10000000 0A000000 20005060 00000000 347497D7 00000000 02000000 |............ .P`....4t..........|
40 SC-NEXT: E16C: 00000000 38000000 40000040 01000000 00000000 00000000 02000000 44010000 |....8...@..@................D...|
41 SC-NEXT: E18C: 48000000 40003040 01000000 00000000 00000000 02000000 8C010000 14000000 |H...@.0@........................|
42 SC-NEXT: E1AC: 40003040 01000000 00000000 00000000 03000000 00000000 04000000 800030C0 |@.0@..........................0.|
43 SC-NEXT: E1CC: 00000000 00000000 00000000 |............|
44 SC-NEXT: )
45
46 SM: Section Map
47 SM-NEXT: ============================================================
48 SM-NEXT: Section Map (
49 SM-NEXT: E1D8: 05000500 0D010000 00000100 FFFFFFFF 00000000 1A100000 09010000 00000200 |................................|
50 SM-NEXT: E1F8: FFFFFFFF 00000000 B2020000 0B010000 00000300 FFFFFFFF 00000000 04000000 |................................|
51 SM-NEXT: E218: 09010000 00000400 FFFFFFFF 00000000 08000000 08020000 00000000 FFFFFFFF |................................|
52 SM-NEXT: E238: 00000000 FFFFFFFF |........|
53 SM-NEXT: )
54
55 TYPE-SERVER: Type Server Map
56 TYPE-SERVER-NEXT: ============================================================
57 TYPE-SERVER-NEXT: Type Server Map (
58 TYPE-SERVER-NEXT: )
1212 #include "llvm-pdbutil.h"
1313
1414 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
1516 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
1617 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
1718 #include "llvm/DebugInfo/PDB/Native/RawError.h"
121122 dumpNameMap();
122123 P.NewLine();
123124 }
125
126 if (opts::bytes::SectionContributions) {
127 dumpSectionContributions();
128 P.NewLine();
129 }
130
131 if (opts::bytes::SectionMap) {
132 dumpSectionMap();
133 P.NewLine();
134 }
135
136 if (opts::bytes::ModuleInfos) {
137 dumpModuleInfos();
138 P.NewLine();
139 }
140
141 if (opts::bytes::FileInfo) {
142 dumpFileInfo();
143 P.NewLine();
144 }
145
146 if (opts::bytes::TypeServerMap) {
147 dumpTypeServerMap();
148 P.NewLine();
149 }
150
151 if (opts::bytes::ECData) {
152 dumpECData();
153 P.NewLine();
154 }
155
124156 return Error::success();
125157 }
126158
154186 }
155187 }
156188
189 void BytesOutputStyle::dumpSectionContributions() {
190 printHeader(P, "Section Contributions");
191
192 AutoIndent Indent(P);
193
194 auto &DbiS = Err(File.getPDBDbiStream());
195 BinarySubstreamRef NS = DbiS.getSectionContributionData();
196 auto Layout = File.getStreamLayout(StreamDBI);
197 P.formatMsfStreamData("Section Contributions", File, Layout, NS);
198 }
199
200 void BytesOutputStyle::dumpSectionMap() {
201 printHeader(P, "Section Map");
202
203 AutoIndent Indent(P);
204
205 auto &DbiS = Err(File.getPDBDbiStream());
206 BinarySubstreamRef NS = DbiS.getSecMapSubstreamData();
207 auto Layout = File.getStreamLayout(StreamDBI);
208 P.formatMsfStreamData("Section Map", File, Layout, NS);
209 }
210
211 void BytesOutputStyle::dumpModuleInfos() {
212 printHeader(P, "Module Infos");
213
214 AutoIndent Indent(P);
215
216 auto &DbiS = Err(File.getPDBDbiStream());
217 BinarySubstreamRef NS = DbiS.getModiSubstreamData();
218 auto Layout = File.getStreamLayout(StreamDBI);
219 P.formatMsfStreamData("Module Infos", File, Layout, NS);
220 }
221
222 void BytesOutputStyle::dumpFileInfo() {
223 printHeader(P, "File Info");
224
225 AutoIndent Indent(P);
226
227 auto &DbiS = Err(File.getPDBDbiStream());
228 BinarySubstreamRef NS = DbiS.getFileInfoSubstreamData();
229 auto Layout = File.getStreamLayout(StreamDBI);
230 P.formatMsfStreamData("File Info", File, Layout, NS);
231 }
232
233 void BytesOutputStyle::dumpTypeServerMap() {
234 printHeader(P, "Type Server Map");
235
236 AutoIndent Indent(P);
237
238 auto &DbiS = Err(File.getPDBDbiStream());
239 BinarySubstreamRef NS = DbiS.getTypeServerMapSubstreamData();
240 auto Layout = File.getStreamLayout(StreamDBI);
241 P.formatMsfStreamData("Type Server Map", File, Layout, NS);
242 }
243
244 void BytesOutputStyle::dumpECData() {
245 printHeader(P, "Edit and Continue Data");
246
247 AutoIndent Indent(P);
248
249 auto &DbiS = Err(File.getPDBDbiStream());
250 BinarySubstreamRef NS = DbiS.getECSubstreamData();
251 auto Layout = File.getStreamLayout(StreamDBI);
252 P.formatMsfStreamData("Edit and Continue Data", File, Layout, NS);
253 }
254
157255 void BytesOutputStyle::dumpByteRanges(uint32_t Min, uint32_t Max) {
158256 printHeader(P, "MSF Bytes");
159257
3232 void dumpByteRanges(uint32_t Min, uint32_t Max);
3333 void dumpStreamBytes();
3434
35 void dumpSectionContributions();
36 void dumpSectionMap();
37 void dumpModuleInfos();
38 void dumpFileInfo();
39 void dumpTypeServerMap();
40 void dumpECData();
41
3542 PDBFile &File;
3643 LinePrinter P;
3744 ExitOnError Err;
145145 ArrayRef Blocks = Layout.Blocks;
146146 assert(!Blocks.empty());
147147 uint32_t StreamBytesRemaining = Layout.Length;
148 Runs.emplace_back(Blocks[0]);
148 uint32_t CurrentBlock = Blocks[0];
149 Runs.emplace_back(CurrentBlock);
149150 while (!Blocks.empty()) {
150151 Run *CurrentRun = &Runs.back();
151152 uint32_t NextBlock = Blocks.front();
152 if (NextBlock < CurrentRun->Block || (NextBlock - CurrentRun->Block > 1)) {
153 if (NextBlock < CurrentBlock || (NextBlock - CurrentBlock > 1)) {
153154 Runs.emplace_back(NextBlock);
154155 CurrentRun = &Runs.back();
155156 }
156
157157 uint32_t Used = std::min(BlockSize, StreamBytesRemaining);
158158 CurrentRun->ByteLen += Used;
159159 StreamBytesRemaining -= Used;
160 CurrentBlock = NextBlock;
160161 Blocks = Blocks.drop_front();
161162 }
162163 return Runs;
266266 cl::OptionCategory FileOptions("Module & File Options");
267267
268268 namespace bytes {
269 cl::OptionCategory MsfBytes("MSF File Options");
270 cl::OptionCategory DbiBytes("Dbi Stream Options");
271 cl::OptionCategory PdbBytes("PDB Stream Options");
272
269273 llvm::Optional DumpBlockRange;
270274 llvm::Optional DumpByteRange;
271275
272276 cl::opt DumpBlockRangeOpt(
273277 "block-range", cl::value_desc("start[-end]"),
274278 cl::desc("Dump binary data from specified range of blocks."),
275 cl::sub(BytesSubcommand));
279 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
276280
277281 cl::opt
278282 DumpByteRangeOpt("byte-range", cl::value_desc("start[-end]"),
279283 cl::desc("Dump binary data from specified range of bytes"),
280 cl::sub(BytesSubcommand));
284 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
281285
282286 cl::list
283287 DumpStreamData("stream-data", cl::CommaSeparated, cl::ZeroOrMore,
284288 cl::desc("Dump binary data from specified streams. Format "
285289 "is SN[:Start][@Size]"),
286 cl::sub(BytesSubcommand));
290 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
287291
288292 cl::opt NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
289 cl::sub(BytesSubcommand));
293 cl::sub(BytesSubcommand), cl::cat(PdbBytes));
294
295 cl::opt SectionContributions("sc", cl::desc("Dump section contributions"),
296 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
297 cl::opt SectionMap("sm", cl::desc("Dump section map"),
298 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
299 cl::opt ModuleInfos("modi", cl::desc("Dump module info"),
300 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
301 cl::opt FileInfo("files", cl::desc("Dump source file info"),
302 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
303 cl::opt TypeServerMap("type-server", cl::desc("Dump type server map"),
304 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
305 cl::opt ECData("ec", cl::desc("Dump edit and continue map"),
306 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
290307
291308 cl::list InputFilenames(cl::Positional,
292309 cl::desc(""),
101101 extern llvm::Optional DumpByteRange;
102102 extern llvm::cl::list DumpStreamData;
103103 extern llvm::cl::opt NameMap;
104
105 extern llvm::cl::opt SectionContributions;
106 extern llvm::cl::opt SectionMap;
107 extern llvm::cl::opt ModuleInfos;
108 extern llvm::cl::opt FileInfo;
109 extern llvm::cl::opt TypeServerMap;
110 extern llvm::cl::opt ECData;
111
104112 } // namespace bytes
105113
106114 namespace dump {