2018-05-08 François Dumont <fdumont@gcc.gnu.org>
+ * src/c++11/debug.cc [_GLIBCXX_HAVE_EXECINFO_H]: Include execinfo.h.
+ [_GLIBCXX_HAVE_EXECINFO_H](_Error_formatter::_M_error): Render
+ backtrace.
+
* include/debug/macros.h (__glibcxx_check_valid_range_at): New.
* include/debug/functions.h (__check_valid_range): Use latter.
* include/debug/macros.h (__glibcxx_check_valid_constructor_range): New,
#include <cxxabi.h> // for __cxa_demangle
+#if defined _GLIBCXX_HAVE_EXECINFO_H
+# include <execinfo.h> // for backtrace
+#endif
+
#include "mutex_pool.h"
using namespace std;
print_literal(ctx, "\n");
}
+#if defined _GLIBCXX_HAVE_EXECINFO_H
+ {
+ void* stack[32];
+ int nb = backtrace(stack, 32);
+
+ // Note that we skip current method symbol.
+ if (nb > 1)
+ {
+ print_literal(ctx, "Backtrace:\n");
+ auto symbols = backtrace_symbols(stack, nb);
+ for (int i = 1; i < nb; ++i)
+ {
+ print_word(ctx, symbols[i]);
+ print_literal(ctx, "\n");
+ }
+
+ free(symbols);
+ ctx._M_first_line = true;
+ print_literal(ctx, "\n");
+ }
+ }
+#endif
+
print_literal(ctx, "Error: ");
// Print the error message