2021-02-05 08:36:31 +00:00
|
|
|
//===--- llvm-objdump.h -----------------------------------------*- C++ -*-===//
|
2011-09-19 17:56:04 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-09-19 17:56:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
|
|
|
#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
2011-09-19 17:56:04 +00:00
|
|
|
|
2020-04-09 15:32:09 -04:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2016-01-26 15:09:42 +00:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2020-04-21 21:52:08 +00:00
|
|
|
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
2023-07-06 11:47:08 -04:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2020-04-09 15:32:09 -04:00
|
|
|
#include "llvm/Object/Archive.h"
|
2023-07-10 12:14:53 -07:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2015-12-29 13:41:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2011-09-19 17:56:04 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2023-07-06 11:47:08 -04:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2023-08-14 08:04:33 -07:00
|
|
|
#include <functional>
|
2023-07-14 12:44:41 -07:00
|
|
|
#include <memory>
|
2011-09-19 17:56:04 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2016-04-18 09:17:29 +00:00
|
|
|
class StringRef;
|
2021-01-07 12:34:11 +00:00
|
|
|
class Twine;
|
2016-04-18 09:17:29 +00:00
|
|
|
|
2022-02-04 18:07:12 -08:00
|
|
|
namespace opt {
|
|
|
|
class Arg;
|
|
|
|
} // namespace opt
|
|
|
|
|
2012-12-05 20:12:35 +00:00
|
|
|
namespace object {
|
2019-01-18 11:33:26 +00:00
|
|
|
class RelocationRef;
|
2021-08-17 09:10:50 -07:00
|
|
|
struct VersionEntry;
|
2023-07-14 12:44:41 -07:00
|
|
|
|
|
|
|
class COFFObjectFile;
|
|
|
|
class ELFObjectFileBase;
|
|
|
|
class MachOObjectFile;
|
|
|
|
class WasmObjectFile;
|
|
|
|
class XCOFFObjectFile;
|
2020-04-06 16:56:13 -04:00
|
|
|
} // namespace object
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2020-04-06 16:56:13 -04:00
|
|
|
namespace objdump {
|
|
|
|
|
2021-11-04 11:01:32 +00:00
|
|
|
enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid };
|
2021-02-15 11:58:35 +00:00
|
|
|
|
2021-04-12 22:31:08 -04:00
|
|
|
extern bool ArchiveHeaders;
|
2021-02-15 11:58:35 +00:00
|
|
|
extern int DbgIndent;
|
|
|
|
extern DebugVarsFormat DbgVariables;
|
2021-04-12 22:31:08 -04:00
|
|
|
extern bool Demangle;
|
|
|
|
extern bool Disassemble;
|
|
|
|
extern bool DisassembleAll;
|
|
|
|
extern DIDumpType DwarfDumpType;
|
|
|
|
extern std::vector<std::string> FilterSections;
|
2021-04-20 09:01:04 -04:00
|
|
|
extern bool LeadingAddr;
|
2021-04-12 22:31:08 -04:00
|
|
|
extern std::vector<std::string> MAttrs;
|
|
|
|
extern std::string MCPU;
|
|
|
|
extern std::string Prefix;
|
|
|
|
extern uint32_t PrefixStrip;
|
|
|
|
extern bool PrintImmHex;
|
2021-02-15 11:58:35 +00:00
|
|
|
extern bool PrintLines;
|
|
|
|
extern bool PrintSource;
|
2021-04-12 22:31:08 -04:00
|
|
|
extern bool PrivateHeaders;
|
|
|
|
extern bool Relocations;
|
|
|
|
extern bool SectionHeaders;
|
|
|
|
extern bool SectionContents;
|
2021-04-20 09:01:04 -04:00
|
|
|
extern bool ShowRawInsn;
|
2021-04-12 22:31:08 -04:00
|
|
|
extern bool SymbolDescription;
|
2023-07-06 11:47:08 -04:00
|
|
|
extern bool TracebackTable;
|
2021-04-12 22:31:08 -04:00
|
|
|
extern bool SymbolTable;
|
|
|
|
extern std::string TripleName;
|
|
|
|
extern bool UnwindInfo;
|
2020-04-06 16:56:13 -04:00
|
|
|
|
2020-04-09 15:32:09 -04:00
|
|
|
extern StringSet<> FoundSectionSet;
|
|
|
|
|
2023-07-11 08:38:02 -07:00
|
|
|
class Dumper {
|
|
|
|
const object::ObjectFile &O;
|
|
|
|
StringSet<> Warnings;
|
|
|
|
|
2023-08-14 08:04:33 -07:00
|
|
|
protected:
|
|
|
|
std::function<Error(const Twine &Msg)> WarningHandler;
|
|
|
|
|
2023-07-11 08:38:02 -07:00
|
|
|
public:
|
2023-08-14 08:04:33 -07:00
|
|
|
Dumper(const object::ObjectFile &O);
|
2023-07-14 12:44:41 -07:00
|
|
|
virtual ~Dumper() {}
|
2023-07-11 08:38:02 -07:00
|
|
|
|
|
|
|
void reportUniqueWarning(Error Err);
|
|
|
|
void reportUniqueWarning(const Twine &Msg);
|
|
|
|
|
2023-07-26 00:25:55 -07:00
|
|
|
virtual void printPrivateHeaders();
|
2023-07-14 13:01:11 -07:00
|
|
|
virtual void printDynamicRelocations() {}
|
2023-07-11 08:38:02 -07:00
|
|
|
void printSymbolTable(StringRef ArchiveName,
|
|
|
|
StringRef ArchitectureName = StringRef(),
|
|
|
|
bool DumpDynamic = false);
|
|
|
|
void printSymbol(const object::SymbolRef &Symbol,
|
|
|
|
ArrayRef<object::VersionEntry> SymbolVersions,
|
|
|
|
StringRef FileName, StringRef ArchiveName,
|
|
|
|
StringRef ArchitectureName, bool DumpDynamic);
|
|
|
|
void printRelocations();
|
|
|
|
};
|
|
|
|
|
2023-07-14 12:44:41 -07:00
|
|
|
std::unique_ptr<Dumper> createCOFFDumper(const object::COFFObjectFile &Obj);
|
|
|
|
std::unique_ptr<Dumper> createELFDumper(const object::ELFObjectFileBase &Obj);
|
|
|
|
std::unique_ptr<Dumper> createMachODumper(const object::MachOObjectFile &Obj);
|
|
|
|
std::unique_ptr<Dumper> createWasmDumper(const object::WasmObjectFile &Obj);
|
|
|
|
std::unique_ptr<Dumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj);
|
|
|
|
|
2011-09-19 17:56:04 +00:00
|
|
|
// Various helper functions.
|
Reland [llvm-objdump] Use a counter for llvm-objdump -h instead of the section index.
This relands r374931 (reverted in r375088). It fixes 32-bit builds by using the right format string specifier for uint64_t (PRIu64) instead of `%d`.
Original description:
When listing the index in `llvm-objdump -h`, use a zero-based counter instead of the actual section index (e.g. shdr->sh_index for ELF).
While this is effectively a noop for now (except one unit test for XCOFF), the index values will change in a future patch that filters certain sections out (e.g. symbol tables). See D68669 for more context. Note: the test case in `test/tools/llvm-objdump/X86/section-index.s` already covers the case of incrementing the section index counter when sections are skipped.
Reviewers: grimar, jhenderson, espindola
Reviewed By: grimar
Subscribers: emaste, sbc100, arichardson, aheejin, arphaman, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68848
llvm-svn: 375178
2019-10-17 21:55:43 +00:00
|
|
|
|
|
|
|
/// Creates a SectionFilter with a standard predicate that conditionally skips
|
|
|
|
/// sections when the --section objdump flag is provided.
|
|
|
|
///
|
|
|
|
/// Idx is an optional output parameter that keeps track of which section index
|
|
|
|
/// this is. This may be different than the actual section number, as some
|
|
|
|
/// sections may be filtered (e.g. symbol tables).
|
2023-07-10 12:14:53 -07:00
|
|
|
object::SectionFilter ToolSectionFilter(const llvm::object::ObjectFile &O,
|
|
|
|
uint64_t *Idx = nullptr);
|
2019-01-18 11:33:26 +00:00
|
|
|
|
2019-01-15 09:19:18 +00:00
|
|
|
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
|
2022-07-14 07:58:38 +01:00
|
|
|
void printSectionHeaders(object::ObjectFile &O);
|
2019-01-15 09:19:18 +00:00
|
|
|
void printSectionContents(const object::ObjectFile *O);
|
2021-07-28 09:31:14 -07:00
|
|
|
[[noreturn]] void reportError(StringRef File, const Twine &Message);
|
|
|
|
[[noreturn]] void reportError(Error E, StringRef FileName,
|
|
|
|
StringRef ArchiveName = "",
|
|
|
|
StringRef ArchitectureName = "");
|
2021-01-07 12:34:11 +00:00
|
|
|
void reportWarning(const Twine &Message, StringRef File);
|
2019-04-07 08:19:55 +00:00
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
T unwrapOrError(Expected<T> EO, Ts &&... Args) {
|
|
|
|
if (EO)
|
|
|
|
return std::move(*EO);
|
2019-08-21 11:07:31 +00:00
|
|
|
reportError(EO.takeError(), std::forward<Ts>(Args)...);
|
2019-04-07 08:19:55 +00:00
|
|
|
}
|
2011-09-19 17:56:04 +00:00
|
|
|
|
2022-02-04 18:07:12 -08:00
|
|
|
void invalidArgValue(const opt::Arg *A);
|
|
|
|
|
2019-08-20 13:19:16 +00:00
|
|
|
std::string getFileNameForError(const object::Archive::Child &C,
|
|
|
|
unsigned Index);
|
2022-07-07 12:14:59 -07:00
|
|
|
SymbolInfoTy createSymbolInfo(const object::ObjectFile &Obj,
|
2023-07-27 20:51:42 -07:00
|
|
|
const object::SymbolRef &Symbol,
|
|
|
|
bool IsMappingSymbol = false);
|
2023-07-06 11:47:08 -04:00
|
|
|
unsigned getInstStartColumn(const MCSubtargetInfo &STI);
|
|
|
|
void printRawData(llvm::ArrayRef<uint8_t> Bytes, uint64_t Address,
|
|
|
|
llvm::formatted_raw_ostream &OS,
|
|
|
|
llvm::MCSubtargetInfo const &STI);
|
2019-08-20 13:19:16 +00:00
|
|
|
|
2020-05-30 18:00:14 -07:00
|
|
|
} // namespace objdump
|
2013-09-27 21:04:00 +00:00
|
|
|
} // end namespace llvm
|
2011-09-19 17:56:04 +00:00
|
|
|
|
|
|
|
#endif
|