[asterisk-commits] mmichelson: branch mmichelson/lock_backtraces r115372 - /team/mmichelson/lock...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 6 14:02:07 CDT 2008


Author: mmichelson
Date: Tue May  6 14:02:06 2008
New Revision: 115372

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115372
Log:
Convert ast_backtrace to use the ast_bt API


Modified:
    team/mmichelson/lock_backtraces/main/logger.c

Modified: team/mmichelson/lock_backtraces/main/logger.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/lock_backtraces/main/logger.c?view=diff&rev=115372&r1=115371&r2=115372
==============================================================================
--- team/mmichelson/lock_backtraces/main/logger.c (original)
+++ team/mmichelson/lock_backtraces/main/logger.c Tue May  6 14:02:06 2008
@@ -1181,27 +1181,29 @@
 void ast_backtrace(void)
 {
 #ifdef HAVE_BKTR
-	int count = 0, i = 0;
-	void **addresses;
+	struct ast_bt *backtrace;
+	int i = 0;
 	char **strings;
 
-	if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) {
-		count = backtrace(addresses, MAX_BACKTRACE_FRAMES);
-		if ((strings = backtrace_symbols(addresses, count))) {
-			ast_debug(1, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
-			for (i = 0; i < count; i++) {
+	if (!(backtrace = ast_bt_create())) {
+		ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
+		return;
+	}
+
+	if ((strings = backtrace_symbols(backtrace->addresses, backtrace->num_frames))) {
+		ast_debug(1, "Got %d backtrace record%c\n", backtrace->num_frames, backtrace->num_frames != 1 ? 's' : ' ');
+		for (i = 0; i < backtrace->num_frames; i++) {
 #if __WORDSIZE == 32
-				ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
+			ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)backtrace->addresses[i], strings[i]);
 #elif __WORDSIZE == 64
-				ast_log(LOG_DEBUG, "#%d: [%016lX] %s\n", i, (unsigned long)addresses[i], strings[i]);
+			ast_log(LOG_DEBUG, "#%d: [%016lX] %s\n", i, (unsigned long)backtrace->addresses[i], strings[i]);
 #endif
-			}
-			free(strings);
-		} else {
-			ast_debug(1, "Could not allocate memory for backtrace\n");
-		}
-		ast_free(addresses);
-	}
+		}
+		free(strings);
+	} else {
+		ast_debug(1, "Could not allocate memory for backtrace\n");
+	}
+	ast_bt_destroy(backtrace);
 #else
 	ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
 #endif




More information about the asterisk-commits mailing list