add clang
This commit is contained in:
parent
4715742aa8
commit
9a4b261179
890 changed files with 229323 additions and 20 deletions
37
05/tcc-final/lib/bt-log.c
Normal file
37
05/tcc-final/lib/bt-log.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* ------------------------------------------------------------- */
|
||||
/* function to get a stack backtrace on demand with a message */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue