[NTOS:KD64] KdInitSystem(): Minor code enhancements.

- Move local variables to the code blocks where they are used.
- if-s one-line bodies on their own lines.
- Massage the boot-images symbols loading, using a for-loop.
This commit is contained in:
Hermès Bélusca-Maïto 2024-11-28 20:07:25 +01:00
parent ba342e1d14
commit cb0c9a4570
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -162,21 +162,10 @@ KdInitSystem(
_In_ ULONG BootPhase, _In_ ULONG BootPhase,
_In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock) _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
{ {
BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable; BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable = FALSE;
PSTR CommandLine, DebugLine, DebugOptionStart, DebugOptionEnd;
STRING ImageName;
PLDR_DATA_TABLE_ENTRY LdrEntry; PLDR_DATA_TABLE_ENTRY LdrEntry;
PLIST_ENTRY NextEntry; ULONG i;
ULONG i, j, Length;
SIZE_T DebugOptionLength;
SIZE_T MemSizeMBs; SIZE_T MemSizeMBs;
CHAR NameBuffer[256];
PWCHAR Name;
#if defined(__GNUC__)
/* Make gcc happy */
BlockEnable = FALSE;
#endif
/* Check if this is Phase 1 */ /* Check if this is Phase 1 */
if (BootPhase) if (BootPhase)
@ -187,7 +176,8 @@ KdInitSystem(
} }
/* Check if we already initialized once */ /* Check if we already initialized once */
if (KdDebuggerEnabled) return TRUE; if (KdDebuggerEnabled)
return TRUE;
/* Set the Debug Routine as the Stub for now */ /* Set the Debug Routine as the Stub for now */
KiDebugRoutine = KdpStub; KiDebugRoutine = KdpStub;
@ -233,6 +223,8 @@ KdInitSystem(
/* Check if we have a loader block */ /* Check if we have a loader block */
if (LoaderBlock) if (LoaderBlock)
{ {
PSTR CommandLine, DebugLine;
/* Get the image entry */ /* Get the image entry */
LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink, LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
LDR_DATA_TABLE_ENTRY, LDR_DATA_TABLE_ENTRY,
@ -263,7 +255,7 @@ KdInitSystem(
/* Don't enable KD and don't let it be enabled later */ /* Don't enable KD and don't let it be enabled later */
KdPitchDebugger = TRUE; KdPitchDebugger = TRUE;
} }
else if ((DebugLine = strstr(CommandLine, "DEBUG")) != NULL) else if ((DebugLine = strstr(CommandLine, "DEBUG")))
{ {
/* Enable KD */ /* Enable KD */
EnableKd = TRUE; EnableKd = TRUE;
@ -272,11 +264,14 @@ KdInitSystem(
if (DebugLine[5] == '=') if (DebugLine[5] == '=')
{ {
/* Save pointers */ /* Save pointers */
PSTR DebugOptionStart, DebugOptionEnd;
DebugOptionStart = DebugOptionEnd = &DebugLine[6]; DebugOptionStart = DebugOptionEnd = &DebugLine[6];
/* Scan the string for debug options */ /* Scan the string for debug options */
for (;;) for (;;)
{ {
SIZE_T DebugOptionLength;
/* Loop until we reach the end of the string */ /* Loop until we reach the end of the string */
while (*DebugOptionEnd != ANSI_NULL) while (*DebugOptionEnd != ANSI_NULL)
{ {
@ -287,7 +282,7 @@ KdInitSystem(
{ {
/* /*
* We reached the end of the option or * We reached the end of the option or
* the end of the string, break out * the end of the string, break out.
*/ */
break; break;
} }
@ -303,18 +298,17 @@ KdInitSystem(
/* /*
* Break out if we reached the last option * Break out if we reached the last option
* or if there were no options at all * or if there were no options at all.
*/ */
if (!DebugOptionLength) break; if (!DebugOptionLength)
break;
/* Now check which option this is */ /* Now check which option this is */
if ((DebugOptionLength == 10) && if ((DebugOptionLength == 10) &&
!(strncmp(DebugOptionStart, "AUTOENABLE", 10))) !(strncmp(DebugOptionStart, "AUTOENABLE", 10)))
{ {
/* /* Disable the debugger, but
* Disable the debugger, but * allow to re-enable it later */
* allow it to be reenabled
*/
DisableKdAfterInit = TRUE; DisableKdAfterInit = TRUE;
BlockEnable = FALSE; BlockEnable = FALSE;
KdAutoEnableOnEvent = TRUE; KdAutoEnableOnEvent = TRUE;
@ -335,14 +329,11 @@ KdInitSystem(
} }
/* /*
* If there are more options then * If there are more options then the next character
* the next character should be a comma * should be a comma. Break out if it isn't.
*/ */
if (*DebugOptionEnd != ',') if (*DebugOptionEnd != ',')
{
/* It isn't, break out */
break; break;
}
/* Move on to the next option */ /* Move on to the next option */
DebugOptionEnd++; DebugOptionEnd++;
@ -431,10 +422,16 @@ KdInitSystem(
/* Check if we have a loader block */ /* Check if we have a loader block */
if (LoaderBlock) if (LoaderBlock)
{ {
/* Loop boot images */ PLIST_ENTRY NextEntry;
NextEntry = LoaderBlock->LoadOrderListHead.Flink; ULONG j, Length;
i = 0; PWCHAR Name;
while ((NextEntry != &LoaderBlock->LoadOrderListHead) && (i < 2)) STRING ImageName;
CHAR NameBuffer[256];
/* Loop over the first two boot images: HAL and kernel */
for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
NextEntry != &LoaderBlock->LoadOrderListHead && (i < 2);
NextEntry = NextEntry->Flink, ++i)
{ {
/* Get the image entry */ /* Get the image entry */
LdrEntry = CONTAINING_RECORD(NextEntry, LdrEntry = CONTAINING_RECORD(NextEntry,
@ -454,15 +451,11 @@ KdInitSystem(
/* Null-terminate */ /* Null-terminate */
NameBuffer[j] = ANSI_NULL; NameBuffer[j] = ANSI_NULL;
/* Load symbols for image */ /* Load the symbols */
RtlInitString(&ImageName, NameBuffer); RtlInitString(&ImageName, NameBuffer);
DbgLoadImageSymbols(&ImageName, DbgLoadImageSymbols(&ImageName,
LdrEntry->DllBase, LdrEntry->DllBase,
(ULONG_PTR)PsGetCurrentProcessId()); (ULONG_PTR)PsGetCurrentProcessId());
/* Go to the next entry */
NextEntry = NextEntry->Flink;
i++;
} }
/* Check for incoming break-in and break on symbol load /* Check for incoming break-in and break on symbol load