49 lines
869 B
C++
49 lines
869 B
C++
#pragma once
|
|
|
|
#include <netinet/in.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
|
|
#include <atomic>
|
|
#include <cstring>
|
|
#include <unordered_map>
|
|
|
|
#include "vm.hpp"
|
|
|
|
class GDBStub {
|
|
public:
|
|
GDBStub(VM &vm, int port);
|
|
~GDBStub();
|
|
|
|
void run();
|
|
void stop();
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
std::unordered_map<uint32_t, uint32_t> breakpoints;
|
|
};
|