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
;
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(PEXCEPTION_RECORD ExceptionRecord
,
102 KPROCESSOR_MODE PreviousMode
,
104 PKTRAP_FRAME TrapFrame
,
108 /* Get out of here if the Debugger isn't enabled */
109 if (!KdDebuggerEnabled
) return kdHandleException
;
112 * Right now, the GDB wrapper seems to handle exceptions differntly
113 * from KDGB and both are called at different times, while the GDB
114 * one is only called once and that's it. I don't really have the knowledge
115 * to fix the GDB stub, so until then, we'll be using this hack
119 /* Call the registered wrapper */
120 if (WrapperInitRoutine
) return WrapperTable
.
121 KdpExceptionRoutine(ExceptionRecord
,
126 /* Call KDBG if available */
127 return KdbEnterDebuggerException(ExceptionRecord
,
134 /* PUBLIC FUNCTIONS *********************************************************/
141 KdDisableDebugger(VOID
)
146 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
148 /* TODO: Disable any breakpoints */
150 /* Disable the Debugger */
151 KdDebuggerEnabled
= FALSE
;
154 KeLowerIrql(OldIrql
);
162 KdEnableDebugger(VOID
)
167 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
169 /* TODO: Re-enable any breakpoints */
171 /* Enable the Debugger */
172 KdDebuggerEnabled
= TRUE
;
175 KeLowerIrql(OldIrql
);
185 return KdpBreakPending
;
193 KeEnterKernelDebugger(VOID
)
195 HalDisplayString("\n\n *** Entered kernel debugger ***\n");
197 /* Set the Variable */
198 KdEnteredDebugger
= TRUE
;
201 for (;;) Ke386HaltProcessor();
209 KdPowerTransition(ULONG PowerState
)
212 return STATUS_NOT_IMPLEMENTED
;
217 NtQueryDebugFilterState(IN ULONG ComponentId
,
222 /* convert Level to mask if it isn't already one */
226 for ( i
= 0; i
< KdComponentTableEntries
; i
++ )
228 if ( ComponentId
== KdComponentTable
[i
].ComponentId
)
230 if ( Level
& KdComponentTable
[i
].Level
)
240 NtSetDebugFilterState(IN ULONG ComponentId
,
245 for ( i
= 0; i
< KdComponentTableEntries
; i
++ )
247 if ( ComponentId
== KdComponentTable
[i
].ComponentId
)
250 if ( i
== KdComponentTableEntries
)
252 if ( i
== MAX_KD_COMPONENT_TABLE_ENTRIES
)
253 return STATUS_INVALID_PARAMETER_1
;
254 ++KdComponentTableEntries
;
255 KdComponentTable
[i
].ComponentId
= ComponentId
;
256 KdComponentTable
[i
].Level
= 0;
259 KdComponentTable
[i
].Level
|= Level
;
261 KdComponentTable
[i
].Level
&= ~Level
;
262 return STATUS_SUCCESS
;