[Asterisk-code-review] astmm.c: Display backtrace with memory show allocations (...asterisk[17])

George Joseph asteriskteam at digium.com
Tue Sep 24 08:27:50 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/12916 )

Change subject: astmm.c:  Display backtrace with memory show allocations
......................................................................

astmm.c:  Display backtrace with memory show allocations

You can currently capture backtraces of memory allocations but they
only get displayed when you stop asterisk and the atexit hooks
are enabled.  Now, if memory backtrace is on and you issue a
"memory show allocations" CLI command for a specific file, then
a backtrace will show for each allocation that occurred after
you turned "memory backtrace on".  The backtrace display is shown
only when a specific file's allocations are displayed to prevent
a massive CLI dump of every file's allocations.

Change-Id: Ic657afc1fc6ec7205e16eb36a97a611d235a2b4f
---
M main/astmm.c
1 file changed, 17 insertions(+), 6 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/main/astmm.c b/main/astmm.c
index 3a28f5d..cb45a03 100644
--- a/main/astmm.c
+++ b/main/astmm.c
@@ -188,7 +188,7 @@
 		}                                    \
 	} while (0)
 
-static void print_backtrace(struct ast_bt *bt)
+static void print_backtrace(struct ast_bt *bt, struct ast_cli_args *a)
 {
 	int i = 0;
 	struct ast_vector_string *strings;
@@ -198,9 +198,17 @@
 	}
 
 	if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
-		astmm_log("Memory allocation backtrace:\n");
+		if (a) {
+			ast_cli(a->fd, "Memory allocation backtrace:\n");
+		} else {
+			astmm_log("Memory allocation backtrace:\n");
+		}
 		for (i = 3; i < AST_VECTOR_SIZE(strings) - 2; i++) {
-			astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
+			if (a) {
+				ast_cli(a->fd, "#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
+			} else {
+				astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
+			}
 		}
 		ast_bt_free_symbols(strings);
 	}
@@ -314,7 +322,7 @@
 		if (*pos != FREED_MAGIC) {
 			astmm_log("WARNING: Memory corrupted after free of %p allocated at %s %s() line %d\n",
 				reg->data, reg->file, reg->func, reg->lineno);
-			print_backtrace(reg->bt);
+			print_backtrace(reg->bt, NULL);
 			my_do_crash();
 			break;
 		}
@@ -434,14 +442,14 @@
 	if (*fence != FENCE_MAGIC) {
 		astmm_log("WARNING: Low fence violation of %p allocated at %s %s() line %d\n",
 			reg->data, reg->file, reg->func, reg->lineno);
-		print_backtrace(reg->bt);
+		print_backtrace(reg->bt, NULL);
 		my_do_crash();
 	}
 	fence = (unsigned int *) (reg->data + reg->len);
 	if (get_unaligned_uint32(fence) != FENCE_MAGIC) {
 		astmm_log("WARNING: High fence violation of %p allocated at %s %s() line %d\n",
 			reg->data, reg->file, reg->func, reg->lineno);
-		print_backtrace(reg->bt);
+		print_backtrace(reg->bt, NULL);
 		my_do_crash();
 	}
 }
@@ -880,6 +888,9 @@
 			ast_cli(a->fd, "%10u bytes allocated%s by %20s() line %5u of %s\n",
 				(unsigned int) reg->len, reg->cache ? " (cache)" : "",
 				reg->func, reg->lineno, reg->file);
+			if (reg->bt && !ast_strlen_zero(fn)) {
+				print_backtrace(reg->bt, a);
+			}
 
 			selected_len += reg->len;
 			if (reg->cache) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12916
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: Ic657afc1fc6ec7205e16eb36a97a611d235a2b4f
Gerrit-Change-Number: 12916
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190924/0fa03b4b/attachment-0001.html>


More information about the asterisk-code-review mailing list