build: check for 'backtrace' presence in meson
This commit is contained in:
parent
416f1650cd
commit
d4a2a28bd5
3 changed files with 7 additions and 25 deletions
|
|
@ -47,6 +47,7 @@
|
||||||
#define WITH_SWIFT_DEMANGLER @WITH_SWIFT_DEMANGLER@
|
#define WITH_SWIFT_DEMANGLER @WITH_SWIFT_DEMANGLER@
|
||||||
#define HAVE_COPYFILE @HAVE_COPYFILE@
|
#define HAVE_COPYFILE @HAVE_COPYFILE@
|
||||||
#define HAVE_COPY_FILE_RANGE @HAVE_COPY_FILE_RANGE@
|
#define HAVE_COPY_FILE_RANGE @HAVE_COPY_FILE_RANGE@
|
||||||
|
#define HAVE_BACKTRACE @HAVE_BACKTRACE@
|
||||||
|
|
||||||
#define HAVE_HEADER_LINUX_ASHMEM_H @HAVE_HEADER_LINUX_ASHMEM_H@
|
#define HAVE_HEADER_LINUX_ASHMEM_H @HAVE_HEADER_LINUX_ASHMEM_H@
|
||||||
#define HAVE_HEADER_SYS_SHM_H @HAVE_HEADER_SYS_SHM_H@
|
#define HAVE_HEADER_SYS_SHM_H @HAVE_HEADER_SYS_SHM_H@
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,10 @@
|
||||||
#if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#if __NetBSD_Prereq__(7, 0, 0)
|
|
||||||
#define NETBSD_WITH_BACKTRACE
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#if __FreeBSD_version >= 1000000
|
|
||||||
#define FREEBSD_WITH_BACKTRACE
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__DragonFly__)
|
#if defined(__DragonFly__)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
@ -37,8 +31,7 @@
|
||||||
|
|
||||||
static char **env = NULL;
|
static char **env = NULL;
|
||||||
|
|
||||||
#if (__linux__ && __GNU_LIBRARY__) || defined(NETBSD_WITH_BACKTRACE) || \
|
#if HAVE_BACKTRACE
|
||||||
defined(FREEBSD_WITH_BACKTRACE) || __DragonFly__ || __sun || __HAIKU__
|
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
|
@ -266,21 +259,8 @@ RZ_API char *rz_sys_cmd_strf(const char *fmt, ...) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __MAC_10_7
|
|
||||||
#define APPLE_WITH_BACKTRACE 1
|
|
||||||
#endif
|
|
||||||
#ifdef __IPHONE_4_0
|
|
||||||
#define APPLE_WITH_BACKTRACE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (__linux__ && __GNU_LIBRARY__) || (__APPLE__ && APPLE_WITH_BACKTRACE) || \
|
|
||||||
defined(NETBSD_WITH_BACKTRACE) || defined(FREEBSD_WITH_BACKTRACE) || \
|
|
||||||
__DragonFly__ || __sun || __HAIKU__
|
|
||||||
#define HAVE_BACKTRACE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RZ_API void rz_sys_backtrace(void) {
|
RZ_API void rz_sys_backtrace(void) {
|
||||||
#ifdef HAVE_BACKTRACE
|
#if HAVE_BACKTRACE
|
||||||
void *array[10];
|
void *array[10];
|
||||||
size_t size = backtrace(array, 10);
|
size_t size = backtrace(array, 10);
|
||||||
eprintf("Backtrace %zd stack frames.\n", size);
|
eprintf("Backtrace %zd stack frames.\n", size);
|
||||||
|
|
@ -291,7 +271,7 @@ RZ_API void rz_sys_backtrace(void) {
|
||||||
void *saved_fp = __builtin_frame_address(1);
|
void *saved_fp = __builtin_frame_address(1);
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
|
|
||||||
printf("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
|
eprintf("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
|
||||||
fp = saved_fp;
|
fp = saved_fp;
|
||||||
while (fp) {
|
while (fp) {
|
||||||
saved_fp = *fp;
|
saved_fp = *fp;
|
||||||
|
|
@ -300,7 +280,7 @@ RZ_API void rz_sys_backtrace(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
saved_pc = *(fp + 2);
|
saved_pc = *(fp + 2);
|
||||||
printf("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
|
eprintf("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
@ -438,7 +418,7 @@ RZ_API int rz_sys_crash_handler(const char *cmd) {
|
||||||
if (!checkcmd(cmd)) {
|
if (!checkcmd(cmd)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_BACKTRACE
|
#if HAVE_BACKTRACE
|
||||||
void *array[1];
|
void *array[1];
|
||||||
/* call this outside of the signal handler to init it safely */
|
/* call this outside of the signal handler to init it safely */
|
||||||
backtrace(array, 1);
|
backtrace(array, 1);
|
||||||
|
|
|
||||||
|
|
@ -485,6 +485,7 @@ foreach item : [
|
||||||
['pipe2', '#define _GNU_SOURCE\n#include <fcntl.h>\n#include <unistd.h>', []],
|
['pipe2', '#define _GNU_SOURCE\n#include <fcntl.h>\n#include <unistd.h>', []],
|
||||||
# copy_file_range for now disable on freebsd as it s not reliable even for small chunks
|
# copy_file_range for now disable on freebsd as it s not reliable even for small chunks
|
||||||
['copy_file_range', '#ifdef __linux__\n#define _GNU_SOURCE\n#include <unistd.h>\n#endif', []],
|
['copy_file_range', '#ifdef __linux__\n#define _GNU_SOURCE\n#include <unistd.h>\n#endif', []],
|
||||||
|
['backtrace', '', []],
|
||||||
]
|
]
|
||||||
func = item[0]
|
func = item[0]
|
||||||
ok = cc.has_function(func, prefix: item[1], dependencies: item[2])
|
ok = cc.has_function(func, prefix: item[1], dependencies: item[2])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue