Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
log.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2012, 2013, 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __LOG_H__
20 #define __LOG_H__
21 
22 #include <stdio.h>
23 #include <error.h>
24 #include <stdlib.h>
25 #include <argp.h>
26 
27 extern struct argp log_argp;
28 #define log_argp_header "Log/Debug Options"
29 
30 #define verror(format,...) fprintf(stderr, "VERROR: %s:%d: "format, \
31  __FUNCTION__, __LINE__, ## __VA_ARGS__)
32 #define verrorc(format,...) fprintf(stderr,format, ## __VA_ARGS__)
33 #define vwarn(format,...) fprintf(stderr, "VWARNING: %s:%d: "format, \
34  __FUNCTION__, __LINE__, ## __VA_ARGS__)
35 #define vwarnc(format,...) fprintf(stderr,format, ## __VA_ARGS__)
36 
37 #define vwarnopt(level,area,flags,format,...) _vmi_warn(level,area,flags, \
38  "VWARNING: %s:%d: "format, \
39  __FUNCTION__, __LINE__, \
40  ## __VA_ARGS__)
41 #define vwarnoptc(level,area,flags,format,...) _vmi_warn(level,area,flags,format, \
42  ## __VA_ARGS__)
43 
44 /*
45  * If you change these flags and bits, make really sure to update
46  * lib/log.c!
47  *
48  * Rule for names: areas and flags must each be an alphanumeric string.
49  */
50 
51 /* Do something for all areas. */
52 #define LA_ALL INT_MAX
53 
54 typedef enum log_area_bits {
55  LAB_NONE = 0,
56  LAB_LIB = 1,
57  LAB_DEBUG = 2,
59  LAB_PROBE = 4,
60  LAB_XML = 5,
61  LAB_TEST = 6,
62  LAB_ANL = 7,
63 
64  LAB_USER = 31,
66 typedef enum log_areas {
67  LA_NONE = 0,
68  LA_LIB = 1 << LAB_LIB,
72  LA_XML = 1 << LAB_XML,
73  LA_TEST = 1 << LAB_TEST,
74  LA_ANL = 1 << LAB_ANL,
75 
76  LA_USER = 1 << LAB_USER,
77 } log_areas_t;
78 
79 /*
80  * Per-area flags.
81  */
82 /* Mask all the per-area enums below :) */
83 typedef int log_flags_t;
84 
85 typedef enum log_flag_bits_lib {
92  LFB_ROP = 6,
93  LFB_CFI = 7,
96 typedef enum log_flags_lib {
103  LF_ROP = 1 << LFB_ROP,
104  LF_CFI = 1 << LFB_CFI,
107 
108 typedef enum log_flag_bits_debug {
112  LFB_DLOC = 3,
118  LFB_DCFA = 9,
120  LFB_ELF = 11,
121  LFB_BFILE = 12,
123 typedef enum log_flags_debug {
135  LF_ELF = 1 << LFB_ELF,
138 
139 typedef enum log_flag_bits_target {
144  LFB_TLOC = 4,
148  LFB_TUNW = 8,
149  LFB_LUP = 9,
150  LFB_XV = 10,
151  LFB_OSP = 11,
152  LFB_PHP = 12,
153  LFB_GDB = 13,
156  LFB_OS = 16,
161 typedef enum log_flags_target {
171  LF_LUP = 1 << LFB_LUP,
172  LF_XV = 1 << LFB_XV,
173  LF_OSP = 1 << LFB_OSP,
174  LF_PHP = 1 << LFB_PHP,
175  LF_GDB = 1 << LFB_GDB,
178  LF_OS = 1 << LFB_OS,
183 
184 typedef enum log_flag_bits_probe {
189 typedef enum log_flags_probe {
194 
195 typedef enum log_flag_bits_xml {
196  LFB_XML = 0,
197  LFB_RPC = 1,
198  LFB_SVC = 2,
201 typedef enum log_flags_xml {
202  LF_XML = 1 << LFB_XML,
203  LF_RPC = 1 << LFB_RPC,
204  LF_SVC = 1 << LFB_SVC,
207 
208 typedef enum log_flag_bits_anl {
209  LFB_ANL = 0,
211 typedef enum log_flags_anl {
212  LF_ANL = 1 << LFB_ANL,
214 
215 /*
216 typedef enum log_flag_bits_ {
217  LFB_ = 0,
218  LFB_ = 1,
219  LFB_ = 2,
220 } log_flag_bits__t;
221 typedef enum log_flags_ {
222  LF_ = 1 << LFB_,
223  LF_ = 1 << LFB_,
224  LF_ = 1 << LFB_,
225 } log_flags__t;
226 */
227 
228 /*
229  * Some special per-area masks.
230  */
231 /* Set every last bit for a specific area. */
232 #define LF_ALL INT_MAX
233 #define LF_L_ALL (LF_CLMATCH | LF_CLRANGE | LF_RFILTER | LF_WAITPIPE | LF_EVLOOP | LF_MONITOR | LF_ROP | LF_CFI | LF_REGCACHE)
234 #define LF_D_ALL (LF_DFILE | LF_SYMBOL | LF_SCOPE | LF_DLOC \
235  | LF_DLOOKUP | LF_DWARF | LF_DWARFATTR \
236  | LF_DWARFSOPS | LF_DWARFOPS | LF_DCFA | LF_DOTHER \
237  | LF_ELF | LF_BFILE )
238 #define LF_T_ALL (LF_TARGET | LF_SPACE | LF_REGION | LF_TLOOKUP \
239  | LF_TLOC | LF_TOTHER | LF_TSYMBOL | LF_MEMCACHE | LF_TUNW \
240  | LF_DISASM | LF_THREAD | LF_OS | LF_PROCESS)
241 #define LF_T_D_ALL (LF_LUP | LF_XV | LF_GDB | LF_OSP | LF_PHP)
242 #define LF_P_ALL (LF_PROBE | LF_PROBEPOINT | LF_ACTION)
243 #define LF_X_ALL (LF_XML | LF_RPC | LF_SVC | LF_PROXYREQ)
244 #define LF_A_ALL (LF_ANL)
245 /* Set every last bit for the user area. */
246 #define LF_U_ALL INT_MAX
247 
248 /*
249  * Set the debug log level.
250  */
251 void vmi_set_log_level(int level);
252 /*
253  * Increase the debug log level by 1.
254  */
255 void vmi_inc_log_level(void);
256 /*
257  * Set the warn log level.
258  */
259 void vmi_set_warn_level(int level);
260 /*
261  * Increase the warn level by 1.
262  */
263 void vmi_inc_warn_level(void);
264 /*
265  * Reinitialize the flags for one or more areas.
266  */
268 int vmi_set_log_area_flaglist(char *flaglist,char *separator);
269 /*
270  * Additively (OR) change the flags for one or more areas.
271  */
273 int vmi_add_log_area_flaglist(char *flaglist,char *separator);
274 /*
275  * Users should set this before calling any argp parsing routines we
276  * provide if they want the -l standard argument to accept their debug
277  * flags.
278  *
279  * @names must be a NULL-terminated list of names.
280  */
281 void vmi_set_user_area_flags(char **names);
282 
283 /*
284  * Users should not need to call this.
285  */
286 int vmi_log_get_flag_val(char *flag,log_areas_t *areaval,log_flags_t *flagval);
287 
288 void _vmi_debug(int level,log_areas_t areas,log_flags_t flags,char *format,...);
289 void _vmi_warn(int level,log_areas_t areas,log_flags_t flags,char *format,...);
290 
291 int vdebug_is_on(int level,log_areas_t areas,log_flags_t flags);
292 int vwarn_is_on(int level,log_areas_t areas,log_flags_t flags);
293 
294 error_t log_argp_parse_opt(int key,char *arg,struct argp_state *state);
295 
296 #ifdef VMI_DEBUG
297 #define vdebug(level,areas,flags,format,...) _vmi_debug(level,areas,flags,"VDEBUG: %s:%d: "format, __FUNCTION__, __LINE__, ## __VA_ARGS__)
298 #define vdebugc(level,areas,flags,format,...) _vmi_debug(level,areas,flags,format, ## __VA_ARGS__)
299 
300 #else
301 
302 #define vdebug(devel,areas,flags,format,...) ((void)0)
303 #define vdebugc(devel,areas,flags,format,...) ((void)0)
304 
305 #endif
306 
307 #endif /* __LOG_H__ */
enum log_flag_bits_target log_flag_bits_target_t
Definition: log.h:103
Definition: log.h:118
void vmi_add_log_area_flags(log_areas_t areas, log_flags_t flags)
Definition: log.c:67
Definition: log.h:120
Definition: log.h:133
Definition: log.h:196
Definition: log.h:212
enum log_flags_probe log_flags_probe_t
Definition: log.h:58
log_flags_lib
Definition: log.h:96
Definition: log.h:74
Definition: log.h:136
Definition: log.h:175
log_areas
Definition: log.h:66
log_flags_debug
Definition: log.h:123
enum log_flags_lib log_flags_lib_t
int vwarn_is_on(int level, log_areas_t areas, log_flags_t flags)
Definition: log.c:357
Definition: log.h:112
void _vmi_warn(int level, log_areas_t areas, log_flags_t flags, char *format,...)
Definition: log.c:389
Definition: log.h:99
Definition: log.h:190
Definition: log.h:152
Definition: log.h:204
Definition: log.h:171
Definition: log.h:61
void vmi_inc_log_level(void)
Definition: log.c:38
Definition: log.h:151
Definition: log.h:166
enum log_flags_anl log_flags_anl_t
log_area_bits
Definition: log.h:54
Definition: log.h:60
int vmi_add_log_area_flaglist(char *flaglist, char *separator)
Definition: log.c:103
struct argp log_argp
Definition: log.c:413
enum log_flag_bits_xml log_flag_bits_xml_t
Definition: log.h:56
Definition: log.h:144
enum log_flag_bits_probe log_flag_bits_probe_t
void vmi_set_log_level(int level)
Definition: log.c:34
Definition: log.h:153
log_flag_bits_target
Definition: log.h:139
enum log_flags_debug log_flags_debug_t
enum log_flags_xml log_flags_xml_t
Definition: log.h:59
Definition: log.h:173
Definition: log.h:124
Definition: log.h:69
log_flag_bits_lib
Definition: log.h:85
Definition: log.h:97
Definition: log.h:64
log_flags_anl
Definition: log.h:211
Definition: log.h:62
void vmi_set_user_area_flags(char **names)
Definition: log.c:164
Definition: log.h:93
enum log_flag_bits_debug log_flag_bits_debug_t
log_flags_xml
Definition: log.h:201
log_flag_bits_debug
Definition: log.h:108
Definition: log.h:167
Definition: log.h:68
int vmi_log_get_flag_val(char *flag, log_areas_t *areaval, log_flags_t *flagval)
Definition: log.c:168
Definition: log.h:101
int vmi_set_log_area_flaglist(char *flaglist, char *separator)
Definition: log.c:84
enum log_areas log_areas_t
Definition: log.h:203
Definition: log.h:111
Definition: log.h:178
log_flags_target
Definition: log.h:161
enum log_flag_bits_anl log_flag_bits_anl_t
void vmi_set_warn_level(int level)
Definition: log.c:42
log_flag_bits_probe
Definition: log.h:184
log_flag_bits_anl
Definition: log.h:208
Definition: log.h:73
Definition: log.h:98
enum log_flag_bits_lib log_flag_bits_lib_t
void vmi_inc_warn_level(void)
Definition: log.c:46
void vmi_set_log_area_flags(log_areas_t area, log_flags_t flags)
Definition: log.c:50
enum log_area_bits log_area_bits_t
Definition: log.h:149
Definition: log.h:170
Definition: log.h:148
Definition: log.h:172
Definition: log.h:134
Definition: log.h:72
Definition: log.h:114
Definition: log.h:129
Definition: log.h:135
Definition: log.h:70
Definition: log.h:121
Definition: log.h:176
Definition: log.h:71
Definition: log.h:198
Definition: log.h:125
Definition: log.h:76
Definition: log.h:126
Definition: log.h:141
Definition: log.h:164
Definition: log.h:174
Definition: log.h:104
Definition: log.h:185
Definition: log.h:162
Definition: log.h:163
Definition: log.h:150
Definition: log.h:202
Definition: log.h:55
enum log_flags_target log_flags_target_t
Definition: log.h:197
log_flags_probe
Definition: log.h:189
Definition: log.h:209
Definition: log.h:109
Definition: log.h:177
Definition: log.h:156
Definition: log.h:90
int vdebug_is_on(int level, log_areas_t areas, log_flags_t flags)
Definition: log.c:335
Definition: log.h:67
error_t log_argp_parse_opt(int key, char *arg, struct argp_state *state)
Definition: log.c:416
Definition: log.h:92
log_flag_bits_xml
Definition: log.h:195
Definition: log.h:57
Definition: log.h:127
void _vmi_debug(int level, log_areas_t areas, log_flags_t flags, char *format,...)
Definition: log.c:379
Definition: log.h:192
int log_flags_t
Definition: log.h:83