gdb: fix parsing of register values.

This commit is contained in:
Daniel Beer 2019-10-22 11:35:00 +13:00
parent eb77903392
commit fb29ec1236
1 changed files with 17 additions and 9 deletions

View File

@ -129,18 +129,26 @@ static int monitor_command(struct gdb_data *data, char *buf)
static int write_registers(struct gdb_data *data, char *buf) static int write_registers(struct gdb_data *data, char *buf)
{ {
address_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
int i; int nibbles = 4;
size_t len = strlen(buf);
if (strlen(buf) < DEVICE_NUM_REGS * 4) if (len >= DEVICE_NUM_REGS * 8)
nibbles = 8;
if (len < DEVICE_NUM_REGS * nibbles) {
printc_err("write_registers: short argument\n");
return gdb_send(data, "E00"); return gdb_send(data, "E00");
}
printc("Writing registers\n"); printc("Writing registers (%d bits each)\n", nibbles * 4);
for (i = 0; i < DEVICE_NUM_REGS; i++) { for (int i = 0; i < DEVICE_NUM_REGS; i++) {
regs[i] = (hexval(buf[2]) << 12) | uint32_t r = 0;
(hexval(buf[3]) << 8) |
(hexval(buf[0]) << 4) | for (int j = 0; j < nibbles; j++)
hexval(buf[1]); r = (r << 4) |
buf += 4; hexval(buf[i * nibbles +
nibbles - 1 - (j ^ 1)]);
regs[i] = r;
} }
if (device_setregs(regs) < 0) if (device_setregs(regs) < 0)