8.3
general documentation
bft_backtrace.h
Go to the documentation of this file.
1#ifndef __BFT_BACKTRACE_H__
2#define __BFT_BACKTRACE_H__
3
4/*============================================================================
5 * Obtaining a stack backtrace
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2024 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30#include "cs_defs.h"
31
32/*----------------------------------------------------------------------------
33 * Standard C library headers
34 *----------------------------------------------------------------------------*/
35
36#include <stdarg.h>
37
38/*----------------------------------------------------------------------------
39 * Local headers
40 *----------------------------------------------------------------------------*/
41
42/*-----------------------------------------------------------------------------*/
43
45
46/*============================================================================
47 * Public types
48 *============================================================================*/
49
50/* BFT backtrace descriptor */
51
52typedef struct _bft_backtrace_t bft_backtrace_t;
53
54/* Pointers for backtrace print functions */
55
56typedef void (bft_backtrace_print_t) (int start_depth);
57
58/*============================================================================
59 * Public function prototypes
60 *============================================================================*/
61
62/*
63 * Build a backtrace description structure.
64 *
65 * returns:
66 * pointer to bft_backtrace_t backtrace descriptor (NULL in case of
67 * error, or if backtracing is unavailable on this architecture).
68 */
69
72
73/*
74 * Free a backtrace description structure.
75 *
76 * parameters:
77 * bt: <-> pointer to backtrace description structure.
78 *
79 * returns:
80 * null pointer.
81 */
82
85
93void
95
96/*
97 * Return the total depth of a backtrace.
98 *
99 * parameters:
100 * bt: <-- pointer to backtrace description structure.
101 *
102 * returns:
103 * total backtrace depth.
104 */
105
106int
108
109/*
110 * Return file name associated with a backtrace at a given depth.
111 *
112 * parameters:
113 * bt: <-- pointer to backtrace description structure.
114 * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
115 *
116 * returns:
117 * file name at the given depth, or NULL.
118 */
119
120const char *
122 int depth);
123
124/*
125 * Return function name associated with a backtrace at a given depth.
126 *
127 * parameters:
128 * bt: <-- pointer to backtrace description structure.
129 * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
130 *
131 * returns:
132 * function name at the given depth, or NULL.
133 */
134
135const char *
137 int depth);
138
139/*
140 * Return address associated with a backtrace at a given depth.
141 *
142 * parameters:
143 * bt: <-- pointer to backtrace description structure.
144 * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
145 *
146 * returns:
147 * address at the given depth, or NULL.
148 */
149
150const char *
152 int depth);
153
154/*
155 * Print a backtrace.
156 *
157 * parameters:
158 * start_depth: <-- depth of backtrace at which to start printing
159 * (0 for all, including backtrace print function)
160 */
161
162void
163bft_backtrace_print(int start_depth);
164
165/*
166 * Returns backtrace print function.
167 *
168 * returns:
169 * pointer to the backtrace print function.
170 */
171
174
175/*
176 * Sets a backtrace print function.
177 *
178 * parameters:
179 * fct: <-- pointer to a bft_backtrace_print_t type function.
180 */
181
182void
184
185/*----------------------------------------------------------------------------*/
186
188
189#endif /* __BFT_BACKTRACE_H__ */
void bft_backtrace_demangle(bft_backtrace_t *bt)
Demangle a backtrace description structure (for C++).
Definition: bft_backtrace.cpp:308
void bft_backtrace_print_set(bft_backtrace_print_t *const fct)
Sets a backtrace print function.
Definition: bft_backtrace.cpp:484
void bft_backtrace_print(int start_depth)
Print a backtrace.
Definition: bft_backtrace.cpp:459
struct _bft_backtrace_t bft_backtrace_t
Definition: bft_backtrace.h:52
bft_backtrace_t * bft_backtrace_create(void)
Build a backtrace description structure.
Definition: bft_backtrace.cpp:123
bft_backtrace_t * bft_backtrace_destroy(bft_backtrace_t *bt)
Free a backtrace description structure.
Definition: bft_backtrace.cpp:270
int bft_backtrace_size(const bft_backtrace_t *bt)
Return the depth of a backtrace.
Definition: bft_backtrace.cpp:377
bft_backtrace_print_t * bft_backtrace_print_get(void)
Returns backtrace print function.
Definition: bft_backtrace.cpp:472
const char * bft_backtrace_function(bft_backtrace_t *bt, int depth)
Return function name associated with a backtrace at a given depth.
Definition: bft_backtrace.cpp:415
const char * bft_backtrace_file(bft_backtrace_t *bt, int depth)
Return file name associated with a backtrace at a given depth.
Definition: bft_backtrace.cpp:392
const char * bft_backtrace_address(bft_backtrace_t *bt, int depth)
Return address associated with a backtrace at a given depth.
Definition: bft_backtrace.cpp:438
void() bft_backtrace_print_t(int start_depth)
Function pointer to backtrace print function.
Definition: bft_backtrace.h:56
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
#define END_C_DECLS
Definition: cs_defs.h:543