1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * libmcachedd client library.
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <libmemcached/common.h>
43 #ifdef HAVE_EXECINFO_H
51 #ifdef HAVE_GCC_ABI_DEMANGLE
52 #define USE_DEMANGLE 1
54 #define USE_DEMANGLE 0
57 void custom_backtrace(void)
59 #ifdef HAVE_EXECINFO_H
62 size_t size
= backtrace(array
, 50);
63 char **strings
= backtrace_symbols(array
, size
);
70 fprintf(stderr
, "Number of stack frames obtained: %lu\n", (unsigned long)size
);
72 char *named_function
= (char *)std::realloc(NULL
, 1024);
74 if (named_function
== NULL
)
80 for (size_t x
= 1; x
< size
; x
++)
85 char *named_function_ptr
= (char *)std::realloc(named_function
, sz
);
86 if (named_function_ptr
== NULL
)
90 named_function
= named_function_ptr
;
93 char *begin_offset
= 0;
96 for (char *j
= strings
[x
]; *j
; ++j
)
106 else if (*j
== ')' and begin_offset
)
113 if (begin_name
and begin_offset
and end_offset
and begin_name
< begin_offset
)
116 *begin_offset
++= '\0';
120 char *ret
= abi::__cxa_demangle(begin_name
, named_function
, &sz
, &status
);
121 if (ret
) // realloc()'ed string
124 fprintf(stderr
, " %s : %s()+%s\n", strings
[x
], begin_name
, begin_offset
);
128 fprintf(stderr
, " %s : %s()+%s\n", strings
[x
], begin_name
, begin_offset
);
133 fprintf(stderr
, " %s\n", strings
[x
]);
138 fprintf(stderr
, " unmangled: %s\n", strings
[x
]);
142 std::free(named_function
);
144 #endif // HAVE_EXECINFO_H