9d59d25034a3ea0fe10d7a0d8218c7b660e01df7
[strongswan.git] / src / libstrongswan / utils / backtrace.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup backtrace backtrace
18 * @{ @ingroup utils
19 */
20
21 #ifndef BACKTRACE_H_
22 #define BACKTRACE_H_
23
24 #include <stdio.h>
25
26 #include <library.h>
27
28 typedef struct backtrace_t backtrace_t;
29
30 /**
31 * A backtrace registers the frames on the stack during creation.
32 */
33 struct backtrace_t {
34
35 /**
36 * Log the backtrace to a FILE stream.
37 *
38 * @param file FILE to log backtrace to
39 * @param detailed TRUE to resolve line/file using addr2line (slow)
40 */
41 void (*log)(backtrace_t *this, FILE *file, bool detailed);
42
43 /**
44 * Check if the backtrace contains a frame having a function in a list.
45 *
46 * @param function name array
47 * @param number of elements in function array
48 * @return TRUE if one of the functions is in the stack
49 */
50 bool (*contains_function)(backtrace_t *this, char *function[], int count);
51
52 /**
53 * Check two backtraces for equality.
54 *
55 * @param other backtrace to compare to this
56 * @return TRUE if backtraces are equal
57 */
58 bool (*equals)(backtrace_t *this, backtrace_t *other);
59 /**
60 * Create an enumerator over the stack frame addresses.
61 *
62 * @return enumerator_t over void*
63 */
64 enumerator_t* (*create_frame_enumerator)(backtrace_t *this);
65
66 /**
67 * Destroy a backtrace instance.
68 */
69 void (*destroy)(backtrace_t *this);
70 };
71
72 /**
73 * Create a backtrace of the current stack.
74 *
75 * @param skip how many of the innerst frames to skip
76 * @return backtrace
77 */
78 backtrace_t *backtrace_create(int skip);
79
80 #endif /** BACKTRACE_H_ @}*/