gdb_server: support sparse register maps

Add additional error handling for targets where gaps may exist in reg_list[]

Signed-off-by: Ian Thompson <ianst@cadence.com>
Change-Id: I65232429e2de08f5d54eeca53aea0db8ce2b58af
Reviewed-on: https://review.openocd.org/c/openocd/+/7103
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Ian Thompson 2022-08-01 15:47:52 -07:00 committed by Antonio Borneo
parent e282d20832
commit d9b2607ca0
1 changed files with 6 additions and 2 deletions

View File

@ -1323,6 +1323,8 @@ static int gdb_set_registers_packet(struct connection *connection,
packet_p = packet;
for (i = 0; i < reg_list_size; i++) {
uint8_t *bin_buf;
if (!reg_list[i] || !reg_list[i]->exist || reg_list[i]->hidden)
continue;
int chars = (DIV_ROUND_UP(reg_list[i]->size, 8) * 2);
if (packet_p + chars > packet + packet_size)
@ -1375,7 +1377,8 @@ static int gdb_get_register_packet(struct connection *connection,
if (retval != ERROR_OK)
return gdb_error(connection, retval);
if (reg_list_size <= reg_num) {
if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
!reg_list[reg_num]->exist || reg_list[reg_num]->hidden) {
LOG_ERROR("gdb requested a non-existing register (reg_num=%d)", reg_num);
return ERROR_SERVER_REMOTE_CLOSED;
}
@ -1437,7 +1440,8 @@ static int gdb_set_register_packet(struct connection *connection,
return gdb_error(connection, retval);
}
if (reg_list_size <= reg_num) {
if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
!reg_list[reg_num]->exist || reg_list[reg_num]->hidden) {
LOG_ERROR("gdb requested a non-existing register (reg_num=%d)", reg_num);
free(bin_buf);
free(reg_list);