>From 036cabf60010269a92e82272c52fbbd37c8fe59f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 18 May 2024 22:53:28 +0200 Subject: [PATCH 2/2] abort-debug: Integrate with CONTINUE_AFTER_ASSERT. * lib/stdlib.in.h (_gl_pre_abort): New declaration. * lib/abort-debug.c (_gl_pre_abort): New function. * tests/macros.h (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT is 1 and the assertion fails, invoke _gl_pre_abort. --- ChangeLog | 8 ++++++++ lib/abort-debug.c | 13 +++++++++++++ lib/stdlib.in.h | 8 ++++++++ tests/macros.h | 10 ++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c119e32014..7de9b90f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-18 Bruno Haible + + abort-debug: Integrate with CONTINUE_AFTER_ASSERT. + * lib/stdlib.in.h (_gl_pre_abort): New declaration. + * lib/abort-debug.c (_gl_pre_abort): New function. + * tests/macros.h (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT + is 1 and the assertion fails, invoke _gl_pre_abort. + 2024-05-18 Bruno Haible tests: Support showing all assertion failures, not just the first one. diff --git a/lib/abort-debug.c b/lib/abort-debug.c index 2ca8f81169..ca4dbc7291 100644 --- a/lib/abort-debug.c +++ b/lib/abort-debug.c @@ -55,6 +55,19 @@ print_stack_trace (FILE *stream) #endif +void +_gl_pre_abort (void) +{ +#if HAVE_EXECINFO_H + print_stack_trace (stderr); +#endif +} + +/* rpl_abort (); + is equivalent to + _gl_pre_abort (); + original abort (); // i.e. raise (SIGABRT); + */ void rpl_abort (void) { diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 1888d3ee31..ef9fde30eb 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -231,6 +231,14 @@ _GL_CXXALIAS_SYS (abort, void, (void)); _GL_CXXALIASWARN (abort); # endif #endif +#if @GNULIB_ABORT_DEBUG@ && @REPLACE_ABORT@ +_GL_EXTERN_C void _gl_pre_abort (void); +#else +# if !GNULIB_defined_gl_pre_abort +# define _gl_pre_abort() /* nothing */ +# define GNULIB_defined_gl_pre_abort 1 +# endif +#endif #if @GNULIB_FREE_POSIX@ diff --git a/tests/macros.h b/tests/macros.h index d60de6fd3e..144905e031 100644 --- a/tests/macros.h +++ b/tests/macros.h @@ -81,7 +81,10 @@ int volatile test_exit_status = EXIT_SUCCESS; __FILE__, __LINE__, #expr); \ fflush (ASSERT_STREAM); \ if (CONTINUE_AFTER_ASSERT) \ - test_exit_status = EXIT_FAILURE; \ + { \ + _gl_pre_abort (); \ + test_exit_status = EXIT_FAILURE; \ + } \ else \ abort (); \ } \ @@ -102,7 +105,10 @@ int volatile test_exit_status = EXIT_SUCCESS; WRITE_TO_STDERR (#expr); \ WRITE_TO_STDERR ("' failed\n"); \ if (CONTINUE_AFTER_ASSERT) \ - test_exit_status = EXIT_FAILURE; \ + { \ + _gl_pre_abort (); \ + test_exit_status = EXIT_FAILURE; \ + } \ else \ abort (); \ } \ -- 2.34.1