Remove unneeded method

This commit is contained in:
Simon Gellis 2024-10-07 22:20:41 -04:00
parent 6ea396a974
commit 64f9d10b4c
3 changed files with 12 additions and 25 deletions

View File

@ -13,17 +13,6 @@ bool cmd_match_str(CommandBuf *cmd, const char *str) {
return false; return false;
} }
bool cmd_match_only_str(CommandBuf *cmd, const char *str) {
size_t len = strlen(str);
if (cmd->len != len) return false;
if (!strncmp(cmd->buf, str, len)) {
cmd->buf += len;
cmd->len -= len;
return true;
}
return false;
}
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) { bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) {
size_t read = 0; size_t read = 0;
size_t max_len = cmd->len; size_t max_len = cmd->len;

View File

@ -12,8 +12,6 @@ typedef struct CommandBuf {
/* Try to consume a string literal. */ /* Try to consume a string literal. */
bool cmd_match_str(CommandBuf *cmd, const char *str); bool cmd_match_str(CommandBuf *cmd, const char *str);
/* Try to consume a string literal, if it is the only thing left in the buffer. */
bool cmd_match_only_str(CommandBuf *cmd, const char *str);
/* Try to consume a base-16 number, and return the value. */ /* Try to consume a base-16 number, and return the value. */
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value); bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value);
/* Try to consume a hex-encoded list of bytes, and return the value. */ /* Try to consume a hex-encoded list of bytes, and return the value. */

View File

@ -72,7 +72,7 @@ const uint32_t PC_INDEX = 32 + 13;
int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) { int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) {
rdb_response_begin_packet(res); rdb_response_begin_packet(res);
if (cmd_match_only_str(cmd, "QStartNoAckMode")) { if (cmd_match_str(cmd, "QStartNoAckMode")) {
// The debugger is asking us to no longer ACK messages. // The debugger is asking us to no longer ACK messages.
// Note that we ack THIS response, because we already called rdb_response_begin_packet. // Note that we ack THIS response, because we already called rdb_response_begin_packet.
res->should_ack = false; res->should_ack = false;
@ -84,24 +84,24 @@ int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) {
rdb_response_write_str(res, "no-resumed+;multiprocess;vContSupported;QNonStop+"); rdb_response_write_str(res, "no-resumed+;multiprocess;vContSupported;QNonStop+");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "QThreadSuffixSupported")) { if (cmd_match_str(cmd, "QThreadSuffixSupported")) {
// The debugger is asking us to include the current thread as a suffix to some responses. // The debugger is asking us to include the current thread as a suffix to some responses.
rdb_response_write_str(res, "OK"); rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "QListThreadsInStopReply")) { if (cmd_match_str(cmd, "QListThreadsInStopReply")) {
// The debugger is asking us to list all threads whenever we stop running. // The debugger is asking us to list all threads whenever we stop running.
rdb_response_write_str(res, "OK"); rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "qHostInfo")) { if (cmd_match_str(cmd, "qHostInfo")) {
// The debugger is asking us to describe the "host machine" getting debugged. // The debugger is asking us to describe the "host machine" getting debugged.
rdb_response_write_str(res, "triple:"); rdb_response_write_str(res, "triple:");
rdb_response_write_str_hex(res, "v810-unknown-vb"); rdb_response_write_str_hex(res, "v810-unknown-vb");
rdb_response_write_str(res, ";endian:little;ptrsize:4;"); rdb_response_write_str(res, ";endian:little;ptrsize:4;");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "qProcessInfo")) { if (cmd_match_str(cmd, "qProcessInfo")) {
// The debugger is asking us to describe the "process" getting debugged. // The debugger is asking us to describe the "process" getting debugged.
// We make up a process with id 1. // We make up a process with id 1.
rdb_response_write_str(res, "pid:1;triple:"); rdb_response_write_str(res, "pid:1;triple:");
@ -118,22 +118,22 @@ int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) {
} }
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "qfThreadInfo")) { if (cmd_match_str(cmd, "qfThreadInfo")) {
// The debugger is asking us to list all threads. Return a list with "thread 1". // The debugger is asking us to list all threads. Return a list with "thread 1".
rdb_response_write_str(res, "mp1.t1"); rdb_response_write_str(res, "mp1.t1");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "qsThreadInfo")) { if (cmd_match_str(cmd, "qsThreadInfo")) {
// The debugger is asking us to list all threads. // The debugger is asking us to list all threads.
rdb_response_write_str(res, "l"); rdb_response_write_str(res, "l");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "vCont?")) { if (cmd_match_str(cmd, "vCont?")) {
// The debugger is asking which vCont commands we support. // The debugger is asking which vCont commands we support.
rdb_response_write_str(res, "c;C;s;S"); rdb_response_write_str(res, "c;C;s;S");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "qC")) { if (cmd_match_str(cmd, "qC")) {
// The debugger is asking for the current thread id. Return "thread 1". // The debugger is asking for the current thread id. Return "thread 1".
rdb_response_write_str(res, "QCp1.t1"); rdb_response_write_str(res, "QCp1.t1");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
@ -188,20 +188,20 @@ int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) {
rdb_response_write_str(res, "OK"); rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "c")) { if (cmd_match_str(cmd, "c")) {
// The debugger has told us to run until we are stopped. // The debugger has told us to run until we are stopped.
// Don't send a response to this until we receive an ETX (when the debugger pauses us). // Don't send a response to this until we receive an ETX (when the debugger pauses us).
*running = true; *running = true;
return 0; return 0;
} }
if (cmd_match_only_str(cmd, "\x03")) { if (cmd_match_str(cmd, "\x03")) {
// Received an ETX, indicating that the server wants to cancel the "c" command from before. // Received an ETX, indicating that the server wants to cancel the "c" command from before.
*running = false; *running = false;
// Send the response to the "c" command from before. // Send the response to the "c" command from before.
rdb_response_write_str(res, "T05thread:p1.t1;threads:p1.t1"); rdb_response_write_str(res, "T05thread:p1.t1;threads:p1.t1");
return rdb_response_send_packet(res); return rdb_response_send_packet(res);
} }
if (cmd_match_only_str(cmd, "?")) { if (cmd_match_str(cmd, "?")) {
// The debugger has asked us why we stopped // The debugger has asked us why we stopped
rdb_response_write_str(res, "T"); rdb_response_write_str(res, "T");
rdb_response_write_str(res, *running ? "00" : "05"); rdb_response_write_str(res, *running ? "00" : "05");