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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
22 |
#include <drizzled/util/backtrace.h> |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
23 |
|
24 |
#include <string.h> |
|
25 |
#include <stdlib.h> |
|
26 |
#include <iostream> |
|
27 |
||
28 |
#ifdef __GNUC__
|
|
29 |
#ifdef HAVE_BACKTRACE
|
|
30 |
#include <execinfo.h> |
|
31 |
#include <cxxabi.h> |
|
32 |
#endif // HAVE_BACKTRACE |
|
33 |
#endif // __GNUC__ |
|
34 |
||
35 |
namespace drizzled |
|
36 |
{
|
|
37 |
namespace util |
|
38 |
{
|
|
39 |
||
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
40 |
void custom_backtrace(const char *file, int line, const char *func) |
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
41 |
{
|
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
42 |
std::cerr << std::endl << "call_backtrace() began at " << file << ":" << line << " for " << func << "()" << std::endl; |
1864
by Brian Aker
Merge for Brian |
43 |
#ifdef __GNUC__
|
44 |
#ifdef HAVE_BACKTRACE
|
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
45 |
void *array[50]; |
46 |
size_t size; |
|
47 |
char **strings; |
|
48 |
||
49 |
size= backtrace(array, 50); |
|
50 |
strings= backtrace_symbols(array, size); |
|
51 |
||
52 |
std::cerr << "Number of stack frames obtained: " << size << std::endl; |
|
53 |
||
54 |
for (size_t x= 1; x < size; x++) |
|
55 |
{
|
|
56 |
size_t sz= 200; |
|
57 |
char *function= (char *)malloc(sz); |
|
58 |
char *begin= 0; |
|
59 |
char *end= 0; |
|
60 |
||
61 |
for (char *j = strings[x]; *j; ++j) |
|
62 |
{
|
|
63 |
if (*j == '(') { |
|
64 |
begin = j; |
|
65 |
}
|
|
66 |
else if (*j == '+') { |
|
67 |
end = j; |
|
68 |
}
|
|
69 |
}
|
|
70 |
if (begin && end) |
|
71 |
{
|
|
72 |
begin++; |
|
73 |
*end= '\0'; |
|
74 |
||
75 |
int status; |
|
76 |
char *ret = abi::__cxa_demangle(begin, function, &sz, &status); |
|
77 |
if (ret) |
|
78 |
{
|
|
79 |
function= ret; |
|
80 |
}
|
|
81 |
else
|
|
82 |
{
|
|
83 |
strncpy(function, begin, sz); |
|
84 |
strncat(function, "()", sz); |
|
85 |
function[sz-1] = '\0'; |
|
86 |
}
|
|
87 |
std::cerr << function << std::endl; |
|
88 |
}
|
|
89 |
else
|
|
90 |
{
|
|
91 |
std::cerr << strings[x] << std::endl; |
|
92 |
}
|
|
93 |
free(function); |
|
94 |
}
|
|
95 |
||
96 |
||
97 |
free (strings); |
|
1864
by Brian Aker
Merge for Brian |
98 |
#endif // HAVE_BACKTRACE |
99 |
#endif // __GNUC__ |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
100 |
}
|
101 |
||
102 |
} /* namespace util */ |
|
103 |
} /* namespace drizzled */ |