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