Skip to content

Commit

Permalink
GdbServer: Splits Multi-letter v command handler
Browse files Browse the repository at this point in the history
Just breaks out the two commands we support and leaves TODOs for
implementing the remaining commands.

NFC
  • Loading branch information
Sonicadvance1 committed Nov 26, 2024
1 parent 7b3f737 commit 123e0d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 38 additions & 1 deletion Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ desc: Provides a gdb interface to the guest state
#include <iomanip>
#include <memory>
#include <optional>
#include <string_view>

#include <Common/FEXServerClient.h>
#include <FEXCore/Config/Config.h>
Expand Down Expand Up @@ -1003,7 +1004,7 @@ GdbServer::HandledPacketType GdbServer::CommandQueryThreadAlive(const fextl::str
return {"OK", HandledPacketType::TYPE_ACK};
}

GdbServer::HandledPacketType GdbServer::CommandMultiLetterV(const fextl::string& packet) {
GdbServer::HandledPacketType GdbServer::HandlevFile(const fextl::string& packet) {
const auto match = [&](const fextl::string& str) -> std::optional<fextl::istringstream> {
if (packet.rfind(str, 0) == 0) {
auto ss = fextl::istringstream(packet);
Expand Down Expand Up @@ -1074,10 +1075,26 @@ GdbServer::HandledPacketType GdbServer::CommandMultiLetterV(const fextl::string&
data.resize(ret);
return {F_data(ret, data), HandledPacketType::TYPE_ACK};
}

return {"", HandledPacketType::TYPE_ACK};
}

GdbServer::HandledPacketType GdbServer::HandlevCont(const fextl::string& packet) {
const auto match = [&](const fextl::string& str) -> std::optional<fextl::istringstream> {
if (packet.rfind(str, 0) == 0) {
auto ss = fextl::istringstream(packet);
ss.seekg(str.size());
return ss;
}
return std::nullopt;
};

std::optional<fextl::istringstream> ss;
if ((ss = match("vCont?"))) {
return {"vCont;c;t;s;r", HandledPacketType::TYPE_ACK}; // We support continue, step and terminate
// FIXME: We also claim to support continue with signal... because it's compulsory
}

if ((ss = match("vCont;"))) {
char action {};
int thread {};
Expand All @@ -1095,6 +1112,26 @@ GdbServer::HandledPacketType GdbServer::CommandMultiLetterV(const fextl::string&

return ThreadAction(action, thread);
}

return {"", HandledPacketType::TYPE_ACK};
}

GdbServer::HandledPacketType GdbServer::CommandMultiLetterV(const fextl::string& packet) {
// TODO: vAttach
if (packet.starts_with("vCont")) {
return HandlevCont(packet);
}

// TODO: vCtrlC

if (packet.starts_with("vFile")) {
return HandlevFile(packet);
}

// TODO: vKill
// TODO: vRun
// TODO: vStopped

return {"", HandledPacketType::TYPE_ACK};
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class GdbServer {
HandledPacketType XferCommandAuxv(const fextl::string& annex, int offset, int length);
HandledPacketType handleXfer(const fextl::string& packet);

HandledPacketType HandlevFile(const fextl::string& packet);
HandledPacketType HandlevCont(const fextl::string& packet);

// Command handlers
HandledPacketType CommandEnableExtendedMode(const fextl::string& packet);
HandledPacketType CommandQueryHalted(const fextl::string& packet);
Expand Down

0 comments on commit 123e0d7

Please sign in to comment.