2021-02-05 16:36:31 +08:00
|
|
|
//===--- llvm-objdump.h -----------------------------------------*- C++ -*-===//
|
2011-09-20 01:56:04 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-20 01:56:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
|
|
|
#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
|
2011-09-20 01:56:04 +08:00
|
|
|
|
2020-04-10 03:32:09 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2016-01-26 23:09:42 +08:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2020-04-22 05:52:08 +08:00
|
|
|
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
2020-04-10 03:32:09 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
2015-12-29 21:41:02 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2011-09-20 01:56:04 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2016-04-18 17:17:29 +08:00
|
|
|
class StringRef;
|
2021-01-07 20:34:11 +08:00
|
|
|
class Twine;
|
2016-04-18 17:17:29 +08:00
|
|
|
|
2012-12-06 04:12:35 +08:00
|
|
|
namespace object {
|
2019-01-18 19:33:26 +08:00
|
|
|
class RelocationRef;
|
2021-08-18 00:10:50 +08:00
|
|
|
struct VersionEntry;
|
2020-04-07 04:56:13 +08:00
|
|
|
} // namespace object
|
2012-12-06 04:12:35 +08:00
|
|
|
|
2020-04-07 04:56:13 +08:00
|
|
|
namespace objdump {
|
|
|
|
|
2021-11-04 19:01:32 +08:00
|
|
|
enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid };
|
2021-02-15 19:58:35 +08:00
|
|
|
|
2021-04-13 10:31:08 +08:00
|
|
|
extern bool ArchiveHeaders;
|
2021-02-15 19:58:35 +08:00
|
|
|
extern int DbgIndent;
|
|
|
|
extern DebugVarsFormat DbgVariables;
|
2021-04-13 10:31:08 +08:00
|
|
|
extern bool Demangle;
|
|
|
|
extern bool Disassemble;
|
|
|
|
extern bool DisassembleAll;
|
|
|
|
extern DIDumpType DwarfDumpType;
|
|
|
|
extern std::vector<std::string> FilterSections;
|
2021-04-20 21:01:04 +08:00
|
|
|
extern bool LeadingAddr;
|
2021-04-13 10:31:08 +08: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 19:58:35 +08:00
|
|
|
extern bool PrintLines;
|
|
|
|
extern bool PrintSource;
|
2021-04-13 10:31:08 +08:00
|
|
|
extern bool PrivateHeaders;
|
|
|
|
extern bool Relocations;
|
|
|
|
extern bool SectionHeaders;
|
|
|
|
extern bool SectionContents;
|
2021-04-20 21:01:04 +08:00
|
|
|
extern bool ShowRawInsn;
|
2021-04-13 10:31:08 +08:00
|
|
|
extern bool SymbolDescription;
|
|
|
|
extern bool SymbolTable;
|
|
|
|
extern std::string TripleName;
|
|
|
|
extern bool UnwindInfo;
|
2020-04-07 04:56:13 +08:00
|
|
|
|
2020-04-10 03:32:09 +08:00
|
|
|
extern StringSet<> FoundSectionSet;
|
|
|
|
|
2019-01-18 19:33:26 +08:00
|
|
|
typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
|
|
|
|
|
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-18 05:55:43 +08:00
|
|
|
/// A filtered iterator for SectionRefs that skips sections based on some given
|
|
|
|
/// predicate.
|
2019-01-18 19:33:26 +08:00
|
|
|
class SectionFilterIterator {
|
|
|
|
public:
|
|
|
|
SectionFilterIterator(FilterPredicate P,
|
|
|
|
llvm::object::section_iterator const &I,
|
|
|
|
llvm::object::section_iterator const &E)
|
|
|
|
: Predicate(std::move(P)), Iterator(I), End(E) {
|
|
|
|
ScanPredicate();
|
|
|
|
}
|
|
|
|
const llvm::object::SectionRef &operator*() const { return *Iterator; }
|
|
|
|
SectionFilterIterator &operator++() {
|
|
|
|
++Iterator;
|
|
|
|
ScanPredicate();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bool operator!=(SectionFilterIterator const &Other) const {
|
|
|
|
return Iterator != Other.Iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ScanPredicate() {
|
|
|
|
while (Iterator != End && !Predicate(*Iterator)) {
|
|
|
|
++Iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FilterPredicate Predicate;
|
|
|
|
llvm::object::section_iterator Iterator;
|
|
|
|
llvm::object::section_iterator End;
|
|
|
|
};
|
|
|
|
|
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-18 05:55:43 +08:00
|
|
|
/// Creates an iterator range of SectionFilterIterators for a given Object and
|
|
|
|
/// predicate.
|
2019-01-18 19:33:26 +08:00
|
|
|
class SectionFilter {
|
|
|
|
public:
|
|
|
|
SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O)
|
|
|
|
: Predicate(std::move(P)), Object(O) {}
|
|
|
|
SectionFilterIterator begin() {
|
|
|
|
return SectionFilterIterator(Predicate, Object.section_begin(),
|
|
|
|
Object.section_end());
|
|
|
|
}
|
|
|
|
SectionFilterIterator end() {
|
|
|
|
return SectionFilterIterator(Predicate, Object.section_end(),
|
|
|
|
Object.section_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FilterPredicate Predicate;
|
|
|
|
llvm::object::ObjectFile const &Object;
|
|
|
|
};
|
|
|
|
|
2011-09-20 01:56:04 +08: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-18 05:55:43 +08: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).
|
|
|
|
SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O,
|
|
|
|
uint64_t *Idx = nullptr);
|
2019-01-18 19:33:26 +08:00
|
|
|
|
2019-01-15 17:19:18 +08:00
|
|
|
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
|
|
|
|
void printRelocations(const object::ObjectFile *O);
|
|
|
|
void printDynamicRelocations(const object::ObjectFile *O);
|
|
|
|
void printSectionHeaders(const object::ObjectFile *O);
|
|
|
|
void printSectionContents(const object::ObjectFile *O);
|
|
|
|
void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
|
2020-04-05 09:58:53 +08:00
|
|
|
StringRef ArchitectureName = StringRef(),
|
|
|
|
bool DumpDynamic = false);
|
|
|
|
void printSymbol(const object::ObjectFile *O, const object::SymbolRef &Symbol,
|
2021-08-18 00:10:50 +08:00
|
|
|
ArrayRef<object::VersionEntry> SymbolVersions,
|
2020-04-05 09:58:53 +08:00
|
|
|
StringRef FileName, StringRef ArchiveName,
|
|
|
|
StringRef ArchitectureName, bool DumpDynamic);
|
2021-07-29 00:31:14 +08:00
|
|
|
[[noreturn]] void reportError(StringRef File, const Twine &Message);
|
|
|
|
[[noreturn]] void reportError(Error E, StringRef FileName,
|
|
|
|
StringRef ArchiveName = "",
|
|
|
|
StringRef ArchitectureName = "");
|
2021-01-07 20:34:11 +08:00
|
|
|
void reportWarning(const Twine &Message, StringRef File);
|
2019-04-07 16:19:55 +08:00
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
T unwrapOrError(Expected<T> EO, Ts &&... Args) {
|
|
|
|
if (EO)
|
|
|
|
return std::move(*EO);
|
2019-08-21 19:07:31 +08:00
|
|
|
reportError(EO.takeError(), std::forward<Ts>(Args)...);
|
2019-04-07 16:19:55 +08:00
|
|
|
}
|
2011-09-20 01:56:04 +08:00
|
|
|
|
2019-08-20 21:19:16 +08:00
|
|
|
std::string getFileNameForError(const object::Archive::Child &C,
|
|
|
|
unsigned Index);
|
2020-04-22 05:52:08 +08:00
|
|
|
SymbolInfoTy createSymbolInfo(const object::ObjectFile *Obj,
|
|
|
|
const object::SymbolRef &Symbol);
|
2019-08-20 21:19:16 +08:00
|
|
|
|
2020-05-31 09:00:14 +08:00
|
|
|
} // namespace objdump
|
2013-09-28 05:04:00 +08:00
|
|
|
} // end namespace llvm
|
2011-09-20 01:56:04 +08:00
|
|
|
|
|
|
|
#endif
|