26 static void (*failed_assertion_cb)(void) = NULL;
27 static int n_bugs_to_capture = 0;
29 #define capturing_bugs() (bug_messages != NULL && n_bugs_to_capture)
31 tor_capture_bugs_(
int n)
33 tor_end_capture_bugs_();
35 n_bugs_to_capture = n;
38 tor_end_capture_bugs_(
void)
40 n_bugs_to_capture = 0;
44 smartlist_free(bug_messages);
48 tor_get_captured_bug_log_(
void)
53 add_captured_bug(
const char *s)
63 tor_set_failed_assertion_callback(
void (*fn)(
void))
65 failed_assertion_cb = fn;
68 #define capturing_bugs() (0)
69 #define add_captured_bug(s) do { } while (0)
75 const char *func,
const char *expr,
83 #pragma clang diagnostic push
84 #pragma clang diagnostic ignored "-Wformat-nonliteral"
92 #pragma clang diagnostic pop
95 log_err(
LD_BUG,
"%s:%u: %s: Assertion %s failed; aborting.",
96 fname, line, func, expr);
97 tor_asprintf(&buf,
"Assertion %s failed in %s at %s:%u: %s",
98 expr, func, fname, line, extra ? extra :
"");
107 const char *func,
const char *expr,
108 int once,
const char *fmt, ...)
111 const char *once_str = once ?
112 " (Future instances of this warning will be silenced.)":
"";
114 if (capturing_bugs()) {
115 add_captured_bug(
"This line should not have been reached.");
118 log_warn(
LD_BUG,
"%s:%u: %s: This line should not have been reached.%s",
119 fname, line, func, once_str);
121 "Line unexpectedly reached at %s at %s:%u",
124 if (capturing_bugs()) {
125 add_captured_bug(expr);
133 #pragma clang diagnostic push
134 #pragma clang diagnostic ignored "-Wformat-nonliteral"
142 #pragma clang diagnostic pop
145 log_warn(
LD_BUG,
"%s:%u: %s: Non-fatal assertion %s failed.%s",
146 fname, line, func, expr, once_str);
147 tor_asprintf(&buf,
"Non-fatal assertion %s failed in %s at %s:%u%s%s",
148 expr, func, fname, line, fmt ?
" : " :
"",
155 #ifdef TOR_UNIT_TESTS
156 if (failed_assertion_cb) {
157 failed_assertion_cb();
185 tor_fix_source_file(
const char *fname)
187 const char *cp1, *cp2, *r;
188 cp1 = strrchr(fname,
'/');
189 cp2 = strrchr(fname,
'\\');
191 r = (cp1<cp2)?(cp2+1):(cp1+1);
void logs_flush_sigsafe(void)
Headers for util_malloc.c.
int tor_vasprintf(char **strp, const char *fmt, va_list args)
int tor_asprintf(char **strp, const char *fmt,...)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
Top-level declarations for the smartlist_t dynamic array type.
Macros for iterating over the elements of a smartlist_t.
#define SMARTLIST_FOREACH(sl, type, var, cmd)
void tor_raw_abort_(void)
void tor_bug_occurred_(const char *fname, unsigned int line, const char *func, const char *expr, int once, const char *fmt,...)
void tor_assertion_failed_(const char *fname, unsigned int line, const char *func, const char *expr, const char *fmt,...)
Macros to manage assertions, fatal and non-fatal.