Commit 6d855b1d authored by Jason Wessel's avatar Jason Wessel

gdbstub: do not directly use dbg_reg_def[] in gdb_cmd_reg_set()

Presently the usable registers definitions on x86 are not contiguous
for kgdb.  The x86 kgdb uses a case statement for the sparse register
accesses.  The array which defines the registers (dbg_reg_def) should
not be used directly in order to safely work with sparse register
definitions.

Specifically there was a problem when gdb accesses ORIG_AX, which is
accessed only through the case statement.

This patch encodes register memory using the size information provided
from the debugger which avoids the need to look up the size of the
register.  The dbg_set_reg() function always further validates the
inputs from the debugger.
Signed-off-by: default avatarJason Wessel <jason.wessel@windriver.com>
Signed-off-by: default avatarDongdong Deng <dongdong.deng@windriver.com>
parent 55751145
...@@ -604,6 +604,7 @@ static void gdb_cmd_reg_set(struct kgdb_state *ks) ...@@ -604,6 +604,7 @@ static void gdb_cmd_reg_set(struct kgdb_state *ks)
{ {
unsigned long regnum; unsigned long regnum;
char *ptr = &remcom_in_buffer[1]; char *ptr = &remcom_in_buffer[1];
int i = 0;
kgdb_hex2long(&ptr, &regnum); kgdb_hex2long(&ptr, &regnum);
if (*ptr++ != '=' || if (*ptr++ != '=' ||
...@@ -612,7 +613,14 @@ static void gdb_cmd_reg_set(struct kgdb_state *ks) ...@@ -612,7 +613,14 @@ static void gdb_cmd_reg_set(struct kgdb_state *ks)
error_packet(remcom_out_buffer, -EINVAL); error_packet(remcom_out_buffer, -EINVAL);
return; return;
} }
kgdb_hex2mem(ptr, (char *)gdb_regs, dbg_reg_def[regnum].size); memset(gdb_regs, 0, sizeof(gdb_regs));
while (i < sizeof(gdb_regs) * 2)
if (hex_to_bin(ptr[i]) >= 0)
i++;
else
break;
i = i / 2;
kgdb_hex2mem(ptr, (char *)gdb_regs, i);
dbg_set_reg(regnum, gdb_regs, ks->linux_regs); dbg_set_reg(regnum, gdb_regs, ks->linux_regs);
strcpy(remcom_out_buffer, "OK"); strcpy(remcom_out_buffer, "OK");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment