From 1fa94d6f926763f9fc0fd0f73e63e85fea31cdc7 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 27 Mar 2015 17:31:15 +0000 Subject: [PATCH] Add a -raw option to the -section mode of llvm-objdump. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233390 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-objdump/macho-sections.test | 5 +++++ tools/llvm-objdump/MachODump.cpp | 16 +++++++++++++--- tools/llvm-objdump/llvm-objdump.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/tools/llvm-objdump/macho-sections.test diff --git a/test/tools/llvm-objdump/macho-sections.test b/test/tools/llvm-objdump/macho-sections.test new file mode 100644 index 00000000000..31efd110a5c --- /dev/null +++ b/test/tools/llvm-objdump/macho-sections.test @@ -0,0 +1,5 @@ +# RUN: llvm-objdump -macho -section=__data %p/Inputs/bind2.macho-x86_64 | FileCheck %s +# RUN: llvm-objdump -macho -section=__data -raw %p/Inputs/bind2.macho-x86_64 | FileCheck --check-prefix=RAW %s + +# CHECK: bind2.macho-x86_64: +# RAW-NOT: bind2.macho-x86_64: diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 86504e60a2d..fc72bc383b6 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -99,6 +99,9 @@ cl::list cl::desc("Prints the specified segment,section for " "Mach-O objects (requires -macho)")); +cl::opt llvm::Raw("raw", + cl::desc("Have -section dump the raw binary contents")); + cl::opt llvm::InfoPlist("info-plist", cl::desc("Print the info plist section as strings for " @@ -1043,8 +1046,7 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, StringRef SegName = O->getSectionFinalSegmentName(Ref); if ((DumpSegName.empty() || SegName == DumpSegName) && (SectName == DumpSectName)) { - outs() << "Contents of (" << SegName << "," << SectName - << ") section\n"; + uint32_t section_flags; if (O->is64Bit()) { const MachO::section_64 Sec = O->getSection64(Ref); @@ -1062,6 +1064,14 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, uint32_t sect_size = BytesStr.size(); uint64_t sect_addr = Section.getAddress(); + if (Raw) { + outs().write(BytesStr.data(), BytesStr.size()); + continue; + } + + outs() << "Contents of (" << SegName << "," << SectName + << ") section\n"; + if (verbose) { if ((section_flags & MachO::S_ATTR_PURE_INSTRUCTIONS) || (section_flags & MachO::S_ATTR_SOME_INSTRUCTIONS)) { @@ -1181,7 +1191,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF, // UniversalHeaders or ArchiveHeaders. if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind || LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints || - DylibsUsed || DylibId || DumpSections.size() != 0) { + DylibsUsed || DylibId || (DumpSections.size() != 0 && !Raw)) { outs() << Filename; if (!ArchiveMemberName.empty()) outs() << '(' << ArchiveMemberName << ')'; diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index c1d5ff8c211..5d0099b18b0 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -27,6 +27,7 @@ extern cl::opt ArchName; extern cl::opt MCPU; extern cl::list MAttrs; extern cl::list DumpSections; +extern cl::opt Raw; extern cl::opt Disassemble; extern cl::opt NoShowRawInsn; extern cl::opt PrivateHeaders;