Skip to content

Commit

Permalink
Merge pull request #527 from galexander1/rdwr_error
Browse files Browse the repository at this point in the history
return error condition if st-util's read/write memory commands fail
  • Loading branch information
texane authored Dec 11, 2016
2 parents 8efa16b + 0879af2 commit e010030
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,10 @@ int serve(stlink_t *sl, st_state_t *st) {
if (count_rnd < count)
count = count_rnd;

stlink_read_mem32(sl, start - adj_start, count_rnd);
if (stlink_read_mem32(sl, start - adj_start, count_rnd) != 0) {
/* read failed somehow, don't return stale buffer */
count = 0;
}

reply = calloc(count * 2 + 1, 1);
for(unsigned int i = 0; i < count; i++) {
Expand All @@ -1527,6 +1530,7 @@ int serve(stlink_t *sl, st_state_t *st) {

stm32_addr_t start = (stm32_addr_t) strtoul(s_start, NULL, 16);
unsigned count = (unsigned) strtoul(s_count, NULL, 16);
int err = 0;

if(start % 4) {
unsigned align_count = 4 - start % 4;
Expand All @@ -1536,7 +1540,7 @@ int serve(stlink_t *sl, st_state_t *st) {
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem8(sl, start, align_count);
err |= stlink_write_mem8(sl, start, align_count);
cache_change(start, align_count);
start += align_count;
count -= align_count;
Expand All @@ -1551,7 +1555,7 @@ int serve(stlink_t *sl, st_state_t *st) {
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem32(sl, start, aligned_count);
err |= stlink_write_mem32(sl, start, aligned_count);
cache_change(start, aligned_count);
count -= aligned_count;
start += aligned_count;
Expand All @@ -1564,10 +1568,10 @@ int serve(stlink_t *sl, st_state_t *st) {
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem8(sl, start, count);
err |= stlink_write_mem8(sl, start, count);
cache_change(start, count);
}
reply = strdup("OK");
reply = strdup(err ? "E00" : "OK");
break;
}

Expand Down

0 comments on commit e010030

Please sign in to comment.