]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
log/util_bug: Make IF_BUG_ONCE() support ALL_BUGS_ARE_FATAL
authorteor <teor@torproject.org>
Wed, 15 Apr 2020 07:45:29 +0000 (17:45 +1000)
committerteor <teor@torproject.org>
Wed, 29 Apr 2020 12:43:09 +0000 (22:43 +1000)
... and DISABLE_ASSERTS_IN_UNIT_TESTS.

Make all of tor's assertion macros support the ALL_BUGS_ARE_FATAL and
DISABLE_ASSERTS_IN_UNIT_TESTS debugging modes.

Implements these modes for IF_BUG_ONCE(). (It used to log a non-fatal
warning, regardless of the debugging mode.)

Fixes bug 33917; bugfix on 0.2.9.1-alpha.

changes/bug33917 [new file with mode: 0644]
src/lib/log/util_bug.h

diff --git a/changes/bug33917 b/changes/bug33917
new file mode 100644 (file)
index 0000000..6a8daa9
--- /dev/null
@@ -0,0 +1,5 @@
+  o Minor bugfixes (logging, testing):
+    - Make all of tor's assertion macros support the ALL_BUGS_ARE_FATAL and
+      DISABLE_ASSERTS_IN_UNIT_TESTS debugging modes. Implements these modes
+      for IF_BUG_ONCE(). (It used to log a non-fatal warning, regardless of
+      the debugging mode.) Fixes bug 33917; bugfix on 0.2.9.1-alpha.
index ae3d125a080a9a834e748a3b51099ab3dcdf5dd4..6b27b36f0345cefff6a84ee1186a99935b54a135 100644 (file)
 #define ALL_BUGS_ARE_FATAL
 #endif
 
+/** Define ALL_BUGS_ARE_FATAL if you want Tor to crash when any problem comes
+ * up, so you can get a coredump and track things down. */
 #ifdef ALL_BUGS_ARE_FATAL
 #define tor_assert_nonfatal_unreached() tor_assert(0)
 #define tor_assert_nonfatal(cond) tor_assert((cond))
    (tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,"!("#cond")",NULL), \
     tor_abort_(), 1)                                                    \
    : 0)
+#ifndef COCCI
+#define IF_BUG_ONCE(cond) if (BUG(cond))
+#endif
 #elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
 #define tor_assert_nonfatal_unreached() STMT_NIL
 #define tor_assert_nonfatal(cond) ((void)(cond))
 #define tor_assert_nonfatal_unreached_once() STMT_NIL
 #define tor_assert_nonfatal_once(cond) ((void)(cond))
 #define BUG(cond) (ASSERT_PREDICT_UNLIKELY_(cond) ? 1 : 0)
+#ifndef COCCI
+#define IF_BUG_ONCE(cond) if (BUG(cond))
+#endif
 #else /* Normal case, !ALL_BUGS_ARE_FATAL, !DISABLE_ASSERTS_IN_UNIT_TESTS */
 #define tor_assert_nonfatal_unreached() STMT_BEGIN                      \
   tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, NULL, 0, NULL);   \
   (ASSERT_PREDICT_UNLIKELY_(cond) ?                                     \
   (tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,"!("#cond")",0,NULL),1) \
    : 0)
-#endif /* defined(ALL_BUGS_ARE_FATAL) || ... */
 
 #ifndef COCCI
 #ifdef __GNUC__
 #define IF_BUG_ONCE_VARNAME__(a)              \
   IF_BUG_ONCE_VARNAME_(a)
 
-/** This macro behaves as 'if (bug(x))', except that it only logs its
+/** This macro behaves as 'if (BUG(x))', except that it only logs its
  * warning once, no matter how many times it triggers.
  */
 
   IF_BUG_ONCE__(ASSERT_PREDICT_UNLIKELY_(cond),                 \
                 IF_BUG_ONCE_VARNAME__(__LINE__))
 
-/** Define this if you want Tor to crash when any problem comes up,
- * so you can get a coredump and track things down. */
-// #define tor_fragile_assert() tor_assert_unreached(0)
+#endif /* defined(ALL_BUGS_ARE_FATAL) || ... */
+
+/** In older code, we used tor_fragile_assert() to mark optional failure
+ * points. At these points, we could make some debug builds fail.
+ * (But release builds would continue.)
+ *
+ * To get the same behaviour in recent tor versions, define
+ * ALL_BUGS_ARE_FATAL, and use any non-fatal assertion or *BUG() macro.
+ */
 #define tor_fragile_assert() tor_assert_nonfatal_unreached_once()
 
 void tor_assertion_failed_(const char *fname, unsigned int line,