mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
backtrace: Refactor ast_bt_get_symbols so it doesn't crash
We've been seeing crashes in libbfd when we attempt to generate a stack trace from multiple threads. It turns out that libbfd is NOT thread-safe. It can cache the bfd structure and give it to multiple threads without protecting itself. To get around this, we've added a global mutex around the bfd functions and also have refactored the use of those functions to be more efficient and to provide more information about inlined functions. Also added a few more tests to test_pbx.c. One just calls ast_assert() and the other calls ast_log_backtrace(). Neither are run by default. WARNING: This change necessitated changing the return value of ast_bt_get_symbols() from an array of strings to a VECTOR of strings. However, the use of this function outside Asterisk is not likely. ASTERISK-28140 Change-Id: I79d02862ddaa2423a0809caa4b3b85c128131621
This commit is contained in:
@@ -191,7 +191,7 @@ AST_MUTEX_DEFINE_STATIC_NOTRACKING(reglock);
|
||||
static void print_backtrace(struct ast_bt *bt)
|
||||
{
|
||||
int i = 0;
|
||||
char **strings;
|
||||
struct ast_vector_string *strings;
|
||||
|
||||
if (!bt) {
|
||||
return;
|
||||
@@ -199,10 +199,10 @@ static void print_backtrace(struct ast_bt *bt)
|
||||
|
||||
if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
|
||||
astmm_log("Memory allocation backtrace:\n");
|
||||
for (i = 3; i < bt->num_frames - 2; i++) {
|
||||
astmm_log("#%d: [%p] %s\n", i - 3, bt->addresses[i], strings[i]);
|
||||
for (i = 3; i < AST_VECTOR_SIZE(strings) - 2; i++) {
|
||||
astmm_log("#%d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
|
||||
}
|
||||
ast_std_free(strings);
|
||||
ast_bt_free_symbols(strings);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user