diff --git a/doc/openocd.texi b/doc/openocd.texi index 66cad5eec5..f1ec1697cf 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -11835,10 +11835,6 @@ which uses TDI pin for selecting SPI flash voltage. @end itemize @end deffn -@deffn {Command} {esp gdb_detach_handler} -Handles @code{gdb-detach} event and makes necessary cleanups. Currently, this is required to remove flash breakpoints when gdb disconnects unexpectedly. -@end deffn - @anchor{softwaredebugmessagesandtracing} @section Software Debug Messages and Tracing @cindex Linux-ARM DCC support diff --git a/src/target/espressif/esp.c b/src/target/espressif/esp.c index c1014cd904..9dbc5586aa 100644 --- a/src/target/espressif/esp.c +++ b/src/target/espressif/esp.c @@ -20,6 +20,8 @@ #define ESP_FLASH_BREAKPOINTS_MAX_NUM 32 #define ESP_ASSIST_DEBUG_INVALID_VALUE 0xFFFFFFFF +static int esp_callback_event_handler(struct target *target, enum target_event event, void *priv); + struct esp_common *target_to_esp_common(struct target *target) { struct xtensa *xtensa = target->arch_info; @@ -31,7 +33,7 @@ struct esp_common *target_to_esp_common(struct target *target) return NULL; } -int esp_common_init(struct esp_common *esp, +int esp_common_init(struct target *target, struct esp_common *esp, const struct esp_flash_breakpoint_ops *flash_brps_ops, const struct esp_algorithm_hw *algo_hw) { @@ -41,6 +43,9 @@ int esp_common_init(struct esp_common *esp, if (!esp->flash_brps.brps) return ERROR_FAIL; + if (target->coreid == 0) + target_register_event_callback(esp_callback_event_handler, esp); + return ERROR_OK; } @@ -474,12 +479,9 @@ int esp_common_read_pseudo_ex_reason(struct target *target) } /* Generic commands for xtensa and riscv */ -int esp_common_gdb_detach_command(struct command_invocation *cmd) -{ - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - struct target *target = get_current_target(CMD_CTX); +int esp_common_gdb_detach_handler(struct target *target) +{ if (target->smp) { struct target_list *head; foreach_smp_target(head, target->smp_targets) { @@ -492,12 +494,8 @@ int esp_common_gdb_detach_command(struct command_invocation *cmd) return esp_common_handle_gdb_detach(target); } -int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd) +int esp_common_process_flash_breakpoints_handler(struct target *target) { - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - struct target *target = get_current_target(CMD_CTX); if (target->smp) { struct target_list *head; foreach_smp_target(head, target->smp_targets) { @@ -509,3 +507,34 @@ int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd) } return esp_common_handle_flash_breakpoints(target); } + +int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd) +{ + if (CMD_ARGC != 0) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct target *target = get_current_target(CMD_CTX); + + return esp_common_process_flash_breakpoints_handler(target); +} + +static int esp_callback_event_handler(struct target *target, enum target_event event, void *priv) +{ + switch (event) { + case TARGET_EVENT_STEP_START: + case TARGET_EVENT_RESUME_START: + case TARGET_EVENT_QXFER_THREAD_READ_END: + return esp_common_process_flash_breakpoints_handler(target); + case TARGET_EVENT_GDB_DETACH: + return esp_common_gdb_detach_handler(target); +#if IS_ESPIDF + case TARGET_EVENT_EXAMINE_FAIL: + extern int examine_failed_ui_handler(struct command_invocation *cmd); + return examine_failed_ui_handler; +#endif + default: + break; + } + + return ERROR_OK; +} diff --git a/src/target/espressif/esp.h b/src/target/espressif/esp.h index 5987685ec7..cf16701f31 100644 --- a/src/target/espressif/esp.h +++ b/src/target/espressif/esp.h @@ -138,7 +138,7 @@ struct esp_ops { }; struct esp_common *target_to_esp_common(struct target *target); -int esp_common_init(struct esp_common *esp, +int esp_common_init(struct target *target, struct esp_common *esp, const struct esp_flash_breakpoint_ops *flash_brps_ops, const struct esp_algorithm_hw *algo_hw); int esp_common_flash_breakpoint_add(struct target *target, @@ -149,11 +149,8 @@ int esp_common_flash_breakpoint_remove(struct target *target, struct breakpoint *breakpoint); bool esp_common_flash_breakpoint_exists(struct esp_common *esp, struct breakpoint *breakpoint); -int esp_common_set_flash_breakpoints(struct command_invocation *cmd); int esp_common_handle_gdb_detach(struct target *target); -int esp_common_gdb_detach_command(struct command_invocation *cmd); int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd); - int esp_dbgstubs_table_read(struct target *target, struct esp_dbg_stubs *dbg_stubs); void esp_common_assist_debug_monitor_disable(struct target *target, uint32_t address, uint32_t *value); diff --git a/src/target/espressif/esp32c2.c b/src/target/espressif/esp32c2.c index 218b0c07f8..ad9a26cd63 100644 --- a/src/target/espressif/esp32c2.c +++ b/src/target/espressif/esp32c2.c @@ -162,8 +162,7 @@ static int esp32c2_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32c2_flash_brp_ops, &esp32c2_semihost_ops); diff --git a/src/target/espressif/esp32c3.c b/src/target/espressif/esp32c3.c index 7887a3bfa3..4262da0666 100644 --- a/src/target/espressif/esp32c3.c +++ b/src/target/espressif/esp32c3.c @@ -178,8 +178,7 @@ static int esp32c3_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32c3_flash_brp_ops, &esp32c3_semihost_ops); diff --git a/src/target/espressif/esp32c5.c b/src/target/espressif/esp32c5.c index b9fc64ff99..e7b88043a1 100644 --- a/src/target/espressif/esp32c5.c +++ b/src/target/espressif/esp32c5.c @@ -81,8 +81,7 @@ static int esp32c5_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32c5_flash_brp_ops, &esp32c5_semihost_ops); diff --git a/src/target/espressif/esp32c6.c b/src/target/espressif/esp32c6.c index 263368d4b5..1b6a96e4f3 100644 --- a/src/target/espressif/esp32c6.c +++ b/src/target/espressif/esp32c6.c @@ -180,8 +180,7 @@ static int esp32c6_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32c6_flash_brp_ops, &esp32c6_semihost_ops); diff --git a/src/target/espressif/esp32h2.c b/src/target/espressif/esp32h2.c index e85f5790fc..bc326b570d 100644 --- a/src/target/espressif/esp32h2.c +++ b/src/target/espressif/esp32h2.c @@ -184,8 +184,7 @@ static int esp32h2_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32h2_flash_brp_ops, &esp32h2_semihost_ops); diff --git a/src/target/espressif/esp32p4.c b/src/target/espressif/esp32p4.c index 06c3aba133..f7ea993da7 100644 --- a/src/target/espressif/esp32p4.c +++ b/src/target/espressif/esp32p4.c @@ -227,8 +227,7 @@ static int esp32p4_init_target(struct command_context *cmd_ctx, struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target); - ret = esp_riscv_init_arch_info(cmd_ctx, - target, + ret = esp_riscv_init_arch_info(target, esp_riscv, &esp32p4_flash_brp_ops, &esp32p4_semihost_ops); diff --git a/src/target/espressif/esp_riscv.c b/src/target/espressif/esp_riscv.c index 93b744c476..24a07b5e84 100644 --- a/src/target/espressif/esp_riscv.c +++ b/src/target/espressif/esp_riscv.c @@ -24,10 +24,6 @@ #include "esp_riscv.h" #include "esp_semihosting.h" -#if IS_ESPIDF -extern int examine_failed_ui_handler(struct command_invocation *cmd); -#endif - /* Argument indexes for ESP_SEMIHOSTING_SYS_BREAKPOINT_SET */ enum { ESP_RISCV_SET_BREAKPOINT_ARG_SET, @@ -941,13 +937,6 @@ COMMAND_HANDLER(esp_riscv_halted_command) } const struct command_registration esp_riscv_command_handlers[] = { - { - .name = "gdb_detach_handler", - .handler = esp_common_gdb_detach_command, - .mode = COMMAND_ANY, - .help = "Handles gdb-detach events and makes necessary cleanups such as removing flash breakpoints", - .usage = "", - }, { .name = "process_lazy_breakpoints", .handler = esp_common_process_flash_breakpoints_command, @@ -962,13 +951,5 @@ const struct command_registration esp_riscv_command_handlers[] = { .help = "Handles halted event and prints exception reason", .usage = "", }, -#if IS_ESPIDF - { - .name = "examine_failed_handler", - .handler = examine_failed_ui_handler, - .mode = COMMAND_EXEC, - .usage = "", - }, -#endif COMMAND_REGISTRATION_DONE }; diff --git a/src/target/espressif/esp_riscv.h b/src/target/espressif/esp_riscv.h index 8fdc09bd30..bc1f2a3a17 100644 --- a/src/target/espressif/esp_riscv.h +++ b/src/target/espressif/esp_riscv.h @@ -53,7 +53,7 @@ static inline int esp_riscv_on_reset(struct target *target) return ERROR_OK; } -static inline int esp_riscv_init_arch_info(struct command_context *cmd_ctx, struct target *target, +static inline int esp_riscv_init_arch_info(struct target *target, struct esp_riscv_common *esp_riscv, const struct esp_flash_breakpoint_ops *flash_brps_ops, const struct esp_semihost_ops *semi_ops) @@ -62,7 +62,7 @@ static inline int esp_riscv_init_arch_info(struct command_context *cmd_ctx, stru INIT_LIST_HEAD(&esp_riscv->semihost.dir_map_list); - int ret = esp_common_init(&esp_riscv->esp, flash_brps_ops, &riscv_algo_hw); + int ret = esp_common_init(target, &esp_riscv->esp, flash_brps_ops, &riscv_algo_hw); if (ret != ERROR_OK) return ret; diff --git a/src/target/espressif/esp_xtensa.c b/src/target/espressif/esp_xtensa.c index efd1cac24c..3dbd25c867 100644 --- a/src/target/espressif/esp_xtensa.c +++ b/src/target/espressif/esp_xtensa.c @@ -19,10 +19,6 @@ #include "esp_xtensa_apptrace.h" #include "esp_xtensa_semihosting.h" -#if IS_ESPIDF -extern int examine_failed_ui_handler(struct command_invocation *cmd); -#endif - #define XTENSA_EXCCAUSE(reg_val) ((reg_val) & 0x3F) static const char *xtensa_get_exception_reason(struct target *target, enum esp_xtensa_exception_cause exccause_code) @@ -172,7 +168,7 @@ int esp_xtensa_init_arch_info(struct target *target, int ret = xtensa_init_arch_info(target, &esp_xtensa->xtensa, dm_cfg); if (ret != ERROR_OK) return ret; - ret = esp_common_init(&esp_xtensa->esp, esp_ops->flash_brps_ops, &xtensa_algo_hw); + ret = esp_common_init(target, &esp_xtensa->esp, esp_ops->flash_brps_ops, &xtensa_algo_hw); if (ret != ERROR_OK) return ret; @@ -389,13 +385,6 @@ int esp_xtensa_breakpoint_remove(struct target *target, struct breakpoint *break } const struct command_registration esp_command_handlers[] = { - { - .name = "gdb_detach_handler", - .handler = esp_common_gdb_detach_command, - .mode = COMMAND_ANY, - .help = "Handles gdb-detach events and makes necessary cleanups such as removing flash breakpoints", - .usage = "", - }, { .name = "process_lazy_breakpoints", .handler = esp_common_process_flash_breakpoints_command, @@ -403,13 +392,5 @@ const struct command_registration esp_command_handlers[] = { .help = "Handles resum-start and step-start events to set/clear all waiting flash breakpoints", .usage = "", }, -#if IS_ESPIDF - { - .name = "examine_failed_handler", - .handler = examine_failed_ui_handler, - .mode = COMMAND_ANY, - .usage = "", - }, -#endif COMMAND_REGISTRATION_DONE }; diff --git a/src/target/espressif/esp_xtensa_smp.c b/src/target/espressif/esp_xtensa_smp.c index c95530cf65..e9c765219e 100644 --- a/src/target/espressif/esp_xtensa_smp.c +++ b/src/target/espressif/esp_xtensa_smp.c @@ -20,10 +20,6 @@ #include "esp_xtensa_semihosting.h" #include "esp_algorithm.h" -#if IS_ESPIDF -extern int examine_failed_ui_handler(struct command_invocation *cmd); -#endif - /* Multiprocessor stuff common: @@ -1097,13 +1093,6 @@ const struct command_registration esp_xtensa_smp_xtensa_command_handlers[] = { }; const struct command_registration esp_xtensa_smp_esp_command_handlers[] = { - { - .name = "gdb_detach_handler", - .handler = esp_common_gdb_detach_command, - .mode = COMMAND_ANY, - .help = "Handles gdb-detach events and makes necessary cleanups such as removing flash breakpoints", - .usage = "", - }, { .name = "process_lazy_breakpoints", .handler = esp_common_process_flash_breakpoints_command, @@ -1111,14 +1100,6 @@ const struct command_registration esp_xtensa_smp_esp_command_handlers[] = { .help = "Handles resum-start and step-start events to set/clear all waiting flash breakpoints", .usage = "", }, -#if IS_ESPIDF - { - .name = "examine_failed_handler", - .handler = examine_failed_ui_handler, - .mode = COMMAND_ANY, - .usage = "", - }, -#endif COMMAND_REGISTRATION_DONE }; diff --git a/tcl/target/esp_common.cfg b/tcl/target/esp_common.cfg index 5fddad309f..1d97a7318e 100644 --- a/tcl/target/esp_common.cfg +++ b/tcl/target/esp_common.cfg @@ -110,23 +110,6 @@ proc create_esp_target { ARCH } { #################### Set event handlers and default settings #################### -proc configure_event_examine_fail { } { - global _ESP_IDF_HOST _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU - - if { $_ESP_IDF_HOST == 1 } { - if {$_ONLYCPU & 1} { - $_TARGETNAME_0 configure -event examine-fail { - esp examine_failed_handler - } - } - if {$_ONLYCPU & 2} { - $_TARGETNAME_1 configure -event examine-fail { - esp examine_failed_handler - } - } - } -} - proc configure_event_examine_end { } { global _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU @@ -175,22 +158,6 @@ proc configure_event_reset_assert_post { } { } } -proc configure_event_gdb_detach { } { - global _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU - - if {$_ONLYCPU & 1} { - $_TARGETNAME_0 configure -event gdb-detach { - $_TARGETNAME_0 esp gdb_detach_handler - } - } - - if {$_ONLYCPU & 2} { - $_TARGETNAME_1 configure -event gdb-detach { - $_TARGETNAME_1 esp gdb_detach_handler - } - } -} - proc configure_event_halted { } { global _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU @@ -206,32 +173,6 @@ proc configure_event_halted { } { } } -proc configure_event_process_flash_breakpoints { } { - global _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU - - $_TARGETNAME_0 configure -event resume-start { - esp process_lazy_breakpoints - } - $_TARGETNAME_0 configure -event step-start { - esp process_lazy_breakpoints - } - $_TARGETNAME_0 configure -event qxfer-thread-read-end { - esp process_lazy_breakpoints - } - - if { $_ONLYCPU != 1 } { - $_TARGETNAME_1 configure -event resume-start { - esp process_lazy_breakpoints - } - $_TARGETNAME_1 configure -event step-start { - esp process_lazy_breakpoints - } - $_TARGETNAME_1 configure -event qxfer-thread-read-end { - esp process_lazy_breakpoints - } - } -} - proc configure_event_gdb_attach { } { global _TARGETNAME_0 _TARGETNAME_1 _ONLYCPU _ESP_ARCH @@ -281,12 +222,9 @@ proc configure_openocd_events { ARCH } { configure_event_halted configure_shutdown_command } - configure_event_process_flash_breakpoints - configure_event_examine_fail configure_event_examine_end configure_event_reset_assert_post configure_event_gdb_attach - configure_event_gdb_detach } proc configure_esp_riscv_default_settings { } {