c6b0ec78f3acda30dc7a484e567a27c317e5e2ca
[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 in a specific function.
45 *
46 * @param function name
47 * @return TRUE if function is in the stack
48 */
49 bool (*contains_function)(backtrace_t *this, char *function);
50
51 /**
52 * Destroy a backtrace instance.
53 */
54 void (*destroy)(backtrace_t *this);
55 };
56
57 /**
58 * Create a backtrace of the current stack.
59 *
60 * @param skip how many of the innerst frames to skip
61 * @return backtrace
62 */
63 backtrace_t *backtrace_create(int skip);
64
65 #endif /** BACKTRACE_H_ @}*/