1 //===--- llvm-objdump.h -----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
10 #define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
12 #include "llvm/ADT/StringSet.h"
13 #include "llvm/DebugInfo/DIContext.h"
14 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
15 #include "llvm/MC/MCSubtargetInfo.h"
16 #include "llvm/Object/Archive.h"
17 #include "llvm/Object/ObjectFile.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/FormattedStream.h"
37 class ELFObjectFileBase
;
38 class MachOObjectFile
;
40 class XCOFFObjectFile
;
45 enum DebugVarsFormat
{ DVDisabled
, DVUnicode
, DVASCII
, DVInvalid
};
47 extern bool ArchiveHeaders
;
49 extern DebugVarsFormat DbgVariables
;
51 extern bool Disassemble
;
52 extern bool DisassembleAll
;
53 extern DIDumpType DwarfDumpType
;
54 extern std::vector
<std::string
> FilterSections
;
55 extern bool LeadingAddr
;
56 extern std::vector
<std::string
> MAttrs
;
57 extern std::string MCPU
;
58 extern std::string Prefix
;
59 extern uint32_t PrefixStrip
;
60 extern bool PrintImmHex
;
61 extern bool PrintLines
;
62 extern bool PrintSource
;
63 extern bool PrivateHeaders
;
64 extern bool Relocations
;
65 extern bool SectionHeaders
;
66 extern bool SectionContents
;
67 extern bool ShowRawInsn
;
68 extern bool SymbolDescription
;
69 extern bool TracebackTable
;
70 extern bool SymbolTable
;
71 extern std::string TripleName
;
72 extern bool UnwindInfo
;
74 extern StringSet
<> FoundSectionSet
;
77 const object::ObjectFile
&O
;
81 std::function
<Error(const Twine
&Msg
)> WarningHandler
;
84 Dumper(const object::ObjectFile
&O
);
87 void reportUniqueWarning(Error Err
);
88 void reportUniqueWarning(const Twine
&Msg
);
90 virtual void printPrivateHeaders();
91 virtual void printDynamicRelocations() {}
92 void printSymbolTable(StringRef ArchiveName
,
93 StringRef ArchitectureName
= StringRef(),
94 bool DumpDynamic
= false);
95 void printSymbol(const object::SymbolRef
&Symbol
,
96 ArrayRef
<object::VersionEntry
> SymbolVersions
,
97 StringRef FileName
, StringRef ArchiveName
,
98 StringRef ArchitectureName
, bool DumpDynamic
);
99 void printRelocations();
102 std::unique_ptr
<Dumper
> createCOFFDumper(const object::COFFObjectFile
&Obj
);
103 std::unique_ptr
<Dumper
> createELFDumper(const object::ELFObjectFileBase
&Obj
);
104 std::unique_ptr
<Dumper
> createMachODumper(const object::MachOObjectFile
&Obj
);
105 std::unique_ptr
<Dumper
> createWasmDumper(const object::WasmObjectFile
&Obj
);
106 std::unique_ptr
<Dumper
> createXCOFFDumper(const object::XCOFFObjectFile
&Obj
);
108 // Various helper functions.
110 /// Creates a SectionFilter with a standard predicate that conditionally skips
111 /// sections when the --section objdump flag is provided.
113 /// Idx is an optional output parameter that keeps track of which section index
114 /// this is. This may be different than the actual section number, as some
115 /// sections may be filtered (e.g. symbol tables).
116 object::SectionFilter
ToolSectionFilter(const llvm::object::ObjectFile
&O
,
117 uint64_t *Idx
= nullptr);
119 bool isRelocAddressLess(object::RelocationRef A
, object::RelocationRef B
);
120 void printSectionHeaders(object::ObjectFile
&O
);
121 void printSectionContents(const object::ObjectFile
*O
);
122 [[noreturn
]] void reportError(StringRef File
, const Twine
&Message
);
123 [[noreturn
]] void reportError(Error E
, StringRef FileName
,
124 StringRef ArchiveName
= "",
125 StringRef ArchitectureName
= "");
126 void reportWarning(const Twine
&Message
, StringRef File
);
128 template <typename T
, typename
... Ts
>
129 T
unwrapOrError(Expected
<T
> EO
, Ts
&&... Args
) {
131 return std::move(*EO
);
132 reportError(EO
.takeError(), std::forward
<Ts
>(Args
)...);
135 void invalidArgValue(const opt::Arg
*A
);
137 std::string
getFileNameForError(const object::Archive::Child
&C
,
139 SymbolInfoTy
createSymbolInfo(const object::ObjectFile
&Obj
,
140 const object::SymbolRef
&Symbol
,
141 bool IsMappingSymbol
= false);
142 unsigned getInstStartColumn(const MCSubtargetInfo
&STI
);
143 void printRawData(llvm::ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
144 llvm::formatted_raw_ostream
&OS
,
145 llvm::MCSubtargetInfo
const &STI
);
147 } // namespace objdump
148 } // end namespace llvm