Merge lp:~trond-norbye/pandora-build/printstack into lp:pandora-build

Proposed by Trond Norbye
Status: Needs review
Proposed branch: lp:~trond-norbye/pandora-build/printstack
Merge into: lp:pandora-build
Diff against target: 63 lines (+59/-0)
1 file modified
m4/pandora_print_callstack.m4 (+59/-0)
To merge this branch: bzr merge lp:~trond-norbye/pandora-build/printstack
Reviewer Review Type Date Requested Status
Monty Taylor Pending
Review via email: mp+15706@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Trond Norbye (trond-norbye) wrote :

Added a "function" to the output header to dump the callstack to a stream by either printstack on the systems that support that, or by the backtrace function from execinfo.h if that's available. If none of the methods is supported it just prints out a notification telling so..

the signature of the "function" would be:

void pandora_print_callstack(FILE *stream)

Unmerged revisions

82. By Trond Norbye

Added pandora_print_callstack()

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: