https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dfb6996b4542fa88595e4bdbfdb0e2e06a2dc360

commit dfb6996b4542fa88595e4bdbfdb0e2e06a2dc360
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Fri Mar 10 18:12:32 2023 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Fri Mar 10 20:56:21 2023 +0100

    [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.
---
 ntoskrnl/include/internal/kd.h |  6 +----
 ntoskrnl/kd/kdio.c             | 18 ---------------
 ntoskrnl/kdbg/kdb.h            | 13 +++++++++--
 ntoskrnl/kdbg/kdb_cli.c        | 47 ++++++++++++++++++++++++++++++++++++++
 ntoskrnl/kdbg/kdb_symbols.c    | 52 +++++++++++++++++-------------------------
 5 files changed, 80 insertions(+), 56 deletions(-)

diff --git a/ntoskrnl/include/internal/kd.h b/ntoskrnl/include/internal/kd.h
index ef014a2c6a5..75ffd8be63f 100644
--- a/ntoskrnl/include/internal/kd.h
+++ b/ntoskrnl/include/internal/kd.h
@@ -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
 
 
diff --git a/ntoskrnl/kd/kdio.c b/ntoskrnl/kd/kdio.c
index 742121e08fb..9c8a486fad8 100644
--- a/ntoskrnl/kd/kdio.c
+++ b/ntoskrnl/kd/kdio.c
@@ -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 *********************************************************/
 
diff --git a/ntoskrnl/kdbg/kdb.h b/ntoskrnl/kdbg/kdb.h
index 8d1e9af2a47..11bc4cb452f 100644
--- a/ntoskrnl/kdbg/kdb.h
+++ b/ntoskrnl/kdbg/kdb.h
@@ -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;
diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c
index 114f4116838..c12f19554ef 100644
--- a/ntoskrnl/kdbg/kdb_cli.c
+++ b/ntoskrnl/kdbg/kdb_cli.c
@@ -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 */
diff --git a/ntoskrnl/kdbg/kdb_symbols.c b/ntoskrnl/kdbg/kdb_symbols.c
index 06325b65fb6..46294733d89 100644
--- a/ntoskrnl/kdbg/kdb_symbols.c
+++ b/ntoskrnl/kdbg/kdb_symbols.c
@@ -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,19 +355,16 @@ 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;
         //LdrHalModuleObject->PatchInformation = NULL;
 
         /* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS,
-        * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
+         * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
         ASSERT(KeLoaderBlock);
         p1 = KeLoaderBlock->LoadOptions;
         while ('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
@@ -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);

Reply via email to