https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9808d32f4a32cc20c2b75…
commit 9808d32f4a32cc20c2b75d42edac0b9fca133254
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Wed Apr 12 18:38:47 2023 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Apr 12 19:30:56 2023 +0200
[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.
---
ntoskrnl/kdbg/debug.h | 51 +++++++++++++++++++++++++++++++++++++++++++
ntoskrnl/kdbg/i386/i386-dis.c | 7 ++----
ntoskrnl/kdbg/kdb_cli.c | 4 ++--
ntoskrnl/kdbg/kdb_expr.c | 42 ++++++++++++++++++-----------------
ntoskrnl/kdbg/kdb_symbols.c | 22 +++++++++----------
5 files changed, 87 insertions(+), 39 deletions(-)
diff --git a/ntoskrnl/kdbg/debug.h b/ntoskrnl/kdbg/debug.h
new file mode 100644
index 00000000000..965f9612739
--- /dev/null
+++ b/ntoskrnl/kdbg/debug.h
@@ -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(a)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 */
diff --git a/ntoskrnl/kdbg/i386/i386-dis.c b/ntoskrnl/kdbg/i386/i386-dis.c
index 86b2e9dac9a..559a3ac1678 100644
--- a/ntoskrnl/kdbg/i386/i386-dis.c
+++ b/ntoskrnl/kdbg/i386/i386-dis.c
@@ -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);
}
}
diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c
index 7ad4cc275ee..cc7aece3d9e 100644
--- a/ntoskrnl/kdbg/kdb_cli.c
+++ b/ntoskrnl/kdbg/kdb_cli.c
@@ -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);
diff --git a/ntoskrnl/kdbg/kdb_expr.c b/ntoskrnl/kdbg/kdb_expr.c
index f868d6df376..50625175e94 100644
--- a/ntoskrnl/kdbg/kdb_expr.c
+++ b/ntoskrnl/kdbg/kdb_expr.c
@@ -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.
*
diff --git a/ntoskrnl/kdbg/kdb_symbols.c b/ntoskrnl/kdbg/kdb_symbols.c
index b8491fefa4b..8cd897f339d 100644
--- a/ntoskrnl/kdbg/kdb_symbols.c
+++ b/ntoskrnl/kdbg/kdb_symbols.c
@@ -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;