1//===--- llvm-objdump.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_LLVM_OBJDUMP_LLVM_OBJDUMP_H
10#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
11
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"
21#include <functional>
22#include <memory>
23
24namespace llvm {
25class StringRef;
26class Twine;
27
28namespace opt {
29class Arg;
30} // namespace opt
31
32namespace object {
33class RelocationRef;
34struct VersionEntry;
35
36class COFFObjectFile;
37class ELFObjectFileBase;
38class MachOObjectFile;
39class WasmObjectFile;
40class XCOFFObjectFile;
41} // namespace object
42
43namespace objdump {
44
45enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid };
46
47extern bool ArchiveHeaders;
48extern int DbgIndent;
49extern DebugVarsFormat DbgVariables;
50extern bool Demangle;
51extern bool Disassemble;
52extern bool DisassembleAll;
53extern DIDumpType DwarfDumpType;
54extern std::vector<std::string> FilterSections;
55extern bool LeadingAddr;
56extern std::vector<std::string> MAttrs;
57extern std::string MCPU;
58extern std::string Prefix;
59extern uint32_t PrefixStrip;
60extern bool PrintImmHex;
61extern bool PrintLines;
62extern bool PrintSource;
63extern bool PrivateHeaders;
64extern bool Relocations;
65extern bool SectionHeaders;
66extern bool SectionContents;
67extern bool ShowRawInsn;
68extern bool SymbolDescription;
69extern bool TracebackTable;
70extern bool SymbolTable;
71extern std::string TripleName;
72extern bool UnwindInfo;
73
74extern StringSet<> FoundSectionSet;
75
76class Dumper {
77 const object::ObjectFile &O;
78 StringSet<> Warnings;
79
80protected:
81 std::function<Error(const Twine &Msg)> WarningHandler;
82
83public:
84 Dumper(const object::ObjectFile &O);
85 virtual ~Dumper() {}
86
87 void reportUniqueWarning(Error Err);
88 void reportUniqueWarning(const Twine &Msg);
89
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();
100};
101
102std::unique_ptr<Dumper> createCOFFDumper(const object::COFFObjectFile &Obj);
103std::unique_ptr<Dumper> createELFDumper(const object::ELFObjectFileBase &Obj);
104std::unique_ptr<Dumper> createMachODumper(const object::MachOObjectFile &Obj);
105std::unique_ptr<Dumper> createWasmDumper(const object::WasmObjectFile &Obj);
106std::unique_ptr<Dumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj);
107
108// Various helper functions.
109
110/// Creates a SectionFilter with a standard predicate that conditionally skips
111/// sections when the --section objdump flag is provided.
112///
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).
116object::SectionFilter ToolSectionFilter(const llvm::object::ObjectFile &O,
117 uint64_t *Idx = nullptr);
118
119bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
120void printSectionHeaders(object::ObjectFile &O);
121void 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 = "");
126void reportWarning(const Twine &Message, StringRef File);
127
128template <typename T, typename... Ts>
129T unwrapOrError(Expected<T> EO, Ts &&... Args) {
130 if (EO)
131 return std::move(*EO);
132 reportError(EO.takeError(), std::forward<Ts>(Args)...);
133}
134
135void invalidArgValue(const opt::Arg *A);
136
137std::string getFileNameForError(const object::Archive::Child &C,
138 unsigned Index);
139SymbolInfoTy createSymbolInfo(const object::ObjectFile &Obj,
140 const object::SymbolRef &Symbol,
141 bool IsMappingSymbol = false);
142unsigned getInstStartColumn(const MCSubtargetInfo &STI);
143void printRawData(llvm::ArrayRef<uint8_t> Bytes, uint64_t Address,
144 llvm::formatted_raw_ostream &OS,
145 llvm::MCSubtargetInfo const &STI);
146
147} // namespace objdump
148} // end namespace llvm
149
150#endif
151

source code of llvm/tools/llvm-objdump/llvm-objdump.h