diff --git a/doc/openocd.texi b/doc/openocd.texi index a2965189f..45c2e4df5 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -5296,6 +5296,18 @@ Displays the current target state: (Also, @pxref{eventpolling,,Event Polling}.) @end deffn +@deffn {Command} {$target_name debug_reason} +Displays the current debug reason: +@code{debug-request}, +@code{breakpoint}, +@code{watchpoint}, +@code{watchpoint-and-breakpoint}, +@code{single-step}, +@code{target-not-halted}, +@code{program-exit}, +@code{exception-catch} or @code{undefined}. +@end deffn + @deffn {Command} {$target_name eventlist} Displays a table listing all event handlers currently associated with this target. diff --git a/src/target/target.c b/src/target/target.c index 61c243510..d368cb515 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5874,6 +5874,18 @@ COMMAND_HANDLER(handle_target_current_state) return ERROR_OK; } +COMMAND_HANDLER(handle_target_debug_reason) +{ + if (CMD_ARGC != 0) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct target *target = get_current_target(CMD_CTX); + + command_print(CMD, "%s", debug_reason_name(target)); + + return ERROR_OK; +} + static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { struct jim_getopt_info goi; @@ -6025,6 +6037,13 @@ static const struct command_registration target_instance_command_handlers[] = { .help = "displays the current state of this target", .usage = "", }, + { + .name = "debug_reason", + .mode = COMMAND_EXEC, + .handler = handle_target_debug_reason, + .help = "displays the debug reason of this target", + .usage = "", + }, { .name = "arp_examine", .mode = COMMAND_EXEC,