[llvm] r284852 - For llvm-objdump for Mach-O files add printing of
Kevin Enderby via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 11:22:35 PDT 2016
Author: enderby
Date: Fri Oct 21 13:22:35 2016
New Revision: 284852
URL: http://llvm.org/viewvc/llvm-project?rev=284852&view=rev
Log:
For llvm-objdump for Mach-O files add printing of
the ARM_THREAD_STATE in the same format as
otool-classic(1) on darwin.
Also remove an extra space in printing the initprot to make
the output match otool-classic(1) on darwin.
rdar://28851457
Added:
llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/thumb.armv7m (with props)
Modified:
llvm/trunk/test/tools/llvm-objdump/ARM/macho-private-headers.test
llvm/trunk/tools/llvm-objdump/MachODump.cpp
Added: llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/thumb.armv7m
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/thumb.armv7m?rev=284852&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/thumb.armv7m
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/thumb.armv7m
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: llvm/trunk/test/tools/llvm-objdump/ARM/macho-private-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/macho-private-headers.test?rev=284852&r1=284851&r2=284852&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/ARM/macho-private-headers.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/ARM/macho-private-headers.test Fri Oct 21 13:22:35 2016
@@ -1,6 +1,8 @@
// RUN: llvm-objdump -p %p/Inputs/hello.obj.macho-arm | FileCheck %s
// RUN: llvm-objdump -p %p/Inputs/hello.exe.macho-arm \
// RUN: | FileCheck %s -check-prefix=EXE
+// RUN: llvm-objdump -macho -private-headers %p/Inputs/thumb.armv7m \
+// RUN: | FileCheck %s -check-prefix=THREAD
CHECK: Mach header
CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
@@ -343,3 +345,14 @@ EXE: cmd LC_DYLIB_CODE_SIGN_DRS
EXE: cmdsize 16
EXE: dataoff 49244
EXE: datasize 20
+
+THREAD: Load command 6
+THREAD: cmd LC_UNIXTHREAD
+THREAD: cmdsize 84
+THREAD: flavor ARM_THREAD_STATE
+THREAD: count ARM_THREAD_STATE_COUNT
+THREAD: r0 0x00000000 r1 0x00000000 r2 0x00000000 r3 0x00000000
+THREAD: r4 0x00000000 r5 0x00000000 r6 0x00000000 r7 0x00000000
+THREAD: r8 0x00000000 r9 0x00000000 r10 0x00000000 r11 0x00000000
+THREAD: r12 0x00000000 sp 0x00000000 lr 0x00000000 pc 0x00001fff
+THREAD: cpsr 0x00000000
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=284852&r1=284851&r2=284852&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Oct 21 13:22:35 2016
@@ -7745,9 +7745,9 @@ static void PrintSegmentCommand(uint32_t
if ((initprot &
~(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE |
MachO::VM_PROT_EXECUTE)) != 0)
- outs() << " initprot ?" << format("0x%08" PRIx32, initprot) << "\n";
+ outs() << " initprot ?" << format("0x%08" PRIx32, initprot) << "\n";
else {
- outs() << " initprot ";
+ outs() << " initprot ";
outs() << ((initprot & MachO::VM_PROT_READ) ? "r" : "-");
outs() << ((initprot & MachO::VM_PROT_WRITE) ? "w" : "-");
outs() << ((initprot & MachO::VM_PROT_EXECUTE) ? "x\n" : "-\n");
@@ -8640,6 +8640,26 @@ static void Print_x86_exception_state_t(
outs() << " faultvaddr " << format("0x%016" PRIx64, exc64.faultvaddr) << "\n";
}
+static void Print_arm_thread_state32_t(MachO::arm_thread_state32_t &cpu32) {
+ outs() << "\t r0 " << format("0x%08" PRIx32, cpu32.r[0]);
+ outs() << " r1 " << format("0x%08" PRIx32, cpu32.r[1]);
+ outs() << " r2 " << format("0x%08" PRIx32, cpu32.r[2]);
+ outs() << " r3 " << format("0x%08" PRIx32, cpu32.r[3]) << "\n";
+ outs() << "\t r4 " << format("0x%08" PRIx32, cpu32.r[4]);
+ outs() << " r5 " << format("0x%08" PRIx32, cpu32.r[5]);
+ outs() << " r6 " << format("0x%08" PRIx32, cpu32.r[6]);
+ outs() << " r7 " << format("0x%08" PRIx32, cpu32.r[7]) << "\n";
+ outs() << "\t r8 " << format("0x%08" PRIx32, cpu32.r[8]);
+ outs() << " r9 " << format("0x%08" PRIx32, cpu32.r[9]);
+ outs() << " r10 " << format("0x%08" PRIx32, cpu32.r[10]);
+ outs() << " r11 " << format("0x%08" PRIx32, cpu32.r[11]) << "\n";
+ outs() << "\t r12 " << format("0x%08" PRIx32, cpu32.r[12]);
+ outs() << " sp " << format("0x%08" PRIx32, cpu32.sp);
+ outs() << " lr " << format("0x%08" PRIx32, cpu32.lr);
+ outs() << " pc " << format("0x%08" PRIx32, cpu32.pc) << "\n";
+ outs() << "\t cpsr " << format("0x%08" PRIx32, cpu32.cpsr) << "\n";
+}
+
static void PrintThreadCommand(MachO::thread_command t, const char *Ptr,
bool isLittleEndian, uint32_t cputype) {
if (t.cmd == MachO::LC_THREAD)
@@ -8792,6 +8812,53 @@ static void PrintThreadCommand(MachO::th
} else {
outs() << " flavor " << flavor << " (unknown)\n";
outs() << " count " << count << "\n";
+ outs() << " state (unknown)\n";
+ begin += count * sizeof(uint32_t);
+ }
+ }
+ } else if (cputype == MachO::CPU_TYPE_ARM) {
+ while (begin < end) {
+ if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
+ memcpy((char *)&flavor, begin, sizeof(uint32_t));
+ begin += sizeof(uint32_t);
+ } else {
+ flavor = 0;
+ begin = end;
+ }
+ if (isLittleEndian != sys::IsLittleEndianHost)
+ sys::swapByteOrder(flavor);
+ if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
+ memcpy((char *)&count, begin, sizeof(uint32_t));
+ begin += sizeof(uint32_t);
+ } else {
+ count = 0;
+ begin = end;
+ }
+ if (isLittleEndian != sys::IsLittleEndianHost)
+ sys::swapByteOrder(count);
+ if (flavor == MachO::ARM_THREAD_STATE) {
+ outs() << " flavor ARM_THREAD_STATE\n";
+ if (count == MachO::ARM_THREAD_STATE_COUNT)
+ outs() << " count ARM_THREAD_STATE_COUNT\n";
+ else
+ outs() << " count " << count
+ << " (not ARM_THREAD_STATE_COUNT)\n";
+ MachO::arm_thread_state32_t cpu32;
+ left = end - begin;
+ if (left >= sizeof(MachO::arm_thread_state32_t)) {
+ memcpy(&cpu32, begin, sizeof(MachO::arm_thread_state32_t));
+ begin += sizeof(MachO::arm_thread_state32_t);
+ } else {
+ memset(&cpu32, '\0', sizeof(MachO::arm_thread_state32_t));
+ memcpy(&cpu32, begin, left);
+ begin += left;
+ }
+ if (isLittleEndian != sys::IsLittleEndianHost)
+ swapStruct(cpu32);
+ Print_arm_thread_state32_t(cpu32);
+ } else {
+ outs() << " flavor " << flavor << " (unknown)\n";
+ outs() << " count " << count << "\n";
outs() << " state (unknown)\n";
begin += count * sizeof(uint32_t);
}
More information about the llvm-commits
mailing list