]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/StreamUtil.cpp
Merge ^/head r319801 through r320041.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / StreamUtil.cpp
1 //===- StreamUtil.cpp - PDB stream utilities --------------------*- 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
10 #include "StreamUtil.h"
11
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"
20
21 namespace llvm {
22 namespace pdb {
23 void discoverStreamPurposes(PDBFile &File,
24                             SmallVectorImpl<std::string> &Purposes) {
25
26   // It's OK if we fail to load some of these streams, we still attempt to print
27   // what we can.
28   auto Dbi = File.getPDBDbiStream();
29   auto Tpi = File.getPDBTpiStream();
30   auto Ipi = File.getPDBIpiStream();
31   auto Info = File.getPDBInfoStream();
32
33   uint32_t StreamCount = File.getNumStreams();
34   DenseMap<uint16_t, DbiModuleDescriptor> ModStreams;
35   DenseMap<uint16_t, std::string> NamedStreams;
36
37   if (Dbi) {
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;
44     }
45   }
46   if (Info) {
47     for (auto &NSE : Info->named_streams()) {
48       if (NSE.second != kInvalidStreamIndex)
49         NamedStreams[NSE.second] = NSE.first();
50     }
51   }
52
53   Purposes.resize(StreamCount);
54   for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
55     std::string Value;
56     if (StreamIdx == OldMSFDirectory)
57       Value = "Old MSF Directory";
58     else if (StreamIdx == StreamPDB)
59       Value = "PDB Stream";
60     else if (StreamIdx == StreamDBI)
61       Value = "DBI Stream";
62     else if (StreamIdx == StreamTPI)
63       Value = "TPI Stream";
64     else if (StreamIdx == StreamIPI)
65       Value = "IPI Stream";
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())
73       Value = "TPI Hash";
74     else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
75       Value = "TPI Aux Hash";
76     else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
77       Value = "IPI Hash";
78     else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
79       Value = "IPI Aux Hash";
80     else if (Dbi &&
81              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
82       Value = "Exception Data";
83     else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
84       Value = "Fixup Data";
85     else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
86       Value = "FPO Data";
87     else if (Dbi &&
88              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
89       Value = "New FPO Data";
90     else if (Dbi &&
91              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
92       Value = "Omap From Source Data";
93     else if (Dbi &&
94              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
95       Value = "Omap To Source Data";
96     else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
97       Value = "Pdata";
98     else if (Dbi &&
99              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
100       Value = "Section Header Data";
101     else if (Dbi &&
102              StreamIdx ==
103                  Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
104       Value = "Section Header Original Data";
105     else if (Dbi &&
106              StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
107       Value = "Token Rid Data";
108     else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
109       Value = "Xdata";
110     else {
111       auto ModIter = ModStreams.find(StreamIdx);
112       auto NSIter = NamedStreams.find(StreamIdx);
113       if (ModIter != ModStreams.end()) {
114         Value = "Module \"";
115         Value += ModIter->second.getModuleName();
116         Value += "\"";
117       } else if (NSIter != NamedStreams.end()) {
118         Value = "Named Stream \"";
119         Value += NSIter->second;
120         Value += "\"";
121       } else {
122         Value = "???";
123       }
124     }
125     Purposes[StreamIdx] = Value;
126   }
127
128   // Consume errors from missing streams.
129   if (!Dbi)
130     consumeError(Dbi.takeError());
131   if (!Tpi)
132     consumeError(Tpi.takeError());
133   if (!Ipi)
134     consumeError(Ipi.takeError());
135   if (!Info)
136     consumeError(Info.takeError());
137 }
138 }
139 }