Index: logger.c =================================================================== RCS file: /usr/cvsroot/asterisk/logger.c,v retrieving revision 1.90 diff -u -r1.90 logger.c --- logger.c 30 Nov 2005 08:49:59 -0000 1.90 +++ logger.c 1 Dec 2005 20:19:41 -0000 @@ -32,6 +32,9 @@ #include #include #include +#ifdef STACK_BACKTRACES +#include +#endif #define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values, from which is included by logger.h */ @@ -816,6 +819,39 @@ } } +void ast_backtrace(void) +{ +#ifdef STACK_BACKTRACES + int count=0, i=0; + void **addresses; + char **strings; + + addresses = calloc(levels, sizeof(void *)); + if (addresses) { + count = backtrace(addresses, 20); + strings = backtrace_symbols(addresses, count); + if (strings) { + ast_log(LOG_WARNING, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' '); + for (i=0; i < count ; i++) { + ast_log(LOG_WARNING, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]); + } + free(strings); + } else { + ast_log(LOG_WARNING, "Could not allocate memory for backtrace\n"); + } + free(addresses); + } else { + ast_log(LOG_WARNING, "Could not allocate memory for backtrace\n"); + } +#else +#ifdef Linux + ast_log(LOG_WARNING, "Must compile with 'make dont-optimize' for stack backtraces\n"); +#else + ast_log(LOG_WARNING, "Inline stack backtraces are only available on the Linux platform.\n"); +#endif +#endif +} + void ast_verbose(const char *fmt, ...) { static char stuff[4096]; Index: Makefile =================================================================== RCS file: /usr/cvsroot/asterisk/Makefile,v retrieving revision 1.233 diff -u -r1.233 Makefile --- Makefile 30 Nov 2005 08:49:58 -0000 1.233 +++ Makefile 1 Dec 2005 20:19:41 -0000 @@ -45,6 +45,11 @@ #Tell gcc to optimize the code OPTIMIZE+=-O6 +else + # Stack backtraces, while useful for debugging, are incompatible with optimizations + ifeq (${OSARCH},Linux) + CFLAGS+=-DSTACK_BACKTRACES + endif endif #Overwite config files on "make samples" Index: include/asterisk/logger.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/logger.h,v retrieving revision 1.15 diff -u -r1.15 logger.h --- include/asterisk/logger.h 8 Sep 2005 02:19:02 -0000 1.15 +++ include/asterisk/logger.h 1 Dec 2005 20:19:41 -0000 @@ -56,6 +56,8 @@ extern void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); +extern void ast_backtrace(void); + extern void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...) __attribute__ ((format (printf, 5, 6)));