1 //===- StreamUtil.cpp - PDB stream utilities --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "StreamUtil.h"
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/DenseMapInfo.h"
14 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
15 #include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
16 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
17 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
18 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
19 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
23 void discoverStreamPurposes(PDBFile &File,
24 SmallVectorImpl<std::string> &Purposes) {
26 // It's OK if we fail to load some of these streams, we still attempt to print
28 auto Dbi = File.getPDBDbiStream();
29 auto Tpi = File.getPDBTpiStream();
30 auto Ipi = File.getPDBIpiStream();
31 auto Info = File.getPDBInfoStream();
33 uint32_t StreamCount = File.getNumStreams();
34 DenseMap<uint16_t, DbiModuleDescriptor> ModStreams;
35 DenseMap<uint16_t, std::string> NamedStreams;
38 const DbiModuleList &Modules = Dbi->modules();
39 for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
40 DbiModuleDescriptor Descriptor = Modules.getModuleDescriptor(I);
41 uint16_t SN = Descriptor.getModuleStreamIndex();
42 if (SN != kInvalidStreamIndex)
43 ModStreams[SN] = Descriptor;
47 for (auto &NSE : Info->named_streams()) {
48 if (NSE.second != kInvalidStreamIndex)
49 NamedStreams[NSE.second] = NSE.first();
53 Purposes.resize(StreamCount);
54 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
56 if (StreamIdx == OldMSFDirectory)
57 Value = "Old MSF Directory";
58 else if (StreamIdx == StreamPDB)
60 else if (StreamIdx == StreamDBI)
62 else if (StreamIdx == StreamTPI)
64 else if (StreamIdx == StreamIPI)
66 else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
67 Value = "Global Symbol Hash";
68 else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
69 Value = "Public Symbol Hash";
70 else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
71 Value = "Public Symbol Records";
72 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
74 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
75 Value = "TPI Aux Hash";
76 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
78 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
79 Value = "IPI Aux Hash";
81 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
82 Value = "Exception Data";
83 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
85 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
88 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
89 Value = "New FPO Data";
91 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
92 Value = "Omap From Source Data";
94 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
95 Value = "Omap To Source Data";
96 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
99 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
100 Value = "Section Header Data";
103 Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
104 Value = "Section Header Original Data";
106 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
107 Value = "Token Rid Data";
108 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
111 auto ModIter = ModStreams.find(StreamIdx);
112 auto NSIter = NamedStreams.find(StreamIdx);
113 if (ModIter != ModStreams.end()) {
115 Value += ModIter->second.getModuleName();
117 } else if (NSIter != NamedStreams.end()) {
118 Value = "Named Stream \"";
119 Value += NSIter->second;
125 Purposes[StreamIdx] = Value;
128 // Consume errors from missing streams.
130 consumeError(Dbi.takeError());
132 consumeError(Tpi.takeError());
134 consumeError(Ipi.takeError());
136 consumeError(Info.takeError());