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

View file

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

View file

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

View file

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