File: demangle.m4

package info (click to toggle)
fastjet 3.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,552 kB
  • sloc: cpp: 78,628; python: 6,112; sh: 1,038; fortran: 673; makefile: 636; ansic: 161
file content (92 lines) | stat: -rw-r--r-- 2,276 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
dnl check demangling begin
dnl this checks if the demangling code using cxxabi in Error.cc is
dnl supported or not
dnl

dnl Note that according to BOOST (see the code in,
dnl /usr/include/boost/units/detail/utility.hpp or the link
dnl http://marc.info/?l=boost-bugs&m=122765675617968), instead of
dnl going through all this we could simply do
dnl   #if defined(__GLIBCXX__) || defined(__GLIBCPP__)
dnl
AC_DEFUN([ACX_CHECK_DEMANGLE_SUPPORT],
[
    dnl backup compiler/linker flags
    save_LIBS="$LIBS"
    save_LDFLAGS="$LDFLAGS"
    save_CXXFLAGS="$CXXFLAGS"
    save_CPPFLAGS="$CPPFLAGS"

    AC_LANG_PUSH(C++)
    dnl note the use of [[ ]] to allow brackets in the code
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <cstdio>     // sscanf
#include <execinfo.h> // for backtrace
#include <cstdlib>
#include <cxxabi.h>   // demangle

#include <iostream>   // cout used only in the test

using namespace std;

std::string demangle(const char* symbol) {
  size_t size;
  int status;
  char temp[128];
  char* demangled;
  //first, try to demangle a c++ name
  if (1 == sscanf(symbol, "%*[^(]%*[^_]%127[^)+]", temp)) {
    if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) {
      std::string result(demangled);
      free(demangled);
      return result;
    }
  }
  //if that didn't work, try to get a regular c symbol
  if (1 == sscanf(symbol, "%127s", temp)) {
    return temp;
  }
 
  //if all else fails, just return the symbol
  return symbol;
}

int main(void){ 
  void * array[10];
  char ** messages;

  int size = backtrace(array, 10);
  messages = backtrace_symbols(array, size);
  
  cout << "stack:" << endl;
  for (int i = 1; i < size && messages != NULL; ++i){
    cout << "  #" << i << ": " << messages[i] << endl;
    cout << "    " << demangle(messages[i]) << endl;
  }
  free(messages);

  return 0;

}
    ]])], [acx_demangle_support=yes],[acx_demangle_support=no])
    AC_LANG_POP(C++)

    dnl restore the original flags
    LIBS="$save_LIBS"
    LDFLAGS="$save_LDFLAGS"
    CXXFLAGS="$save_CXXFLAGS"
    CPPFLAGS="$save_CPPFLAGS"

    AC_MSG_CHECKING([demangling support])

    if test "$acx_demangle_support" == yes; then 
	AC_MSG_RESULT(yes);
	$1
    else
	AC_MSG_RESULT(no);
        $2
   fi]
)


dnl check demangling end