crash-stack: align output format with sys-assert 60/104560/1
authorŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 13 Dec 2016 09:33:24 +0000 (10:33 +0100)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 13 Dec 2016 13:27:43 +0000 (14:27 +0100)
Make crash-stack print register information the very same way as
sys-assert does it.

Change output format slightly for 64 bit architectures to match hw
requirements.

Support both i686 and x86_64 in the same architecture specific file.

Change-Id: Ica03360b61c1aa133b83c5622334cf4f375db3c2

src/crash-stack/CMakeLists.txt
src/crash-stack/crash-stack-aarch64.c
src/crash-stack/crash-stack-arm.c
src/crash-stack/crash-stack-x86.c [new file with mode: 0644]
src/crash-stack/crash-stack-x86_64.c [deleted file]

index 34c44eaee6e1e206f28fd97c6e9d1b5f3a9a1938..ccf845ee2a052153925e42f3783400c4c2b3d5aa 100644 (file)
@@ -14,7 +14,10 @@ else()
     set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-aarch64.c)
   elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
     set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-libelf.c)
-    set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-x86_64.c)
+    set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-x86.c)
+  elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
+    set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-libelf.c)
+    set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-x86.c)
   else()
     set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-libelf.c)
     set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-stub.c)
index 646128472da021b6028a5b4d71a832269a05974c..0c67286e21aa447679055dc4cde36322c886f743 100644 (file)
@@ -103,24 +103,25 @@ void *_get_place_for_register_value(const char *regname, int regnum)
 
 void _crash_stack_print_regs(FILE* outputfile)
 {
-       int i,top_reg;
-
-       if ((g_registers.pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == PSR_MODE32_BIT) {
-               top_reg = 12;
-       } else {
-               top_reg = 29;
-       }
+       int i;
 
        fprintf(outputfile, "\nRegister Information\n");
-       fprintf(outputfile, "pc : [<%016llx>] lr : [<%016llx>] pstate: %08llx\n",
-               g_registers.pc, g_registers.regs[30], g_registers.pstate);
-       fprintf(outputfile, "sp : %016llx\n", g_registers.sp);
-
-       for (i = top_reg; i >= 0; i--) {
-               fprintf(outputfile, "x%-2d: %016llx ", i, g_registers.regs[i]);
-               if ((i%2) == 0) {
-                       fprintf(outputfile,"\n");
-               }
+       for (i = 0; i <= 30; i++) {
+               fprintf(outputfile, "x%-2d  = 0x%016llx", i, g_registers.regs[i]);
+               if (i != 30 && 0 == i % 2)
+                       fprintf(outputfile, ", ");
+               else
+                       fprintf(outputfile, "\n");
        }
-       fprintf(outputfile,"\n");
+       fprintf(outputfile, "\n");
+       fprintf(outputfile, "xr   = 0x%016llx, ip0  = 0x%016llx\nip1  = 0x%016llx, pr   = 0x%016llx\n",
+               g_registers.regs[8],   /* Indirect result location register */
+               g_registers.regs[16],  /* Intra-procedure call scratch register 0 */
+               g_registers.regs[17],  /* Intra-procedure call scratch register 1 */
+               g_registers.regs[18]); /* Platform register */
+       fprintf(outputfile, "fp   = 0x%016llx, lr   = 0x%016llx\npc   = 0x%016llx, sp   = 0x%016llx\n",
+               g_registers.regs[29],  /* Frame register */
+               g_registers.regs[30],  /* Procedure link register */
+               g_registers.pc,        /* Program counter */
+               g_registers.sp);       /* Stack pointer */
 }
index 8d91486439328ee38067b5d631cfcc1804be049b..5f9033f5e66ca8c9f101a1962cffd03a230c282a 100644 (file)
@@ -89,24 +89,18 @@ void _crash_stack_set_ptrace_registers(void *regbuf)
 void _crash_stack_print_regs(FILE* outputfile)
 {
        fprintf(outputfile, "\nRegister Information\n");
-       fprintf(outputfile, "pc : [<%08lx>]    lr : [<%08lx>]    psr: %08lx\n",
-               g_ptrace_registers.uregs[REG_PC], g_ptrace_registers.uregs[REG_LR],
-               g_ptrace_registers.uregs[REG_SPSR]
-               );
-       fprintf(outputfile, "sp : %08lx  ip : %08lx  fp : %08lx\n",
-               g_ptrace_registers.uregs[REG_SP], g_ptrace_registers.uregs[REG_IP],
-               g_ptrace_registers.uregs[REG_FP]
-               );
-       fprintf(outputfile, "r10: %08lx  r9 : %08lx  r8 : %08lx\n",
-               g_ptrace_registers.uregs[10], g_ptrace_registers.uregs[9],
-               g_ptrace_registers.uregs[8]
-               );
-       fprintf(outputfile, "r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
-               g_ptrace_registers.uregs[7], g_ptrace_registers.uregs[6],
-               g_ptrace_registers.uregs[5], g_ptrace_registers.uregs[4]
-               );
-       fprintf(outputfile, "r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
-               g_ptrace_registers.uregs[3], g_ptrace_registers.uregs[2],
-               g_ptrace_registers.uregs[1], g_ptrace_registers.uregs[0]
-               );
+       fprintf(outputfile, "r0   = 0x%08lx, r1   = 0x%08lx\nr2   = 0x%08lx, r3   = 0x%08lx\n",
+              g_ptrace_registers.uregs[0], g_ptrace_registers.uregs[1],
+              g_ptrace_registers.uregs[2], g_ptrace_registers.uregs[3]);
+       fprintf(outputfile, "r4   = 0x%08lx, r5   = 0x%08lx\nr6   = 0x%08lx, r7   = 0x%08lx\n",
+              g_ptrace_registers.uregs[4], g_ptrace_registers.uregs[5],
+              g_ptrace_registers.uregs[6], g_ptrace_registers.uregs[7]);
+       fprintf(outputfile, "r8   = 0x%08lx, r9   = 0x%08lx\nr10  = 0x%08lx, fp   = 0x%08lx\n",
+              g_ptrace_registers.uregs[8], g_ptrace_registers.uregs[9],
+              g_ptrace_registers.uregs[10], g_ptrace_registers.uregs[REG_FP]);
+       fprintf(outputfile, "ip   = 0x%08lx, sp   = 0x%08lx\nlr   = 0x%08lx, pc   = 0x%08lx\n",
+              g_ptrace_registers.uregs[REG_IP], g_ptrace_registers.uregs[REG_SP],
+              g_ptrace_registers.uregs[REG_LR], g_ptrace_registers.uregs[REG_PC]);
+       /* XXX the label should probably write "spsr" */
+       fprintf(outputfile, "cpsr = 0x%08lx\n", g_ptrace_registers.uregs[REG_SPSR]);
 }
diff --git a/src/crash-stack/crash-stack-x86.c b/src/crash-stack/crash-stack-x86.c
new file mode 100644 (file)
index 0000000..b63f279
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors: Adrian Szyndela <adrian.s@samsung.com>
+ *          Łukasz Stelmach <l.stelmach@samsung.com>
+ */
+/**
+ * @file crash-stack-x86_64.c
+ * @brief unwinding call stacks, functions specific for x86_64
+ */
+#include "crash-stack.h"
+#include <sys/user.h>
+#include <string.h>
+
+struct user_regs_struct g_registers;   ///< static storage for ptrace buffer for registers
+
+void *_crash_stack_get_memory_for_ptrace_registers(size_t *size)
+{
+       if (NULL != size)
+               *size = sizeof(g_registers);
+       return &g_registers;
+}
+
+void _crash_stack_set_ptrace_registers(void *regbuf)
+{
+       void *rsp = _get_place_for_register_value("rsp", 0);
+       void *rip = _get_place_for_register_value("rip", 0);
+
+       struct user_regs_struct *regs = regbuf;
+
+#if defined(__x86_64__)
+       memcpy(rsp, &regs->rsp, sizeof(regs->rsp));
+       memcpy(rip, &regs->rip, sizeof(regs->rip));
+#else
+       memcpy(rsp, &regs->esp, sizeof(regs->esp));
+       memcpy(rip, &regs->eip, sizeof(regs->eip));
+#endif
+}
+
+void _crash_stack_print_regs(FILE* outputfile)
+{
+       fprintf(outputfile, "\nRegister Information\n");
+#if defined(__x86_64__)
+       fprintf(outputfile, "gs  = 0x%016llx, fs  = 0x%016llx\nes  = 0x%016llx, ds  = 0x%016llx\n",
+               g_registers.gs,
+               g_registers.fs,
+               g_registers.es,
+               g_registers.ds);
+       fprintf(outputfile, "rdi = 0x%016llx, rsi = 0x%016llx\nrbp = 0x%016llx, rsp = 0x%016llx\n",
+               g_registers.rdi,
+               g_registers.rsi,
+               g_registers.rbp,
+               g_registers.rsp);
+       fprintf(outputfile, "rax = 0x%016llx, rbx = 0x%016llx\nrcx = 0x%016llx, rdx = 0x%016llx\n",
+               g_registers.rax,
+               g_registers.rbx,
+               g_registers.rcx,
+               g_registers.rdx);
+       fprintf(outputfile, "r8  = 0x%016llx, r9  = 0x%016llx\nr10 = 0x%016llx, r11 = 0x%016llx\n",
+               g_registers.r8,
+               g_registers.r9,
+               g_registers.r10,
+               g_registers.r11);
+       fprintf(outputfile, "r12 = 0x%016llx, r13 = 0x%016llx\nr14 = 0x%016llx, r15 = 0x%016llx\n",
+               g_registers.r12,
+               g_registers.r13,
+               g_registers.r14,
+               g_registers.r15);
+       fprintf(outputfile, "rip = 0x%016llx\n",
+               g_registers.rip);
+#else
+       fprintf(outputfile, "gs  = 0x%08lx, fs  = 0x%08lx\nes  = 0x%08lx, ds  = 0x%08lx\n",
+              g_registers.xgs,
+              g_registers.xfs,
+              g_registers.xes,
+              g_registers.xds);
+       fprintf(outputfile, "edi = 0x%08lx, esi = 0x%08lx\nebp = 0x%08lx, esp = 0x%08lx\n",
+              g_registers.edi,
+              g_registers.esi,
+              g_registers.ebp,
+              g_registers.esp);
+       fprintf(outputfile, "eax = 0x%08lx, ebx = 0x%08lx\necx = 0x%08lx, edx = 0x%08lx\n",
+              g_registers.eax,
+              g_registers.ebx,
+              g_registers.ecx,
+              g_registers.edx);
+       fprintf(outputfile, "eip = 0x%08lx\n",
+              g_registers.eip);
+#endif
+}
diff --git a/src/crash-stack/crash-stack-x86_64.c b/src/crash-stack/crash-stack-x86_64.c
deleted file mode 100644 (file)
index 1aad750..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Authors: Adrian Szyndela <adrian.s@samsung.com>
- *          Łukasz Stelmach <l.stelmach@samsung.com>
- */
-/**
- * @file crash-stack-x86_64.c
- * @brief unwinding call stacks, functions specific for x86_64
- */
-#include "crash-stack.h"
-#include <sys/user.h>
-#include <string.h>
-
-struct user_regs_struct g_registers;   ///< static storage for ptrace buffer for registers
-
-void *_crash_stack_get_memory_for_ptrace_registers(size_t *size)
-{
-       if (NULL != size)
-               *size = sizeof(g_registers);
-       return &g_registers;
-}
-
-void _crash_stack_set_ptrace_registers(void *regbuf)
-{
-       void *rsp = _get_place_for_register_value("rsp", 0);
-       void *rip = _get_place_for_register_value("rip", 0);
-
-       struct user_regs_struct *regs = regbuf;
-
-       memcpy(rsp, &regs->rsp, sizeof(regs->rsp));
-       memcpy(rip, &regs->rip, sizeof(regs->rip));
-}
-
-void _crash_stack_print_regs(FILE* outputfile)
-{
-#define _PRINT_REGISTERS(a,b,c)                                                \
-       fprintf(outputfile, "%3s: %016llx %3s: %016llx %3s: %016llx\n", \
-               #a, g_registers.a, \
-               #b, g_registers.b, \
-               #c, g_registers.c)
-       fprintf(outputfile, "\nRegister Information\n");
-#ifdef __x86_64__
-       fprintf(outputfile, "rip: %04llx:[<%016llx>]\n",
-               g_registers.cs & 0xffff,
-               g_registers.rip);
-       fprintf(outputfile, "rsp: %04llx:%016llx eflags: %08llx\n",
-               g_registers.ss,
-               g_registers.rsp,
-               g_registers.eflags);
-       _PRINT_REGISTERS(rax, rbx, rcx);
-       _PRINT_REGISTERS(rdx, rsi, rdi);
-       _PRINT_REGISTERS(rbp, r8, r9);
-       _PRINT_REGISTERS(r10, r11, r12);
-       _PRINT_REGISTERS(r13, r14, r15);
-#else
-       fprintf(outputfile, "Unsupported architecture\n")
-#endif
-       fprintf(outputfile, "\n");
-#undef _PRINT_REGISTERS
-}