Path: blob/main/contrib/llvm-project/llvm/tools/llvm-objdump/llvm-objdump.h
35231 views
//===--- llvm-objdump.h -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H9#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H1011#include "llvm/ADT/StringSet.h"12#include "llvm/DebugInfo/DIContext.h"13#include "llvm/MC/MCDisassembler/MCDisassembler.h"14#include "llvm/MC/MCSubtargetInfo.h"15#include "llvm/Object/Archive.h"16#include "llvm/Object/ObjectFile.h"17#include "llvm/Support/Compiler.h"18#include "llvm/Support/DataTypes.h"19#include "llvm/Support/FormattedStream.h"20#include <functional>21#include <memory>2223namespace llvm {24class StringRef;25class Twine;2627namespace opt {28class Arg;29} // namespace opt3031namespace object {32class RelocationRef;33struct VersionEntry;3435class COFFObjectFile;36class ELFObjectFileBase;37class MachOObjectFile;38class WasmObjectFile;39class XCOFFObjectFile;40} // namespace object4142namespace objdump {4344enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid };4546extern bool ArchiveHeaders;47extern int DbgIndent;48extern DebugVarsFormat DbgVariables;49extern bool Demangle;50extern bool Disassemble;51extern bool DisassembleAll;52extern DIDumpType DwarfDumpType;53extern std::vector<std::string> FilterSections;54extern bool LeadingAddr;55extern std::vector<std::string> MAttrs;56extern std::string MCPU;57extern std::string Prefix;58extern uint32_t PrefixStrip;59extern bool PrintImmHex;60extern bool PrintLines;61extern bool PrintSource;62extern bool PrivateHeaders;63extern bool Relocations;64extern bool SectionHeaders;65extern bool SectionContents;66extern bool ShowRawInsn;67extern bool SymbolDescription;68extern bool TracebackTable;69extern bool SymbolTable;70extern std::string TripleName;71extern bool UnwindInfo;7273extern StringSet<> FoundSectionSet;7475class Dumper {76const object::ObjectFile &O;77StringSet<> Warnings;7879protected:80std::function<Error(const Twine &Msg)> WarningHandler;8182public:83Dumper(const object::ObjectFile &O);84virtual ~Dumper() {}8586void reportUniqueWarning(Error Err);87void reportUniqueWarning(const Twine &Msg);8889virtual void printPrivateHeaders();90virtual void printDynamicRelocations() {}91void printSymbolTable(StringRef ArchiveName,92StringRef ArchitectureName = StringRef(),93bool DumpDynamic = false);94void printSymbol(const object::SymbolRef &Symbol,95ArrayRef<object::VersionEntry> SymbolVersions,96StringRef FileName, StringRef ArchiveName,97StringRef ArchitectureName, bool DumpDynamic);98void printRelocations();99};100101std::unique_ptr<Dumper> createCOFFDumper(const object::COFFObjectFile &Obj);102std::unique_ptr<Dumper> createELFDumper(const object::ELFObjectFileBase &Obj);103std::unique_ptr<Dumper> createMachODumper(const object::MachOObjectFile &Obj);104std::unique_ptr<Dumper> createWasmDumper(const object::WasmObjectFile &Obj);105std::unique_ptr<Dumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj);106107// Various helper functions.108109/// Creates a SectionFilter with a standard predicate that conditionally skips110/// sections when the --section objdump flag is provided.111///112/// Idx is an optional output parameter that keeps track of which section index113/// this is. This may be different than the actual section number, as some114/// sections may be filtered (e.g. symbol tables).115object::SectionFilter ToolSectionFilter(const llvm::object::ObjectFile &O,116uint64_t *Idx = nullptr);117118bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);119void printSectionHeaders(object::ObjectFile &O);120void printSectionContents(const object::ObjectFile *O);121[[noreturn]] void reportError(StringRef File, const Twine &Message);122[[noreturn]] void reportError(Error E, StringRef FileName,123StringRef ArchiveName = "",124StringRef ArchitectureName = "");125void reportWarning(const Twine &Message, StringRef File);126127template <typename T, typename... Ts>128T unwrapOrError(Expected<T> EO, Ts &&... Args) {129if (EO)130return std::move(*EO);131reportError(EO.takeError(), std::forward<Ts>(Args)...);132}133134void invalidArgValue(const opt::Arg *A);135136std::string getFileNameForError(const object::Archive::Child &C,137unsigned Index);138SymbolInfoTy createSymbolInfo(const object::ObjectFile &Obj,139const object::SymbolRef &Symbol,140bool IsMappingSymbol = false);141unsigned getInstStartColumn(const MCSubtargetInfo &STI);142void printRawData(llvm::ArrayRef<uint8_t> Bytes, uint64_t Address,143llvm::formatted_raw_ostream &OS,144llvm::MCSubtargetInfo const &STI);145146} // namespace objdump147} // end namespace llvm148149#endif150151152