mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-22 05:03:56 +00:00
Refactor gdb interface
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <ranges>
|
||||
#include <cstddef>
|
||||
#include <sstream>
|
||||
#include <cwctype>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -44,4 +45,27 @@ namespace utils::string
|
||||
{
|
||||
return to_lower(std::move(str));
|
||||
}
|
||||
|
||||
template <typename Integer>
|
||||
requires(std::is_integral_v<Integer>)
|
||||
std::string to_hex_string(const Integer& i)
|
||||
{
|
||||
std::stringstream stream{};
|
||||
stream << std::hex << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(const void* data, const size_t size)
|
||||
{
|
||||
std::stringstream stream{};
|
||||
stream << std::hex;
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
const auto value = static_cast<const uint8_t*>(data)[i];
|
||||
stream << value;
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
|
||||
namespace gdb_stub
|
||||
{
|
||||
@@ -17,13 +16,4 @@ namespace gdb_stub
|
||||
|
||||
return checksum;
|
||||
}
|
||||
|
||||
inline std::string compute_checksum_as_string(const std::string_view data)
|
||||
{
|
||||
const auto checksum = compute_checksum(data);
|
||||
|
||||
std::stringstream stream{};
|
||||
stream << std::hex << checksum;
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "connection_handler.hpp"
|
||||
#include "checksum.hpp"
|
||||
#include <utils/string.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace gdb_stub
|
||||
|
||||
void connection_handler::send_packet(const std::string_view data) const
|
||||
{
|
||||
const auto checksum = compute_checksum_as_string(data);
|
||||
const auto checksum = utils::string::to_hex_string(compute_checksum(data));
|
||||
this->send_raw_data("$" + std::string(data) + "#" + checksum);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,10 @@ namespace gdb_stub
|
||||
}
|
||||
}
|
||||
|
||||
void read_registers()
|
||||
{
|
||||
}
|
||||
|
||||
void handle_command(const connection_handler& connection, async_handler& async, gdb_stub_handler& handler,
|
||||
const uint8_t command, const std::string_view data)
|
||||
{
|
||||
@@ -73,18 +77,20 @@ namespace gdb_stub
|
||||
{
|
||||
case 'c':
|
||||
async.run();
|
||||
process_action(connection, handler.cont());
|
||||
process_action(connection, handler.run());
|
||||
async.pause();
|
||||
break;
|
||||
|
||||
case 's':
|
||||
process_action(connection, handler.stepi());
|
||||
process_action(connection, handler.singlestep());
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
process_query(connection, data);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
|
||||
default:
|
||||
connection.send_packet({});
|
||||
break;
|
||||
|
||||
@@ -24,21 +24,24 @@ namespace gdb_stub
|
||||
{
|
||||
virtual ~gdb_stub_handler() = default;
|
||||
|
||||
virtual gdb_action cont() = 0;
|
||||
virtual gdb_action stepi() = 0;
|
||||
virtual gdb_action run() = 0;
|
||||
virtual gdb_action singlestep() = 0;
|
||||
|
||||
virtual bool read_reg(int regno, size_t* value) = 0;
|
||||
virtual bool write_reg(int regno, size_t value) = 0;
|
||||
virtual size_t get_register_count() = 0;
|
||||
virtual size_t get_max_register_size() = 0;
|
||||
|
||||
virtual bool read_mem(size_t addr, size_t len, void* val) = 0;
|
||||
virtual bool write_mem(size_t addr, size_t len, void* val) = 0;
|
||||
virtual bool read_register(size_t reg, void* data, size_t max_length) = 0;
|
||||
virtual bool write_register(size_t reg, const void* data, size_t size) = 0;
|
||||
|
||||
virtual bool set_bp(breakpoint_type type, size_t addr, size_t size) = 0;
|
||||
virtual bool del_bp(breakpoint_type type, size_t addr, size_t size) = 0;
|
||||
virtual bool read_memory(size_t address, void* data, size_t length) = 0;
|
||||
virtual bool write_memory(size_t address, const void* data, size_t length) = 0;
|
||||
|
||||
virtual bool set_breakpoint(breakpoint_type type, size_t address, size_t size) = 0;
|
||||
virtual bool delete_breakpoint(breakpoint_type type, size_t address, size_t size) = 0;
|
||||
|
||||
virtual void on_interrupt() = 0;
|
||||
|
||||
virtual std::string get_target_description() const = 0;
|
||||
virtual std::string get_target_description() = 0;
|
||||
};
|
||||
|
||||
bool run_gdb_stub(const network::address& bind_address, gdb_stub_handler& handler);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "checksum.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace gdb_stub
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user