Skip to content

Commit 947a80e

Browse files
committed
gh-127604: Allow faulthandler to dumpC stack on MacOS
1 parent dc3e963 commit 947a80e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Python/traceback.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@
1818
#ifdef HAVE_UNISTD_H
1919
# include <unistd.h> // lseek()
2020
#endif
21-
#if defined(HAVE_EXECINFO_H) && defined(HAVE_DLFCN_H) && defined(HAVE_LINK_H)
21+
22+
#if (defined(HAVE_EXECINFO_H) && defined(HAVE_DLFCN_H) && defined(HAVE_LINK_H))
23+
#define _PY_HAS_BACKTRACE_HEADERS 1
24+
#endif
25+
26+
#if (defined(__APPLE__) && defined(HAVE_EXECINFO_H) && defined(HAVE_DLFCN_H))
27+
#define _PY_HAS_BACKTRACE_HEADERS 1
28+
#endif
29+
30+
#ifdef _PY_HAS_BACKTRACE_HEADERS
2231
# include <execinfo.h> // backtrace(), backtrace_symbols()
2332
# include <dlfcn.h> // dladdr1()
24-
# include <link.h> // struct DL_info
25-
# if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_DLADDR1)
33+
#ifdef HAVE_LINK_H
34+
# include <link.h> // struct DL_info
35+
#endif
36+
#if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && (defined(__APPLE__) || defined(HAVE_DLADDR1))
2637
# define CAN_C_BACKTRACE
2738
# endif
2839
#endif
@@ -1193,6 +1204,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
11931204
VLA(int, status, size);
11941205
/* Fill in the information we can get from dladdr() */
11951206
for (Py_ssize_t i = 0; i < size; ++i) {
1207+
#ifdef __APPLE__
1208+
status[i] = dladdr(array[i], &info[i]);
1209+
#else
11961210
struct link_map *map;
11971211
status[i] = dladdr1(array[i], &info[i], (void **)&map, RTLD_DL_LINKMAP);
11981212
if (status[i] != 0
@@ -1204,6 +1218,7 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
12041218
something we want to subtract out */
12051219
info[i].dli_fbase = (void *) map->l_addr;
12061220
}
1221+
#endif
12071222
}
12081223
for (Py_ssize_t i = 0; i < size; ++i) {
12091224
if (status[i] == 0

0 commit comments

Comments
 (0)