From 3cc1e2deee0c4ac295b8cb2952fcfb8976851d81 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Wed, 4 Feb 2015 21:38:42 +0000 Subject: [PATCH] =?utf8?q?Add=20code=20to=20llvm-objdump=20so=20the=20-sec?= =?utf8?q?tion=20option=20with=20-macho=20will=20dump=20=E2=80=98C?= =?utf8?q?=E2=80=99=20string=20sections=20with=20the=20Mach-O=20S=5FCSTRIN?= =?utf8?q?G=5FLITERALS=20section=20type.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228198 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm-objdump/X86/macho-cstring-dump.test | 4 ++++ tools/llvm-objdump/MachODump.cpp | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/tools/llvm-objdump/X86/macho-cstring-dump.test diff --git a/test/tools/llvm-objdump/X86/macho-cstring-dump.test b/test/tools/llvm-objdump/X86/macho-cstring-dump.test new file mode 100644 index 00000000000..869462da233 --- /dev/null +++ b/test/tools/llvm-objdump/X86/macho-cstring-dump.test @@ -0,0 +1,4 @@ +RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s + +CHECK: Contents of (__TEXT,__cstring) section +CHECK: 0x000000000000003b Hello world\n diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 9a0255d428b..1bb9bfce666 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -537,6 +537,25 @@ static const char *GuessSymbolName(uint64_t value, SymbolAddressMap *AddrMap) { return SymbolName; } +static void DumpCstringSection(MachOObjectFile *O, const char *sect, + uint32_t sect_size, uint64_t sect_addr, + bool verbose) { + for (uint32_t i = 0; i < sect_size; i++) { + if (O->is64Bit()) + outs() << format("0x%016" PRIx64, sect_addr + i) << " "; + else + outs() << format("0x%08" PRIx64, sect_addr + i) << " "; + for ( ; i < sect_size && sect[i] != '\0'; i++) { + char p[2]; + p[0] = sect[i]; + p[1] = '\0'; + outs().write_escaped(p); + } + if (i < sect_size && sect[i] == '\0') + outs() << "\n"; + } +} + static void DumpInitTermPointerSection(MachOObjectFile *O, const char *sect, uint32_t sect_size, uint64_t sect_addr, SymbolAddressMap *AddrMap, @@ -676,6 +695,9 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, case MachO::S_ZEROFILL: outs() << "zerofill section and has no contents in the file\n"; break; + case MachO::S_CSTRING_LITERALS: + DumpCstringSection(O, sect, sect_size, sect_addr, verbose); + break; case MachO::S_MOD_INIT_FUNC_POINTERS: case MachO::S_MOD_TERM_FUNC_POINTERS: DumpInitTermPointerSection(O, sect, sect_size, sect_addr, &AddrMap, -- 2.34.1