[quagga-dev 11492] Patch: Better backtrace support

Paul Jakma paul at jakma.org
Fri Sep 12 11:48:27 BST 2014


Another one that got lost in my git repo (sorry). Joakim tells me it is 
still relevant. Will queue for merging, unless there's an objection.

commit b92852517018d5903ea22bb265952eed91617c34
Author: Joakim Tjernlund <joakim.tjernlund at transmode.se>
Date:   Thu Jun 25 16:40:06 2009 +0100

     [lib] Add support for backtrace on more platforms

     * lib/sigevent.c: (program_counter) extend to support more platforms. Joint
       effort with Paul Jakma.

diff --git a/configure.ac b/configure.ac
index f1df482..a7f31cf 100755
--- a/configure.ac
+++ b/configure.ac
@@ -533,6 +533,18 @@ AC_CHECK_HEADERS([ucontext.h], [], [],
  QUAGGA_INCLUDES
  ])

+m4_define([UCONTEXT_INCLUDES],
+[#include <ucontext.h>])dnl
+
+AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.uc_regs],
+  [], [], [UCONTEXT_INCLUDES])
+AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.regs],
+  [AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.regs->nip],
+   [], [], [UCONTEXT_INCLUDES])],
+  [], [UCONTEXT_INCLUDES])
+AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.gregs],
+  [], [], [UCONTEXT_INCLUDES])
+
  m4_define([QUAGGA_INCLUDES],
  QUAGGA_INCLUDES
  [#if HAVE_SYS_UN_H
diff --git a/lib/sigevent.c b/lib/sigevent.c
index 7d08fd9..c80a729 100644
--- a/lib/sigevent.c
+++ b/lib/sigevent.c
@@ -175,11 +175,35 @@ program_counter(void *context)
  {
  #ifdef HAVE_UCONTEXT_H
  #ifdef GNU_LINUX
-#ifdef REG_EIP
-  if (context)
-    return (void *)(((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]);
-#endif /* REG_EIP */
+  /* these are from GNU libc, rather than Linux, strictly speaking */
+# if defined(REG_EIP)
+#  define REG_INDEX REG_EIP
+# elif defined(REG_RIP)
+#  define REG_INDEX REG_RIP
+# elif defined(__powerpc__)
+#  define REG_INDEX 32
+# endif
+#elif defined(SUNOS_5) /* !GNU_LINUX */
+# define REG_INDEX REG_PC
  #endif /* GNU_LINUX */
+
+#ifdef REG_INDEX
+# ifdef HAVE_UCONTEXT_T_UC_MCONTEXT_GREGS
+#  define REGS gregs[REG_INDEX]
+# elif defined(HAVE_UCONTEXT_T_UC_MCONTEXT_UC_REGS)
+#  define REGS uc_regs->gregs[REG_INDEX]
+# endif /* HAVE_UCONTEXT_T_UC_MCONTEXT_GREGS */
+#endif /* REG_INDEX */
+
+#ifdef REGS
+  if (context)
+    return (void *)(((ucontext_t *)context)->uc_mcontext.REGS);
+#elif defined(HAVE_UCONTEXT_T_UC_MCONTEXT_REGS__NIP) 
+  /* older Linux / struct pt_regs ? */
+  if (context)
+    return (void *)(((ucontext_t *)context)->uc_mcontext.regs->nip);
+#endif /* REGS */
+
  #endif /* HAVE_UCONTEXT_H */
    return NULL;
  }

-- 
Paul Jakma	paul at jakma.org	@pjakma	Key ID: 64A2FF6A
Fortune:
Computers are unreliable, but humans are even more unreliable.
Any system which depends on human reliability is unreliable.
 		-- Gilb




More information about the Quagga-dev mailing list