1 dnl Copyright (C) 2009 Sun Microsystems, Inc.
2 dnl This file is free software; Sun Microsystems, Inc.
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
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]) ])
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]) ])
22 #define PANDORA_PRINTSTACK_STD_PREFIX std::
25 #define PANDORA_PRINTSTACK_STD_PREFIX
28 #if defined(HAVE_UCONTEXT_H) && defined(HAVE_PRINTSTACK)
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)
36 #define pandora_print_callstack(a) \
39 int depth = backtrace(stack, 100); \
40 backtrace_symbols_fd(stack, depth, PANDORA_PRINTSTACK_STD_PREFIX fileno(a)); \
42 #elif defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && !defined(HAVE_BACKTRACE_SYMBOLS_FD)
46 #define pandora_print_callstack(a) \
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]); \
55 #define pandora_print_callstack(a) \
56 PANDORA_PRINTSTACK_STD_PREFIX fprintf(a, \
57 "Stackdump not supported for this platform\n");