]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
backends: sparc: support for core backtraces
authorJose E. Marchesi <jose.marchesi@oracle.com>
Tue, 8 Dec 2015 18:10:42 +0000 (19:10 +0100)
committerMark Wielaard <mjw@redhat.com>
Sun, 3 Jan 2016 11:17:16 +0000 (12:17 +0100)
This patch adds sparc support to the unwinder, providing a default CFI
program that works in both sparcv9-*-* and sparc64-*-* targets.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
backends/ChangeLog
backends/Makefile.am
backends/sparc_cfi.c [new file with mode: 0644]
backends/sparc_corenote.c
backends/sparc_init.c
tests/ChangeLog
tests/Makefile.am
tests/backtrace.sparc.core.bz2 [new file with mode: 0644]
tests/backtrace.sparc.exec.bz2 [new file with mode: 0755]
tests/run-backtrace-core-sparc.sh [new file with mode: 0755]

index 7f0d1c00e1f5027c5ff996f5aed39f39fb5461e5..7ee8c2c3009bb179ac95eba544b950b05775d05c 100644 (file)
@@ -1,3 +1,13 @@
+2015-12-08  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * sparc_corenote.c: Header comment typo fixed.
+       (PRSTATUS_REGSET_ITEMS): Defined, so the PC can be fetched from
+       core files.
+       * Makefile.am (sparc_SRCS): Added sparc_cfi.c
+       * sparc_cfi.c: New file.
+       * sparc_init.c (sparc_init): Set eh->frame_nregs, eh->ra_offset
+       and hook sparc_abi_cfi.
+
 2015-10-21  Chih-Hung Hsieh  <chh@google.com>
 
        * ia64_retval.c (hfa_type): Move nested function 'hfa' to file scope.
index f7002fb569641c887afe0bd28deb8ae0b20d9195..f07b20279b526eb897bc2b93db6e38c3bf7fec09 100644 (file)
@@ -84,7 +84,8 @@ libebl_aarch64_pic_a_SOURCES = $(aarch64_SRCS)
 am_libebl_aarch64_pic_a_OBJECTS = $(aarch64_SRCS:.c=.os)
 
 sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c \
-            sparc_corenote.c sparc64_corenote.c sparc_auxv.c sparc_attrs.c
+            sparc_corenote.c sparc64_corenote.c sparc_auxv.c sparc_attrs.c \
+             sparc_cfi.c
 libebl_sparc_pic_a_SOURCES = $(sparc_SRCS)
 am_libebl_sparc_pic_a_OBJECTS = $(sparc_SRCS:.c=.os)
 
diff --git a/backends/sparc_cfi.c b/backends/sparc_cfi.c
new file mode 100644 (file)
index 0000000..dcc17bd
--- /dev/null
@@ -0,0 +1,83 @@
+/* SPARC defaults for DWARF CFI.
+   Copyright (C) 2015 Oracle 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 <dwarf.h>
+
+#define BACKEND sparc_
+#include "libebl_CPU.h"
+
+int
+sparc_abi_cfi (Ebl *ebl __attribute__ ((unused)), Dwarf_CIE *abi_info)
+{
+  static const uint8_t abi_cfi[] =
+    {
+#define SV(n) DW_CFA_same_value, ULEB128_7 (n)
+      /* %g0 .. %g7 */
+      SV (0), SV (1), SV (2), SV (3), SV (4), SV (5), SV (6), SV (7),
+      /* %o0 .. %o7 */
+      SV (8), SV (9), SV (10), SV (11), SV (12), SV (13), SV (14), SV (15),
+      /* %l0 .. %l7 */
+      SV (16), SV (17), SV (18), SV (19), SV (20), SV (21), SV (22), SV (23),
+      /* %i0 .. %i7 */
+      SV (24), SV (25), SV (26), SV (27), SV (28), SV (29), SV (30), SV (31),
+      /* %f0 .. %f32 */
+      SV (32), SV (33), SV (34), SV (35), SV (36), SV (37), SV (38), SV (39),
+      SV (40), SV (41), SV (42), SV (43), SV (44), SV (45), SV (46), SV (47),
+      SV (48), SV (49), SV (50), SV (51), SV (52), SV (53), SV (54), SV (55),
+      SV (56), SV (57), SV (58), SV (59), SV (60), SV (61), SV (52), SV (63),
+      /* %f33 .. %63
+         Note that there are DWARF columns for the odd registers, even
+         if they don't exist in hardware) */
+      SV (64), SV (65), SV (66), SV (67), SV (68), SV (69), SV (70), SV (71),
+      SV (72), SV (73), SV (74), SV (75), SV (76), SV (77), SV (78), SV (79),
+      SV (80), SV (81), SV (82), SV (83), SV (84), SV (85), SV (86), SV (87),
+      SV (88), SV (89), SV (90), SV (91), SV (92), SV (93), SV (94), SV (95),
+      /* %fcc[0123] */
+      SV (96), SV (97), SV (98), SV (99),
+      /* %icc/%xcc */
+      SV (100),
+      /* Soft frame-pointer */
+      SV (101),
+      /* %gsr */
+      SV (102)
+#undef SV
+    };
+
+  abi_info->initial_instructions = abi_cfi;
+  abi_info->initial_instructions_end = &abi_cfi[sizeof abi_cfi];
+  abi_info->data_alignment_factor = 4;
+
+  abi_info->return_address_register = 31; /* %i7 */
+
+  return 0;
+}
+
index 7912539b0865242f237e4a58e20c4ab94ed0e832..c9b6ff3d76e9539771ffa2bf4cc8f2a3f6742269 100644 (file)
@@ -1,5 +1,6 @@
-/* PowerPC specific core note handling.
+/* SPARC specific core note handling.
    Copyright (C) 2007 Red Hat, Inc.
+   Copyright (C) 2015 Oracle, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -109,4 +110,11 @@ static const Ebl_Register_Location fpregset_regs[] =
 #define ALIGN_PID_T            4
 #define TYPE_PID_T             ELF_T_SWORD
 
+#define PRSTATUS_REGSET_ITEMS                                                \
+  {                                                                          \
+    .name = "pc", .type = ELF_T_ADDR, .format = 'x',                         \
+    .offset = offsetof (struct EBLHOOK(prstatus), pr_reg[33]),               \
+    .group = "register", .pc_register = true                                 \
+  }
+
 #include "linux-core-note.c"
index f8a7cfbdb2875951bfce43bd9206a7613df18868..98b697c3ce9150917308e06f5f1edd4a2d587bdc 100644 (file)
@@ -76,6 +76,13 @@ sparc_init (Elf *elf __attribute__ ((unused)),
   HOOK (eh, register_info);
   HOOK (eh, return_value_location);
   HOOK (eh, check_object_attribute);
+  HOOK (eh, abi_cfi);
+  /* gcc/config/sparc.h define FIRST_PSEUDO_REGISTER  */
+  eh->frame_nregs = 103;
+  /* The CFI Dwarf register with the "return address" in sparc
+     actually contains the call address.  The return address is
+     located 8 bytes after it.  */
+  eh->ra_offset = 8;
 
   return MODVERSION;
 }
index 2940e3829b8d4565ea9e7e162f70154ffa24d74c..b8d1d954983fc6ea2bfad3dc61ef35cc0527e5c5 100644 (file)
@@ -1,3 +1,11 @@
+2015-12-08  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * run-backtrace-core-sparc.sh: New file.
+       * backtrace.sparc.core.bz2: New file.
+       * backtrace.sparc.exec.bz2: New file.
+       * Makefile.am (EXTRA_DIST): ... and added all here.
+       (TESTS): Added run-backtrace-core-sparc.sh.
+
 2015-12-02  Mark Wielaard  <mjw@redhat.com>
 
        * Makefile.am (valgrind_cmd): Use --leak-check=full.
index 0077c0f59b393475bc845bb3acce8a5bab3ef488..8fca80140463dae4d498a5672c6454b0d4cd2632 100644 (file)
@@ -114,7 +114,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-backtrace-core-x32.sh \
        run-backtrace-core-i386.sh run-backtrace-core-ppc.sh \
        run-backtrace-core-s390x.sh run-backtrace-core-s390.sh \
-       run-backtrace-core-aarch64.sh \
+       run-backtrace-core-aarch64.sh run-backtrace-core-sparc.sh \
        run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \
        run-stack-demangled-test.sh \
        run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \
@@ -287,6 +287,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             run-backtrace-core-s390x.sh run-backtrace-core-s390.sh \
             run-backtrace-core-aarch64.sh \
             backtrace.aarch64.core.bz2 backtrace.aarch64.exec.bz2 \
+            run-backtrace-core-sparc.sh \
+            backtrace.sparc.core.bz2 backtrace.sparc.exec.bz2 \
             run-backtrace-demangle.sh testfile-backtrace-demangle.bz2 \
             testfile-backtrace-demangle.cc \
             testfile-backtrace-demangle.core.bz2 \
diff --git a/tests/backtrace.sparc.core.bz2 b/tests/backtrace.sparc.core.bz2
new file mode 100644 (file)
index 0000000..ad37f75
Binary files /dev/null and b/tests/backtrace.sparc.core.bz2 differ
diff --git a/tests/backtrace.sparc.exec.bz2 b/tests/backtrace.sparc.exec.bz2
new file mode 100755 (executable)
index 0000000..b049ec5
Binary files /dev/null and b/tests/backtrace.sparc.exec.bz2 differ
diff --git a/tests/run-backtrace-core-sparc.sh b/tests/run-backtrace-core-sparc.sh
new file mode 100755 (executable)
index 0000000..60399ba
--- /dev/null
@@ -0,0 +1,20 @@
+#! /bin/bash
+# Copyright (C) 2015 Oracle, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/backtrace-subr.sh
+
+check_core sparc