PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/third_party/glog/m4/pc_from_ucontext.m4

http://github.com/tomahawk-player/tomahawk
m4 | 71 lines | 58 code | 3 blank | 10 comment | 0 complexity | d39e9e95cf9b24132b8412d41d4ef237 MD5 | raw file
 1# We want to access the "PC" (Program Counter) register from a struct
 2# ucontext.  Every system has its own way of doing that.  We try all the
 3# possibilities we know about.  Note REG_PC should come first (REG_RIP
 4# is also defined on solaris, but does the wrong thing).
 5
 6# OpenBSD doesn't have ucontext.h, but we can get PC from ucontext_t
 7# by using signal.h.
 8
 9# The first argument of AC_PC_FROM_UCONTEXT will be invoked when we
10# cannot find a way to obtain PC from ucontext.
11
12AC_DEFUN([AC_PC_FROM_UCONTEXT],
13  [AC_CHECK_HEADERS(ucontext.h)
14   AC_CHECK_HEADERS(sys/ucontext.h)       # ucontext on OS X 10.6 (at least)
15   AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
16   pc_fields="           uc_mcontext.gregs[[REG_PC]]"  # Solaris x86 (32 + 64 bit)
17   pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
18   pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
19   pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
20   pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
21   pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
22   pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
23   pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
24   pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
25   pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]"  # NetBSD (i386)
26   pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]"  # NetBSD (x86_64)
27   pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
28   pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
29   pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
30   pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
31   pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
32   pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
33   pc_field_found=false
34   for pc_field in $pc_fields; do
35     if ! $pc_field_found; then
36       if test "x$ac_cv_header_sys_ucontext_h" = xyes; then
37         AC_TRY_COMPILE([#define _GNU_SOURCE 1
38                         #include <sys/ucontext.h>],
39                        [ucontext_t u; return u.$pc_field == 0;],
40                        AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
41                                           How to access the PC from a struct ucontext)
42                        AC_MSG_RESULT([$pc_field])
43                        pc_field_found=true)
44       else
45         AC_TRY_COMPILE([#define _GNU_SOURCE 1
46                         #include <ucontext.h>],
47                        [ucontext_t u; return u.$pc_field == 0;],
48                        AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
49                                           How to access the PC from a struct ucontext)
50                        AC_MSG_RESULT([$pc_field])
51                        pc_field_found=true)
52       fi
53     fi
54   done
55   if ! $pc_field_found; then
56     pc_fields="           sc_eip"  # OpenBSD (i386)
57     pc_fields="$pc_fields sc_rip"  # OpenBSD (x86_64)
58     for pc_field in $pc_fields; do
59       if ! $pc_field_found; then
60         AC_TRY_COMPILE([#include <signal.h>],
61                        [ucontext_t u; return u.$pc_field == 0;],
62                        AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
63                                           How to access the PC from a struct ucontext)
64                        AC_MSG_RESULT([$pc_field])
65                        pc_field_found=true)
66       fi
67     done
68   fi
69   if ! $pc_field_found; then
70     [$1]
71   fi])