strip whitespace from end of lines
[reactos.git] / reactos / ntoskrnl / kd / kdmain.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/kd/kdinit.c
5 * PURPOSE: Kernel Debugger Initializtion
6 *
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8 */
9
10 #include <ntoskrnl.h>
11 #define NDEBUG
12 #include <internal/debug.h>
13
14 /* VARIABLES ***************************************************************/
15
16 BOOLEAN EXPORTED KdDebuggerEnabled = FALSE;
17 BOOLEAN EXPORTED KdEnteredDebugger = FALSE;
18 BOOLEAN EXPORTED KdDebuggerNotPresent = TRUE;
19 BOOLEAN EXPORTED KiEnableTimerWatchdog = FALSE;
20 ULONG EXPORTED KiBugCheckData;
21 BOOLEAN KdpBreakPending;
22 VOID STDCALL PspDumpThreads(BOOLEAN SystemThreads);
23
24 /* PRIVATE FUNCTIONS *********************************************************/
25
26 ULONG
27 STDCALL
28 KdpServiceDispatcher(ULONG Service,
29 PVOID Context1,
30 PVOID Context2)
31 {
32 ULONG Result = 0;
33
34 switch (Service)
35 {
36 case 1: /* DbgPrint */
37 Result = KdpPrintString ((PANSI_STRING)Context1);
38 break;
39
40 case TAG('R', 'o', 's', ' '): /* ROS-INTERNAL */
41 {
42 switch ((ULONG)Context1)
43 {
44 case DumpNonPagedPool:
45 MiDebugDumpNonPagedPool(FALSE);
46 break;
47
48 case ManualBugCheck:
49 KEBUGCHECK(MANUALLY_INITIATED_CRASH);
50 break;
51
52 case DumpNonPagedPoolStats:
53 MiDebugDumpNonPagedPoolStats(FALSE);
54 break;
55
56 case DumpNewNonPagedPool:
57 MiDebugDumpNonPagedPool(TRUE);
58 break;
59
60 case DumpNewNonPagedPoolStats:
61 MiDebugDumpNonPagedPoolStats(TRUE);
62 break;
63
64 case DumpAllThreads:
65 PspDumpThreads(TRUE);
66 break;
67
68 case DumpUserThreads:
69 PspDumpThreads(FALSE);
70 break;
71
72 case EnterDebugger:
73 DbgBreakPoint();
74 break;
75
76 default:
77 break;
78 }
79 }
80
81 default:
82 HalDisplayString ("Invalid debug service call!\n");
83 break;
84 }
85
86 return Result;
87 }
88
89 KD_CONTINUE_TYPE
90 STDCALL
91 KdpEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
92 KPROCESSOR_MODE PreviousMode,
93 PCONTEXT Context,
94 PKTRAP_FRAME TrapFrame,
95 BOOLEAN FirstChance,
96 BOOLEAN Gdb)
97 {
98 /* Get out of here if the Debugger isn't enabled */
99 if (!KdDebuggerEnabled) return kdHandleException;
100
101 /* FIXME:
102 * Right now, the GDB wrapper seems to handle exceptions differntly
103 * from KDGB and both are called at different times, while the GDB
104 * one is only called once and that's it. I don't really have the knowledge
105 * to fix the GDB stub, so until then, we'll be using this hack
106 */
107 if (Gdb)
108 {
109 /* Call the registered wrapper */
110 if (WrapperInitRoutine) return WrapperTable.
111 KdpExceptionRoutine(ExceptionRecord,
112 Context,
113 TrapFrame);
114 }
115
116 /* Call KDBG if available */
117 return KdbEnterDebuggerException(ExceptionRecord,
118 PreviousMode,
119 Context,
120 TrapFrame,
121 FirstChance);
122 }
123
124 /* PUBLIC FUNCTIONS *********************************************************/
125
126 /*
127 * @implemented
128 */
129 VOID
130 STDCALL
131 KdDisableDebugger(VOID)
132 {
133 KIRQL OldIrql;
134
135 /* Raise IRQL */
136 KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
137
138 /* TODO: Disable any breakpoints */
139
140 /* Disable the Debugger */
141 KdDebuggerEnabled = FALSE;
142
143 /* Lower the IRQL */
144 KeLowerIrql(OldIrql);
145 }
146
147 /*
148 * @implemented
149 */
150 VOID
151 STDCALL
152 KdEnableDebugger(VOID)
153 {
154 KIRQL OldIrql;
155
156 /* Raise IRQL */
157 KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
158
159 /* TODO: Re-enable any breakpoints */
160
161 /* Enable the Debugger */
162 KdDebuggerEnabled = TRUE;
163
164 /* Lower the IRQL */
165 KeLowerIrql(OldIrql);
166 }
167
168 /*
169 * @implemented
170 */
171 BOOLEAN
172 STDCALL
173 KdPollBreakIn(VOID)
174 {
175 return KdpBreakPending;
176 }
177
178 /*
179 * @implemented
180 */
181 VOID
182 STDCALL
183 KeEnterKernelDebugger(VOID)
184 {
185 HalDisplayString("\n\n *** Entered kernel debugger ***\n");
186
187 /* Set the Variable */
188 KdEnteredDebugger = TRUE;
189
190 /* Halt the CPU */
191 for (;;) Ke386HaltProcessor();
192 }
193
194 /*
195 * @unimplemented
196 */
197 NTSTATUS
198 STDCALL
199 KdPowerTransition(ULONG PowerState)
200 {
201 UNIMPLEMENTED;
202 return STATUS_NOT_IMPLEMENTED;
203 }
204
205 /* EOF */