Skip to content

Commit

Permalink
Only propagate register errors on some targets
Browse files Browse the repository at this point in the history
Without this change, connecting to ARM targets is impossible.

Fixes #115.

Change-Id: Ie33c7e15ac1bed8c9cbd8e6a78de92d5498c5999
  • Loading branch information
timsifive committed Mar 1, 2018
1 parent 0c8235d commit 1d9418f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/server/gdb_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ static int gdb_get_registers_packet(struct connection *connection,
for (i = 0; i < reg_list_size; i++) {
if (!reg_list[i]->valid) {
retval = reg_list[i]->type->get(reg_list[i]);
if (retval != ERROR_OK) {
if (retval != ERROR_OK && target->propagate_register_errors) {
LOG_DEBUG("Couldn't get register %s.", reg_list[i]->name);
free(reg_packet);
free(reg_list);
Expand Down Expand Up @@ -1242,7 +1242,7 @@ static int gdb_set_registers_packet(struct connection *connection,
gdb_target_to_reg(target, packet_p, chars, bin_buf);

retval = reg_list[i]->type->set(reg_list[i], bin_buf);
if (retval != ERROR_OK) {
if (retval != ERROR_OK && target->propagate_register_errors) {
LOG_DEBUG("Couldn't set register %s.", reg_list[i]->name);
free(reg_list);
free(bin_buf);
Expand Down Expand Up @@ -1289,7 +1289,7 @@ static int gdb_get_register_packet(struct connection *connection,

if (!reg_list[reg_num]->valid) {
retval = reg_list[reg_num]->type->get(reg_list[reg_num]);
if (retval != ERROR_OK) {
if (retval != ERROR_OK && target->propagate_register_errors) {
LOG_DEBUG("Couldn't get register %s.", reg_list[reg_num]->name);
free(reg_list);
return gdb_error(connection, retval);
Expand Down Expand Up @@ -1349,7 +1349,7 @@ static int gdb_set_register_packet(struct connection *connection,
gdb_target_to_reg(target, separator + 1, chars, bin_buf);

retval = reg_list[reg_num]->type->set(reg_list[reg_num], bin_buf);
if (retval != ERROR_OK) {
if (retval != ERROR_OK && target->propagate_register_errors) {
LOG_DEBUG("Couldn't set register %s.", reg_list[reg_num]->name);
free(bin_buf);
free(reg_list);
Expand Down
1 change: 1 addition & 0 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static int riscv_init_target(struct command_context *cmd_ctx,
struct target *target)
{
LOG_DEBUG("riscv_init_target()");
target->propagate_register_errors = true;
target->arch_info = calloc(1, sizeof(riscv_info_t));
if (!target->arch_info)
return ERROR_FAIL;
Expand Down
8 changes: 8 additions & 0 deletions src/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ struct target {

/* file-I/O information for host to do syscall */
struct gdb_fileio_info *fileio_info;

/**
* When true, send gdb an error result when reading/writing a register
* fails. This must be false for some ARM targets (Cortex-M3), where a 'g'
* packet results in an attempt to read 'r0', which fails, which causes gdb
* to close the connection.
*/
bool propagate_register_errors;
};

struct target_list {
Expand Down

0 comments on commit 1d9418f

Please sign in to comment.