<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12916">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">astmm.c: Display backtrace with memory show allocations<br><br>You can currently capture backtraces of memory allocations but they<br>only get displayed when you stop asterisk and the atexit hooks<br>are enabled. Now, if memory backtrace is on and you issue a<br>"memory show allocations" CLI command for a specific file, then<br>a backtrace will show for each allocation that occurred after<br>you turned "memory backtrace on". The backtrace display is shown<br>only when a specific file's allocations are displayed to prevent<br>a massive CLI dump of every file's allocations.<br><br>Change-Id: Ic657afc1fc6ec7205e16eb36a97a611d235a2b4f<br>---<br>M main/astmm.c<br>1 file changed, 17 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/astmm.c b/main/astmm.c</span><br><span>index 3a28f5d..cb45a03 100644</span><br><span>--- a/main/astmm.c</span><br><span>+++ b/main/astmm.c</span><br><span>@@ -188,7 +188,7 @@</span><br><span> } \</span><br><span> } while (0)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void print_backtrace(struct ast_bt *bt)</span><br><span style="color: hsl(120, 100%, 40%);">+static void print_backtrace(struct ast_bt *bt, struct ast_cli_args *a)</span><br><span> {</span><br><span> int i = 0;</span><br><span> struct ast_vector_string *strings;</span><br><span>@@ -198,9 +198,17 @@</span><br><span> }</span><br><span> </span><br><span> if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {</span><br><span style="color: hsl(0, 100%, 40%);">- astmm_log("Memory allocation backtrace:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Memory allocation backtrace:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ astmm_log("Memory allocation backtrace:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> for (i = 3; i < AST_VECTOR_SIZE(strings) - 2; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> ast_bt_free_symbols(strings);</span><br><span> }</span><br><span>@@ -314,7 +322,7 @@</span><br><span> if (*pos != FREED_MAGIC) {</span><br><span> astmm_log("WARNING: Memory corrupted after free of %p allocated at %s %s() line %d\n",</span><br><span> reg->data, reg->file, reg->func, reg->lineno);</span><br><span style="color: hsl(0, 100%, 40%);">- print_backtrace(reg->bt);</span><br><span style="color: hsl(120, 100%, 40%);">+ print_backtrace(reg->bt, NULL);</span><br><span> my_do_crash();</span><br><span> break;</span><br><span> }</span><br><span>@@ -434,14 +442,14 @@</span><br><span> if (*fence != FENCE_MAGIC) {</span><br><span> astmm_log("WARNING: Low fence violation of %p allocated at %s %s() line %d\n",</span><br><span> reg->data, reg->file, reg->func, reg->lineno);</span><br><span style="color: hsl(0, 100%, 40%);">- print_backtrace(reg->bt);</span><br><span style="color: hsl(120, 100%, 40%);">+ print_backtrace(reg->bt, NULL);</span><br><span> my_do_crash();</span><br><span> }</span><br><span> fence = (unsigned int *) (reg->data + reg->len);</span><br><span> if (get_unaligned_uint32(fence) != FENCE_MAGIC) {</span><br><span> astmm_log("WARNING: High fence violation of %p allocated at %s %s() line %d\n",</span><br><span> reg->data, reg->file, reg->func, reg->lineno);</span><br><span style="color: hsl(0, 100%, 40%);">- print_backtrace(reg->bt);</span><br><span style="color: hsl(120, 100%, 40%);">+ print_backtrace(reg->bt, NULL);</span><br><span> my_do_crash();</span><br><span> }</span><br><span> }</span><br><span>@@ -880,6 +888,9 @@</span><br><span> ast_cli(a->fd, "%10u bytes allocated%s by %20s() line %5u of %s\n",</span><br><span> (unsigned int) reg->len, reg->cache ? " (cache)" : "",</span><br><span> reg->func, reg->lineno, reg->file);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (reg->bt && !ast_strlen_zero(fn)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ print_backtrace(reg->bt, a);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> selected_len += reg->len;</span><br><span> if (reg->cache) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12916">change 12916</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/12916"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: Ic657afc1fc6ec7205e16eb36a97a611d235a2b4f </div>
<div style="display:none"> Gerrit-Change-Number: 12916 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>