rve/src/debug.hpp

53 lines
904 B
C++
Raw Normal View History

#pragma once
2024-12-09 00:48:40 +00:00
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <atomic>
#include <cstring>
2024-12-09 00:48:40 +00:00
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <thread>
#include <vector>
2024-12-09 00:48:40 +00:00
#include "vm.hpp"
class GDBStub {
2024-12-09 00:48:40 +00:00
public:
GDBStub(VM &vm, int port);
~GDBStub();
void run();
void stop();
2024-12-09 00:48:40 +00:00
private:
int server_fd;
int client_fd;
std::atomic<bool> running;
// Buffer size for GDB packet handling
static constexpr size_t BUFFER_SIZE = 4096;
void send_packet(const std::string &packet);
void send_ack();
void wait_ack();
std::string receive_packet();
void handle_packet(const std::string &packet);
2024-12-09 00:48:40 +00:00
bool parse_memory_request(const std::string &packet, size_t &addr,
size_t &length);
std::string read_registers();
std::string read_memory(size_t addr, size_t length);
VM &vm;
};