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-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/49840
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
diff --git a/pw_assert_basic/basic_handler.cc b/pw_assert_basic/basic_handler.cc
index 29d44e3..24262d4 100644
--- a/pw_assert_basic/basic_handler.cc
+++ b/pw_assert_basic/basic_handler.cc
@@ -17,6 +17,7 @@
//#define PW_LOG_MODULE_NAME "ASRT"
//#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.
if (!PW_ASSERT_BASIC_DISABLE_NORETURN) {
if (PW_ASSERT_BASIC_ABORT) {
- // 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("");
WriteLine(MAGENTA " HANG TIME" RESET);