diff options
author | Michael Trent <mtrent@apple.com> | 2019-05-30 17:56:05 +0000 |
---|---|---|
committer | Michael Trent <mtrent@apple.com> | 2019-05-30 17:56:05 +0000 |
commit | 50daaa5f6b2636578ac70ed08e0db246be3b95b8 (patch) | |
tree | 89670d89b56e9c87c129a00ac49a5467afc3bb94 /llvm/tools/llvm-objdump/MachODump.cpp | |
parent | 2980f3c18f980b20bb8b5106978555ef147035f6 (diff) | |
download | bcm5719-llvm-50daaa5f6b2636578ac70ed08e0db246be3b95b8.tar.gz bcm5719-llvm-50daaa5f6b2636578ac70ed08e0db246be3b95b8.zip |
Support Universal dSYM files in llvm-objdump
Summary:
Commonly programmers use llvm-objdump to disassemble Mach-O target
binaries with Mach-O dSYMS. While llvm-objdump allows programmers to
disassemble Universal binaries, it previously did not recognize
Universal dSYM files. This change updates llvm-objdump to support
passing in Universal files via the -dsym option. Now, when
disassembling a Mach-O file either as a stand alone file or as an entry
in a Universal binariy, llvm-objdump will search through a Universal
dSYM for a Mach-O matching the architecture flag of the file being
disassembled.
Reviewers: pete, lhames
Reviewed By: pete
Subscribers: rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62642
llvm-svn: 362121
Diffstat (limited to 'llvm/tools/llvm-objdump/MachODump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/MachODump.cpp | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index ea92ef9268a..b684daacb61 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7223,11 +7223,13 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, raw_ostream &DebugOut = nulls(); #endif + // Try to find debug info and set up the DIContext for it. std::unique_ptr<DIContext> diContext; - ObjectFile *DbgObj = MachOOF; + std::unique_ptr<Binary> DSYMBinary; std::unique_ptr<MemoryBuffer> DSYMBuf; - // Try to find debug info and set up the DIContext for it. if (UseDbg) { + ObjectFile *DbgObj = MachOOF; + // A separate DSym file path was specified, parse it as a macho file, // get the sections and supply it to the section name parsing machinery. if (!DSYMFile.empty()) { @@ -7238,12 +7240,61 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, return; } - std::unique_ptr<MachOObjectFile> DbgObjCheck = unwrapOrError( - ObjectFile::createMachOObjectFile(BufOrErr.get()->getMemBufferRef()), - DSYMFile.getValue()); - DbgObj = DbgObjCheck.release(); // We need to keep the file alive, because we're replacing DbgObj with it. DSYMBuf = std::move(BufOrErr.get()); + + Expected<std::unique_ptr<Binary>> BinaryOrErr = + createBinary(DSYMBuf.get()->getMemBufferRef()); + if (!BinaryOrErr) { + report_error(BinaryOrErr.takeError(), DSYMFile); + return; + } + + // We need to keep the Binary elive with the buffer + DSYMBinary = std::move(BinaryOrErr.get()); + + if (ObjectFile *O = dyn_cast<ObjectFile>(DSYMBinary.get())) { + // this is a Mach-O object file, use it + if (MachOObjectFile *MachDSYM = dyn_cast<MachOObjectFile>(&*O)) { + DbgObj = MachDSYM; + } + else { + WithColor::error(errs(), "llvm-objdump") + << DSYMFile << " is not a Mach-O file type.\n"; + return; + } + } + else if (auto UB = dyn_cast<MachOUniversalBinary>(DSYMBinary.get())){ + // this is a Universal Binary, find a Mach-O for this architecture + uint32_t CPUType, CPUSubType; + const char *ArchFlag; + if (MachOOF->is64Bit()) { + const MachO::mach_header_64 H_64 = MachOOF->getHeader64(); + CPUType = H_64.cputype; + CPUSubType = H_64.cpusubtype; + } else { + const MachO::mach_header H = MachOOF->getHeader(); + CPUType = H.cputype; + CPUSubType = H.cpusubtype; + } + Triple T = MachOObjectFile::getArchTriple(CPUType, CPUSubType, nullptr, + &ArchFlag); + Expected<std::unique_ptr<MachOObjectFile>> MachDSYM = + UB->getObjectForArch(ArchFlag); + if (!MachDSYM) { + report_error(MachDSYM.takeError(), DSYMFile); + return; + } + + // We need to keep the Binary elive with the buffer + DbgObj = &*MachDSYM.get(); + DSYMBinary = std::move(*MachDSYM); + } + else { + WithColor::error(errs(), "llvm-objdump") + << DSYMFile << " is not a Mach-O or Universal file type.\n"; + return; + } } // Setup the DIContext |