27static void (*failed_assertion_cb)(void) = NULL;
28static int n_bugs_to_capture = 0;
30#define capturing_bugs() (bug_messages != NULL && n_bugs_to_capture)
32tor_capture_bugs_(
int n)
34 tor_end_capture_bugs_();
36 n_bugs_to_capture = n;
39tor_end_capture_bugs_(
void)
41 n_bugs_to_capture = 0;
45 smartlist_free(bug_messages);
49tor_get_captured_bug_log_(
void)
54add_captured_bug(
const char *s)
64tor_set_failed_assertion_callback(
void (*fn)(
void))
66 failed_assertion_cb = fn;
69#define capturing_bugs() (0)
70#define add_captured_bug(s) do { } while (0)
76 const char *func,
const char *expr,
84#pragma clang diagnostic push
85#pragma clang diagnostic ignored "-Wformat-nonliteral"
93#pragma clang diagnostic pop
96 log_err(
LD_BUG,
"%s:%u: %s: Assertion %s failed; aborting.",
97 fname, line, func, expr);
98 tor_asprintf(&buf,
"Assertion %s failed in %s at %s:%u: %s",
99 expr, func, fname, line, extra ? extra :
"");
108tor_bug_init_counter(
void)
121tor_bug_get_count(
void)
129 const char *func,
const char *expr,
130 int once,
const char *fmt, ...)
133 const char *once_str = once ?
134 " (Future instances of this warning will be silenced.)":
"";
141 if (capturing_bugs()) {
142 add_captured_bug(
"This line should not have been reached.");
145 log_warn(
LD_BUG,
"%s:%u: %s: This line should not have been reached.%s",
146 fname, line, func, once_str);
148 "Line unexpectedly reached at %s at %s:%u",
151 if (capturing_bugs()) {
152 add_captured_bug(expr);
160#pragma clang diagnostic push
161#pragma clang diagnostic ignored "-Wformat-nonliteral"
169#pragma clang diagnostic pop
172 log_warn(
LD_BUG,
"%s:%u: %s: Non-fatal assertion %s failed.%s",
173 fname, line, func, expr, once_str);
174 tor_asprintf(&buf,
"Non-fatal assertion %s failed in %s at %s:%u%s%s",
175 expr, func, fname, line, fmt ?
" : " :
"",
183 if (failed_assertion_cb) {
184 failed_assertion_cb();
212tor_fix_source_file(
const char *fname)
214 const char *cp1, *cp2, *r;
215 cp1 = strrchr(fname,
'/');
216 cp2 = strrchr(fname,
'\\');
218 r = (cp1<cp2)?(cp2+1):(cp1+1);
void atomic_counter_init(atomic_counter_t *counter)
void atomic_counter_add(atomic_counter_t *counter, size_t add)
size_t atomic_counter_get(atomic_counter_t *counter)
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,...)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
smartlist_t * smartlist_new(void)
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_bug_increment_count_(void)
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.