47 lines
835 B
C++
47 lines
835 B
C++
|
#pragma once
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <cstring>
|
||
|
#include <stdexcept>
|
||
|
#include <thread>
|
||
|
#include <atomic>
|
||
|
#include <vector>
|
||
|
#include <sstream>
|
||
|
#include <iomanip>
|
||
|
#include <sys/socket.h>
|
||
|
#include <netinet/in.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
class GDBStub {
|
||
|
public:
|
||
|
GDBStub(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);
|
||
|
};
|