branch update for HEAD-2003021201
[reactos.git] / include / debug.h
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            include/internal/debug.h
5  * PURPOSE:         Useful debugging macros
6  * PROGRAMMER:      David Welch (welch@mcmail.com)
7  * UPDATE HISTORY: 
8  *                28/05/98: Created
9  */
10
11 /*
12  * NOTE: Define NDEBUG before including this header to disable debugging
13  * macros
14  */
15
16 #ifndef __INTERNAL_DEBUG
17 #define __INTERNAL_DEBUG
18
19 #define UNIMPLEMENTED do {DbgPrint("%s at %s:%d is unimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;);  } while(0);
20
21 /*  FIXME: should probably remove this later  */
22 #if !defined(CHECKED) && !defined(NDEBUG)
23 #define CHECKED
24 #endif
25
26 #ifndef assert
27 #ifndef NASSERT
28 #define assert(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
29 #else
30 #define assert(x)
31 #endif
32 #endif
33
34 #define DPRINT1(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0);
35 #define CHECKPOINT1 do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
36
37 extern unsigned int old_idt[256][2];
38 //extern unsigned int idt;
39 extern unsigned int old_idt_valid;
40
41 #ifdef __NTOSKRNL__
42 //#define DPRINT_CHECKS ExAllocatePool(NonPagedPool,0); assert(old_idt_valid || (!memcmp(old_idt,KiIdt,256*2)));
43 //#define DPRINT_CHECKS ExAllocatePool(NonPagedPool,0);
44 #define DPRINT_CHECKS
45 #else
46 #define DPRINT_CHECKS
47 #endif
48
49 #ifndef NDEBUG
50 #define OLD_DPRINT(fmt,args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(fmt,args); } while(0);
51 #define DPRINT(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); DPRINT_CHECKS  } while(0);
52 #define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
53 #else
54 //#define DPRINT(args...) do { DPRINT_CHECKS } while (0);
55 #define DPRINT(args...)
56 #define OLD_DPRINT(args...)
57 #define CHECKPOINT
58 #endif /* NDEBUG */
59
60 /*
61  * FUNCTION: Assert a maximum value for the current irql
62  * ARGUMENTS:
63  *        x = Maximum irql
64  */
65 #define ASSERT_IRQL(x) assert(KeGetCurrentIrql()<=(x))
66 #define assert_irql(x) assert(KeGetCurrentIrql()<=(x))
67
68 #define HBP_EXECUTE     (0)
69 #define HBP_WRITE       (1)
70 #define HBP_READWRITE   (3)
71
72 #define HBP_BYTE        (0)
73 #define HBP_WORD        (1)
74 #define HBP_DWORD       (3)
75
76 /*
77  * FUNCTION: Sets a hardware breakpoint
78  * ARGUMENTS:
79  *          i = breakpoint to set (0 to 3)
80  *          addr = linear address to break on
81  *          type = Type of access to break on
82  *          len = length of the variable to watch
83  * NOTES:
84  *       The variable to watch must be aligned to its length (i.e. a dword
85  *       breakpoint must be aligned to a dword boundary)
86  * 
87  *       A fatal exception will be generated on the access to the variable.
88  *       It is (at the moment) only really useful for catching undefined
89  *       pointers if you know the variable effected but not the buggy
90  *       routine. 
91  * 
92  * FIXME: Extend to call out to kernel debugger on breakpoint
93  *        Add support for I/O breakpoints
94  * REFERENCES: See the i386 programmer manual for more details
95  */ 
96 void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
97                     unsigned int len);
98
99
100 #endif /* __INTERNAL_DEBUG */