/* The locations that no longer correspond to any breakpoint, unlinked
from the bp_locations array, but for which a hit may still be
reported by a target. */
-VEC(bp_location_p) *moribund_locations = NULL;
+static std::vector<bp_location *> moribund_locations;
/* Number of last breakpoint made. */
for (c = commands; c; c = c->next)
{
- int i;
-
if (c->control_type == while_stepping_control)
error (_("The 'while-stepping' command can "
"only be used for tracepoints"));
/* Return a vector of all the static tracepoints set at ADDR. The
caller is responsible for releasing the vector. */
-VEC(breakpoint_p) *
+std::vector<breakpoint *>
static_tracepoints_here (CORE_ADDR addr)
{
struct breakpoint *b;
- VEC(breakpoint_p) *found = 0;
+ std::vector<breakpoint *> found;
struct bp_location *loc;
ALL_BREAKPOINTS (b)
{
for (loc = b->loc; loc; loc = loc->next)
if (loc->address == addr)
- VEC_safe_push(breakpoint_p, found, b);
+ found.push_back (b);
}
return found;
struct command_line *control)
{
counted_command_line cmd;
+ /* cmd_read will be true once we have read cmd. Note that cmd might still be
+ NULL after the call to read_command_lines if the user provides an empty
+ list of command by just typing "end". */
+ bool cmd_read = false;
std::string new_arg;
map_breakpoint_numbers
(arg, [&] (breakpoint *b)
{
- if (cmd == NULL)
+ if (!cmd_read)
{
+ gdb_assert (cmd == NULL);
if (control != NULL)
cmd = control->body_list_0;
else
cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
}
+ cmd_read = true;
}
/* If a breakpoint was on the list more than once, we don't need to
watchpoint_in_thread_scope (struct watchpoint *b)
{
return (b->pspace == current_program_space
- && (ptid_equal (b->watchpoint_thread, null_ptid)
- || (ptid_equal (inferior_ptid, b->watchpoint_thread)
- && !is_executing (inferior_ptid))));
+ && (b->watchpoint_thread == null_ptid
+ || (inferior_ptid == b->watchpoint_thread
+ && !inferior_thread ()->executing)));
}
/* Set watchpoint B to disp_del_at_next_stop, even including its possible
{
int pc = 0;
std::vector<value_ref_ptr> val_chain;
- struct value *v, *result, *next;
+ struct value *v, *result;
struct program_space *frame_pspace;
fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
struct thread_info *thr = find_thread_global_id (bl->owner->thread);
struct regcache *regcache;
- regcache = get_thread_regcache (thr->ptid);
+ regcache = get_thread_regcache (thr);
return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
regcache, addr);
if we aren't attached to any process yet, we should still
insert breakpoints. */
if (!gdbarch_has_global_breakpoints (target_gdbarch ())
- && ptid_equal (inferior_ptid, null_ptid))
+ && inferior_ptid == null_ptid)
continue;
val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
if we aren't attached to any process yet, we should still
insert breakpoints. */
if (!gdbarch_has_global_breakpoints (target_gdbarch ())
- && ptid_equal (inferior_ptid, null_ptid))
+ && inferior_ptid == null_ptid)
continue;
val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
}
}
-/* Remove breakpoints of process PID. */
+/* Remove breakpoints of inferior INF. */
int
-remove_breakpoints_pid (int pid)
+remove_breakpoints_inf (inferior *inf)
{
struct bp_location *bl, **blp_tmp;
int val;
- struct inferior *inf = find_inferior_pid (pid);
ALL_BP_LOCATIONS (bl, blp_tmp)
{
}
addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
- addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, target_stack);
+ addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
+ current_top_target ());
b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
&internal_breakpoint_ops);
initialize_explicit_location (&explicit_loc);
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
struct inferior *inf = current_inferior ();
- if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
+ if (ptid.pid () == inferior_ptid.pid ())
error (_("Cannot detach breakpoints of inferior_ptid"));
/* Set inferior_ptid; remove_breakpoint_1 uses this global. */
breakpoint_init_inferior (enum inf_context context)
{
struct breakpoint *b, *b_tmp;
- struct bp_location *bl;
- int ix;
struct program_space *pspace = current_program_space;
/* If breakpoint locations are shared across processes, then there's
}
/* Get rid of the moribund locations. */
- for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
+ for (bp_location *bl : moribund_locations)
decref_bp_location (&bl);
- VEC_free (bp_location_p, moribund_locations);
+ moribund_locations.clear ();
}
/* These functions concern about actual breakpoints inserted in the
int
moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
{
- struct bp_location *loc;
- int ix;
-
- for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
+ for (bp_location *loc : moribund_locations)
if (breakpoint_location_address_match (loc, aspace, pc))
return 1;
void
bpstat_clear_actions (void)
{
- struct thread_info *tp;
bpstat bs;
- if (ptid_equal (inferior_ptid, null_ptid))
- return;
-
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
return;
+ thread_info *tp = inferior_thread ();
for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
{
bs->commands = NULL;
static void
breakpoint_about_to_proceed (void)
{
- if (!ptid_equal (inferior_ptid, null_ptid))
+ if (inferior_ptid != null_ptid)
{
struct thread_info *tp = inferior_thread ();
return again;
}
+/* Helper for bpstat_do_actions. Get the current thread, if there's
+ one, is alive and has execution. Return NULL otherwise. */
+
+static thread_info *
+get_bpstat_thread ()
+{
+ if (inferior_ptid == null_ptid || !target_has_execution)
+ return NULL;
+
+ thread_info *tp = inferior_thread ();
+ if (tp->state == THREAD_EXITED || tp->executing)
+ return NULL;
+ return tp;
+}
+
void
bpstat_do_actions (void)
{
struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
+ thread_info *tp;
/* Do any commands attached to breakpoint we are stopped at. */
- while (!ptid_equal (inferior_ptid, null_ptid)
- && target_has_execution
- && !is_exited (inferior_ptid)
- && !is_executing (inferior_ptid))
- /* Since in sync mode, bpstat_do_actions may resume the inferior,
- and only return when it is stopped at the next breakpoint, we
- keep doing breakpoint actions until it returns false to
- indicate the inferior was not resumed. */
- if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
- break;
+ while ((tp = get_bpstat_thread ()) != NULL)
+ {
+ /* Since in sync mode, bpstat_do_actions may resume the
+ inferior, and only return when it is stopped at the next
+ breakpoint, we keep doing breakpoint actions until it returns
+ false to indicate the inferior was not resumed. */
+ if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
+ break;
+ }
discard_cleanups (cleanup_if_error);
}
return 0;
}
- if (!target_stopped_data_address (target_stack, &addr))
+ if (!target_stopped_data_address (current_top_target (), &addr))
{
/* We were stopped by a watchpoint, but we don't know where.
Mark all watchpoints as unknown. */
}
}
/* Exact match not required. Within range is sufficient. */
- else if (target_watchpoint_addr_within_range (target_stack,
+ else if (target_watchpoint_addr_within_range (current_top_target (),
addr, loc->address,
loc->length))
{
breakpoint, set BS->stop to 0. */
static void
-bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
+bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
{
const struct bp_location *bl;
struct breakpoint *b;
/* If this is a thread/task-specific breakpoint, don't waste cpu
evaluating the condition if this isn't the specified
thread/task. */
- if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
- || (b->task != 0 && b->task != ada_get_task_number (ptid)))
-
+ if ((b->thread != -1 && b->thread != thread->global_num)
+ || (b->task != 0 && b->task != ada_get_task_number (thread)))
{
bs->stop = 0;
return;
if (!target_supports_stopped_by_sw_breakpoint ()
|| !target_supports_stopped_by_hw_breakpoint ())
{
- bp_location *loc;
-
- for (int ix = 0;
- VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
+ for (bp_location *loc : moribund_locations)
{
if (breakpoint_location_address_match (loc, aspace, bp_addr)
&& need_moribund_for_location_type (loc))
bpstat
bpstat_stop_status (const address_space *aspace,
- CORE_ADDR bp_addr, ptid_t ptid,
+ CORE_ADDR bp_addr, thread_info *thread,
const struct target_waitstatus *ws,
bpstat stop_chain)
{
b->ops->check_status (bs);
if (bs->stop)
{
- bpstat_check_breakpoint_conditions (bs, ptid);
+ bpstat_check_breakpoint_conditions (bs, thread);
if (bs->stop)
{
{
const struct symbol *sym = loc->symbol;
- if (sym == NULL)
- sym = find_pc_sect_function (loc->address, loc->section);
-
if (sym)
{
uiout->text ("in ");
/* 1 */
annotate_field (0);
if (part_of_multiple)
- {
- char *formatted;
- formatted = xstrprintf ("%d.%d", b->number, loc_number);
- uiout->field_string ("number", formatted);
- xfree (formatted);
- }
+ uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
else
- {
- uiout->field_int ("number", b->number);
- }
+ uiout->field_int ("number", b->number);
/* 2 */
annotate_field (1);
new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
&momentary_breakpoint_ops,
1);
- new_b->thread = ptid_to_global_thread_id (inferior_ptid);
+ new_b->thread = inferior_thread ()->global_num;
/* Link NEW_B into the chain of RETVAL breakpoints. */
|| frame_find_by_id (dummy_b->frame_id) != NULL)
continue;
- dummy_frame_discard (dummy_b->frame_id, tp->ptid);
+ dummy_frame_discard (dummy_b->frame_id, tp);
while (b->related_breakpoint != b)
{
static int
insert_catch_fork (struct bp_location *bl)
{
- return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_insert_fork_catchpoint (inferior_ptid.pid ());
}
/* Implement the "remove" breakpoint_ops method for fork
static int
remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
{
- return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_remove_fork_catchpoint (inferior_ptid.pid ());
}
/* Implement the "breakpoint_hit" breakpoint_ops method for fork
}
uiout->field_int ("bkptno", b->number);
uiout->text (" (forked process ");
- uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
+ uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
uiout->text ("), ");
return PRINT_SRC_AND_LOC;
}
uiout->field_skip ("addr");
annotate_field (5);
uiout->text ("fork");
- if (!ptid_equal (c->forked_inferior_pid, null_ptid))
+ if (c->forked_inferior_pid != null_ptid)
{
uiout->text (", process ");
- uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
+ uiout->field_int ("what", c->forked_inferior_pid.pid ());
uiout->spaces (1);
}
static int
insert_catch_vfork (struct bp_location *bl)
{
- return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_insert_vfork_catchpoint (inferior_ptid.pid ());
}
/* Implement the "remove" breakpoint_ops method for vfork
static int
remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
{
- return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_remove_vfork_catchpoint (inferior_ptid.pid ());
}
/* Implement the "breakpoint_hit" breakpoint_ops method for vfork
}
uiout->field_int ("bkptno", b->number);
uiout->text (" (vforked process ");
- uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
+ uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
uiout->text ("), ");
return PRINT_SRC_AND_LOC;
}
uiout->field_skip ("addr");
annotate_field (5);
uiout->text ("vfork");
- if (!ptid_equal (c->forked_inferior_pid, null_ptid))
+ if (c->forked_inferior_pid != null_ptid)
{
uiout->text (", process ");
- uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
+ uiout->field_int ("what", c->forked_inferior_pid.pid ());
uiout->spaces (1);
}
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
struct value_print_options opts;
struct ui_out *uiout = current_uiout;
- char *msg;
get_user_print_options (&opts);
/* Field 4, the address, is omitted (which makes the columns not
uiout->field_skip ("addr");
}
+ std::string msg;
annotate_field (5);
if (self->is_load)
{
if (self->regex)
- msg = xstrprintf (_("load of library matching %s"), self->regex);
+ msg = string_printf (_("load of library matching %s"), self->regex);
else
- msg = xstrdup (_("load of library"));
+ msg = _("load of library");
}
else
{
if (self->regex)
- msg = xstrprintf (_("unload of library matching %s"), self->regex);
+ msg = string_printf (_("unload of library matching %s"), self->regex);
else
- msg = xstrdup (_("unload of library"));
+ msg = _("unload of library");
}
uiout->field_string ("what", msg);
- xfree (msg);
if (uiout->is_mi_like_p ())
uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
static int
insert_catch_exec (struct bp_location *bl)
{
- return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_insert_exec_catchpoint (inferior_ptid.pid ());
}
static int
remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
{
- return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
+ return target_remove_exec_catchpoint (inferior_ptid.pid ());
}
static int
b->disposition = disp_donttouch;
b->frame_id = frame_id;
- /* If we're debugging a multi-threaded program, then we want
- momentary breakpoints to be active in only a single thread of
- control. */
- if (in_thread_list (inferior_ptid))
- b->thread = ptid_to_global_thread_id (inferior_ptid);
+ b->thread = inferior_thread ()->global_num;
update_global_location_list_nothrow (UGLL_MAY_INSERT);
}
if (badInput)
- printf_filtered (_("Usage: stop at <line>\n"));
+ printf_filtered (_("Usage: stop at LINE\n"));
else
break_command_1 (arg, 0, from_tty);
}
old_loc->events_till_retirement = 3 * (thread_count () + 1);
old_loc->owner = NULL;
- VEC_safe_push (bp_location_p, moribund_locations, old_loc);
+ moribund_locations.push_back (old_loc);
}
else
{
void
breakpoint_retire_moribund (void)
{
- struct bp_location *loc;
- int ix;
-
- for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
- if (--(loc->events_till_retirement) == 0)
- {
- decref_bp_location (&loc);
- VEC_unordered_remove (bp_location_p, moribund_locations, ix);
- --ix;
- }
+ for (int ix = 0; ix < moribund_locations.size (); ++ix)
+ {
+ struct bp_location *loc = moribund_locations[ix];
+ if (--(loc->events_till_retirement) == 0)
+ {
+ decref_bp_location (&loc);
+ unordered_remove (moribund_locations, ix);
+ --ix;
+ }
+ }
}
static void
{
if (b->thread != -1)
{
- if (in_thread_list (inferior_ptid))
- b->thread = ptid_to_global_thread_id (inferior_ptid);
+ b->thread = inferior_thread ()->global_num;
/* We're being called after following a fork. The new fork is
selected as current, and unless this was a vfork will have a
target_disable_tracepoint (loc);
}
update_global_location_list (UGLL_DONT_INSERT);
+
+ gdb::observers::breakpoint_modified.notify (loc->owner);
}
/* Enable or disable a range of breakpoint locations. BP_NUM is the
/* Create a vector of all tracepoints. */
-VEC(breakpoint_p) *
+std::vector<breakpoint *>
all_tracepoints (void)
{
- VEC(breakpoint_p) *tp_vec = 0;
+ std::vector<breakpoint *> tp_vec;
struct breakpoint *tp;
ALL_TRACEPOINTS (tp)
{
- VEC_safe_push (breakpoint_p, tp_vec, tp);
+ tp_vec.push_back (tp);
}
return tp_vec;
static struct cmd_list_element *enablebreaklist = NULL;
+/* See breakpoint.h. */
+
+cmd_list_element *commands_cmd_element = nullptr;
+
void
_initialize_breakpoint (void)
{
Set ignore-count of breakpoint number N to COUNT.\n\
Usage is `ignore N COUNT'."));
- add_com ("commands", class_breakpoint, commands_command, _("\
+ commands_cmd_element = add_com ("commands", class_breakpoint,
+ commands_command, _("\
Set commands to be executed when the given breakpoints are hit.\n\
Give a space-separated breakpoint list as argument after \"commands\".\n\
A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\