xref: /reactos/drivers/filesystems/udfs/udf_dbg.h (revision 34593d93)
1*c2c66affSColin Finck ////////////////////////////////////////////////////////////////////
2*c2c66affSColin Finck // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3*c2c66affSColin Finck // All rights reserved
4*c2c66affSColin Finck // This file was released under the GPLv2 on June 2015.
5*c2c66affSColin Finck ////////////////////////////////////////////////////////////////////
6*c2c66affSColin Finck /*
7*c2c66affSColin Finck     Module name:
8*c2c66affSColin Finck 
9*c2c66affSColin Finck    Udf_dbg.h
10*c2c66affSColin Finck 
11*c2c66affSColin Finck     Abstract:
12*c2c66affSColin Finck 
13*c2c66affSColin Finck    This file contains small set of debug macroses.
14*c2c66affSColin Finck    It is used by the UDF project.
15*c2c66affSColin Finck 
16*c2c66affSColin Finck */
17*c2c66affSColin Finck 
18*c2c66affSColin Finck #ifndef _UDF_DEBUG_H_
19*c2c66affSColin Finck #define _UDF_DEBUG_H_
20*c2c66affSColin Finck 
21*c2c66affSColin Finck //======================================
22*c2c66affSColin Finck 
23*c2c66affSColin Finck //#define ALWAYS_CHECK_WAIT_TIMEOUT
24*c2c66affSColin Finck //#define PRINT_ALWAYS
25*c2c66affSColin Finck 
26*c2c66affSColin Finck #ifdef UDF_DBG
27*c2c66affSColin Finck 
28*c2c66affSColin Finck //#define CHECK_ALLOC_FRAMES
29*c2c66affSColin Finck 
30*c2c66affSColin Finck //#define TRACK_SYS_ALLOCS
31*c2c66affSColin Finck //#define TRACK_SYS_ALLOC_CALLERS
32*c2c66affSColin Finck 
33*c2c66affSColin Finck // Use internal deadlock detector
34*c2c66affSColin Finck //#define USE_DLD
35*c2c66affSColin Finck 
36*c2c66affSColin Finck #endif //UDF_DBG
37*c2c66affSColin Finck 
38*c2c66affSColin Finck #define PROTECTED_MEM_RTL
39*c2c66affSColin Finck 
40*c2c66affSColin Finck //#define UDF_SIMULATE_WRITES
41*c2c66affSColin Finck 
42*c2c66affSColin Finck //#define USE_PERF_PRINT
43*c2c66affSColin Finck 
44*c2c66affSColin Finck #define USE_KD_PRINT
45*c2c66affSColin Finck #define USE_MM_PRINT
46*c2c66affSColin Finck #define USE_AD_PRINT
47*c2c66affSColin Finck #define UDF_DUMP_EXTENT
48*c2c66affSColin Finck //#define USE_TH_PRINT
49*c2c66affSColin Finck //#define USE_TIME_PRINT
50*c2c66affSColin Finck //#define CHECK_REF_COUNTS
51*c2c66affSColin Finck 
52*c2c66affSColin Finck //======================================
53*c2c66affSColin Finck 
54*c2c66affSColin Finck #if defined UDF_DBG || defined PRINT_ALWAYS
55*c2c66affSColin Finck 
56*c2c66affSColin Finck   ULONG
57*c2c66affSColin Finck   _cdecl
58*c2c66affSColin Finck   DbgPrint(
59*c2c66affSColin Finck       PCH Format,
60*c2c66affSColin Finck       ...
61*c2c66affSColin Finck       );
62*c2c66affSColin Finck 
63*c2c66affSColin Finck 
64*c2c66affSColin Finck   #ifdef KdPrint
65*c2c66affSColin Finck     #undef KdPrint
66*c2c66affSColin Finck   #endif
67*c2c66affSColin Finck 
68*c2c66affSColin Finck   #ifdef USE_KD_PRINT
69*c2c66affSColin Finck     #define KdPrint(_x_) DbgPrint _x_
70*c2c66affSColin Finck   #else
71*c2c66affSColin Finck     #define KdPrint(a)  {NOTHING;}
72*c2c66affSColin Finck   #endif //USE_KD_PRINT
73*c2c66affSColin Finck 
74*c2c66affSColin Finck   #ifdef USE_MM_PRINT
75*c2c66affSColin Finck     #define MmPrint(_x_) DbgPrint _x_
76*c2c66affSColin Finck   #else
77*c2c66affSColin Finck     #define MmPrint(_x_) {NOTHING;}
78*c2c66affSColin Finck   #endif //USE_MM_PRINT
79*c2c66affSColin Finck 
80*c2c66affSColin Finck   #ifdef USE_TIME_PRINT
81*c2c66affSColin Finck     extern ULONG UdfTimeStamp;
82*c2c66affSColin Finck     #define TmPrint(_x_) {UdfTimeStamp++;KdPrint(("TM:%d: ",UdfTimeStamp));KdPrint(_x_);}
83*c2c66affSColin Finck   #else
84*c2c66affSColin Finck     #define TmPrint KdPrint
85*c2c66affSColin Finck   #endif //USE_MM_PRINT
86*c2c66affSColin Finck 
87*c2c66affSColin Finck   #ifdef USE_PERF_PRINT
88*c2c66affSColin Finck     #define PerfPrint(_x_) DbgPrint _x_
89*c2c66affSColin Finck   #else
90*c2c66affSColin Finck     #define PerfPrint(_x_) {NOTHING;}
91*c2c66affSColin Finck   #endif //USE_MM_PRINT
92*c2c66affSColin Finck 
93*c2c66affSColin Finck   #ifdef USE_AD_PRINT
94*c2c66affSColin Finck     #define AdPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
95*c2c66affSColin Finck   #else
96*c2c66affSColin Finck     #define AdPrint(_x_) {NOTHING;}
97*c2c66affSColin Finck   #endif
98*c2c66affSColin Finck 
99*c2c66affSColin Finck   #ifdef USE_TH_PRINT
100*c2c66affSColin Finck     #define ThPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
101*c2c66affSColin Finck   #else
102*c2c66affSColin Finck     #define ThPrint(_x_) {NOTHING;}
103*c2c66affSColin Finck   #endif
104*c2c66affSColin Finck 
105*c2c66affSColin Finck   #ifdef UDF_DUMP_EXTENT
106*c2c66affSColin Finck     #define ExtPrint(_x_)  KdPrint(_x_)
107*c2c66affSColin Finck   #else
108*c2c66affSColin Finck     #define ExtPrint(_x_)  {NOTHING;}
109*c2c66affSColin Finck   #endif
110*c2c66affSColin Finck 
111*c2c66affSColin Finck #else // defined UDF_DBG || defined PRINT_ALWAYS
112*c2c66affSColin Finck 
113*c2c66affSColin Finck   #define MmPrint(_x_)   {NOTHING;}
114*c2c66affSColin Finck   #define TmPrint(_x_)   {NOTHING;}
115*c2c66affSColin Finck   #define PerfPrint(_x_) {NOTHING;}
116*c2c66affSColin Finck   #define AdPrint(_x_)   {NOTHING;}
117*c2c66affSColin Finck   #define ThPrint(_x_)   {NOTHING;}
118*c2c66affSColin Finck   #define ExtPrint(_x_)  {NOTHING;}
119*c2c66affSColin Finck 
120*c2c66affSColin Finck #endif // defined UDF_DBG || defined PRINT_ALWAYS
121*c2c66affSColin Finck 
122*c2c66affSColin Finck NTSTATUS
123*c2c66affSColin Finck DbgWaitForSingleObject_(
124*c2c66affSColin Finck     IN PVOID Object,
125*c2c66affSColin Finck     IN PLARGE_INTEGER Timeout OPTIONAL
126*c2c66affSColin Finck     );
127*c2c66affSColin Finck 
128*c2c66affSColin Finck #if defined ALWAYS_CHECK_WAIT_TIMEOUT
129*c2c66affSColin Finck   #define DbgWaitForSingleObject(o, to)   DbgWaitForSingleObject_(o, to)
130*c2c66affSColin Finck #else
131*c2c66affSColin Finck   #define DbgWaitForSingleObject(o, to)   KeWaitForSingleObject(o, Executive, KernelMode, FALSE, to);
132*c2c66affSColin Finck #endif
133*c2c66affSColin Finck 
134*c2c66affSColin Finck #ifdef UDF_DBG
135*c2c66affSColin Finck 
136*c2c66affSColin Finck #ifdef _X86_
137*c2c66affSColin Finck // This is an illegal use of INT3
138*c2c66affSColin Finck #define UDFBreakPoint() { __asm int 3 }
139*c2c66affSColin Finck #else // _X86_
140*c2c66affSColin Finck 
141*c2c66affSColin Finck #define UDFBreakPoint() DbgBreakPoint()
142*c2c66affSColin Finck #endif // _X86_
143*c2c66affSColin Finck 
144*c2c66affSColin Finck #ifdef BRUTE
145*c2c66affSColin Finck #define BrutePoint() UDFBreakPoint()
146*c2c66affSColin Finck #else
147*c2c66affSColin Finck #define BrutePoint() {}
148*c2c66affSColin Finck #endif // BRUTE
149*c2c66affSColin Finck 
150*c2c66affSColin Finck #ifdef CHECK_REF_COUNTS
151*c2c66affSColin Finck #define ASSERT_REF(_a_) ASSERT(_a_)
152*c2c66affSColin Finck #else
153*c2c66affSColin Finck #define ASSERT_REF(_a_) {NOTHING;}
154*c2c66affSColin Finck #endif //CHECK_REF_COUNTS
155*c2c66affSColin Finck 
156*c2c66affSColin Finck #ifdef TRACK_SYS_ALLOCS
157*c2c66affSColin Finck 
158*c2c66affSColin Finck PVOID DebugAllocatePool(POOL_TYPE Type,ULONG size
159*c2c66affSColin Finck #ifdef TRACK_SYS_ALLOC_CALLERS
160*c2c66affSColin Finck , ULONG SrcId, ULONG SrcLine
161*c2c66affSColin Finck #endif //TRACK_SYS_ALLOC_CALLERS
162*c2c66affSColin Finck );
163*c2c66affSColin Finck VOID DebugFreePool(PVOID addr);
164*c2c66affSColin Finck 
165*c2c66affSColin Finck #ifdef TRACK_SYS_ALLOC_CALLERS
166*c2c66affSColin Finck   #define DbgAllocatePoolWithTag(a,b,c) DebugAllocatePool(a,b,UDF_BUG_CHECK_ID,__LINE__)
167*c2c66affSColin Finck   #define DbgAllocatePool(x,y) DebugAllocatePool(x,y,UDF_BUG_CHECK_ID,__LINE__)
168*c2c66affSColin Finck #else //TRACK_SYS_ALLOC_CALLERS
169*c2c66affSColin Finck   #define DbgAllocatePoolWithTag(a,b,c) DebugAllocatePool(a,b)
170*c2c66affSColin Finck   #define DbgAllocatePool(x,y) DebugAllocatePool(x,y)
171*c2c66affSColin Finck #endif //TRACK_SYS_ALLOC_CALLERS
172*c2c66affSColin Finck #define DbgFreePool(x) DebugFreePool(x)
173*c2c66affSColin Finck 
174*c2c66affSColin Finck #else //TRACK_SYS_ALLOCS
175*c2c66affSColin Finck 
176*c2c66affSColin Finck #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
177*c2c66affSColin Finck #define DbgAllocatePool(x,y) ExAllocatePoolWithTag(x,y,'Fnwd')
178*c2c66affSColin Finck #define DbgFreePool(x) ExFreePool(x)
179*c2c66affSColin Finck 
180*c2c66affSColin Finck #endif //TRACK_SYS_ALLOCS
181*c2c66affSColin Finck 
182*c2c66affSColin Finck 
183*c2c66affSColin Finck #ifdef PROTECTED_MEM_RTL
184*c2c66affSColin Finck 
185*c2c66affSColin Finck #define DbgMoveMemory(d, s, l)   \
186*c2c66affSColin Finck _SEH2_TRY {                               \
187*c2c66affSColin Finck     RtlMoveMemory(d, s, l);               \
188*c2c66affSColin Finck } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {  \
189*c2c66affSColin Finck     BrutePoint();                         \
190*c2c66affSColin Finck } _SEH2_END;
191*c2c66affSColin Finck 
192*c2c66affSColin Finck #define DbgCopyMemory(d, s, l)   \
193*c2c66affSColin Finck _SEH2_TRY {                               \
194*c2c66affSColin Finck     RtlCopyMemory(d, s, l);               \
195*c2c66affSColin Finck } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {  \
196*c2c66affSColin Finck     BrutePoint();                         \
197*c2c66affSColin Finck } _SEH2_END;
198*c2c66affSColin Finck 
199*c2c66affSColin Finck __inline
200*c2c66affSColin Finck ULONG
DbgCompareMemory(PVOID d,PVOID s,ULONG l)201*c2c66affSColin Finck DbgCompareMemory(PVOID d, PVOID s, ULONG l) {
202*c2c66affSColin Finck     _SEH2_TRY {
203*c2c66affSColin Finck         return RtlCompareMemory(d, s, l);
204*c2c66affSColin Finck     } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
205*c2c66affSColin Finck         BrutePoint();
206*c2c66affSColin Finck     } _SEH2_END;
207*c2c66affSColin Finck     return -1;
208*c2c66affSColin Finck }
209*c2c66affSColin Finck 
210*c2c66affSColin Finck #else //PROTECTED_MEM_RTL
211*c2c66affSColin Finck 
212*c2c66affSColin Finck #define DbgMoveMemory(d, s, l)     RtlMoveMemory(d, s, l)
213*c2c66affSColin Finck #define DbgCopyMemory(d, s, l)     RtlCopyMemory(d, s, l)
214*c2c66affSColin Finck #define DbgCompareMemory(d, s, l)  RtlCompareMemory(d, s, l)
215*c2c66affSColin Finck 
216*c2c66affSColin Finck #endif //PROTECTED_MEM_RTL
217*c2c66affSColin Finck 
218*c2c66affSColin Finck //#define KdPrint(_x_)
219*c2c66affSColin Finck 
220*c2c66affSColin Finck #ifdef VALIDATE_STRUCTURES
221*c2c66affSColin Finck #define ValidateFileInfo(fi)            \
222*c2c66affSColin Finck {    /* validate FileInfo */            \
223*c2c66affSColin Finck     if(!fi || (fi)->IntegrityTag) {            \
224*c2c66affSColin Finck         KdPrint(("UDF: ERROR! Using deallocated structure !!!\n"));\
225*c2c66affSColin Finck         BrutePoint();                   \
226*c2c66affSColin Finck     }                                   \
227*c2c66affSColin Finck     if(fi && !fi->Dloc) {               \
228*c2c66affSColin Finck         KdPrint(("UDF: ERROR! FI without Dloc !!!\n"));\
229*c2c66affSColin Finck         BrutePoint();                   \
230*c2c66affSColin Finck     }                                   \
231*c2c66affSColin Finck }
232*c2c66affSColin Finck 
233*c2c66affSColin Finck #else
234*c2c66affSColin Finck #define ValidateFileInfo(fi)  {}
235*c2c66affSColin Finck #endif
236*c2c66affSColin Finck 
237*c2c66affSColin Finck #if defined (_X86_) && defined (_MSC_VER)
238*c2c66affSColin Finck 
UDFTouch(IN PVOID addr)239*c2c66affSColin Finck __inline VOID UDFTouch(IN PVOID addr)
240*c2c66affSColin Finck {
241*c2c66affSColin Finck     __asm {
242*c2c66affSColin Finck         mov  eax,addr
243*c2c66affSColin Finck         mov  al,[byte ptr eax]
244*c2c66affSColin Finck     }
245*c2c66affSColin Finck }
246*c2c66affSColin Finck 
247*c2c66affSColin Finck #else   // NO X86 optimization , use generic C/C++
248*c2c66affSColin Finck 
UDFTouch(IN PVOID addr)249*c2c66affSColin Finck __inline VOID UDFTouch(IN PVOID addr)
250*c2c66affSColin Finck {
251*c2c66affSColin Finck     UCHAR a = ((PUCHAR)addr)[0];
252*c2c66affSColin Finck     a = a;
253*c2c66affSColin Finck }
254*c2c66affSColin Finck 
255*c2c66affSColin Finck #endif // _X86_
256*c2c66affSColin Finck 
257*c2c66affSColin Finck #else // UDF_DBG
258*c2c66affSColin Finck 
259*c2c66affSColin Finck #define DbgAllocatePool(x,y) ExAllocatePoolWithTag(x,y,'Fnwd')
260*c2c66affSColin Finck #define DbgFreePool(x) ExFreePool(x)
261*c2c66affSColin Finck #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
262*c2c66affSColin Finck 
263*c2c66affSColin Finck #define DbgMoveMemory(d, s, l)     RtlMoveMemory(d, s, l)
264*c2c66affSColin Finck #define DbgCopyMemory(d, s, l)     RtlCopyMemory(d, s, l)
265*c2c66affSColin Finck #define DbgCompareMemory(d, s, l)  RtlCompareMemory(d, s, l)
266*c2c66affSColin Finck 
267*c2c66affSColin Finck #define ASSERT_REF(_a_) {NOTHING;}
268*c2c66affSColin Finck 
269*c2c66affSColin Finck #define UDFBreakPoint() {}
270*c2c66affSColin Finck #define BrutePoint() {}
271*c2c66affSColin Finck #define ValidateFileInfo(fi)  {}
272*c2c66affSColin Finck 
273*c2c66affSColin Finck #define UDFTouch(addr) {}
274*c2c66affSColin Finck 
275*c2c66affSColin Finck #endif // UDF_DBG
276*c2c66affSColin Finck 
277*c2c66affSColin Finck #if defined UDF_DBG || defined PRINT_ALWAYS
278*c2c66affSColin Finck 
279*c2c66affSColin Finck #define KdDump(a,b)                         \
280*c2c66affSColin Finck if((a)!=NULL) {                             \
281*c2c66affSColin Finck     ULONG i;                                \
282*c2c66affSColin Finck     for(i=0; i<(b); i++) {                  \
283*c2c66affSColin Finck         ULONG c;                            \
284*c2c66affSColin Finck         c = (ULONG)(*(((PUCHAR)(a))+i));    \
285*c2c66affSColin Finck         KdPrint(("%2.2x ",c));              \
286*c2c66affSColin Finck         if ((i & 0x0f) == 0x0f) KdPrint(("\n"));   \
287*c2c66affSColin Finck     }                                       \
288*c2c66affSColin Finck     KdPrint(("\n"));                        \
289*c2c66affSColin Finck }
290*c2c66affSColin Finck 
291*c2c66affSColin Finck #else
292*c2c66affSColin Finck 
293*c2c66affSColin Finck #define KdDump(a,b) {}
294*c2c66affSColin Finck 
295*c2c66affSColin Finck #endif // UDF_DBG
296*c2c66affSColin Finck 
297*c2c66affSColin Finck #define UserPrint  KdPrint
298*c2c66affSColin Finck 
299*c2c66affSColin Finck #endif  // _UDF_DEBUG_H_
300