Use the set/reg register error return code when registers don't exist.

This commit is contained in:
Megan Wachs 2017-02-05 21:06:43 -08:00
parent 9bab0782d3
commit 2ae0078fc7
2 changed files with 45 additions and 9 deletions

View File

@ -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.");
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.");
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.");
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.");
free(bin_buf);
free(reg_list);
return gdb_error(connection, retval);
}
gdb_put_packet(connection, "OK", 2);

View File

@ -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.");
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.");
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);