summaryrefslogtreecommitdiff
path: root/lcmodule/source/legacy_compatibility/r_debug.h
blob: 6c6c280c50c90eab11afddf88bba93eb21008cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#ifndef INCLUSION_GUARD_R_DEBUG_H
#define INCLUSION_GUARD_R_DEBUG_H

/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/

#include <stdio.h>
#include "t_basicdefinitions.h"

/* Disable printouts if debug subsystem is disabled */
#ifndef ENABLE_DEBUG
#define DISABLE_PRINT_ALL_
#endif

// Disable flags ( "command line #undef" )
#ifdef DISABLE_PRINT_A_
#undef PRINT_A_
#endif
#ifdef DISABLE_PRINT_B_
#undef PRINT_B_
#endif
#ifdef DISABLE_PRINT_C_
#undef PRINT_C_
#endif
#ifdef DISABLE_PRINT_ALL_
#undef PRINT_C_
#undef PRINT_B_
#undef PRINT_A_
#endif

#if defined(PRINT_A_)
#define PRINT_LEVEL_A_
#endif

#if defined(PRINT_B_)
#define PRINT_LEVEL_B_
#endif

#if defined(PRINT_C_)
#define PRINT_LEVEL_C_
#endif

#if defined(PRINT_A_) || defined(PRINT_B_)
#define PRINT_LEVEL_A_B_
#endif

#if defined(PRINT_A_) || defined(PRINT_C_)
#define PRINT_LEVEL_A_C_
#endif

#if defined(PRINT_B_) || defined(PRINT_C_)
#define PRINT_LEVEL_B_C_
#endif

#if defined(PRINT_A_) || defined(PRINT_B_) || defined(PRINT_C_)
#define PRINT_LEVEL_A_B_C_
#endif

#define A_(_PAR_)
#define A_ASSERT_(exp)
#define B_(_PAR_)
#define B_ASSERT_(exp)
#define C_(_PAR_)
#define C_ASSERT_(exp)
#define A_B_(p)
#define A_B_ASSERT_(bool)
#define A_C_(p)
#define A_C_ASSERT_(bool)
#define B_C_(p)
#define B_C_ASSERT_(bool)
#define A_B_C_(p)
#define A_B_C_ASSERT_(bool)

#ifdef _WIN32
//#pragma message("COMPILING FOR WIN32")
#ifdef __cplusplus
extern "C"
{
#endif
    int _TraceEnter(int Level);
    void _TraceExit(int Level);
    void _TraceAssert(void *, void *, unsigned);
#ifdef __cplusplus
} // extern "C" {
#endif

#define _ABCTRACE(_PAR_, _ABC_) if (_TraceEnter(_ABC_)) {_PAR_; _TraceExit(_ABC_);}
#define _ASSERT(exp) (void)( (exp) || (_TraceAssert(#exp, __FILE__, __LINE__), 0) )

#ifdef PRINT_A_
#undef A_
#define A_(_PAR_) _ABCTRACE(_PAR_, 'A')
#undef A_ASSERT_
#define A_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_B_
#undef B_
#define B_(_PAR_) _ABCTRACE(_PAR_, 'B')
#undef B_ASSERT_
#define B_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_C_
#undef C_
#define C_(_PAR_) _ABCTRACE(_PAR_, 'C')
#undef C_ASSERT_
#define C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_B_
#undef A_B_
#define A_B_(_PAR_) _ABCTRACE(_PAR_, 'A')
#undef A_B__ASSERT_
#define A_B__ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_C_
#undef A_C_
#define A_C_(_PAR_) _ABCTRACE(_PAR_, 'A')
#undef A_C_ASSERT_
#define A_C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_B_C_
#undef B_C_
#define B_C_(_PAR_) _ABCTRACE(_PAR_, 'B')
#undef B_C_ASSERT_
#define B_C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_B_C_
#undef A_B_C_
#define A_B_C_(_PAR_) _ABCTRACE(_PAR_, 'A')
#undef A_B_C_ASSERT_
#define A_B_C_ASSERT_(exp) _ASSERT(exp)
#endif

#ifndef PRINT_LEVEL_IS_SETTABLE
// We Can remove this TRACE_IS_SETTABLE test when:
// * We do not have constructions with functions inserted in A_ macro's like: A_(void foo(void);)
// beacause  an if statement will be prefixed to the _PAR_ experssion
#ifdef PRINT_A_
#undef A_
#define A_(_PAR_) _PAR_
#undef A_ASSERT_
#define A_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_B_
#undef B_
#define B_(_PAR_) _PAR_
#undef B_ASSERT_
#define B_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_C_
#undef C_
#define C_(_PAR_) _PAR_
#undef C_ASSERT_
#define C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_B_
#undef A_B_
#define A_B_(_PAR_) _PAR_
#undef A_B__ASSERT_
#define A_B__ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_C_
#undef A_C_
#define A_C_(_PAR_) _PAR_
#undef A_C_ASSERT_
#define A_C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_B_C_
#undef B_C_
#define B_C_(_PAR_) _PAR_
#undef B_C_ASSERT_
#define B_C_ASSERT_(exp) _ASSERT(exp)
#endif
#ifdef PRINT_LEVEL_A_B_C_
#undef A_B_C_
#define A_B_C_(_PAR_) _PAR_
#undef A_B_C_ASSERT_
#define A_B_C_ASSERT_(exp) _ASSERT(exp)
#endif
#endif // PRINT_LEVEL_IS_SETTABLE

#else // _WIN32

#ifdef BSYS_ASSERT_CAUSE_DUMP
extern void p_assert_dump(const char *, unsigned int);

#define _ASSERT(expr) \
     do \
     { \
       if (!(expr)) \
       { \
         p_assert_dump(__FILE__, __LINE__); \
       } \
     } while (0)
#else
extern void p_assert_print(const char *, unsigned int);

#define _ASSERT(expr) \
     do \
     { \
       if (!(expr)) \
       { \
         p_assert_print(__FILE__, __LINE__); \
       } \
     } while (0)
#endif /* BSYS_ASSERT_CAUSE_DUMP */

#undef A_
#undef A_ASSERT_
#ifdef PRINT_A_
#define A_(p) p
#define A_ASSERT_(bool) _ASSERT(bool)
#else
#define A_(p)
#define A_ASSERT_(bool)
#endif

#undef B_
#undef B_ASSERT_
#ifdef PRINT_B_
#define B_(p) p
#define B_ASSERT_(bool) _ASSERT(bool)
#else
#define B_(p)
#define B_ASSERT_(bool)
#endif

#undef C_
#undef C_ASSERT_
#ifdef PRINT_C_
#define C_(p) p
#define C_ASSERT_(bool) _ASSERT(bool)
#else
#define C_(p)
#define C_ASSERT_(bool)
#endif

#undef A_B_
#undef A_B_ASSERT_
#ifdef PRINT_LEVEL_A_B_
#define A_B_(p) p
#define A_B_ASSERT_(bool) _ASSERT(bool)
#else
#define A_B_(p)
#define A_B_ASSERT_(bool)
#endif

#undef A_C_
#undef A_C_ASSERT_
#ifdef PRINT_LEVEL_A_C_
#define A_C_(p) p
#define A_C_ASSERT_(bool) _ASSERT(bool)
#else
#define A_C_(p)
#define A_C_ASSERT_(bool)
#endif

#undef B_C_
#undef B_C_ASSERT_
#ifdef PRINT_LEVEL_B_C_
#define B_C_(p) p
#define B_C_ASSERT_(bool) _ASSERT(bool)
#else
#define B_C_(p)
#define B_C_ASSERT_(bool)
#endif

#undef A_B_C_
#undef A_B_C_ASSERT_
#ifdef PRINT_LEVEL_A_B_C_
#define A_B_C_(p) p
#define A_B_C_ASSERT_(bool) _ASSERT(bool)
#else
#define A_B_C_(p)
#define A_B_C_ASSERT_(bool)
#endif

#endif // else _WIN32

/*
 * Obsolete TAE debugging. A_(), B_(), etc. should be used in new code.
 */
#if defined(PRINT_TA_)

#define DbgTrace1(msg)                      printf(msg)
#define DbgTrace2(msg,a1)                   printf(msg,a1)
#define DbgTrace3(msg,a1,a2)                printf(msg,a1,a2)
#define DbgTrace4(msg,a1,a2,a3)             printf(msg,a1,a2,a3)
#define DbgTrace5(msg,a1,a2,a3,a4)          printf(msg,a1,a2,a3,a4)
#define DbgTrace6(msg,a1,a2,a3,a4,a5)       printf(msg,a1,a2,a3,a4,a5)
#define DbgTrace7(msg,a1,a2,a3,a4,a5,a6)    printf(msg,a1,a2,a3,a4,a5,a6)
#define DbgTrace8(msg,a1,a2,a3,a4,a5,a6,a7) printf(msg,a1,a2,a3,a4,a5,a6,a7)

#else

#define DbgTrace1(msg)
#define DbgTrace2(msg,a1)
#define DbgTrace3(msg,a1,a2)
#define DbgTrace4(msg,a1,a2,a3)
#define DbgTrace5(msg,a1,a2,a3,a4)
#define DbgTrace6(msg,a1,a2,a3,a4,a5)
#define DbgTrace7(msg,a1,a2,a3,a4,a5,a6)
#define DbgTrace8(msg,a1,a2,a3,a4,a5,a6,a7)

#endif

#if defined(PRINT_TA_)

#define LLPRE2(expr) do{ if(expr){ printf("WARNING: ");
#define LLPOST2 }}while(0)

#define DbgIf_Warn1(expr,msg)                      LLPRE2(expr) printf(msg); LLPOST2
#define DbgIf_Warn2(expr,msg,a1)                   LLPRE2(expr) printf(msg,a1); LLPOST2
#define DbgIf_Warn3(expr,msg,a1,a2)                LLPRE2(expr) printf(msg,a1,a2); LLPOST2
#define DbgIf_Warn4(expr,msg,a1,a2,a3)             LLPRE2(expr) printf(msg,a1,a2,a3); LLPOST2
#define DbgIf_Warn5(expr,msg,a1,a2,a3,a4)          LLPRE2(expr) printf(msg,a1,a2,a3,a4); LLPOST2
#define DbgIf_Warn6(expr,msg,a1,a2,a3,a4,a5)       LLPRE2(expr) printf(msg,a1,a2,a3,a4,a5); LLPOST2
#define DbgIf_Warn7(expr,msg,a1,a2,a3,a4,a5,a6)    LLPRE2(expr) printf(msg,a1,a2,a3,a4,a5,a6); LLPOST2
#define DbgIf_Warn8(expr,msg,a1,a2,a3,a4,a5,a6,a7) LLPRE2(expr) printf(msg,a1,a2,a3,a4,a5,a6,a7); LLPOST2

#else

#define DbgIf_Warn1(expr,msg)
#define DbgIf_Warn2(expr,msg,a1)
#define DbgIf_Warn3(expr,msg,a1,a2)
#define DbgIf_Warn4(expr,msg,a1,a2,a3)
#define DbgIf_Warn5(expr,msg,a1,a2,a3,a4)
#define DbgIf_Warn6(expr,msg,a1,a2,a3,a4,a5)
#define DbgIf_Warn7(expr,msg,a1,a2,a3,a4,a5,a6)
#define DbgIf_Warn8(expr,msg,a1,a2,a3,a4,a5,a6,a7)

#endif

#define LLPRE3(expr) do{ if(expr){ printf("*FATAL* ");
#if defined(PRINT_TA_)
#define LLPOST3 LL_TerminateSystem(); }}while(0)
#else
#define LLPOST3 error(0xBABE); }}while(0)
#endif

#define DbgIf_Fatal1(expr,msg)                      LLPRE3(expr) printf(msg); LLPOST3
#define DbgIf_Fatal2(expr,msg,a1)                   LLPRE3(expr) printf(msg,a1); LLPOST3
#define DbgIf_Fatal3(expr,msg,a1,a2)                LLPRE3(expr) printf(msg,a1,a2); LLPOST3
#define DbgIf_Fatal4(expr,msg,a1,a2,a3)             LLPRE3(expr) printf(msg,a1,a2,a3); LLPOST3
#define DbgIf_Fatal5(expr,msg,a1,a2,a3,a4)          LLPRE3(expr) printf(msg,a1,a2,a3,a4); LLPOST3
#define DbgIf_Fatal6(expr,msg,a1,a2,a3,a4,a5)       LLPRE3(expr) printf(msg,a1,a2,a3,a4,a5); LLPOST3
#define DbgIf_Fatal7(expr,msg,a1,a2,a3,a4,a5,a6)    LLPRE3(expr) printf(msg,a1,a2,a3,a4,a5,a6); LLPOST3
#define DbgIf_Fatal8(expr,msg,a1,a2,a3,a4,a5,a6,a7) LLPRE3(expr) printf(msg,a1,a2,a3,a4,a5,a6,a7); LLPOST3



// Map TA calls
#define DbgTrace_HexDump(pData,nLength) BSYS_HexDump(pData,nLength,0)

// Prototypes

void BSYS_HexDump(const void *pData, int nLength, boolean DumpWithOffset);

#endif // INCLUSION_GUARD_R_DEBUG_H