Ion C
C library for Ion
ion_debug.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at:
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12  * language governing permissions and limitations under the License.
13  */
14 
17 #ifndef ION_DEBUG_H_
18 #define ION_DEBUG_H_
19 
20 #include "ion_types.h"
21 #include "ion_platform_config.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 //
28 // support routines for error handling
29 //
30 
31 #define ION_ERROR_MESSAGE_MAX_LENGTH 1024
32 
33 
34 #ifdef DEBUG
35 
36  #define DEBUG_ERR(x) fprintf(stderr,"\nERROR %d [%s] AT LINE %d IN %s\n" \
37  , (int)(x), ion_error_to_str(x) \
38  , (int)__LINE__, __location_display_name__)
39  #define DEBUG_ERRMSG(x,m) fprintf(stderr,"\nERROR %d [%s] WITH MESSAGE '%s' AT LINE %d IN %s\n" \
40  , (int)(x), ion_error_to_str(x) \
41  , (char *)(m) \
42  , (int)__LINE__, __location_display_name__)
43  #define BREAK ion_helper_breakpoint()
44  #define ENTER(f,l,c) ion_helper_enter(f, l, c)
45  #define RETURN(f,l,c,e) return ion_helper_return(f, l, c, e)
46  #ifndef __func__
47  #define __location_name__ __file__
48  #define __location_display_name__ ion_helper_short_filename(__file__)
49  #define ENTER_FILE static /*const*/ char *__file__ = __FILE__
50  #else
51  #define __location_name__ __func__
52  #define __location_display_name__ __func__
53  #define ENTER_FILE static const char *__file__ = __func__
54  #endif
55  #define FN_DEF static long __count__ = 0; \
56  ENTER_FILE; \
57  /* static const*/ int __line__ = __LINE__; \
58  long __temp__ = ENTER(__file__, __line__, __count__);
59 #else
60  #define DEBUG_ERR(x) /* nothing */
61  #define DEBUG_ERRMSG(x,m) /* nothing */
62  #define BREAK ion_helper_breakpoint() /* nothing */
63  #define ENTER(f,l,c) /* nothing */
64  #define RETURN(f,l,c,e) return e
65  #define FN_DEF /* nothing */
66 #endif
67 
68 #define iENTER FN_DEF iERR err = IERR_OK
69 #define DONTFAILWITH(x) { err = x; goto fail; }
70 #define FAILWITH(x) { BREAK; DEBUG_ERR(x); err = x; goto fail; }
71 #define FAILWITHMSG(x,s) { BREAK; DEBUG_ERRMSG(x,s); err = x; goto fail; }
72 #define IONCHECK(x) { err = x; if (err) goto fail; }
73 #define SUCCEED() { err = IERR_OK; goto fail; }
74 #define iRETURN fail: RETURN(__location_name__, __line__, __count__++, err)
75 
84 #define UPDATEERROR(x) { iERR errBackup = (x); if (err == IERR_OK) { err = errBackup; }}
85 
86 #define ION_TIMESTAMP_STRING_LENGTH 55 /* does NOT include null terminator */
87 
88 #define ION_VERSION_MARKER_LENGTH 4
89 
91 GLOBAL BOOL g_ion_debug_tracing INITTO(FALSE);
92 
93 ION_API_EXPORT BOOL ion_debug_has_tracing(void);
94 ION_API_EXPORT void ion_debug_set_tracing(BOOL state);
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif /* ION_DEBUG_H_ */
GLOBAL BOOL g_ion_debug_tracing INITTO(FALSE)
#define GLOBAL
Definition: ion_types.h:41