mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
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
This commit is contained in:
@@ -848,8 +848,10 @@ int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request,
|
|||||||
#define DO_CRASH_NORETURN
|
#define DO_CRASH_NORETURN
|
||||||
#endif
|
#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
|
#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__)
|
#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)
|
static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
|
||||||
{
|
{
|
||||||
|
@@ -178,22 +178,17 @@ int internal_is_ao2_object(void *user_data)
|
|||||||
void log_bad_ao2(void *user_data, const char *file, int line, const char *func)
|
void log_bad_ao2(void *user_data, const char *file, int line, const char *func)
|
||||||
{
|
{
|
||||||
struct astobj2 *p;
|
struct astobj2 *p;
|
||||||
|
char bad_magic[100];
|
||||||
|
|
||||||
if (!user_data) {
|
if (!user_data) {
|
||||||
ast_log(__LOG_ERROR, file, line, func, "user_data is NULL\n");
|
__ast_assert_failed(0, "user_data is NULL", file, line, func);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = INTERNAL_OBJ(user_data);
|
p = INTERNAL_OBJ(user_data);
|
||||||
if (p->priv_data.magic) {
|
snprintf(bad_magic, sizeof(bad_magic), "bad magic number 0x%x for object %p",
|
||||||
ast_log(__LOG_ERROR, file, line, func,
|
p->priv_data.magic, user_data);
|
||||||
"bad magic number 0x%x for object %p\n",
|
__ast_assert_failed(0, bad_magic, file, line, func);
|
||||||
p->priv_data.magic, user_data);
|
|
||||||
} else {
|
|
||||||
ast_log(__LOG_ERROR, file, line, func,
|
|
||||||
"bad magic number for object %p. Object is likely destroyed.\n",
|
|
||||||
user_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int __ao2_lock(void *user_data, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var)
|
int __ao2_lock(void *user_data, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var)
|
||||||
@@ -205,7 +200,6 @@ int __ao2_lock(void *user_data, enum ao2_lock_req lock_how, const char *file, co
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
ast_assert(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +263,6 @@ int __ao2_unlock(void *user_data, const char *file, const char *func, int line,
|
|||||||
int current_value;
|
int current_value;
|
||||||
|
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
ast_assert(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +316,6 @@ int __ao2_trylock(void *user_data, enum ao2_lock_req lock_how, const char *file,
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
ast_assert(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,7 +446,6 @@ void *ao2_object_get_lockaddr(void *user_data)
|
|||||||
obj = INTERNAL_OBJ_CHECK(user_data);
|
obj = INTERNAL_OBJ_CHECK(user_data);
|
||||||
|
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
ast_assert(0);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +477,6 @@ int __ao2_ref(void *user_data, int delta,
|
|||||||
user_data, delta, ast_get_tid(), file, line, func, tag ?: "");
|
user_data, delta, ast_get_tid(), file, line, func, tag ?: "");
|
||||||
fflush(ref_log);
|
fflush(ref_log);
|
||||||
}
|
}
|
||||||
ast_assert(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -101,10 +101,13 @@ int __ao2_link(struct ao2_container *self, void *obj_new, int flags,
|
|||||||
struct ao2_container_node *node;
|
struct ao2_container_node *node;
|
||||||
|
|
||||||
if (!__is_ao2_object(obj_new, file, line, func)
|
if (!__is_ao2_object(obj_new, file, line, func)
|
||||||
|| !__is_ao2_object(self, file, line, func)
|
|| !__is_ao2_object(self, file, line, func)) {
|
||||||
|| !self->v_table || !self->v_table->new_node || !self->v_table->insert) {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!self->v_table || !self->v_table->new_node || !self->v_table->insert) {
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
ast_assert(0);
|
__ast_assert_failed(0, "invalid container v_table", file, line, func);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +179,6 @@ void *__ao2_unlink(struct ao2_container *c, void *user_data, int flags,
|
|||||||
{
|
{
|
||||||
if (!__is_ao2_object(user_data, file, line, func)) {
|
if (!__is_ao2_object(user_data, file, line, func)) {
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
ast_assert(0);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,10 +243,14 @@ static void *internal_ao2_traverse(struct ao2_container *self, enum search_flags
|
|||||||
struct ao2_container *multi_container = NULL;
|
struct ao2_container *multi_container = NULL;
|
||||||
struct ao2_iterator *multi_iterator = NULL;
|
struct ao2_iterator *multi_iterator = NULL;
|
||||||
|
|
||||||
if (!__is_ao2_object(self, file, line, func) || !self->v_table
|
if (!__is_ao2_object(self, file, line, func)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!self->v_table
|
||||||
|| !self->v_table->traverse_first || !self->v_table->traverse_next) {
|
|| !self->v_table->traverse_first || !self->v_table->traverse_next) {
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
ast_assert(0);
|
__ast_assert_failed(0, "invalid container v_table", file, line, func);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,8 +457,7 @@ struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
|
|||||||
void ao2_iterator_restart(struct ao2_iterator *iter)
|
void ao2_iterator_restart(struct ao2_iterator *iter)
|
||||||
{
|
{
|
||||||
if (!is_ao2_object(iter->c)) {
|
if (!is_ao2_object(iter->c)) {
|
||||||
ast_log(LOG_ERROR, "Iterator container is not valid.\n");
|
/* Sanity check. */
|
||||||
ast_assert(0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,12 +465,6 @@ void ao2_iterator_restart(struct ao2_iterator *iter)
|
|||||||
if (iter->last_node) {
|
if (iter->last_node) {
|
||||||
enum ao2_lock_req orig_lock;
|
enum ao2_lock_req orig_lock;
|
||||||
|
|
||||||
if (!is_ao2_object(iter->c)) {
|
|
||||||
/* Sanity check. */
|
|
||||||
ast_assert(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do a read lock in case the container node unref does not
|
* Do a read lock in case the container node unref does not
|
||||||
* destroy the node. If the container node is destroyed then
|
* destroy the node. If the container node is destroyed then
|
||||||
@@ -521,10 +520,13 @@ void *__ao2_iterator_next(struct ao2_iterator *iter,
|
|||||||
struct ao2_container_node *node;
|
struct ao2_container_node *node;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if (!__is_ao2_object(iter->c, file, line, func)
|
if (!__is_ao2_object(iter->c, file, line, func)) {
|
||||||
|| !iter->c->v_table || !iter->c->v_table->iterator_next) {
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!iter->c->v_table || !iter->c->v_table->iterator_next) {
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
ast_assert(0);
|
__ast_assert_failed(0, "invalid iterator container v_table", file, line, func);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,12 +663,16 @@ struct ao2_container *__ao2_container_clone(struct ao2_container *orig, enum sea
|
|||||||
int failed;
|
int failed;
|
||||||
|
|
||||||
/* Create the clone container with the same properties as the original. */
|
/* Create the clone container with the same properties as the original. */
|
||||||
if (!__is_ao2_object(orig, file, line, func)
|
if (!__is_ao2_object(orig, file, line, func)) {
|
||||||
|| !orig->v_table || !orig->v_table->alloc_empty_clone) {
|
|
||||||
/* Sanity checks. */
|
|
||||||
ast_assert(0);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!orig->v_table || !orig->v_table->alloc_empty_clone) {
|
||||||
|
/* Sanity checks. */
|
||||||
|
__ast_assert_failed(0, "invalid container v_table", file, line, func);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
clone = orig->v_table->alloc_empty_clone(orig, tag, file, line, func);
|
clone = orig->v_table->alloc_empty_clone(orig, tag, file, line, func);
|
||||||
if (!clone) {
|
if (!clone) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -166,7 +166,9 @@ static void hash_ao2_node_destructor(void *v_doomed)
|
|||||||
* same node.
|
* same node.
|
||||||
*/
|
*/
|
||||||
my_container = (struct ao2_container_hash *) doomed->common.my_container;
|
my_container = (struct ao2_container_hash *) doomed->common.my_container;
|
||||||
ast_assert(is_ao2_object(my_container));
|
#ifdef AST_DEVMODE
|
||||||
|
is_ao2_object(my_container);
|
||||||
|
#endif
|
||||||
|
|
||||||
__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
|
__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
|
||||||
|
|
||||||
|
@@ -858,7 +858,9 @@ static void rb_ao2_node_destructor(void *v_doomed)
|
|||||||
* same node.
|
* same node.
|
||||||
*/
|
*/
|
||||||
my_container = (struct ao2_container_rbtree *) doomed->common.my_container;
|
my_container = (struct ao2_container_rbtree *) doomed->common.my_container;
|
||||||
ast_assert(is_ao2_object(my_container));
|
#ifdef AST_DEVMODE
|
||||||
|
is_ao2_object(my_container);
|
||||||
|
#endif
|
||||||
|
|
||||||
__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
|
__adjust_lock(my_container, AO2_LOCK_REQ_WRLOCK, 1);
|
||||||
|
|
||||||
|
@@ -2467,17 +2467,16 @@ void DO_CRASH_NORETURN ast_do_crash(void)
|
|||||||
#endif /* defined(DO_CRASH) */
|
#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)
|
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
|
* Attempt to put it into the logger, but hope that at least
|
||||||
* someone saw the message on stderr ...
|
* 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",
|
fprintf(stderr, "FRACK!, Failed assertion %s (%d) at line %d in %s of %s\n",
|
||||||
condition_str, condition, line, function, file);
|
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 */
|
/* Generate a backtrace for the assert */
|
||||||
ast_log_backtrace();
|
ast_log_backtrace();
|
||||||
@@ -2490,7 +2489,6 @@ void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_
|
|||||||
usleep(1);
|
usleep(1);
|
||||||
ast_do_crash();
|
ast_do_crash();
|
||||||
}
|
}
|
||||||
#endif /* defined(AST_DEVMODE) */
|
|
||||||
|
|
||||||
char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
|
char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user