diff options
-rw-r--r-- | src/server/gdb_server.c | 37 | ||||
-rw-r--r-- | src/target/target.c | 17 |
2 files changed, 45 insertions, 9 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 4a18198..2387496 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -1163,8 +1163,15 @@ static int gdb_get_registers_packet(struct connection *connection, reg_packet_p = reg_packet; for (i = 0; i < reg_list_size; i++) { - if (!reg_list[i]->valid) - reg_list[i]->type->get(reg_list[i]); + if (!reg_list[i]->valid) { + retval = reg_list[i]->type->get(reg_list[i]); + if (retval != ERROR_OK) { + LOG_DEBUG("Couldn't get register %s.", reg_list[i]->name); + free(reg_packet); + free(reg_list); + return gdb_error(connection, retval); + } + } gdb_str_to_target(target, reg_packet_p, reg_list[i]); reg_packet_p += DIV_ROUND_UP(reg_list[i]->size, 8) * 2; } @@ -1225,7 +1232,13 @@ static int gdb_set_registers_packet(struct connection *connection, bin_buf = malloc(DIV_ROUND_UP(reg_list[i]->size, 8)); gdb_target_to_reg(target, packet_p, chars, bin_buf); - reg_list[i]->type->set(reg_list[i], bin_buf); + retval = reg_list[i]->type->set(reg_list[i], bin_buf); + if (retval != ERROR_OK) { + LOG_DEBUG("Couldn't set register %s.", reg_list[i]->name); + free(reg_list); + free(bin_buf); + return gdb_error(connection, retval); + } /* advance packet pointer */ packet_p += chars; @@ -1265,8 +1278,14 @@ static int gdb_get_register_packet(struct connection *connection, return ERROR_SERVER_REMOTE_CLOSED; } - if (!reg_list[reg_num]->valid) - reg_list[reg_num]->type->get(reg_list[reg_num]); + if (!reg_list[reg_num]->valid) { + retval = reg_list[reg_num]->type->get(reg_list[reg_num]); + if (retval != ERROR_OK) { + LOG_DEBUG("Couldn't get register %s.", reg_list[reg_num]->name); + free (reg_list); + return gdb_error(connection, retval); + } + } reg_packet = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2 + 1); /* plus one for string termination null */ @@ -1320,7 +1339,13 @@ static int gdb_set_register_packet(struct connection *connection, gdb_target_to_reg(target, separator + 1, chars, bin_buf); - reg_list[reg_num]->type->set(reg_list[reg_num], bin_buf); + retval = reg_list[reg_num]->type->set(reg_list[reg_num], bin_buf); + if (retval != ERROR_OK){ + LOG_DEBUG("Couldn't set register %s.", reg_list[reg_num]->name); + free(bin_buf); + free(reg_list); + return gdb_error(connection, retval); + } gdb_put_packet(connection, "OK", 2); diff --git a/src/target/target.c b/src/target/target.c index 82ba349..42a8cac 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2614,6 +2614,7 @@ COMMAND_HANDLER(handle_reg_command) struct reg *reg = NULL; unsigned count = 0; char *value; + int retval; LOG_DEBUG("-"); @@ -2699,8 +2700,13 @@ COMMAND_HANDLER(handle_reg_command) if ((CMD_ARGC == 2) && (strcmp(CMD_ARGV[1], "force") == 0)) reg->valid = 0; - if (reg->valid == 0) - reg->type->get(reg); + if (reg->valid == 0) { + retval = reg->type->get(reg); + if (retval != ERROR_OK) { + LOG_DEBUG("Couldn't get register %s.", reg->name); + return retval; + } + } value = buf_to_str(reg->value, reg->size, 16); command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); @@ -2714,7 +2720,12 @@ COMMAND_HANDLER(handle_reg_command) return ERROR_FAIL; str_to_buf(CMD_ARGV[1], strlen(CMD_ARGV[1]), buf, reg->size, 0); - reg->type->set(reg, buf); + retval = reg->type->set(reg, buf); + if (retval != ERROR_OK) { + LOG_DEBUG("Couldn't set register %s.", reg->name); + free (buf); + return retval; + } value = buf_to_str(reg->value, reg->size, 16); command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); |