<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10702">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">backtrace: Refactor ast_bt_get_symbols so it doesn't crash<br><br>We've been seeing crashes in libbfd when we attempt to generate<br>a stack trace from multiple threads. It turns out that libbfd<br>is NOT thread-safe. It can cache the bfd structure and give it to<br>multiple threads without protecting itself. To get around this,<br>we've added a global mutex around the bfd functions and also have<br>refactored the use of those functions to be more efficient and<br>to provide more information about inlined functions.<br><br>Also added a few more tests to test_pbx.c. One just calls<br>ast_assert() and the other calls ast_log_backtrace(). Neither are<br>run by default.<br><br>WARNING: This change necessitated changing the return value of<br>ast_bt_get_symbols() from an array of strings to a VECTOR of<br>strings. However, the use of this function outside Asterisk is not<br>likely.<br><br>ASTERISK-28140<br><br>Change-Id: I79d02862ddaa2423a0809caa4b3b85c128131621<br>---<br>M CHANGES<br>M UPGRADE.txt<br>M include/asterisk/backtrace.h<br>M main/astmm.c<br>M main/backtrace.c<br>M main/logger.c<br>M main/utils.c<br>M tests/test_pbx.c<br>M utils/ael_main.c<br>M utils/check_expr.c<br>M utils/conf2ael.c<br>11 files changed, 332 insertions(+), 183 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/10702/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CHANGES b/CHANGES</span><br><span>index 95d3303..c4fcf38 100644</span><br><span>--- a/CHANGES</span><br><span>+++ b/CHANGES</span><br><span>@@ -9,6 +9,15 @@</span><br><span> ==============================================================================</span><br><span> </span><br><span> ------------------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+--- Functionality changes from Asterisk 13.21-cert3 to Asterisk 13.21-cert4---</span><br><span style="color: hsl(120, 100%, 40%);">+------------------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Core</span><br><span style="color: hsl(120, 100%, 40%);">+------------------</span><br><span style="color: hsl(120, 100%, 40%);">+ * ast_bt_get_symbols() now returns a vector of strings instead of an</span><br><span style="color: hsl(120, 100%, 40%);">+ array of strings. This must be freed with ast_bt_free_symbols.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+------------------------------------------------------------------------------</span><br><span> --- Functionality changes from Asterisk 13.21.0 to Asterisk 13.22.0 ----------</span><br><span> ------------------------------------------------------------------------------</span><br><span> </span><br><span>diff --git a/UPGRADE.txt b/UPGRADE.txt</span><br><span>index 133e8a8..c0d1dca 100644</span><br><span>--- a/UPGRADE.txt</span><br><span>+++ b/UPGRADE.txt</span><br><span>@@ -21,6 +21,13 @@</span><br><span> === UPGRADE-12.txt -- Upgrade info for 11 to 12</span><br><span> ===========================================================</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+From certified/13.21-cert3 to certified/13.21-cert4:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Core</span><br><span style="color: hsl(120, 100%, 40%);">+------------------</span><br><span style="color: hsl(120, 100%, 40%);">+ * ast_bt_get_symbols() now returns a vector of strings instead of an</span><br><span style="color: hsl(120, 100%, 40%);">+ array of strings. This must be freed with ast_bt_free_symbols.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> From 13.20.0 to 13.21.0:</span><br><span> </span><br><span> app_dial</span><br><span>diff --git a/include/asterisk/backtrace.h b/include/asterisk/backtrace.h</span><br><span>index 95358bf..fdacf98 100644</span><br><span>--- a/include/asterisk/backtrace.h</span><br><span>+++ b/include/asterisk/backtrace.h</span><br><span>@@ -33,11 +33,13 @@</span><br><span> #define ast_bt_create() __ast_bt_create()</span><br><span> #define ast_bt_destroy(bt) __ast_bt_destroy((bt))</span><br><span> #define ast_bt_get_symbols(addresses, num_frames) __ast_bt_get_symbols((addresses), (num_frames))</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_bt_free_symbols(string_vector) __ast_bt_free_symbols((string_vector))</span><br><span> #else</span><br><span> #define ast_bt_get_addresses(bt) 0</span><br><span> #define ast_bt_create() NULL</span><br><span> #define ast_bt_destroy(bt) NULL</span><br><span> #define ast_bt_get_symbols(addresses, num_frames) NULL</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_bt_free_symbols(string_vector) NULL</span><br><span> #endif</span><br><span> </span><br><span> /* \brief</span><br><span>@@ -86,11 +88,24 @@</span><br><span> *</span><br><span> * \param addresses A list of addresses, such as the ->addresses structure element of struct ast_bt.</span><br><span> * \param num_frames Number of addresses in the addresses list</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span> * \retval NULL Unable to allocate memory</span><br><span style="color: hsl(0, 100%, 40%);">- * \return List of strings. Free the entire list with a single ast_std_free call.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return Vector of strings. Free with ast_bt_free_symbols</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note The first frame in the addresses array will usually point to __ast_bt_create</span><br><span style="color: hsl(120, 100%, 40%);">+ * so when printing the symbols you may wish to start at position 1 rather than 0.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span> * \since 1.6.2.16</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames);</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* \brief Free symbols returned from ast_bt_get_symbols</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param symbols The symbol string vector</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.24.0</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void __ast_bt_free_symbols(struct ast_vector_string *symbols);</span><br><span> </span><br><span> #endif /* HAVE_BKTR */</span><br><span> </span><br><span>diff --git a/main/astmm.c b/main/astmm.c</span><br><span>index 2134a1f..7dafbac 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> static void print_backtrace(struct ast_bt *bt)</span><br><span> {</span><br><span> int i = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- char **strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *strings;</span><br><span> </span><br><span> if (!bt) {</span><br><span> return;</span><br><span>@@ -196,10 +196,10 @@</span><br><span> </span><br><span> if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {</span><br><span> astmm_log("Memory allocation backtrace:\n");</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 3; i < bt->num_frames - 2; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- astmm_log("#%d: [%p] %s\n", i - 3, bt->addresses[i], strings[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 3; i < AST_VECTOR_SIZE(strings) - 2; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_bt_free_symbols(strings);</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>diff --git a/main/backtrace.c b/main/backtrace.c</span><br><span>index cb1a870..394a12c 100644</span><br><span>--- a/main/backtrace.c</span><br><span>+++ b/main/backtrace.c</span><br><span>@@ -26,12 +26,38 @@</span><br><span> <support_level>core</support_level></span><br><span> ***/</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk.h"</span><br><span style="color: hsl(0, 100%, 40%);">-ASTERISK_FILE_VERSION(__FILE__, "$Revision$");</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Block automatic include of asterisk/lock.h to allow use of pthread_mutex</span><br><span style="color: hsl(120, 100%, 40%);">+ * functions directly. We don't need or want the lock.h overhead.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define _ASTERISK_LOCK_H</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"</span><br><span> #include "asterisk/backtrace.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/utils.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/strings.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * The astmm ast_ memory management functions can cause ast_bt_get_symbols</span><br><span style="color: hsl(120, 100%, 40%);">+ * to be invoked so we must not use them. To use the libc functions, we</span><br><span style="color: hsl(120, 100%, 40%);">+ * could call the ast_std_ functions but the vector macros call ast_calloc,</span><br><span style="color: hsl(120, 100%, 40%);">+ * ast_free and ast_malloc so it just makes sense to undef the standard</span><br><span style="color: hsl(120, 100%, 40%);">+ * function overrides and use them directly.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef malloc</span><br><span style="color: hsl(120, 100%, 40%);">+#undef calloc</span><br><span style="color: hsl(120, 100%, 40%);">+#undef strdup</span><br><span style="color: hsl(120, 100%, 40%);">+#undef free</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * As stated above, the vector macros call the ast_ functions so</span><br><span style="color: hsl(120, 100%, 40%);">+ * we need to remap those back to the libc ones.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef ast_free</span><br><span style="color: hsl(120, 100%, 40%);">+#undef ast_calloc</span><br><span style="color: hsl(120, 100%, 40%);">+#undef ast_malloc</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_free(x) free(x)</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_calloc(n, x) calloc(n, x)</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_malloc(x) malloc(x)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/vector.h"</span><br><span> </span><br><span> #ifdef HAVE_BKTR</span><br><span> #include <execinfo.h></span><br><span>@@ -40,9 +66,14 @@</span><br><span> #include <bfd.h></span><br><span> #endif</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include <pthread.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* simple definition of S_OR so we don't have include strings.h */</span><br><span style="color: hsl(120, 100%, 40%);">+#define S_OR(a, b) (a && a[0] != '\0') ? a : b</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_bt *__ast_bt_create(void)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_bt *bt = ast_std_calloc(1, sizeof(*bt));</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_bt *bt = calloc(1, sizeof(*bt));</span><br><span> </span><br><span> if (!bt) {</span><br><span> return NULL;</span><br><span>@@ -63,164 +94,217 @@</span><br><span> void *__ast_bt_destroy(struct ast_bt *bt)</span><br><span> {</span><br><span> if (bt && bt->alloced) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(bt);</span><br><span style="color: hsl(120, 100%, 40%);">+ free(bt);</span><br><span> }</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- char **strings;</span><br><span style="color: hsl(0, 100%, 40%);">-#if defined(BETTER_BACKTRACES)</span><br><span style="color: hsl(0, 100%, 40%);">- int stackfr;</span><br><span style="color: hsl(0, 100%, 40%);">- bfd *bfdobj; /* bfd.h */</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef BETTER_BACKTRACES</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct bfd_data {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *return_strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_vma pc; /* bfd.h */</span><br><span style="color: hsl(120, 100%, 40%);">+ asymbol **syms; /* bfd.h */</span><br><span> Dl_info dli; /* dlfcn.h */</span><br><span style="color: hsl(0, 100%, 40%);">- long allocsize;</span><br><span style="color: hsl(0, 100%, 40%);">- asymbol **syms = NULL; /* bfd.h */</span><br><span style="color: hsl(0, 100%, 40%);">- bfd_vma offset; /* bfd.h */</span><br><span style="color: hsl(0, 100%, 40%);">- const char *lastslash;</span><br><span style="color: hsl(0, 100%, 40%);">- asection *section;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *libname;</span><br><span style="color: hsl(120, 100%, 40%);">+ int dynamic;</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_syms;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *msg;</span><br><span style="color: hsl(120, 100%, 40%);">+ int found;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define MSG_BUFF_LEN 1024</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void process_section(bfd *bfdobj, asection *section, void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct bfd_data *data = obj;</span><br><span> const char *file, *func;</span><br><span> unsigned int line;</span><br><span style="color: hsl(0, 100%, 40%);">- char address_str[128];</span><br><span style="color: hsl(0, 100%, 40%);">- char msg[1024];</span><br><span style="color: hsl(0, 100%, 40%);">- size_t strings_size;</span><br><span style="color: hsl(0, 100%, 40%);">- size_t *eachlen;</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_vma offset;</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_vma vma;</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_size_type size;</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_boolean line_found = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *fn;</span><br><span style="color: hsl(120, 100%, 40%);">+ int inlined = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#if defined(BETTER_BACKTRACES)</span><br><span style="color: hsl(0, 100%, 40%);">- strings_size = num_frames * sizeof(*strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ offset = data->pc - (data->dynamic ? (bfd_vma) data->dli.dli_fbase : 0);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- eachlen = ast_std_calloc(num_frames, sizeof(*eachlen));</span><br><span style="color: hsl(0, 100%, 40%);">- strings = ast_std_calloc(num_frames, sizeof(*strings));</span><br><span style="color: hsl(0, 100%, 40%);">- if (!eachlen || !strings) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(eachlen);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(bfd_get_section_flags(bfdobj, section) & SEC_ALLOC)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ vma = bfd_get_section_vma(bfdobj, section);</span><br><span style="color: hsl(120, 100%, 40%);">+ size = bfd_get_section_size(section);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (offset < vma || offset >= vma + size) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Not in this section */</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ line_found = bfd_find_nearest_line(bfdobj, section, data->syms, offset - vma, &file,</span><br><span style="color: hsl(120, 100%, 40%);">+ &func, &line);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!line_found) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * If we find a line, we will want to continue calling bfd_find_inliner_info</span><br><span style="color: hsl(120, 100%, 40%);">+ * to capture any inlined functions that don't have their own stack frames.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ do {</span><br><span style="color: hsl(120, 100%, 40%);">+ data->found++;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* file can possibly be null even with a success result from bfd_find_nearest_line */</span><br><span style="color: hsl(120, 100%, 40%);">+ file = file ? file : "";</span><br><span style="color: hsl(120, 100%, 40%);">+ fn = strrchr(file, '/');</span><br><span style="color: hsl(120, 100%, 40%);">+#define FMT_INLINED "[%s] %s %s:%u %s()"</span><br><span style="color: hsl(120, 100%, 40%);">+#define FMT_NOT_INLINED "[%p] %s %s:%u %s()"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(data->msg, MSG_BUFF_LEN, inlined ? FMT_INLINED : FMT_NOT_INLINED,</span><br><span style="color: hsl(120, 100%, 40%);">+ inlined ? "inlined" : (char *)data->pc,</span><br><span style="color: hsl(120, 100%, 40%);">+ data->libname,</span><br><span style="color: hsl(120, 100%, 40%);">+ fn ? fn + 1 : file,</span><br><span style="color: hsl(120, 100%, 40%);">+ line, S_OR(func, "???"));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_VECTOR_APPEND(data->return_strings, strdup(data->msg))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ inlined++;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Let's see if there are any inlined functions */</span><br><span style="color: hsl(120, 100%, 40%);">+ } while (bfd_find_inliner_info(bfdobj, &file, &func, &line));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *return_strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ int stackfr;</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd *bfdobj;</span><br><span style="color: hsl(120, 100%, 40%);">+ long allocsize;</span><br><span style="color: hsl(120, 100%, 40%);">+ char msg[MSG_BUFF_LEN];</span><br><span style="color: hsl(120, 100%, 40%);">+ static pthread_mutex_t bfd_mutex = PTHREAD_MUTEX_INITIALIZER;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return_strings = malloc(sizeof(struct ast_vector_string));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!return_strings) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_VECTOR_INIT(return_strings, num_frames)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ free(return_strings);</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span> for (stackfr = 0; stackfr < num_frames; stackfr++) {</span><br><span style="color: hsl(0, 100%, 40%);">- int found = 0, symbolcount;</span><br><span style="color: hsl(120, 100%, 40%);">+ int symbolcount;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct bfd_data data = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .return_strings = return_strings,</span><br><span style="color: hsl(120, 100%, 40%);">+ .msg = msg,</span><br><span style="color: hsl(120, 100%, 40%);">+ .pc = (bfd_vma)addresses[stackfr],</span><br><span style="color: hsl(120, 100%, 40%);">+ .found = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ .dynamic = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ };</span><br><span> </span><br><span> msg[0] = '\0';</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!dladdr(addresses[stackfr], &dli)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dladdr((void *)data.pc, &data.dli)) {</span><br><span> continue;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (strcmp(dli.dli_fname, "asterisk") == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- char asteriskpath[256];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(dli.dli_fname = ast_utils_which("asterisk", asteriskpath, sizeof(asteriskpath)))) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* This will fail to find symbols */</span><br><span style="color: hsl(0, 100%, 40%);">- dli.dli_fname = "asterisk";</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ data.libname = strrchr(data.dli.dli_fname, '/');</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!data.libname) {</span><br><span style="color: hsl(120, 100%, 40%);">+ data.libname = data.dli.dli_fname;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ data.libname++;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- lastslash = strrchr(dli.dli_fname, '/');</span><br><span style="color: hsl(0, 100%, 40%);">- if ((bfdobj = bfd_openr(dli.dli_fname, NULL)) &&</span><br><span style="color: hsl(0, 100%, 40%);">- bfd_check_format(bfdobj, bfd_object) &&</span><br><span style="color: hsl(0, 100%, 40%);">- (allocsize = bfd_get_symtab_upper_bound(bfdobj)) > 0 &&</span><br><span style="color: hsl(0, 100%, 40%);">- (syms = ast_std_malloc(allocsize)) &&</span><br><span style="color: hsl(0, 100%, 40%);">- (symbolcount = bfd_canonicalize_symtab(bfdobj, syms))) {</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (bfdobj->flags & DYNAMIC) {</span><br><span style="color: hsl(0, 100%, 40%);">- offset = addresses[stackfr] - dli.dli_fbase;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- offset = addresses[stackfr] - (void *) 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ pthread_mutex_lock(&bfd_mutex);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Using do while(0) here makes it easier to escape and clean up */</span><br><span style="color: hsl(120, 100%, 40%);">+ do {</span><br><span style="color: hsl(120, 100%, 40%);">+ bfdobj = bfd_openr(data.dli.dli_fname, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!bfdobj) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (section = bfdobj->sections; section; section = section->next) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(bfd_get_section_flags(bfdobj, section) & SEC_ALLOC) ||</span><br><span style="color: hsl(0, 100%, 40%);">- section->vma > offset ||</span><br><span style="color: hsl(0, 100%, 40%);">- section->size + section->vma < offset) {</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!bfd_find_nearest_line(bfdobj, section, syms, offset - section->vma, &file, &func, &line)) {</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* file can possibly be null even with a success result from bfd_find_nearest_line */</span><br><span style="color: hsl(0, 100%, 40%);">- file = file ? file : "";</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Stack trace output */</span><br><span style="color: hsl(0, 100%, 40%);">- found++;</span><br><span style="color: hsl(0, 100%, 40%);">- if ((lastslash = strrchr(file, '/'))) {</span><br><span style="color: hsl(0, 100%, 40%);">- const char *prevslash;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (prevslash = lastslash - 1; *prevslash != '/' && prevslash >= file; prevslash--) {</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (prevslash >= file) {</span><br><span style="color: hsl(0, 100%, 40%);">- lastslash = prevslash;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (dli.dli_saddr == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- address_str[0] = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(address_str, sizeof(address_str), " (%p+%lX)",</span><br><span style="color: hsl(0, 100%, 40%);">- dli.dli_saddr,</span><br><span style="color: hsl(0, 100%, 40%);">- (unsigned long) (addresses[stackfr] - dli.dli_saddr));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(msg, sizeof(msg), "%s:%u %s()%s",</span><br><span style="color: hsl(0, 100%, 40%);">- lastslash ? lastslash + 1 : file, line,</span><br><span style="color: hsl(0, 100%, 40%);">- S_OR(func, "???"),</span><br><span style="color: hsl(0, 100%, 40%);">- address_str);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- break; /* out of section iteration */</span><br><span style="color: hsl(120, 100%, 40%);">+ /* bfd_check_format does more than check. It HAS to be called */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!bfd_check_format(bfdobj, bfd_object)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ data.has_syms = !!(bfd_get_file_flags(bfdobj) & HAS_SYMS);</span><br><span style="color: hsl(120, 100%, 40%);">+ data.dynamic = !!(bfd_get_file_flags(bfdobj) & DYNAMIC);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!data.has_syms) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ allocsize = data.dynamic ?</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_get_dynamic_symtab_upper_bound(bfdobj) : bfd_get_symtab_upper_bound(bfdobj);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (allocsize < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ data.syms = malloc(allocsize);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!data.syms) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ symbolcount = data.dynamic ?</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_canonicalize_dynamic_symtab(bfdobj, data.syms) : bfd_canonicalize_symtab(bfdobj, data.syms);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (symbolcount < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ bfd_map_over_sections(bfdobj, process_section, &data);</span><br><span style="color: hsl(120, 100%, 40%);">+ } while(0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (bfdobj) {</span><br><span> bfd_close(bfdobj);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(syms);</span><br><span style="color: hsl(0, 100%, 40%);">- syms = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ free(data.syms);</span><br><span style="color: hsl(120, 100%, 40%);">+ data.syms = NULL;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ pthread_mutex_unlock(&bfd_mutex);</span><br><span> </span><br><span> /* Default output, if we cannot find the information within BFD */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!found) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (dli.dli_saddr == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- address_str[0] = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(address_str, sizeof(address_str), " (%p+%lX)",</span><br><span style="color: hsl(0, 100%, 40%);">- dli.dli_saddr,</span><br><span style="color: hsl(0, 100%, 40%);">- (unsigned long) (addresses[stackfr] - dli.dli_saddr));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(msg, sizeof(msg), "%s %s()%s",</span><br><span style="color: hsl(0, 100%, 40%);">- lastslash ? lastslash + 1 : dli.dli_fname,</span><br><span style="color: hsl(0, 100%, 40%);">- S_OR(dli.dli_sname, "<unknown>"),</span><br><span style="color: hsl(0, 100%, 40%);">- address_str);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(msg)) {</span><br><span style="color: hsl(0, 100%, 40%);">- char **tmp;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- eachlen[stackfr] = strlen(msg) + 1;</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(tmp = ast_std_realloc(strings, strings_size + eachlen[stackfr]))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(strings);</span><br><span style="color: hsl(0, 100%, 40%);">- strings = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- break; /* out of stack frame iteration */</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- strings = tmp;</span><br><span style="color: hsl(0, 100%, 40%);">- strings[stackfr] = (char *) strings + strings_size;</span><br><span style="color: hsl(0, 100%, 40%);">- strcpy(strings[stackfr], msg);/* Safe since we just allocated the room. */</span><br><span style="color: hsl(0, 100%, 40%);">- strings_size += eachlen[stackfr];</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!data.found) {</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(msg, sizeof(msg), "%s %s()",</span><br><span style="color: hsl(120, 100%, 40%);">+ data.libname,</span><br><span style="color: hsl(120, 100%, 40%);">+ S_OR(data.dli.dli_sname, "<unknown>"));</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_APPEND(return_strings, strdup(msg));</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (strings) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Recalculate the offset pointers because of the reallocs. */</span><br><span style="color: hsl(0, 100%, 40%);">- strings[0] = (char *) strings + num_frames * sizeof(*strings);</span><br><span style="color: hsl(0, 100%, 40%);">- for (stackfr = 1; stackfr < num_frames; stackfr++) {</span><br><span style="color: hsl(0, 100%, 40%);">- strings[stackfr] = strings[stackfr - 1] + eachlen[stackfr - 1];</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(eachlen);</span><br><span style="color: hsl(120, 100%, 40%);">+ return return_strings;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#else /* !defined(BETTER_BACKTRACES) */</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char **strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *return_strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return_strings = malloc(sizeof(struct ast_vector_string));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!return_strings) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_VECTOR_INIT(return_strings, num_frames)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ free(return_strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> strings = backtrace_symbols(addresses, num_frames);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif /* defined(BETTER_BACKTRACES) */</span><br><span style="color: hsl(0, 100%, 40%);">- return strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strings) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < num_frames; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_APPEND(return_strings, strdup(strings[i]));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ free(strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return return_strings;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* BETTER_BACKTRACES */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void __ast_bt_free_symbols(struct ast_vector_string *symbols)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_CALLBACK_VOID(symbols, free);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_PTR_FREE(symbols);</span><br><span> }</span><br><span> </span><br><span> #endif /* HAVE_BKTR */</span><br><span>diff --git a/main/logger.c b/main/logger.c</span><br><span>index 89a40f0..b6a8790 100644</span><br><span>--- a/main/logger.c</span><br><span>+++ b/main/logger.c</span><br><span>@@ -1432,6 +1432,9 @@</span><br><span> /* Console channels */</span><br><span> } else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) {</span><br><span> char linestr[128];</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_file = !ast_strlen_zero(logmsg->file);</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_line = (logmsg->line > 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_func = !ast_strlen_zero(logmsg->function);</span><br><span> </span><br><span> /* If the level is verbose, then skip it */</span><br><span> if (logmsg->level == __LOG_VERBOSE)</span><br><span>@@ -1440,15 +1443,17 @@</span><br><span> /* Turn the numerical line number into a string */</span><br><span> snprintf(linestr, sizeof(linestr), "%d", logmsg->line);</span><br><span> /* Build string to print out */</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(buf, sizeof(buf), "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT ":" COLORIZE_FMT " " COLORIZE_FMT ": %s",</span><br><span style="color: hsl(0, 100%, 40%);">- logmsg->date,</span><br><span style="color: hsl(0, 100%, 40%);">- COLORIZE(colors[logmsg->level], 0, logmsg->level_name),</span><br><span style="color: hsl(0, 100%, 40%);">- logmsg->lwp,</span><br><span style="color: hsl(0, 100%, 40%);">- call_identifier_str,</span><br><span style="color: hsl(0, 100%, 40%);">- COLORIZE(COLOR_BRWHITE, 0, logmsg->file),</span><br><span style="color: hsl(0, 100%, 40%);">- COLORIZE(COLOR_BRWHITE, 0, linestr),</span><br><span style="color: hsl(0, 100%, 40%);">- COLORIZE(COLOR_BRWHITE, 0, logmsg->function),</span><br><span style="color: hsl(0, 100%, 40%);">- logmsg->message);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buf, sizeof(buf), "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT "%s" COLORIZE_FMT " " COLORIZE_FMT "%s %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ logmsg->date,</span><br><span style="color: hsl(120, 100%, 40%);">+ COLORIZE(colors[logmsg->level], 0, logmsg->level_name),</span><br><span style="color: hsl(120, 100%, 40%);">+ logmsg->lwp,</span><br><span style="color: hsl(120, 100%, 40%);">+ call_identifier_str,</span><br><span style="color: hsl(120, 100%, 40%);">+ COLORIZE(COLOR_BRWHITE, 0, has_file ? logmsg->file : ""),</span><br><span style="color: hsl(120, 100%, 40%);">+ has_file ? ":" : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ COLORIZE(COLOR_BRWHITE, 0, has_line ? linestr : ""),</span><br><span style="color: hsl(120, 100%, 40%);">+ COLORIZE(COLOR_BRWHITE, 0, has_func ? logmsg->function : ""),</span><br><span style="color: hsl(120, 100%, 40%);">+ has_func ? ":" : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ logmsg->message);</span><br><span> /* Print out */</span><br><span> ast_console_puts_mutable(buf, logmsg->level);</span><br><span> /* File channels */</span><br><span>@@ -2043,7 +2048,7 @@</span><br><span> #ifdef HAVE_BKTR</span><br><span> struct ast_bt *bt;</span><br><span> int i = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- char **strings;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *strings;</span><br><span> </span><br><span> if (!(bt = ast_bt_create())) {</span><br><span> ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");</span><br><span>@@ -2051,14 +2056,21 @@</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%);">- ast_verbose("Got %d backtrace record%c\n", bt->num_frames, bt->num_frames != 1 ? 's' : ' ');</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 3; i < bt->num_frames - 2; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_verbose("#%d: [%p] %s\n", i - 3, bt->addresses[i], strings[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ int count = AST_VECTOR_SIZE(strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *buf = ast_str_create(bt->num_frames * 64);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log_safe(__LOG_ERROR, NULL, 0, NULL, "%s\n", ast_str_buffer(buf));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(buf);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(strings);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_bt_free_symbols(strings);</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_verbose("Could not allocate memory for backtrace\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");</span><br><span> }</span><br><span> ast_bt_destroy(bt);</span><br><span> #else</span><br><span>diff --git a/main/utils.c b/main/utils.c</span><br><span>index 56bcdd9..54a06af 100644</span><br><span>--- a/main/utils.c</span><br><span>+++ b/main/utils.c</span><br><span>@@ -965,7 +965,7 @@</span><br><span> #ifdef HAVE_BKTR</span><br><span> static void append_backtrace_information(struct ast_str **str, struct ast_bt *bt)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char **symbols;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *symbols;</span><br><span> int num_frames;</span><br><span> </span><br><span> if (!bt) {</span><br><span>@@ -979,11 +979,11 @@</span><br><span> if ((symbols = ast_bt_get_symbols(bt->addresses, num_frames))) {</span><br><span> int frame_iterator;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (frame_iterator = 0; frame_iterator < num_frames; ++frame_iterator) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_str_append(str, 0, "\t%s\n", symbols[frame_iterator]);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (frame_iterator = 1; frame_iterator < AST_VECTOR_SIZE(symbols); ++frame_iterator) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(str, 0, "\t%s\n", AST_VECTOR_GET(symbols, frame_iterator));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_std_free(symbols);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_bt_free_symbols(symbols);</span><br><span> } else {</span><br><span> ast_str_append(str, 0, "\tCouldn't retrieve backtrace symbols\n");</span><br><span> }</span><br><span>diff --git a/tests/test_pbx.c b/tests/test_pbx.c</span><br><span>index df6b88d..a247ff3 100644</span><br><span>--- a/tests/test_pbx.c</span><br><span>+++ b/tests/test_pbx.c</span><br><span>@@ -345,8 +345,50 @@</span><br><span> return AST_TEST_FAIL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(call_assert)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ info->name = "CALL_ASSERT";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->category = "/DO_NOT_RUN/";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->summary = "Calls ast_asert()!!! (will only be run if explicitly called)";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->description = "Calls ast_asert()!!! (will only be run if explicitly called). "</span><br><span style="color: hsl(120, 100%, 40%);">+ "This test is mainly used for testing CI and tool failure scenarios.";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->explicit_only = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(call_backtrace)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ info->name = "CALL_BACKTRACE";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->category = "/DO_NOT_RUN/";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->summary = "Calls ast_log_backtrace()!!! (will only be run if explicitly called)";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->description = "Calls ast_log_backtrace()!!! (will only be run if explicitly called). "</span><br><span style="color: hsl(120, 100%, 40%);">+ "This test is mainly used for testing CI and tool failure scenarios.";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->explicit_only = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log_backtrace();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_UNREGISTER(call_backtrace);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_UNREGISTER(call_assert);</span><br><span> AST_TEST_UNREGISTER(segv);</span><br><span> AST_TEST_UNREGISTER(pattern_match_test);</span><br><span> return 0;</span><br><span>@@ -356,6 +398,8 @@</span><br><span> {</span><br><span> AST_TEST_REGISTER(pattern_match_test);</span><br><span> AST_TEST_REGISTER(segv);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(call_assert);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(call_backtrace);</span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span>diff --git a/utils/ael_main.c b/utils/ael_main.c</span><br><span>index 6c83746..c136513 100644</span><br><span>--- a/utils/ael_main.c</span><br><span>+++ b/utils/ael_main.c</span><br><span>@@ -625,16 +625,9 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char **foo = calloc(num_frames, sizeof(char *) + 1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (foo) {</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < num_frames; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- foo[i] = (char *) foo + sizeof(char *) * num_frames;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return foo;</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span> #else</span><br><span> void ast_remove_lock_info(void *lock_addr)</span><br><span>diff --git a/utils/check_expr.c b/utils/check_expr.c</span><br><span>index 27c92d2..4eb5a17 100644</span><br><span>--- a/utils/check_expr.c</span><br><span>+++ b/utils/check_expr.c</span><br><span>@@ -79,17 +79,10 @@</span><br><span> /* Suck it, you stupid utils directory! */</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames);</span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames);</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char **foo = calloc(num_frames, sizeof(char *) + 1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (foo) {</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < num_frames; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- foo[i] = (char *) foo + sizeof(char *) * num_frames;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return foo;</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span> #else</span><br><span> void ast_store_lock_info(enum ast_lock_type type, const char *filename,</span><br><span>diff --git a/utils/conf2ael.c b/utils/conf2ael.c</span><br><span>index 4ece875..db01049 100644</span><br><span>--- a/utils/conf2ael.c</span><br><span>+++ b/utils/conf2ael.c</span><br><span>@@ -740,18 +740,10 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-char **__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_vector_string *__ast_bt_get_symbols(void **addresses, size_t num_frames)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char **foo = calloc(num_frames, sizeof(char *) + 1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (foo) {</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < num_frames; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- foo[i] = (char *) foo + sizeof(char *) * num_frames;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return foo;</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #else</span><br><span> void ast_remove_lock_info(void *lock_addr)</span><br><span> {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10702">change 10702</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/10702"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: certified/13.21 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I79d02862ddaa2423a0809caa4b3b85c128131621 </div>
<div style="display:none"> Gerrit-Change-Number: 10702 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>