summaryrefslogtreecommitdiffstats
path: root/backends
diff options
context:
space:
mode:
authorJan Kratochvil <[email protected]>2013-12-17 18:49:54 +0100
committerJan Kratochvil <[email protected]>2013-12-18 13:01:05 +0100
commitc6a41483f2986d5542c554981348f75b815ef9b1 (patch)
treeafbd87ebb664bfe07a7d03790920fdbbc3be9e38 /backends
parentc8c610bcfb9e90ab2d43c019da7eaade7017baec (diff)
unwinder: s390 and s390x
Signed-off-by: Jan Kratochvil <[email protected]>
Diffstat (limited to 'backends')
-rw-r--r--backends/ChangeLog11
-rw-r--r--backends/Makefile.am3
-rw-r--r--backends/s390_corenote.c10
-rw-r--r--backends/s390_init.c9
-rw-r--r--backends/s390_initreg.c87
-rw-r--r--backends/s390_unwind.c139
6 files changed, 253 insertions, 6 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog
index dc960485..cb56d217 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,14 @@
+2013-12-18 Jan Kratochvil <[email protected]>
+
+ unwinder: s390 and s390x
+ * Makefile.am (s390_SRCS): Add s390_initreg.c and s390_unwind.c.
+ * s390_corenote.c (prstatus_regs): Set PC_REGISTER. Reindent all the
+ entries.
+ * s390_init.c (s390_init): Initialize frame_nregs,
+ set_initial_registers_tid, normalize_pc and unwind.
+ * s390_initreg.c: New file.
+ * s390_unwind.c: New file.
+
2013-12-15 Jan Kratochvil <[email protected]>
unwinder: ppc and ppc64
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 4752a643..ec9e0a3c 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -106,7 +106,8 @@ libebl_ppc64_pic_a_SOURCES = $(ppc64_SRCS)
am_libebl_ppc64_pic_a_OBJECTS = $(ppc64_SRCS:.c=.os)
s390_SRCS = s390_init.c s390_symbol.c s390_regs.c s390_retval.c \
- s390_corenote.c s390x_corenote.c s390_cfi.c
+ s390_corenote.c s390x_corenote.c s390_cfi.c s390_initreg.c \
+ s390_unwind.c
libebl_s390_pic_a_SOURCES = $(s390_SRCS)
am_libebl_s390_pic_a_OBJECTS = $(s390_SRCS:.c=.os)
diff --git a/backends/s390_corenote.c b/backends/s390_corenote.c
index b88c05cf..7ca35168 100644
--- a/backends/s390_corenote.c
+++ b/backends/s390_corenote.c
@@ -47,13 +47,13 @@
static const Ebl_Register_Location prstatus_regs[] =
{
-#define GR(at, n, dwreg, b) \
+#define GR(at, n, dwreg, b...) \
{ .offset = at * BITS/8, .regno = dwreg, .count = n, .bits = b }
- GR ( 0, 1, 64, BITS), /* pswm */
- GR ( 1, 1, 65, BITS), /* pswa */
- GR ( 2, 16, 0, BITS), /* r0-r15 */
- GR (18, 16, 48, 32), /* ar0-ar15 */
+ GR ( 0, 1, 64, BITS), /* pswm */
+ GR ( 1, 1, 65, BITS, .pc_register = true ), /* pswa */
+ GR ( 2, 16, 0, BITS), /* r0-r15 */
+ GR (18, 16, 48, 32), /* ar0-ar15 */
#undef GR
};
diff --git a/backends/s390_init.c b/backends/s390_init.c
index 630a2ee3..26b20b49 100644
--- a/backends/s390_init.c
+++ b/backends/s390_init.c
@@ -62,6 +62,15 @@ s390_init (elf, machine, eh, ehlen)
else
HOOK (eh, core_note);
HOOK (eh, abi_cfi);
+ /* gcc/config/ #define DWARF_FRAME_REGISTERS 34.
+ But from the gcc/config/s390/s390.h "Register usage." comment it looks as
+ if #32 (Argument pointer) and #33 (Condition code) are not used for
+ unwinding. */
+ eh->frame_nregs = 32;
+ HOOK (eh, set_initial_registers_tid);
+ if (eh->class == ELFCLASS32)
+ HOOK (eh, normalize_pc);
+ HOOK (eh, unwind);
/* Only the 64-bit format uses the incorrect hash table entry size. */
if (eh->class == ELFCLASS64)
diff --git a/backends/s390_initreg.c b/backends/s390_initreg.c
new file mode 100644
index 00000000..62a1531e
--- /dev/null
+++ b/backends/s390_initreg.c
@@ -0,0 +1,87 @@
+/* Fetch live process registers from TID.
+ Copyright (C) 2013 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "system.h"
+#include <assert.h>
+#ifdef __s390__
+# include <sys/user.h>
+# include <asm/ptrace.h>
+# include <sys/ptrace.h>
+#endif
+
+#define BACKEND s390_
+#include "libebl_CPU.h"
+
+bool
+s390_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
+ ebl_tid_registers_t *setfunc __attribute__ ((unused)),
+ void *arg __attribute__ ((unused)))
+{
+#ifndef __s390__
+ return false;
+#else /* __s390__ */
+ struct user user_regs;
+ ptrace_area parea;
+ parea.process_addr = (uintptr_t) &user_regs;
+ parea.kernel_addr = 0;
+ parea.len = sizeof (user_regs);
+ if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea, NULL) != 0)
+ return false;
+ /* If we run as s390x we get the 64-bit registers of tid.
+ But -m31 executable seems to use only the 32-bit parts of its
+ registers so we ignore the upper half. */
+ Dwarf_Word dwarf_regs[16];
+ for (unsigned u = 0; u < 16; u++)
+ dwarf_regs[u] = user_regs.regs.gprs[u];
+ if (! setfunc (0, 16, dwarf_regs, arg))
+ return false;
+ /* Avoid conversion double -> integer. */
+ eu_static_assert (sizeof user_regs.regs.fp_regs.fprs[0]
+ == sizeof dwarf_regs[0]);
+ for (unsigned u = 0; u < 16; u++)
+ dwarf_regs[u] = *((const __typeof (dwarf_regs[0]) *)
+ &user_regs.regs.fp_regs.fprs[u]);
+ if (! setfunc (16, 16, dwarf_regs, arg))
+ return false;
+ dwarf_regs[0] = user_regs.regs.psw.addr;
+ return setfunc (-1, 1, dwarf_regs, arg);
+#endif /* __s390__ */
+}
+
+void
+s390_normalize_pc (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr *pc)
+{
+ assert (ebl->class == ELFCLASS32);
+
+ /* Clear S390 bit 31. */
+ *pc &= (1U << 31) - 1;
+}
diff --git a/backends/s390_unwind.c b/backends/s390_unwind.c
new file mode 100644
index 00000000..752bc287
--- /dev/null
+++ b/backends/s390_unwind.c
@@ -0,0 +1,139 @@
+/* Get previous frame state for an existing frame state.
+ Copyright (C) 2013 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <assert.h>
+
+#define BACKEND s390_
+#include "libebl_CPU.h"
+
+/* s390/s390x do not annotate signal handler frame by CFI. It would be also
+ difficult as PC points into a stub built on stack. Function below is called
+ only if unwinder could not find CFI. Function then verifies the register
+ state for this frame really belongs to a signal frame. In such case it
+ fetches original registers saved by the signal frame. */
+
+bool
+s390_unwind (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc,
+ ebl_tid_registers_get_t *getfunc, ebl_pid_memory_read_t *readfunc,
+ void *arg, bool *signal_framep)
+{
+ /* Caller already assumed caller adjustment but S390 instructions are 4 bytes
+ long. Undo it. */
+ if ((pc & 0x3) != 0x3)
+ return false;
+ pc++;
+ /* We can assume big-endian read here. */
+ Dwarf_Word instr;
+ if (! readfunc (pc, &instr, arg))
+ return false;
+ /* Fetch only the very first two bytes. */
+ instr = (instr >> (ebl->class == ELFCLASS64 ? 48 : 16)) & 0xffff;
+ /* See GDB s390_sigtramp_frame_sniffer. */
+ /* Check for 'svc' as the first instruction. */
+ if (((instr >> 8) & 0xff) != 0x0a)
+ return false;
+ /* Check for 'sigreturn' or 'rt_sigreturn' as the second instruction. */
+ if ((instr & 0xff) != 119 && (instr & 0xff) != 173)
+ return false;
+ /* See GDB s390_sigtramp_frame_unwind_cache. */
+ Dwarf_Word this_sp;
+ if (! getfunc (0 + 15, 1, &this_sp, arg))
+ return false;
+ unsigned word_size = ebl->class == ELFCLASS64 ? 8 : 4;
+ Dwarf_Addr next_cfa = this_sp + 16 * word_size + 32;
+ /* "New-style RT frame" is not supported,
+ assuming "Old-style RT frame and all non-RT frames".
+ Pointer to the array of saved registers is at NEXT_CFA + 8. */
+ Dwarf_Word sigreg_ptr;
+ if (! readfunc (next_cfa + 8, &sigreg_ptr, arg))
+ return false;
+ /* Skip PSW mask. */
+ sigreg_ptr += word_size;
+ /* Read PSW address. */
+ Dwarf_Word val;
+ if (! readfunc (sigreg_ptr, &val, arg))
+ return false;
+ if (! setfunc (-1, 1, &val, arg))
+ return false;
+ sigreg_ptr += word_size;
+ /* Then the GPRs. */
+ Dwarf_Word gprs[16];
+ for (int i = 0; i < 16; i++)
+ {
+ if (! readfunc (sigreg_ptr, &gprs[i], arg))
+ return false;
+ sigreg_ptr += word_size;
+ }
+ /* Then the ACRs. Skip them, they are not used in CFI. */
+ for (int i = 0; i < 16; i++)
+ sigreg_ptr += 4;
+ /* The floating-point control word. */
+ sigreg_ptr += 8;
+ /* And finally the FPRs. */
+ Dwarf_Word fprs[16];
+ for (int i = 0; i < 16; i++)
+ {
+ if (! readfunc (sigreg_ptr, &val, arg))
+ return false;
+ if (ebl->class == ELFCLASS32)
+ {
+ Dwarf_Addr val_low;
+ if (! readfunc (sigreg_ptr + 4, &val_low, arg))
+ return false;
+ val = (val << 32) | val_low;
+ }
+ fprs[i] = val;
+ sigreg_ptr += 8;
+ }
+ /* If we have them, the GPR upper halves are appended at the end. */
+ if (ebl->class == ELFCLASS32)
+ {
+ /* Skip signal number. */
+ sigreg_ptr += 4;
+ for (int i = 0; i < 16; i++)
+ {
+ if (! readfunc (sigreg_ptr, &val, arg))
+ return false;
+ Dwarf_Word val_low = gprs[i];
+ val = (val << 32) | val_low;
+ gprs[i] = val;
+ sigreg_ptr += 4;
+ }
+ }
+ if (! setfunc (0, 16, gprs, arg))
+ return false;
+ if (! setfunc (16, 16, fprs, arg))
+ return false;
+ *signal_framep = true;
+ return true;
+}