[tor-commits] [tor/master] log/util_bug: Make IF_BUG_ONCE() support ALL_BUGS_ARE_FATAL

nickm at torproject.org nickm at torproject.org
Wed Apr 29 23:23:42 UTC 2020


commit 6c458d2d6eaed20e48b1e66bebd1ec0466838e33
Author: teor <teor at torproject.org>
Date:   Wed Apr 15 17:45:29 2020 +1000

    log/util_bug: Make IF_BUG_ONCE() support ALL_BUGS_ARE_FATAL
    
    ... 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       |  5 +++++
 src/lib/log/util_bug.h | 23 ++++++++++++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/changes/bug33917 b/changes/bug33917
new file mode 100644
index 000000000..6a8daa9e2
--- /dev/null
+++ b/changes/bug33917
@@ -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.
diff --git a/src/lib/log/util_bug.h b/src/lib/log/util_bug.h
index ae3d125a0..6b27b36f0 100644
--- a/src/lib/log/util_bug.h
+++ b/src/lib/log/util_bug.h
@@ -142,6 +142,8 @@
 #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))
@@ -154,6 +156,9 @@
    (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))
@@ -164,6 +169,9 @@
 #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);   \
@@ -200,7 +208,6 @@
   (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__
@@ -232,7 +239,7 @@
 #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.
  */
 
@@ -240,9 +247,15 @@
   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,





More information about the tor-commits mailing list