aboutsummaryrefslogtreecommitdiffstats
path: root/logger.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 06:24:28 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 06:24:28 +0000
commit8d6c048c863c339896931fe09d3c41c745971738 (patch)
tree78f6f99e827cb89cd38d83adcdb5e85138669707 /logger.c
parentc1c4a6835a005bcd381052e755cc26a46f66db89 (diff)
Bug 5183 - Inline stack backtraces
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7646 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'logger.c')
-rw-r--r--logger.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/logger.c b/logger.c
index aae10c604..66977677d 100644
--- a/logger.c
+++ b/logger.c
@@ -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_log(int level, const char *file, int line, const char *function, const
}
}
+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];