31#if defined(FREECIV_DEBUG) && defined(HAVE_BACKTRACE) && !defined(FREECIV_TESTMATIC)
32#define BACKTRACE_ACTIVE 1
35#ifdef BACKTRACE_ACTIVE
40#define LOG_BACKTRACE LOG_NORMAL
42#define MAX_NUM_FRAMES 256
46static void write_backtrace_line(
enum log_level level,
bool print_from_where,
47 const char *where,
const char *msg);
48static void backtrace_log(
enum log_level level,
bool print_from_where,
49 const char *where,
const char *msg);
57#ifdef BACKTRACE_ACTIVE
67#ifdef BACKTRACE_ACTIVE
72 if (active != backtrace_log) {
76 log_error(
"Backtrace log (pre)callback cannot be removed");
81#ifdef BACKTRACE_ACTIVE
85static void write_backtrace_line(
enum log_level level,
bool print_from_where,
86 const char *where,
const char *msg)
90 if (previous != NULL) {
91 previous(
level, print_from_where, where, msg);
98static void backtrace_log(
enum log_level level,
bool print_from_where,
99 const char *where,
const char *msg)
101 if (previous != NULL) {
103 previous(
level, print_from_where, where, msg);
118#ifdef BACKTRACE_ACTIVE
119 void *buffer[MAX_NUM_FRAMES];
123 frames = backtrace(buffer,
ARRAY_SIZE(buffer));
124 names = backtrace_symbols(buffer, frames);
127 write_backtrace_line(
level,
FALSE, NULL,
"No backtrace");
131 write_backtrace_line(
level,
FALSE, NULL,
"Backtrace:");
133 for (i = 0; i <
MIN(frames, MAX_NUM_FRAMES); i++) {
136 fc_snprintf(linestr,
sizeof(linestr),
"%5d: %s", i, names[i]);
138 write_backtrace_line(
level,
FALSE, NULL, linestr);
void backtrace_deinit(void)
void backtrace_init(void)
void backtrace_print(enum log_level level)
log_pre_callback_fn log_set_pre_callback(log_pre_callback_fn precallback)
void(* log_pre_callback_fn)(enum log_level, bool print_from_where, const char *where, const char *msg)
#define log_error(message,...)
struct setting_list * level[OLEVELS_NUM]
int fc_snprintf(char *str, size_t n, const char *format,...)