diff options
author | Oxore <oxore@protonmail.com> | 2022-08-30 16:49:38 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2022-08-30 16:49:38 +0300 |
commit | ed3cf413dfe5f874f203f8b6a696af29cfc47dcd (patch) | |
tree | 9d9c181a568cf1833218444c0d2b26b33063435e /gdbremote_parser.cpp | |
parent | 026894023fa53fa32fd342d18e05f55743cf6c4b (diff) |
Impl emulator stepping with GDB
Diffstat (limited to 'gdbremote_parser.cpp')
-rw-r--r-- | gdbremote_parser.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/gdbremote_parser.cpp b/gdbremote_parser.cpp index d8f4f50..204690d 100644 --- a/gdbremote_parser.cpp +++ b/gdbremote_parser.cpp @@ -24,6 +24,13 @@ static inline bool isseparator(uint8_t byte) return ':' == byte || ';' == byte || ',' == byte; } +static inline bool IsTokenTypeSeparator(TokenType token_type) +{ + return token_type == TokenType::kSeparatorColon || + token_type == TokenType::kSeparatorComma || + token_type == TokenType::kSeparatorSemicolon; +} + static inline TokenType separatorTypeFromByte(uint8_t byte) { if (':' == byte) return TokenType::kSeparatorColon; @@ -143,14 +150,47 @@ struct Command { { return Packet{PacketType::kInterrupt}; } - static Packet parseContinue(const std::vector<Token>&&) + static Packet parseContinue(const std::vector<Token>&& tokens) { + const std::string first = tokens[0].data; + constexpr size_t command_len = strlen("vCont"); + // Check if it is "vCont?" command + if (first.length() > command_len && first[command_len] == '?') { + return Packet{PacketType::kContinueAskSupported}; + } + // TODO arguments return Packet{PacketType::kContinue}; } static Packet parseReadGeneralRegisters(const std::vector<Token>&&) { return Packet{PacketType::kReadGeneralRegisters}; } + static Packet parseReadMemory(const std::vector<Token>&& tokens) + { + if (tokens.size() < 3 || + tokens[0].type != TokenType::kArbitrary || + !IsTokenTypeSeparator(tokens[1].type) || + tokens[2].type != TokenType::kNumeric) + { + return Packet::None(); + } + constexpr size_t command_len = strlen("m"); + const std::string first = tokens[0].data; + const std::string second = tokens[2].data; + const uint32_t offset = strtol( + first.substr(command_len, first.length()-command_len).c_str(), + nullptr, + 16); + const uint32_t lenght = strtol(second.c_str(), nullptr, 16); + return Packet{ + PacketType::kReadMemory, + std::make_unique<const PacketDataReadMemory>(offset, lenght), + }; + } + static Packet parseStep(const std::vector<Token>&&) + { + return Packet{PacketType::kStep}; + } }; static const Command commands[] = { @@ -169,7 +209,9 @@ static const Command commands[] = { { "\x03", Command::parseInterrupt }, { "vCtrlC", Command::parseInterrupt }, { "vCont", Command::parseContinue }, + { "m", Command::parseReadMemory }, { "g", Command::parseReadGeneralRegisters }, + { "s", Command::parseStep }, }; Packet Packet::Parse(std::string packet_data) |