X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Friscv%2Friscv.c;h=44da5a9e6592d70cc0833c2488ce50893735a4d7;hp=7bae39034690d8408ab18510a867309a658599fb;hb=d5936dc688bedf54848a29b7c171ef47deb2bf91;hpb=bc72695f6738951571502706bd48680de5ccc84c diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 7bae390346..44da5a9e65 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -271,16 +271,8 @@ static int riscv_init_target(struct command_context *cmd_ctx, return ERROR_OK; } -static void riscv_deinit_target(struct target *target) +static void riscv_free_registers(struct target *target) { - LOG_DEBUG("riscv_deinit_target()"); - struct target_type *tt = get_target_type(target); - if (tt) { - tt->deinit_target(target); - riscv_info_t *info = (riscv_info_t *) target->arch_info; - free(info->reg_names); - free(info); - } /* Free the shared structure use for most registers. */ if (target->reg_cache) { if (target->reg_cache->reg_list) { @@ -293,6 +285,21 @@ static void riscv_deinit_target(struct target *target) } free(target->reg_cache); } +} + +static void riscv_deinit_target(struct target *target) +{ + LOG_DEBUG("riscv_deinit_target()"); + struct target_type *tt = get_target_type(target); + if (tt) { + tt->deinit_target(target); + riscv_info_t *info = (riscv_info_t *) target->arch_info; + free(info->reg_names); + free(info); + } + + riscv_free_registers(target); + target->arch_info = NULL; } @@ -1900,28 +1907,28 @@ extern __COMMAND_HANDLER(handle_common_semihosting_cmdline); */ static const struct command_registration arm_exec_command_handlers[] = { { - "semihosting", + .name = "semihosting", .handler = handle_common_semihosting_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting operations", }, { - "semihosting_cmdline", + .name = "semihosting_cmdline", .handler = handle_common_semihosting_cmdline, .mode = COMMAND_EXEC, .usage = "arguments", .help = "command line arguments to be passed to program", }, { - "semihosting_fileio", + .name = "semihosting_fileio", .handler = handle_common_semihosting_fileio_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting fileio operations", }, { - "semihosting_resexit", + .name = "semihosting_resexit", .handler = handle_common_semihosting_resumable_exit_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", @@ -2503,11 +2510,7 @@ int riscv_init_registers(struct target *target) { RISCV_INFO(info); - if (target->reg_cache) { - if (target->reg_cache->reg_list) - free(target->reg_cache->reg_list); - free(target->reg_cache); - } + riscv_free_registers(target); target->reg_cache = calloc(1, sizeof(*target->reg_cache)); target->reg_cache->name = "RISC-V Registers";