int stub_main(int arch_reason) { int ret; int gdb_signal; gdb_signal = decode_signal(arch_reason); /* Do not announce stop reply if we were detached. */ if (isattached) { send_stop_reply(gdb_signal); } /* We are now attached. */ isattached = 1; do { int cmd; char *p; while (getpkt(&pktbuf[0], sizeof(pktbuf)) < 1); p = &pktbuf[0]; cmd = *p; if ('?' == cmd) { send_stop_reply(gdb_signal); ret = 0; } else if ('c' == cmd) { ret = handle_c(p); } else if ('s' == cmd) { ret = handle_s(p); } else if ('D' == cmd) { ret = handle_D(p); if (ret & CMD_LEAVE) { isattached = 0; } } else if ('g' == cmd) { ret = handle_g(p); } else if ('G' == cmd) { ret = handle_G(p); } else if ('P' == cmd) { ret = handle_P(p); } else if ('m' == cmd) { ret = handle_m(p); } else if ('M' == cmd) { ret = handle_M(p); } else { /* * For any command not supported by the stub, an empty * response ('$#00') should be returned. */ p = ""; ret = CMD_REPLY; } if (ret & CMD_REPLY) { putpkt(p); } } while (!(ret & CMD_LEAVE)); return ret; }
int gdbr_write_register(libgdbr_t* g, int index, char* value, int len) { char command[255] = {}; int ret = snprintf (command, 255, "%s%d=", CMD_WRITEREG, index); memcpy(command + ret, value, len); pack_hex (value, len, (command + ret)); if (send_command (g, command) < 0) return -1; if (read_packet (g) > 0) { parse_packet (g, 0); handle_P (g); } return 0; }
int gdbr_write_register(libgdbr_t *g, int index, char *value, int len) { int ret; char command[255] = { 0 }; if (!g) { return -1; } reg_cache.valid = false; ret = snprintf (command, 255, "%s%d=", CMD_WRITEREG, index); memcpy (command + ret, value, len); pack_hex (value, len, (command + ret)); if (send_msg (g, command) < 0) { return -1; } if (read_packet (g) >= 0) { handle_P (g); } return 0; }