gdb: use -1 for breakpoint::task default value

Within the breakpoint struct we have two fields ::thread and ::task
which are used for thread or task specific breakpoints.  When a
breakpoint doesn't have a specific thread or task then these fields
have the values -1 and 0 respectively.

There's no particular reason (as far as I can tell) why these two
"default" values are different, and I find the difference a little
confusing.  Long term I'd like to potentially fold these two fields
into a single field, but that isn't what this commit does.

What this commit does is switch to using -1 as the "default" value for
both fields, this means that the default for breakpoint::task has
changed from 0 to -1.   I've updated all the code I can find that
relied on the value of 0, and I see no test regressions, especially in
gdb.ada/tasks.exp, which still fully passes.

There should be no user visible changes after this commit.

Approved-By: Pedro Alves <pedro@palves.net>
This commit is contained in:
Andrew Burgess 2023-02-08 10:31:14 +00:00
parent 0a9ccb9dd7
commit 2ecee23675
4 changed files with 29 additions and 29 deletions

View file

@ -1462,7 +1462,7 @@ breakpoint_set_thread (struct breakpoint *b, int thread)
/* It is invalid to set the thread field to anything other than -1 (which /* It is invalid to set the thread field to anything other than -1 (which
means no thread restriction) if a task restriction is already in means no thread restriction) if a task restriction is already in
place. */ place. */
gdb_assert (thread == -1 || b->task == 0); gdb_assert (thread == -1 || b->task == -1);
int old_thread = b->thread; int old_thread = b->thread;
@ -1476,10 +1476,10 @@ breakpoint_set_thread (struct breakpoint *b, int thread)
void void
breakpoint_set_task (struct breakpoint *b, int task) breakpoint_set_task (struct breakpoint *b, int task)
{ {
/* It is invalid to set the task field to anything other than 0 (which /* It is invalid to set the task field to anything other than -1 (which
means no task restriction) if a thread restriction is already in means no task restriction) if a thread restriction is already in
place. */ place. */
gdb_assert (task == 0 || b->thread == -1); gdb_assert (task == -1 || b->thread == -1);
int old_task = b->task; int old_task = b->task;
@ -5473,7 +5473,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
evaluating the condition if this isn't the specified evaluating the condition if this isn't the specified
thread/task. */ thread/task. */
if ((b->thread != -1 && b->thread != thread->global_num) if ((b->thread != -1 && b->thread != thread->global_num)
|| (b->task != 0 && b->task != ada_get_task_number (thread))) || (b->task != -1 && b->task != ada_get_task_number (thread)))
{ {
infrun_debug_printf ("incorrect thread or task, not stopping"); infrun_debug_printf ("incorrect thread or task, not stopping");
bs->stop = false; bs->stop = false;
@ -6487,7 +6487,7 @@ print_one_breakpoint_location (struct breakpoint *b,
{ {
if (b->thread != -1) if (b->thread != -1)
uiout->field_signed ("thread", b->thread); uiout->field_signed ("thread", b->thread);
else if (b->task != 0) else if (b->task != -1)
uiout->field_signed ("task", b->task); uiout->field_signed ("task", b->task);
} }
@ -6544,7 +6544,7 @@ print_one_breakpoint_location (struct breakpoint *b,
uiout->text ("\n"); uiout->text ("\n");
} }
if (!part_of_multiple && b->task != 0) if (!part_of_multiple && b->task != -1)
{ {
uiout->text ("\tstop only in task "); uiout->text ("\tstop only in task ");
uiout->field_signed ("task", b->task); uiout->field_signed ("task", b->task);
@ -8452,7 +8452,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_,
gdb_assert (!sals.empty ()); gdb_assert (!sals.empty ());
/* At most one of thread or task can be set on any breakpoint. */ /* At most one of thread or task can be set on any breakpoint. */
gdb_assert (thread == -1 || task == 0); gdb_assert (thread == -1 || task == -1);
thread = thread_; thread = thread_;
task = task_; task = task_;
@ -8768,7 +8768,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
{ {
cond_string->reset (); cond_string->reset ();
*thread = -1; *thread = -1;
*task = 0; *task = -1;
rest->reset (); rest->reset ();
bool force = false; bool force = false;
@ -8821,7 +8821,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
if (*thread != -1) if (*thread != -1)
error(_("You can specify only one thread.")); error(_("You can specify only one thread."));
if (*task != 0) if (*task != -1)
error (_("You can specify only one of thread or task.")); error (_("You can specify only one of thread or task."));
tok = end_tok + 1; tok = end_tok + 1;
@ -8835,7 +8835,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
{ {
char *tmptok; char *tmptok;
if (*task != 0) if (*task != -1)
error(_("You can specify only one task.")); error(_("You can specify only one task."));
if (*thread != -1) if (*thread != -1)
@ -8876,7 +8876,7 @@ find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
{ {
gdb::unique_xmalloc_ptr<char> cond; gdb::unique_xmalloc_ptr<char> cond;
int thread_id = -1; int thread_id = -1;
int task_id = 0; int task_id = -1;
gdb::unique_xmalloc_ptr<char> remaining; gdb::unique_xmalloc_ptr<char> remaining;
/* Here we want to parse 'arg' to separate condition from thread /* Here we want to parse 'arg' to separate condition from thread
@ -8891,7 +8891,7 @@ find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
&task_id, &remaining); &task_id, &remaining);
*cond_string = std::move (cond); *cond_string = std::move (cond);
/* At most one of thread or task can be set. */ /* At most one of thread or task can be set. */
gdb_assert (thread_id == -1 || task_id == 0); gdb_assert (thread_id == -1 || task_id == -1);
*thread = thread_id; *thread = thread_id;
*task = task_id; *task = task_id;
*rest = std::move (remaining); *rest = std::move (remaining);
@ -8993,7 +8993,7 @@ create_breakpoint (struct gdbarch *gdbarch,
{ {
struct linespec_result canonical; struct linespec_result canonical;
bool pending = false; bool pending = false;
int task = 0; int task = -1;
int prev_bkpt_count = breakpoint_count; int prev_bkpt_count = breakpoint_count;
gdb_assert (ops != NULL); gdb_assert (ops != NULL);
@ -10062,7 +10062,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
the hardware watchpoint. */ the hardware watchpoint. */
bool use_mask = false; bool use_mask = false;
CORE_ADDR mask = 0; CORE_ADDR mask = 0;
int task = 0; int task = -1;
/* Make sure that we actually have parameters to parse. */ /* Make sure that we actually have parameters to parse. */
if (arg != NULL && arg[0] != '\0') if (arg != NULL && arg[0] != '\0')
@ -10109,7 +10109,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
if (thread != -1) if (thread != -1)
error(_("You can specify only one thread.")); error(_("You can specify only one thread."));
if (task != 0) if (task != -1)
error (_("You can specify only one of thread or task.")); error (_("You can specify only one of thread or task."));
/* Extract the thread ID from the next token. */ /* Extract the thread ID from the next token. */
@ -10125,7 +10125,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
{ {
char *tmp; char *tmp;
if (task != 0) if (task != -1)
error(_("You can specify only one task.")); error(_("You can specify only one task."));
if (thread != -1) if (thread != -1)
@ -10307,7 +10307,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
w.reset (new watchpoint (nullptr, bp_type)); w.reset (new watchpoint (nullptr, bp_type));
/* At most one of thread or task can be set on a watchpoint. */ /* At most one of thread or task can be set on a watchpoint. */
gdb_assert (thread == -1 || task == 0); gdb_assert (thread == -1 || task == -1);
w->thread = thread; w->thread = thread;
w->task = task; w->task = task;
w->disposition = disp_donttouch; w->disposition = disp_donttouch;
@ -14145,7 +14145,7 @@ breakpoint::print_recreate_thread (struct ui_file *fp) const
if (thread != -1) if (thread != -1)
gdb_printf (fp, " thread %d", thread); gdb_printf (fp, " thread %d", thread);
if (task != 0) if (task != -1)
gdb_printf (fp, " task %d", task); gdb_printf (fp, " task %d", task);
gdb_printf (fp, "\n"); gdb_printf (fp, "\n");

View file

@ -802,9 +802,9 @@ struct breakpoint
care. */ care. */
int thread = -1; int thread = -1;
/* Ada task number for task-specific breakpoint, or 0 if don't /* Ada task number for task-specific breakpoint, or -1 if don't
care. */ care. */
int task = 0; int task = -1;
/* Count of the number of times this breakpoint was taken, dumped /* Count of the number of times this breakpoint was taken, dumped
with the info, but not used for anything else. Useful for seeing with the info, but not used for anything else. Useful for seeing
@ -1680,9 +1680,9 @@ extern void breakpoint_set_silent (struct breakpoint *b, int silent);
extern void breakpoint_set_thread (struct breakpoint *b, int thread); extern void breakpoint_set_thread (struct breakpoint *b, int thread);
/* Set the task for this breakpoint. If TASK is 0, make the breakpoint /* Set the task for this breakpoint. If TASK is -1, make the breakpoint
work for any task. Passing a value other than 0 for TASK should only be work for any task. Passing a value other than -1 for TASK should only
done if b->thread is -1; it is not valid to try and set both a thread be done if b->thread is -1; it is not valid to try and set both a thread
and task restriction on a breakpoint. */ and task restriction on a breakpoint. */
extern void breakpoint_set_task (struct breakpoint *b, int task); extern void breakpoint_set_task (struct breakpoint *b, int task);

View file

@ -774,7 +774,7 @@ gdbscm_set_breakpoint_thread_x (SCM self, SCM newvalue)
_("invalid thread id")); _("invalid thread id"));
} }
if (bp_smob->bp->task != 0) if (bp_smob->bp->task != -1)
scm_misc_error (FUNC_NAME, scm_misc_error (FUNC_NAME,
_("cannot set both task and thread attributes"), _("cannot set both task and thread attributes"),
SCM_EOL); SCM_EOL);
@ -797,7 +797,7 @@ gdbscm_breakpoint_task (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);
if (bp_smob->bp->task == 0) if (bp_smob->bp->task == -1)
return SCM_BOOL_F; return SCM_BOOL_F;
return scm_from_long (bp_smob->bp->task); return scm_from_long (bp_smob->bp->task);
@ -840,7 +840,7 @@ gdbscm_set_breakpoint_task_x (SCM self, SCM newvalue)
SCM_EOL); SCM_EOL);
} }
else if (gdbscm_is_false (newvalue)) else if (gdbscm_is_false (newvalue))
id = 0; id = -1;
else else
SCM_ASSERT_TYPE (0, newvalue, SCM_ARG2, FUNC_NAME, _("integer or #f")); SCM_ASSERT_TYPE (0, newvalue, SCM_ARG2, FUNC_NAME, _("integer or #f"));

View file

@ -271,7 +271,7 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
return -1; return -1;
} }
if (self_bp->bp->task != 0) if (self_bp->bp->task != -1)
{ {
PyErr_SetString (PyExc_RuntimeError, PyErr_SetString (PyExc_RuntimeError,
_("Cannot set both task and thread attributes.")); _("Cannot set both task and thread attributes."));
@ -337,7 +337,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
} }
} }
else if (newvalue == Py_None) else if (newvalue == Py_None)
id = 0; id = -1;
else else
{ {
PyErr_SetString (PyExc_TypeError, PyErr_SetString (PyExc_TypeError,
@ -711,7 +711,7 @@ bppy_get_task (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp); BPPY_REQUIRE_VALID (self_bp);
if (self_bp->bp->task == 0) if (self_bp->bp->task == -1)
Py_RETURN_NONE; Py_RETURN_NONE;
return gdb_py_object_from_longest (self_bp->bp->task).release (); return gdb_py_object_from_longest (self_bp->bp->task).release ();