Avoid accessing null target->reg_cache

GDB might request registers even if target was not successfully initialized.
This commit is contained in:
Megan Wachs 2017-05-05 09:37:26 -07:00 committed by Palmer Dabbelt
parent 325f17f6ec
commit fa8d7adf33
1 changed files with 6 additions and 0 deletions

View File

@ -414,6 +414,12 @@ static int riscv_get_gdb_reg_list(struct target *target,
if (!*reg_list) {
return ERROR_FAIL;
}
if (!target->reg_cache) {
LOG_ERROR("Target not initialized. Return ERROR_FAIL.");
return ERROR_FAIL;
}
for (int i = 0; i < *reg_list_size; i++) {
assert(target->reg_cache->reg_list[i].size > 0);
(*reg_list)[i] = &target->reg_cache->reg_list[i];