2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/kd/kdinit.c
5 * PURPOSE: Kernel Debugger Initializtion
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
12 #include <internal/debug.h>
14 /* VARIABLES ***************************************************************/
16 BOOLEAN KdDebuggerEnabled
= FALSE
;
17 BOOLEAN KdEnteredDebugger
= FALSE
;
18 BOOLEAN KdDebuggerNotPresent
= TRUE
;
19 BOOLEAN KiEnableTimerWatchdog
= FALSE
;
20 BOOLEAN KdBreakAfterSymbolLoad
= FALSE
;
21 BOOLEAN KdpBreakPending
;
22 VOID STDCALL
PspDumpThreads(BOOLEAN SystemThreads
);
29 #define MAX_KD_COMPONENT_TABLE_ENTRIES 128
30 KD_COMPONENT_DATA KdComponentTable
[MAX_KD_COMPONENT_TABLE_ENTRIES
];
31 ULONG KdComponentTableEntries
= 0;
33 /* PRIVATE FUNCTIONS *********************************************************/
37 KdpServiceDispatcher(ULONG Service
,
45 case BREAKPOINT_PRINT
: /* DbgPrint */
46 Result
= KdpPrintString(Buffer1
, Buffer1Length
);
50 case TAG('R', 'o', 's', ' '): /* ROS-INTERNAL */
52 switch ((ULONG
)Buffer1
)
54 case DumpNonPagedPool
:
55 MiDebugDumpNonPagedPool(FALSE
);
59 KEBUGCHECK(MANUALLY_INITIATED_CRASH
);
62 case DumpNonPagedPoolStats
:
63 MiDebugDumpNonPagedPoolStats(FALSE
);
66 case DumpNewNonPagedPool
:
67 MiDebugDumpNonPagedPool(TRUE
);
70 case DumpNewNonPagedPoolStats
:
71 MiDebugDumpNonPagedPoolStats(TRUE
);
79 PspDumpThreads(FALSE
);
92 HalDisplayString ("Invalid debug service call!\n");
101 KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame
,
102 IN PKEXCEPTION_FRAME ExceptionFrame
,
103 IN PEXCEPTION_RECORD ExceptionRecord
,
105 IN KPROCESSOR_MODE PreviousMode
,
106 IN BOOLEAN SecondChance
)
108 KD_CONTINUE_TYPE Return
;
110 /* HACK (just like all this routine */
111 if (ExceptionRecord
->ExceptionCode
== STATUS_BREAKPOINT
) Context
->Eip
++;
113 /* Get out of here if the Debugger isn't connected */
114 if (KdDebuggerNotPresent
) return FALSE
;
116 /* Call KDBG if available */
117 Return
= KdbEnterDebuggerException(ExceptionRecord
,
123 /* Convert return to BOOLEAN */
124 if (Return
== kdContinue
) return TRUE
;
130 KdpCallGdb(IN PKTRAP_FRAME TrapFrame
,
131 IN PEXCEPTION_RECORD ExceptionRecord
,
134 KD_CONTINUE_TYPE Return
= kdDoNotHandleException
;
136 /* Get out of here if the Debugger isn't connected */
137 if (KdDebuggerNotPresent
) return FALSE
;
140 * Right now, the GDB wrapper seems to handle exceptions differntly
141 * from KDGB and both are called at different times, while the GDB
142 * one is only called once and that's it. I don't really have the knowledge
143 * to fix the GDB stub, so until then, we'll be using this hack
145 if (WrapperInitRoutine
)
147 Return
= WrapperTable
.KdpExceptionRoutine(ExceptionRecord
,
152 /* Convert return to BOOLEAN */
153 if (Return
== kdContinue
) return TRUE
;
157 /* PUBLIC FUNCTIONS *********************************************************/
164 KdDisableDebugger(VOID
)
169 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
171 /* TODO: Disable any breakpoints */
173 /* Disable the Debugger */
174 KdDebuggerEnabled
= FALSE
;
177 KeLowerIrql(OldIrql
);
180 return STATUS_SUCCESS
;
188 KdEnableDebugger(VOID
)
193 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
195 /* TODO: Re-enable any breakpoints */
197 /* Enable the Debugger */
198 KdDebuggerEnabled
= TRUE
;
201 KeLowerIrql(OldIrql
);
204 return STATUS_SUCCESS
;
214 return KdpBreakPending
;
222 KeEnterKernelDebugger(VOID
)
224 HalDisplayString("\n\n *** Entered kernel debugger ***\n");
226 /* Set the Variable */
227 KdEnteredDebugger
= TRUE
;
230 for (;;) Ke386HaltProcessor();
238 KdPowerTransition(ULONG PowerState
)
241 return STATUS_NOT_IMPLEMENTED
;
249 KdChangeOption(IN KD_OPTION Option
,
250 IN ULONG InBufferLength OPTIONAL
,
252 IN ULONG OutBufferLength OPTIONAL
,
254 OUT PULONG OutBufferRequiredLength OPTIONAL
)
257 return STATUS_NOT_IMPLEMENTED
;
263 NtQueryDebugFilterState(IN ULONG ComponentId
,
268 /* convert Level to mask if it isn't already one */
272 for ( i
= 0; i
< KdComponentTableEntries
; i
++ )
274 if ( ComponentId
== KdComponentTable
[i
].ComponentId
)
276 if ( Level
& KdComponentTable
[i
].Level
)
286 NtSetDebugFilterState(IN ULONG ComponentId
,
291 for ( i
= 0; i
< KdComponentTableEntries
; i
++ )
293 if ( ComponentId
== KdComponentTable
[i
].ComponentId
)
296 if ( i
== KdComponentTableEntries
)
298 if ( i
== MAX_KD_COMPONENT_TABLE_ENTRIES
)
299 return STATUS_INVALID_PARAMETER_1
;
300 ++KdComponentTableEntries
;
301 KdComponentTable
[i
].ComponentId
= ComponentId
;
302 KdComponentTable
[i
].Level
= 0;
305 KdComponentTable
[i
].Level
|= Level
;
307 KdComponentTable
[i
].Level
&= ~Level
;
308 return STATUS_SUCCESS
;
311 PKDEBUG_ROUTINE KiDebugRoutine
= KdpEnterDebuggerException
;