1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
1 |
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Brian Aker
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <config.h> |
23 |
#include <drizzled/util/backtrace.h> |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
24 |
|
25 |
#include <string.h> |
|
26 |
#include <stdlib.h> |
|
27 |
#include <iostream> |
|
28 |
||
29 |
#ifdef __GNUC__
|
|
30 |
#ifdef HAVE_BACKTRACE
|
|
31 |
#include <execinfo.h> |
|
32 |
#include <cxxabi.h> |
|
33 |
#endif // HAVE_BACKTRACE |
|
34 |
#endif // __GNUC__ |
|
35 |
||
36 |
||
37 |
namespace drizzled |
|
38 |
{
|
|
39 |
namespace util |
|
40 |
{
|
|
41 |
||
42 |
void custom_backtrace(void) |
|
43 |
{
|
|
1864
by Brian Aker
Merge for Brian |
44 |
#ifdef __GNUC__
|
45 |
#ifdef HAVE_BACKTRACE
|
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
46 |
void *array[50]; |
47 |
size_t size; |
|
48 |
char **strings; |
|
49 |
||
50 |
size= backtrace(array, 50); |
|
51 |
strings= backtrace_symbols(array, size); |
|
52 |
||
53 |
std::cerr << "Number of stack frames obtained: " << size << std::endl; |
|
54 |
||
55 |
for (size_t x= 1; x < size; x++) |
|
56 |
{
|
|
57 |
size_t sz= 200; |
|
58 |
char *function= (char *)malloc(sz); |
|
59 |
char *begin= 0; |
|
60 |
char *end= 0; |
|
61 |
||
62 |
for (char *j = strings[x]; *j; ++j) |
|
63 |
{
|
|
64 |
if (*j == '(') { |
|
65 |
begin = j; |
|
66 |
}
|
|
67 |
else if (*j == '+') { |
|
68 |
end = j; |
|
69 |
}
|
|
70 |
}
|
|
71 |
if (begin && end) |
|
72 |
{
|
|
73 |
begin++; |
|
74 |
*end= '\0'; |
|
75 |
||
76 |
int status; |
|
77 |
char *ret = abi::__cxa_demangle(begin, function, &sz, &status); |
|
78 |
if (ret) |
|
79 |
{
|
|
80 |
function= ret; |
|
81 |
}
|
|
82 |
else
|
|
83 |
{
|
|
84 |
strncpy(function, begin, sz); |
|
85 |
strncat(function, "()", sz); |
|
86 |
function[sz-1] = '\0'; |
|
87 |
}
|
|
88 |
std::cerr << function << std::endl; |
|
89 |
}
|
|
90 |
else
|
|
91 |
{
|
|
92 |
std::cerr << strings[x] << std::endl; |
|
93 |
}
|
|
94 |
free(function); |
|
95 |
}
|
|
96 |
||
97 |
||
98 |
free (strings); |
|
1864
by Brian Aker
Merge for Brian |
99 |
#endif // HAVE_BACKTRACE |
100 |
#endif // __GNUC__ |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
101 |
}
|
102 |
||
103 |
} /* namespace util */ |
|
104 |
} /* namespace drizzled */ |