/* Everything about breakpoints, for GDB.
- Copyright (C) 1986-2015 Free Software Foundation, Inc.
+ Copyright (C) 1986-2016 Free Software Foundation, Inc.
This file is part of GDB.
#include "interps.h"
#include "format.h"
#include "location.h"
+#include "thread-fsm.h"
+#include "tid-parse.h"
/* readline include files */
#include "readline/readline.h"
struct address_space *aspace,
CORE_ADDR addr);
+static int breakpoint_location_address_range_overlap (struct bp_location *,
+ struct address_space *,
+ CORE_ADDR, int);
+
static void breakpoints_info (char *, int);
static void watchpoints_info (char *, int);
static struct counted_command_line *
alloc_counted_command_line (struct command_line *commands)
{
- struct counted_command_line *result
- = xmalloc (sizeof (struct counted_command_line));
+ struct counted_command_line *result = XNEW (struct counted_command_line);
result->refc = 1;
result->commands = commands;
+
return result;
}
static void
do_cleanup_counted_command_line (void *arg)
{
- decref_counted_command_line (arg);
+ decref_counted_command_line ((struct counted_command_line **) arg);
}
/* Create a cleanup that calls decref_counted_command_line on the
static int
bp_location_compare_addrs (const void *ap, const void *bp)
{
- struct bp_location *a = *(void **) ap;
- struct bp_location *b = *(void **) bp;
+ const struct bp_location *a = *(const struct bp_location **) ap;
+ const struct bp_location *b = *(const struct bp_location **) bp;
if (a->address == b->address)
return 0;
dummy_loc.address = address;
/* Find a close match to the first location at ADDRESS. */
- locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
- sizeof (struct bp_location **),
- bp_location_compare_addrs);
+ locp_found = ((struct bp_location **)
+ bsearch (&dummy_locp, bp_location, bp_location_count,
+ sizeof (struct bp_location **),
+ bp_location_compare_addrs));
/* Nothing was found, nothing left to do. */
if (locp_found == NULL)
void
check_tracepoint_command (char *line, void *closure)
{
- struct breakpoint *b = closure;
+ struct breakpoint *b = (struct breakpoint *) closure;
validate_actionline (line, b);
}
static void
do_map_commands_command (struct breakpoint *b, void *data)
{
- struct commands_info *info = data;
+ struct commands_info *info = (struct commands_info *) data;
if (info->cmd == NULL)
{
return bit_val;
}
+/* Allocate a dummy location and add it to B, which must be a software
+ watchpoint. This is required because even if a software watchpoint
+ is not watching any memory, bpstat_stop_status requires a location
+ to be able to report stops. */
+
+static void
+software_watchpoint_add_no_memory_location (struct breakpoint *b,
+ struct program_space *pspace)
+{
+ gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
+
+ b->loc = allocate_bp_location (b);
+ b->loc->pspace = pspace;
+ b->loc->address = -1;
+ b->loc->length = -1;
+}
+
+/* Returns true if B is a software watchpoint that is not watching any
+ memory (e.g., "watch $pc"). */
+
+static int
+is_no_memory_software_watchpoint (struct breakpoint *b)
+{
+ return (b->type == bp_watchpoint
+ && b->loc != NULL
+ && b->loc->next == NULL
+ && b->loc->address == -1
+ && b->loc->length == -1);
+}
+
/* Assuming that B is a watchpoint:
- Reparse watchpoint expression, if REPARSE is non-zero
- Evaluate expression and store the result in B->val
bpstat_stop_status requires a location to be able to report
stops, so make sure there's at least a dummy one. */
if (b->base.type == bp_watchpoint && b->base.loc == NULL)
- {
- struct breakpoint *base = &b->base;
- base->loc = allocate_bp_location (base);
- base->loc->pspace = frame_pspace;
- base->loc->address = -1;
- base->loc->length = -1;
- base->loc->watchpoint_type = -1;
- }
+ software_watchpoint_add_no_memory_location (&b->base, frame_pspace);
}
else if (!within_current_scope)
{
the thread no longer exists. ALL_BP_LOCATIONS bp_location
has BL->OWNER always non-NULL. */
if (bl->owner->thread != -1
- && !valid_thread_id (bl->owner->thread))
+ && !valid_global_thread_id (bl->owner->thread))
continue;
switch_to_program_space_and_thread (bl->pspace);
ALL_BREAKPOINTS_SAFE (b, b_tmp)
{
- if (b->thread == tp->num && user_breakpoint_p (b))
+ if (b->thread == tp->global_num && user_breakpoint_p (b))
{
b->disposition = disp_del_at_next_stop;
printf_filtered (_("\
-Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
- b->number, tp->num);
+Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
+ b->number, print_thread_id (tp));
/* Hide it from the user. */
b->number = 0;
{
struct breakpoint_objfile_data *bp_objfile_data;
- bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
+ bp_objfile_data = ((struct breakpoint_objfile_data *)
+ objfile_data (objfile, breakpoint_objfile_key));
if (bp_objfile_data == NULL)
{
- bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
- sizeof (*bp_objfile_data));
+ bp_objfile_data =
+ XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
static void
free_breakpoint_probes (struct objfile *obj, void *data)
{
- struct breakpoint_objfile_data *bp_objfile_data = data;
+ struct breakpoint_objfile_data *bp_objfile_data
+ = (struct breakpoint_objfile_data *) data;
VEC_free (probe_p, bp_objfile_data->longjmp_probes);
VEC_free (probe_p, bp_objfile_data->exception_probes);
struct breakpoint *b;
struct breakpoint_objfile_data *bp_objfile_data;
CORE_ADDR addr;
- char *p;
+ struct explicit_location explicit_loc;
bp_objfile_data = get_breakpoint_objfile_data (objfile);
b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
bp_overlay_event,
&internal_breakpoint_ops);
- p = ASTRDUP (func_name);
- b->location = new_linespec_location (&p);
+ initialize_explicit_location (&explicit_loc);
+ explicit_loc.function_name = ASTRDUP (func_name);
+ b->location = new_explicit_location (&explicit_loc);
if (overlay_debugging == ovly_auto)
{
struct breakpoint *b;
const char *func_name;
CORE_ADDR addr;
- char *p;
+ struct explicit_location explicit_loc;
if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
continue;
addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
&internal_breakpoint_ops);
- p = ASTRDUP (func_name);
- b->location = new_linespec_location (&p);
+ initialize_explicit_location (&explicit_loc);
+ explicit_loc.function_name = ASTRDUP (func_name);
+ b->location = new_explicit_location (&explicit_loc);
b->enable_state = bp_disabled;
}
}
{
struct breakpoint *b;
struct breakpoint_objfile_data *bp_objfile_data;
- char *p;
+ struct explicit_location explicit_loc;
bp_objfile_data = get_breakpoint_objfile_data (objfile);
b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
bp_std_terminate_master,
&internal_breakpoint_ops);
- p = ASTRDUP (func_name);
- b->location = new_linespec_location (&p);
+ initialize_explicit_location (&explicit_loc);
+ explicit_loc.function_name = ASTRDUP (func_name);
+ b->location = new_explicit_location (&explicit_loc);
b->enable_state = bp_disabled;
}
}
struct gdbarch *gdbarch;
struct breakpoint_objfile_data *bp_objfile_data;
CORE_ADDR addr;
- char *p;
+ struct explicit_location explicit_loc;
bp_objfile_data = get_breakpoint_objfile_data (objfile);
¤t_target);
b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
&internal_breakpoint_ops);
- p = ASTRDUP (func_name);
- b->location = new_linespec_location (&p);
+ initialize_explicit_location (&explicit_loc);
+ explicit_loc.function_name = ASTRDUP (func_name);
+ b->location = new_explicit_location (&explicit_loc);
b->enable_state = bp_disabled;
}
return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
}
+/* See breakpoint.h. */
+
+int
+breakpoint_in_range_p (struct address_space *aspace,
+ CORE_ADDR addr, ULONGEST len)
+{
+ struct bp_location *bl, **blp_tmp;
+
+ ALL_BP_LOCATIONS (bl, blp_tmp)
+ {
+ if (bl->loc_type != bp_loc_software_breakpoint
+ && bl->loc_type != bp_loc_hardware_breakpoint)
+ continue;
+
+ if ((breakpoint_enabled (bl->owner)
+ || bl->permanent)
+ && breakpoint_location_address_range_overlap (bl, aspace,
+ addr, len))
+ {
+ if (overlay_debugging
+ && section_is_overlay (bl->section)
+ && !section_is_mapped (bl->section))
+ {
+ /* Unmapped overlay -- can't be a match. */
+ continue;
+ }
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/* Return true if there's a moribund breakpoint at PC. */
int
if (breakpoint_proceeded)
{
- if (interpreter_async && target_can_async_p ())
+ if (interpreter_async)
/* If we are in async mode, then the target might be still
running, not stopped at any breakpoint, so nothing for
us to do here -- just return to the event loop. */
}
}
+/* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
+ debugging multiple threads. */
+
+void
+maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
+{
+ if (ui_out_is_mi_like_p (uiout))
+ return;
+
+ ui_out_text (uiout, "\n");
+
+ if (show_thread_that_caused_stop ())
+ {
+ const char *name;
+ struct thread_info *thr = inferior_thread ();
+
+ ui_out_text (uiout, "Thread ");
+ ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr));
+
+ name = thr->name != NULL ? thr->name : target_thread_name (thr);
+ if (name != NULL)
+ {
+ ui_out_text (uiout, " \"");
+ ui_out_field_fmt (uiout, "name", "%s", name);
+ ui_out_text (uiout, "\"");
+ }
+
+ ui_out_text (uiout, " hit ");
+ }
+}
+
/* Generic routine for printing messages indicating why we
stopped. The behavior of this function depends on the value
'print_it' in the bpstat structure. Under some circumstances we
/* 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 != pid_to_thread_id (ptid))
+ if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
|| (b->task != 0 && b->task != ada_get_task_number (ptid)))
{
struct frame_info *frame;
struct gdbarch *gdbarch;
+ if (debug_infrun)
+ fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
+
/* Switch terminal for any messages produced by
breakpoint_re_set. */
target_terminal_ours_for_output ();
retval.main_action = max (retval.main_action, this_action);
}
- /* These operations may affect the bs->breakpoint_at state so they are
- delayed after MAIN_ACTION is decided above. */
-
- if (jit_event)
- {
- if (debug_infrun)
- fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
+ return retval;
+}
- handle_jit_event ();
- }
+void
+bpstat_run_callbacks (bpstat bs_head)
+{
+ bpstat bs;
for (bs = bs_head; bs != NULL; bs = bs->next)
{
continue;
switch (b->type)
{
+ case bp_jit_event:
+ handle_jit_event ();
+ break;
case bp_gnu_ifunc_resolver:
gnu_ifunc_resolver_stop (b);
break;
break;
}
}
-
- return retval;
}
/* Nonzero if we should step constantly (e.g. watchpoints on machines
{
/* FIXME should make an annotation for this. */
ui_out_text (uiout, "\tstop only in thread ");
- ui_out_field_int (uiout, "thread", b->thread);
+ if (ui_out_is_mi_like_p (uiout))
+ ui_out_field_int (uiout, "thread", b->thread);
+ else
+ {
+ struct thread_info *thr = find_thread_global_id (b->thread);
+
+ ui_out_field_string (uiout, "thread", print_thread_id (thr));
+ }
ui_out_text (uiout, "\n");
}
int print_address_bits = 0;
struct bp_location *loc;
+ /* Software watchpoints that aren't watching memory don't have an
+ address to print. */
+ if (is_no_memory_software_watchpoint (b))
+ return 0;
+
for (loc = b->loc; loc; loc = loc->next)
{
int addr_bit;
- /* Software watchpoints that aren't watching memory don't have
- an address to print. */
- if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
- continue;
-
addr_bit = gdbarch_addr_bit (loc->gdbarch);
if (addr_bit > print_address_bits)
print_address_bits = addr_bit;
static int
do_captured_breakpoint_query (struct ui_out *uiout, void *data)
{
- struct captured_breakpoint_query_args *args = data;
+ struct captured_breakpoint_query_args *args
+ = (struct captured_breakpoint_query_args *) data;
struct breakpoint *b;
struct bp_location *dummy_loc = NULL;
\f
/* Return true iff it is meaningful to use the address member of
- BPT. For some breakpoint types, the address member is irrelevant
- and it makes no sense to attempt to compare it to other addresses
- (or use it for any other purpose either).
+ BPT locations. For some breakpoint types, the locations' address members
+ are irrelevant and it makes no sense to attempt to compare them to other
+ addresses (or use them for any other purpose either).
More specifically, each of the following breakpoint types will
- always have a zero valued address and we don't want to mark
+ always have a zero valued location address and we don't want to mark
breakpoints of any of these types to be a duplicate of an actual
- breakpoint at address zero:
+ breakpoint location at address zero:
bp_watchpoint
bp_catchpoint
aspace, addr)));
}
+/* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
+ breakpoint BL. BL may be a ranged breakpoint. In most targets, a
+ match happens only if ASPACE matches the breakpoint's address
+ space. On targets that have global breakpoints, the address space
+ doesn't really matter. */
+
+static int
+breakpoint_location_address_range_overlap (struct bp_location *bl,
+ struct address_space *aspace,
+ CORE_ADDR addr, int len)
+{
+ if (gdbarch_has_global_breakpoints (target_gdbarch ())
+ || bl->pspace->aspace == aspace)
+ {
+ int bl_len = bl->length != 0 ? bl->length : 1;
+
+ if (mem_ranges_overlap (addr, len, bl->address, bl_len))
+ return 1;
+ }
+ return 0;
+}
+
/* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
Then, if LOC1 and LOC2 represent the same tracepoint location, returns
true, otherwise returns false. */
set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
{
struct breakpoint *b, *b_tmp;
- int thread = tp->num;
+ int thread = tp->global_num;
/* To avoid having to rescan all objfile symbols at every step,
we maintain a list of continually-inserted but always disabled
new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
&momentary_breakpoint_ops,
1);
- new_b->thread = pid_to_thread_id (inferior_ptid);
+ new_b->thread = ptid_to_global_thread_id (inferior_ptid);
/* Link NEW_B into the chain of RETVAL breakpoints. */
struct breakpoint *b, *b_tmp;
ALL_BREAKPOINTS_SAFE (b, b_tmp)
- if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
+ if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
{
struct breakpoint *dummy_b = b->related_breakpoint;
return b;
}
-void
-remove_thread_event_breakpoints (void)
-{
- struct breakpoint *b, *b_tmp;
-
- ALL_BREAKPOINTS_SAFE (b, b_tmp)
- if (b->type == bp_thread_event
- && b->loc->pspace == current_program_space)
- delete_breakpoint (b);
-}
-
struct lang_and_radix
{
enum language lang;
struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
annotate_catchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
if (b->disposition == disp_del)
- ui_out_text (uiout, "\nTemporary catchpoint ");
+ ui_out_text (uiout, "Temporary catchpoint ");
else
- ui_out_text (uiout, "\nCatchpoint ");
+ ui_out_text (uiout, "Catchpoint ");
if (ui_out_is_mi_like_p (uiout))
{
ui_out_field_string (uiout, "reason",
struct fork_catchpoint *c = (struct fork_catchpoint *) b;
annotate_catchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
if (b->disposition == disp_del)
- ui_out_text (uiout, "\nTemporary catchpoint ");
+ ui_out_text (uiout, "Temporary catchpoint ");
else
- ui_out_text (uiout, "\nCatchpoint ");
+ ui_out_text (uiout, "Catchpoint ");
if (ui_out_is_mi_like_p (uiout))
{
ui_out_field_string (uiout, "reason",
struct ui_out *uiout = current_uiout;
annotate_catchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
if (b->disposition == disp_del)
- ui_out_text (uiout, "\nTemporary catchpoint ");
+ ui_out_text (uiout, "Temporary catchpoint ");
else
- ui_out_text (uiout, "\nCatchpoint ");
+ ui_out_text (uiout, "Catchpoint ");
ui_out_field_int (uiout, "bkptno", b->number);
ui_out_text (uiout, "\n");
if (ui_out_is_mi_like_p (uiout))
struct exec_catchpoint *c = (struct exec_catchpoint *) b;
annotate_catchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
if (b->disposition == disp_del)
- ui_out_text (uiout, "\nTemporary catchpoint ");
+ ui_out_text (uiout, "Temporary catchpoint ");
else
- ui_out_text (uiout, "\nCatchpoint ");
+ ui_out_text (uiout, "Catchpoint ");
if (ui_out_is_mi_like_p (uiout))
{
ui_out_field_string (uiout, "reason",
momentary breakpoints to be active in only a single thread of
control. */
if (in_thread_list (inferior_ptid))
- b->thread = pid_to_thread_id (inferior_ptid);
+ b->thread = ptid_to_global_thread_id (inferior_ptid);
update_global_location_list_nothrow (UGLL_MAY_INSERT);
if (bpoint == NULL)
return 0;
- target_mem = alloca (len);
+ target_mem = (gdb_byte *) alloca (len);
/* Enable the automatic memory restoration from breakpoints while
we read the memory. Otherwise we could say about our temporary
gdb_assert (loc != NULL);
+ /* If we have a catchpoint or a watchpoint, just return 0. We should not
+ attempt to read from the addresses the locations of these breakpoint types
+ point to. program_breakpoint_here_p, below, will attempt to read
+ memory. */
+ if (!breakpoint_address_is_meaningful (loc->owner))
+ return 0;
+
cleanup = save_current_space_and_thread ();
switch_to_program_space_and_thread (loc->pspace);
gdb_assert (printf_line != NULL);
/* Manufacture a printf sequence. */
{
- struct command_line *printf_cmd_line
- = xmalloc (sizeof (struct command_line));
+ struct command_line *printf_cmd_line = XNEW (struct command_line);
printf_cmd_line->control_type = simple_control;
printf_cmd_line->body_count = 0;
CORE_ADDR pc;
init_sal (&sal); /* Initialize to zeroes. */
- lsal.sals.sals = (struct symtab_and_line *)
- xmalloc (sizeof (struct symtab_and_line));
+ lsal.sals.sals = XNEW (struct symtab_and_line);
/* Set sal's pspace, pc, symtab, and line to the values
corresponding to the last call to print_frame_info.
}
}
-/* Issue an invalid thread ID error. */
-
-static void ATTRIBUTE_NORETURN
-invalid_thread_id_error (int id)
-{
- error (_("Unknown thread %d."), id);
-}
-
/* Given TOK, a string specification of condition and thread, as
accepted by the 'break' command, extract the condition
string and thread number and set *COND_STRING and *THREAD.
}
else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
{
- char *tmptok;
+ const char *tmptok;
+ struct thread_info *thr;
tok = end_tok + 1;
- *thread = strtol (tok, &tmptok, 0);
+ thr = parse_thread_id (tok, &tmptok);
if (tok == tmptok)
error (_("Junk after thread keyword."));
- if (!valid_thread_id (*thread))
- invalid_thread_id_error (*thread);
+ *thread = thr->global_num;
tok = tmptok;
}
else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
error (_("No known static tracepoint marker named %s"), marker_str);
sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
- sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
+ sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
for (i = 0; i < sals.nelts; i++)
{
gdb_assert (bl && bl->next == NULL);
annotate_breakpoint (b->number);
+
+ maybe_print_thread_hit_breakpoint (uiout);
+
if (b->disposition == disp_del)
- ui_out_text (uiout, "\nTemporary ranged breakpoint ");
+ ui_out_text (uiout, "Temporary ranged breakpoint ");
else
- ui_out_text (uiout, "\nRanged breakpoint ");
+ ui_out_text (uiout, "Ranged breakpoint ");
if (ui_out_is_mi_like_p (uiout))
{
ui_out_field_string (uiout, "reason",
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
+ annotate_watchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
+
switch (b->type)
{
case bp_watchpoint:
case bp_hardware_watchpoint:
- annotate_watchpoint (b->number);
if (ui_out_is_mi_like_p (uiout))
ui_out_field_string
(uiout, "reason",
case bp_access_watchpoint:
if (bs->old_val != NULL)
{
- annotate_watchpoint (b->number);
if (ui_out_is_mi_like_p (uiout))
ui_out_field_string
(uiout, "reason",
/* Masked watchpoints have only one location. */
gdb_assert (b->loc && b->loc->next == NULL);
+ annotate_watchpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
+
switch (b->type)
{
case bp_hardware_watchpoint:
- annotate_watchpoint (b->number);
if (ui_out_is_mi_like_p (uiout))
ui_out_field_string
(uiout, "reason",
if (toklen == 6 && startswith (tok, "thread"))
{
+ struct thread_info *thr;
/* At this point we've found a "thread" token, which means
the user is trying to set a watchpoint that triggers
only in a specific thread. */
- char *endp;
+ const char *endp;
if (thread != -1)
error(_("You can specify only one thread."));
/* Extract the thread ID from the next token. */
- thread = strtol (value_start, &endp, 0);
+ thr = parse_thread_id (value_start, &endp);
- /* Check if the user provided a valid numeric value for the
- thread ID. */
+ /* Check if the user provided a valid thread ID. */
if (*endp != ' ' && *endp != '\t' && *endp != '\0')
- error (_("Invalid thread ID specification %s."), value_start);
+ invalid_thread_id_error (value_start);
- /* Check if the thread actually exists. */
- if (!valid_thread_id (thread))
- invalid_thread_id_error (thread);
+ thread = thr->global_num;
}
else if (toklen == 4 && startswith (tok, "mask"))
{
}
\f
-/* Helper routines for the until_command routine in infcmd.c. Here
- because it uses the mechanisms of breakpoints. */
+/* Data for the FSM that manages the until(location)/advance commands
+ in infcmd.c. Here because it uses the mechanisms of
+ breakpoints. */
-struct until_break_command_continuation_args
+struct until_break_fsm
{
- struct breakpoint *breakpoint;
- struct breakpoint *breakpoint2;
- int thread_num;
+ /* The base class. */
+ struct thread_fsm thread_fsm;
+
+ /* The thread that as current when the command was executed. */
+ int thread;
+
+ /* The breakpoint set at the destination location. */
+ struct breakpoint *location_breakpoint;
+
+ /* Breakpoint set at the return address in the caller frame. May be
+ NULL. */
+ struct breakpoint *caller_breakpoint;
};
-/* This function is called by fetch_inferior_event via the
- cmd_continuation pointer, to complete the until command. It takes
- care of cleaning up the temporary breakpoints set up by the until
- command. */
+static void until_break_fsm_clean_up (struct thread_fsm *self);
+static int until_break_fsm_should_stop (struct thread_fsm *self);
+static enum async_reply_reason
+ until_break_fsm_async_reply_reason (struct thread_fsm *self);
+
+/* until_break_fsm's vtable. */
+
+static struct thread_fsm_ops until_break_fsm_ops =
+{
+ NULL, /* dtor */
+ until_break_fsm_clean_up,
+ until_break_fsm_should_stop,
+ NULL, /* return_value */
+ until_break_fsm_async_reply_reason,
+};
+
+/* Allocate a new until_break_command_fsm. */
+
+static struct until_break_fsm *
+new_until_break_fsm (int thread,
+ struct breakpoint *location_breakpoint,
+ struct breakpoint *caller_breakpoint)
+{
+ struct until_break_fsm *sm;
+
+ sm = XCNEW (struct until_break_fsm);
+ thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops);
+
+ sm->thread = thread;
+ sm->location_breakpoint = location_breakpoint;
+ sm->caller_breakpoint = caller_breakpoint;
+
+ return sm;
+}
+
+/* Implementation of the 'should_stop' FSM method for the
+ until(location)/advance commands. */
+
+static int
+until_break_fsm_should_stop (struct thread_fsm *self)
+{
+ struct until_break_fsm *sm = (struct until_break_fsm *) self;
+ struct thread_info *tp = inferior_thread ();
+
+ if (bpstat_find_breakpoint (tp->control.stop_bpstat,
+ sm->location_breakpoint) != NULL
+ || (sm->caller_breakpoint != NULL
+ && bpstat_find_breakpoint (tp->control.stop_bpstat,
+ sm->caller_breakpoint) != NULL))
+ thread_fsm_set_finished (self);
+
+ return 1;
+}
+
+/* Implementation of the 'clean_up' FSM method for the
+ until(location)/advance commands. */
+
static void
-until_break_command_continuation (void *arg, int err)
+until_break_fsm_clean_up (struct thread_fsm *self)
{
- struct until_break_command_continuation_args *a = arg;
+ struct until_break_fsm *sm = (struct until_break_fsm *) self;
+
+ /* Clean up our temporary breakpoints. */
+ if (sm->location_breakpoint != NULL)
+ {
+ delete_breakpoint (sm->location_breakpoint);
+ sm->location_breakpoint = NULL;
+ }
+ if (sm->caller_breakpoint != NULL)
+ {
+ delete_breakpoint (sm->caller_breakpoint);
+ sm->caller_breakpoint = NULL;
+ }
+ delete_longjmp_breakpoint (sm->thread);
+}
- delete_breakpoint (a->breakpoint);
- if (a->breakpoint2)
- delete_breakpoint (a->breakpoint2);
- delete_longjmp_breakpoint (a->thread_num);
+/* Implementation of the 'async_reply_reason' FSM method for the
+ until(location)/advance commands. */
+
+static enum async_reply_reason
+until_break_fsm_async_reply_reason (struct thread_fsm *self)
+{
+ return EXEC_ASYNC_LOCATION_REACHED;
}
void
struct gdbarch *frame_gdbarch;
struct frame_id stack_frame_id;
struct frame_id caller_frame_id;
- struct breakpoint *breakpoint;
- struct breakpoint *breakpoint2 = NULL;
+ struct breakpoint *location_breakpoint;
+ struct breakpoint *caller_breakpoint = NULL;
struct cleanup *old_chain, *cleanup;
int thread;
struct thread_info *tp;
struct event_location *location;
+ struct until_break_fsm *sm;
clear_proceed_status (0);
resolve_sal_pc (&sal);
tp = inferior_thread ();
- thread = tp->num;
+ thread = tp->global_num;
old_chain = make_cleanup (null_cleanup, NULL);
if (frame_id_p (caller_frame_id))
{
struct symtab_and_line sal2;
+ struct gdbarch *caller_gdbarch;
sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
sal2.pc = frame_unwind_caller_pc (frame);
- breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
- sal2,
- caller_frame_id,
- bp_until);
- make_cleanup_delete_breakpoint (breakpoint2);
+ caller_gdbarch = frame_unwind_caller_arch (frame);
+ caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
+ sal2,
+ caller_frame_id,
+ bp_until);
+ make_cleanup_delete_breakpoint (caller_breakpoint);
set_longjmp_breakpoint (tp, caller_frame_id);
make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
if (anywhere)
/* If the user told us to continue until a specified location,
we don't specify a frame at which we need to stop. */
- breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
- null_frame_id, bp_until);
+ location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
+ null_frame_id, bp_until);
else
/* Otherwise, specify the selected frame, because we want to stop
only at the very same frame. */
- breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
- stack_frame_id, bp_until);
- make_cleanup_delete_breakpoint (breakpoint);
-
- proceed (-1, GDB_SIGNAL_DEFAULT);
-
- /* If we are running asynchronously, and proceed call above has
- actually managed to start the target, arrange for breakpoints to
- be deleted when the target stops. Otherwise, we're already
- stopped and delete breakpoints via cleanup chain. */
+ location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
+ stack_frame_id, bp_until);
+ make_cleanup_delete_breakpoint (location_breakpoint);
- if (target_can_async_p () && is_running (inferior_ptid))
- {
- struct until_break_command_continuation_args *args;
- args = xmalloc (sizeof (*args));
+ sm = new_until_break_fsm (tp->global_num,
+ location_breakpoint, caller_breakpoint);
+ tp->thread_fsm = &sm->thread_fsm;
- args->breakpoint = breakpoint;
- args->breakpoint2 = breakpoint2;
- args->thread_num = thread;
+ discard_cleanups (old_chain);
- discard_cleanups (old_chain);
- add_continuation (inferior_thread (),
- until_break_command_continuation, args,
- xfree);
- }
- else
- do_cleanups (old_chain);
+ proceed (-1, GDB_SIGNAL_DEFAULT);
do_cleanups (cleanup);
}
static int
compare_breakpoints (const void *a, const void *b)
{
- const breakpoint_p *ba = a;
+ const breakpoint_p *ba = (const breakpoint_p *) a;
uintptr_t ua = (uintptr_t) *ba;
- const breakpoint_p *bb = b;
+ const breakpoint_p *bb = (const breakpoint_p *) b;
uintptr_t ub = (uintptr_t) *bb;
if ((*ba)->number < (*bb)->number)
}
else
{
- sals.sals = (struct symtab_and_line *)
- xmalloc (sizeof (struct symtab_and_line));
+ sals.sals = XNEW (struct symtab_and_line);
make_cleanup (xfree, sals.sals);
init_sal (&sal); /* Initialize to zeroes. */
static int
bp_location_compare (const void *ap, const void *bp)
{
- struct bp_location *a = *(void **) ap;
- struct bp_location *b = *(void **) bp;
+ const struct bp_location *a = *(const struct bp_location **) ap;
+ const struct bp_location *b = *(const struct bp_location **) bp;
if (a->address != b->address)
return (a->address > b->address) - (a->address < b->address);
{
struct breakpoint *b;
struct cleanup *old_chain;
-
- if (!target_can_download_tracepoint ())
- return;
+ enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
old_chain = save_current_space_and_thread ();
: !may_insert_tracepoints))
continue;
+ if (can_download_tracepoint == TRIBOOL_UNKNOWN)
+ {
+ if (target_can_download_tracepoint ())
+ can_download_tracepoint = TRIBOOL_TRUE;
+ else
+ can_download_tracepoint = TRIBOOL_FALSE;
+ }
+
+ if (can_download_tracepoint == TRIBOOL_FALSE)
+ break;
+
for (bl = b->loc; bl; bl = bl->next)
{
/* In tracepoint, locations are _never_ duplicated, so
for (loc = b->loc; loc; loc = loc->next)
bp_location_count++;
- bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
+ bp_location = XNEWVEC (struct bp_location *, bp_location_count);
locp = bp_location;
ALL_BREAKPOINTS (b)
for (loc = b->loc; loc; loc = loc->next)
static int
bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
{
- struct breakpoint *bpt = data;
+ struct breakpoint *bpt = (struct breakpoint *) data;
bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
return 0;
bl->address,
b->number, 1);
annotate_breakpoint (b->number);
+ maybe_print_thread_hit_breakpoint (uiout);
+
if (bp_temp)
- ui_out_text (uiout, "\nTemporary breakpoint ");
+ ui_out_text (uiout, "Temporary breakpoint ");
else
- ui_out_text (uiout, "\nBreakpoint ");
+ ui_out_text (uiout, "Breakpoint ");
if (ui_out_is_mi_like_p (uiout))
{
ui_out_field_string (uiout, "reason",
static enum print_stop_action
momentary_bkpt_print_it (bpstat bs)
{
- struct ui_out *uiout = current_uiout;
-
- if (ui_out_is_mi_like_p (uiout))
- {
- struct breakpoint *b = bs->breakpoint_at;
-
- switch (b->type)
- {
- case bp_finish:
- ui_out_field_string
- (uiout, "reason",
- async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
- break;
-
- case bp_until:
- ui_out_field_string
- (uiout, "reason",
- async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
- break;
- }
- }
-
return PRINT_UNKNOWN;
}
static void
longjmp_bkpt_dtor (struct breakpoint *self)
{
- struct thread_info *tp = find_thread_id (self->thread);
+ struct thread_info *tp = find_thread_global_id (self->thread);
if (tp)
tp->initiating_frame = null_frame_id;
if (self->type == bp_fast_tracepoint)
fprintf_unfiltered (fp, "ftrace");
- if (self->type == bp_static_tracepoint)
+ else if (self->type == bp_static_tracepoint)
fprintf_unfiltered (fp, "strace");
else if (self->type == bp_tracepoint)
fprintf_unfiltered (fp, "trace");
static void
do_delete_breakpoint_cleanup (void *b)
{
- delete_breakpoint (b);
+ delete_breakpoint ((struct breakpoint *) b);
}
struct cleanup *
if (!VEC_empty(static_tracepoint_marker_p, markers))
{
- char *p, *tmp;
struct symtab_and_line sal2;
struct symbol *sym;
struct static_tracepoint_marker *tpmarker;
struct ui_out *uiout = current_uiout;
- struct cleanup *cleanup;
+ struct explicit_location explicit_loc;
tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
delete_event_location (b->location);
- p = tmp = xstrprintf ("%s:%d",
- symtab_to_filename_for_display (sal2.symtab),
- b->loc->line_number);
- cleanup = make_cleanup (xfree, tmp);
- b->location = new_linespec_location (&tmp);
- do_cleanups (cleanup);
+ initialize_explicit_location (&explicit_loc);
+ explicit_loc.source_filename
+ = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
+ explicit_loc.line_offset.offset = b->loc->line_number;
+ explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
+ b->location = new_explicit_location (&explicit_loc);
/* Might be nice to check if function changed, and warn if
so. */
if (b->thread != -1)
{
if (in_thread_list (inferior_ptid))
- b->thread = pid_to_thread_id (inferior_ptid);
+ b->thread = ptid_to_global_thread_id (inferior_ptid);
/* We're being called after following a fork. The new fork is
selected as current, and unless this was a vfork will have a
if (tp->control.single_step_breakpoints == NULL)
{
tp->control.single_step_breakpoints
- = new_single_step_breakpoint (tp->num, gdbarch);
+ = new_single_step_breakpoint (tp->global_num, gdbarch);
}
sal = find_pc_line (pc, 0);
}
\f
+/* This help string is used to consolidate all the help string for specifying
+ locations used by several commands. */
+
+#define LOCATION_HELP_STRING \
+"Linespecs are colon-separated lists of location parameters, such as\n\
+source filename, function name, label name, and line number.\n\
+Example: To specify the start of a label named \"the_top\" in the\n\
+function \"fact\" in the file \"factorial.c\", use\n\
+\"factorial.c:fact:the_top\".\n\
+\n\
+Address locations begin with \"*\" and specify an exact address in the\n\
+program. Example: To specify the fourth byte past the start function\n\
+\"main\", use \"*main + 4\".\n\
+\n\
+Explicit locations are similar to linespecs but use an option/argument\n\
+syntax to specify location parameters.\n\
+Example: To specify the start of the label named \"the_top\" in the\n\
+function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
+-function fact -label the_top\".\n"
+
/* This help string is used for the break, hbreak, tbreak and thbreak
commands. It is defined as a macro to prevent duplication.
COMMAND should be a string constant containing the name of the
command. */
+
#define BREAK_ARGS_HELP(command) \
command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
PROBE_MODIFIER shall be present if the command is to be placed in a\n\
probe point. Accepted values are `-probe' (for a generic, automatically\n\
guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
`-probe-dtrace' (for a DTrace probe).\n\
-LOCATION may be a line number, function name, or \"*\" and an address.\n\
-If a line number is specified, break at start of code for that line.\n\
-If a function is specified, break at start of code for that function.\n\
-If an address is specified, break at that exact address.\n\
+LOCATION may be a linespec, address, or explicit location as described\n\
+below.\n\
+\n\
With no LOCATION, uses current execution address of the selected\n\
stack frame. This is useful for breaking on return to a stack frame.\n\
\n\
THREADNUM is the number from \"info threads\".\n\
CONDITION is a boolean expression.\n\
-\n\
+\n" LOCATION_HELP_STRING "\n\
Multiple breakpoints at one place are permitted, and useful if their\n\
conditions are different.\n\
\n\
&deletelist);
add_com ("clear", class_breakpoint, clear_command, _("\
-Clear breakpoint at specified line or function.\n\
-Argument may be line number, function name, or \"*\" and an address.\n\
-If line number is specified, all breakpoints in that line are cleared.\n\
-If function is specified, breakpoints at beginning of function are cleared.\n\
-If an address is specified, breakpoints at that address are cleared.\n\
+Clear breakpoint at specified location.\n\
+Argument may be a linespec, explicit, or address location as described below.\n\
\n\
With no argument, clears all breakpoints in the line that the selected frame\n\
-is executing in.\n\
-\n\
+is executing in.\n"
+"\n" LOCATION_HELP_STRING "\n\
See also the \"delete\" command which clears breakpoints by number."));
add_com_alias ("cl", "clear", class_breakpoint, 1);
c = add_com ("break", class_breakpoint, break_command, _("\
-Set breakpoint at specified line or function.\n"
+Set breakpoint at specified location.\n"
BREAK_ARGS_HELP ("break")));
set_cmd_completer (c, location_completer);
/* Tracepoint manipulation commands. */
c = add_com ("trace", class_breakpoint, trace_command, _("\
-Set a tracepoint at specified line or function.\n\
+Set a tracepoint at specified location.\n\
\n"
BREAK_ARGS_HELP ("trace") "\n\
Do \"help tracepoints\" for info on other tracepoint commands."));
add_com_alias ("trac", "trace", class_alias, 1);
c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
-Set a fast tracepoint at specified line or function.\n\
+Set a fast tracepoint at specified location.\n\
\n"
BREAK_ARGS_HELP ("ftrace") "\n\
Do \"help tracepoints\" for info on other tracepoint commands."));
set_cmd_completer (c, location_completer);
c = add_com ("strace", class_breakpoint, strace_command, _("\
-Set a static tracepoint at specified line, function or marker.\n\
+Set a static tracepoint at location or marker.\n\
\n\
strace [LOCATION] [if CONDITION]\n\
-LOCATION may be a line number, function name, \"*\" and an address,\n\
-or -m MARKER_ID.\n\
-If a line number is specified, probe the marker at start of code\n\
-for that line. If a function is specified, probe the marker at start\n\
-of code for that function. If an address is specified, probe the marker\n\
-at that exact address. If a marker id is specified, probe the marker\n\
-with that name. With no LOCATION, uses current execution address of\n\
-the selected stack frame.\n\
+LOCATION may be a linespec, explicit, or address location (described below) \n\
+or -m MARKER_ID.\n\n\
+If a marker id is specified, probe the marker with that name. With\n\
+no LOCATION, uses current execution address of the selected stack frame.\n\
Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
This collects arbitrary user data passed in the probe point call to the\n\
tracing library. You can inspect it when analyzing the trace buffer,\n\
by printing the $_sdata variable like any other convenience variable.\n\
\n\
CONDITION is a boolean expression.\n\
-\n\
+\n" LOCATION_HELP_STRING "\n\
Multiple tracepoints at one place are permitted, and useful if their\n\
conditions are different.\n\
\n\
range (including START-LOCATION and END-LOCATION)."));
c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
-Set a dynamic printf at specified line or function.\n\
+Set a dynamic printf at specified location.\n\
dprintf location,format string,arg1,arg2,...\n\
-location may be a line number, function name, or \"*\" and an address.\n\
-If a line number is specified, break at start of code for that line.\n\
-If a function is specified, break at start of code for that function."));
+location may be a linespec, explicit, or address location.\n"
+"\n" LOCATION_HELP_STRING));
set_cmd_completer (c, location_completer);
add_setshow_enum_cmd ("dprintf-style", class_support,