+2024-05-12 Bruno Haible <bruno@clisp.org>
+
+ execinfo tests: Strengthen tests.
+ * tests/test-execinfo.c (test_backtrace): Add an argument. Check the
+ return value of backtrace(). Check that backtrace_symbols_fd is defined.
+ Check the return value of backtrace_symbols().
+ (main): Test also the case of a short buffer.
+ * modules/execinfo-tests (Makefile.am): Verify that LIB_EXECINFO is
+ defined.
+
2024-05-11 Paul Eggert <eggert@cs.ucla.edu>
stdbit: don’t assume -DHAVE_CONFIG_H
#include "macros.h"
static void
-test_backtrace (void)
+test_backtrace (int pass)
{
void *buffer[10];
- char **symbols;
+ int max_size;
int size;
+ char **symbols;
+
+ max_size = (pass == 0 ? SIZEOF (buffer) : 1);
+ size = backtrace (buffer, max_size);
+ ASSERT (size >= 0 && size <= max_size);
+
+ /* Print the backtrace to a file descriptor. */
+ backtrace_symbols_fd (buffer, size, 1);
+ printf ("\n");
- size = backtrace (buffer, SIZEOF (buffer));
symbols = backtrace_symbols (buffer, size);
+ if (size > 0)
+ /* We have enough memory available. */
+ ASSERT (symbols != NULL);
/* Print the backtrace if possible. */
- if (0 < size && symbols != NULL)
+ if (symbols != NULL)
{
for (int i = 0; i < size; ++i)
printf ("%s\n", symbols[i]);
int
main (void)
{
- test_backtrace ();
+ printf ("Full stack trace:\n"); fflush (stdout);
+ test_backtrace (0);
+ printf ("\nTruncated stack trace:\n"); fflush (stdout);
+ test_backtrace (1);
return 0;
}