Add the option, -dis-symname to llvm-objdump used with -macho and

-disassemble to disassemble just one symbol’s instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232503 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Enderby
2015-03-17 17:10:57 +00:00
parent 6e4a97dfce
commit 73cd697dec
3 changed files with 35 additions and 0 deletions

View File

@@ -116,6 +116,10 @@ cl::opt<bool>
cl::desc("Print the info for Mach-O objects in "
"non-verbose or numeric form (requires -macho)"));
cl::opt<std::string> llvm::DisSymName(
"dis-symname",
cl::desc("disassemble just this symbol's instructions (requires -macho"));
static cl::list<std::string>
ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
cl::ZeroOrMore);
@@ -3181,6 +3185,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
// Create a map of symbol addresses to symbol names for use by
// the SymbolizerSymbolLookUp() routine.
SymbolAddressMap AddrMap;
bool DisSymNameFound = false;
for (const SymbolRef &Symbol : MachOOF->symbols()) {
SymbolRef::Type ST;
Symbol.getType(ST);
@@ -3191,8 +3196,14 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
StringRef SymName;
Symbol.getName(SymName);
AddrMap[Address] = SymName;
if (!DisSymName.empty() && DisSymName == SymName)
DisSymNameFound = true;
}
}
if (!DisSymName.empty() && DisSymNameFound == false) {
outs() << "Can't find -dis-symname: " << DisSymName << "\n";
return;
}
// Set up the block of info used by the Symbolizer call backs.
SymbolizerInfo.verbose = true;
SymbolizerInfo.O = MachOOF;
@@ -3235,6 +3246,10 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
if (!containsSym)
continue;
// If we are only disassembling one symbol see if this is that symbol.
if (!DisSymName.empty() && DisSymName != SymName)
continue;
// Start at the address of the symbol relative to the section's address.
uint64_t Start = 0;
uint64_t SectionAddress = Sections[SectIdx].getAddress();