Skip to content

Commit

Permalink
target: Throw error in 'debug_reason' command
Browse files Browse the repository at this point in the history
Instead of returning an 'error string', throw an error. This makes it
much easier to handle errors in Tcl scripts or in tools that use Tcl RPC.

Change-Id: I75c48750cfad7430fa5e6bc88fe04ebd59d34cea
Signed-off-by: Marc Schink <[email protected]>
Reviewed-on: https://review.openocd.org/c/openocd/+/8006
Tested-by: jenkins
Reviewed-by: Antonio Borneo <[email protected]>
  • Loading branch information
zapb-0 authored and borneoa committed Nov 24, 2023
1 parent be5cfdc commit 1b0b07b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/target/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -5845,7 +5845,17 @@ COMMAND_HANDLER(handle_target_debug_reason)

struct target *target = get_current_target(CMD_CTX);

command_print(CMD, "%s", debug_reason_name(target));

const char *debug_reason = nvp_value2name(nvp_target_debug_reason,
target->debug_reason)->name;

if (!debug_reason) {
command_print(CMD, "bug: invalid debug reason (%d)",
target->debug_reason);
return ERROR_FAIL;
}

command_print(CMD, "%s", debug_reason);

return ERROR_OK;
}
Expand Down

0 comments on commit 1b0b07b

Please sign in to comment.