diff options
author | Rafael Auler <rafaelauler@fb.com> | 2018-03-09 19:13:44 +0000 |
---|---|---|
committer | Rafael Auler <rafaelauler@fb.com> | 2018-03-09 19:13:44 +0000 |
commit | b0e4b91660f4c04f9abf5022de547479282af9ca (patch) | |
tree | 98503c1f80b6b087e64188a84858ddf94e350590 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 2974856ad4326989052f04299affaa516985e77a (diff) | |
download | bcm5719-llvm-b0e4b91660f4c04f9abf5022de547479282af9ca.tar.gz bcm5719-llvm-b0e4b91660f4c04f9abf5022de547479282af9ca.zip |
[llvm-objdump] Support disassembling by symbol name
Summary:
Add a new option -df to llvm-objdump that takes function names
as arguments and instructs the disassembler to only dump those function
contents. Based on code originally written by Bill Nell.
Reviewers: espindola, JDevlieghere
Differential Revision: https://reviews.llvm.org/D44224
llvm-svn: 327164
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 3be2c423bb5..7764c1d6e10 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" #include "llvm/CodeGen/FaultMaps.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" @@ -85,6 +86,12 @@ static cl::alias DisassembleAlld("D", cl::desc("Alias for --disassemble-all"), cl::aliasopt(DisassembleAll)); +static cl::list<std::string> +DisassembleFunctions("df", + cl::CommaSeparated, + cl::desc("List of functions to disassemble")); +static StringSet<> DisasmFuncsSet; + cl::opt<bool> llvm::Relocations("r", cl::desc("Display the relocation entries in the file")); @@ -1388,23 +1395,15 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { DataRefImpl DR = Section.getRawDataRefImpl(); SegmentName = MachO->getSectionFinalSegmentName(DR); } - StringRef name; - error(Section.getName(name)); - - if ((SectionAddr <= StopAddress) && - (SectionAddr + SectSize) >= StartAddress) { - outs() << "Disassembly of section "; - if (!SegmentName.empty()) - outs() << SegmentName << ","; - outs() << name << ':'; - } + StringRef SectionName; + error(Section.getName(SectionName)); // If the section has no symbol at the start, just insert a dummy one. if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) { - Symbols.insert(Symbols.begin(), - std::make_tuple(SectionAddr, name, Section.isText() - ? ELF::STT_FUNC - : ELF::STT_OBJECT)); + Symbols.insert( + Symbols.begin(), + std::make_tuple(SectionAddr, SectionName, + Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT)); } SmallString<40> Comments; @@ -1417,6 +1416,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { uint64_t Size; uint64_t Index; + bool PrintedSection = false; std::vector<RelocationRef>::const_iterator rel_cur = Rels.begin(); std::vector<RelocationRef>::const_iterator rel_end = Rels.end(); @@ -1441,6 +1441,19 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { continue; } + /// Skip if user requested specific symbols and this is not in the list + if (!DisasmFuncsSet.empty() && + !DisasmFuncsSet.count(std::get<1>(Symbols[si]))) + continue; + + if (!PrintedSection) { + PrintedSection = true; + outs() << "Disassembly of section "; + if (!SegmentName.empty()) + outs() << SegmentName << ","; + outs() << SectionName << ':'; + } + // Stop disassembly at the stop address specified if (End + SectionAddr > StopAddress) End = StopAddress - SectionAddr; @@ -2203,6 +2216,9 @@ int main(int argc, char **argv) { return 2; } + DisasmFuncsSet.insert(DisassembleFunctions.begin(), + DisassembleFunctions.end()); + llvm::for_each(InputFilenames, DumpInput); return EXIT_SUCCESS; |