#include "wrapper.h"
#include "valprint.h"
#include "jit.h"
+#include "xml-syscall.h"
/* readline include files */
#include "readline/readline.h"
struct symtab_and_line,
enum bptype);
-static void check_duplicates (struct breakpoint *);
-
static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
CORE_ADDR bpaddr,
enum bptype bptype);
-static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR,
+static void describe_other_breakpoints (struct gdbarch *,
+ struct program_space *, CORE_ADDR,
struct obj_section *, int);
+static int breakpoint_address_match (struct address_space *aspace1,
+ CORE_ADDR addr1,
+ struct address_space *aspace2,
+ CORE_ADDR addr2);
+
static void breakpoints_info (char *, int);
static void breakpoint_1 (int, int);
insertion_state_t;
static int remove_breakpoint (struct bp_location *, insertion_state_t);
+static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
static enum print_stop_action print_it_typical (bpstat);
static void ep_skip_leading_whitespace (char **s);
-static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
+static int single_step_breakpoint_inserted_here_p (struct address_space *,
+ CORE_ADDR pc);
static void free_bp_location (struct bp_location *loc);
static void insert_breakpoint_locations (void);
+static int syscall_catchpoint_p (struct breakpoint *b);
+
static void tracepoints_info (char *, int);
static void delete_trace_command (char *, int);
/* Are overlay event breakpoints enabled? */
static int overlay_events_enabled;
-/* Are we executing startup code? */
-static int executing_startup;
-
/* Walk the following statement or block through all breakpoints.
ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
breakpoint. */
B ? (TMP=B->next, 1): 0; \
B = TMP)
-/* Similar iterators for the low-level breakpoints. */
+/* Similar iterator for the low-level breakpoints. SAFE variant is not
+ provided so update_global_location_list must not be called while executing
+ the block of ALL_BP_LOCATIONS. */
-#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
-
-#define ALL_BP_LOCATIONS_SAFE(B,TMP) \
- for (B = bp_location_chain; \
- B ? (TMP=B->global_next, 1): 0; \
- B = TMP)
+#define ALL_BP_LOCATIONS(B,BP_TMP) \
+ for (BP_TMP = bp_location; \
+ BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
+ BP_TMP++)
/* Iterator for tracepoints only. */
struct breakpoint *breakpoint_chain;
-struct bp_location *bp_location_chain;
+/* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
+
+static struct bp_location **bp_location;
+
+/* Number of elements of BP_LOCATION. */
+
+static unsigned bp_location_count;
+
+/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
+ for the current elements of BP_LOCATION which get a valid result from
+ bp_location_has_shadow. You can use it for roughly limiting the subrange of
+ BP_LOCATION to scan for shadow bytes for an address you need to read. */
+
+static CORE_ADDR bp_location_placed_address_before_address_max;
+
+/* Maximum offset plus alignment between
+ bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
+ the current elements of BP_LOCATION which get a valid result from
+ bp_location_has_shadow. You can use it for roughly limiting the subrange of
+ BP_LOCATION to scan for shadow bytes for an address you need to read. */
+
+static CORE_ADDR bp_location_shadow_len_after_address_max;
/* The locations that no longer correspond to any breakpoint,
- unlinked from bp_location_chain, but for which a hit
+ unlinked from bp_location array, but for which a hit
may still be reported by a target. */
VEC(bp_location_p) *moribund_locations = NULL;
CORE_ADDR default_breakpoint_address;
struct symtab *default_breakpoint_symtab;
int default_breakpoint_line;
+struct program_space *default_breakpoint_pspace;
+
\f
/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
Advance *PP after the string and any trailing whitespace.
}
error (_("No breakpoint number %d."), bnum);
}
-\f
+
+/* Return non-zero if BL->TARGET_INFO contains valid information. */
+
+static int
+bp_location_has_shadow (struct bp_location *bl)
+{
+ if (bl->loc_type != bp_loc_software_breakpoint)
+ return 0;
+ if (!bl->inserted)
+ return 0;
+ if (bl->target_info.shadow_len == 0)
+ /* bp isn't valid, or doesn't shadow memory. */
+ return 0;
+ return 1;
+}
+
/* Update BUF, which is LEN bytes read from the target address MEMADDR,
- by replacing any memory breakpoints with their shadowed contents. */
+ by replacing any memory breakpoints with their shadowed contents.
+
+ The range of shadowed area by each bp_location is:
+ b->address - bp_location_placed_address_before_address_max
+ up to b->address + bp_location_shadow_len_after_address_max
+ The range we were requested to resolve shadows for is:
+ memaddr ... memaddr + len
+ Thus the safe cutoff boundaries for performance optimization are
+ memaddr + len <= b->address - bp_location_placed_address_before_address_max
+ and:
+ b->address + bp_location_shadow_len_after_address_max <= memaddr */
void
breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
{
- struct bp_location *b;
- CORE_ADDR bp_addr = 0;
- int bp_size = 0;
- int bptoffset = 0;
+ /* Left boundary, right boundary and median element of our binary search. */
+ unsigned bc_l, bc_r, bc;
+
+ /* Find BC_L which is a leftmost element which may affect BUF content. It is
+ safe to report lower value but a failure to report higher one. */
+
+ bc_l = 0;
+ bc_r = bp_location_count;
+ while (bc_l + 1 < bc_r)
+ {
+ struct bp_location *b;
+
+ bc = (bc_l + bc_r) / 2;
+ b = bp_location[bc];
+
+ /* Check first B->ADDRESS will not overflow due to the added constant.
+ Then advance the left boundary only if we are sure the BC element can
+ in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
+
+ Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
+ we cannot miss a breakpoint with its shadow range tail still reaching
+ MEMADDR. */
+
+ if (b->address + bp_location_shadow_len_after_address_max >= b->address
+ && b->address + bp_location_shadow_len_after_address_max <= memaddr)
+ bc_l = bc;
+ else
+ bc_r = bc;
+ }
- ALL_BP_LOCATIONS (b)
+ /* Now do full processing of the found relevant range of elements. */
+
+ for (bc = bc_l; bc < bp_location_count; bc++)
{
+ struct bp_location *b = bp_location[bc];
+ CORE_ADDR bp_addr = 0;
+ int bp_size = 0;
+ int bptoffset = 0;
+
if (b->owner->type == bp_none)
warning (_("reading through apparently deleted breakpoint #%d?"),
b->owner->number);
- if (b->loc_type != bp_loc_software_breakpoint)
+ /* Performance optimization: any futher element can no longer affect BUF
+ content. */
+
+ if (b->address >= bp_location_placed_address_before_address_max
+ && memaddr + len <= b->address
+ - bp_location_placed_address_before_address_max)
+ break;
+
+ if (!bp_location_has_shadow (b))
continue;
- if (!b->inserted)
+ if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
+ current_program_space->aspace, 0))
continue;
+
/* Addresses and length of the part of the breakpoint that
we need to copy. */
bp_addr = b->target_info.placed_address;
bp_size = b->target_info.shadow_len;
- if (bp_size == 0)
- /* bp isn't valid, or doesn't shadow memory. */
- continue;
if (bp_addr + bp_size <= memaddr)
/* The breakpoint is entirely before the chunk of memory we
int within_current_scope;
struct frame_id saved_frame_id;
struct bp_location *loc;
+ int frame_saved;
bpstat bs;
+ struct program_space *frame_pspace;
- /* We don't free locations. They are stored in bp_location_chain and
+ /* We don't free locations. They are stored in bp_location array and
update_global_locations will eventually delete them and remove
breakpoints if needed. */
b->loc = NULL;
if (b->disposition == disp_del_at_next_stop)
return;
- /* Save the current frame's ID so we can restore it after
- evaluating the watchpoint expression on its own frame. */
- /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
- took a frame parameter, so that we didn't have to change the
- selected frame. */
- saved_frame_id = get_frame_id (get_selected_frame (NULL));
+ frame_saved = 0;
/* Determine if the watchpoint is within scope. */
if (b->exp_valid_block == NULL)
else
{
struct frame_info *fi;
+
+ /* Save the current frame's ID so we can restore it after
+ evaluating the watchpoint expression on its own frame. */
+ /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
+ took a frame parameter, so that we didn't have to change the
+ selected frame. */
+ frame_saved = 1;
+ saved_frame_id = get_frame_id (get_selected_frame (NULL));
+
fi = frame_find_by_id (b->watchpoint_frame);
within_current_scope = (fi != NULL);
if (within_current_scope)
select_frame (fi);
}
+ frame_pspace = get_frame_program_space (get_selected_frame (NULL));
+
if (within_current_scope && reparse)
{
char *s;
;
*tmp = loc;
loc->gdbarch = get_type_arch (value_type (v));
+
+ loc->pspace = frame_pspace;
loc->address = addr;
loc->length = len;
loc->watchpoint_type = type;
}
/* Restore the selected frame. */
- select_frame (frame_find_by_id (saved_frame_id));
+ if (frame_saved)
+ select_frame (frame_find_by_id (saved_frame_id));
}
if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
return 0;
+ /* This is set for example, when we're attached to the parent of a
+ vfork, and have detached from the child. The child is running
+ free, and we expect it to do an exec or exit, at which point the
+ OS makes the parent schedulable again (and the target reports
+ that the vfork is done). Until the child is done with the shared
+ memory region, do not insert breakpoints in the parent, otherwise
+ the child could still trip on the parent's breakpoints. Since
+ the parent is blocked anyway, it won't miss any breakpoint. */
+ if (bpt->pspace->breakpoints_not_allowed)
+ return 0;
+
/* Tracepoints are inserted by the target at a time of its choosing,
not by us. */
if (bpt->owner->type == bp_tracepoint)
/* Initialize the target-specific information. */
memset (&bpt->target_info, 0, sizeof (bpt->target_info));
bpt->target_info.placed_address = bpt->address;
+ bpt->target_info.placed_address_space = bpt->pspace->aspace;
if (bpt->loc_type == bp_loc_software_breakpoint
|| bpt->loc_type == bp_loc_hardware_breakpoint)
if (val)
{
/* Can't set the breakpoint. */
- if (solib_name_from_address (bpt->address))
+ if (solib_name_from_address (bpt->pspace, bpt->address))
{
/* See also: disable_breakpoints_in_shlibs. */
val = 0;
return 0;
}
+/* This function is called when program space PSPACE is about to be
+ deleted. It takes care of updating breakpoints to not reference
+ PSPACE anymore. */
+
+void
+breakpoint_program_space_exit (struct program_space *pspace)
+{
+ struct breakpoint *b, *b_temp;
+ struct bp_location *loc, **loc_temp;
+
+ /* Remove any breakpoint that was set through this program space. */
+ ALL_BREAKPOINTS_SAFE (b, b_temp)
+ {
+ if (b->pspace == pspace)
+ delete_breakpoint (b);
+ }
+
+ /* Breakpoints set through other program spaces could have locations
+ bound to PSPACE as well. Remove those. */
+ ALL_BP_LOCATIONS (loc, loc_temp)
+ {
+ struct bp_location *tmp;
+
+ if (loc->pspace == pspace)
+ {
+ if (loc->owner->loc == loc)
+ loc->owner->loc = loc->next;
+ else
+ for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
+ if (tmp->next == loc)
+ {
+ tmp->next = loc->next;
+ break;
+ }
+ }
+ }
+
+ /* Now update the global location list to permanently delete the
+ removed locations above. */
+ update_global_location_list (0);
+}
+
/* Make sure all breakpoints are inserted in inferior.
Throws exception on any error.
A breakpoint that is already inserted won't be inserted
insert_breakpoint_locations (void)
{
struct breakpoint *bpt;
- struct bp_location *b, *temp;
+ struct bp_location *b, **bp_tmp;
int error = 0;
int val = 0;
int disabled_breaks = 0;
/* Explicitly mark the warning -- this will only be printed if
there was an error. */
fprintf_unfiltered (tmp_error_stream, "Warning:\n");
-
- ALL_BP_LOCATIONS_SAFE (b, temp)
+
+ save_current_space_and_thread ();
+
+ ALL_BP_LOCATIONS (b, bp_tmp)
{
+ struct thread_info *tp;
+ CORE_ADDR last_addr;
+
if (!should_be_inserted (b) || b->inserted)
continue;
&& !valid_thread_id (b->owner->thread))
continue;
+ switch_to_program_space_and_thread (b->pspace);
+
+ /* For targets that support global breakpoints, there's no need
+ to select an inferior to insert breakpoint to. In fact, even
+ 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))
+ continue;
+
val = insert_bp_location (b, tmp_error_stream,
&disabled_breaks,
&hw_breakpoint_error);
continue;
for (loc = bpt->loc; loc; loc = loc->next)
- if (!loc->inserted)
+ if (!loc->inserted && should_be_inserted (loc))
{
some_failed = 1;
break;
int
remove_breakpoints (void)
{
- struct bp_location *b;
+ struct bp_location *b, **bp_tmp;
int val = 0;
- ALL_BP_LOCATIONS (b)
+ ALL_BP_LOCATIONS (b, bp_tmp)
{
if (b->inserted)
val |= remove_breakpoint (b, mark_uninserted);
return val;
}
+/* Remove breakpoints of process PID. */
+
+int
+remove_breakpoints_pid (int pid)
+{
+ struct bp_location *b, **b_tmp;
+ int val;
+ struct inferior *inf = find_inferior_pid (pid);
+
+ ALL_BP_LOCATIONS (b, b_tmp)
+ {
+ if (b->pspace != inf->pspace)
+ continue;
+
+ if (b->inserted)
+ {
+ val = remove_breakpoint (b, mark_uninserted);
+ if (val != 0)
+ return val;
+ }
+ }
+ return 0;
+}
+
int
remove_hw_watchpoints (void)
{
- struct bp_location *b;
+ struct bp_location *b, **bp_tmp;
int val = 0;
- ALL_BP_LOCATIONS (b)
+ ALL_BP_LOCATIONS (b, bp_tmp)
{
if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
val |= remove_breakpoint (b, mark_uninserted);
int
reattach_breakpoints (int pid)
{
- struct bp_location *b;
+ struct cleanup *old_chain;
+ struct bp_location *b, **bp_tmp;
int val;
- struct cleanup *old_chain = save_inferior_ptid ();
struct ui_file *tmp_error_stream = mem_fileopen ();
int dummy1 = 0, dummy2 = 0;
+ struct inferior *inf;
+ struct thread_info *tp;
+
+ tp = any_live_thread_of_process (pid);
+ if (tp == NULL)
+ return 1;
+
+ inf = find_inferior_pid (pid);
+ old_chain = save_inferior_ptid ();
+
+ inferior_ptid = tp->ptid;
make_cleanup_ui_file_delete (tmp_error_stream);
- inferior_ptid = pid_to_ptid (pid);
- ALL_BP_LOCATIONS (b)
+ ALL_BP_LOCATIONS (b, bp_tmp)
{
+ if (b->pspace != inf->pspace)
+ continue;
+
if (b->inserted)
{
b->inserted = 0;
sal.pc = address;
sal.section = find_pc_overlay (sal.pc);
+ sal.pspace = current_program_space;
b = set_raw_breakpoint (gdbarch, sal, type);
b->number = internal_breakpoint_number--;
static void
create_longjmp_master_breakpoint (char *func_name)
{
+ struct program_space *pspace;
struct objfile *objfile;
+ struct cleanup *old_chain;
+ old_chain = save_current_program_space ();
+
+ ALL_PSPACES (pspace)
ALL_OBJFILES (objfile)
{
struct breakpoint *b;
if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
continue;
+ set_current_program_space (pspace);
+
m = lookup_minimal_symbol_text (func_name, objfile);
if (m == NULL)
continue;
b->enable_state = bp_disabled;
}
update_global_location_list (1);
+
+ do_cleanups (old_chain);
}
void
{
struct breakpoint *b;
struct breakpoint *temp;
- struct bp_location *bploc;
+ struct bp_location *bploc, **bplocp_tmp;
/* We're about to delete breakpoints from GDB's lists. If the
INSERTED flag is true, GDB will try to lift the breakpoints by
breakpoints out as soon as it detects an exec. We don't do that
here instead, because there may be other attempts to delete
breakpoints after detecting an exec and before reaching here. */
- ALL_BP_LOCATIONS (bploc)
- gdb_assert (!bploc->inserted);
+ ALL_BP_LOCATIONS (bploc, bplocp_tmp)
+ if (bploc->pspace == current_program_space)
+ gdb_assert (!bploc->inserted);
ALL_BREAKPOINTS_SAFE (b, temp)
{
+ if (b->pspace != current_program_space)
+ continue;
+
/* Solib breakpoints must be explicitly reset after an exec(). */
if (b->type == bp_shlib_event)
{
int
detach_breakpoints (int pid)
{
- struct bp_location *b;
+ struct bp_location *b, **bp_tmp;
int val = 0;
struct cleanup *old_chain = save_inferior_ptid ();
+ struct inferior *inf = current_inferior ();
if (pid == PIDGET (inferior_ptid))
error (_("Cannot detach breakpoints of inferior_ptid"));
- /* Set inferior_ptid; remove_breakpoint uses this global. */
+ /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
inferior_ptid = pid_to_ptid (pid);
- ALL_BP_LOCATIONS (b)
+ ALL_BP_LOCATIONS (b, bp_tmp)
{
+ if (b->pspace != inf->pspace)
+ continue;
+
if (b->inserted)
- val |= remove_breakpoint (b, mark_inserted);
+ val |= remove_breakpoint_1 (b, mark_inserted);
}
do_cleanups (old_chain);
return val;
}
+/* Remove the breakpoint location B from the current address space.
+ Note that this is used to detach breakpoints from a child fork.
+ When we get here, the child isn't in the inferior list, and neither
+ do we have objects to represent its address space --- we should
+ *not* look at b->pspace->aspace here. */
+
static int
-remove_breakpoint (struct bp_location *b, insertion_state_t is)
+remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
{
int val;
+ struct cleanup *old_chain;
if (b->owner->enable_state == bp_permanent)
/* Permanent breakpoints cannot be inserted or removed. */
/* In some cases, we might not be able to remove a breakpoint
in a shared library that has already been removed, but we
have not yet processed the shlib unload event. */
- if (val && solib_name_from_address (b->address))
+ if (val && solib_name_from_address (b->pspace, b->address))
val = 0;
if (val)
return 0;
}
+static int
+remove_breakpoint (struct bp_location *b, insertion_state_t is)
+{
+ int ret;
+ struct cleanup *old_chain;
+
+ if (b->owner->enable_state == bp_permanent)
+ /* Permanent breakpoints cannot be inserted or removed. */
+ return 0;
+
+ /* The type of none suggests that owner is actually deleted.
+ This should not ever happen. */
+ gdb_assert (b->owner->type != bp_none);
+
+ old_chain = save_current_space_and_thread ();
+
+ switch_to_program_space_and_thread (b->pspace);
+
+ ret = remove_breakpoint_1 (b, is);
+
+ do_cleanups (old_chain);
+ return ret;
+}
+
/* Clear the "inserted" flag in all breakpoints. */
void
mark_breakpoints_out (void)
{
- struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
- ALL_BP_LOCATIONS (bpt)
- bpt->inserted = 0;
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
+ if (bpt->pspace == current_program_space)
+ bpt->inserted = 0;
}
/* Clear the "inserted" flag in all breakpoints and delete any
breakpoint_init_inferior (enum inf_context context)
{
struct breakpoint *b, *temp;
- struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
int ix;
+ struct program_space *pspace = current_program_space;
/* If breakpoint locations are shared across processes, then there's
nothing to do. */
if (gdbarch_has_global_breakpoints (target_gdbarch))
return;
- ALL_BP_LOCATIONS (bpt)
- if (bpt->owner->enable_state != bp_permanent)
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
+ {
+ if (bpt->pspace == pspace
+ && bpt->owner->enable_state != bp_permanent)
bpt->inserted = 0;
+ }
ALL_BREAKPOINTS_SAFE (b, temp)
{
+ if (b->loc && b->loc->pspace != pspace)
+ continue;
+
switch (b->type)
{
case bp_call_dummy:
VEC_free (bp_location_p, moribund_locations);
}
+/* These functions concern about actual breakpoints inserted in the
+ target --- to e.g. check if we need to do decr_pc adjustment or if
+ we need to hop over the bkpt --- so we check for address space
+ match, not program space. */
+
/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
exists at PC. It returns ordinary_breakpoint_here if it's an
ordinary breakpoint, or permanent_breakpoint_here if it's a
the target, to advance the PC past the breakpoint. */
enum breakpoint_here
-breakpoint_here_p (CORE_ADDR pc)
+breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
{
- const struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
int any_breakpoint_here = 0;
- ALL_BP_LOCATIONS (bpt)
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
{
if (bpt->loc_type != bp_loc_software_breakpoint
&& bpt->loc_type != bp_loc_hardware_breakpoint)
if ((breakpoint_enabled (bpt->owner)
|| bpt->owner->enable_state == bp_permanent)
- && bpt->address == pc) /* bp is enabled and matches pc */
+ && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+ aspace, pc))
{
if (overlay_debugging
&& section_is_overlay (bpt->section)
/* Return true if there's a moribund breakpoint at PC. */
int
-moribund_breakpoint_here_p (CORE_ADDR pc)
+moribund_breakpoint_here_p (struct 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)
- if (loc->address == pc)
+ if (breakpoint_address_match (loc->pspace->aspace, loc->address,
+ aspace, pc))
return 1;
return 0;
}
/* Returns non-zero if there's a breakpoint inserted at PC, which is
- inserted using regular breakpoint_chain/bp_location_chain mechanism.
+ inserted using regular breakpoint_chain / bp_location array mechanism.
This does not check for single-step breakpoints, which are
inserted and removed using direct target manipulation. */
int
-regular_breakpoint_inserted_here_p (CORE_ADDR pc)
+regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
{
- const struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
- ALL_BP_LOCATIONS (bpt)
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
{
if (bpt->loc_type != bp_loc_software_breakpoint
&& bpt->loc_type != bp_loc_hardware_breakpoint)
continue;
if (bpt->inserted
- && bpt->address == pc) /* bp is inserted and matches pc */
+ && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+ aspace, pc))
{
if (overlay_debugging
&& section_is_overlay (bpt->section)
or a single step breakpoint inserted at PC. */
int
-breakpoint_inserted_here_p (CORE_ADDR pc)
+breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
{
- if (regular_breakpoint_inserted_here_p (pc))
+ if (regular_breakpoint_inserted_here_p (aspace, pc))
return 1;
- if (single_step_breakpoint_inserted_here_p (pc))
+ if (single_step_breakpoint_inserted_here_p (aspace, pc))
return 1;
return 0;
inserted at PC. */
int
-software_breakpoint_inserted_here_p (CORE_ADDR pc)
+software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
{
- const struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
int any_breakpoint_here = 0;
- ALL_BP_LOCATIONS (bpt)
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
{
if (bpt->loc_type != bp_loc_software_breakpoint)
continue;
if (bpt->inserted
- && bpt->address == pc) /* bp is enabled and matches pc */
+ && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+ aspace, pc))
{
if (overlay_debugging
&& section_is_overlay (bpt->section)
}
/* Also check for software single-step breakpoints. */
- if (single_step_breakpoint_inserted_here_p (pc))
+ if (single_step_breakpoint_inserted_here_p (aspace, pc))
return 1;
return 0;
PC is valid for process/thread PTID. */
int
-breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
+breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
+ ptid_t ptid)
{
- const struct bp_location *bpt;
+ struct bp_location *bpt, **bptp_tmp;
/* The thread and task IDs associated to PTID, computed lazily. */
int thread = -1;
int task = 0;
- ALL_BP_LOCATIONS (bpt)
+ ALL_BP_LOCATIONS (bpt, bptp_tmp)
{
if (bpt->loc_type != bp_loc_software_breakpoint
&& bpt->loc_type != bp_loc_hardware_breakpoint)
&& bpt->owner->enable_state != bp_permanent)
continue;
- if (bpt->address != pc)
+ if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+ aspace, pc))
continue;
if (bpt->owner->thread != -1)
breakpoint location BL. This function does not check if we
should stop, only if BL explains the stop. */
static int
-bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
+bpstat_check_location (const struct bp_location *bl,
+ struct address_space *aspace, CORE_ADDR bp_addr)
{
struct breakpoint *b = bl->owner;
&& b->type != bp_hardware_breakpoint
&& b->type != bp_catchpoint) /* a non-watchpoint bp */
{
- if (bl->address != bp_addr) /* address doesn't match */
+ if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
+ aspace, bp_addr))
return 0;
if (overlay_debugging /* unmapped overlay section */
&& section_is_overlay (bl->section)
commands, FIXME??? fields. */
bpstat
-bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
+bpstat_stop_status (struct address_space *aspace,
+ CORE_ADDR bp_addr, ptid_t ptid)
{
struct breakpoint *b = NULL;
- const struct bp_location *bl;
+ struct bp_location *bl, **blp_tmp;
struct bp_location *loc;
/* Root of the chain of bpstat's */
struct bpstats root_bs[1];
/* Pointer to the last thing in the chain currently. */
bpstat bs = root_bs;
int ix;
- int need_remove_insert;
+ int need_remove_insert, update_locations = 0;
- ALL_BP_LOCATIONS (bl)
+ ALL_BP_LOCATIONS (bl, blp_tmp)
{
b = bl->owner;
gdb_assert (b);
The watchpoint_check function will work on entire expression,
not the individual locations. For read watchopints, the
watchpoints_triggered function have checked all locations
- alrea
- */
+ already. */
if (b->type == bp_hardware_watchpoint && bl != b->loc)
continue;
- if (!bpstat_check_location (bl, bp_addr))
+ if (!bpstat_check_location (bl, aspace, bp_addr))
continue;
/* Come here if it's a watchpoint, or if the break address matches */
if (bs->stop)
{
- ++(b->hit_count);
+ if (b->enable_state != bp_disabled)
+ ++(b->hit_count);
/* We will stop here */
if (b->disposition == disp_disable)
{
if (b->enable_state != bp_permanent)
b->enable_state = bp_disabled;
- update_global_location_list (0);
+ update_locations = 1;
}
if (b->silent)
bs->print = 0;
bs->print_it = print_it_noop;
}
+ /* Delay this call which would break the ALL_BP_LOCATIONS iteration above. */
+ if (update_locations)
+ update_global_location_list (0);
+
for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
{
- if (loc->address == bp_addr)
+ if (breakpoint_address_match (loc->pspace->aspace, loc->address,
+ aspace, bp_addr))
{
bs = bpstat_alloc (loc, bs);
/* For hits of moribund locations, we should just proceed. */
char *wrap_indent,
struct ui_stream *stb)
{
+ struct cleanup *old_chain = save_current_program_space ();
+
+ if (loc != NULL)
+ set_current_program_space (loc->pspace);
+
if (b->source_file)
{
struct symbol *sym
print_address_symbolic (loc->address, stb->stream, demangle, "");
ui_out_field_stream (uiout, "at", stb);
}
+
+ do_cleanups (old_chain);
}
/* Print B to gdb_stdout. */
struct bp_location *loc,
int loc_number,
struct bp_location **last_loc,
- int print_address_bits)
+ int print_address_bits,
+ int allflag)
{
struct command_line *l;
struct symbol *sym;
break;
}
+
+ /* For backward compatibility, don't display inferiors unless there
+ are several. */
+ if (loc != NULL
+ && !header_of_multiple
+ && (allflag
+ || (!gdbarch_has_global_breakpoints (target_gdbarch)
+ && (number_of_program_spaces () > 1
+ || number_of_inferiors () > 1)
+ && loc->owner->type != bp_catchpoint)))
+ {
+ struct inferior *inf;
+ int first = 1;
+
+ for (inf = inferior_list; inf != NULL; inf = inf->next)
+ {
+ if (inf->pspace == loc->pspace)
+ {
+ if (first)
+ {
+ first = 0;
+ ui_out_text (uiout, " inf ");
+ }
+ else
+ ui_out_text (uiout, ", ");
+ ui_out_text (uiout, plongest (inf->num));
+ }
+ }
+ }
+
if (!part_of_multiple)
{
if (b->thread != -1)
static void
print_one_breakpoint (struct breakpoint *b,
- struct bp_location **last_loc, int print_address_bits)
+ struct bp_location **last_loc, int print_address_bits,
+ int allflag)
{
- print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits);
+ print_one_breakpoint_location (b, NULL, 0, last_loc,
+ print_address_bits, allflag);
/* If this breakpoint has custom print function,
it's already printed. Otherwise, print individual
int n = 1;
for (loc = b->loc; loc; loc = loc->next, ++n)
print_one_breakpoint_location (b, loc, n, last_loc,
- print_address_bits);
+ print_address_bits, allflag);
}
}
}
if (args->bnum == b->number)
{
int print_address_bits = breakpoint_address_bits (b);
- print_one_breakpoint (b, &dummy_loc, print_address_bits);
+ print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
return GDB_RC_OK;
}
}
/* We only print out user settable breakpoints unless the
allflag is set. */
if (allflag || user_settable_breakpoint (b))
- print_one_breakpoint (b, &last_loc, print_address_bits);
+ print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
}
do_cleanups (bkpttbl_chain);
static int
breakpoint_has_pc (struct breakpoint *b,
+ struct program_space *pspace,
CORE_ADDR pc, struct obj_section *section)
{
struct bp_location *bl = b->loc;
for (; bl; bl = bl->next)
{
- if (bl->address == pc
+ if (bl->pspace == pspace
+ && bl->address == pc
&& (!overlay_debugging || bl->section == section))
return 1;
}
return 0;
}
-/* Print a message describing any breakpoints set at PC. */
+/* Print a message describing any breakpoints set at PC. This
+ concerns with logical breakpoints, so we match program spaces, not
+ address spaces. */
static void
-describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
+describe_other_breakpoints (struct gdbarch *gdbarch,
+ struct program_space *pspace, CORE_ADDR pc,
struct obj_section *section, int thread)
{
int others = 0;
struct breakpoint *b;
ALL_BREAKPOINTS (b)
- others += breakpoint_has_pc (b, pc, section);
+ others += breakpoint_has_pc (b, pspace, pc, section);
if (others > 0)
{
if (others == 1)
else /* if (others == ???) */
printf_filtered (_("Note: breakpoints "));
ALL_BREAKPOINTS (b)
- if (breakpoint_has_pc (b, pc, section))
+ if (breakpoint_has_pc (b, pspace, pc, section))
{
others--;
printf_filtered ("%d", b->number);
for the `break' command with no arguments. */
void
-set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
+set_default_breakpoint (int valid, struct program_space *pspace,
+ CORE_ADDR addr, struct symtab *symtab,
int line)
{
default_breakpoint_valid = valid;
+ default_breakpoint_pspace = pspace;
default_breakpoint_address = addr;
default_breakpoint_symtab = symtab;
default_breakpoint_line = line;
(or use it 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 check_duplicates() to mark
- breakpoints of any of these types to be a duplicate of an actual
- breakpoint at address zero:
+ have a zero valued 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:
bp_watchpoint
bp_hardware_watchpoint
&& type != bp_catchpoint);
}
-/* Rescan breakpoints at the same address and section as BPT,
- marking the first one as "first" and any others as "duplicates".
- This is so that the bpt instruction is only inserted once.
- If we have a permanent breakpoint at the same place as BPT, make
- that one the official one, and the rest as duplicates. */
-
-static void
-check_duplicates_for (CORE_ADDR address, struct obj_section *section)
-{
- struct bp_location *b;
- int count = 0;
- struct bp_location *perm_bp = 0;
-
- ALL_BP_LOCATIONS (b)
- if (b->owner->enable_state != bp_disabled
- && b->owner->enable_state != bp_call_disabled
- && b->owner->enable_state != bp_startup_disabled
- && b->enabled
- && !b->shlib_disabled
- && b->address == address /* address / overlay match */
- && (!overlay_debugging || b->section == section)
- && breakpoint_address_is_meaningful (b->owner))
- {
- /* Have we found a permanent breakpoint? */
- if (b->owner->enable_state == bp_permanent)
- {
- perm_bp = b;
- break;
- }
-
- count++;
- b->duplicate = count > 1;
- }
-
- /* If we found a permanent breakpoint at this address, go over the
- list again and declare all the other breakpoints there (except
- other permanent breakpoints) to be the duplicates. */
- if (perm_bp)
- {
- perm_bp->duplicate = 0;
-
- /* Permanent breakpoint should always be inserted. */
- if (! perm_bp->inserted)
- internal_error (__FILE__, __LINE__,
- _("allegedly permanent breakpoint is not "
- "actually inserted"));
-
- ALL_BP_LOCATIONS (b)
- if (b != perm_bp)
- {
- if (b->owner->enable_state != bp_permanent
- && b->owner->enable_state != bp_disabled
- && b->owner->enable_state != bp_call_disabled
- && b->owner->enable_state != bp_startup_disabled
- && b->enabled && !b->shlib_disabled
- && b->address == address /* address / overlay match */
- && (!overlay_debugging || b->section == section)
- && breakpoint_address_is_meaningful (b->owner))
- {
- if (b->inserted)
- internal_error (__FILE__, __LINE__,
- _("another breakpoint was inserted on top of "
- "a permanent breakpoint"));
-
- b->duplicate = 1;
- }
- }
- }
-}
+/* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
+ same breakpoint location. In most targets, this can only be true
+ if ASPACE1 matches ASPACE2. On targets that have global
+ breakpoints, the address space doesn't really matter. */
-static void
-check_duplicates (struct breakpoint *bpt)
+static int
+breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
+ struct address_space *aspace2, CORE_ADDR addr2)
{
- struct bp_location *bl = bpt->loc;
-
- if (! breakpoint_address_is_meaningful (bpt))
- return;
-
- for (; bl; bl = bl->next)
- check_duplicates_for (bl->address, bl->section);
+ return ((gdbarch_has_global_breakpoints (target_gdbarch)
+ || aspace1 == aspace2)
+ && addr1 == addr2);
}
static void
b->frame_id = null_frame_id;
b->forked_inferior_pid = null_ptid;
b->exec_pathname = NULL;
+ b->syscalls_to_be_caught = NULL;
b->ops = NULL;
b->condition_not_parsed = 0;
if (!loc_gdbarch)
loc_gdbarch = b->gdbarch;
+ if (bptype != bp_catchpoint)
+ gdb_assert (sal.pspace != NULL);
+
/* Adjust the breakpoint's address prior to allocating a location.
Once we call allocate_bp_location(), that mostly uninitialized
location will be placed on the location chain. Adjustment of the
b->loc->gdbarch = loc_gdbarch;
b->loc->requested_address = sal.pc;
b->loc->address = adjusted_address;
+ b->loc->pspace = sal.pspace;
+
+ /* Store the program space that was used to set the breakpoint, for
+ breakpoint resetting. */
+ b->pspace = sal.pspace;
if (sal.symtab == NULL)
b->source_file = NULL;
longjmp "master" breakpoints. Here, we simply create momentary
clones of those and enable them for the requested thread. */
ALL_BREAKPOINTS_SAFE (b, temp)
- if (b->type == bp_longjmp_master)
+ if (b->pspace == current_program_space
+ && b->type == bp_longjmp_master)
{
struct breakpoint *clone = clone_momentary_breakpoint (b);
clone->type = bp_longjmp;
struct breakpoint *b, *temp;
ALL_BREAKPOINTS_SAFE (b, temp)
- if (b->type == bp_thread_event)
+ if (b->type == bp_thread_event
+ && b->loc->pspace == current_program_space)
delete_breakpoint (b);
}
struct breakpoint *b, *temp;
ALL_BREAKPOINTS_SAFE (b, temp)
- if (b->type == bp_shlib_event)
+ if (b->type == bp_shlib_event
+ && b->loc->pspace == current_program_space)
delete_breakpoint (b);
}
void
disable_breakpoints_in_shlibs (void)
{
- struct bp_location *loc;
+ struct bp_location *loc, **locp_tmp;
- ALL_BP_LOCATIONS (loc)
+ ALL_BP_LOCATIONS (loc, locp_tmp)
{
struct breakpoint *b = loc->owner;
/* We apply the check to all breakpoints, including disabled
if (((b->type == bp_breakpoint)
|| (b->type == bp_hardware_breakpoint)
|| (b->type == bp_tracepoint))
+ && loc->pspace == current_program_space
&& !loc->shlib_disabled
#ifdef PC_SOLIB
&& PC_SOLIB (loc->address)
#else
- && solib_name_from_address (loc->address)
+ && solib_name_from_address (loc->pspace, loc->address)
#endif
)
{
static void
disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
{
- struct bp_location *loc;
+ struct bp_location *loc, **locp_tmp;
int disabled_shlib_breaks = 0;
/* SunOS a.out shared libraries are always mapped, so do not
&& bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
return;
- ALL_BP_LOCATIONS (loc)
+ ALL_BP_LOCATIONS (loc, locp_tmp)
{
struct breakpoint *b = loc->owner;
if ((loc->loc_type == bp_loc_hardware_breakpoint
|| loc->loc_type == bp_loc_software_breakpoint)
+ && solib->pspace == loc->pspace
&& !loc->shlib_disabled
&& (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
&& solib_contains_address_p (solib, loc->address))
print_mention_catch_vfork
};
-/* Create a new breakpoint of the bp_catchpoint kind and return it.
-
- If TEMPFLAG is non-zero, then make the breakpoint temporary.
- If COND_STRING is not NULL, then store it in the breakpoint.
- OPS, if not NULL, is the breakpoint_ops structure associated
- to the catchpoint. */
+/* Implement the "insert" breakpoint_ops method for syscall
+ catchpoints. */
-static struct breakpoint *
-create_catchpoint (struct gdbarch *gdbarch, int tempflag,
- char *cond_string, struct breakpoint_ops *ops)
+static void
+insert_catch_syscall (struct breakpoint *b)
{
- struct symtab_and_line sal;
- struct breakpoint *b;
-
- init_sal (&sal);
- sal.pc = 0;
- sal.symtab = NULL;
- sal.line = 0;
-
- b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
- set_breakpoint_count (breakpoint_count + 1);
- b->number = breakpoint_count;
-
- b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
- b->thread = -1;
- b->addr_string = NULL;
- b->enable_state = bp_enabled;
- b->disposition = tempflag ? disp_del : disp_donttouch;
- b->ops = ops;
+ struct inferior *inf = current_inferior ();
- mention (b);
- update_global_location_list (1);
+ ++inf->total_syscalls_count;
+ if (!b->syscalls_to_be_caught)
+ ++inf->any_syscall_count;
+ else
+ {
+ int i, iter;
+ for (i = 0;
+ VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+ i++)
+ {
+ int elem;
+ if (iter >= VEC_length (int, inf->syscalls_counts))
+ {
+ int old_size = VEC_length (int, inf->syscalls_counts);
+ uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
+ uintptr_t vec_addr;
+ VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
+ vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
+ vec_addr_offset;
+ memset ((void *) vec_addr, 0,
+ (iter + 1 - old_size) * sizeof (int));
+ }
+ elem = VEC_index (int, inf->syscalls_counts, iter);
+ VEC_replace (int, inf->syscalls_counts, iter, ++elem);
+ }
+ }
- return b;
+ target_set_syscall_catchpoint (PIDGET (inferior_ptid),
+ inf->total_syscalls_count != 0,
+ inf->any_syscall_count,
+ VEC_length (int, inf->syscalls_counts),
+ VEC_address (int, inf->syscalls_counts));
}
-static void
-create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
- int tempflag, char *cond_string,
- struct breakpoint_ops *ops)
-{
- struct breakpoint *b
- = create_catchpoint (gdbarch, tempflag, cond_string, ops);
+/* Implement the "remove" breakpoint_ops method for syscall
+ catchpoints. */
- /* FIXME: We should put this information in a breakpoint private data
- area. */
- b->forked_inferior_pid = null_ptid;
-}
+static int
+remove_catch_syscall (struct breakpoint *b)
+{
+ struct inferior *inf = current_inferior ();
-/* Exec catchpoints. */
+ --inf->total_syscalls_count;
+ if (!b->syscalls_to_be_caught)
+ --inf->any_syscall_count;
+ else
+ {
+ int i, iter;
+ for (i = 0;
+ VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+ i++)
+ {
+ int elem;
+ if (iter >= VEC_length (int, inf->syscalls_counts))
+ /* Shouldn't happen. */
+ continue;
+ elem = VEC_index (int, inf->syscalls_counts, iter);
+ VEC_replace (int, inf->syscalls_counts, iter, --elem);
+ }
+ }
-static void
-insert_catch_exec (struct breakpoint *b)
-{
- target_insert_exec_catchpoint (PIDGET (inferior_ptid));
+ return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
+ inf->total_syscalls_count != 0,
+ inf->any_syscall_count,
+ VEC_length (int, inf->syscalls_counts),
+ VEC_address (int, inf->syscalls_counts));
}
+/* Implement the "breakpoint_hit" breakpoint_ops method for syscall
+ catchpoints. */
+
static int
-remove_catch_exec (struct breakpoint *b)
+breakpoint_hit_catch_syscall (struct breakpoint *b)
+{
+ /* We must check if we are catching specific syscalls in this breakpoint.
+ If we are, then we must guarantee that the called syscall is the same
+ syscall we are catching. */
+ int syscall_number = 0;
+
+ if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
+ return 0;
+
+ /* Now, checking if the syscall is the same. */
+ if (b->syscalls_to_be_caught)
+ {
+ int i, iter;
+ for (i = 0;
+ VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+ i++)
+ if (syscall_number == iter)
+ break;
+ /* Not the same. */
+ if (!iter)
+ return 0;
+ }
+
+ return 1;
+}
+
+/* Implement the "print_it" breakpoint_ops method for syscall
+ catchpoints. */
+
+static enum print_stop_action
+print_it_catch_syscall (struct breakpoint *b)
+{
+ /* These are needed because we want to know in which state a
+ syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
+ or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
+ must print "called syscall" or "returned from syscall". */
+ ptid_t ptid;
+ struct target_waitstatus last;
+ struct syscall s;
+ struct cleanup *old_chain;
+ char *syscall_id;
+
+ get_last_target_status (&ptid, &last);
+
+ get_syscall_by_number (last.value.syscall_number, &s);
+
+ annotate_catchpoint (b->number);
+
+ if (s.name == NULL)
+ syscall_id = xstrprintf ("%d", last.value.syscall_number);
+ else
+ syscall_id = xstrprintf ("'%s'", s.name);
+
+ old_chain = make_cleanup (xfree, syscall_id);
+
+ if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
+ printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
+ b->number, syscall_id);
+ else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
+ printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
+ b->number, syscall_id);
+
+ do_cleanups (old_chain);
+
+ return PRINT_SRC_AND_LOC;
+}
+
+/* Implement the "print_one" breakpoint_ops method for syscall
+ catchpoints. */
+
+static void
+print_one_catch_syscall (struct breakpoint *b,
+ struct bp_location **last_loc)
+{
+ struct value_print_options opts;
+
+ get_user_print_options (&opts);
+ /* Field 4, the address, is omitted (which makes the columns
+ not line up too nicely with the headers, but the effect
+ is relatively readable). */
+ if (opts.addressprint)
+ ui_out_field_skip (uiout, "addr");
+ annotate_field (5);
+
+ if (b->syscalls_to_be_caught
+ && VEC_length (int, b->syscalls_to_be_caught) > 1)
+ ui_out_text (uiout, "syscalls \"");
+ else
+ ui_out_text (uiout, "syscall \"");
+
+ if (b->syscalls_to_be_caught)
+ {
+ int i, iter;
+ char *text = xstrprintf ("%s", "");
+ for (i = 0;
+ VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+ i++)
+ {
+ char *x = text;
+ struct syscall s;
+ get_syscall_by_number (iter, &s);
+
+ if (s.name != NULL)
+ text = xstrprintf ("%s%s, ", text, s.name);
+ else
+ text = xstrprintf ("%s%d, ", text, iter);
+
+ /* We have to xfree the last 'text' (now stored at 'x')
+ because xstrprintf dinamically allocates new space for it
+ on every call. */
+ xfree (x);
+ }
+ /* Remove the last comma. */
+ text[strlen (text) - 2] = '\0';
+ ui_out_field_string (uiout, "what", text);
+ }
+ else
+ ui_out_field_string (uiout, "what", "<any syscall>");
+ ui_out_text (uiout, "\" ");
+}
+
+/* Implement the "print_mention" breakpoint_ops method for syscall
+ catchpoints. */
+
+static void
+print_mention_catch_syscall (struct breakpoint *b)
+{
+ if (b->syscalls_to_be_caught)
+ {
+ int i, iter;
+
+ if (VEC_length (int, b->syscalls_to_be_caught) > 1)
+ printf_filtered (_("Catchpoint %d (syscalls"), b->number);
+ else
+ printf_filtered (_("Catchpoint %d (syscall"), b->number);
+
+ for (i = 0;
+ VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+ i++)
+ {
+ struct syscall s;
+ get_syscall_by_number (iter, &s);
+
+ if (s.name)
+ printf_filtered (" '%s' [%d]", s.name, s.number);
+ else
+ printf_filtered (" %d", s.number);
+ }
+ printf_filtered (")");
+ }
+ else
+ printf_filtered (_("Catchpoint %d (any syscall)"),
+ b->number);
+}
+
+/* The breakpoint_ops structure to be used in syscall catchpoints. */
+
+static struct breakpoint_ops catch_syscall_breakpoint_ops =
+{
+ insert_catch_syscall,
+ remove_catch_syscall,
+ breakpoint_hit_catch_syscall,
+ print_it_catch_syscall,
+ print_one_catch_syscall,
+ print_mention_catch_syscall
+};
+
+/* Returns non-zero if 'b' is a syscall catchpoint. */
+
+static int
+syscall_catchpoint_p (struct breakpoint *b)
+{
+ return (b->ops == &catch_syscall_breakpoint_ops);
+}
+
+/* Create a new breakpoint of the bp_catchpoint kind and return it,
+ but does NOT mention it nor update the global location list.
+ This is useful if you need to fill more fields in the
+ struct breakpoint before calling mention.
+
+ If TEMPFLAG is non-zero, then make the breakpoint temporary.
+ If COND_STRING is not NULL, then store it in the breakpoint.
+ OPS, if not NULL, is the breakpoint_ops structure associated
+ to the catchpoint. */
+
+static struct breakpoint *
+create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
+ char *cond_string,
+ struct breakpoint_ops *ops)
+{
+ struct symtab_and_line sal;
+ struct breakpoint *b;
+
+ init_sal (&sal);
+ sal.pspace = current_program_space;
+
+ b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
+ set_breakpoint_count (breakpoint_count + 1);
+ b->number = breakpoint_count;
+
+ b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
+ b->thread = -1;
+ b->addr_string = NULL;
+ b->enable_state = bp_enabled;
+ b->disposition = tempflag ? disp_del : disp_donttouch;
+ b->ops = ops;
+
+ return b;
+}
+
+/* Create a new breakpoint of the bp_catchpoint kind and return it.
+
+ If TEMPFLAG is non-zero, then make the breakpoint temporary.
+ If COND_STRING is not NULL, then store it in the breakpoint.
+ OPS, if not NULL, is the breakpoint_ops structure associated
+ to the catchpoint. */
+
+static struct breakpoint *
+create_catchpoint (struct gdbarch *gdbarch, int tempflag,
+ char *cond_string, struct breakpoint_ops *ops)
+{
+ struct breakpoint *b =
+ create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
+
+ mention (b);
+ update_global_location_list (1);
+
+ return b;
+}
+
+static void
+create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
+ int tempflag, char *cond_string,
+ struct breakpoint_ops *ops)
+{
+ struct breakpoint *b
+ = create_catchpoint (gdbarch, tempflag, cond_string, ops);
+
+ /* FIXME: We should put this information in a breakpoint private data
+ area. */
+ b->forked_inferior_pid = null_ptid;
+}
+
+/* Exec catchpoints. */
+
+static void
+insert_catch_exec (struct breakpoint *b)
+{
+ target_insert_exec_catchpoint (PIDGET (inferior_ptid));
+}
+
+static int
+remove_catch_exec (struct breakpoint *b)
{
return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
}
print_mention_catch_exec
};
+static void
+create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
+ struct breakpoint_ops *ops)
+{
+ struct gdbarch *gdbarch = get_current_arch ();
+ struct breakpoint *b =
+ create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
+
+ b->syscalls_to_be_caught = filter;
+
+ /* Now, we have to mention the breakpoint and update the global
+ location list. */
+ mention (b);
+ update_global_location_list (1);
+}
+
static int
hw_breakpoint_used_count (void)
{
ALL_BREAKPOINTS (b)
{
+ if (b->pspace != current_program_space)
+ continue;
+
if ((b->type == bp_breakpoint
|| b->type == bp_hardware_breakpoint)
&& breakpoint_enabled (b))
if (found)
update_global_location_list (0);
- executing_startup = 1;
+ current_program_space->executing_startup = 1;
}
void
struct breakpoint *b;
int found = 0;
- executing_startup = 0;
+ current_program_space->executing_startup = 0;
ALL_BREAKPOINTS (b)
{
+ if (b->pspace != current_program_space)
+ continue;
+
if ((b->type == bp_breakpoint
|| b->type == bp_hardware_breakpoint)
&& b->enable_state == bp_startup_disabled)
copy->loc->requested_address = orig->loc->requested_address;
copy->loc->address = orig->loc->address;
copy->loc->section = orig->loc->section;
+ copy->loc->pspace = orig->loc->pspace;
if (orig->source_file == NULL)
copy->source_file = NULL;
copy->line_number = orig->line_number;
copy->frame_id = orig->frame_id;
copy->thread = orig->thread;
+ copy->pspace = orig->pspace;
copy->enable_state = bp_enabled;
copy->disposition = disp_donttouch;
loc->requested_address = sal->pc;
loc->address = adjust_breakpoint_address (loc->gdbarch,
loc->requested_address, b->type);
+ loc->pspace = sal->pspace;
+ gdb_assert (loc->pspace != NULL);
loc->section = sal->section;
set_breakpoint_location_function (loc);
/* Enable the automatic memory restoration from breakpoints while
we read the memory. Otherwise we could say about our temporary
breakpoints they are permanent. */
- cleanup = make_show_memory_breakpoints_cleanup (0);
+ cleanup = save_current_space_and_thread ();
+
+ switch_to_program_space_and_thread (loc->pspace);
+ make_show_memory_breakpoints_cleanup (0);
if (target_read_memory (loc->address, target_mem, len) == 0
&& memcmp (target_mem, brk, len) == 0)
error (_("Hardware breakpoints used exceeds limit."));
}
+ gdb_assert (sals.nelts > 0);
+
for (i = 0; i < sals.nelts; ++i)
{
struct symtab_and_line sal = sals.sals[i];
loc_gdbarch = gdbarch;
describe_other_breakpoints (loc_gdbarch,
- sal.pc, sal.section, thread);
+ sal.pspace, sal.pc, sal.section, thread);
}
if (i == 0)
b->enable_state = enabled ? bp_enabled : bp_disabled;
b->disposition = disposition;
- if (enabled && executing_startup
+ b->pspace = sals.sals[0].pspace;
+
+ if (enabled && b->pspace->executing_startup
&& (b->type == bp_breakpoint
|| b->type == bp_hardware_breakpoint))
b->enable_state = bp_startup_disabled;
--(sal->nelts);
}
-/* If appropriate, obtains all sals that correspond
- to the same file and line as SAL. This is done
- only if SAL does not have explicit PC and has
- line and file information. If we got just a single
- expanded sal, return the original.
+/* If appropriate, obtains all sals that correspond to the same file
+ and line as SAL, in all program spaces. Users debugging with IDEs,
+ will want to set a breakpoint at foo.c:line, and not really care
+ about program spaces. This is done only if SAL does not have
+ explicit PC and has line and file information. If we got just a
+ single expanded sal, return the original.
- Otherwise, if SAL.explicit_line is not set, filter out
- all sals for which the name of enclosing function
- is different from SAL. This makes sure that if we have
- breakpoint originally set in template instantiation, say
- foo<int>(), we won't expand SAL to locations at the same
- line in all existing instantiations of 'foo'.
+ Otherwise, if SAL.explicit_line is not set, filter out all sals for
+ which the name of enclosing function is different from SAL. This
+ makes sure that if we have breakpoint originally set in template
+ instantiation, say foo<int>(), we won't expand SAL to locations at
+ the same line in all existing instantiations of 'foo'. */
-*/
static struct symtabs_and_lines
expand_line_sal_maybe (struct symtab_and_line sal)
{
char *original_function = NULL;
int found;
int i;
+ struct cleanup *old_chain;
/* If we have explicit pc, don't expand.
If we have no line number, we can't expand. */
}
sal.pc = 0;
+
+ old_chain = save_current_space_and_thread ();
+
+ switch_to_program_space_and_thread (sal.pspace);
+
find_pc_partial_function (original_pc, &original_function, NULL, NULL);
-
+
+ /* Note that expand_line_sal visits *all* program spaces. */
expanded = expand_line_sal (sal);
+
if (expanded.nelts == 1)
{
/* We had one sal, we got one sal. Without futher
expanded.sals = xmalloc (sizeof (struct symtab_and_line));
sal.pc = original_pc;
expanded.sals[0] = sal;
+ do_cleanups (old_chain);
return expanded;
}
{
CORE_ADDR pc = expanded.sals[i].pc;
char *this_function;
+
+ /* We need to switch threads as well since we're about to
+ read memory. */
+ switch_to_program_space_and_thread (expanded.sals[i].pspace);
+
if (find_pc_partial_function (pc, &this_function,
&func_addr, &func_end))
{
}
}
-
+ do_cleanups (old_chain);
+
if (expanded.nelts <= 1)
{
/* This is un ugly workaround. If we get zero
sal.pc = default_breakpoint_address;
sal.line = default_breakpoint_line;
sal.symtab = default_breakpoint_symtab;
+ sal.pspace = default_breakpoint_pspace;
sal.section = find_pc_overlay (sal.pc);
/* "break" without arguments is equivalent to "break *PC" where PC is
b->condition_not_parsed = 1;
b->ops = ops;
b->enable_state = enabled ? bp_enabled : bp_disabled;
+ b->pspace = current_program_space;
- if (enabled && executing_startup
+ if (enabled && b->pspace->executing_startup
&& (b->type == bp_breakpoint
|| b->type == bp_hardware_breakpoint))
b->enable_state = bp_startup_disabled;
static void
skip_prologue_sal (struct symtab_and_line *sal)
{
- struct symbol *sym = find_pc_function (sal->pc);
+ struct symbol *sym;
struct symtab_and_line start_sal;
+ struct cleanup *old_chain;
- if (sym == NULL)
- return;
+ old_chain = save_current_space_and_thread ();
- start_sal = find_function_start_sal (sym, 1);
- if (sal->pc < start_sal.pc)
+ sym = find_pc_function (sal->pc);
+ if (sym != NULL)
{
- start_sal.explicit_line = sal->explicit_line;
- start_sal.explicit_pc = sal->explicit_pc;
- *sal = start_sal;
+ start_sal = find_function_start_sal (sym, 1);
+ if (sal->pc < start_sal.pc)
+ {
+ start_sal.explicit_line = sal->explicit_line;
+ start_sal.explicit_pc = sal->explicit_pc;
+ *sal = start_sal;
+ }
}
+
+ do_cleanups (old_chain);
}
/* Helper function for break_command_1 and disassemble_command. */
source). */
struct minimal_symbol *msym;
+ struct cleanup *old_chain = save_current_space_and_thread ();
+
+ switch_to_program_space_and_thread (sal->pspace);
msym = lookup_minimal_symbol_by_pc (sal->pc);
if (msym)
sal->section = SYMBOL_OBJ_SECTION (msym);
+
+ do_cleanups (old_chain);
}
}
}
}
}
+ sal.pspace = current_program_space;
+
/* Parse the rest of the arguments. */
innermost_block = NULL;
exp_start = arg;
if (!loc_gdbarch)
loc_gdbarch = gdbarch;
- describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1);
+ describe_other_breakpoints (loc_gdbarch,
+ sal.pspace, sal.pc, sal.section, -1);
/* FIXME: brobecker/2006-12-28: Actually, re-implement a special
version for exception catchpoints, because two catchpoints
used for different exception names will use the same address.
from_tty);
}
+/* Cleanup function for a syscall filter list. */
+static void
+clean_up_filters (void *arg)
+{
+ VEC(int) *iter = *(VEC(int) **) arg;
+ VEC_free (int, iter);
+}
+
+/* Splits the argument using space as delimiter. Returns an xmalloc'd
+ filter list, or NULL if no filtering is required. */
+static VEC(int) *
+catch_syscall_split_args (char *arg)
+{
+ VEC(int) *result = NULL;
+ struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
+
+ while (*arg != '\0')
+ {
+ int i, syscall_number;
+ char *endptr;
+ char cur_name[128];
+ struct syscall s;
+
+ /* Skip whitespace. */
+ while (isspace (*arg))
+ arg++;
+
+ for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
+ cur_name[i] = arg[i];
+ cur_name[i] = '\0';
+ arg += i;
+
+ /* Check if the user provided a syscall name or a number. */
+ syscall_number = (int) strtol (cur_name, &endptr, 0);
+ if (*endptr == '\0')
+ get_syscall_by_number (syscall_number, &s);
+ else
+ {
+ /* We have a name. Let's check if it's valid and convert it
+ to a number. */
+ get_syscall_by_name (cur_name, &s);
+
+ if (s.number == UNKNOWN_SYSCALL)
+ /* Here we have to issue an error instead of a warning, because
+ GDB cannot do anything useful if there's no syscall number to
+ be caught. */
+ error (_("Unknown syscall name '%s'."), cur_name);
+ }
+
+ /* Ok, it's valid. */
+ VEC_safe_push (int, result, s.number);
+ }
+
+ discard_cleanups (cleanup);
+ return result;
+}
+
+/* Implement the "catch syscall" command. */
+
+static void
+catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
+{
+ int tempflag;
+ VEC(int) *filter;
+ struct syscall s;
+ struct gdbarch *gdbarch = get_current_arch ();
+
+ /* Checking if the feature if supported. */
+ if (gdbarch_get_syscall_number_p (gdbarch) == 0)
+ error (_("The feature 'catch syscall' is not supported on \
+this architeture yet."));
+
+ tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+
+ ep_skip_leading_whitespace (&arg);
+
+ /* We need to do this first "dummy" translation in order
+ to get the syscall XML file loaded or, most important,
+ to display a warning to the user if there's no XML file
+ for his/her architecture. */
+ get_syscall_by_number (0, &s);
+
+ /* The allowed syntax is:
+ catch syscall
+ catch syscall <name | number> [<name | number> ... <name | number>]
+
+ Let's check if there's a syscall name. */
+
+ if (arg != NULL)
+ filter = catch_syscall_split_args (arg);
+ else
+ filter = NULL;
+
+ create_syscall_event_catchpoint (tempflag, filter,
+ &catch_syscall_breakpoint_ops);
+}
+
/* Implement the "catch assert" command. */
static void
sal.line = default_breakpoint_line;
sal.symtab = default_breakpoint_symtab;
sal.pc = default_breakpoint_address;
+ sal.pspace = default_breakpoint_pspace;
if (sal.symtab == 0)
error (_("No source file specified."));
struct bp_location *loc = b->loc;
for (; loc; loc = loc->next)
{
- int pc_match = sal.pc
+ int pc_match = sal.pc
+ && (loc->pspace == sal.pspace)
&& (loc->address == sal.pc)
&& (!section_is_overlay (loc->section)
|| loc->section == sal.section);
int line_match = ((default_match || (0 == sal.pc))
&& b->source_file != NULL
&& sal.symtab != NULL
+ && sal.pspace == loc->pspace
&& strcmp (b->source_file, sal.symtab->filename) == 0
&& b->line_number == sal.line);
if (pc_match || line_match)
}
}
-/* A cleanup function which destroys a vector. */
+/* A comparison function for bp_location A and B being interfaced to qsort.
+ Sort elements primarily by their ADDRESS (no matter what does
+ breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
+ first bp_permanent OWNERed elements and terciarily just ensuring the array
+ is sorted stable way despite qsort being an instable algorithm. */
+
+static int
+bp_location_compare (struct bp_location *a, struct bp_location *b)
+{
+ int a_perm = a->owner->enable_state == bp_permanent;
+ int b_perm = b->owner->enable_state == bp_permanent;
+
+ if (a->address != b->address)
+ return (a->address > b->address) - (a->address < b->address);
+
+ /* Sort permanent breakpoints first. */
+ if (a_perm != b_perm)
+ return (a_perm < b_perm) - (a_perm > b_perm);
+
+ /* Make the user-visible order stable across GDB runs. Locations of the same
+ breakpoint can be sorted in arbitrary order. */
+
+ if (a->owner->number != b->owner->number)
+ return (a->owner->number > b->owner->number)
+ - (a->owner->number < b->owner->number);
+
+ return (a > b) - (a < b);
+}
+
+/* Interface bp_location_compare as the COMPAR parameter of qsort function. */
+
+static int
+bp_location_compare_for_qsort (const void *ap, const void *bp)
+{
+ struct bp_location *a = *(void **) ap;
+ struct bp_location *b = *(void **) bp;
+
+ return bp_location_compare (a, b);
+}
+
+/* Set bp_location_placed_address_before_address_max and
+ bp_location_shadow_len_after_address_max according to the current content of
+ the bp_location array. */
static void
-do_vec_free (void *p)
+bp_location_target_extensions_update (void)
{
- VEC(bp_location_p) **vec = p;
- if (*vec)
- VEC_free (bp_location_p, *vec);
+ struct bp_location *bl, **blp_tmp;
+
+ bp_location_placed_address_before_address_max = 0;
+ bp_location_shadow_len_after_address_max = 0;
+
+ ALL_BP_LOCATIONS (bl, blp_tmp)
+ {
+ CORE_ADDR start, end, addr;
+
+ if (!bp_location_has_shadow (bl))
+ continue;
+
+ start = bl->target_info.placed_address;
+ end = start + bl->target_info.shadow_len;
+
+ gdb_assert (bl->address >= start);
+ addr = bl->address - start;
+ if (addr > bp_location_placed_address_before_address_max)
+ bp_location_placed_address_before_address_max = addr;
+
+ /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
+
+ gdb_assert (bl->address < end);
+ addr = end - bl->address;
+ if (addr > bp_location_shadow_len_after_address_max)
+ bp_location_shadow_len_after_address_max = addr;
+ }
}
/* If SHOULD_INSERT is false, do not insert any breakpoint locations
update_global_location_list (int should_insert)
{
struct breakpoint *b;
- struct bp_location **next = &bp_location_chain;
- struct bp_location *loc;
- struct bp_location *loc2;
- VEC(bp_location_p) *old_locations = NULL;
- int ret;
- int ix;
+ struct bp_location **locp, *loc;
struct cleanup *cleanups;
- cleanups = make_cleanup (do_vec_free, &old_locations);
- /* Store old locations for future reference. */
- for (loc = bp_location_chain; loc; loc = loc->global_next)
- VEC_safe_push (bp_location_p, old_locations, loc);
+ /* The first bp_location being the only one non-DUPLICATE for the current run
+ of the same ADDRESS. */
+ struct bp_location *loc_first;
+
+ /* Saved former bp_location array which we compare against the newly built
+ bp_location from the current state of ALL_BREAKPOINTS. */
+ struct bp_location **old_location, **old_locp;
+ unsigned old_location_count;
+
+ old_location = bp_location;
+ old_location_count = bp_location_count;
+ bp_location = NULL;
+ bp_location_count = 0;
+ cleanups = make_cleanup (xfree, old_location);
- bp_location_chain = NULL;
ALL_BREAKPOINTS (b)
- {
- for (loc = b->loc; loc; loc = loc->next)
- {
- *next = loc;
- next = &(loc->global_next);
- *next = NULL;
- }
- }
+ for (loc = b->loc; loc; loc = loc->next)
+ bp_location_count++;
+
+ bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
+ locp = bp_location;
+ ALL_BREAKPOINTS (b)
+ for (loc = b->loc; loc; loc = loc->next)
+ *locp++ = loc;
+ qsort (bp_location, bp_location_count, sizeof (*bp_location),
+ bp_location_compare_for_qsort);
+
+ bp_location_target_extensions_update ();
/* Identify bp_location instances that are no longer present in the new
list, and therefore should be freed. Note that it's not necessary that
those locations should be removed from inferior -- if there's another
location at the same address (previously marked as duplicate),
- we don't need to remove/insert the location. */
- for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
+ we don't need to remove/insert the location.
+
+ LOCP is kept in sync with OLD_LOCP, each pointing to the current and
+ former bp_location array state respectively. */
+
+ locp = bp_location;
+ for (old_locp = old_location; old_locp < old_location + old_location_count;
+ old_locp++)
{
- /* Tells if 'loc' is found amoung the new locations. If not, we
+ struct bp_location *old_loc = *old_locp;
+
+ /* Tells if 'old_loc' is found amoung the new locations. If not, we
have to free it. */
- int found_object = 0;
+ int found_object;
/* Tells if the location should remain inserted in the target. */
int keep_in_target = 0;
int removed = 0;
- for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
- if (loc2 == loc)
- {
- found_object = 1;
- break;
- }
+
+ /* Skip LOCP entries which will definitely never be needed. Stop either
+ at or being the one matching OLD_LOC. */
+ while (locp < bp_location + bp_location_count
+ && bp_location_compare (*locp, old_loc) < 0)
+ locp++;
+ found_object = locp < bp_location + bp_location_count && *locp == old_loc;
/* If this location is no longer present, and inserted, look if there's
maybe a new location at the same address. If so, mark that one
don't have a time window where a breakpoint at certain location is not
inserted. */
- if (loc->inserted)
+ if (old_loc->inserted)
{
/* If the location is inserted now, we might have to remove it. */
- if (found_object && should_be_inserted (loc))
+ if (found_object && should_be_inserted (old_loc))
{
/* The location is still present in the location list, and still
should be inserted. Don't do anything. */
/* The location is either no longer present, or got disabled.
See if there's another location at the same address, in which
case we don't need to remove this one from the target. */
- if (breakpoint_address_is_meaningful (loc->owner))
- for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
- {
- /* For the sake of should_insert_location. The
- call to check_duplicates will fix up this later. */
- loc2->duplicate = 0;
- if (should_be_inserted (loc2)
- && loc2 != loc && loc2->address == loc->address)
- {
- loc2->inserted = 1;
- loc2->target_info = loc->target_info;
- keep_in_target = 1;
- break;
- }
- }
+
+ if (breakpoint_address_is_meaningful (old_loc->owner))
+ {
+ struct bp_location **loc2p;
+
+ for (loc2p = locp;
+ loc2p < bp_location + bp_location_count
+ && breakpoint_address_match ((*loc2p)->pspace->aspace,
+ (*loc2p)->address,
+ old_loc->pspace->aspace,
+ old_loc->address);
+ loc2p++)
+ {
+ struct bp_location *loc2 = *loc2p;
+
+ /* For the sake of should_be_inserted.
+ Duplicates check below will fix up this later. */
+ loc2->duplicate = 0;
+ if (loc2 != old_loc && should_be_inserted (loc2))
+ {
+ loc2->inserted = 1;
+ loc2->target_info = old_loc->target_info;
+ keep_in_target = 1;
+ break;
+ }
+ }
+ }
}
if (!keep_in_target)
{
- if (remove_breakpoint (loc, mark_uninserted))
+ if (remove_breakpoint (old_loc, mark_uninserted))
{
/* This is just about all we can do. We could keep this
location on the global list, and try to remove it next
time, but there's no particular reason why we will
succeed next time.
- Note that at this point, loc->owner is still valid,
+ Note that at this point, old_loc->owner is still valid,
as delete_breakpoint frees the breakpoint only
after calling us. */
printf_filtered (_("warning: Error removing breakpoint %d\n"),
- loc->owner->number);
+ old_loc->owner->number);
}
removed = 1;
}
longer need to keep this breakpoint. This is just a
heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
which is usability issue, but not a correctness problem. */
- loc->events_till_retirement = 3 * (thread_count () + 1);
- loc->owner = NULL;
+ old_loc->events_till_retirement = 3 * (thread_count () + 1);
+ old_loc->owner = NULL;
- VEC_safe_push (bp_location_p, moribund_locations, loc);
+ VEC_safe_push (bp_location_p, moribund_locations, old_loc);
}
else
- free_bp_location (loc);
+ free_bp_location (old_loc);
}
}
- ALL_BREAKPOINTS (b)
+ /* Rescan breakpoints at the same address and section,
+ marking the first one as "first" and any others as "duplicates".
+ This is so that the bpt instruction is only inserted once.
+ If we have a permanent breakpoint at the same place as BPT, make
+ that one the official one, and the rest as duplicates. Permanent
+ breakpoints are sorted first for the same address. */
+
+ loc_first = NULL;
+ ALL_BP_LOCATIONS (loc, locp)
{
- check_duplicates (b);
+ struct breakpoint *b = loc->owner;
+
+ if (b->enable_state == bp_disabled
+ || b->enable_state == bp_call_disabled
+ || b->enable_state == bp_startup_disabled
+ || !loc->enabled
+ || loc->shlib_disabled
+ || !breakpoint_address_is_meaningful (b))
+ continue;
+
+ /* Permanent breakpoint should always be inserted. */
+ if (b->enable_state == bp_permanent && ! loc->inserted)
+ internal_error (__FILE__, __LINE__,
+ _("allegedly permanent breakpoint is not "
+ "actually inserted"));
+
+ if (loc_first == NULL
+ || (overlay_debugging && loc->section != loc_first->section)
+ || !breakpoint_address_match (loc->pspace->aspace, loc->address,
+ loc_first->pspace->aspace,
+ loc_first->address))
+ {
+ loc_first = loc;
+ loc->duplicate = 0;
+ continue;
+ }
+
+ loc->duplicate = 1;
+
+ if (loc_first->owner->enable_state == bp_permanent && loc->inserted
+ && b->enable_state != bp_permanent)
+ internal_error (__FILE__, __LINE__,
+ _("another breakpoint was inserted on top of "
+ "a permanent breakpoint"));
}
if (breakpoints_always_inserted_mode () && should_insert
xfree (bpt->source_file);
if (bpt->exec_pathname != NULL)
xfree (bpt->exec_pathname);
+ clean_up_filters (&bpt->syscalls_to_be_caught);
/* Be sure no bpstat's are pointing at it after it's been freed. */
/* FIXME, how can we find all bpstat's?
if (have_ambiguous_names)
{
for (; l; l = l->next)
- if (e->address == l->address)
+ if (breakpoint_address_match (e->pspace->aspace, e->address,
+ l->pspace->aspace, l->address))
{
l->enabled = 0;
break;
int i;
int not_found = 0;
int *not_found_ptr = ¬_found;
- struct symtabs_and_lines sals = {};
- struct symtabs_and_lines expanded;
+ struct symtabs_and_lines sals = {0};
+ struct symtabs_and_lines expanded = {0};
char *s;
enum enable_state save_enable;
struct gdb_exception e;
- struct cleanup *cleanups;
+ struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
switch (b->type)
{
set_language (b->language);
input_radix = b->input_radix;
s = b->addr_string;
+
+ save_current_space_and_thread ();
+ switch_to_program_space_and_thread (b->pspace);
+
TRY_CATCH (e, RETURN_MASK_ERROR)
{
sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
}
}
- if (not_found)
- break;
-
- gdb_assert (sals.nelts == 1);
- resolve_sal_pc (&sals.sals[0]);
- if (b->condition_not_parsed && s && s[0])
+ if (!not_found)
{
- char *cond_string = 0;
- int thread = -1;
- int task = 0;
-
- find_condition_and_thread (s, sals.sals[0].pc,
- &cond_string, &thread, &task);
- if (cond_string)
- b->cond_string = cond_string;
- b->thread = thread;
- b->task = task;
- b->condition_not_parsed = 0;
+ gdb_assert (sals.nelts == 1);
+
+ resolve_sal_pc (&sals.sals[0]);
+ if (b->condition_not_parsed && s && s[0])
+ {
+ char *cond_string = 0;
+ int thread = -1;
+ int task = 0;
+
+ find_condition_and_thread (s, sals.sals[0].pc,
+ &cond_string, &thread, &task);
+ if (cond_string)
+ b->cond_string = cond_string;
+ b->thread = thread;
+ b->task = task;
+ b->condition_not_parsed = 0;
+ }
+
+ expanded = expand_line_sal_maybe (sals.sals[0]);
}
- expanded = expand_line_sal_maybe (sals.sals[0]);
- cleanups = make_cleanup (xfree, sals.sals);
+
+ make_cleanup (xfree, sals.sals);
update_breakpoint_locations (b, expanded);
- do_cleanups (cleanups);
break;
case bp_watchpoint:
break;
}
+ do_cleanups (cleanups);
return 0;
}
struct breakpoint *b, *temp;
enum language save_language;
int save_input_radix;
+ struct cleanup *old_chain;
save_language = current_language->la_language;
save_input_radix = input_radix;
+ old_chain = save_current_program_space ();
+
ALL_BREAKPOINTS_SAFE (b, temp)
{
/* Format possible error msg */
jit_breakpoint_re_set ();
+ do_cleanups (old_chain);
+
create_overlay_event_breakpoint ("_ovly_debug_event");
create_longjmp_master_breakpoint ("longjmp");
create_longjmp_master_breakpoint ("_longjmp");
{
if (in_thread_list (inferior_ptid))
b->thread = pid_to_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
+ different program space from the original thread. Reset that
+ as well. */
+ b->loc->pspace = current_program_space;
}
}
someday. */
void *
-deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
+deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
+ struct address_space *aspace, CORE_ADDR pc)
{
struct bp_target_info *bp_tgt;
- bp_tgt = xmalloc (sizeof (struct bp_target_info));
- memset (bp_tgt, 0, sizeof (struct bp_target_info));
+ bp_tgt = XZALLOC (struct bp_target_info);
+ bp_tgt->placed_address_space = aspace;
bp_tgt->placed_address = pc;
+
if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
{
/* Could not insert the breakpoint. */
/* Create and insert a breakpoint for software single step. */
void
-insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc)
+insert_single_step_breakpoint (struct gdbarch *gdbarch,
+ struct address_space *aspace, CORE_ADDR next_pc)
{
void **bpt_p;
corresponding changes elsewhere where single step breakpoints are
handled, however. So, for now, we use this. */
- *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc);
+ *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
if (*bpt_p == NULL)
error (_("Could not insert single-step breakpoint at %s"),
paddress (gdbarch, next_pc));
/* Check whether a software single-step breakpoint is inserted at PC. */
static int
-single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
+single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
{
int i;
for (i = 0; i < 2; i++)
{
struct bp_target_info *bp_tgt = single_step_breakpoints[i];
- if (bp_tgt && bp_tgt->placed_address == pc)
+ if (bp_tgt
+ && breakpoint_address_match (bp_tgt->placed_address_space,
+ bp_tgt->placed_address,
+ aspace, pc))
return 1;
}
return 0;
}
+/* Returns 0 if 'bp' is NOT a syscall catchpoint,
+ non-zero otherwise. */
+static int
+is_syscall_catchpoint_enabled (struct breakpoint *bp)
+{
+ if (syscall_catchpoint_p (bp)
+ && bp->enable_state != bp_disabled
+ && bp->enable_state != bp_call_disabled)
+ return 1;
+ else
+ return 0;
+}
+
+int
+catch_syscall_enabled (void)
+{
+ struct inferior *inf = current_inferior ();
+
+ return inf->total_syscalls_count != 0;
+}
+
+int
+catching_syscall_number (int syscall_number)
+{
+ struct breakpoint *bp;
+
+ ALL_BREAKPOINTS (bp)
+ if (is_syscall_catchpoint_enabled (bp))
+ {
+ if (bp->syscalls_to_be_caught)
+ {
+ int i, iter;
+ for (i = 0;
+ VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
+ i++)
+ if (syscall_number == iter)
+ return 1;
+ }
+ else
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Complete syscall names. Used by "catch syscall". */
+static char **
+catch_syscall_completer (struct cmd_list_element *cmd,
+ char *text, char *word)
+{
+ const char **list = get_syscall_names ();
+ return (list == NULL) ? NULL : complete_on_enum (list, text, word);
+}
+
/* Tracepoint-specific operations. */
/* Set tracepoint count to NUM. */
add_catch_command (char *name, char *docstring,
void (*sfunc) (char *args, int from_tty,
struct cmd_list_element *command),
+ char **(*completer) (struct cmd_list_element *cmd,
+ char *text, char *word),
void *user_data_catch,
void *user_data_tcatch)
{
&catch_cmdlist);
set_cmd_sfunc (command, sfunc);
set_cmd_context (command, user_data_catch);
+ set_cmd_completer (command, completer);
command = add_cmd (name, class_breakpoint, NULL, docstring,
&tcatch_cmdlist);
set_cmd_sfunc (command, sfunc);
set_cmd_context (command, user_data_tcatch);
+ set_cmd_completer (command, completer);
+}
+
+static void
+clear_syscall_counts (int pid)
+{
+ struct inferior *inf = find_inferior_pid (pid);
+
+ inf->total_syscalls_count = 0;
+ inf->any_syscall_count = 0;
+ VEC_free (int, inf->syscalls_counts);
}
void
struct cmd_list_element *c;
observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
+ observer_attach_inferior_exit (clear_syscall_counts);
breakpoint_chain = 0;
/* Don't bother to call set_breakpoint_count. $bpnum isn't useful
Catch an exception, when caught.\n\
With an argument, catch only exceptions with the given name."),
catch_catch_command,
+ NULL,
CATCH_PERMANENT,
CATCH_TEMPORARY);
add_catch_command ("throw", _("\
Catch an exception, when thrown.\n\
With an argument, catch only exceptions with the given name."),
catch_throw_command,
+ NULL,
CATCH_PERMANENT,
CATCH_TEMPORARY);
add_catch_command ("fork", _("Catch calls to fork."),
catch_fork_command_1,
+ NULL,
(void *) (uintptr_t) catch_fork_permanent,
(void *) (uintptr_t) catch_fork_temporary);
add_catch_command ("vfork", _("Catch calls to vfork."),
catch_fork_command_1,
+ NULL,
(void *) (uintptr_t) catch_vfork_permanent,
(void *) (uintptr_t) catch_vfork_temporary);
add_catch_command ("exec", _("Catch calls to exec."),
catch_exec_command_1,
+ NULL,
+ CATCH_PERMANENT,
+ CATCH_TEMPORARY);
+ add_catch_command ("syscall", _("\
+Catch system calls by their names and/or numbers.\n\
+Arguments say which system calls to catch. If no arguments\n\
+are given, every system call will be caught.\n\
+Arguments, if given, should be one or more system call names\n\
+(if your system supports that), or system call numbers."),
+ catch_syscall_command_1,
+ catch_syscall_completer,
CATCH_PERMANENT,
CATCH_TEMPORARY);
add_catch_command ("exception", _("\
Catch Ada exceptions, when raised.\n\
With an argument, catch only exceptions with the given name."),
catch_ada_exception_command,
+ NULL,
CATCH_PERMANENT,
CATCH_TEMPORARY);
add_catch_command ("assert", _("\
Catch failed Ada assertions, when raised.\n\
With an argument, catch only exceptions with the given name."),
catch_assert_command,
+ NULL,
CATCH_PERMANENT,
CATCH_TEMPORARY);