~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
dnl  Copyright (C) 2009 Sun Microsystems, Inc.
dnl This file is free software; Sun Microsystems, Inc.
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl Try to define a macro to dump the current callstack.
AC_DEFUN([PANDORA_PRINT_CALLSTACK],[
  AC_CHECK_HEADERS([ucontext.h])
  AS_IF([test "x$ac_cv_header_ucontext_h" = "xyes"],
  	[ AC_CHECK_FUNCS([printstack]) ])


  AS_IF([ test "x$ac_cv_func_printstack" != "xyes"],
        [ AC_CHECK_HEADERS([dlfcn.h])
          AC_CHECK_HEADERS([execinfo.h])
          AC_CHECK_FUNCS([backtrace])
          AC_CHECK_FUNCS([backtrace_symbols_fd]) ])

  AH_BOTTOM([
#ifdef __cplusplus
#include <cstdio>
#define PANDORA_PRINTSTACK_STD_PREFIX std::
#else
#include <stdio.h>
#define PANDORA_PRINTSTACK_STD_PREFIX
#endif

#if defined(HAVE_UCONTEXT_H) && defined(HAVE_PRINTSTACK)
#include <ucontext.h>
#define pandora_print_callstack(a) \
printstack(PANDORA_PRINTSTACK_STD_PREFIX fileno(a))
#elif defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS_FD)

#include <execinfo.h>

#define pandora_print_callstack(a) \
{ \
  void *stack[100];  \
  int depth = backtrace(stack, 100); \
  backtrace_symbols_fd(stack, depth, PANDORA_PRINTSTACK_STD_PREFIX fileno(a)); \
}
#elif defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && !defined(HAVE_BACKTRACE_SYMBOLS_FD)

#include <execinfo.h>

#define pandora_print_callstack(a) \
{ \
  void *stack[100];  \
  int depth= backtrace(stack, 100); \
  char **symbol= backtrace_symbols(stack, depth); \
  for (int x= 0; x < size; ++x) \
    PANDORA_PRINTSTACK_STD_PREFIX fprintf(a, "%s\n", symbol[x]); \
}
#else
#define pandora_print_callstack(a) \
    PANDORA_PRINTSTACK_STD_PREFIX fprintf(a, \
      "Stackdump not supported for this platform\n");
#endif
  ])

])