Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
Macros | Functions
backtrace.c File Reference

Asterisk backtrace generation. More...

#include "asterisk.h"
#include "asterisk/backtrace.h"
#include "asterisk/vector.h"
#include <execinfo.h>
#include <pthread.h>
Include dependency graph for backtrace.c:

Go to the source code of this file.

Macros

#define _ASTERISK_LOCK_H
 
#define ast_calloc(n, x)   calloc(n, x)
 
#define ast_free(x)   free(x)
 
#define ast_malloc(x)   malloc(x)
 
#define ASTMM_LIBC   ASTMM_IGNORE
 
#define S_OR(a, b)   (a && a[0] != '\0') ? a : b
 

Functions

struct ast_bt__ast_bt_create (void)
 
void * __ast_bt_destroy (struct ast_bt *bt)
 
void __ast_bt_free_symbols (struct ast_vector_string *symbols)
 
int __ast_bt_get_addresses (struct ast_bt *bt)
 
struct ast_vector_string__ast_bt_get_symbols (void **addresses, size_t num_frames)
 

Detailed Description

Asterisk backtrace generation.

This file provides backtrace generation utilities

Definition in file backtrace.c.

Macro Definition Documentation

◆ _ASTERISK_LOCK_H

#define _ASTERISK_LOCK_H

Definition at line 33 of file backtrace.c.

◆ ast_calloc

#define ast_calloc (   n,
 
)    calloc(n, x)

Definition at line 52 of file backtrace.c.

◆ ast_free

#define ast_free (   x)    free(x)

Definition at line 51 of file backtrace.c.

◆ ast_malloc

#define ast_malloc (   x)    malloc(x)

Definition at line 53 of file backtrace.c.

◆ ASTMM_LIBC

#define ASTMM_LIBC   ASTMM_IGNORE

Definition at line 39 of file backtrace.c.

◆ S_OR

#define S_OR (   a,
  b 
)    (a && a[0] != '\0') ? a : b

Definition at line 76 of file backtrace.c.

Function Documentation

◆ __ast_bt_create()

struct ast_bt * __ast_bt_create ( void  )

Definition at line 78 of file backtrace.c.

79{
80 struct ast_bt *bt = calloc(1, sizeof(*bt));
81
82 if (!bt) {
83 return NULL;
84 }
85 bt->alloced = 1;
86
88
89 return bt;
90}
#define calloc(a, b)
Definition: astmm.h:155
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
#define NULL
Definition: resample.c:96
A structure to hold backtrace information. This structure provides an easy means to store backtrace i...
Definition: backtrace.h:50
unsigned int alloced
Definition: backtrace.h:56

References ast_bt::alloced, ast_bt_get_addresses, calloc, and NULL.

◆ __ast_bt_destroy()

void * __ast_bt_destroy ( struct ast_bt bt)

Definition at line 98 of file backtrace.c.

99{
100 if (bt && bt->alloced) {
101 free(bt);
102 }
103 return NULL;
104}
void free()

References ast_bt::alloced, free(), and NULL.

◆ __ast_bt_free_symbols()

void __ast_bt_free_symbols ( struct ast_vector_string symbols)

Definition at line 308 of file backtrace.c.

309{
311 AST_VECTOR_PTR_FREE(symbols);
312}
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
Definition: vector.h:189
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:862

References AST_VECTOR_CALLBACK_VOID, AST_VECTOR_PTR_FREE, and free().

◆ __ast_bt_get_addresses()

int __ast_bt_get_addresses ( struct ast_bt bt)

Definition at line 92 of file backtrace.c.

93{
94 bt->num_frames = backtrace(bt->addresses, AST_MAX_BT_FRAMES);
95 return 0;
96}
#define AST_MAX_BT_FRAMES
Definition: backtrace.h:29
void * addresses[AST_MAX_BT_FRAMES]
Definition: backtrace.h:52
int num_frames
Definition: backtrace.h:54

References ast_bt::addresses, AST_MAX_BT_FRAMES, and ast_bt::num_frames.

◆ __ast_bt_get_symbols()

struct ast_vector_string * __ast_bt_get_symbols ( void **  addresses,
size_t  num_frames 
)

Definition at line 281 of file backtrace.c.

282{
283 char **strings;
284 struct ast_vector_string *return_strings;
285 int i;
286
287 return_strings = malloc(sizeof(struct ast_vector_string));
288 if (!return_strings) {
289 return NULL;
290 }
291 if (AST_VECTOR_INIT(return_strings, num_frames)) {
292 free(return_strings);
293 return NULL;
294 }
295
296 strings = backtrace_symbols(addresses, num_frames);
297 if (strings) {
298 for (i = 0; i < num_frames; i++) {
299 AST_VECTOR_APPEND(return_strings, strdup(strings[i]));
300 }
301 free(strings);
302 }
303
304 return return_strings;
305}
#define strdup(a)
Definition: astmm.h:163
char * malloc()
String vector definitions.
Definition: vector.h:55
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References AST_VECTOR_APPEND, AST_VECTOR_INIT, free(), malloc(), NULL, and strdup.