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

@@ -1370,7 +1370,7 @@ static void stm8_enable_breakpoints(struct target *target)
/* set any pending breakpoints */
while (breakpoint) {
if (breakpoint->set == 0)
if (!breakpoint->is_set)
stm8_set_breakpoint(target, breakpoint);
breakpoint = breakpoint->next;
}
@@ -1383,7 +1383,7 @@ static int stm8_set_breakpoint(struct target *target,
struct stm8_comparator *comparator_list = stm8->hw_break_list;
int retval;
if (breakpoint->set) {
if (breakpoint->is_set) {
LOG_WARNING("breakpoint already set");
return ERROR_OK;
}
@@ -1398,7 +1398,7 @@ static int stm8_set_breakpoint(struct target *target,
breakpoint->unique_id);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
breakpoint->set = bp_num + 1;
breakpoint_hw_set(breakpoint, bp_num);
comparator_list[bp_num].used = true;
comparator_list[bp_num].bp_value = breakpoint->address;
comparator_list[bp_num].type = HWBRK_EXEC;
@@ -1435,7 +1435,7 @@ static int stm8_set_breakpoint(struct target *target,
} else {
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
breakpoint->set = 1; /* Any nice value but 0 */
breakpoint->is_set = true;
}
return ERROR_OK;
@@ -1476,14 +1476,14 @@ static int stm8_unset_breakpoint(struct target *target,
struct stm8_comparator *comparator_list = stm8->hw_break_list;
int retval;
if (!breakpoint->set) {
if (!breakpoint->is_set) {
LOG_WARNING("breakpoint not set");
return ERROR_OK;
}
if (breakpoint->type == BKPT_HARD) {
int bp_num = breakpoint->set - 1;
if ((bp_num < 0) || (bp_num >= stm8->num_hw_bpoints)) {
int bp_num = breakpoint->number;
if (bp_num >= stm8->num_hw_bpoints) {
LOG_DEBUG("Invalid comparator number in breakpoint (bpid: %" PRIu32 ")",
breakpoint->unique_id);
return ERROR_OK;
@@ -1517,7 +1517,7 @@ static int stm8_unset_breakpoint(struct target *target,
} else
return ERROR_FAIL;
}
breakpoint->set = 0;
breakpoint->is_set = false;
return ERROR_OK;
}
@@ -1533,7 +1533,7 @@ static int stm8_remove_breakpoint(struct target *target,
return ERROR_TARGET_NOT_HALTED;
}
if (breakpoint->set)
if (breakpoint->is_set)
stm8_unset_breakpoint(target, breakpoint);
if (breakpoint->type == BKPT_HARD)
@@ -1550,7 +1550,7 @@ static int stm8_set_watchpoint(struct target *target,
int wp_num = 0;
int ret;
if (watchpoint->set) {
if (watchpoint->is_set) {
LOG_WARNING("watchpoint already set");
return ERROR_OK;
}
@@ -1593,7 +1593,7 @@ static int stm8_set_watchpoint(struct target *target,
return ret;
}
watchpoint->set = wp_num + 1;
watchpoint_set(watchpoint, wp_num);
LOG_DEBUG("wp_num %i bp_value 0x%" PRIx32 "",
wp_num,
@@ -1627,7 +1627,7 @@ static void stm8_enable_watchpoints(struct target *target)
/* set any pending watchpoints */
while (watchpoint) {
if (watchpoint->set == 0)
if (!watchpoint->is_set)
stm8_set_watchpoint(target, watchpoint);
watchpoint = watchpoint->next;
}
@@ -1640,18 +1640,18 @@ static int stm8_unset_watchpoint(struct target *target,
struct stm8_common *stm8 = target_to_stm8(target);
struct stm8_comparator *comparator_list = stm8->hw_break_list;
if (!watchpoint->set) {
if (!watchpoint->is_set) {
LOG_WARNING("watchpoint not set");
return ERROR_OK;
}
int wp_num = watchpoint->set - 1;
if ((wp_num < 0) || (wp_num >= stm8->num_hw_bpoints)) {
int wp_num = watchpoint->number;
if (wp_num >= stm8->num_hw_bpoints) {
LOG_DEBUG("Invalid hw comparator number in watchpoint");
return ERROR_OK;
}
comparator_list[wp_num].used = false;
watchpoint->set = 0;
watchpoint->is_set = false;
stm8_set_hwbreak(target, comparator_list);
@@ -1669,7 +1669,7 @@ static int stm8_remove_watchpoint(struct target *target,
return ERROR_TARGET_NOT_HALTED;
}
if (watchpoint->set)
if (watchpoint->is_set)
stm8_unset_watchpoint(target, watchpoint);
stm8->num_hw_bpoints_avail++;