[NTOS:KDBG] Use local KdbPrintf function for DPRINT1 instead of DbgPrint...

... that would otherwise cause a debugger re-entry.

Also use KdbPuts/Printf instead of KdpDprintf that won't be available
once KDBG is moved out of it.
This commit is contained in:
Hermès Bélusca-Maïto 2023-04-12 18:38:47 +02:00
parent f620ce7705
commit 9808d32f4a
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 87 additions and 39 deletions

51
ntoskrnl/kdbg/debug.h Normal file
View file

@ -0,0 +1,51 @@
/*
* PROJECT: ReactOS KDBG Kernel Debugger
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Useful debugging macros
* COPYRIGHT: Copyright 2023 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/
/*
* NOTE: Define NDEBUG before including this header
* to disable debugging macros.
*/
#pragma once
#ifndef __RELFILE__
#define __RELFILE__ __FILE__
#endif
/* Print stuff only on Debug Builds */
#if DBG
/* These are always printed */
#define DPRINT1(fmt, ...) \
KdbPrintf("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
/* These are printed only if NDEBUG is NOT defined */
#ifndef NDEBUG
#define DPRINT(fmt, ...) \
KdbPrintf("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
#else
#if defined(_MSC_VER)
#define DPRINT __noop
#else
#define DPRINT(...) do { if(0) { KdbPrintf(__VA_ARGS__); } } while(0)
#endif
#endif
#else /* not DBG */
/* On non-debug builds, we never show these */
#if defined(_MSC_VER)
#define DPRINT1 __noop
#define DPRINT __noop
#else
#define DPRINT1(...) do { if(0) { KdbPrintf(__VA_ARGS__); } } while(0)
#define DPRINT(...) do { if(0) { KdbPrintf(__VA_ARGS__); } } while(0)
#endif /* _MSC_VER */
#endif /* not DBG */
/* EOF */

View file

@ -10,9 +10,6 @@
#include <ntoskrnl.h> #include <ntoskrnl.h>
#include "../kdb.h" #include "../kdb.h"
#define NDEBUG
#include <debug.h>
/* ReactOS compatibility stuff. */ /* ReactOS compatibility stuff. */
#define PARAMS(X) X #define PARAMS(X) X
#define PTR void* #define PTR void*
@ -53,7 +50,7 @@ KdbpPrintDisasm(void* Ignored, const char* fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
ret = vsprintf(buffer, fmt, ap); ret = vsprintf(buffer, fmt, ap);
KdpDprintf("%s", buffer); KdbPuts(buffer);
va_end(ap); va_end(ap);
return(ret); return(ret);
} }
@ -82,7 +79,7 @@ KdbpPrintAddressInCode(uintptr_t Addr, struct disassemble_info * Ignored)
{ {
if (!KdbSymPrintAddress((void*)Addr, NULL)) if (!KdbSymPrintAddress((void*)Addr, NULL))
{ {
KdpDprintf("<%08x>", Addr); KdbPrintf("<%08x>", Addr);
} }
} }

View file

@ -33,7 +33,7 @@
#include "../kd/kdterminal.h" #include "../kd/kdterminal.h"
#define NDEBUG #define NDEBUG
#include <debug.h> #include "debug.h"
/* DEFINES *******************************************************************/ /* DEFINES *******************************************************************/
@ -655,7 +655,7 @@ KdbpCmdPrintStruct(
DPRINT1("BaseAddress: %p\n", BaseAddress); DPRINT1("BaseAddress: %p\n", BaseAddress);
} }
} }
DPRINT1("BaseAddress %p\n", BaseAddress); DPRINT1("BaseAddress: %p\n", BaseAddress);
KdbpPrintStructInternal(Info, Indent, !!BaseAddress, BaseAddress, &Aggregate); KdbpPrintStructInternal(Info, Indent, !!BaseAddress, BaseAddress, &Aggregate);
end: end:
RosSymFreeAggregate(&Aggregate); RosSymFreeAggregate(&Aggregate);

View file

@ -37,7 +37,7 @@
#include "kdb.h" #include "kdb.h"
#define NDEBUG #define NDEBUG
#include <debug.h> #include "debug.h"
/* TYPES *********************************************************************/ /* TYPES *********************************************************************/
typedef enum _RPN_OP_TYPE typedef enum _RPN_OP_TYPE
@ -244,6 +244,7 @@ RpnBinaryOperatorGreaterThanOrEquals(
return (a >= b); return (a >= b);
} }
#ifdef DEBUG_RPN
/*!\brief Dumps the given RPN stack content /*!\brief Dumps the given RPN stack content
* *
* \param Stack Pointer to a RPN_STACK structure. * \param Stack Pointer to a RPN_STACK structure.
@ -255,7 +256,7 @@ RpnpDumpStack(
ULONG ul; ULONG ul;
ASSERT(Stack); ASSERT(Stack);
KdpDprintf("\nStack size: %ld\n", Stack->Sp); KdbPrintf("\nStack size: %ld\n", Stack->Sp);
for (ul = 0; ul < Stack->Sp; ul++) for (ul = 0; ul < Stack->Sp; ul++)
{ {
@ -263,61 +264,62 @@ RpnpDumpStack(
switch (Op->Type) switch (Op->Type)
{ {
case RpnOpNop: case RpnOpNop:
KdpDprintf("NOP,"); KdbPuts("NOP,");
break; break;
case RpnOpImmediate: case RpnOpImmediate:
KdpDprintf("0x%I64x,", Op->Data.Immediate); KdbPrintf("0x%I64x,", Op->Data.Immediate);
break; break;
case RpnOpBinaryOperator: case RpnOpBinaryOperator:
if (Op->Data.BinaryOperator == RpnBinaryOperatorAdd) if (Op->Data.BinaryOperator == RpnBinaryOperatorAdd)
KdpDprintf("+,"); KdbPuts("+,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorSub) else if (Op->Data.BinaryOperator == RpnBinaryOperatorSub)
KdpDprintf("-,"); KdbPuts("-,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorMul) else if (Op->Data.BinaryOperator == RpnBinaryOperatorMul)
KdpDprintf("*,"); KdbPuts("*,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorDiv) else if (Op->Data.BinaryOperator == RpnBinaryOperatorDiv)
KdpDprintf("/,"); KdbPuts("/,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorMod) else if (Op->Data.BinaryOperator == RpnBinaryOperatorMod)
KdpDprintf("%%,"); KdbPuts("%%,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorEquals) else if (Op->Data.BinaryOperator == RpnBinaryOperatorEquals)
KdpDprintf("==,"); KdbPuts("==,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorNotEquals) else if (Op->Data.BinaryOperator == RpnBinaryOperatorNotEquals)
KdpDprintf("!=,"); KdbPuts("!=,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorLessThan) else if (Op->Data.BinaryOperator == RpnBinaryOperatorLessThan)
KdpDprintf("<,"); KdbPuts("<,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorLessThanOrEquals) else if (Op->Data.BinaryOperator == RpnBinaryOperatorLessThanOrEquals)
KdpDprintf("<=,"); KdbPuts("<=,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorGreaterThan) else if (Op->Data.BinaryOperator == RpnBinaryOperatorGreaterThan)
KdpDprintf(">,"); KdbPuts(">,");
else if (Op->Data.BinaryOperator == RpnBinaryOperatorGreaterThanOrEquals) else if (Op->Data.BinaryOperator == RpnBinaryOperatorGreaterThanOrEquals)
KdpDprintf(">=,"); KdbPuts(">=,");
else else
KdpDprintf("UNKNOWN OP,"); KdbPuts("UNKNOWN OP,");
break; break;
case RpnOpRegister: case RpnOpRegister:
KdpDprintf("%s,", RegisterToTrapFrame[Op->Data.Register].Name); KdbPrintf("%s,", RegisterToTrapFrame[Op->Data.Register].Name);
break; break;
case RpnOpDereference: case RpnOpDereference:
KdpDprintf("[%s],", KdbPrintf("[%s],",
(Op->Data.DerefMemorySize == 1) ? ("byte") : (Op->Data.DerefMemorySize == 1) ? ("byte") :
((Op->Data.DerefMemorySize == 2) ? ("word") : ((Op->Data.DerefMemorySize == 2) ? ("word") :
((Op->Data.DerefMemorySize == 4) ? ("dword") : ("qword")))); ((Op->Data.DerefMemorySize == 4) ? ("dword") : ("qword"))));
break; break;
default: default:
KdpDprintf("\nUnsupported Type: %d\n", Op->Type); KdbPrintf("\nUnsupported Type: %d\n", Op->Type);
ul = Stack->Sp; ul = Stack->Sp;
break; break;
} }
} }
KdpDprintf("\n"); KdbPuts("\n");
} }
#endif // DEBUG_RPN
/*!\brief Clears the given RPN stack. /*!\brief Clears the given RPN stack.
* *

View file

@ -14,7 +14,7 @@
#include "kdb.h" #include "kdb.h"
#define NDEBUG #define NDEBUG
#include <debug.h> #include "debug.h"
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
@ -170,17 +170,15 @@ KdbSymPrintAddress(
CHAR FileName[256]; CHAR FileName[256];
CHAR FunctionName[256]; CHAR FunctionName[256];
if (RosSymGetAddressInformation(LdrEntry->PatchInformation, RelativeAddress, &LineNumber, FileName, FunctionName)) if (RosSymGetAddressInformation(LdrEntry->PatchInformation,
RelativeAddress,
&LineNumber,
FileName,
FunctionName))
{ {
STRING str; KdbPrintf("<%s:%x (%s:%d (%s))>",
/* Use KdpPrintString because KdpDprintf is limited wrt string size */ ModuleNameAnsi, RelativeAddress,
KdpDprintf("<%s:%x (", ModuleNameAnsi, RelativeAddress); FileName, LineNumber, FunctionName);
str.Buffer = FileName;
str.Length = (USHORT)strnlen(FileName, sizeof(FileName));
str.MaximumLength = sizeof(FileName);
KdpPrintString(&str);
KdpDprintf(":%d (%s))>", LineNumber, FunctionName);
Printed = TRUE; Printed = TRUE;
} }
} }
@ -188,7 +186,7 @@ KdbSymPrintAddress(
if (!Printed) if (!Printed)
{ {
/* Just print module & address */ /* Just print module & address */
KdpDprintf("<%s:%x>", ModuleNameAnsi, RelativeAddress); KdbPrintf("<%s:%x>", ModuleNameAnsi, RelativeAddress);
} }
return TRUE; return TRUE;