/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. # OpenBSD doesn't have ucontext.h, but we can get PC from ucontext_t
  6. # by using signal.h.
  7. # The first argument of AC_PC_FROM_UCONTEXT will be invoked when we
  8. # cannot find a way to obtain PC from ucontext.
  9. AC_DEFUN([AC_PC_FROM_UCONTEXT],
  10. [AC_CHECK_HEADERS(ucontext.h)
  11. AC_CHECK_HEADERS(sys/ucontext.h) # ucontext on OS X 10.6 (at least)
  12. AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
  13. pc_fields=" uc_mcontext.gregs[[REG_PC]]" # Solaris x86 (32 + 64 bit)
  14. pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
  15. pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
  16. pc_fields="$pc_fields uc_mcontext.sc_ip" # Linux (ia64)
  17. pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
  18. pc_fields="$pc_fields uc_mcontext.gregs[[R15]]" # Linux (arm old [untested])
  19. pc_fields="$pc_fields uc_mcontext.arm_pc" # Linux (arm new [untested])
  20. pc_fields="$pc_fields uc_mcontext.mc_eip" # FreeBSD (i386)
  21. pc_fields="$pc_fields uc_mcontext.mc_rip" # FreeBSD (x86_64 [untested])
  22. pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]" # NetBSD (i386)
  23. pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]" # NetBSD (x86_64)
  24. pc_fields="$pc_fields uc_mcontext->ss.eip" # OS X (i386, <=10.4)
  25. pc_fields="$pc_fields uc_mcontext->__ss.__eip" # OS X (i386, >=10.5)
  26. pc_fields="$pc_fields uc_mcontext->ss.rip" # OS X (x86_64)
  27. pc_fields="$pc_fields uc_mcontext->__ss.__rip" # OS X (>=10.5 [untested])
  28. pc_fields="$pc_fields uc_mcontext->ss.srr0" # OS X (ppc, ppc64 [untested])
  29. pc_fields="$pc_fields uc_mcontext->__ss.__srr0" # OS X (>=10.5 [untested])
  30. pc_field_found=false
  31. for pc_field in $pc_fields; do
  32. if ! $pc_field_found; then
  33. if test "x$ac_cv_header_sys_ucontext_h" = xyes; then
  34. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  35. #include <sys/ucontext.h>],
  36. [ucontext_t u; return u.$pc_field == 0;],
  37. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  38. How to access the PC from a struct ucontext)
  39. AC_MSG_RESULT([$pc_field])
  40. pc_field_found=true)
  41. else
  42. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  43. #include <ucontext.h>],
  44. [ucontext_t u; return u.$pc_field == 0;],
  45. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  46. How to access the PC from a struct ucontext)
  47. AC_MSG_RESULT([$pc_field])
  48. pc_field_found=true)
  49. fi
  50. fi
  51. done
  52. if ! $pc_field_found; then
  53. pc_fields=" sc_eip" # OpenBSD (i386)
  54. pc_fields="$pc_fields sc_rip" # OpenBSD (x86_64)
  55. for pc_field in $pc_fields; do
  56. if ! $pc_field_found; then
  57. AC_TRY_COMPILE([#include <signal.h>],
  58. [ucontext_t u; return u.$pc_field == 0;],
  59. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  60. How to access the PC from a struct ucontext)
  61. AC_MSG_RESULT([$pc_field])
  62. pc_field_found=true)
  63. fi
  64. done
  65. fi
  66. if ! $pc_field_found; then
  67. [$1]
  68. fi])