xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-pdbutil/DumpOutputStyle.h (revision d11f81afd5a4a71d5f725950b0592ca212084780)
1 //===- DumpOutputStyle.h -------------------------------------- *- C++ --*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
11 
12 #include "LinePrinter.h"
13 #include "OutputStyle.h"
14 #include "StreamUtil.h"
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
20 
21 #include <string>
22 
23 namespace llvm {
24 class BitVector;
25 
26 namespace codeview {
27 class LazyRandomTypeCollection;
28 }
29 
30 namespace object {
31 class COFFObjectFile;
32 }
33 
34 namespace pdb {
35 class GSIHashTable;
36 class InputFile;
37 class TypeReferenceTracker;
38 
39 struct StatCollection {
40   struct Stat {
41     Stat() {}
42     Stat(uint32_t Count, uint32_t Size) : Count(Count), Size(Size) {}
43     uint32_t Count = 0;
44     uint32_t Size = 0;
45 
46     void update(uint32_t RecordSize) {
47       ++Count;
48       Size += RecordSize;
49     }
50   };
51 
52   using KindAndStat = std::pair<uint32_t, Stat>;
53 
54   void update(uint32_t Kind, uint32_t RecordSize) {
55     Totals.update(RecordSize);
56     auto Iter = Individual.try_emplace(Kind, 1, RecordSize);
57     if (!Iter.second)
58       Iter.first->second.update(RecordSize);
59   }
60   Stat Totals;
61   DenseMap<uint32_t, Stat> Individual;
62 
63   std::vector<KindAndStat> getStatsSortedBySize() const;
64 };
65 
66 class DumpOutputStyle : public OutputStyle {
67 
68 public:
69   DumpOutputStyle(InputFile &File);
70   ~DumpOutputStyle() override;
71 
72   Error dump() override;
73 
74 private:
75   PDBFile &getPdb();
76   object::COFFObjectFile &getObj();
77 
78   void printStreamNotValidForObj();
79   void printStreamNotPresent(StringRef StreamName);
80 
81   Error dumpFileSummary();
82   Error dumpStreamSummary();
83   Error dumpSymbolStats();
84   Error dumpUdtStats();
85   Error dumpTypeStats();
86   Error dumpNamedStreams();
87   Error dumpStringTable();
88   Error dumpStringTableFromPdb();
89   Error dumpStringTableFromObj();
90   Error dumpLines();
91   Error dumpInlineeLines();
92   Error dumpXmi();
93   Error dumpXme();
94   Error dumpFpo();
95   Error dumpOldFpo(PDBFile &File);
96   Error dumpNewFpo(PDBFile &File);
97   Error dumpTpiStream(uint32_t StreamIdx);
98   Error dumpTypesFromObjectFile();
99   Error dumpTypeRefStats();
100   Error dumpModules();
101   Error dumpModuleFiles();
102   Error dumpModuleSymsForPdb();
103   Error dumpModuleSymsForObj();
104   Error dumpGSIRecords();
105   Error dumpGlobals();
106   Error dumpPublics();
107   Error dumpSymbolsFromGSI(const GSIHashTable &Table, bool HashExtras);
108   Error dumpSectionHeaders();
109   Error dumpSectionContribs();
110   Error dumpSectionMap();
111 
112   void dumpSectionHeaders(StringRef Label, DbgHeaderType Type);
113 
114   InputFile &File;
115   std::unique_ptr<TypeReferenceTracker> RefTracker;
116   LinePrinter P;
117   SmallVector<StreamInfo, 32> StreamPurposes;
118 };
119 } // namespace pdb
120 } // namespace llvm
121 
122 #endif
123