From a5634af63899454b5c7a85aae7b5c547a06f43d8 Mon Sep 17 00:00:00 2001 From: ga Date: Wed, 16 Mar 2022 15:49:39 +0000 Subject: [PATCH] Really fix handling of 'break' (testing blunder) and include a helpful message when it is executed. Also add help message response for gdb's "monitor" command. --- simavr/sim/sim_gdb.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/simavr/sim/sim_gdb.c b/simavr/sim/sim_gdb.c index b8c48b8..ec950e6 100644 --- a/simavr/sim/sim_gdb.c +++ b/simavr/sim/sim_gdb.c @@ -309,13 +309,34 @@ gdb_read_register( return strlen(rep); } +static int tohex(const char *in, char *out, unsigned int len) +{ + int n = 0; + + while (*in && n + 2 < len) + n += sprintf(out + n, "%02x", (uint8_t)*in++); + return n; +} + +/* Send a message to the user. Gdb must be expecting a reply, otherwise this + * is ignored. + */ + +static void message(avr_gdb_t * g, const char *m) +{ + char buff[256]; + + buff[0] = 'O'; + tohex(m, buff + 1, sizeof buff - 1); + gdb_send_reply(g, buff); +} -static uint8_t +static int handle_monitor(avr_t * avr, avr_gdb_t * g, char * cmd) { char *ip, *op; unsigned int c1, c2; - char dehex[64]; + char dehex[128]; if (*cmd++ != ',') return 1; // Bad format @@ -374,7 +395,10 @@ handle_monitor(avr_t * avr, avr_gdb_t * g, char * cmd) ip += strlen(ip); ) } else { - return 5; + tohex("Monitor subcommands are: ior halt reset" DBG(" say") "\n", + dehex, sizeof dehex); + gdb_send_reply(g, dehex); + return -1; } } return 0; @@ -574,12 +598,12 @@ gdb_handle_command( // all available registers. } } else if (strncmp(cmd, "Rcmd", 4) == 0) { // monitor command - uint8_t err = handle_monitor(avr, g, cmd + 4); - if (err) { + int err = handle_monitor(avr, g, cmd + 4); + if (err > 0) { snprintf(rep, sizeof rep, "E%02x", err); gdb_send_reply(g, rep); - } else { + } else if (err == 0) { gdb_send_reply(g, "OK"); } break; @@ -854,7 +878,9 @@ void avr_gdb_handle_break(avr_t *avr) { avr_gdb_t *g = avr->gdb; - gdb_send_stop_status(g, 5, "hwbreak", NULL); + message(g, "Simavr executed 'break' instruction.\n"); + //gdb_send_stop_status(g, 5, "swbreak", NULL); Correct but ignored! + gdb_send_quick_status(g, 5); } /** -- 2.39.5