tool_chain/cxx: use '__cxa_demangle()' for exception names

Fixes #1976
This commit is contained in:
Christian Prochaska 2016-05-18 14:47:36 +02:00 committed by Christian Helmuth
parent 2a92f4bf55
commit 44648bb5c7
4 changed files with 101 additions and 2 deletions

View File

@ -20,6 +20,11 @@
extern "C" char __eh_frame_start__[]; /* from linker script */
extern "C" void __register_frame (const void *begin); /* from libgcc_eh */
extern "C" char *__cxa_demangle(const char *mangled_name,
char *output_buffer,
size_t *length,
int *status);
extern "C" void free(void *ptr);
/*
* This symbol is overwritten by Genode's dynamic linker (ld.lib.so).
@ -48,7 +53,14 @@ void terminate_handler()
{
std::type_info *t = __cxxabiv1::__cxa_current_exception_type();
if (t)
if (!t)
return;
char *demangled_name = __cxa_demangle(t->name(), nullptr, nullptr, nullptr);
if (demangled_name) {
PERR("Uncaught exception of type '%s'", demangled_name);
free(demangled_name);
} else
PERR("Uncaught exception of type '%s' (use 'c++filt -t' to demangle)",
t->name());
}

View File

@ -1 +1 @@
2a59b9a759881adf43812b5e6b8c5cd3dec8fb0d
fe976d168f9937cac0ffaa7ec4999d385d076fe2

View File

@ -0,0 +1,86 @@
Enable '___cxa_demangle()' in libsupc++
From: Christian Prochaska <christian.prochaska@genode-labs.com>
---
include/libiberty.h | 4 ++++
libiberty/cp-demangle.c | 4 +++-
libstdc++-v3/libsupc++/Makefile.in | 10 +++++-----
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/libiberty.h b/include/libiberty.h
index 78c42eb..4fcf284 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -47,7 +47,11 @@ extern "C" {
/* Get a definition for va_list. */
#include <stdarg.h>
+#ifdef GENODE
+#define FILE void
+#else
#include <stdio.h>
+#endif
/* If the OS supports it, ensure that the supplied stream is setup to
avoid any multi-threaded locking. Otherwise leave the FILE pointer
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 3d5d33e..e5f542f 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -103,7 +103,9 @@
#include "config.h"
#endif
+#ifndef GENODE
#include <stdio.h>
+#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -5875,7 +5877,7 @@ d_demangle (const char *mangled, int options, size_t *palc)
return dgs.buf;
}
-#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
+#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3) || defined(GENODE)
extern char *__cxa_demangle (const char *, char *, size_t *, int *);
diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
index 88b237e..f861d29 100644
--- a/libstdc++-v3/libsupc++/Makefile.in
+++ b/libstdc++-v3/libsupc++/Makefile.in
@@ -104,7 +104,7 @@ am__objects_1 = array_type_info.lo atexit_arm.lo atexit_thread.lo \
new_opv.lo new_opvnt.lo pbase_type_info.lo pmem_type_info.lo \
pointer_type_info.lo pure.lo si_class_type_info.lo tinfo.lo \
tinfo2.lo vec.lo vmi_class_type_info.lo vterminate.lo
-@GLIBCXX_HOSTED_TRUE@am__objects_2 = cp-demangle.lo
+am__objects_2 = cp-demangle.lo
@ENABLE_VTABLE_VERIFY_TRUE@am__objects_3 = vtv_stubs.lo
am_libsupc___la_OBJECTS = $(am__objects_1) $(am__objects_2) \
$(am__objects_3)
@@ -367,8 +367,8 @@ bits_HEADERS = \
exception_defines.h exception_ptr.h hash_bytes.h nested_exception.h
headers = $(std_HEADERS) $(bits_HEADERS)
-@GLIBCXX_HOSTED_TRUE@c_sources = \
-@GLIBCXX_HOSTED_TRUE@ cp-demangle.c
+c_sources = \
+ cp-demangle.c
sources = \
array_type_info.cc \
@@ -801,9 +801,9 @@ cp-demangle.c:
rm -f $@
$(LN_S) $(toplevel_srcdir)/libiberty/cp-demangle.c $@
cp-demangle.lo: cp-demangle.c
- $(LTCOMPILE) -DIN_GLIBCPP_V3 -Wno-error -c $<
+ $(LTCOMPILE) -DGENODE -Wno-error -c $<
cp-demangle.o: cp-demangle.c
- $(C_COMPILE) -DIN_GLIBCPP_V3 -Wno-error -c $<
+ $(C_COMPILE) -DGENODE -Wno-error -c $<
# Use special rules for the C++11 sources so that the proper flags are passed.
bad_array_length.lo: bad_array_length.cc

View File

@ -6,6 +6,7 @@ no_short_enums.patch
host_target_combination.patch
prefer_pic.patch
libstdcxx_without_libc.patch
libsupcxx_demangle.patch
libgcc_s.patch
go_libbacktrace.patch
target_libbacktrace.patch