diff options
author | Oxore <oxore@protonmail.com> | 2022-08-27 22:52:31 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2022-08-27 22:52:31 +0300 |
commit | 8c012736814265e198d68654ccdc597c265f4f82 (patch) | |
tree | 67bf114dd4424c89af0862a7ee9fe01afd9443c9 /gdbremote.cpp | |
parent | 9580a9a8daa4426914f396a694903ab880ecd3f2 (diff) |
Introduce sophisticated parsing in GDBRemote
Diffstat (limited to 'gdbremote.cpp')
-rw-r--r-- | gdbremote.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/gdbremote.cpp b/gdbremote.cpp index 98a0e2a..a093192 100644 --- a/gdbremote.cpp +++ b/gdbremote.cpp @@ -78,15 +78,28 @@ int main(int argc, char *argv[]) while ((read_size = recv(conn_fd, msg_buf, MESSAGE_BUFFER_SIZE, 0)) > 0) { for (size_t i = 0; i < static_cast<size_t>(read_size); i++) { const auto res = exchange_ctx.Consume(msg_buf[i]); - if (res != nullptr) { - if (res->packet.length() > 0) { - printf("<- \"%s\"\n", res->packet.c_str()); - } - if (res->response.length() > 0) { - printf("-> \"%s\"\n", res->response.c_str()); - if (send(conn_fd, &res->response[0], res->response.length(), 0) == -1) - perror("Send failed"); - } + if (res == nullptr) continue; + if (res->packet.length() > 0) { + if (0) printf("<- \"%s\"\n", res->packet.c_str()); + printf("<- \"%s\"\n", exchange_ctx.GetLastPacket().c_str()); + const auto packet = GDBRemote::Packet::Parse(res->packet); + printf( + " Packet type: \"%s\"\n", + GDBRemote::Packet::PacketTypeToString(packet.type)); + } + if (res->ack.length() > 0) { + printf("-> \"%s\"\n", res->ack.c_str()); + if (send(conn_fd, &res->ack[0], res->ack.length(), 0) == -1) + perror("Send failed (ack/nak)"); + } + if (res->packet.length() > 0) { + const auto packet = GDBRemote::Packet::Parse(res->packet); + + (void) packet; + const auto response = exchange_ctx.WrapDataToSend(); + printf("-> \"%s\"\n", response.c_str()); + if (send(conn_fd, &response[0], response.length(), 0) == -1) + perror("Send failed (response)"); } } memset(msg_buf, '\0', MESSAGE_BUFFER_SIZE); |