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