KDSTATUS gdb_receive_and_interpret_packet( _Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext) { KDSTATUS Status; do { Status = gdb_receive_packet(KdContext); KDDBGPRINT("KDGBD: Packet received with status %u\n", Status); if (Status != KdPacketReceived) return Status; Status = (KDSTATUS)-1; switch (gdb_input[0]) { case '?': /* Send the Status */ gdb_send_exception(TRUE); break; case '!': send_gdb_packet("OK"); break; case 'g': gdb_send_registers(); break; case 'H': handle_gdb_set_thread(); break; case 'm': Status = handle_gdb_read_mem(State, MessageData, MessageLength, KdContext); break; case 'p': gdb_send_register(); break; case 'q': handle_gdb_query(); break; case 'T': handle_gdb_thread_alive(); break; case 'v': Status = handle_gdb_v(State, MessageData, MessageLength, KdContext); break; default: /* We don't know how to handle this request. Maybe this is something for KD */ State->ReturnStatus = STATUS_NOT_SUPPORTED; KDDBGPRINT("Unsupported GDB command: %s.\n", gdb_input); return KdPacketReceived; } } while (Status == (KDSTATUS)-1); return Status; }
/****************************************************************************** * \name KdReceivePacket * \brief Receive a packet from the KD port. * \param [in] PacketType Describes the type of the packet to receive. * This can be one of the PACKET_TYPE_ constants. * \param [out] MessageHeader Pointer to a STRING structure for the header. * \param [out] MessageData Pointer to a STRING structure for the data. * \return KdPacketReceived if successful, KdPacketTimedOut if the receive * timed out, KdPacketNeedsResend to signal that the last packet needs * to be sent again. * \note If PacketType is PACKET_TYPE_KD_POLL_BREAKIN, the function doesn't * wait for any data, but returns KdPacketTimedOut instantly if no breakin * packet byte is received. * \sa http://www.nynaeve.net/?p=169 */ KDSTATUS NTAPI KdReceivePacket( _In_ ULONG PacketType, _Out_ PSTRING MessageHeader, _Out_ PSTRING MessageData, _Out_ PULONG DataLength, _Inout_ PKD_CONTEXT KdContext) { KDSTATUS Status; DBGKD_MANIPULATE_STATE64* State; /* Special handling for breakin packet */ if (PacketType == PACKET_TYPE_KD_POLL_BREAKIN) { return KdpPollBreakIn(); } if (PacketType != PACKET_TYPE_KD_STATE_MANIPULATE) { /* What should we do ? */ while (1); } State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer; /* Maybe we are in a send<->receive loop that GDB doesn't need to know about */ if (KdpManipulateStateHandler != NULL) return KdpManipulateStateHandler(State, MessageData, DataLength, KdContext); /* Receive data from GDB */ Status = gdb_receive_packet(KdContext); if (Status != KdPacketReceived) return Status; /* Interpret it */ return gdb_interpret_input(State, MessageData, DataLength, KdContext); }