2005-04-25 14:44:48 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel
|
2015-10-04 11:54:25 +00:00
|
|
|
* FILE: ntoskrnl/kd/kdmain.c
|
2008-12-29 14:26:01 +00:00
|
|
|
* PURPOSE: Kernel Debugger Initialization
|
2005-05-09 01:38:29 +00:00
|
|
|
*
|
2005-04-25 14:44:48 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2005-04-25 14:44:48 +00:00
|
|
|
|
|
|
|
/* VARIABLES ***************************************************************/
|
|
|
|
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
|
- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.
Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
svn path=/trunk/; revision=18078
2005-09-26 04:59:48 +00:00
|
|
|
|
2020-03-07 16:18:33 +00:00
|
|
|
extern ANSI_STRING KdpLogFileName;
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* PUBLIC FUNCTIONS *********************************************************/
|
|
|
|
|
2020-03-07 18:14:09 +00:00
|
|
|
static PCHAR
|
2020-03-07 16:18:33 +00:00
|
|
|
NTAPI
|
|
|
|
KdpGetDebugMode(PCHAR Currentp2)
|
|
|
|
{
|
|
|
|
PCHAR p1, p2 = Currentp2;
|
|
|
|
ULONG Value;
|
|
|
|
|
|
|
|
/* Check for Screen Debugging */
|
|
|
|
if (!_strnicmp(p2, "SCREEN", 6))
|
|
|
|
{
|
|
|
|
/* Enable It */
|
|
|
|
p2 += 6;
|
|
|
|
KdpDebugMode.Screen = TRUE;
|
|
|
|
}
|
|
|
|
/* Check for Serial Debugging */
|
|
|
|
else if (!_strnicmp(p2, "COM", 3))
|
|
|
|
{
|
|
|
|
/* Gheck for a valid Serial Port */
|
|
|
|
p2 += 3;
|
|
|
|
if (*p2 != ':')
|
|
|
|
{
|
|
|
|
Value = (ULONG)atol(p2);
|
|
|
|
if (Value > 0 && Value < 5)
|
|
|
|
{
|
|
|
|
/* Valid port found, enable Serial Debugging */
|
|
|
|
KdpDebugMode.Serial = TRUE;
|
|
|
|
|
|
|
|
/* Set the port to use */
|
|
|
|
SerialPortNumber = Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Value = strtoul(p2 + 1, NULL, 0);
|
|
|
|
if (Value)
|
|
|
|
{
|
|
|
|
KdpDebugMode.Serial = TRUE;
|
|
|
|
SerialPortInfo.Address = UlongToPtr(Value);
|
|
|
|
SerialPortNumber = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Check for Debug Log Debugging */
|
|
|
|
else if (!_strnicmp(p2, "FILE", 4))
|
|
|
|
{
|
|
|
|
/* Enable It */
|
|
|
|
p2 += 4;
|
|
|
|
KdpDebugMode.File = TRUE;
|
|
|
|
if (*p2 == ':')
|
|
|
|
{
|
|
|
|
p2++;
|
|
|
|
p1 = p2;
|
|
|
|
while (*p2 != '\0' && *p2 != ' ') p2++;
|
|
|
|
KdpLogFileName.MaximumLength = KdpLogFileName.Length = p2 - p1;
|
|
|
|
KdpLogFileName.Buffer = p1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:39:37 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
KdDebuggerInitialize0(
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
|
|
|
|
{
|
2020-03-07 16:18:33 +00:00
|
|
|
ULONG i;
|
2020-03-28 18:15:57 +00:00
|
|
|
PCHAR CommandLine, Port = NULL;
|
2020-03-07 16:18:33 +00:00
|
|
|
|
|
|
|
if (LoaderBlock)
|
|
|
|
{
|
|
|
|
/* Check if we have a command line */
|
|
|
|
CommandLine = LoaderBlock->LoadOptions;
|
|
|
|
if (CommandLine)
|
|
|
|
{
|
|
|
|
/* Upcase it */
|
|
|
|
_strupr(CommandLine);
|
|
|
|
|
2020-03-09 22:45:22 +00:00
|
|
|
#ifdef KDBG
|
|
|
|
/* Get the KDBG Settings */
|
|
|
|
KdbpGetCommandLineSettings(CommandLine);
|
|
|
|
#endif
|
|
|
|
|
2020-03-28 18:15:57 +00:00
|
|
|
/* Get the port */
|
2020-03-07 16:18:33 +00:00
|
|
|
Port = strstr(CommandLine, "DEBUGPORT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we got the /DEBUGPORT parameter(s) */
|
|
|
|
while (Port)
|
|
|
|
{
|
|
|
|
/* Move past the actual string, to reach the port*/
|
|
|
|
Port += sizeof("DEBUGPORT") - 1;
|
|
|
|
|
|
|
|
/* Now get past any spaces and skip the equal sign */
|
|
|
|
while (*Port == ' ') Port++;
|
|
|
|
Port++;
|
|
|
|
|
|
|
|
/* Get the debug mode and wrapper */
|
|
|
|
Port = KdpGetDebugMode(Port);
|
|
|
|
Port = strstr(Port, "DEBUGPORT");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use serial port then */
|
|
|
|
if (KdpDebugMode.Value == 0)
|
|
|
|
KdpDebugMode.Serial = TRUE;
|
|
|
|
|
|
|
|
/* Call Providers at Phase 0 */
|
|
|
|
for (i = 0; i < KdMax; i++)
|
|
|
|
{
|
|
|
|
InitRoutines[i](&DispatchTable[i], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2020-03-07 10:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
KdDebuggerInitialize1(
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
|
|
|
|
{
|
2020-03-07 17:00:20 +00:00
|
|
|
PLIST_ENTRY CurrentEntry;
|
|
|
|
PKD_DISPATCH_TABLE CurrentTable;
|
|
|
|
|
|
|
|
/* Call the registered handlers */
|
|
|
|
CurrentEntry = KdProviders.Flink;
|
|
|
|
while (CurrentEntry != &KdProviders)
|
|
|
|
{
|
|
|
|
/* Get the current table */
|
|
|
|
CurrentTable = CONTAINING_RECORD(CurrentEntry,
|
|
|
|
KD_DISPATCH_TABLE,
|
|
|
|
KdProvidersList);
|
|
|
|
|
|
|
|
/* Call it */
|
|
|
|
CurrentTable->KdpInitRoutine(CurrentTable, 1);
|
|
|
|
|
|
|
|
/* Next Table */
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
}
|
|
|
|
|
2020-03-08 22:16:43 +00:00
|
|
|
NtGlobalFlag |= FLG_STOP_ON_EXCEPTION;
|
|
|
|
|
2020-03-07 17:00:20 +00:00
|
|
|
return STATUS_SUCCESS;
|
2020-03-07 10:39:37 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* EOF */
|