From 458738d52a9068a140155061757c7fa3bc27cc45 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Thu, 18 Jul 2024 22:36:57 +0800
Subject: [PATCH] gmt_common_sighandler.c: fix ucontext for Apple

---
 src/gmt_common_sighandler.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git src/gmt_common_sighandler.c src/gmt_common_sighandler.c
index b6eaf7c95..f21d0ae58 100644
--- src/gmt_common_sighandler.c
+++ src/gmt_common_sighandler.c
@@ -80,13 +80,19 @@ GMT_LOCAL void backtrace_symbols_fd(void *const *buffer, int size, int fd) {
 # if __DARWIN_UNIX03
 #  ifdef __x86_64__
 #   define UC_IP(uc) ((void *) (uc)->uc_mcontext->__ss.__rip)
-#  elif __arm64__	/* Apple Silicon, e.g. M1 */
+#  elif defined(__arm64__)	/* Apple Silicon, e.g. M1 */
 #   define UC_IP(uc) ((void *) (uc)->uc_mcontext->__ss.__pc)
+#  elif defined(__POWERPC__)	/* Both ppc and ppc64 */
+#   define UC_IP(uc) ((void *) (uc)->uc_mcontext->__ss.__srr0)
 #  else
 #   define UC_IP(uc) ((void *) (uc)->uc_mcontext->__ss.__eip)
 #  endif
 # else
-#  define UC_IP(uc) ((void *) (uc)->uc_mcontext->ss.eip)
+#  ifdef __ppc__
+#   define UC_IP(uc) ((void *) (uc)->uc_mcontext->ss.srr0)
+#  else
+#   define UC_IP(uc) ((void *) (uc)->uc_mcontext->ss.eip)
+#  endif
 # endif
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 # ifdef __x86_64__
