[svn-commits] trunk - r7646 in /trunk: Makefile
include/asterisk/logger.h logger.c
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Tue Dec 27 00:24:30 CST 2005
Author: tilghman
Date: Tue Dec 27 00:24:28 2005
New Revision: 7646
URL: http://svn.digium.com/view/asterisk?rev=7646&view=rev
Log:
Bug 5183 - Inline stack backtraces
Modified:
trunk/Makefile
trunk/include/asterisk/logger.h
trunk/logger.c
Modified: trunk/Makefile
URL: http://svn.digium.com/view/asterisk/trunk/Makefile?rev=7646&r1=7645&r2=7646&view=diff
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Tue Dec 27 00:24:28 2005
@@ -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"
@@ -332,7 +337,10 @@
ASTCFLAGS+= $(MALLOC_DEBUG)
ASTCFLAGS+= $(BUSYDETECT)
ASTCFLAGS+= $(OPTIONS)
+ifneq ($(findstring dont-optimize,$(MAKECMDGOALS)),dont-optimize)
ASTCFLAGS+= -fomit-frame-pointer
+endif
+
SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
Modified: trunk/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/logger.h?rev=7646&r1=7645&r2=7646&view=diff
==============================================================================
--- trunk/include/asterisk/logger.h (original)
+++ trunk/include/asterisk/logger.h Tue Dec 27 00:24:28 2005
@@ -60,6 +60,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)));
Modified: trunk/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/logger.c?rev=7646&r1=7645&r2=7646&view=diff
==============================================================================
--- trunk/logger.c (original)
+++ trunk/logger.c Tue Dec 27 00:24:28 2005
@@ -32,6 +32,9 @@
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
+#ifdef STACK_BACKTRACES
+#include <execinfo.h>
+#endif
#define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values,
from <syslog.h> 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];
More information about the svn-commits
mailing list