Asterisk - The Open Source Telephony Project GIT-master-70eff7f
Loading...
Searching...
No Matches
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 <stdbool.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 78 of file backtrace.c.

Function Documentation

◆ __ast_bt_create()

struct ast_bt * __ast_bt_create ( void  )

Definition at line 80 of file backtrace.c.

81{
82 struct ast_bt *bt = calloc(1, sizeof(*bt));
83
84 if (!bt) {
85 return NULL;
86 }
87 bt->alloced = 1;
88
90
91 return bt;
92}
#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, and NULL.

◆ __ast_bt_destroy()

void * __ast_bt_destroy ( struct ast_bt bt)

Definition at line 100 of file backtrace.c.

101{
102 if (bt && bt->alloced) {
103 free(bt);
104 }
105 return NULL;
106}
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 310 of file backtrace.c.

311{
313 AST_VECTOR_PTR_FREE(symbols);
314}
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
Definition vector.h:200
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition vector.h:890

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 94 of file backtrace.c.

95{
96 bt->num_frames = backtrace(bt->addresses, AST_MAX_BT_FRAMES);
97 return 0;
98}
#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 283 of file backtrace.c.

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

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