Route ampif77 and ampif90 through ampiCC, factoring out duplicated code
[charm.git] / src / conv-core / cmibacktrace.c
blob9c0a09cf9c81dc3996f3bb42922356e1c9b4a008
1 /*
2 Stack Tracing, for debugging.
4 This routine lets you inspect the run-time stack
5 for the names of the routines that have been called up
6 to this point. It's useful for things like CkAbort
7 that are called when stuff has gone really wrong and
8 you'd like to know what led up to this point.
9 These routines even seem to work from signal handlers,
10 although I wouldn't count on that.
12 This file is intended to be #included whole by the autoconf
13 script and conv-core.c.
15 Orion Sky Lawlor, olawlor@acm.org, 8/20/2002
18 #if CMK_USE_BACKTRACE
19 # include <execinfo.h> /* for backtrace (GNU glibc header) */
21 /* Extract the function-return pointers listed in the stack
22 up to this depth.
24 void CmiBacktraceRecord(void **retPtrs,int nSkip,int *nLevels) {
25 int i;
26 #define max_stack 64 /* trace back at most this many levels of the stack */
27 void *stackPtrs[max_stack];
28 nSkip++; /* don't trace this routine */
29 *nLevels=backtrace(stackPtrs,nSkip+*nLevels)-nSkip;
30 for (i=0;i<*nLevels;i++)
31 retPtrs[i]=stackPtrs[nSkip+i];
34 /* Meant to be used for large stack traces, avoids copy */
35 void CmiBacktraceRecordHuge(void **retPtrs,int *nLevels) {
36 *nLevels=backtrace(retPtrs,*nLevels);
39 /* Look up the names of these function pointers */
40 char **CmiBacktraceLookup(void **srcPtrs,int nLevels) {
41 return backtrace_symbols(srcPtrs,nLevels);
44 #else /*Backtrace not available-- use do-nothing version*/
45 #include <stddef.h> /* for NULL */
46 void CmiBacktraceRecord(void **retPtrs,int nSkip,int *nLevels) {
47 *nLevels=0;
50 void CmiBacktraceRecordHuge(void **retPtrs,int nSkip,int *nLevels) {
51 *nLevels=0;
54 /* Look up the names of these function pointers */
55 char **CmiBacktraceLookup(void **srcPtrs,int nLevels) {
56 return NULL;
58 #endif