summaryrefslogtreecommitdiff
path: root/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
commit044eb2f6afba375a914ac9d8024f8f5142bb912e (patch)
tree1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /tools/llvm-objdump/llvm-objdump.cpp
parenteb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff)
Notes
Diffstat (limited to 'tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp61
1 files changed, 26 insertions, 35 deletions
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 74593e6202aa..79204c6e9533 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -62,8 +62,8 @@
#include <cctype>
#include <cstring>
#include <system_error>
-#include <utility>
#include <unordered_map>
+#include <utility>
using namespace llvm;
using namespace object;
@@ -191,7 +191,7 @@ cl::opt<bool> PrintFaultMaps("fault-map-section",
cl::opt<DIDumpType> llvm::DwarfDumpType(
"dwarf", cl::init(DIDT_Null), cl::desc("Dump of dwarf debug sections:"),
- cl::values(clEnumValN(DIDT_Frames, "frames", ".debug_frame")));
+ cl::values(clEnumValN(DIDT_DebugFrame, "frames", ".debug_frame")));
cl::opt<bool> PrintSource(
"source",
@@ -362,29 +362,11 @@ static const Target *getTarget(const ObjectFile *Obj = nullptr) {
llvm::Triple TheTriple("unknown-unknown-unknown");
if (TripleName.empty()) {
if (Obj) {
- auto Arch = Obj->getArch();
- TheTriple.setArch(Triple::ArchType(Arch));
-
- // For ARM targets, try to use the build attributes to build determine
- // the build target. Target features are also added, but later during
- // disassembly.
- if (Arch == Triple::arm || Arch == Triple::armeb) {
- Obj->setARMSubArch(TheTriple);
- }
-
- // TheTriple defaults to ELF, and COFF doesn't have an environment:
- // the best we can do here is indicate that it is mach-o.
- if (Obj->isMachO())
- TheTriple.setObjectFormat(Triple::MachO);
-
- if (Obj->isCOFF()) {
- const auto COFFObj = dyn_cast<COFFObjectFile>(Obj);
- if (COFFObj->getArch() == Triple::thumb)
- TheTriple.setTriple("thumbv7-windows");
- }
+ TheTriple = Obj->makeTriple();
}
} else {
TheTriple.setTriple(Triple::normalize(TripleName));
+
// Use the triple, but also try to combine with ARM build attributes.
if (Obj) {
auto Arch = Obj->getArch();
@@ -418,7 +400,7 @@ namespace {
class SourcePrinter {
protected:
DILineInfo OldLineInfo;
- const ObjectFile *Obj;
+ const ObjectFile *Obj = nullptr;
std::unique_ptr<symbolize::LLVMSymbolizer> Symbolizer;
// File name to file contents of source
std::unordered_map<std::string, std::unique_ptr<MemoryBuffer>> SourceCache;
@@ -426,22 +408,22 @@ protected:
std::unordered_map<std::string, std::vector<StringRef>> LineCache;
private:
- bool cacheSource(std::string File);
+ bool cacheSource(const std::string& File);
public:
- virtual ~SourcePrinter() {}
- SourcePrinter() : Obj(nullptr), Symbolizer(nullptr) {}
+ SourcePrinter() = default;
SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch) : Obj(Obj) {
symbolize::LLVMSymbolizer::Options SymbolizerOpts(
DILineInfoSpecifier::FunctionNameKind::None, true, false, false,
DefaultArch);
Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts));
}
+ virtual ~SourcePrinter() = default;
virtual void printSourceLine(raw_ostream &OS, uint64_t Address,
StringRef Delimiter = "; ");
};
-bool SourcePrinter::cacheSource(std::string File) {
+bool SourcePrinter::cacheSource(const std::string& File) {
auto BufferOrError = MemoryBuffer::getFile(File);
if (!BufferOrError)
return false;
@@ -509,7 +491,7 @@ static bool isArmElf(const ObjectFile *Obj) {
class PrettyPrinter {
public:
- virtual ~PrettyPrinter(){}
+ virtual ~PrettyPrinter() = default;
virtual void printInst(MCInstPrinter &IP, const MCInst *MI,
ArrayRef<uint8_t> Bytes, uint64_t Address,
raw_ostream &OS, StringRef Annot,
@@ -883,8 +865,19 @@ static void printRelocationTargetName(const MachOObjectFile *O,
} else {
section_iterator SI = O->section_begin();
// Adjust for the fact that sections are 1-indexed.
- advance(SI, Val - 1);
- SI->getName(S);
+ if (Val == 0) {
+ fmt << "0 (?,?)";
+ return;
+ }
+ uint32_t i = Val - 1;
+ while (i != 0 && SI != O->section_end()) {
+ i--;
+ advance(SI, 1);
+ }
+ if (SI == O->section_end())
+ fmt << Val << " (?,?)";
+ else
+ SI->getName(S);
}
fmt << S;
@@ -1223,7 +1216,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
MCObjectFileInfo MOFI;
MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
// FIXME: for now initialize MCObjectFileInfo with default values
- MOFI.InitMCObjectFileInfo(Triple(TripleName), false, CodeModel::Default, Ctx);
+ MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
@@ -2081,11 +2074,10 @@ static void DumpObject(ObjectFile *o, const Archive *a = nullptr) {
if (PrintFaultMaps)
printFaultMaps(o);
if (DwarfDumpType != DIDT_Null) {
- std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(*o));
+ std::unique_ptr<DIContext> DICtx = DWARFContext::create(*o);
// Dump the complete DWARF structure.
DIDumpOptions DumpOpts;
DumpOpts.DumpType = DwarfDumpType;
- DumpOpts.DumpEH = true;
DICtx->dump(outs(), DumpOpts);
}
}
@@ -2205,8 +2197,7 @@ int main(int argc, char **argv) {
return 2;
}
- std::for_each(InputFilenames.begin(), InputFilenames.end(),
- DumpInput);
+ llvm::for_each(InputFilenames, DumpInput);
return EXIT_SUCCESS;
}