xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.h (revision f078c492a9b57877c723586db26d789cda1b98ea)
1 //===- MinimalSymbolDumper.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_LLVMPDBUTIL_MINIMAL_SYMBOL_DUMPER_H
10 #define LLVM_TOOLS_LLVMPDBUTIL_MINIMAL_SYMBOL_DUMPER_H
11 
12 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
13 
14 namespace llvm {
15 namespace codeview {
16 class LazyRandomTypeCollection;
17 }
18 
19 namespace pdb {
20 class LinePrinter;
21 class SymbolGroup;
22 
23 class MinimalSymbolDumper : public codeview::SymbolVisitorCallbacks {
24 public:
25   MinimalSymbolDumper(LinePrinter &P, bool RecordBytes,
26                       codeview::LazyRandomTypeCollection &Ids,
27                       codeview::LazyRandomTypeCollection &Types)
28       : P(P), RecordBytes(RecordBytes), Ids(Ids), Types(Types) {}
29   MinimalSymbolDumper(LinePrinter &P, bool RecordBytes,
30                       const SymbolGroup &SymGroup,
31                       codeview::LazyRandomTypeCollection &Ids,
32                       codeview::LazyRandomTypeCollection &Types)
33       : P(P), RecordBytes(RecordBytes), SymGroup(&SymGroup), Ids(Ids),
34         Types(Types) {}
35 
36   Error visitSymbolBegin(codeview::CVSymbol &Record) override;
37   Error visitSymbolBegin(codeview::CVSymbol &Record, uint32_t Offset) override;
38   Error visitSymbolEnd(codeview::CVSymbol &Record) override;
39 
40   void setSymbolGroup(const SymbolGroup *Group) { SymGroup = Group; }
41 
42 #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
43   virtual Error visitKnownRecord(codeview::CVSymbol &CVR,                      \
44                                  codeview::Name &Record) override;
45 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
46 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
47 
48 private:
49   std::string typeOrIdIndex(codeview::TypeIndex TI, bool IsType) const;
50 
51   std::string typeIndex(codeview::TypeIndex TI) const;
52   std::string idIndex(codeview::TypeIndex TI) const;
53 
54   LinePrinter &P;
55 
56   /// Dumping certain records requires knowing what machine this is. The
57   /// S_COMPILE3 record will tell us, but if we don't see one, default to X64.
58   codeview::CPUType CompilationCPU = codeview::CPUType::X64;
59 
60   bool RecordBytes;
61   const SymbolGroup *SymGroup = nullptr;
62   codeview::LazyRandomTypeCollection &Ids;
63   codeview::LazyRandomTypeCollection &Types;
64 };
65 } // namespace pdb
66 } // namespace llvm
67 
68 #endif
69