[NTOS:KDBG] Split KdbInitialize into KdbSymInit and KDBG initialization proper.

- KdbSymInit() in kdb_symbols.c only initializes symbols implementation
  support.
- The rest of KdbInitialize gets moved into kdb_cli.c and initializes
  the KDBG debugger itself.
- Move KdbDebugPrint to kdb_cli.c as well.
This commit is contained in:
Hermès Bélusca-Maïto 2023-03-10 18:12:32 +01:00
parent 793e9f20ef
commit dfb6996b45
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 80 additions and 56 deletions

View file

@ -78,11 +78,7 @@ KdpDebugLogInit(
_In_ ULONG BootPhase);
#ifdef KDBG
VOID
NTAPI
KdpKdbgInit(
_In_ struct _KD_DISPATCH_TABLE *DispatchTable,
_In_ ULONG BootPhase);
#define KdpKdbgInit KdbInitialize
#endif

View file

@ -577,24 +577,6 @@ KdpScreenInit(
}
}
#ifdef KDBG
/* KDBG FUNCTIONS ************************************************************/
/* NOTE: This may be moved completely into kdb_symbols.c */
VOID NTAPI
KdbInitialize(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase);
VOID
NTAPI
KdpKdbgInit(
_In_ PKD_DISPATCH_TABLE DispatchTable,
_In_ ULONG BootPhase)
{
/* Forward the call */
KdbInitialize(DispatchTable, BootPhase);
}
#endif
/* GENERAL FUNCTIONS *********************************************************/

View file

@ -82,6 +82,12 @@ KdbpStackSwitchAndCall(
extern PCHAR KdbInitFileBuffer;
VOID
NTAPI
KdbInitialize(
_In_ PKD_DISPATCH_TABLE DispatchTable,
_In_ ULONG BootPhase);
BOOLEAN
NTAPI
KdbRegisterCliCallback(
@ -158,14 +164,17 @@ KdbpSymFindModule(
BOOLEAN
KdbSymPrintAddress(
IN PVOID Address,
IN PCONTEXT Context
);
IN PCONTEXT Context);
VOID
KdbSymProcessSymbols(
_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry,
_In_ BOOLEAN Load);
VOID
KdbSymInit(
_In_ ULONG BootPhase);
/* from kdb.c */
extern PEPROCESS KdbCurrentProcess;

View file

@ -3880,3 +3880,50 @@ KdbpCliInit(VOID)
ExFreePool(FileBuffer);
}
static VOID
NTAPI
KdbDebugPrint(
PCH Message,
ULONG Length)
{
/* Nothing here */
}
/**
* @brief Initializes the KDBG debugger.
*
* @param[in] DispatchTable
* Pointer to the KD dispatch table.
*
* @param[in] BootPhase
* Phase of initialization.
*
* @return None.
* @note Also known as "KdpKdbgInit".
**/
VOID
NTAPI
KdbInitialize(
_In_ PKD_DISPATCH_TABLE DispatchTable,
_In_ ULONG BootPhase)
{
if (BootPhase == 0)
{
/* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdbInitialize;
DispatchTable->KdpPrintRoutine = KdbDebugPrint;
/* Register as a Provider */
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
}
if (BootPhase <= 1)
{
/* Initialize symbols support */
KdbSymInit(BootPhase);
}
}
/* EOF */

View file

@ -330,31 +330,19 @@ KdbSymProcessSymbols(
KeSetEvent(&SymbolsToLoadEvent, IO_NO_INCREMENT, FALSE);
}
VOID
NTAPI
KdbDebugPrint(
PCH Message,
ULONG Length)
{
/* Nothing here */
}
/*! \brief Initializes the KDB symbols implementation.
/**
* @brief Initializes the KDB symbols implementation.
*
* \param DispatchTable Pointer to the KD dispatch table
* \param BootPhase Phase of initialization
*/
* @param[in] BootPhase
* Phase of initialization.
*
* @return None.
**/
VOID
NTAPI
KdbInitialize(
_In_ PKD_DISPATCH_TABLE DispatchTable,
KdbSymInit(
_In_ ULONG BootPhase)
{
PCHAR p1, p2;
SHORT Found = FALSE;
CHAR YesNo;
DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
LoadSymbols = FALSE;
@ -367,12 +355,9 @@ KdbInitialize(
if (BootPhase == 0)
{
/* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdbInitialize;
DispatchTable->KdpPrintRoutine = KdbDebugPrint;
/* Register as a Provider */
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
PCHAR p1, p2;
SHORT Found = FALSE;
CHAR YesNo;
/* Perform actual initialization of symbol module */
//NtoskrnlModuleObject->PatchInformation = NULL;
@ -425,13 +410,18 @@ KdbInitialize(
HANDLE Thread;
NTSTATUS Status;
KIRQL OldIrql;
PLIST_ENTRY ListEntry;
/* Launch our worker thread */
InitializeListHead(&SymbolsToLoad);
KeInitializeSpinLock(&SymbolsToLoadLock);
KeInitializeEvent(&SymbolsToLoadEvent, SynchronizationEvent, FALSE);
Status = PsCreateSystemThread(&Thread, THREAD_ALL_ACCESS, NULL, NULL, NULL, LoadSymbolsRoutine, NULL);
Status = PsCreateSystemThread(&Thread,
THREAD_ALL_ACCESS,
NULL, NULL, NULL,
LoadSymbolsRoutine,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed starting symbols loader thread: 0x%08x\n", Status);
@ -443,12 +433,12 @@ KdbInitialize(
KeAcquireSpinLock(&PsLoadedModuleSpinLock, &OldIrql);
PLIST_ENTRY ListEntry = PsLoadedModuleList.Flink;
while (ListEntry != &PsLoadedModuleList)
for (ListEntry = PsLoadedModuleList.Flink;
ListEntry != &PsLoadedModuleList;
ListEntry = ListEntry->Flink)
{
PLDR_DATA_TABLE_ENTRY LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
KdbSymProcessSymbols(LdrEntry, TRUE);
ListEntry = ListEntry->Flink;
}
KeReleaseSpinLock(&PsLoadedModuleSpinLock, OldIrql);