[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().
This commit is contained in:
Hermès Bélusca-Maïto 2019-11-17 22:55:36 +01:00
parent 54c03f6965
commit a890fc64d1
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
10 changed files with 297 additions and 516 deletions

View file

@ -7,9 +7,6 @@
//
struct _KD_DISPATCH_TABLE;
extern CPPORT GdbPortInfo;
extern BOOLEAN KdBreakAfterSymbolLoad;
extern BOOLEAN KdPitchDebugger;
extern BOOLEAN KdIgnoreUmExceptions;
BOOLEAN
NTAPI
@ -93,8 +90,7 @@ typedef enum _KD_CONTINUE_TYPE
kdContinue = 0,
kdDoNotHandleException,
kdHandleException
}
KD_CONTINUE_TYPE;
} KD_CONTINUE_TYPE;
typedef
VOID
@ -122,14 +118,6 @@ KD_CONTINUE_TYPE
PKTRAP_FRAME TrapFrame
);
BOOLEAN
NTAPI
KdIsThisAKdTrap(
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN KPROCESSOR_MODE PreviousMode
);
/* INIT ROUTINES *************************************************************/
BOOLEAN
@ -188,13 +176,6 @@ KdpKdbgInit(
/* KD ROUTINES ***************************************************************/
ULONG
NTAPI
KdpPrintString(
_In_reads_bytes_(Length) PCHAR UnsafeString,
_In_ ULONG Length,
_In_ KPROCESSOR_MODE PreviousMode);
BOOLEAN
NTAPI
KdpDetectConflicts(PCM_RESOURCE_LIST DriverList);
@ -215,37 +196,22 @@ KdpSafeWriteMemory(
IN ULONGLONG Value
);
VOID
NTAPI
KdpEnableSafeMem(VOID);
/* KD GLOBALS ***************************************************************/
typedef
BOOLEAN
(NTAPI *PKDEBUG_ROUTINE)(
IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame,
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN KPROCESSOR_MODE PreviousMode,
IN BOOLEAN SecondChance
);
/* serial debug connection */
/* Serial debug connection */
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
#define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */
#define DEFAULT_DEBUG_COM2_IRQ 3 /* COM2 IRQ */
#define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
/* KD Native Modes */
#define KdScreen 0
#define KdSerial 1
#define KdFile 2
#define KdBochs 3
#define KdKdbg 4
#define KdMax 5
#define KdScreen 0
#define KdSerial 1
#define KdFile 2
#define KdBochs 3
#define KdKdbg 4
#define KdMax 5
/* KD Private Debug Modes */
typedef struct _KDP_DEBUG_MODE
@ -268,8 +234,7 @@ typedef struct _KDP_DEBUG_MODE
/* Generic Value */
ULONG Value;
};
}
KDP_DEBUG_MODE;
} KDP_DEBUG_MODE;
/* KD Internal Debug Services */
typedef enum _KDP_DEBUG_SERVICE
@ -286,8 +251,7 @@ typedef enum _KDP_DEBUG_SERVICE
KdSpare3 = 0x24, /* j */
EnterDebugger = 0x25, /* k */
ThatsWhatSheSaid = 69 /* FIGURE IT OUT */
}
KDP_DEBUG_SERVICE;
} KDP_DEBUG_SERVICE;
/* Dispatch Table for Wrapper Functions */
typedef struct _KD_DISPATCH_TABLE
@ -297,8 +261,7 @@ typedef struct _KD_DISPATCH_TABLE
PKDP_PRINT_ROUTINE KdpPrintRoutine;
PKDP_PROMPT_ROUTINE KdpPromptRoutine;
PKDP_EXCEPTION_ROUTINE KdpExceptionRoutine;
}
KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE;
} KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE;
/* The current Debugging Mode */
extern KDP_DEBUG_MODE KdpDebugMode;
@ -328,10 +291,6 @@ extern KD_DISPATCH_TABLE WrapperTable;
/* The KD Native Provider List */
extern LIST_ENTRY KdProviders;
extern PKDEBUG_ROUTINE KiDebugRoutine;
extern KD_CONTEXT KdpContext;
extern ULONG Kd_WIN2000_Mask;
#endif
#if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c