summaryrefslogtreecommitdiff
path: root/gdbremote_parser.cpp
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2022-08-30 20:34:04 +0300
committerOxore <oxore@protonmail.com>2022-08-30 22:31:47 +0300
commit1c108b02f62c0812a8a71e78854666588a811840 (patch)
tree45a223e75cc5a76273c88e3c96148a67a07324d8 /gdbremote_parser.cpp
parented3cf413dfe5f874f203f8b6a696af29cfc47dcd (diff)
Implement GDB's execution continue and interrupt
Diffstat (limited to 'gdbremote_parser.cpp')
-rw-r--r--gdbremote_parser.cpp25
1 files changed, 16 insertions, 9 deletions
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<Token>&& tokens)
+ static Packet parseContinueVCont(const std::vector<Token>&& 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<Token>&&)
+ static Packet parseContinue(const std::vector<Token>&&)
{
- return Packet{PacketType::kReadGeneralRegisters};
+ return Packet{PacketType::kContinue};
}
static Packet parseReadMemory(const std::vector<Token>&& tokens)
{
@@ -187,6 +187,10 @@ struct Command {
std::make_unique<const PacketDataReadMemory>(offset, lenght),
};
}
+ static Packet parseReadGeneralRegisters(const std::vector<Token>&&)
+ {
+ return Packet{PacketType::kReadGeneralRegisters};
+ }
static Packet parseStep(const std::vector<Token>&&)
{
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<ExchangeResult> 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();