Match guy naming convention

This commit is contained in:
Simon Gellis 2024-10-10 18:38:40 -04:00
parent 884b52b397
commit 26ecf29a3f
11 changed files with 156 additions and 156 deletions

View File

@ -2,7 +2,7 @@
#include <hex.h>
#include <string.h>
bool cmd_match_str(CommandBuf *cmd, const char *str) {
bool cmdMatchStr(CommandBuf *cmd, const char *str) {
size_t len = strlen(str);
if (cmd->len < len) return false;
if (!strncmp(cmd->buf, str, len)) {
@ -13,7 +13,7 @@ bool cmd_match_str(CommandBuf *cmd, const char *str) {
return false;
}
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) {
bool cmdMatchHexNumber(CommandBuf *cmd, uint32_t *value) {
size_t read = 0;
size_t max_len = cmd->len;
if (max_len > 8) max_len = 8;
@ -21,7 +21,7 @@ bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) {
*value = 0;
for (; read < max_len; ++read) {
char digit;
if (!parse_hex_digit(cmd->buf[read], &digit)) break;
if (!parseHexDigit(cmd->buf[read], &digit)) break;
*value = (*value << 4) | digit;
}
if (!read) return false;
@ -31,13 +31,13 @@ bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) {
return true;
}
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, uint8_t *value) {
bool cmdMatchHexBytes(CommandBuf *cmd, const uint32_t count, uint8_t *value) {
size_t i;
if (cmd->len < (count * 2)) return false;
for (i = 0; i < count; ++i) {
char hi, lo;
if (!parse_hex_digit(cmd->buf[i * 2], &hi)) return false;
if (!parse_hex_digit(cmd->buf[(i * 2) + 1], &lo)) return false;
if (!parseHexDigit(cmd->buf[i * 2], &hi)) return false;
if (!parseHexDigit(cmd->buf[(i * 2) + 1], &lo)) return false;
value[i] = (hi << 4) | lo;
}
cmd->buf += (count * 2);

2
hex.c
View File

@ -1,6 +1,6 @@
#include <hex.h>
bool parse_hex_digit(char digit, char *out) {
bool parseHexDigit(char digit, char *out) {
if (digit >= '0' && digit <= '9') {
*out = digit - '0';
return true;

View File

@ -11,10 +11,10 @@ typedef struct CommandBuf {
} CommandBuf;
/* Try to consume a string literal. */
bool cmd_match_str(CommandBuf *cmd, const char *str);
bool cmdMatchStr(CommandBuf *cmd, const char *str);
/* Try to consume a base-16 number, and return the value. */
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value);
bool cmdMatchHexNumber(CommandBuf *cmd, uint32_t *value);
/* Try to consume a hex-encoded list of bytes, and return the value. */
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, uint8_t *value);
bool cmdMatchHexBytes(CommandBuf *cmd, const uint32_t count, uint8_t *value);
#endif

View File

@ -3,6 +3,6 @@
#include <stdbool.h>
bool parse_hex_digit(char digit, char *out);
bool parseHexDigit(char digit, char *out);
#endif

View File

@ -35,9 +35,9 @@ typedef struct RdbRequest {
char chk;
} RdbRequest;
void rdb_request_init(RdbRequest *req, int connfd, char *buf, size_t buflen);
void rdb_request_reset(RdbRequest *req);
void rdb_request_set_blocking(RdbRequest *req, bool blocking);
rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd);
void rdbRequestInit(RdbRequest *req, int connfd, char *buf, size_t buflen);
void rdbRequestReset(RdbRequest *req);
void rdbRequestSetBlocking(RdbRequest *req, bool blocking);
rdb_read_result_t rdbRequestRead(RdbRequest *req, CommandBuf *cmd);
#endif

View File

@ -15,12 +15,12 @@ typedef struct RdbResponse {
bool should_ack;
} RdbResponse;
void rdb_response_init(RdbResponse *self, int connfd, char *buf, size_t buflen);
void rdb_response_begin_packet(RdbResponse *self);
bool rdb_response_write_str(RdbResponse *self, const char *str);
bool rdb_response_write_str_hex(RdbResponse *self, const char *str);
bool rdb_response_write_i8_hex(RdbResponse *self, uint8_t value);
bool rdb_response_write_i32_hex(RdbResponse *self, uint32_t value);
int rdb_response_send_packet(RdbResponse *self);
void rdbResponseInit(RdbResponse *self, int connfd, char *buf, size_t buflen);
void rdbResponseBeginPacket(RdbResponse *self);
bool rdbResponseWriteStr(RdbResponse *self, const char *str);
bool rdbResponseWriteStrHex(RdbResponse *self, const char *str);
bool rdbResponseWriteI8Hex(RdbResponse *self, uint8_t value);
bool rdbResponseWriteI32Hex(RdbResponse *self, uint32_t value);
int rdbResponseSendPacket(RdbResponse *self);
#endif

View File

@ -11,8 +11,8 @@ typedef struct RdbServer {
bool running;
} RdbServer;
void rdb_server_init(RdbServer *srv, VB *sim);
int rdb_server_handle_command(RdbServer *srv, CommandBuf *cmd, RdbResponse *res);
int rdb_server_break(RdbServer *srv, RdbResponse *res);
void rdbServerInit(RdbServer *srv, VB *sim);
int rdbServerHandleCommand(RdbServer *srv, CommandBuf *cmd, RdbResponse *res);
int rdbServerBreak(RdbServer *srv, RdbResponse *res);
#endif

20
main.c
View File

@ -13,7 +13,7 @@
#define BUFLEN 8096
#define MAX_STEP_CYCLES 20000
int sleep_nanos(long int ns) {
int sleepNanos(long int ns) {
struct timespec time;
time.tv_sec = ns / 1000000000;
time.tv_nsec = ns % 1000000000;
@ -29,15 +29,15 @@ int server(int connfd, VB *sim) {
rdb_read_result_t read_result;
int result;
rdb_request_init(&req, connfd, reqbuf, BUFLEN);
rdb_response_init(&res, connfd, resbuf, BUFLEN);
rdb_server_init(&srv, sim);
rdbRequestInit(&req, connfd, reqbuf, BUFLEN);
rdbResponseInit(&res, connfd, resbuf, BUFLEN);
rdbServerInit(&srv, sim);
while (1) {
CommandBuf cmd;
int brk;
uint32_t cycles;
read_result = rdb_request_read(&req, &cmd);
read_result = rdbRequestRead(&req, &cmd);
if (read_result == read_result_error) {
return -1;
} else if (read_result == read_result_disconnected) {
@ -51,25 +51,25 @@ int server(int connfd, VB *sim) {
/* We hit a breakpoint */
if (brk == -1) {
/* actually, not implemented */
rdb_server_break(&srv, &res);
rdbServerBreak(&srv, &res);
} else {
fprintf(stderr, "surprising response %d from vbEmulate\n", brk);
return -1;
}
} else {
sleep_nanos((MAX_STEP_CYCLES - cycles) * 50);
sleepNanos((MAX_STEP_CYCLES - cycles) * 50);
}
}
continue;
} else {
printf("received command \"%.*s\"\n", (int) cmd.len, cmd.buf);
fflush(stdout);
result = rdb_server_handle_command(&srv, &cmd, &res);
result = rdbServerHandleCommand(&srv, &cmd, &res);
if (result != 0) {
return result;
}
rdb_request_set_blocking(&req, !srv.running);
rdb_request_reset(&req);
rdbRequestSetBlocking(&req, !srv.running);
rdbRequestReset(&req);
}
}

View File

@ -5,25 +5,25 @@
#include <sys/socket.h>
#include <unistd.h>
void rdb_request_init(RdbRequest *req, int connfd, char *buf, size_t buflen) {
void rdbRequestInit(RdbRequest *req, int connfd, char *buf, size_t buflen) {
req->connfd = connfd;
req->outbuf = buf;
req->blocking = true;
rdb_request_reset(req);
rdbRequestReset(req);
}
void rdb_request_reset(RdbRequest *req) {
void rdbRequestReset(RdbRequest *req) {
req->state = read_state_header;
req->inbuf.len = 0;
req->inbuf.index = 0;
req->chk = 0;
}
void rdb_request_set_blocking(RdbRequest *req, bool blocking) {
void rdbRequestSetBlocking(RdbRequest *req, bool blocking) {
req->blocking = blocking;
}
static rdb_read_result_t read_char(RdbRequest *req, char *in) {
static rdb_read_result_t readChar(RdbRequest *req, char *in) {
if (req->inbuf.index >= req->inbuf.len) {
int flags = req->blocking ? 0 : MSG_DONTWAIT;
ssize_t inlen = recv(req->connfd, req->inbuf.buf, INBUF_LEN, flags);
@ -45,7 +45,7 @@ static rdb_read_result_t read_char(RdbRequest *req, char *in) {
return read_result_success;
}
rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd) {
rdb_read_result_t rdbRequestRead(RdbRequest *req, CommandBuf *cmd) {
rdb_read_result_t res;
char in, hi, lo;
@ -56,7 +56,7 @@ rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd) {
/* read any acknowledgements and continue */
do {
res = read_char(req, &in);
res = readChar(req, &in);
if (res != read_result_success) return res;
} while (in == '+');
@ -83,7 +83,7 @@ rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd) {
case read_state_body:
case read_state_body_escape:
while (1) {
res = read_char(req, &in);
res = readChar(req, &in);
if (res != read_result_success) return res;
if (req->state == read_state_body && in == '#') {
@ -115,11 +115,11 @@ rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd) {
req->state = read_state_checksum_1;
__attribute__ ((fallthrough));
case read_state_checksum_1:
res = read_char(req, &in);
res = readChar(req, &in);
if (res != read_result_success) return res;
/* check the high digit of the checksum */
if (!parse_hex_digit(in, &hi)) {
if (!parseHexDigit(in, &hi)) {
fprintf(stderr, "invalid checksum1\n");
return read_result_error;
}
@ -130,11 +130,11 @@ rdb_read_result_t rdb_request_read(RdbRequest *req, CommandBuf *cmd) {
req->state = read_state_checksum_2;
__attribute__ ((fallthrough));
case read_state_checksum_2:
res = read_char(req, &in);
res = readChar(req, &in);
if (res != read_result_success) return res;
/* check the high digit of the checksum */
if (!parse_hex_digit(in, &lo)) {
if (!parseHexDigit(in, &lo)) {
fprintf(stderr, "invalid checksum3 %c\n", in);
return read_result_error;
}

View File

@ -4,7 +4,7 @@
#include <string.h>
#include <unistd.h>
static bool write_char(RdbResponse *res, char out) {
static bool writeChar(RdbResponse *res, char out) {
if (res->len >= res->buflen) {
return false;
}
@ -21,7 +21,7 @@ static bool write_char(RdbResponse *res, char out) {
return true;
}
bool char_to_hex_digit(char in, char *out) {
bool charToHexDigit(char in, char *out) {
if (in & 0xf0) {
return false;
}
@ -34,12 +34,12 @@ bool char_to_hex_digit(char in, char *out) {
return true;
}
bool char_to_hex_digits(char in, char *hi, char *lo) {
return char_to_hex_digit((in & 0xf0) >> 4, hi)
&& char_to_hex_digit(in & 0x0f, lo);
bool charToHexDigits(char in, char *hi, char *lo) {
return charToHexDigit((in & 0xf0) >> 4, hi)
&& charToHexDigit(in & 0x0f, lo);
}
void rdb_response_init(RdbResponse *res, int connfd, char *buf, size_t buflen) {
void rdbResponseInit(RdbResponse *res, int connfd, char *buf, size_t buflen) {
res->connfd = connfd;
res->buf = buf;
res->buflen = buflen;
@ -48,7 +48,7 @@ void rdb_response_init(RdbResponse *res, int connfd, char *buf, size_t buflen) {
res->should_ack = true;
}
void rdb_response_begin_packet(RdbResponse *res) {
void rdbResponseBeginPacket(RdbResponse *res) {
res->len = 0;
res->chk = 0;
if (res->should_ack) {
@ -57,44 +57,44 @@ void rdb_response_begin_packet(RdbResponse *res) {
res->buf[res->len++] = '$';
}
bool rdb_response_write_str(RdbResponse *res, const char *str) {
bool rdbResponseWriteStr(RdbResponse *res, const char *str) {
size_t i, len = strlen(str);
for (i = 0; i < len; ++i) {
if (!write_char(res, str[i])) {
if (!writeChar(res, str[i])) {
return false;
}
}
return true;
}
bool rdb_response_write_str_hex(RdbResponse *res, const char *str) {
bool rdbResponseWriteStrHex(RdbResponse *res, const char *str) {
size_t i, len = strlen(str);
for (i = 0; i < len; ++i) {
char hi, lo;
if (!char_to_hex_digits(str[i], &hi, &lo)
|| !write_char(res, hi)
|| !write_char(res, lo)) {
if (!charToHexDigits(str[i], &hi, &lo)
|| !writeChar(res, hi)
|| !writeChar(res, lo)) {
return false;
}
}
return true;
}
bool rdb_response_write_i8_hex(RdbResponse *res, uint8_t value) {
bool rdbResponseWriteI8Hex(RdbResponse *res, uint8_t value) {
char hi, lo;
return char_to_hex_digits(value, &hi, &lo)
&& write_char(res, hi)
&& write_char(res, lo);
return charToHexDigits(value, &hi, &lo)
&& writeChar(res, hi)
&& writeChar(res, lo);
}
bool rdb_response_write_i32_hex(RdbResponse *res, uint32_t value) {
return rdb_response_write_i8_hex(res, (uint8_t) value)
&& rdb_response_write_i8_hex(res, (uint8_t) (value >> 8))
&& rdb_response_write_i8_hex(res, (uint8_t) (value >> 16))
&& rdb_response_write_i8_hex(res, (uint8_t) (value >> 24));
bool rdbResponseWriteI32Hex(RdbResponse *res, uint32_t value) {
return rdbResponseWriteI8Hex(res, (uint8_t) value)
&& rdbResponseWriteI8Hex(res, (uint8_t) (value >> 8))
&& rdbResponseWriteI8Hex(res, (uint8_t) (value >> 16))
&& rdbResponseWriteI8Hex(res, (uint8_t) (value >> 24));
}
int rdb_response_send_packet(RdbResponse *res) {
int rdbResponseSendPacket(RdbResponse *res) {
char hi, lo;
ssize_t rwrite;
@ -102,7 +102,7 @@ int rdb_response_send_packet(RdbResponse *res) {
return -1;
}
res->buf[res->len++] = '#';
if (!char_to_hex_digits(res->chk, &hi, &lo)) {
if (!charToHexDigits(res->chk, &hi, &lo)) {
return -1;
}
res->buf[res->len++] = hi;

170
server.c
View File

@ -69,88 +69,88 @@ const uint32_t SYSTEM_REGISTERS[] = {
const uint32_t PC_INDEX = 32 + 13;
void rdb_server_init(RdbServer *srv, VB *sim) {
void rdbServerInit(RdbServer *srv, VB *sim) {
srv->sim = sim;
srv->running = false;
}
int rdb_server_handle_command(RdbServer *srv, CommandBuf *cmd, RdbResponse *res) {
rdb_response_begin_packet(res);
int rdbServerHandleCommand(RdbServer *srv, CommandBuf *cmd, RdbResponse *res) {
rdbResponseBeginPacket(res);
if (cmd_match_str(cmd, "QStartNoAckMode")) {
if (cmdMatchStr(cmd, "QStartNoAckMode")) {
/* 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 rdbResponseBeginPacket. */
res->should_ack = false;
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qSupported")) {
if (cmdMatchStr(cmd, "qSupported")) {
/* The debugger is asking for a list of features we support. */
rdb_response_write_str(res, "no-resumed+;multiprocess;vContSupported;QNonStop+");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "no-resumed+;multiprocess;vContSupported;QNonStop+");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "QThreadSuffixSupported")) {
if (cmdMatchStr(cmd, "QThreadSuffixSupported")) {
/* The debugger is asking us to include the current thread as a suffix to some responses. */
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "QListThreadsInStopReply")) {
if (cmdMatchStr(cmd, "QListThreadsInStopReply")) {
/* The debugger is asking us to list all threads whenever we stop running. */
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qHostInfo")) {
if (cmdMatchStr(cmd, "qHostInfo")) {
/* The debugger is asking us to describe the "host machine" getting debugged. */
rdb_response_write_str(res, "triple:");
rdb_response_write_str_hex(res, "v810-unknown-vb");
rdb_response_write_str(res, ";endian:little;ptrsize:4;");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "triple:");
rdbResponseWriteStrHex(res, "v810-unknown-vb");
rdbResponseWriteStr(res, ";endian:little;ptrsize:4;");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qProcessInfo")) {
if (cmdMatchStr(cmd, "qProcessInfo")) {
/* The debugger is asking us to describe the "process" getting debugged. */
/* We make up a process with id 1. */
rdb_response_write_str(res, "pid:1;triple:");
rdb_response_write_str_hex(res, "v810-unknown-vb");
rdb_response_write_str(res, "endian:little;ptrsize:4;");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "pid:1;triple:");
rdbResponseWriteStrHex(res, "v810-unknown-vb");
rdbResponseWriteStr(res, "endian:little;ptrsize:4;");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qRegisterInfo")) {
if (cmdMatchStr(cmd, "qRegisterInfo")) {
uint32_t reg_no;
/* The debugger is asking for information about a specific register. */
if (!cmd_match_hex_number(cmd, &reg_no)) return 1;
if (!cmdMatchHexNumber(cmd, &reg_no)) return 1;
if (reg_no <= PC_INDEX) {
rdb_response_write_str(res, REGISTERS[reg_no]);
rdbResponseWriteStr(res, REGISTERS[reg_no]);
}
return rdb_response_send_packet(res);
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qfThreadInfo")) {
if (cmdMatchStr(cmd, "qfThreadInfo")) {
/* The debugger is asking us to list all threads. Return a list with "thread 1". */
rdb_response_write_str(res, "mp1.t1");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "mp1.t1");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qsThreadInfo")) {
if (cmdMatchStr(cmd, "qsThreadInfo")) {
/* The debugger is asking us to list all threads. */
rdb_response_write_str(res, "l");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "l");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "vCont?")) {
if (cmdMatchStr(cmd, "vCont?")) {
/* The debugger is asking which vCont commands we support. */
rdb_response_write_str(res, "c;C;s;S");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "c;C;s;S");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "qC")) {
if (cmdMatchStr(cmd, "qC")) {
/* The debugger is asking for the current thread id. Return "thread 1". */
rdb_response_write_str(res, "QCp1.t1");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "QCp1.t1");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "p")) {
if (cmdMatchStr(cmd, "p")) {
uint32_t reg_no, reg_value;
/* read a register. */
if (!cmd_match_hex_number(cmd, &reg_no)) return 1;
if (!cmdMatchHexNumber(cmd, &reg_no)) return 1;
if (reg_no > PC_INDEX) {
return rdb_response_send_packet(res);
return rdbResponseSendPacket(res);
}
if (reg_no == PC_INDEX) {
@ -160,17 +160,17 @@ int rdb_server_handle_command(RdbServer *srv, CommandBuf *cmd, RdbResponse *res)
} else {
reg_value = vbGetProgramRegister(srv->sim, reg_no);
}
rdb_response_write_i32_hex(res, reg_value);
return rdb_response_send_packet(res);
rdbResponseWriteI32Hex(res, reg_value);
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "P")) {
if (cmdMatchStr(cmd, "P")) {
uint32_t reg_no, reg_value;
uint8_t reg_bytes[4];
/* write a register. */
if (!cmd_match_hex_number(cmd, &reg_no)) return -1;
if (!cmd_match_str(cmd, "=")) return -1;
if (!cmd_match_hex_bytes(cmd, 4, reg_bytes)) return -1;
if (!cmdMatchHexNumber(cmd, &reg_no)) return -1;
if (!cmdMatchStr(cmd, "=")) return -1;
if (!cmdMatchHexBytes(cmd, 4, reg_bytes)) return -1;
reg_value = ((uint32_t) (reg_bytes[3]) << 24) |
((uint32_t) (reg_bytes[2]) << 16) |
@ -178,7 +178,7 @@ int rdb_server_handle_command(RdbServer *srv, CommandBuf *cmd, RdbResponse *res)
((uint32_t) reg_bytes[0]);
if (reg_no > PC_INDEX) {
return rdb_response_send_packet(res);
return rdbResponseSendPacket(res);
}
if (reg_no == PC_INDEX) {
vbSetProgramCounter(srv->sim, reg_value);
@ -187,71 +187,71 @@ int rdb_server_handle_command(RdbServer *srv, CommandBuf *cmd, RdbResponse *res)
} else {
vbSetProgramRegister(srv->sim, reg_no, reg_value);
}
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "Hc-1")) {
if (cmdMatchStr(cmd, "Hc-1")) {
/* Set the "current thread" for future commands to all threads (thread -1). */
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "c")) {
if (cmdMatchStr(cmd, "c")) {
/* 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). */
srv->running = true;
return 0;
}
if (cmd_match_str(cmd, "\x03")) {
if (cmdMatchStr(cmd, "\x03")) {
/* Received an ETX, indicating that the server wants to cancel the "c" command from before. */
srv->running = false;
/* Send the response to the "c" command from before. */
rdb_response_write_str(res, "T05thread:p1.t1;threads:p1.t1");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "T05thread:p1.t1;threads:p1.t1");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "?")) {
if (cmdMatchStr(cmd, "?")) {
/* The debugger has asked us why we stopped */
rdb_response_write_str(res, "T");
rdb_response_write_str(res, srv->running ? "00" : "05");
rdb_response_write_str(res, "thread:p1.t1;threads:p1.t1;");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "T");
rdbResponseWriteStr(res, srv->running ? "00" : "05");
rdbResponseWriteStr(res, "thread:p1.t1;threads:p1.t1;");
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "m")) {
if (cmdMatchStr(cmd, "m")) {
/* read memory */
uint32_t i, address, len;
if (!cmd_match_hex_number(cmd, &address)) return -1;
if (!cmd_match_str(cmd, ",")) return -1;
if (!cmd_match_hex_number(cmd, &len)) return -1;
if (!cmdMatchHexNumber(cmd, &address)) return -1;
if (!cmdMatchStr(cmd, ",")) return -1;
if (!cmdMatchHexNumber(cmd, &len)) return -1;
for (i = 0; i < len; ++i) {
uint8_t byte = vbRead(srv->sim, address + i, VB_U8);
rdb_response_write_i8_hex(res, byte);
rdbResponseWriteI8Hex(res, byte);
}
return rdb_response_send_packet(res);
return rdbResponseSendPacket(res);
}
if (cmd_match_str(cmd, "M")) {
if (cmdMatchStr(cmd, "M")) {
/* write memory */
uint32_t i, address, len;
if (!cmd_match_hex_number(cmd, &address)) return -1;
if (!cmd_match_str(cmd, ",")) return -1;
if (!cmd_match_hex_number(cmd, &len)) return -1;
if (!cmd_match_str(cmd, ":")) return -1;
if (!cmdMatchHexNumber(cmd, &address)) return -1;
if (!cmdMatchStr(cmd, ",")) return -1;
if (!cmdMatchHexNumber(cmd, &len)) return -1;
if (!cmdMatchStr(cmd, ":")) return -1;
for (i = 0; i < len; ++i) {
uint8_t byte;
if (!cmd_match_hex_bytes(cmd, 1, &byte)) return -1;
if (!cmdMatchHexBytes(cmd, 1, &byte)) return -1;
vbWrite(srv->sim, address + i, VB_U8, byte);
}
rdb_response_write_str(res, "OK");
return rdb_response_send_packet(res);
rdbResponseWriteStr(res, "OK");
return rdbResponseSendPacket(res);
}
fprintf(stderr, "Unrecognized command.\n");
return rdb_response_send_packet(res);
return rdbResponseSendPacket(res);
}
int rdb_server_break(RdbServer *srv, RdbResponse *res) {
int rdbServerBreak(RdbServer *srv, RdbResponse *res) {
srv->running = false;
rdb_response_begin_packet(res);
rdb_response_write_str(res, "T05:thread:p1.t1;threads:p1.t1;");
return rdb_response_send_packet(res);
rdbResponseBeginPacket(res);
rdbResponseWriteStr(res, "T05:thread:p1.t1;threads:p1.t1;");
return rdbResponseSendPacket(res);
}