]> granicus.if.org Git - icinga2/commitdiff
Added support for demangling GCC C++ names.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 11:38:30 +0000 (13:38 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 11:48:37 +0000 (13:48 +0200)
base/application.h
base/i2-base.h
configure.ac
m4/ax_cxx_gcc_abi_demangle.m4 [new file with mode: 0644]

index a27afbb01ad148970111926e66e02cc2cb853254..72940ba64ec3e7747766acb703e9639f0a3cf330 100644 (file)
@@ -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;
index cfccd7b81d547c266a5143774fdd5933014eebb5..f0b4b3b572b0a777fc3344ac3c4ccf17c0b79708 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef I2BASE_H
 #define I2BASE_H
 
+#ifndef _MSC_VER
+#      include "config.h"
+#endif /* _MSC_VER */
+
 #include <cstdlib>
 #include <cstdarg>
 #include <cstdio>
 #include <map>
 #include <list>
 
+#ifdef HAVE_GCC_ABI_DEMANGLE
+#      include <cxxabi.h>
+#endif /* HAVE_GCC_ABI_DEMANGLE */
+
 using namespace std;
 
 #ifdef _MSC_VER
index 2e618d159ad4aceae2545d61fb146d72ba344486..3abf6feb68ee83be077a2d52761c9bab9fc58863 100644 (file)
@@ -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 (file)
index 0000000..746f686
--- /dev/null
@@ -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 <nferguso@eso.org>
+#
+#   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 <stdlib.h>
+#include <typeinfo>
+#include <cxxabi.h>
+#include <string>
+
+template<typename TYPE>
+class A {};
+],[A<int> 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<int>";
+],
+ 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