From: Gunnar Beutner Date: Tue, 3 Apr 2012 11:38:30 +0000 (+0200) Subject: Added support for demangling GCC C++ names. X-Git-Tag: v0.0.1~651 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34d50924e819cf65b3b7c1b078f79016e6137d6d;p=icinga2 Added support for demangling GCC C++ names. --- diff --git a/base/application.h b/base/application.h index a27afbb01..72940ba64 100644 --- a/base/application.h +++ b/base/application.h @@ -65,7 +65,20 @@ int application_main(int argc, char **argv) #ifndef _DEBUG } catch (const Exception& ex) { cout << "---" << endl; - cout << "Exception: " << typeid(ex).name() << endl; + + string klass = typeid(ex).name(); + +#ifdef HAVE_GCC_ABI_DEMANGLE + int status; + char *realname = abi::__cxa_demangle(klass.c_str(), 0, 0, &status); + + if (realname != NULL) { + klass = string(realname); + free(realname); + } +#endif /* HAVE_GCC_ABI_DEMANGLE */ + + cout << "Exception: " << klass << endl; cout << "Message: " << ex.GetMessage() << endl; return EXIT_FAILURE; diff --git a/base/i2-base.h b/base/i2-base.h index cfccd7b81..f0b4b3b57 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -1,6 +1,10 @@ #ifndef I2BASE_H #define I2BASE_H +#ifndef _MSC_VER +# include "config.h" +#endif /* _MSC_VER */ + #include #include #include @@ -17,6 +21,10 @@ #include #include +#ifdef HAVE_GCC_ABI_DEMANGLE +# include +#endif /* HAVE_GCC_ABI_DEMANGLE */ + using namespace std; #ifdef _MSC_VER diff --git a/configure.ac b/configure.ac index 2e618d159..3abf6feb6 100644 --- a/configure.ac +++ b/configure.ac @@ -3,14 +3,17 @@ dnl Created by Anjuta application wizard. AC_INIT(icinga, 2.0) +AC_CONFIG_AUX_DIR([m4]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([1.11]) +m4_include([m4/ax_cxx_gcc_abi_demangle.m4]) + AM_SILENT_RULES([yes]) AC_PROG_CXX - +AX_CXX_GCC_ABI_DEMANGLE diff --git a/m4/ax_cxx_gcc_abi_demangle.m4 b/m4/ax_cxx_gcc_abi_demangle.m4 new file mode 100644 index 000000000..746f68669 --- /dev/null +++ b/m4/ax_cxx_gcc_abi_demangle.m4 @@ -0,0 +1,58 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_gcc_abi_demangle.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_GCC_ABI_DEMANGLE +# +# DESCRIPTION +# +# If the compiler supports GCC C++ ABI name demangling (has header +# cxxabi.h and abi::__cxa_demangle() function), define +# HAVE_GCC_ABI_DEMANGLE +# +# Adapted from AX_CXX_RTTI by Luc Maisonobe +# +# LICENSE +# +# Copyright (c) 2008 Neil Ferguson +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AC_DEFUN([AX_CXX_GCC_ABI_DEMANGLE], +[AC_CACHE_CHECK(whether the compiler supports GCC C++ ABI name demangling, +ax_cv_cxx_gcc_abi_demangle, +[AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([#include +#include +#include +#include + +template +class A {}; +],[A instance; +int status = 0; +char* c_name = 0; + +c_name = abi::__cxa_demangle(typeid(instance).name(), 0, 0, &status); + +std::string name(c_name); +free(c_name); + +return name == "A"; +], + ax_cv_cxx_gcc_abi_demangle=yes, ax_cv_cxx_gcc_abi_demangle=no) + AC_LANG_RESTORE +]) +if test "$ax_cv_cxx_gcc_abi_demangle" = yes; then + AC_DEFINE(HAVE_GCC_ABI_DEMANGLE,1, + [define if the compiler supports GCC C++ ABI name demangling]) +fi +]) \ No newline at end of file