diff --git a/repos/base/src/lib/cxx/exception.cc b/repos/base/src/lib/cxx/exception.cc index 20a7b552c..9e79fca5b 100644 --- a/repos/base/src/lib/cxx/exception.cc +++ b/repos/base/src/lib/cxx/exception.cc @@ -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()); } diff --git a/repos/ports/ports/gcc.hash b/repos/ports/ports/gcc.hash index 2c8503235..b107a0dda 100644 --- a/repos/ports/ports/gcc.hash +++ b/repos/ports/ports/gcc.hash @@ -1 +1 @@ -2a59b9a759881adf43812b5e6b8c5cd3dec8fb0d +fe976d168f9937cac0ffaa7ec4999d385d076fe2 diff --git a/tool/patches/gcc-4.9.2/libsupcxx_demangle.patch b/tool/patches/gcc-4.9.2/libsupcxx_demangle.patch new file mode 100644 index 000000000..7cd22882c --- /dev/null +++ b/tool/patches/gcc-4.9.2/libsupcxx_demangle.patch @@ -0,0 +1,86 @@ +Enable '___cxa_demangle()' in libsupc++ + +From: Christian Prochaska + + +--- + 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 + ++#ifdef GENODE ++#define FILE void ++#else + #include ++#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 ++#endif + + #ifdef HAVE_STDLIB_H + #include +@@ -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 diff --git a/tool/patches/gcc-4.9.2/series b/tool/patches/gcc-4.9.2/series index bed1e7d09..b23957eb1 100644 --- a/tool/patches/gcc-4.9.2/series +++ b/tool/patches/gcc-4.9.2/series @@ -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