[dbg_unix] Make sure to use execinfo.h only when available, fixes #1

This commit is contained in:
Lorenzo Cogotti 2023-06-23 09:26:10 +02:00
parent b57316654b
commit 25707a25d8
1 changed files with 9 additions and 5 deletions

View File

@ -18,8 +18,12 @@
#include <string.h>
#include <unistd.h>
#ifdef __GNUC__
#ifdef __has_include
#if __has_include(<execinfo.h>)
#include <execinfo.h>
#define EXECINFO_AVAILABLE 1
#endif
#endif
Boolean Sys_IsDebuggerPresent(void)
@ -63,7 +67,7 @@ size_t Sys_GetBacktrace(void **dest, size_t n)
USED(dest);
USED(n);
#ifdef __GNUC__
#ifdef EXECINFO_AVAILABLE
if (n > (size_t) (INT_MAX - 1))
n = INT_MAX - 1;
@ -84,7 +88,7 @@ size_t Sys_GetBacktrace(void **dest, size_t n)
void *Sys_GetCaller(void)
{
#ifdef __GNUC__
#ifdef EXECINFO_AVAILABLE
void *trace[3]; // ourselves, caller, caller's caller
int n = backtrace(trace, ARRAY_SIZE(trace));
@ -100,7 +104,7 @@ char *Sys_GetSymbolName(void *sym)
{
USED(sym);
#ifdef __GNUC__
#ifdef EXECINFO_AVAILABLE
static THREAD_LOCAL char buf[128];
char **names = backtrace_symbols(&sym, 1);
@ -132,7 +136,7 @@ void Sys_DumpBacktrace(ConHn hn, void **trace, size_t n)
USED(trace);
USED(n);
#ifdef __GNUC__
#ifdef EXECINFO_AVAILABLE
backtrace_symbols_fd(trace, MIN(n, (size_t) INT_MAX), hn);
#endif
}