[DebugInfo] Avoid re-ordering assignments in LCSSA
[llvm-project.git] / llvm / tools / llvm-readobj / ObjDumper.h
blobd4e166b504cf2ad68f0643cb263d8da8d31457bb
1 //===-- ObjDumper.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
10 #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
12 #include <memory>
13 #include <system_error>
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Object/ObjectFile.h"
17 #include "llvm/Support/CommandLine.h"
19 #include <unordered_set>
21 namespace llvm {
22 namespace object {
23 class COFFImportFile;
24 class ObjectFile;
25 class XCOFFObjectFile;
26 class ELFObjectFileBase;
28 namespace codeview {
29 class GlobalTypeTableBuilder;
30 class MergingTypeTableBuilder;
31 } // namespace codeview
33 class ScopedPrinter;
35 class ObjDumper {
36 public:
37 ObjDumper(ScopedPrinter &Writer, StringRef ObjName);
38 virtual ~ObjDumper();
40 virtual bool canDumpContent() { return true; }
42 virtual void printFileHeaders() = 0;
43 virtual void printSectionHeaders() = 0;
44 virtual void printRelocations() = 0;
45 virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) {
46 if (PrintSymbols)
47 printSymbols();
48 if (PrintDynamicSymbols)
49 printDynamicSymbols();
51 virtual void printProgramHeaders(bool PrintProgramHeaders,
52 cl::boolOrDefault PrintSectionMapping) {
53 if (PrintProgramHeaders)
54 printProgramHeaders();
55 if (PrintSectionMapping == cl::BOU_TRUE)
56 printSectionMapping();
59 virtual void printUnwindInfo() = 0;
61 // Only implemented for ELF at this time.
62 virtual void printDependentLibs() {}
63 virtual void printDynamicRelocations() { }
64 virtual void printDynamicTable() { }
65 virtual void printNeededLibraries() { }
66 virtual void printSectionAsHex(StringRef SectionName) {}
67 virtual void printHashTable() { }
68 virtual void printGnuHashTable() {}
69 virtual void printHashSymbols() {}
70 virtual void printLoadName() {}
71 virtual void printVersionInfo() {}
72 virtual void printGroupSections() {}
73 virtual void printHashHistograms() {}
74 virtual void printCGProfile() {}
75 virtual void printAddrsig() {}
76 virtual void printNotes() {}
77 virtual void printELFLinkerOptions() {}
78 virtual void printStackSizes() {}
79 virtual void printSectionDetails() {}
80 virtual void printArchSpecificInfo() {}
82 // Only implemented for PE/COFF.
83 virtual void printCOFFImports() { }
84 virtual void printCOFFExports() { }
85 virtual void printCOFFDirectives() { }
86 virtual void printCOFFBaseReloc() { }
87 virtual void printCOFFDebugDirectory() { }
88 virtual void printCOFFTLSDirectory() {}
89 virtual void printCOFFResources() {}
90 virtual void printCOFFLoadConfig() { }
91 virtual void printCodeViewDebugInfo() { }
92 virtual void
93 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
94 llvm::codeview::MergingTypeTableBuilder &CVTypes,
95 llvm::codeview::GlobalTypeTableBuilder &GlobalCVIDs,
96 llvm::codeview::GlobalTypeTableBuilder &GlobalCVTypes,
97 bool GHash) {}
99 // Only implemented for MachO.
100 virtual void printMachODataInCode() { }
101 virtual void printMachOVersionMin() { }
102 virtual void printMachODysymtab() { }
103 virtual void printMachOSegment() { }
104 virtual void printMachOIndirectSymbols() { }
105 virtual void printMachOLinkerOptions() { }
107 virtual void printStackMap() const = 0;
109 void printSectionsAsString(const object::ObjectFile &Obj,
110 ArrayRef<std::string> Sections);
111 void printSectionsAsHex(const object::ObjectFile &Obj,
112 ArrayRef<std::string> Sections);
114 std::function<Error(const Twine &Msg)> WarningHandler;
115 void reportUniqueWarning(Error Err) const;
116 void reportUniqueWarning(const Twine &Msg) const;
118 protected:
119 ScopedPrinter &W;
121 private:
122 virtual void printSymbols() {}
123 virtual void printDynamicSymbols() {}
124 virtual void printProgramHeaders() {}
125 virtual void printSectionMapping() {}
127 std::unordered_set<std::string> Warnings;
130 std::unique_ptr<ObjDumper> createCOFFDumper(const object::COFFObjectFile &Obj,
131 ScopedPrinter &Writer);
133 std::unique_ptr<ObjDumper> createELFDumper(const object::ELFObjectFileBase &Obj,
134 ScopedPrinter &Writer);
136 std::unique_ptr<ObjDumper> createMachODumper(const object::MachOObjectFile &Obj,
137 ScopedPrinter &Writer);
139 std::unique_ptr<ObjDumper> createWasmDumper(const object::WasmObjectFile &Obj,
140 ScopedPrinter &Writer);
142 std::unique_ptr<ObjDumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj,
143 ScopedPrinter &Writer);
145 void dumpCOFFImportFile(const object::COFFImportFile *File,
146 ScopedPrinter &Writer);
148 void dumpCodeViewMergedTypes(ScopedPrinter &Writer,
149 ArrayRef<ArrayRef<uint8_t>> IpiRecords,
150 ArrayRef<ArrayRef<uint8_t>> TpiRecords);
152 } // namespace llvm
154 #endif