mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
1803762e3f
When compiling on macOS (at least in version 10.12) the TCC compiler failed to compile libtcc1.a. Three problems were solved: - The predefined macro "__APPLE__" is now available, as it is tested in the libc darwin header files - the libtcc1 Makefile defined _ANSI_SOURCE, although it used signals - stdargs.h defined va_list differently from the darwin libc. If the darwin standard library was included BEFORE stdargs this caused problems. - the darwin libc generated a warning if GCC < 4 was used - additional defines are predefined now to make darwin libc headers compile.
38 lines
911 B
C
38 lines
911 B
C
/* ------------------------------------------------------------- */
|
|
/* function to get a stack backtrace on demand with a message */
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
|
|
int (*__rt_error)(void*, void*, const char *, va_list);
|
|
|
|
#ifdef _WIN32
|
|
# define DLL_EXPORT __declspec(dllexport)
|
|
#else
|
|
# define DLL_EXPORT
|
|
#endif
|
|
|
|
DLL_EXPORT int tcc_backtrace(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
int ret;
|
|
|
|
if (__rt_error) {
|
|
void *fp = __builtin_frame_address(1);
|
|
void *ip = __builtin_return_address(0);
|
|
va_start(ap, fmt);
|
|
ret = __rt_error(fp, ip, fmt, ap);
|
|
va_end(ap);
|
|
} else {
|
|
const char *p;
|
|
if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0])))
|
|
fmt = p + 1;
|
|
va_start(ap, fmt);
|
|
ret = vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, "\n"), fflush(stderr);
|
|
}
|
|
return ret;
|
|
}
|