ReactOS  0.4.15-dev-1397-g19779b3
kdprint.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdprint.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define KD_PRINT_MAX_BYTES   512
 

Functions

BOOLEAN NTAPI KdpPrintString (_In_ PSTRING Output)
 
BOOLEAN NTAPI KdpPromptString (_In_ PSTRING PromptString, _In_ PSTRING ResponseString)
 
VOID NTAPI KdpCommandString (IN PSTRING NameString, IN PSTRING CommandString, IN KPROCESSOR_MODE PreviousMode, IN PCONTEXT ContextRecord, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
VOID NTAPI KdpSymbol (IN PSTRING DllPath, IN PKD_SYMBOLS_INFO SymbolInfo, IN BOOLEAN Unload, IN KPROCESSOR_MODE PreviousMode, IN PCONTEXT ContextRecord, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
USHORT NTAPI KdpPrompt (_In_reads_bytes_(PromptLength) PCHAR PromptString, _In_ USHORT PromptLength, _Out_writes_bytes_(MaximumResponseLength) PCHAR ResponseString, _In_ USHORT MaximumResponseLength, _In_ KPROCESSOR_MODE PreviousMode, _In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
 
static NTSTATUS NTAPI KdpPrintFromUser (_In_ ULONG ComponentId, _In_ ULONG Level, _In_reads_bytes_(Length) PCHAR String, _In_ USHORT Length, _In_ KPROCESSOR_MODE PreviousMode, _In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PBOOLEAN Handled)
 
NTSTATUS NTAPI KdpPrint (_In_ ULONG ComponentId, _In_ ULONG Level, _In_reads_bytes_(Length) PCHAR String, _In_ USHORT Length, _In_ KPROCESSOR_MODE PreviousMode, _In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PBOOLEAN Handled)
 
VOID __cdecl KdpDprintf (_In_ PCHAR Format,...)
 

Macro Definition Documentation

◆ KD_PRINT_MAX_BYTES

#define KD_PRINT_MAX_BYTES   512

Definition at line 16 of file kdprint.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file kdprint.c.

Function Documentation

◆ KdpCommandString()

VOID NTAPI KdpCommandString ( IN PSTRING  NameString,
IN PSTRING  CommandString,
IN KPROCESSOR_MODE  PreviousMode,
IN PCONTEXT  ContextRecord,
IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 137 of file kdprint.c.

143 {
144  BOOLEAN Enable;
145  PKPRCB Prcb = KeGetCurrentPrcb();
146 
147  /* Check if we need to do anything */
148  if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return;
149 
150  /* Enter the debugger */
151  Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
152 
153  /* Save the CPU Control State and save the context */
157  sizeof(CONTEXT));
158 
159  /* Send the command string to the debugger */
161  CommandString,
163 
164  /* Restore the processor state */
167  sizeof(CONTEXT));
169 
170  /* Exit the debugger and return */
172 }
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1924
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
CONTEXT ContextFrame
Definition: ketypes.h:531
unsigned char BOOLEAN
VOID NTAPI KiRestoreProcessorControlState(IN PKPROCESSOR_STATE ProcessorState)
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:579
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:655
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:375
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1871
VOID NTAPI KdpReportCommandStringStateChange(IN PSTRING NameString, IN PSTRING CommandString, IN OUT PCONTEXT Context)
Definition: kdapi.c:1653

Referenced by KdpTrap().

◆ KdpDprintf()

VOID __cdecl KdpDprintf ( _In_ PCHAR  Format,
  ... 
)

Definition at line 441 of file kdprint.c.

444 {
445  STRING String;
446  USHORT Length;
447  va_list ap;
448  CHAR Buffer[100];
449 
450  /* Format the string */
451  va_start(ap, Format);
453  sizeof(Buffer),
454  Format,
455  ap);
456  va_end(ap);
457 
458  /* Set it up */
459  String.Buffer = Buffer;
460  String.Length = String.MaximumLength = Length;
461 
462  /* Send it to the debugger directly */
464 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
char CHAR
Definition: xmlstorage.h:175
BOOLEAN NTAPI KdpPrintString(_In_ PSTRING Output)
Definition: kdprint.c:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
va_start(ap, x)
std::wstring STRING
Definition: fontsub.cpp:33
unsigned short USHORT
Definition: pedump.c:61
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char * Format
Definition: acpixf.h:1216

◆ KdpPrint()

NTSTATUS NTAPI KdpPrint ( _In_ ULONG  ComponentId,
_In_ ULONG  Level,
_In_reads_bytes_(Length) PCHAR  String,
_In_ USHORT  Length,
_In_ KPROCESSOR_MODE  PreviousMode,
_In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame,
_Out_ PBOOLEAN  Handled 
)

Definition at line 358 of file kdprint.c.

367 {
369  BOOLEAN Enable;
370  STRING OutputString;
371 
373  {
374  /* Mask validation failed */
375  *Handled = TRUE;
376  return STATUS_SUCCESS;
377  }
378 
379  /* Assume failure */
380  *Handled = FALSE;
381 
382  /* Normalize the length */
384 
385  /* Check if we need to verify the string */
386  if (PreviousMode != KernelMode)
387  {
388  /* This case requires a 512 byte stack buffer.
389  * We don't want to use that much stack in the kernel case, but we
390  * can't use _alloca due to PSEH. So the buffer exists in this
391  * helper function instead.
392  */
394  Level,
395  String,
396  Length,
397  PreviousMode,
398  TrapFrame,
399  ExceptionFrame,
400  Handled);
401  }
402 
403  /* Setup the output string */
404  OutputString.Buffer = String;
405  OutputString.Length = OutputString.MaximumLength = Length;
406 
407  /* Log the print */
408  //KdLogDbgPrint(&OutputString);
409 
410  /* Check for a debugger */
412  {
413  /* Fail */
414  *Handled = TRUE;
416  }
417 
418  /* Enter the debugger */
419  Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
420 
421  /* Print the string */
422  if (KdpPrintString(&OutputString))
423  {
424  /* User pressed CTRL-C, breakpoint on return */
426  }
427  else
428  {
429  /* String was printed */
431  }
432 
433  /* Exit the debugger and return */
435  *Handled = TRUE;
436  return Status;
437 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1924
BOOLEAN NTAPI KdpPrintString(_In_ PSTRING Output)
Definition: kdprint.c:22
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
NTSTATUS NTAPI NtQueryDebugFilterState(_In_ ULONG ComponentId, _In_ ULONG Level)
Definition: kdapi.c:2352
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define STATUS_BREAKPOINT
Definition: ntstatus.h:184
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define KD_PRINT_MAX_BYTES
Definition: kdprint.c:16
_In_ BOOLEAN Handled
Definition: ketypes.h:337
std::wstring STRING
Definition: fontsub.cpp:33
#define min(a, b)
Definition: monoChain.cc:55
static NTSTATUS NTAPI KdpPrintFromUser(_In_ ULONG ComponentId, _In_ ULONG Level, _In_reads_bytes_(Length) PCHAR String, _In_ USHORT Length, _In_ KPROCESSOR_MODE PreviousMode, _In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PBOOLEAN Handled)
Definition: kdprint.c:315
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1871
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by KdpPrintFromUser(), and KdpTrap().

◆ KdpPrintFromUser()

static NTSTATUS NTAPI KdpPrintFromUser ( _In_ ULONG  ComponentId,
_In_ ULONG  Level,
_In_reads_bytes_(Length) PCHAR  String,
_In_ USHORT  Length,
_In_ KPROCESSOR_MODE  PreviousMode,
_In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame,
_Out_ PBOOLEAN  Handled 
)
static

Definition at line 315 of file kdprint.c.

324 {
325  CHAR CapturedString[KD_PRINT_MAX_BYTES];
326 
328  ASSERT(Length <= sizeof(CapturedString));
329 
330  /* Capture user-mode buffers */
331  _SEH2_TRY
332  {
333  /* Probe and capture the string */
335  KdpMoveMemory(CapturedString, String, Length);
336  String = CapturedString;
337  }
339  {
340  /* Bad string pointer, bail out */
342  }
343  _SEH2_END;
344 
345  /* Now go through the kernel-mode code path */
346  return KdpPrint(ComponentId,
347  Level,
348  String,
349  Length,
350  KernelMode,
351  TrapFrame,
352  ExceptionFrame,
353  Handled);
354 }
NTSTATUS NTAPI KdpPrint(_In_ ULONG ComponentId, _In_ ULONG Level, _In_reads_bytes_(Length) PCHAR String, _In_ USHORT Length, _In_ KPROCESSOR_MODE PreviousMode, _In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PBOOLEAN Handled)
Definition: kdprint.c:358
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
char CHAR
Definition: xmlstorage.h:175
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
_SEH2_TRY
Definition: create.c:4226
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define ASSERT(a)
Definition: mode.c:45
#define KD_PRINT_MAX_BYTES
Definition: kdprint.c:16
_In_ BOOLEAN Handled
Definition: ketypes.h:337
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_SEH2_END
Definition: create.c:4400
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by KdpPrint().

◆ KdpPrintString()

BOOLEAN NTAPI KdpPrintString ( _In_ PSTRING  Output)

Definition at line 22 of file kdprint.c.

24 {
26  DBGKD_DEBUG_IO DebugIo;
27  USHORT Length;
28 
29  /* Copy the string */
31  Output->Buffer,
32  Output->Length);
33 
34  /* Make sure we don't exceed the KD Packet size */
35  Length = Output->Length;
36  if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE)
37  {
38  /* Normalize length */
40  }
41 
42  /* Build the packet header */
45  DebugIo.Processor = KeGetCurrentPrcb()->Number;
47  Header.Length = sizeof(DBGKD_DEBUG_IO);
48  Header.Buffer = (PCHAR)&DebugIo;
49 
50  /* Build the data */
51  Data.Length = Length;
52  Data.Buffer = KdpMessageBuffer;
53 
54  /* Send the packet */
56 
57  /* Check if the user pressed CTRL+C */
59 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
ULONG ApiNumber
Definition: windbgkd.h:401
CHAR KdpMessageBuffer[0x1000]
Definition: kddata.c:127
Definition: Header.h:8
#define DbgKdPrintStringApi
Definition: windbgkd.h:122
struct _DBGKD_DEBUG_IO DBGKD_DEBUG_IO
union _DBGKD_DEBUG_IO::@3527 u
USHORT ProcessorLevel
Definition: windbgkd.h:402
BOOLEAN NTAPI KdpPollBreakInWithPortLock(VOID)
Definition: kdlock.c:35
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
Definition: arc.h:85
DBGKD_PRINT_STRING PrintString
Definition: windbgkd.h:406
unsigned short USHORT
Definition: pedump.c:61
#define PACKET_TYPE_KD_DEBUG_IO
Definition: windbgkd.h:44
USHORT KeProcessorLevel
Definition: krnlinit.c:20
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
USHORT Processor
Definition: windbgkd.h:403

Referenced by KdpDprintf(), KdpPrint(), and KdReceivePacket().

◆ KdpPrompt()

USHORT NTAPI KdpPrompt ( _In_reads_bytes_(PromptLength) PCHAR  PromptString,
_In_ USHORT  PromptLength,
_Out_writes_bytes_(MaximumResponseLength) PCHAR  ResponseString,
_In_ USHORT  MaximumResponseLength,
_In_ KPROCESSOR_MODE  PreviousMode,
_In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 217 of file kdprint.c.

225 {
226  STRING PromptBuffer, ResponseBuffer;
227  BOOLEAN Enable, Resend;
228  PCHAR SafeResponseString;
229  CHAR CapturedPrompt[KD_PRINT_MAX_BYTES];
230  CHAR SafeResponseBuffer[KD_PRINT_MAX_BYTES];
231 
232  /* Normalize the lengths */
233  PromptLength = min(PromptLength,
234  sizeof(CapturedPrompt));
236  sizeof(SafeResponseBuffer));
237 
238  /* Check if we need to verify the string */
239  if (PreviousMode != KernelMode)
240  {
241  /* Handle user-mode buffers safely */
242  _SEH2_TRY
243  {
244  /* Probe and capture the prompt */
245  ProbeForRead(PromptString, PromptLength, 1);
246  KdpMoveMemory(CapturedPrompt, PromptString, PromptLength);
247  PromptString = CapturedPrompt;
248 
249  /* Probe and make room for the response */
250  ProbeForWrite(ResponseString, MaximumResponseLength, 1);
251  SafeResponseString = SafeResponseBuffer;
252  }
254  {
255  /* Bad string pointer, bail out */
256  _SEH2_YIELD(return 0);
257  }
258  _SEH2_END;
259  }
260  else
261  {
262  SafeResponseString = ResponseString;
263  }
264 
265  /* Setup the prompt and response buffers */
266  PromptBuffer.Buffer = PromptString;
267  PromptBuffer.Length = PromptBuffer.MaximumLength = PromptLength;
268  ResponseBuffer.Buffer = SafeResponseString;
269  ResponseBuffer.Length = 0;
270  ResponseBuffer.MaximumLength = MaximumResponseLength;
271 
272  /* Log the print */
273  //KdLogDbgPrint(&PromptBuffer);
274 
275  /* Enter the debugger */
276  Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
277 
278  /* Enter prompt loop */
279  do
280  {
281  /* Send the prompt and receive the response */
282  Resend = KdpPromptString(&PromptBuffer, &ResponseBuffer);
283 
284  /* Loop while we need to resend */
285  } while (Resend);
286 
287  /* Exit the debugger */
289 
290  /* Copy back the response if required */
291  if (PreviousMode != KernelMode)
292  {
293  _SEH2_TRY
294  {
295  /* Safely copy back the response to user mode */
296  KdpMoveMemory(ResponseString,
297  ResponseBuffer.Buffer,
298  ResponseBuffer.Length);
299  }
301  {
302  /* String became invalid after we exited, fail */
303  _SEH2_YIELD(return 0);
304  }
305  _SEH2_END;
306  }
307 
308  /* Return the number of characters received */
309  return ResponseBuffer.Length;
310 }
signed char * PCHAR
Definition: retypes.h:7
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
char CHAR
Definition: xmlstorage.h:175
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
BOOLEAN NTAPI KdpPromptString(_In_ PSTRING PromptString, _In_ PSTRING ResponseString)
Definition: kdprint.c:63
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1924
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
_In_ ULONG MaximumResponseLength
Definition: kdfuncs.h:11
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define KD_PRINT_MAX_BYTES
Definition: kdprint.c:16
std::wstring STRING
Definition: fontsub.cpp:33
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_SEH2_END
Definition: create.c:4400
#define min(a, b)
Definition: monoChain.cc:55
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1871
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by KdpTrap().

◆ KdpPromptString()

BOOLEAN NTAPI KdpPromptString ( _In_ PSTRING  PromptString,
_In_ PSTRING  ResponseString 
)

Definition at line 63 of file kdprint.c.

66 {
68  DBGKD_DEBUG_IO DebugIo;
69  ULONG Length;
71 
72  /* Copy the string to the message buffer */
74  PromptString->Buffer,
75  PromptString->Length);
76 
77  /* Make sure we don't exceed the KD Packet size */
78  Length = PromptString->Length;
79  if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE)
80  {
81  /* Normalize length */
83  }
84 
85  /* Build the packet header */
86  DebugIo.ApiNumber = DbgKdGetStringApi;
88  DebugIo.Processor = KeGetCurrentPrcb()->Number;
90  DebugIo.u.GetString.LengthOfStringRead = ResponseString->MaximumLength;
91  Header.Length = sizeof(DBGKD_DEBUG_IO);
92  Header.Buffer = (PCHAR)&DebugIo;
93 
94  /* Build the data */
95  Data.Length = Length;
96  Data.Buffer = KdpMessageBuffer;
97 
98  /* Send the packet */
100 
101  /* Set the maximum lengths for the receive */
102  Header.MaximumLength = sizeof(DBGKD_DEBUG_IO);
103  Data.MaximumLength = sizeof(KdpMessageBuffer);
104 
105  /* Enter receive loop */
106  do
107  {
108  /* Get our reply */
110  &Header,
111  &Data,
112  &Length,
113  &KdpContext);
114 
115  /* Return TRUE if we need to resend */
116  if (Status == KdPacketNeedsResend) return TRUE;
117 
118  /* Loop until we succeed */
119  } while (Status != KdPacketReceived);
120 
121  /* Don't copy back a larger response than there is room for */
122  Length = min(Length,
123  ResponseString->MaximumLength);
124 
125  /* Copy back the string and return the length */
126  KdpMoveMemory(ResponseString->Buffer,
128  Length);
129  ResponseString->Length = (USHORT)Length;
130 
131  /* Success; we don't need to resend */
132  return FALSE;
133 }
#define KdPacketReceived
Definition: kddll.h:5
ULONG LengthOfStringRead
Definition: windbgkd.h:393
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
KDP_STATUS NTAPI KdReceivePacket(IN ULONG PacketType, OUT PSTRING MessageHeader, OUT PSTRING MessageData, OUT PULONG DataLength, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:80
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
ULONG ApiNumber
Definition: windbgkd.h:401
CHAR KdpMessageBuffer[0x1000]
Definition: kddata.c:127
#define DbgKdGetStringApi
Definition: windbgkd.h:123
#define KdPacketNeedsResend
Definition: kddll.h:7
#define FALSE
Definition: types.h:117
Definition: Header.h:8
ULONG LengthOfPromptString
Definition: windbgkd.h:392
struct _DBGKD_DEBUG_IO DBGKD_DEBUG_IO
union _DBGKD_DEBUG_IO::@3527 u
USHORT ProcessorLevel
Definition: windbgkd.h:402
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
Status
Definition: gdiplustypes.h:24
std::wstring STRING
Definition: fontsub.cpp:33
DBGKD_GET_STRING GetString
Definition: windbgkd.h:407
unsigned short USHORT
Definition: pedump.c:61
#define PACKET_TYPE_KD_DEBUG_IO
Definition: windbgkd.h:44
ULONG KDSTATUS
Definition: kddll.h:4
#define min(a, b)
Definition: monoChain.cc:55
USHORT KeProcessorLevel
Definition: krnlinit.c:20
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
USHORT Processor
Definition: windbgkd.h:403

Referenced by KdpPrompt().

◆ KdpSymbol()

VOID NTAPI KdpSymbol ( IN PSTRING  DllPath,
IN PKD_SYMBOLS_INFO  SymbolInfo,
IN BOOLEAN  Unload,
IN KPROCESSOR_MODE  PreviousMode,
IN PCONTEXT  ContextRecord,
IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 176 of file kdprint.c.

183 {
184  BOOLEAN Enable;
185  PKPRCB Prcb = KeGetCurrentPrcb();
186 
187  /* Check if we need to do anything */
188  if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return;
189 
190  /* Enter the debugger */
191  Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
192 
193  /* Save the CPU Control State and save the context */
197  sizeof(CONTEXT));
198 
199  /* Report the new state */
201  SymbolInfo,
202  Unload,
204 
205  /* Restore the processor state */
208  sizeof(CONTEXT));
210 
211  /* Exit the debugger and return */
213 }
VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: csqtest.c:160
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1924
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
CONTEXT ContextFrame
Definition: ketypes.h:531
unsigned char BOOLEAN
VOID NTAPI KiRestoreProcessorControlState(IN PKPROCESSOR_STATE ProcessorState)
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
VOID NTAPI KdpReportLoadSymbolsStateChange(IN PSTRING PathName, IN PKD_SYMBOLS_INFO SymbolInfo, IN BOOLEAN Unload, IN OUT PCONTEXT Context)
Definition: kdapi.c:1581
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:579
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:655
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:375
static const char const char * DllPath
Definition: image.c:34
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1871

Referenced by KdpTrap().