diff options
author | Colin LeMahieu <colinl@codeaurora.org> | 2016-03-18 16:26:48 +0000 |
---|---|---|
committer | Colin LeMahieu <colinl@codeaurora.org> | 2016-03-18 16:26:48 +0000 |
commit | 307a83d76a4ad4c7684837ec2c7357b69b614dd0 (patch) | |
tree | ea9260ce918a93876337eaaba33948a0cf791e9f /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 95e8ffd39803b729aae94faaf83c7f607a269d1a (diff) | |
download | bcm5719-llvm-307a83d76a4ad4c7684837ec2c7357b69b614dd0.tar.gz bcm5719-llvm-307a83d76a4ad4c7684837ec2c7357b69b614dd0.zip |
[llvm-objdump] Print <unknown> in place of instruction text if it couldn't be disassembled.
llvm-svn: 263793
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 133 |
1 files changed, 69 insertions, 64 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index eedfe30275f..f436183f065 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -314,12 +314,15 @@ public: ArrayRef<uint8_t> Bytes, uint64_t Address, raw_ostream &OS, StringRef Annot, MCSubtargetInfo const &STI) { - outs() << format("%8" PRIx64 ":", Address); + OS << format("%8" PRIx64 ":", Address); if (!NoShowRawInsn) { - outs() << "\t"; - dumpBytes(Bytes, outs()); + OS << "\t"; + dumpBytes(Bytes, OS); } - IP.printInst(MI, outs(), "", STI); + if (MI) + IP.printInst(MI, OS, "", STI); + else + OS << " <unknown>"; } }; PrettyPrinter PrettyPrinterInst; @@ -340,6 +343,11 @@ public: ArrayRef<uint8_t> Bytes, uint64_t Address, raw_ostream &OS, StringRef Annot, MCSubtargetInfo const &STI) override { + if (!MI) { + printLead(Bytes, Address, OS); + OS << " <unknown>"; + return; + } std::string Buffer; { raw_string_ostream TempStream(Buffer); @@ -1088,72 +1096,69 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (Index >= End) break; - if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), - SectionAddr + Index, DebugOut, - CommentStream)) { - PIP.printInst(*IP, &Inst, - Bytes.slice(Index, Size), - SectionAddr + Index, outs(), "", *STI); - outs() << CommentStream.str(); - Comments.clear(); - - // Try to resolve the target of a call, tail call, etc. to a specific - // symbol. - if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || - MIA->isConditionalBranch(Inst))) { - uint64_t Target; - if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { - // In a relocatable object, the target's section must reside in - // the same section as the call instruction or it is accessed - // through a relocation. - // - // In a non-relocatable object, the target may be in any section. - // - // N.B. We don't walk the relocations in the relocatable case yet. - auto *TargetSectionSymbols = &Symbols; - if (!Obj->isRelocatableObject()) { - auto SectionAddress = std::upper_bound( - SectionAddresses.begin(), SectionAddresses.end(), Target, - [](uint64_t LHS, - const std::pair<uint64_t, SectionRef> &RHS) { - return LHS < RHS.first; - }); - if (SectionAddress != SectionAddresses.begin()) { - --SectionAddress; - TargetSectionSymbols = &AllSymbols[SectionAddress->second]; - } else { - TargetSectionSymbols = nullptr; - } + bool Disassembled = DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), + SectionAddr + Index, DebugOut, + CommentStream); + if (Size == 0) + Size = 1; + PIP.printInst(*IP, Disassembled ? &Inst : nullptr, + Bytes.slice(Index, Size), + SectionAddr + Index, outs(), "", *STI); + outs() << CommentStream.str(); + Comments.clear(); + + // Try to resolve the target of a call, tail call, etc. to a specific + // symbol. + if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || + MIA->isConditionalBranch(Inst))) { + uint64_t Target; + if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { + // In a relocatable object, the target's section must reside in + // the same section as the call instruction or it is accessed + // through a relocation. + // + // In a non-relocatable object, the target may be in any section. + // + // N.B. We don't walk the relocations in the relocatable case yet. + auto *TargetSectionSymbols = &Symbols; + if (!Obj->isRelocatableObject()) { + auto SectionAddress = std::upper_bound( + SectionAddresses.begin(), SectionAddresses.end(), Target, + [](uint64_t LHS, + const std::pair<uint64_t, SectionRef> &RHS) { + return LHS < RHS.first; + }); + if (SectionAddress != SectionAddresses.begin()) { + --SectionAddress; + TargetSectionSymbols = &AllSymbols[SectionAddress->second]; + } else { + TargetSectionSymbols = nullptr; } + } - // Find the first symbol in the section whose offset is less than - // or equal to the target. - if (TargetSectionSymbols) { - auto TargetSym = std::upper_bound( - TargetSectionSymbols->begin(), TargetSectionSymbols->end(), - Target, [](uint64_t LHS, - const std::pair<uint64_t, StringRef> &RHS) { - return LHS < RHS.first; - }); - if (TargetSym != TargetSectionSymbols->begin()) { - --TargetSym; - uint64_t TargetAddress = std::get<0>(*TargetSym); - StringRef TargetName = std::get<1>(*TargetSym); - outs() << " <" << TargetName; - uint64_t Disp = Target - TargetAddress; - if (Disp) - outs() << "+0x" << utohexstr(Disp); - outs() << '>'; - } + // Find the first symbol in the section whose offset is less than + // or equal to the target. + if (TargetSectionSymbols) { + auto TargetSym = std::upper_bound( + TargetSectionSymbols->begin(), TargetSectionSymbols->end(), + Target, [](uint64_t LHS, + const std::pair<uint64_t, StringRef> &RHS) { + return LHS < RHS.first; + }); + if (TargetSym != TargetSectionSymbols->begin()) { + --TargetSym; + uint64_t TargetAddress = std::get<0>(*TargetSym); + StringRef TargetName = std::get<1>(*TargetSym); + outs() << " <" << TargetName; + uint64_t Disp = Target - TargetAddress; + if (Disp) + outs() << "+0x" << utohexstr(Disp); + outs() << '>'; } } } - outs() << "\n"; - } else { - errs() << ToolName << ": warning: invalid instruction encoding\n"; - if (Size == 0) - Size = 1; // skip illegible bytes } + outs() << "\n"; // Print relocation for instruction. while (rel_cur != rel_end) { |