ReactOS  0.4.15-dev-2355-gaf9df93
kdmain.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel
4  * FILE: ntoskrnl/kd/kdmain.c
5  * PURPOSE: Kernel Debugger Initialization
6  *
7  * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8  */
9 
10 #include <ntoskrnl.h>
11 #define NDEBUG
12 #include <debug.h>
13 
14 /* VARIABLES ***************************************************************/
15 
16 VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
17 
19 
20 /* PUBLIC FUNCTIONS *********************************************************/
21 
22 static PCHAR
23 NTAPI
25 {
26  PCHAR p1, p2 = Currentp2;
27  ULONG Value;
28 
29  /* Check for Screen Debugging */
30  if (!_strnicmp(p2, "SCREEN", 6))
31  {
32  /* Enable It */
33  p2 += 6;
34  KdpDebugMode.Screen = TRUE;
35  }
36  /* Check for Serial Debugging */
37  else if (!_strnicmp(p2, "COM", 3))
38  {
39  /* Gheck for a valid Serial Port */
40  p2 += 3;
41  if (*p2 != ':')
42  {
43  Value = (ULONG)atol(p2);
44  if (Value > 0 && Value < 5)
45  {
46  /* Valid port found, enable Serial Debugging */
47  KdpDebugMode.Serial = TRUE;
48 
49  /* Set the port to use */
51  }
52  }
53  else
54  {
55  Value = strtoul(p2 + 1, NULL, 0);
56  if (Value)
57  {
58  KdpDebugMode.Serial = TRUE;
60  SerialPortNumber = 0;
61  }
62  }
63  }
64  /* Check for Debug Log Debugging */
65  else if (!_strnicmp(p2, "FILE", 4))
66  {
67  /* Enable It */
68  p2 += 4;
69  KdpDebugMode.File = TRUE;
70  if (*p2 == ':')
71  {
72  p2++;
73  p1 = p2;
74  while (*p2 != '\0' && *p2 != ' ') p2++;
77  }
78  }
79 
80  return p2;
81 }
82 
84 NTAPI
87 {
88  ULONG i;
89  PCHAR CommandLine, Port = NULL;
90 
91  if (LoaderBlock)
92  {
93  /* Check if we have a command line */
94  CommandLine = LoaderBlock->LoadOptions;
95  if (CommandLine)
96  {
97  /* Upcase it */
98  _strupr(CommandLine);
99 
100 #ifdef KDBG
101  /* Get the KDBG Settings */
102  KdbpGetCommandLineSettings(CommandLine);
103 #endif
104 
105  /* Get the port */
106  Port = strstr(CommandLine, "DEBUGPORT");
107  }
108  }
109 
110  /* Check if we got the /DEBUGPORT parameter(s) */
111  while (Port)
112  {
113  /* Move past the actual string, to reach the port*/
114  Port += sizeof("DEBUGPORT") - 1;
115 
116  /* Now get past any spaces and skip the equal sign */
117  while (*Port == ' ') Port++;
118  Port++;
119 
120  /* Get the debug mode and wrapper */
122  Port = strstr(Port, "DEBUGPORT");
123  }
124 
125  /* Use serial port then */
126  if (KdpDebugMode.Value == 0)
127  KdpDebugMode.Serial = TRUE;
128 
129  /* Call Providers at Phase 0 */
130  for (i = 0; i < KdMax; i++)
131  {
132  InitRoutines[i](&DispatchTable[i], 0);
133  }
134 
135  return STATUS_SUCCESS;
136 }
137 
138 NTSTATUS
139 NTAPI
141  IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
142 {
143  PLIST_ENTRY CurrentEntry;
144  PKD_DISPATCH_TABLE CurrentTable;
145 
146  /* Call the registered handlers */
147  CurrentEntry = KdProviders.Flink;
148  while (CurrentEntry != &KdProviders)
149  {
150  /* Get the current table */
151  CurrentTable = CONTAINING_RECORD(CurrentEntry,
152  KD_DISPATCH_TABLE,
153  KdProvidersList);
154 
155  /* Call it */
156  CurrentTable->KdpInitRoutine(CurrentTable, 1);
157 
158  /* Next Table */
159  CurrentEntry = CurrentEntry->Flink;
160  }
161 
163 
164  return STATUS_SUCCESS;
165 }
166 
167  /* EOF */
signed char * PCHAR
Definition: retypes.h:7
CPPORT Port[4]
Definition: headless.c:35
#define IN
Definition: typedefs.h:39
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
NTSTATUS NTAPI KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
Definition: kdmain.c:140
#define TRUE
Definition: types.h:120
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads)
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:48
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned char BOOLEAN
VOID NTAPI KdbpGetCommandLineSettings(PCHAR p1)
Definition: kdb.c:1649
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define UlongToPtr(u)
Definition: config.h:106
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
USHORT MaximumLength
Definition: env_spec_w32.h:377
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
static PCHAR NTAPI KdpGetDebugMode(PCHAR Currentp2)
Definition: kdmain.c:24
NTSTATUS NTAPI KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
Definition: kdmain.c:85
Definition: typedefs.h:119
PUCHAR Address
Definition: cportlib.h:29
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PKDP_INIT_ROUTINE InitRoutines[KdMax]
Definition: kdio.c:52
CPPORT SerialPortInfo
Definition: kdio.c:34
#define NULL
Definition: types.h:112
ULONG SerialPortNumber
Definition: kdio.c:33
ANSI_STRING KdpLogFileName
Definition: kdio.c:29
unsigned int ULONG
Definition: retypes.h:1
#define FLG_STOP_ON_EXCEPTION
Definition: pstypes.h:56
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:245
ULONG NtGlobalFlag
Definition: init.c:52
LIST_ENTRY KdProviders
Definition: kdio.c:49
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68