target: Rework 'set' variable of break-/watchpoints

The 'set' variable name suggests a boolean data type which determines
whether a breakpoint (or watchpoint) is active. However, it is also
used to store the number of the breakpoint.

This encoding leads to inconsistent value assignments: boolean and
integer values are mixed. Also, associated hardware comparator
numbers, which are usually numbered from 0, cannot be used directly.
An additional offset is required to store the comparator numbers.

In order to make the code more readable and the value assignment more
consistent, change the variable name to 'is_set', its data type to 'bool'
and introduce a dedicated variable for the break-/watchpoint
number.

In order to make the review easier, the data types of various related
variables (e.g. number of breakpoints) are not changed.

While at it, fix a few coding style issues.

Change-Id: I2193f5639247cce6b80580d4c1c6afee916aeb82
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/6319
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Marc Schink
2021-06-13 11:21:18 +02:00
committed by Antonio Borneo
parent ab43721be6
commit fb43f1ff4e
21 changed files with 258 additions and 242 deletions

View File

@@ -1090,7 +1090,7 @@ void cortex_m_enable_breakpoints(struct target *target)
/* set any pending breakpoints */
while (breakpoint) {
if (!breakpoint->set)
if (!breakpoint->is_set)
cortex_m_set_breakpoint(target, breakpoint);
breakpoint = breakpoint->next;
}
@@ -1578,7 +1578,7 @@ int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint
struct cortex_m_common *cortex_m = target_to_cm(target);
struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list;
if (breakpoint->set) {
if (breakpoint->is_set) {
LOG_TARGET_WARNING(target, "breakpoint (BPID: %" PRIu32 ") already set", breakpoint->unique_id);
return ERROR_OK;
}
@@ -1591,7 +1591,7 @@ int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint
LOG_TARGET_ERROR(target, "Can not find free FPB Comparator!");
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
breakpoint->set = fp_num + 1;
breakpoint_hw_set(breakpoint, fp_num);
fpcr_value = breakpoint->address | 1;
if (cortex_m->fp_rev == 0) {
if (breakpoint->address > 0x1FFFFFFF) {
@@ -1643,15 +1643,15 @@ int cortex_m_set_breakpoint(struct target *target, struct breakpoint *breakpoint
code);
if (retval != ERROR_OK)
return retval;
breakpoint->set = true;
breakpoint->is_set = true;
}
LOG_TARGET_DEBUG(target, "BPID: %" PRIu32 ", Type: %d, Address: " TARGET_ADDR_FMT " Length: %d (set=%d)",
LOG_TARGET_DEBUG(target, "BPID: %" PRIu32 ", Type: %d, Address: " TARGET_ADDR_FMT " Length: %d (n=%u)",
breakpoint->unique_id,
(int)(breakpoint->type),
breakpoint->address,
breakpoint->length,
breakpoint->set);
(breakpoint->type == BKPT_SOFT) ? 0 : breakpoint->number);
return ERROR_OK;
}
@@ -1662,20 +1662,20 @@ int cortex_m_unset_breakpoint(struct target *target, struct breakpoint *breakpoi
struct cortex_m_common *cortex_m = target_to_cm(target);
struct cortex_m_fp_comparator *comparator_list = cortex_m->fp_comparator_list;
if (breakpoint->set <= 0) {
if (!breakpoint->is_set) {
LOG_TARGET_WARNING(target, "breakpoint not set");
return ERROR_OK;
}
LOG_TARGET_DEBUG(target, "BPID: %" PRIu32 ", Type: %d, Address: " TARGET_ADDR_FMT " Length: %d (set=%d)",
LOG_TARGET_DEBUG(target, "BPID: %" PRIu32 ", Type: %d, Address: " TARGET_ADDR_FMT " Length: %d (n=%u)",
breakpoint->unique_id,
(int)(breakpoint->type),
breakpoint->address,
breakpoint->length,
breakpoint->set);
(breakpoint->type == BKPT_SOFT) ? 0 : breakpoint->number);
if (breakpoint->type == BKPT_HARD) {
unsigned int fp_num = breakpoint->set - 1;
unsigned int fp_num = breakpoint->number;
if (fp_num >= cortex_m->fp_num_code) {
LOG_TARGET_DEBUG(target, "Invalid FP Comparator number in breakpoint");
return ERROR_OK;
@@ -1692,7 +1692,7 @@ int cortex_m_unset_breakpoint(struct target *target, struct breakpoint *breakpoi
if (retval != ERROR_OK)
return retval;
}
breakpoint->set = false;
breakpoint->is_set = false;
return ERROR_OK;
}
@@ -1714,7 +1714,7 @@ int cortex_m_add_breakpoint(struct target *target, struct breakpoint *breakpoint
int cortex_m_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
{
if (!breakpoint->set)
if (!breakpoint->is_set)
return ERROR_OK;
return cortex_m_unset_breakpoint(target, breakpoint);
@@ -1741,7 +1741,7 @@ static int cortex_m_set_watchpoint(struct target *target, struct watchpoint *wat
return ERROR_FAIL;
}
comparator->used = true;
watchpoint->set = dwt_num + 1;
watchpoint_set(watchpoint, dwt_num);
comparator->comp = watchpoint->address;
target_write_u32(target, comparator->dwt_comparator_address + 0,
@@ -1808,15 +1808,15 @@ static int cortex_m_unset_watchpoint(struct target *target, struct watchpoint *w
struct cortex_m_common *cortex_m = target_to_cm(target);
struct cortex_m_dwt_comparator *comparator;
if (watchpoint->set <= 0) {
if (!watchpoint->is_set) {
LOG_TARGET_WARNING(target, "watchpoint (wpid: %d) not set",
watchpoint->unique_id);
return ERROR_OK;
}
unsigned int dwt_num = watchpoint->set - 1;
unsigned int dwt_num = watchpoint->number;
LOG_TARGET_DEBUG(target, "Watchpoint (ID %d) DWT%d address: 0x%08x clear",
LOG_TARGET_DEBUG(target, "Watchpoint (ID %d) DWT%u address: 0x%08x clear",
watchpoint->unique_id, dwt_num,
(unsigned) watchpoint->address);
@@ -1831,7 +1831,7 @@ static int cortex_m_unset_watchpoint(struct target *target, struct watchpoint *w
target_write_u32(target, comparator->dwt_comparator_address + 8,
comparator->function);
watchpoint->set = false;
watchpoint->is_set = false;
return ERROR_OK;
}
@@ -1895,7 +1895,7 @@ int cortex_m_remove_watchpoint(struct target *target, struct watchpoint *watchpo
return ERROR_TARGET_NOT_HALTED;
}
if (watchpoint->set)
if (watchpoint->is_set)
cortex_m_unset_watchpoint(target, watchpoint);
cortex_m->dwt_comp_available++;
@@ -1912,10 +1912,10 @@ int cortex_m_hit_watchpoint(struct target *target, struct watchpoint **hit_watch
struct cortex_m_common *cortex_m = target_to_cm(target);
for (struct watchpoint *wp = target->watchpoints; wp; wp = wp->next) {
if (!wp->set)
if (!wp->is_set)
continue;
unsigned int dwt_num = wp->set - 1;
unsigned int dwt_num = wp->number;
struct cortex_m_dwt_comparator *comparator = cortex_m->dwt_comparator_list + dwt_num;
uint32_t dwt_function;
@@ -1939,7 +1939,7 @@ void cortex_m_enable_watchpoints(struct target *target)
/* set any pending watchpoints */
while (watchpoint) {
if (!watchpoint->set)
if (!watchpoint->is_set)
cortex_m_set_watchpoint(target, watchpoint);
watchpoint = watchpoint->next;
}