gdbstub: Fix GDB command matching and don't reply with "Unrecognized Command" (#3497)

Also:
* Mark thread as suspended so we can resume later
This commit is contained in:
FirebirdTA01
2025-04-01 08:46:02 -05:00
committed by GitHub
parent bee56386cc
commit 9878f15221
2 changed files with 11 additions and 3 deletions
+9 -3
View File
@@ -696,7 +696,8 @@ constexpr bool cmp_less(T t, U u) noexcept {
}
static bool command_begins_with(PacketCommand &command, const std::string_view small_str) {
if (!cmp_less(small_str.size(), command.content_length))
// If the command's content is shorter than small_str, it can't match
if (static_cast<size_t>(command.content_length) < small_str.size())
return false;
return std::memcmp(command.content_start, small_str.data(), small_str.size()) == 0;
@@ -737,8 +738,10 @@ static int64_t server_next(EmuEnvState &state) {
PacketCommand command = parse_command(buffer + a, length - a);
if (command.is_valid) {
bool found_command = false;
for (const auto &function : functions) {
if (command_begins_with(command, function.name)) {
found_command = true;
LOG_GDB("GDB Server Recognized Command as {}. {}", function.name,
std::string(command.content_start, command.content_length));
state.gdb.last_reply = function.function(state, command);
@@ -748,8 +751,11 @@ static int64_t server_next(EmuEnvState &state) {
break;
}
}
LOG_GDB("GDB Server Unrecognized Command. {}", std::string(command.content_start, command.content_length));
if (!found_command) {
LOG_GDB("GDB Server Unrecognized Command. {}", std::string(command.content_start, command.content_length));
state.gdb.last_reply = "";
server_reply(state.gdb, state.gdb.last_reply.c_str());
}
a += command.content_length + 3;
} else {
+2
View File
@@ -299,6 +299,8 @@ bool ThreadState::run_loop() {
something_to_do.wait(lock);
break;
case ThreadToDo::suspend:
update_status(ThreadStatus::suspend);
something_to_do.wait(lock);
break;
}
}