Use gdb::checked_static_cast for watchpoints

This replaces some casts to 'watchpoint *' with checked_static_cast.
In one spot, an unnecessary block is also removed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey
2023-09-15 11:56:35 -06:00
parent 093da43d2a
commit bcafd1c19e
3 changed files with 146 additions and 153 deletions

View File

@@ -5243,13 +5243,12 @@ enum wp_check_result
static wp_check_result static wp_check_result
watchpoint_check (bpstat *bs) watchpoint_check (bpstat *bs)
{ {
struct watchpoint *b;
frame_info_ptr fr; frame_info_ptr fr;
bool within_current_scope; bool within_current_scope;
/* BS is built from an existing struct breakpoint. */ /* BS is built from an existing struct breakpoint. */
gdb_assert (bs->breakpoint_at != NULL); gdb_assert (bs->breakpoint_at != NULL);
b = (struct watchpoint *) bs->breakpoint_at; watchpoint *b = gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
/* If this is a local watchpoint, we only want to check if the /* If this is a local watchpoint, we only want to check if the
watchpoint frame is in scope if the current thread is the thread watchpoint frame is in scope if the current thread is the thread
@@ -5405,15 +5404,12 @@ static void
bpstat_check_watchpoint (bpstat *bs) bpstat_check_watchpoint (bpstat *bs)
{ {
const struct bp_location *bl; const struct bp_location *bl;
struct watchpoint *b;
/* BS is built for existing struct breakpoint. */ /* BS is built for existing struct breakpoint. */
bl = bs->bp_location_at.get (); bl = bs->bp_location_at.get ();
gdb_assert (bl != NULL); gdb_assert (bl != NULL);
b = (struct watchpoint *) bs->breakpoint_at; watchpoint *b = gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
gdb_assert (b != NULL);
{
bool must_check_value = false; bool must_check_value = false;
if (b->type == bp_watchpoint) if (b->type == bp_watchpoint)
@@ -5563,7 +5559,6 @@ bpstat_check_watchpoint (bpstat *bs)
bs->stop = false; bs->stop = false;
} }
} }
}
/* For breakpoints that are currently marked as telling gdb to stop, /* For breakpoints that are currently marked as telling gdb to stop,
check conditions (condition proper, frame, thread and ignore count) check conditions (condition proper, frame, thread and ignore count)
@@ -5625,7 +5620,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
if (is_watchpoint (b)) if (is_watchpoint (b))
{ {
struct watchpoint *w = (struct watchpoint *) b; watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
cond = w->cond_exp.get (); cond = w->cond_exp.get ();
} }
@@ -5635,7 +5630,6 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
if (cond != nullptr && b->disposition != disp_del_at_next_stop) if (cond != nullptr && b->disposition != disp_del_at_next_stop)
{ {
bool within_current_scope = true; bool within_current_scope = true;
struct watchpoint * w;
/* We use scoped_value_mark because it could be a long time /* We use scoped_value_mark because it could be a long time
before we return to the command level and call before we return to the command level and call
@@ -5643,10 +5637,9 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
might be in the middle of evaluating a function call. */ might be in the middle of evaluating a function call. */
scoped_value_mark mark; scoped_value_mark mark;
watchpoint *w = nullptr;
if (is_watchpoint (b)) if (is_watchpoint (b))
w = (struct watchpoint *) b; w = gdb::checked_static_cast<watchpoint *> (b);
else
w = NULL;
/* Need to select the frame, with all that implies so that /* Need to select the frame, with all that implies so that
the conditions will have the right context. Because we the conditions will have the right context. Because we
@@ -5794,7 +5787,8 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
iteration. */ iteration. */
if (b.type == bp_watchpoint_scope && b.related_breakpoint != &b) if (b.type == bp_watchpoint_scope && b.related_breakpoint != &b)
{ {
struct watchpoint *w = (struct watchpoint *) b.related_breakpoint; watchpoint *w
= gdb::checked_static_cast<watchpoint *> (b.related_breakpoint);
w->watchpoint_triggered = watch_triggered_yes; w->watchpoint_triggered = watch_triggered_yes;
} }
@@ -5918,7 +5912,8 @@ bpstat_stop_status (const address_space *aspace,
&& bs->breakpoint_at && bs->breakpoint_at
&& is_hardware_watchpoint (bs->breakpoint_at)) && is_hardware_watchpoint (bs->breakpoint_at))
{ {
struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; watchpoint *w
= gdb::checked_static_cast<watchpoint *> (bs->breakpoint_at);
update_watchpoint (w, false /* don't reparse. */); update_watchpoint (w, false /* don't reparse. */);
need_remove_insert = 1; need_remove_insert = 1;
@@ -6568,7 +6563,7 @@ print_one_breakpoint_location (struct breakpoint *b,
{ {
if (is_watchpoint (b)) if (is_watchpoint (b))
{ {
struct watchpoint *w = (struct watchpoint *) b; watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
/* Field 4, the address, is omitted (which makes the columns /* Field 4, the address, is omitted (which makes the columns
not line up too nicely with the headers, but the effect not line up too nicely with the headers, but the effect
@@ -6828,7 +6823,7 @@ print_one_breakpoint_location (struct breakpoint *b,
{ {
if (is_watchpoint (b)) if (is_watchpoint (b))
{ {
struct watchpoint *w = (struct watchpoint *) b; watchpoint *w = gdb::checked_static_cast<watchpoint *> (b);
uiout->field_string ("original-location", w->exp_string.get ()); uiout->field_string ("original-location", w->exp_string.get ());
} }
@@ -7257,8 +7252,8 @@ static bool
watchpoint_locations_match (const struct bp_location *loc1, watchpoint_locations_match (const struct bp_location *loc1,
const struct bp_location *loc2) const struct bp_location *loc2)
{ {
struct watchpoint *w1 = (struct watchpoint *) loc1->owner; watchpoint *w1 = gdb::checked_static_cast<watchpoint *> (loc1->owner);
struct watchpoint *w2 = (struct watchpoint *) loc2->owner; watchpoint *w2 = gdb::checked_static_cast<watchpoint *> (loc2->owner);
/* Both of them must exist. */ /* Both of them must exist. */
gdb_assert (w1 != NULL); gdb_assert (w1 != NULL);
@@ -12618,9 +12613,9 @@ delete_breakpoint (struct breakpoint *bpt)
struct watchpoint *w; struct watchpoint *w;
if (bpt->type == bp_watchpoint_scope) if (bpt->type == bp_watchpoint_scope)
w = (struct watchpoint *) bpt->related_breakpoint; w = gdb::checked_static_cast<watchpoint *> (bpt->related_breakpoint);
else if (bpt->related_breakpoint->type == bp_watchpoint_scope) else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
w = (struct watchpoint *) bpt; w = gdb::checked_static_cast<watchpoint *> (bpt);
else else
w = NULL; w = NULL;
if (w != NULL) if (w != NULL)
@@ -13784,7 +13779,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
try try
{ {
struct watchpoint *w = (struct watchpoint *) bpt; watchpoint *w = gdb::checked_static_cast<watchpoint *> (bpt);
orig_enable_state = bpt->enable_state; orig_enable_state = bpt->enable_state;
bpt->enable_state = bp_enabled; bpt->enable_state = bp_enabled;

View File

@@ -890,12 +890,11 @@ gdbscm_breakpoint_expression (SCM self)
{ {
breakpoint_smob *bp_smob breakpoint_smob *bp_smob
= bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); = bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct watchpoint *wp;
if (!is_watchpoint (bp_smob->bp)) if (!is_watchpoint (bp_smob->bp))
return SCM_BOOL_F; return SCM_BOOL_F;
wp = (struct watchpoint *) bp_smob->bp; watchpoint *wp = gdb::checked_static_cast<watchpoint *> (bp_smob->bp);
const char *str = wp->exp_string.get (); const char *str = wp->exp_string.get ();
if (! str) if (! str)

View File

@@ -549,14 +549,13 @@ bppy_get_expression (PyObject *self, void *closure)
{ {
const char *str; const char *str;
gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self; gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
struct watchpoint *wp;
BPPY_REQUIRE_VALID (obj); BPPY_REQUIRE_VALID (obj);
if (!is_watchpoint (obj->bp)) if (!is_watchpoint (obj->bp))
Py_RETURN_NONE; Py_RETURN_NONE;
wp = (struct watchpoint *) obj->bp; watchpoint *wp = gdb::checked_static_cast<watchpoint *> (obj->bp);
str = wp->exp_string.get (); str = wp->exp_string.get ();
if (! str) if (! str)