This is an automated email from Gerrit. "Marek Vrbka <marek.vr...@codasip.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7907
-- gerrit commit cfa1f06ccf3335780eac2fe7d3a0b6f5f5ec16ef Author: Marek Vrbka <marek.vr...@codasip.com> Date: Fri Sep 22 13:57:04 2023 +0200 breakpoints: add rwp all command This patch adds the "all" option to the rwp command. It removes all watchpoints, much like rbp all removes all breakpoints. Change-Id: Id58dd103085e558f17afa4a287888cf085566ca9 Signed-off-by: Marek Vrbka <marek.vr...@codasip.com> diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index 5ce0346bb4..2f304c56b7 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -373,7 +373,52 @@ int breakpoint_remove(struct target *target, target_addr_t address) return retval; } -int breakpoint_remove_all(struct target *target) +static int watchpoint_free(struct target *target, struct watchpoint *watchpoint_to_remove) +{ + struct watchpoint *watchpoint = target->watchpoints; + struct watchpoint **watchpoint_p = &target->watchpoints; + int retval; + + while (watchpoint) { + if (watchpoint == watchpoint_to_remove) + break; + watchpoint_p = &watchpoint->next; + watchpoint = watchpoint->next; + } + + if (!watchpoint) + return ERROR_OK; + retval = target_remove_watchpoint(target, watchpoint); + if (retval != ERROR_OK) { + LOG_TARGET_ERROR(target, "could not remove watchpoint #%d on this target", + watchpoint->number); + return retval; + } + + LOG_DEBUG("free WPID: %d --> %d", watchpoint->unique_id, retval); + (*watchpoint_p) = watchpoint->next; + free(watchpoint); + + return ERROR_OK; +} + +static int watchpoint_remove_all_internal(struct target *target) +{ + struct watchpoint *watchpoint = target->watchpoints; + int retval = ERROR_OK; + + while (watchpoint) { + struct watchpoint *tmp = watchpoint; + watchpoint = watchpoint->next; + int status = watchpoint_free(target, tmp); + if (status != ERROR_OK) + retval = status; + } + + return retval; +} + +int breakpoint_watchpoint_remove_all(struct target *target, enum breakpoint_watchpoint bp_wp) { int retval = ERROR_OK; if (target->smp) { @@ -381,13 +426,25 @@ int breakpoint_remove_all(struct target *target) foreach_smp_target(head, target->smp_targets) { struct target *curr = head->target; - int status = breakpoint_remove_all_internal(curr); + + int status; + if (bp_wp == BREAKPOINT) + status = breakpoint_remove_all_internal(curr); + else if (bp_wp == WATCHPOINT) + status = watchpoint_remove_all_internal(curr); + else + assert(false && "Function called with nether breakpoint or watchpoint"); if (status != ERROR_OK) retval = status; } } else { - retval = breakpoint_remove_all_internal(target); + if (bp_wp == BREAKPOINT) + retval = breakpoint_remove_all_internal(target); + else if (bp_wp == WATCHPOINT) + retval = watchpoint_remove_all_internal(target); + else + assert(false && "Function called with nether breakpoint or watchpoint"); } return retval; @@ -530,35 +587,6 @@ int watchpoint_add(struct target *target, target_addr_t address, } } -static int watchpoint_free(struct target *target, struct watchpoint *watchpoint_to_remove) -{ - struct watchpoint *watchpoint = target->watchpoints; - struct watchpoint **watchpoint_p = &target->watchpoints; - int retval; - - while (watchpoint) { - if (watchpoint == watchpoint_to_remove) - break; - watchpoint_p = &watchpoint->next; - watchpoint = watchpoint->next; - } - - if (!watchpoint) - return ERROR_OK; - retval = target_remove_watchpoint(target, watchpoint); - if (retval != ERROR_OK) { - LOG_TARGET_ERROR(target, "could not remove watchpoint #%d on this target", - watchpoint->number); - return retval; - } - - LOG_DEBUG("free WPID: %d --> %d", watchpoint->unique_id, retval); - (*watchpoint_p) = watchpoint->next; - free(watchpoint); - - return ERROR_OK; -} - static int watchpoint_remove_internal(struct target *target, target_addr_t address) { struct watchpoint *watchpoint = target->watchpoints; diff --git a/src/target/breakpoints.h b/src/target/breakpoints.h index daa31f711c..d229abb182 100644 --- a/src/target/breakpoints.h +++ b/src/target/breakpoints.h @@ -23,6 +23,11 @@ enum watchpoint_rw { WPT_READ = 0, WPT_WRITE = 1, WPT_ACCESS = 2 }; +enum breakpoint_watchpoint { + BREAKPOINT, + WATCHPOINT, +}; + struct breakpoint { target_addr_t address; uint32_t asid; @@ -58,7 +63,7 @@ int context_breakpoint_add(struct target *target, int hybrid_breakpoint_add(struct target *target, target_addr_t address, uint32_t asid, uint32_t length, enum breakpoint_type type); int breakpoint_remove(struct target *target, target_addr_t address); -int breakpoint_remove_all(struct target *target); +int breakpoint_watchpoint_remove_all(struct target *target, enum breakpoint_watchpoint bp_wp); struct breakpoint *breakpoint_find(struct target *target, target_addr_t address); diff --git a/src/target/target.c b/src/target/target.c index 1219743750..a4db825fbe 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4042,7 +4042,7 @@ COMMAND_HANDLER(handle_rbp_command) struct target *target = get_current_target(CMD_CTX); if (!strcmp(CMD_ARGV[0], "all")) { - retval = breakpoint_remove_all(target); + retval = breakpoint_watchpoint_remove_all(target, BREAKPOINT); if (retval != ERROR_OK) { command_print(CMD, "Error encountered during removal of all breakpoints."); @@ -4136,17 +4136,28 @@ COMMAND_HANDLER(handle_wp_command) COMMAND_HANDLER(handle_rwp_command) { + int retval; + if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - target_addr_t addr; - COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); - struct target *target = get_current_target(CMD_CTX); - int retval = watchpoint_remove(target, addr); + if (!strcmp(CMD_ARGV[0], "all")) { + retval = breakpoint_watchpoint_remove_all(target, WATCHPOINT); - if (retval != ERROR_OK) - command_print(CMD, "Error during removal of watchpoint at address " TARGET_ADDR_FMT, addr); + if (retval != ERROR_OK) { + command_print(CMD, "Error encountered during removal of all watchpoints."); + command_print(CMD, "Some watchpoints may have remained set."); + } + } else { + target_addr_t addr; + COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); + + retval = watchpoint_remove(target, addr); + + if (retval != ERROR_OK) + command_print(CMD, "Error during removal of watchpoint at address " TARGET_ADDR_FMT, addr); + } return retval; } @@ -7065,7 +7076,7 @@ static const struct command_registration target_exec_command_handlers[] = { .handler = handle_rwp_command, .mode = COMMAND_EXEC, .help = "remove watchpoint", - .usage = "address", + .usage = "'all' | address", }, { .name = "load_image", --