* Removed some temporary diagnostics that had been left in serv_sieve.c
[citadel.git] / citadel / ecrash.h
blob271e9914446a43969de74f8b73712c64a2dff209
1 /**
2 * \file eCrash.h
3 * @author David Frascone
4 *
5 * eCrash types and prototypes.
7 * vim: ts=4
8 */
10 #ifndef _ECRASH_H_
11 #define _ECRASH_H_
13 #include <stdio.h>
14 #include <signal.h>
16 typedef void (*sighandler_t)(int);
18 typedef long BOOL;
20 #define MAX_LINE_LEN 256
22 #ifndef TRUE
23 #define TRUE 1
24 #define FALSE 0
25 #define BOOL int
26 #endif
28 #define ECRASH_DEFAULT_STACK_DEPTH 10
29 #define ECRASH_DEFAULT_BACKTRACE_SIGNAL SIGUSR2
30 #define ECRASH_DEFAULT_THREAD_WAIT_TIME 10
31 #define ECRASH_MAX_NUM_SIGNALS 30
33 /** \struct eCrashSymbol
34 * \brief Function Name / Address pair
36 * This is used in conjunction with eCrashSymbolTable to
37 * provide an alternative to backtrace_symbols.
39 typedef struct {
40 char *function;
41 void *address;
42 } eCrashSymbol;
43 /** \struct eCrashSymbolTable
44 * \brief Symbol table used to avoid backtrace_symbols()
46 * This structure is used to provide a alternative to
47 * backtrace_symbols which is not async signal safe.
49 * The symbol table should be sorted by address (it will
50 * be either binary or linearly searched)
52 typedef struct {
53 int numSymbols;
54 eCrashSymbol *symbols;
55 } eCrashSymbolTable;
59 #define ECRASH_DEBUG_ENABLE /* undef to turn off debug */
61 #ifdef ECRASH_DEBUG_ENABLE
62 # define ECRASH_DEBUG_VERY_VERBOSE 1
63 # define ECRASH_DEBUG_VERBOSE 2
64 # define ECRASH_DEBUG_INFO 3
65 # define ECRASH_DEBUG_WARN 4
66 # define ECRASH_DEBUG_ERROR 5
67 # define ECRASH_DEBUG_OFF 6
68 # define ECRASH_DEBUG_DEFAULT (ECRASH_DEBUG_ERROR)
69 # define DPRINTF(level, fmt...) \
70 if (level >= gbl_params.debugLevel) { printf(fmt); fflush(stdout); }
71 #else /* ECRASH_DEBUG_ENABLE */
72 # define DPRINTF(level, fmt...)
73 #endif /* ECRASH_DEBUG_ENABLE */
76 /** \struct eCrashParameters
77 * \brief eCrash Initialization Parameters
79 * This structure contains all the global initialization functions
80 * for eCrash.
82 * @see eCrash_Init
84 typedef struct {
87 /* OUTPUT OPTIONS */
88 /** Filename to output to, or NULL */
89 char *filename;
90 /** FILE * to output to or NULL */
91 FILE *filep;
92 /** fd to output to or -1 */
93 int fd;
95 int debugLevel;
97 /** If true, all registered threads will
98 * be dumped
100 BOOL dumpAllThreads;
102 /** How far to backtrace each stack */
103 unsigned int maxStackDepth;
105 /** Default signal to use to tell a thread to drop it's
106 * stack.
108 int defaultBacktraceSignal;
110 /** How long to wait for a threads
111 * dump
113 unsigned int threadWaitTime;
115 /** If this is non-zero, the dangerous function, backtrace_symbols
116 * will be used. That function does a malloc(), so is not async
117 * signal safe, and could cause deadlocks.
119 BOOL useBacktraceSymbols;
121 /** To avoid the issues with backtrace_symbols (see comments above)
122 * the caller can supply it's own symbol table, containing function
123 * names and start addresses. This table can be created using
124 * a script, or a static table.
126 * If this variable is not null, it will be used, instead of
127 * backtrace_symbols, reguardless of the setting
128 * of useBacktraceSymbols.
130 eCrashSymbolTable *symbolTable;
132 /** Array of crash signals to catch,
133 * ending in 0 I would have left it a [] array, but I
134 * do a static copy, so I needed a set size.
136 int signals[ECRASH_MAX_NUM_SIGNALS];
138 } eCrashParameters;
141 * Initialize eCrash.
143 * This function must be called before calling any other eCrash
144 * functions. It sets up the global behavior of the system.
146 * @param params Our input parameters. The passed in structure will be copied.
148 * @return Zero on success.
150 int eCrash_Init(eCrashParameters *params);
152 * UnInitialize eCrash.
154 * This function may be called to de-activate eCrash, release the
155 * signal handlers, and free any memory allocated by eCrash.
157 * @return Zero on success.
159 int eCrash_Uninit( void );
162 * Register a thread for backtracing on crash.
164 * This function must be called by any thread wanting it's stack
165 * dumped in the event of a crash. The thread my specify what
166 * signal should be used, or the default, SIGUSR1 will be used.
168 * @param name String used to refer to us in crash dumps
169 * @param signo Signal to use to generate dump (default: SIGUSR1)
171 * @return Zero on success.
173 int eCrash_RegisterThread(char *name, int signo);
176 * Un-register a thread for stack dumps.
178 * This function may be called to un-register any previously
179 * registered thread.
181 * @return Zero on success.
183 int eCrash_UnregisterThread( void );
185 #endif /* _E_CRASH_H_ */