pw_assert_basic: Flush and abort rather than exit

Debuggers break on abort(), but not exit(1). Abort doesn't allow stdout
and stderr to flush, so manually flush them first.

Change-Id: I8510478fe5ebdb27c09519e9e345ec9b3702203d
Reviewed-by: Keir Mierle <>
Commit-Queue: Auto-Submit <>
Pigweed-Auto-Submit: Wyatt Hepler <>
diff --git a/pw_assert_basic/ b/pw_assert_basic/
index 29d44e3..24262d4 100644
--- a/pw_assert_basic/
+++ b/pw_assert_basic/
@@ -17,6 +17,7 @@
 //#include "pw_log/log.h"
+#include <cstdio>
 #include <cstring>
 #include "pw_assert/options.h"
@@ -138,16 +139,11 @@
   // now this is acceptable since no one is using this basic backend.
-      // Using exit() instead of abort() here because exit() allows for the
-      // destructors for the stdout buffers to be called. This addresses an
-      // issue that occurs when Bazel's execution wrapper binds stdout. This
-      // results in stdout going from a synchronized to a buffered file
-      // descriptor. In this case when abort() is called in a Bazel test the
-      // program exits before the stdout buffer can be synchronized with Bazel's
-      // execution wrapper, the resulting output from a test is an empty output
-      // buffer. Using exit() here allows the destructors to synchronized the
-      // stdout buffer before exiting.
-      exit(1);
+      // abort() doesn't flush stderr/stdout, so manually flush them before
+      // aborting. abort() is preferred to exit(1) because debuggers catch it.
+      std::fflush(stderr);
+      std::fflush(stdout);
+      std::abort();
     } else {
       WriteLine(MAGENTA "  HANG TIME" RESET);