diff --git a/src/gdb-stub/gdb_stub.cpp b/src/gdb-stub/gdb_stub.cpp
index 6f67cd0d..308cded5 100644
--- a/src/gdb-stub/gdb_stub.cpp
+++ b/src/gdb-stub/gdb_stub.cpp
@@ -49,15 +49,45 @@ namespace gdb_stub
return {name, args};
}
+ void handle_features(connection_handler& connection, debugging_handler& handler, const std::string_view payload)
+ {
+ const auto [command, args] = split_string(payload, ':');
+
+ if (command != "read")
+ {
+ connection.send_reply({});
+ return;
+ }
+
+ const auto [file, data] = split_string(args, ':');
+
+ size_t offset{}, length{};
+ rt_assert(sscanf_s(std::string(data).c_str(), "%zx,%zx", &offset, &length) == 2);
+
+ const auto target_description = handler.get_target_description(file);
+
+ if (offset >= target_description.size())
+ {
+ connection.send_reply("l");
+ return;
+ }
+
+ const auto remaining = target_description.size() - offset;
+ const auto real_length = std::min(remaining, length);
+ const auto is_end = real_length == remaining;
+
+ const auto sub_region = target_description.substr(offset, real_length);
+
+ connection.send_reply((is_end ? "l" : "m") + sub_region);
+ }
+
void process_xfer(connection_handler& connection, debugging_handler& handler, const std::string_view payload)
{
auto [name, args] = split_string(payload, ':');
if (name == "features")
{
- connection.send_reply("l" //
- + handler.get_target_description() //
- + "");
+ handle_features(connection, handler, args);
}
else
{
diff --git a/src/gdb-stub/gdb_stub.hpp b/src/gdb-stub/gdb_stub.hpp
index 9a71b7b2..493a960e 100644
--- a/src/gdb-stub/gdb_stub.hpp
+++ b/src/gdb-stub/gdb_stub.hpp
@@ -42,7 +42,7 @@ namespace gdb_stub
virtual void on_interrupt() = 0;
- virtual std::string get_target_description() = 0;
+ virtual std::string get_target_description(std::string_view file) = 0;
};
bool run_gdb_stub(const network::address& bind_address, debugging_handler& handler);
diff --git a/src/windows-emulator/debugging/win_x64_gdb_stub_handler.hpp b/src/windows-emulator/debugging/win_x64_gdb_stub_handler.hpp
index 96b87212..451078a8 100644
--- a/src/windows-emulator/debugging/win_x64_gdb_stub_handler.hpp
+++ b/src/windows-emulator/debugging/win_x64_gdb_stub_handler.hpp
@@ -40,11 +40,6 @@ class win_x64_gdb_stub_handler : public x64_gdb_stub_handler
return gdb_stub::action::resume;
}
- std::string get_target_description() override
- {
- return "i386:x86-64";
- }
-
private:
windows_emulator* win_emu_{};
};
diff --git a/src/windows-emulator/debugging/x64_gdb_stub_handler.hpp b/src/windows-emulator/debugging/x64_gdb_stub_handler.hpp
index f80996cd..7dde76a4 100644
--- a/src/windows-emulator/debugging/x64_gdb_stub_handler.hpp
+++ b/src/windows-emulator/debugging/x64_gdb_stub_handler.hpp
@@ -4,6 +4,8 @@
#include
#include
+#include "x64_target_descriptions.hpp"
+
inline std::vector gdb_registers{
x64_register::rax, x64_register::rbx, x64_register::rcx, x64_register::rdx, x64_register::rsi, x64_register::rdi,
x64_register::rbp, x64_register::rsp, x64_register::r8, x64_register::r9, x64_register::r10, x64_register::r11,
@@ -211,6 +213,17 @@ class x64_gdb_stub_handler : public gdb_stub::debugging_handler
this->emu_->stop();
}
+ std::string get_target_description(const std::string_view file) override
+ {
+ const auto entry = x64_target_descriptions.find(file);
+ if (entry == x64_target_descriptions.end())
+ {
+ return {};
+ }
+
+ return entry->second;
+ }
+
private:
x64_emulator* emu_{};
diff --git a/src/windows-emulator/debugging/x64_target_descriptions.hpp b/src/windows-emulator/debugging/x64_target_descriptions.hpp
new file mode 100644
index 00000000..a775f6ad
--- /dev/null
+++ b/src/windows-emulator/debugging/x64_target_descriptions.hpp
@@ -0,0 +1,215 @@
+#pragma once
+
+#include