00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023 #include <drizzled/util/backtrace.h>
00024
00025 #include <string.h>
00026 #include <stdlib.h>
00027 #include <iostream>
00028
00029 #ifdef __GNUC__
00030 #ifdef HAVE_BACKTRACE
00031 #include <execinfo.h>
00032 #include <cxxabi.h>
00033 #endif // HAVE_BACKTRACE
00034 #endif // __GNUC__
00035
00036
00037 namespace drizzled
00038 {
00039 namespace util
00040 {
00041
00042 void custom_backtrace(void)
00043 {
00044 #ifdef __GNUC__
00045 #ifdef HAVE_BACKTRACE
00046 void *array[50];
00047 size_t size;
00048 char **strings;
00049
00050 size= backtrace(array, 50);
00051 strings= backtrace_symbols(array, size);
00052
00053 std::cerr << "Number of stack frames obtained: " << size << std::endl;
00054
00055 for (size_t x= 1; x < size; x++)
00056 {
00057 size_t sz= 200;
00058 char *function= (char *)malloc(sz);
00059 char *begin= 0;
00060 char *end= 0;
00061
00062 for (char *j = strings[x]; *j; ++j)
00063 {
00064 if (*j == '(') {
00065 begin = j;
00066 }
00067 else if (*j == '+') {
00068 end = j;
00069 }
00070 }
00071 if (begin && end)
00072 {
00073 begin++;
00074 *end= '\0';
00075
00076 int status;
00077 char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
00078 if (ret)
00079 {
00080 function= ret;
00081 }
00082 else
00083 {
00084 strncpy(function, begin, sz);
00085 strncat(function, "()", sz);
00086 function[sz-1] = '\0';
00087 }
00088 std::cerr << function << std::endl;
00089 }
00090 else
00091 {
00092 std::cerr << strings[x] << std::endl;
00093 }
00094 free(function);
00095 }
00096
00097
00098 free (strings);
00099 #endif // HAVE_BACKTRACE
00100 #endif // __GNUC__
00101 }
00102
00103 }
00104 }