[asterisk-commits] tilghman: branch tilghman/better_backtrace_1.4 r297948 - in /team/tilghman/be...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Dec 8 17:15:31 CST 2010
Author: tilghman
Date: Wed Dec 8 17:15:26 2010
New Revision: 297948
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=297948
Log:
Saving progress
Modified:
team/tilghman/better_backtrace_1.4/apps/app_sayunixtime.c
team/tilghman/better_backtrace_1.4/build_tools/menuselect-deps.in
team/tilghman/better_backtrace_1.4/configure
team/tilghman/better_backtrace_1.4/configure.ac
team/tilghman/better_backtrace_1.4/include/asterisk/autoconfig.h.in
team/tilghman/better_backtrace_1.4/main/Makefile
team/tilghman/better_backtrace_1.4/main/devicestate.c
team/tilghman/better_backtrace_1.4/main/logger.c
team/tilghman/better_backtrace_1.4/makeopts.in
team/tilghman/better_backtrace_1.4/pbx/pbx_dundi.c
Modified: team/tilghman/better_backtrace_1.4/apps/app_sayunixtime.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/apps/app_sayunixtime.c?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/apps/app_sayunixtime.c (original)
+++ team/tilghman/better_backtrace_1.4/apps/app_sayunixtime.c Wed Dec 8 17:15:26 2010
@@ -85,6 +85,8 @@
u = ast_module_user_add(chan);
+ ast_backtrace();
+
AST_STANDARD_APP_ARGS(args, parse);
ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
Modified: team/tilghman/better_backtrace_1.4/build_tools/menuselect-deps.in
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/build_tools/menuselect-deps.in?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/build_tools/menuselect-deps.in (original)
+++ team/tilghman/better_backtrace_1.4/build_tools/menuselect-deps.in Wed Dec 8 17:15:26 2010
@@ -1,4 +1,5 @@
ASOUND=@PBX_ALSA@
+BFD=@PBX_BFD@
BISON=@PBX_BISON@
CURL=@PBX_CURL@
DAHDI=@PBX_DAHDI@
Modified: team/tilghman/better_backtrace_1.4/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/configure.ac?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/configure.ac (original)
+++ team/tilghman/better_backtrace_1.4/configure.ac Wed Dec 8 17:15:26 2010
@@ -232,6 +232,7 @@
# by the --with option name, to make things easier for the users :-)
AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
+AST_EXT_LIB_SETUP([BFD], [Debug symbol decoding], [bfd])
AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
AST_EXT_LIB_SETUP([DAHDI], [DAHDI], [dahdi])
@@ -673,10 +674,26 @@
AC_DEFINE([TYPEOF_FD_SET_FDS_BITS], [long long], [Define to a type of the same size as fd_set.fds_bits[[0]]])
fi ; fi ; fi
+AC_MSG_CHECKING(for dladdr in dlfcn.h)
+old_LIBS=${LIBS}
+LIBS="${LIBS} -ldl"
+AC_LINK_IFELSE(
+ AC_LANG_PROGRAM([#define _GNU_SOURCE 1
+#include <dlfcn.h>],
+ [dladdr((void *)0, (void *)0)]
+ ),
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_DLADDR], 1, [Define to 1 if your system has the dladdr() GNU extension]),
+ AC_MSG_RESULT(no)
+)
+LIBS=${old_LIBS}
+
# do the package library checks now
AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
+
+AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h])
AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
Modified: team/tilghman/better_backtrace_1.4/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/include/asterisk/autoconfig.h.in?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/include/asterisk/autoconfig.h.in (original)
+++ team/tilghman/better_backtrace_1.4/include/asterisk/autoconfig.h.in Wed Dec 8 17:15:26 2010
@@ -74,6 +74,9 @@
attribute. */
#undef HAVE_ATTRIBUTE_warn_unused_result
+/* Define to 1 if you have the Debug symbol decoding library. */
+#undef HAVE_BFD
+
/* Define to 1 if you have the `bzero' function. */
#undef HAVE_BZERO
@@ -98,6 +101,9 @@
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
+
+/* Define to 1 if your system has the dladdr() GNU extension */
+#undef HAVE_DLADDR
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
Modified: team/tilghman/better_backtrace_1.4/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/main/Makefile?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/main/Makefile (original)
+++ team/tilghman/better_backtrace_1.4/main/Makefile Wed Dec 8 17:15:26 2010
@@ -48,6 +48,10 @@
AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
else
AST_LIBS+=$(EDITLINE_LIB) -lm
+endif
+
+ifneq ($(BFD_LIB),)
+ AST_LIBS+=$(BFD_LIB)
endif
ifneq ($(findstring darwin,$(OSARCH)),)
Modified: team/tilghman/better_backtrace_1.4/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/main/devicestate.c?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/main/devicestate.c (original)
+++ team/tilghman/better_backtrace_1.4/main/devicestate.c Wed Dec 8 17:15:26 2010
@@ -83,7 +83,16 @@
/*! \brief The state change queue. State changes are queued
for processing by a separate thread */
+#ifndef AST_MUTEX_INIT_W_CONSTRUCTORS
static AST_LIST_HEAD_STATIC(state_changes, state_change);
+#else
+static AST_LIST_HEAD(state_changes, state_change) state_changes;
+static pthread_once_t state_changes_once = PTHREAD_ONCE_INIT;
+static void state_changes_init(void)
+{
+ AST_LIST_HEAD_INIT(&state_changes);
+}
+#endif
/*! \brief The device state change notification thread */
static pthread_t change_thread = AST_PTHREADT_NULL;
@@ -308,6 +317,9 @@
} else {
/* queue the change */
strcpy(change->device, device);
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+ pthread_once(&state_changes_once, state_changes_init);
+#endif
AST_LIST_LOCK(&state_changes);
AST_LIST_INSERT_TAIL(&state_changes, change, list);
if (AST_LIST_FIRST(&state_changes) == change)
@@ -335,6 +347,9 @@
static void *do_devstate_changes(void *data)
{
struct state_change *cur;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+ pthread_once(&state_changes_once, state_changes_init);
+#endif
AST_LIST_LOCK(&state_changes);
for(;;) {
Modified: team/tilghman/better_backtrace_1.4/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/main/logger.c?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/main/logger.c (original)
+++ team/tilghman/better_backtrace_1.4/main/logger.c Wed Dec 8 17:15:26 2010
@@ -39,8 +39,12 @@
#include <errno.h>
#include <sys/stat.h>
#if ((defined(AST_DEVMODE)) && (defined(linux)))
-#include <execinfo.h>
-#define MAX_BACKTRACE_FRAMES 20
+# include <execinfo.h>
+# define MAX_BACKTRACE_FRAMES 20
+# if defined(HAVE_DLADDR) && defined(HAVE_BFD)
+# include <dlfcn.h>
+# include <bfd.h>
+# endif
#endif
#define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values,
@@ -832,10 +836,103 @@
#ifdef AST_DEVMODE
int count=0, i=0;
void **addresses;
+#if defined(HAVE_DLADDR) && defined(HAVE_BFD)
+ bfd *bfdobj;
+ Dl_info dli;
+ long allocsize;
+ asymbol **syms = NULL;
+ bfd_vma offset;
+ asection *section;
+ const char *last_slash, *file, *func;
+ unsigned int line;
+#else
char **strings;
+#endif
if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) {
count = backtrace(addresses, MAX_BACKTRACE_FRAMES);
+#if defined(HAVE_DLADDR) && defined(HAVE_BFD)
+ ast_log(LOG_DEBUG, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
+ for (i = 0; i < count; i++) {
+ int found = 0;
+
+ if (!dladdr(addresses[i], &dli)) {
+ continue;
+ }
+ if ( (bfdobj = bfd_openr(dli.dli_fname, NULL)) &&
+ bfd_check_format(bfdobj, bfd_object) &&
+ (allocsize = bfd_get_symtab_upper_bound(bfdobj)) > 0 &&
+ (syms = ast_malloc(allocsize)) &&
+ bfd_canonicalize_symtab(bfdobj, syms)) {
+
+ if (bfdobj->flags & BSF_DYNAMIC) {
+ /* Convert library symbols from absolute address to offset address */
+ offset = addresses[i] - dli.dli_fbase;
+ } else {
+ /* Core asterisk routine */
+ offset = addresses[i] - (void *) 0;
+ }
+
+ for (section = bfdobj->sections; section; section = section->next) {
+ if ( !bfd_get_section_flags(bfdobj, section) & SEC_ALLOC ||
+ section->vma > offset ||
+ section->size + section->vma < offset) {
+ continue;
+ }
+
+ if (!bfd_find_nearest_line(bfdobj, section, syms, offset - section->vma, &file, &func, &line)) {
+ break;
+ }
+
+ /* TODO Stack trace output */
+ found++;
+#if __WORDSIZE == 32
+ ast_log(LOG_DEBUG, "#%d: [%08lX] %s:%u %s (%08lX+%lX)\n", i,
+ (unsigned long) addresses[i],
+ file, line,
+ S_OR(func, "???"),
+ (unsigned long) dli.dli_saddr,
+ (unsigned long) (addresses[i] - dli.dli_saddr));
+#elif __WORDSIZE == 64
+ ast_log(LOG_DEBUG, "#%d: [%016lX] %s:%u %s (%16lX+%lX)\n", i,
+ (unsigned long) addresses[i],
+ file, line,
+ S_OR(func, "???"),
+ (unsigned long) dli.dli_saddr,
+ (unsigned long) (addresses[i] - dli.dli_saddr));
+#endif
+
+ break;
+ }
+ }
+ last_slash = strrchr(dli.dli_fname, '/');
+ if (bfdobj) {
+ bfd_close(bfdobj);
+ if (syms) {
+ ast_free(syms);
+ }
+ }
+
+ /* Default output, if we cannot find the information within BFD */
+ if (!found) {
+#if __WORDSIZE == 32
+ ast_log(LOG_DEBUG, "#%d: [%08lX] %s %s (%08lX+%lX)\n", i,
+ (unsigned long) addresses[i],
+ last_slash ? last_slash + 1 : dli.dli_fname,
+ S_OR(dli.dli_sname, "<unknown>"),
+ (unsigned long) dli.dli_saddr,
+ (unsigned long) (addresses[i] - dli.dli_saddr));
+#elif __WORDSIZE == 64
+ ast_log(LOG_DEBUG, "#%d: [%016lX] %s %s (%08lX+%lX)\n", i,
+ (unsigned long) addresses[i],
+ last_slash ? last_slash + 1 : dli.dli_fname,
+ S_OR(dli.dli_sname, "<unknown>"),
+ (unsigned long) dli.dli_saddr,
+ (unsigned long) (addresses[i] - dli.dli_saddr));
+#endif
+ }
+ }
+#else
if ((strings = backtrace_symbols(addresses, count))) {
ast_log(LOG_DEBUG, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
for (i=0; i < count ; i++) {
@@ -849,6 +946,7 @@
} else {
ast_log(LOG_DEBUG, "Could not allocate memory for backtrace\n");
}
+#endif
free(addresses);
}
#else
Modified: team/tilghman/better_backtrace_1.4/makeopts.in
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/makeopts.in?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/makeopts.in (original)
+++ team/tilghman/better_backtrace_1.4/makeopts.in Wed Dec 8 17:15:26 2010
@@ -73,6 +73,9 @@
ASOUND_INCLUDE=@ALSA_INCLUDE@
ASOUND_LIB=@ALSA_LIB@
+BFD_INCLUDE=@BFD_INCLUDE@
+BFD_LIB=@BFD_LIB@
+
CURL_INCLUDE=@CURL_INCLUDE@
CURL_LIB=@CURL_LIB@
Modified: team/tilghman/better_backtrace_1.4/pbx/pbx_dundi.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/better_backtrace_1.4/pbx/pbx_dundi.c?view=diff&rev=297948&r1=297947&r2=297948
==============================================================================
--- team/tilghman/better_backtrace_1.4/pbx/pbx_dundi.c (original)
+++ team/tilghman/better_backtrace_1.4/pbx/pbx_dundi.c Wed Dec 8 17:15:26 2010
@@ -262,8 +262,13 @@
AST_LIST_ENTRY(dundi_peer) list;
};
+#ifndef AST_MUTEX_INIT_W_CONSTRUCTORS
static AST_LIST_HEAD_STATIC(peers, dundi_peer);
static AST_LIST_HEAD_STATIC(pcq, dundi_precache_queue);
+#else
+static AST_LIST_HEAD(peers, dundi_peer) peers;
+static AST_LIST_HEAD(pcq, dundi_precache_queue) pcq;
+#endif
static AST_LIST_HEAD_NOLOCK_STATIC(mappings, dundi_mapping);
static AST_LIST_HEAD_NOLOCK_STATIC(requests, dundi_request);
static AST_LIST_HEAD_NOLOCK_STATIC(alltrans, dundi_transaction);
@@ -4609,6 +4614,11 @@
mark_peers();
prune_peers();
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+ ast_mutex_destroy(&peers.lock);
+ ast_mutex_destroy(&pcq.lock);
+#endif
+
return 0;
}
@@ -4623,6 +4633,11 @@
{
int res = 0;
struct sockaddr_in sin;
+
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+ ast_mutex_init(&peers.lock);
+ ast_mutex_init(&pcq.lock);
+#endif
dundi_set_output(dundi_debug_output);
dundi_set_error(dundi_error_output);
More information about the asterisk-commits
mailing list