aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2018-05-08 20:00:52 +0000
committerfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2018-05-08 20:00:52 +0000
commit01836a386e96e00539a012065007a165eff88da2 (patch)
tree07c76ba2eaaa14bf1de6f1b70323e9d5f49d4900
parent19bdc21a60a0694ffc217bc7c0066039b9a1a1fd (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260054 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog4
-rw-r--r--libstdc++-v3/src/c++11/debug.cc27
2 files changed, 31 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index bf1e80333be..25430fd9e51 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,9 @@
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,
diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 89d387cdea5..ede6b703aae 100644
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -40,6 +40,10 @@
#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;
@@ -1043,6 +1047,29 @@ namespace __gnu_debug
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