test: kddbgio.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# kddbgio.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1990  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     kddbgio.c
    00008
    00009 Abstract:
    00010
    00011     This module implements kernel debugger based Dbg I/O. This
    00012     is the foundation for DbgPrint and DbgPrompt.
    00013
    00014 Author:
    00015
    00016     Mark Lucovsky (markl) 31-Aug-1990
    00017
    00018 Revision History:
    00019
    00020 --*/
    00021
    00022 #include "kdp.h"
    00023
    00024 #ifdef ALLOC_PRAGMA
    00025 #pragma alloc_text(PAGEKD, KdpPrintString)
    00026 #pragma alloc_text(PAGEKD, KdpPromptString)
    00027 #endif
    00028
    00029 BOOLEAN
    00030 KdpPrintString (
    00031     IN PSTRING Output
    00032     )
    00033
    00034 /*++
    00035
    00036 Routine Description:
    00037
    00038     This routine prints a string.
    00039
    00040 Arguments:
    00041
    00042     Output - Supplies a pointer to a string descriptor for the output string.
    00043
    00044 Return Value:
    00045
    00046     TRUE if Control-C present in input buffer after print is done.
    00047     FALSE otherwise.
    00048
    00049 --*/
    00050
    00051 {
    00052
    00053     ULONG Length;
    00054     STRING MessageData;
    00055     STRING MessageHeader;
    00056     DBGKD_DEBUG_IO DebugIo;
    00057
    00058     //
    00059     // Move the output string to the message buffer.
    00060     //
    00061
    00062     Length = KdpMoveMemory(
    00063                 (PCHAR)KdpMessageBuffer,
    00064                 (PCHAR)Output->Buffer,
    00065                 Output->Length
    00066                 );
    00067
    00068     //
    00069     // If the total message length is greater than the maximum packet size,
    00070     // then truncate the output string.
    00071     //
    00072
    00073     if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE) {
    00074         Length = PACKET_MAX_SIZE - sizeof(DBGKD_DEBUG_IO);
    00075     }
    00076
    00077     //
    00078     // Construct the print string message and message descriptor.
    00079     //
    00080
    00081     DebugIo.ApiNumber = DbgKdPrintStringApi;
    00082     DebugIo.ProcessorLevel = KeProcessorLevel;
    00083     DebugIo.Processor = (USHORT)KeGetCurrentPrcb()->Number;
    00084     DebugIo.u.PrintString.LengthOfString = Length;
    00085     MessageHeader.Length = sizeof(DBGKD_DEBUG_IO);
    00086     MessageHeader.Buffer = (PCHAR)&DebugIo;
    00087
    00088     //
    00089     // Construct the print string data and data descriptor.
    00090     //
    00091
    00092     MessageData.Length = (USHORT)Length;
    00093     MessageData.Buffer = KdpMessageBuffer;
    00094
    00095     //
    00096     // Send packet to the kernel debugger on the host machine.
    00097     //
    00098
    00099     KdpSendPacket(
    00100                   PACKET_TYPE_KD_DEBUG_IO,
    00101                   &MessageHeader,
    00102                   &MessageData
    00103                   );
    00104
    00105     return KdpPollBreakInWithPortLock();
    00106 }
    00107
    00108
    00109 BOOLEAN
    00110 KdpPromptString (
    00111     IN PSTRING Output,
    00112     IN OUT PSTRING Input
    00113     )
    00114
    00115 /*++
    00116
    00117 Routine Description:
    00118
    00119     This routine prints a string, then reads a reply string.
    00120
    00121 Arguments:
    00122
    00123     Output - Supplies a pointer to a string descriptor for the output string.
    00124
    00125     Input - Supplies a pointer to a string descriptor for the input string.
    00126             (Length stored/returned in Input->Length)
    00127
    00128 Return Value:
    00129
    00130     TRUE - A Breakin sequence was seen, caller should breakpoint and retry
    00131     FALSE - No Breakin seen.
    00132
    00133 --*/
    00134
    00135 {
    00136
    00137     ULONG Length;
    00138     STRING MessageData;
    00139     STRING MessageHeader;
    00140     DBGKD_DEBUG_IO DebugIo;
    00141     ULONG ReturnCode;
    00142
    00143     //
    00144     // Move the output string to the message buffer.
    00145     //
    00146
    00147     Length = KdpMoveMemory(
    00148                 (PCHAR)KdpMessageBuffer,
    00149                 (PCHAR)Output->Buffer,
    00150                 Output->Length
    00151                 );
    00152
    00153     //
    00154     // If the total message length is greater than the maximum packet size,
    00155     // then truncate the output string.
    00156     //
    00157
    00158     if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE) {
    00159         Length = PACKET_MAX_SIZE - sizeof(DBGKD_DEBUG_IO);
    00160     }
    00161
    00162     //
    00163     // Construct the prompt string message and message descriptor.
    00164     //
    00165
    00166     DebugIo.ApiNumber = DbgKdGetStringApi;
    00167     DebugIo.ProcessorLevel = KeProcessorLevel;
    00168     DebugIo.Processor = (USHORT)KeGetCurrentPrcb()->Number;
    00169     DebugIo.u.GetString.LengthOfPromptString = Length;
    00170     DebugIo.u.GetString.LengthOfStringRead = Input->MaximumLength;
    00171     MessageHeader.Length = sizeof(DBGKD_DEBUG_IO);
    00172     MessageHeader.Buffer = (PCHAR)&DebugIo;
    00173
    00174     //
    00175     // Construct the prompt string data and data descriptor.
    00176     //
    00177
    00178     MessageData.Length = (USHORT)Length;
    00179     MessageData.Buffer = KdpMessageBuffer;
    00180
    00181     //
    00182     // Send packet to the kernel debugger on the host machine.
    00183     //
    00184
    00185     KdpSendPacket(
    00186                   PACKET_TYPE_KD_DEBUG_IO,
    00187                   &MessageHeader,
    00188                   &MessageData
    00189                   );
    00190
    00191
    00192     //
    00193     // Receive packet from the kernel debugger on the host machine.
    00194     //
    00195
    00196     MessageHeader.MaximumLength = sizeof(DBGKD_DEBUG_IO);
    00197     MessageData.MaximumLength = KDP_MESSAGE_BUFFER_SIZE;
    00198
    00199     do {
    00200         ReturnCode = KdpReceivePacket(
    00201                                       PACKET_TYPE_KD_DEBUG_IO,
    00202                                       &MessageHeader,
    00203                                       &MessageData,
    00204                                       &Length
    00205                                       );
    00206         if (ReturnCode == KDP_PACKET_RESEND) {
    00207             return TRUE;
    00208         }
    00209     } while (ReturnCode != KDP_PACKET_RECEIVED);
    00210
    00211
    00212     if (Length > Input->MaximumLength) {
    00213         Length = Input->MaximumLength;
    00214     }
    00215
    00216     Input->Length = (USHORT)KdpMoveMemory(
    00217                                 (PCHAR)Input->Buffer,
    00218                                 (PCHAR)KdpMessageBuffer,
    00219                                 Length
    00220                                 );
    00221
    00222     return FALSE;
    00223 }