source: branches/swt/include/dbglog.h

Last change on this file was 22092, checked in by rousseau, 11 years ago

Made simple console logging a build option

File size: 4.5 KB
Line 
1/*
2 * Miscellaneous definitions
3 * Debug prototypes and macros
4 */
5
6
7#ifndef __DBGLOG_H__
8#define __DBGLOG_H__
9
10#if !defined(_OS2WIN_H) && !defined(__INCLUDE_WINUSER_H) && !defined(__WINE_WINBASE_H) && !defined(__WINE_WINDEF_H)
11 #include <win32type.h>
12#endif
13
14#ifdef __cplusplus
15 extern "C" {
16#endif
17
18// To enable global console logging, use 'kmk DBG_CON=' _or_ set 'DBG_CON='
19// in LocalConfig.kmk _or_ set DBG_CON to some value in the environment.
20// Per source console logging can be enabled by defining DBG_CON _before_
21// the inclusion of the <misc.h> header.
22#ifdef DBG_CON
23#define PFXFMT "**__con_debug(%d)** "
24#define __con_debug(lvl, fmt, ...)\
25switch (lvl) {\
26 case 0:\
27 break;\
28 case 2:\
29 printf(PFXFMT, lvl);\
30 printf(fmt, __VA_ARGS__);\
31 break;\
32 case 3:\
33 printf(PFXFMT"FUNCTION:%s ", lvl, __FUNCTION__);\
34 printf(fmt, __VA_ARGS__);\
35 break;\
36 case 4:\
37 printf(PFXFMT"FILE:%s FUNCTION:%s ", lvl, __FILE__, __FUNCTION__);\
38 printf(fmt, __VA_ARGS__);\
39 break;\
40 case 5:\
41 printf(PFXFMT, lvl);\
42 printf(fmt, __VA_ARGS__);\
43 break;\
44 default:\
45 printf(fmt, __VA_ARGS__);\
46 break;\
47}\
48fflush(stdout)
49#else
50#define __con_debug(lvl, fmt, ...)
51#endif
52
53#ifdef DEBUG
54#define DEBUG_LOGGING 1
55#ifdef PRIVATE_LOGGING
56 //To use private dll logging, define PRIVATE_LOGGING and
57 //add Open/ClosePrivateLogFiles (see below) functions to the dll
58 //to open close the private logfile. The logfile handle should
59 //be stored in the _privateLogFile variable
60 //dprintf can be called like this:
61 //dprintf((LOG, "PE file : %s", szFileName));
62 #define LOG (void*)_privateLogFile
63 #define dprintf(a) WritePrivateLog a
64 #define dprintfGlobal(a) WriteLog a
65#else
66 #define dprintf(a) WriteLog a
67 #define dprintfNoEOL(a) WriteLogNoEOL a
68#endif
69 #define eprintf(a) WriteLog a
70 #define dassert(a, b) if(!(a)) dprintf b
71 #define dbgCheckObj(a) a->checkObject()
72 #define dprintfLock() WriteLogLock()
73 #define dprintfUnlock() WriteLogUnlock()
74 #define DisableLogging() DecreaseLogCount()
75 #define EnableLogging() IncreaseLogCount()
76
77#ifdef DEBUG_ENABLELOG_LEVEL2
78#ifdef PRIVATE_LOGGING
79 #define dprintf2(a) WritePrivateLog a
80#else
81 #define dprintf2(a) WriteLog a
82#endif
83#else
84 #define dprintf2(a)
85#endif
86
87#else
88 #define dprintfGlobal(a)
89 #define dprintf(a)
90 #define dprintf2(a)
91 #define dprintfNoEOL(a)
92 #define eprintf(a)
93 #define dassert(a, b)
94 #define dbgCheckObj(a)
95 #define dprintfLock()
96 #define dprintfUnlock()
97 #define DisableLogging()
98 #define EnableLogging()
99#endif
100
101
102// necessary types
103#ifndef __WINE_WINDEF_H
104#ifdef ULONG
105 #error ULONG definition is bad.
106 #define ULONG nope.
107#endif
108#if !defined(NO_ULONG) && !defined(OS2DEF_INCLUDED)
109 typedef unsigned long ULONG;
110 typedef unsigned long HMODULE;
111#endif
112#endif //!__WINE_WINDEF_H
113
114#ifndef SYSTEM
115# define SYSTEM _System
116#endif
117
118
119int SYSTEM WriteLog(const char *tekst, ...);
120int SYSTEM WriteLogNoEOL(const char *tekst, ...);
121int SYSTEM WritePrivateLog(void *logfile, const char *tekst, ...);
122
123void SYSTEM WriteLogLock();
124void SYSTEM WriteLogUnlock();
125
126void SYSTEM DecreaseLogCount();
127void SYSTEM IncreaseLogCount();
128
129void SYSTEM CheckVersion(ULONG version, char *modname);
130
131void SYSTEM CheckVersionFromHMOD(ULONG version, HMODULE hModule);
132
133int SYSTEM DebugErrorBox(ULONG iErrorCode,
134 char* pszFormat,
135 ...);
136
137//To use private logfiles for dlls, you must have these functions and call
138//them when the dll is loaded (open) and the exitlist handler is called (close)
139void OpenPrivateLogFiles();
140void ClosePrivateLogFiles();
141
142/* enable support for the _interrupt() statement */
143#if defined(__IBMCPP__) || defined(__IBMC__) || defined(__GNUC__)
144
145#ifndef __GNUC__
146# include <builtin.h>
147#endif
148
149#ifdef DEBUG
150
151#ifdef __cplusplus
152
153#ifdef PRIVATE_LOGGING
154#define DebugInt3() do { \
155 dprintf((LOG, "BREAKPOINT %s %s %d", __FILE__, __FUNCTION__, __LINE__)); \
156 _interrupt(3); \
157} while (0)
158#else
159#define DebugInt3() do { \
160 dprintf(("BREAKPOINT %s %s %d", __FILE__, __FUNCTION__, __LINE__)); \
161 _interrupt(3); \
162} while (0)
163#endif
164
165#else /* __cplusplus */
166 #define DebugInt3() _interrupt(3)
167#endif
168
169#else /* DEBUG */
170 #define DebugInt3()
171#endif
172
173#else /* defined(__IBMCPP__) || defined(__IBMC__) || defined(__GNUC__) */
174
175#ifdef DEBUG
176 #define DebugInt3() _asm int 3;
177#else
178 #define DebugInt3()
179#endif
180
181#endif /* defined(__IBMCPP__) || defined(__IBMC__) || defined(__GNUC__) */
182
183#ifdef __cplusplus
184 }
185#endif
186
187
188#endif //__DBGLOG_H__
189
Note: See TracBrowser for help on using the repository browser.