[asterisk-commits] astobj2: Add backtrace to log bad ao2. (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 11 13:57:54 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: astobj2: Add backtrace to log_bad_ao2.
......................................................................


astobj2: Add backtrace to log_bad_ao2.

* Compile __ast_assert_failed unconditionally.
* Use __ast_assert_failed to log messages from log_bad_ao2
* Remove calls to ast_assert(0) that happen after log_bad_ao2 was run.

Change-Id: I48f1af44b2718ad74a421ff75cb6397b924a9751
---
M include/asterisk/utils.h
M main/astobj2.c
M main/astobj2_container.c
M main/astobj2_hash.c
M main/astobj2_rbtree.c
M main/utils.c
6 files changed, 42 insertions(+), 37 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c3df477..a504a5d 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -849,8 +849,10 @@
 #define DO_CRASH_NORETURN
 #endif
 
+void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str,
+	const char *file, int line, const char *function);
+
 #ifdef AST_DEVMODE
-void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function);
 #define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
 {
diff --git a/main/astobj2.c b/main/astobj2.c
index 1bb5237..f5175ea 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -116,21 +116,17 @@
 	struct astobj2 *p;
 
 	if (!user_data) {
-		ast_log(LOG_ERROR, "user_data is NULL\n");
+		__ast_assert_failed(0, "user_data is NULL", __FILE__, __LINE__, __PRETTY_FUNCTION__);
 		return NULL;
 	}
 
 	p = (struct astobj2 *) ((char *) user_data - sizeof(*p));
 	if (AO2_MAGIC != p->priv_data.magic) {
-		if (p->priv_data.magic) {
-			ast_log(LOG_ERROR, "bad magic number 0x%x for object %p\n",
-				p->priv_data.magic, user_data);
-		} else {
-			ast_log(LOG_ERROR,
-				"bad magic number for object %p. Object is likely destroyed.\n",
-				user_data);
-		}
-		ast_assert(0);
+		char bad_magic[100];
+
+		snprintf(bad_magic, sizeof(bad_magic), "bad magic number 0x%x for object %p",
+			p->priv_data.magic, user_data);
+		__ast_assert_failed(0, bad_magic, __FILE__, __LINE__, __PRETTY_FUNCTION__);
 		return NULL;
 	}
 
@@ -157,7 +153,6 @@
 	int res = 0;
 
 	if (obj == NULL) {
-		ast_assert(0);
 		return -1;
 	}
 
@@ -216,7 +211,6 @@
 	int current_value;
 
 	if (obj == NULL) {
-		ast_assert(0);
 		return -1;
 	}
 
@@ -265,7 +259,6 @@
 	int res = 0;
 
 	if (obj == NULL) {
-		ast_assert(0);
 		return -1;
 	}
 
@@ -385,7 +378,6 @@
 	struct astobj2_lock *obj_mutex;
 
 	if (obj == NULL) {
-		ast_assert(0);
 		return NULL;
 	}
 
@@ -409,7 +401,6 @@
 	int ret;
 
 	if (obj == NULL) {
-		ast_assert(0);
 		return -1;
 	}
 
@@ -502,10 +493,6 @@
 				delta, ast_get_tid(), file, line, func, old_refcount, tag);
 			fflush(ref_log);
 		}
-	}
-
-	if (obj == NULL) {
-		ast_assert(0);
 	}
 
 	return old_refcount;
diff --git a/main/astobj2_container.c b/main/astobj2_container.c
index 5a27a0a..466c103 100644
--- a/main/astobj2_container.c
+++ b/main/astobj2_container.c
@@ -103,8 +103,11 @@
 	enum ao2_lock_req orig_lock;
 	struct ao2_container_node *node;
 
-	if (!is_ao2_object(obj_new) || !is_ao2_object(self)
-		|| !self->v_table || !self->v_table->new_node || !self->v_table->insert) {
+	if (!is_ao2_object(obj_new) || !is_ao2_object(self)) {
+		return 0;
+	}
+
+	if (!self->v_table || !self->v_table->new_node || !self->v_table->insert) {
 		/* Sanity checks. */
 		ast_assert(0);
 		return 0;
@@ -187,8 +190,6 @@
 	const char *tag, const char *file, int line, const char *func)
 {
 	if (!is_ao2_object(user_data)) {
-		/* Sanity checks. */
-		ast_assert(0);
 		return NULL;
 	}
 
@@ -202,8 +203,6 @@
 void *__ao2_unlink(struct ao2_container *c, void *user_data, int flags)
 {
 	if (!is_ao2_object(user_data)) {
-		/* Sanity checks. */
-		ast_assert(0);
 		return NULL;
 	}
 
@@ -268,7 +267,11 @@
 	struct ao2_container *multi_container = NULL;
 	struct ao2_iterator *multi_iterator = NULL;
 
-	if (!is_ao2_object(self) || !self->v_table || !self->v_table->traverse_first
+	if (!is_ao2_object(self)) {
+		return NULL;
+	}
+
+	if (!self->v_table || !self->v_table->traverse_first
 		|| !self->v_table->traverse_next) {
 		/* Sanity checks. */
 		ast_assert(0);
@@ -512,7 +515,6 @@
 {
 	if (!is_ao2_object(iter->c)) {
 		ast_log(LOG_ERROR, "Iterator container is not valid.\n");
-		ast_assert(0);
 		return;
 	}
 
@@ -577,7 +579,11 @@
 	struct ao2_container_node *node;
 	void *ret;
 
-	if (!is_ao2_object(iter->c) || !iter->c->v_table || !iter->c->v_table->iterator_next) {
+	if (!is_ao2_object(iter->c)) {
+		return NULL;
+	}
+
+	if (!iter->c->v_table || !iter->c->v_table->iterator_next) {
 		/* Sanity checks. */
 		ast_assert(0);
 		return NULL;
@@ -748,7 +754,11 @@
 	int failed;
 
 	/* Create the clone container with the same properties as the original. */
-	if (!is_ao2_object(orig) || !orig->v_table || !orig->v_table->alloc_empty_clone) {
+	if (!is_ao2_object(orig)) {
+		return NULL;
+	}
+
+	if (!orig->v_table || !orig->v_table->alloc_empty_clone) {
 		/* Sanity checks. */
 		ast_assert(0);
 		return NULL;
@@ -779,7 +789,11 @@
 	int failed;
 
 	/* Create the clone container with the same properties as the original. */
-	if (!is_ao2_object(orig) || !orig->v_table || !orig->v_table->alloc_empty_clone_debug) {
+	if (!is_ao2_object(orig)) {
+		return NULL;
+	}
+
+	if (!orig->v_table || !orig->v_table->alloc_empty_clone_debug) {
 		/* Sanity checks. */
 		ast_assert(0);
 		return NULL;
diff --git a/main/astobj2_hash.c b/main/astobj2_hash.c
index 341ff79..f5c6787 100644
--- a/main/astobj2_hash.c
+++ b/main/astobj2_hash.c
@@ -186,7 +186,9 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_hash *) doomed->common.my_container;
-		ast_assert(is_ao2_object(my_container));
+#if defined(AST_DEVMODE)
+		is_ao2_object(my_container);
+#endif
 
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
diff --git a/main/astobj2_rbtree.c b/main/astobj2_rbtree.c
index a8d5e3a..4362b83 100644
--- a/main/astobj2_rbtree.c
+++ b/main/astobj2_rbtree.c
@@ -878,7 +878,9 @@
 		 * same node.
 		 */
 		my_container = (struct ao2_container_rbtree *) doomed->common.my_container;
-		ast_assert(is_ao2_object(my_container));
+#if defined(AST_DEVMODE)
+		is_ao2_object(my_container);
+#endif
 
 		__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
 
diff --git a/main/utils.c b/main/utils.c
index 1a034c1..af0ee7f 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2437,17 +2437,16 @@
 #endif	/* defined(DO_CRASH) */
 }
 
-#if defined(AST_DEVMODE)
 void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function)
 {
 	/*
 	 * Attempt to put it into the logger, but hope that at least
 	 * someone saw the message on stderr ...
 	 */
-	ast_log(__LOG_ERROR, file, line, function, "FRACK!, Failed assertion %s (%d)\n",
-		condition_str, condition);
 	fprintf(stderr, "FRACK!, Failed assertion %s (%d) at line %d in %s of %s\n",
 		condition_str, condition, line, function, file);
+	ast_log(__LOG_ERROR, file, line, function, "FRACK!, Failed assertion %s (%d)\n",
+		condition_str, condition);
 
 	/* Generate a backtrace for the assert */
 	ast_log_backtrace();
@@ -2460,7 +2459,6 @@
 	usleep(1);
 	ast_do_crash();
 }
-#endif	/* defined(AST_DEVMODE) */
 
 char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
 {

-- 
To view, visit https://gerrit.asterisk.org/4037
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I48f1af44b2718ad74a421ff75cb6397b924a9751
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-commits mailing list