File: DbgInfo.h

package info (click to toggle)
capi4hylafax 1%3A01.02.03-10sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,856 kB
  • ctags: 2,966
  • sloc: cpp: 20,126; sh: 7,703; makefile: 215; perl: 36
file content (295 lines) | stat: -rw-r--r-- 11,697 bytes parent folder | download | duplicates (6)
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
/*---------------------------------------------------------------------------*\

    Copyright (C) 2000 AVM GmbH. All rights reserved.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY, without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, and WITHOUT
    ANY LIABILITY FOR ANY DAMAGES arising out of or in connection
    with the use or performance of this software. See the
    GNU General Public License for further details.

\*---------------------------------------------------------------------------*/

#ifndef _DBGINFO_H_
#define _DBGINFO_H_

#include "aTypes.h"
#include "ExtFuncs.h"

/*---------------------------------------------------------------------------*\
    Debug- und Print-Levels
\*---------------------------------------------------------------------------*/

#define Dbg_Level_Nothing           0x00    // Wirklich nichts ausgeben
#define Dbg_Level_Errors            0x01    // Nur Asserts und Errors
#define Dbg_Level_Infos             0x02    // Assert, Errors, Warnungen und Infos
#define Dbg_Level_Logs              0x03    // Assert, Errors, Warnungen, Infos und Logs
#define Dbg_Level_Short             0x04    // -"- und der Funktionsaufruf (inkl. Parameter)
#define Dbg_Level_Entry             0x06    // -"- und Funktionsaufrufe und -ende (inkl. Parameter)
#define Dbg_Level_Internal          0x07    // Alles wird ausgegeben

                                            // Print-Ausgabe von:
#define Prt_Level_NoFunctionName    0x0000  // Keine Ausgabe des Funktonsnamen
#define Prt_Level_NameInEveryLine   0x0040  // Name der Funkton bei jeder
                                            // Print-Ausgabe angeben
#define Prt_Level_NameAtFuncStart   0x0080  // Name der Funktion nur am Funktions-
                                            // Ein- & Austrittspunkt angeben
#define Prt_Level_FileNameAtStart   0x0100  // Dateiname nur beim Funktionsaufruf
#define Prt_Level_FileNameAtInfo    0x0200  // Dateiname vor jeder Debug-Ausgabe
#define Prt_Level_FuncNameAtError   0x0400  // Funktionsname statt Dateiname bei Fehlern

#define Prt_Level_Default           (Prt_Level_NameAtFuncStart |    \
                                     Prt_Level_FileNameAtInfo)

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

#define _USE_DEBUG_INFO_CLASS_NONE          0       // Reihenfolge wichtig!!
#define _USE_DEBUG_INFO_CLASS_EMULATION     1       // noch nicht ganz implementiert
#define _USE_DEBUG_INFO_CLASS_NORMAL        2

#ifndef USE_DEBUG_INFO_CLASS
#error USE_DEBUG_INFO_CLASS not defined!
#endif

/*---------------------------------------------------------------------------*\
    Activate Assert-BreakPoints
\*---------------------------------------------------------------------------*/
#if (USE_DEBUG_INFO_CLASS == _USE_DEBUG_INFO_CLASS_NONE)

#define dActivateBreakPoint(activate)

#else

void dActivateBreakPoint (tBool activate);

#endif


/*---------------------------------------------------------------------------*\
    dwriteE & dwriteI
\*---------------------------------------------------------------------------*/
#if (USE_DEBUG_INFO_CLASS == _USE_DEBUG_INFO_CLASS_NONE)

#define dwriteErr(DL, format)
#define dwriteWrn(DL, format)
#define dwriteLog(DL, format)
#define dwriteS(DL, format)
#define dwriteE(DL, format)
#define dwriteI(DL, format)

#else

void dwriteErr (unsigned DL, char *format, ...);      // Logs
void dwriteWrn (unsigned DL, char *format, ...);      // Logs
void dwriteLog (unsigned DL, char *format, ...);      // Logs
void dwriteS   (unsigned DL, char *format, ...);      // Short
void dwriteE   (unsigned DL, char *format, ...);      // Entry
void dwriteI   (unsigned DL, char *format, ...);      // Internal

#endif

#if (USE_DEBUG_INFO_CLASS == _USE_DEBUG_INFO_CLASS_NONE)
/*---------------------------------------------------------------------------*\
    Release Makros
\*---------------------------------------------------------------------------*/

#define dhead(name, DL)
#define dheadP(name, DL, PL)
#define dprintBuf(data, length)
#define dassert(expr)
#define dwarning(expr)
#define dvalue(val)                         (val)
#define RETURN(format, retval)              return (retval)


#ifdef __linux__

#define dparams(format, x...)
#define dprint(format, x...)
#define dprintWrn(format, x...)
#define dprintErr(format, x...)
#define dinfo(expression, format, x...)

#else

#pragma warning (disable: 4002)             // Ignore: "too many parameters for macro"
#define dparams(format)
#define dprint(format)
#define dprintWrn(format)
#define dprintErr(format)
#define dinfo(expression, format)

#endif


#elif (USE_DEBUG_INFO_CLASS == _USE_DEBUG_INFO_CLASS_EMULATION)
/*---------------------------------------------------------------------------*\
    Debug-Ausgaben direkt ohne die DebugInfoClass
    TODO: noch nicht vollstndig implementiert!!!!!
\*---------------------------------------------------------------------------*/

#define dhead(name, DL)             char *_CDI_Object_Name  = (name);               \
                                    tUInt _CDI_Object_Level = (DL);                 \
                                    if (_CDI_Object_Level >= Dbg_Level_Short) {     \
                                        DbgIPrintFull (NAMEATFUNCSTART_BEGIN "%s%s" \
                                                       NAMEATFUNCSTART_END,         \
                                                       DbgIPrintLinePrefix,         \
                                                       _CDI_Object_Name);           \
                                    }
#define dheadP(name, DL, PL)        char *_CDI_Object_Name = (name);                \
                                    tUInt _CDI_Object_Level = (DL);                 \
                                    if (_CDI_Object_Level >= Dbg_Level_Short) {     \
                                        DbgIPrintFull (NAMEATFUNCSTART_BEGIN "%s%s" \
                                                       NAMEATFUNCSTART_END,         \
                                                       DbgIPrintLinePrefix,         \
                                                       _CDI_Object_Name);           \
                                    }


#define dparams                     if (_CDI_Object_Level >= Dbg_Level_Entry) DbgIPrintParams

#define dprint                      if (_CDI_Object_Level >= Dbg_Level_Internal) DbgIPrintFull

#define dprintBuf(data, length)     if (_CDI_Object_Level >= Dbg_Level_Internal) DbgIPrintBuf

#define dprintWrn                   if (_CDI_Object_Level >= Dbg_Level_Infos) DbgIPrintFull

#define dprintErr                   DbgIPrintFull

#define dwarning(expr)              if (_CDI_Object_Level >= Dbg_Level_Infos) DbgIAssert (expr)

#define dassert(expr)               DbgIAssert (expr)

#define dinfo                       if (_CDI_Object_Level >= Dbg_Level_Infos) DbgIPrintInfo

#define dvalue(val)                 ((_CDI_Object_Level >= Dbg_Level_Internal) ?            \
                                        DbgIPrintValue (val, #val, __FILE__, __LINE__) : (val))

#define RETURN(format, retval)      if (_CDI_Object_Level >= Dbg_Level_Short) {             \
                                        DbgIPrintFull (RETURNVALUE_BEGIN "%x"               \
                                                       RETURNVALUE_END NAMEATFUNCEND_BEGIN  \
                                                       "%s" NAMEATFUNCEND_END, (retval),    \
                                                       _CDI_Object_Name);                   \
                                    }                                                       \
                                    return (retval)


#elif (USE_DEBUG_INFO_CLASS >= _USE_DEBUG_INFO_CLASS_NORMAL)
/*---------------------------------------------------------------------------*\
    Includes nur frs Debuggen
\*---------------------------------------------------------------------------*/

#include <stdarg.h>
#include "CDbgIDS.h"

/*---------------------------------------------------------------------------*\
    Debug Makros & Funktionen
\*---------------------------------------------------------------------------*/

#define dhead(name, DL)             CDebugInfo _CDI_Object (name, DL, Prt_Level_Default, __FILE__, __LINE__)
#define dheadP(name, DL, PL)        CDebugInfo _CDI_Object (name, DL, PL, __FILE__, __LINE__)


//void dparams (const char *format, ...);
#define dparams                     _CDI_Object.PrintParams


//int dprint (const char *format, ...);
#define dprint                      _CDI_Object.print


#define dprintBuf(data, length)     _CDI_Object.printBuf (data, length)


#define dprintWrn                   _CDI_Object.printWrn


#define dprintErr                   _CDI_Object.printErr


#define dassert(expr)               (void) ((expr) || (_CDI_Object.assertion (#expr, __LINE__), 0))

#define dwarning(expr)              (void) ((expr) || (_CDI_Object.warning (#expr, __LINE__), 0))


//int dinfo (const int expression, const char *format, ...);
#define dinfo                       _CDI_Object.info


#define dvalue(val)                 _CDI_Object.printValue (val, #val, __LINE__)


#define RETURN(format, retval)      _CDI_Object.SetRetVal ((format), (retval));     \
                                    return (retval)


/*---------------------------------------------------------------------------*\
    CDebugInfo - Class
\*---------------------------------------------------------------------------*/

class CDebugInfo {
public:
    CDebugInfo (char *FuncName, unsigned DebugLevel, unsigned PrintLevel,
                char *_FileName = "?", unsigned _LineNumber = 0);
    virtual ~CDebugInfo (void);

    void print (const char *format, ...);
    void printBuf (const void *data, unsigned length);
    unsigned printValue (unsigned val, const char *sval, const unsigned int line);

    void printWrn (const char *format, ...);
    void printErr (const char *format, ...);

    void assertion (const char *exp, const unsigned int line);
    void assertion (const int expValue, const char *exp, const char *fname, const unsigned int line);

    void warning (const char *output, const unsigned int line);
    void warning (const int expression, const char *output, const char *fname, const unsigned int line);

    void info (const int expression, const char *format, ...);

    void PrintParams (const char *format, ...);
    void SetRetVal (const char format, ...);

    void ShowAllOutputs (void);

protected:
    void RememberOutput (const char *format, ...);
    void vRememberOutput (const char *format, va_list param);

private:
    char *name;
    char *filename;
    unsigned linenumber;
    unsigned debuglevel;
    unsigned printlevel;
    unsigned spaces;
    CDbgIDynString Output;

    struct RetValueStruct {
        char format;
        union  {
            void *p;
            char *s;
            char  c;
            tUInt u;
            tSInt i;
            tBool b;
        };
    } RetValue;

    void DbgPrintIntern (void);
};

#endif /* (USE_DEBUG_INFO_CLASS) */
/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

#endif