Code_Saturne
CFD tool
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2012 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 /* Standard C library headers */
31 
32 #include <stdarg.h>
33 
34 /* BFT library headers */
35 
36 /*-----------------------------------------------------------------------------*/
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #if 0
41 } /* Fake brace to force Emacs auto-indentation back to column 0 */
42 #endif
43 #endif /* __cplusplus */
44 
45 /*============================================================================
46  * Public types
47  *============================================================================*/
48 
49 /* BFT backtrace descriptor */
50 
51 typedef struct _bft_backtrace_t bft_backtrace_t;
52 
53 /* Pointers for backtrace print functions */
54 
55 typedef void (bft_backtrace_print_t) (int start_depth);
56 
57 /*============================================================================
58  * Public function prototypes
59  *============================================================================*/
60 
61 /*
62  * Build a backtrace description structure.
63  *
64  * returns:
65  * pointer to bft_backtrace_t backtrace descriptor (NULL in case of
66  * error, or if backtracing is unavailable on this architecture).
67  */
68 
71 
72 /*
73  * Free a backtrace description structure.
74  *
75  * parameters:
76  * bt: <-> pointer to backtrace description structure.
77  *
78  * returns:
79  * NULL pointer.
80  */
81 
84 
92 void
94 
95 /*
96  * Return the total depth of a backtrace.
97  *
98  * parameters:
99  * bt: <-- pointer to backtrace description structure.
100  *
101  * returns:
102  * total backtrace depth.
103  */
104 
105 int
107 
108 /*
109  * Return file name associated with a backtrace at a given depth.
110  *
111  * parameters:
112  * bt: <-- pointer to backtrace description structure.
113  * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
114  *
115  * returns:
116  * file name at the given depth, or NULL.
117  */
118 
119 const char *
121  int depth);
122 
123 /*
124  * Return function name associated with a backtrace at a given depth.
125  *
126  * parameters:
127  * bt: <-- pointer to backtrace description structure.
128  * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
129  *
130  * returns:
131  * function name at the given depth, or NULL.
132  */
133 
134 const char *
136  int depth);
137 
138 /*
139  * Return address associated with a backtrace at a given depth.
140  *
141  * parameters:
142  * bt: <-- pointer to backtrace description structure.
143  * depth: <-- index in backtrace structure (< bft_backtrace_size(bt)).
144  *
145  * returns:
146  * address at the given depth, or NULL.
147  */
148 
149 const char *
151  int depth);
152 
153 /*
154  * Print a backtrace.
155  *
156  * parameters:
157  * start_depth: <-- depth of backtrace at which to start printing
158  * (0 for all, including backtrace print function)
159  */
160 
161 void
162 bft_backtrace_print(int start_depth);
163 
164 /*
165  * Returns backtrace print function.
166  *
167  * returns:
168  * pointer to the backtrace print function.
169  */
170 
173 
174 /*
175  * Sets a backtrace print function.
176  *
177  * parameters:
178  * fct: <-- pointer to a bft_backtrace_print_t type function.
179  */
180 
181 void
183 
184 /*----------------------------------------------------------------------------*/
185 
186 #ifdef __cplusplus
187 }
188 #endif /* __cplusplus */
189 
190 #endif /* __BFT_BACKTRACE_H__ */
void( bft_backtrace_print_t)(int start_depth)
Function pointer to backtrace print function.
Definition: bft_backtrace.h:55
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.c:388
const char * bft_backtrace_address(bft_backtrace_t *bt, int depth)
Return address associated with a backtrace at a given depth.
Definition: bft_backtrace.c:434
bft_backtrace_t * bft_backtrace_destroy(bft_backtrace_t *bt)
Free a backtrace description structure.
Definition: bft_backtrace.c:270
int bft_backtrace_size(const bft_backtrace_t *bt)
Return the depth of a backtrace.
Definition: bft_backtrace.c:373
void bft_backtrace_print_set(bft_backtrace_print_t *const fct)
Sets a backtrace print function.
Definition: bft_backtrace.c:480
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.c:411
bft_backtrace_print_t * bft_backtrace_print_get(void)
Returns backtrace print function.
Definition: bft_backtrace.c:468
void bft_backtrace_demangle(bft_backtrace_t *bt)
Demangle a backtrace description structure (for C++).
Definition: bft_backtrace.c:308
void bft_backtrace_print(int start_depth)
Print a backtrace.
Definition: bft_backtrace.c:455
struct _bft_backtrace_t bft_backtrace_t
Definition: bft_backtrace.h:51
bft_backtrace_t * bft_backtrace_create(void)
Build a backtrace description structure.
Definition: bft_backtrace.c:126