From 1c108b02f62c0812a8a71e78854666588a811840 Mon Sep 17 00:00:00 2001 From: Oxore Date: Tue, 30 Aug 2022 20:34:04 +0300 Subject: Implement GDB's execution continue and interrupt --- gdbremote_parser.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'gdbremote_parser.cpp') diff --git a/gdbremote_parser.cpp b/gdbremote_parser.cpp index 204690d..641590f 100644 --- a/gdbremote_parser.cpp +++ b/gdbremote_parser.cpp @@ -150,7 +150,7 @@ struct Command { { return Packet{PacketType::kInterrupt}; } - static Packet parseContinue(const std::vector&& tokens) + static Packet parseContinueVCont(const std::vector&& tokens) { const std::string first = tokens[0].data; constexpr size_t command_len = strlen("vCont"); @@ -161,9 +161,9 @@ struct Command { // TODO arguments return Packet{PacketType::kContinue}; } - static Packet parseReadGeneralRegisters(const std::vector&&) + static Packet parseContinue(const std::vector&&) { - return Packet{PacketType::kReadGeneralRegisters}; + return Packet{PacketType::kContinue}; } static Packet parseReadMemory(const std::vector&& tokens) { @@ -187,6 +187,10 @@ struct Command { std::make_unique(offset, lenght), }; } + static Packet parseReadGeneralRegisters(const std::vector&&) + { + return Packet{PacketType::kReadGeneralRegisters}; + } static Packet parseStep(const std::vector&&) { return Packet{PacketType::kStep}; @@ -208,7 +212,8 @@ static const Command commands[] = { { "!", Command::parseEnableExtendedMode }, { "\x03", Command::parseInterrupt }, { "vCtrlC", Command::parseInterrupt }, - { "vCont", Command::parseContinue }, + { "vCont", Command::parseContinueVCont }, + { "c", Command::parseContinue }, { "m", Command::parseReadMemory }, { "g", Command::parseReadGeneralRegisters }, { "s", Command::parseStep }, @@ -217,17 +222,19 @@ static const Command commands[] = { Packet Packet::Parse(std::string packet_data) { const auto tokens = Token::Tokenize(packet_data); - if (tokens.size() == 0) return Packet::None(); + if (tokens.size() == 0) { + printf("Warning: no tokens to parse\n"); + return Packet::None(); + } const auto first_token = tokens[0]; - if (first_token.type != TokenType::kArbitrary) return Packet::None(); for (const auto& command: commands) { const auto cmdlen = command.name.length(); const auto toklen = first_token.data.length(); - const auto len = std::min(cmdlen, cmdlen); // Make sure first token fully includes the command from the beginning // and not necessary fully equals to it. + // TODO tokenize as if the command is always a separate token if (cmdlen <= toklen && 0 == memcmp( - &command.name[0], &first_token.data[0], len)) + &command.name[0], &first_token.data[0], cmdlen)) { return command.parse(std::move(tokens)); } @@ -286,7 +293,7 @@ std::unique_ptr ExchangeContext::Consume(uint8_t byte) return ExchangeResult::Ack(packet_data); } else { printf( - "Checksum mismatch received: %02X, expected: %02X\n", + "Checksum mismatch: received=%02x, expected=%02x\n", given_checksum, checksum); printf("Packet data: \"%s\"\n", packet_data.c_str()); return ExchangeResult::Nak(); -- cgit v1.2.3