Fixed dtrace building.
[m6w6/libmemcached] / m4 / pandora_print_callstack.m4
1 dnl Copyright (C) 2009 Sun Microsystems
2 dnl This file is free software; Sun Microsystems
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
5
6 dnl Try to define a macro to dump the current callstack.
7 AC_DEFUN([PANDORA_PRINT_CALLSTACK],[
8 AC_CHECK_HEADERS([ucontext.h])
9 AS_IF([test "x$ac_cv_header_ucontext_h" = "xyes"],
10 [ AC_CHECK_FUNCS([printstack]) ])
11
12
13 AS_IF([ test "x$ac_cv_func_printstack" != "xyes"],
14 [ AC_CHECK_HEADERS([dlfcn.h])
15 AC_CHECK_HEADERS([execinfo.h])
16 AC_CHECK_FUNCS([backtrace])
17 AC_CHECK_FUNCS([backtrace_symbols_fd]) ])
18
19 AH_BOTTOM([
20 #ifdef __cplusplus
21 #include <cstdio>
22 #define PANDORA_PRINTSTACK_STD_PREFIX std::
23 #else
24 #include <stdio.h>
25 #define PANDORA_PRINTSTACK_STD_PREFIX
26 #endif
27
28 #if defined(HAVE_UCONTEXT_H) && defined(HAVE_PRINTSTACK)
29 #include <ucontext.h>
30 #define pandora_print_callstack(a) \
31 printstack(PANDORA_PRINTSTACK_STD_PREFIX fileno(a))
32 #elif defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS_FD)
33
34 #include <execinfo.h>
35
36 #define pandora_print_callstack(a) \
37 { \
38 void *stack[100]; \
39 int depth = backtrace(stack, 100); \
40 backtrace_symbols_fd(stack, depth, PANDORA_PRINTSTACK_STD_PREFIX fileno(a)); \
41 }
42 #elif defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && !defined(HAVE_BACKTRACE_SYMBOLS_FD)
43
44 #include <execinfo.h>
45
46 #define pandora_print_callstack(a) \
47 { \
48 void *stack[100]; \
49 int depth= backtrace(stack, 100); \
50 char **symbol= backtrace_symbols(stack, depth); \
51 for (int x= 0; x < size; ++x) \
52 PANDORA_PRINTSTACK_STD_PREFIX fprintf(a, "%s\n", symbol[x]); \
53 }
54 #else
55 #define pandora_print_callstack(a) \
56 PANDORA_PRINTSTACK_STD_PREFIX fprintf(a, \
57 "Stackdump not supported for this platform\n");
58 #endif
59 ])
60
61 ])