* breakpoint.c (should_be_inserted): Don't insert breakpoints if
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 66252ba61360b7e2f1501257e4582c196a949d31..0034338a0ee261bc1bf0627ac9ea9872ec20d380 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include <ctype.h>
 #include "hashtab.h"
 #include "symtab.h"
 #include "frame.h"
 #include "breakpoint.h"
+#include "tracepoint.h"
 #include "gdbtypes.h"
 #include "expression.h"
 #include "gdbcore.h"
 #include "top.h"
 #include "wrapper.h"
 #include "valprint.h"
+#include "jit.h"
+#include "xml-syscall.h"
+
+/* readline include files */
+#include "readline/readline.h"
+#include "readline/history.h"
+
+/* readline defines this.  */
+#undef savestring
 
 #include "mi/mi-common.h"
 
@@ -96,16 +107,25 @@ static void break_command_1 (char *, int, int);
 
 static void mention (struct breakpoint *);
 
-struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
-
-static void check_duplicates (struct breakpoint *);
+/* This function is used in gdbtk sources and thus can not be made static.  */
+struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
+                                             struct symtab_and_line,
+                                             enum bptype);
 
 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
-static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
+static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
+                                           CORE_ADDR bpaddr,
                                             enum bptype bptype);
 
-static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int);
+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);
 
@@ -133,6 +153,7 @@ typedef enum
 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);
 
@@ -142,8 +163,6 @@ static int watchpoint_check (void *);
 
 static void maintenance_info_breakpoints (char *, int);
 
-static void create_overlay_event_breakpoint (char *);
-
 static int hw_breakpoint_used_count (void);
 
 static int hw_watchpoint_used_count (enum bptype, int *);
@@ -177,7 +196,8 @@ static void tcatch_command (char *arg, int from_tty);
 
 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);
 
@@ -191,6 +211,26 @@ static int is_hardware_watchpoint (struct breakpoint *bpt);
 
 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);
+
+static void enable_trace_command (char *, int);
+
+static void disable_trace_command (char *, int);
+
+static void trace_pass_command (char *, int);
+
+static void skip_prologue_sal (struct symtab_and_line *sal);
+
+
+/* Flag indicating that a command has proceeded the inferior past the
+   current breakpoint.  */
+
+static int breakpoint_proceeded;
+
 static const char *
 bpdisp_text (enum bpdisp disp)
 {
@@ -300,23 +340,50 @@ static int overlay_events_enabled;
             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(B,BP_TMP)                                     \
+       for (BP_TMP = bp_location;                                      \
+            BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
+            BP_TMP++)
 
-#define ALL_BP_LOCATIONS_SAFE(B,TMP)   \
-       for (B = bp_location_chain;     \
-            B ? (TMP=B->global_next, 1): 0;    \
-            B = TMP)
+/* Iterator for tracepoints only.  */
+
+#define ALL_TRACEPOINTS(B)  \
+  for (B = breakpoint_chain; B; B = B->next)  \
+    if ((B)->type == bp_tracepoint)
 
 /* Chains of all breakpoints defined.  */
 
 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;
 
@@ -324,6 +391,10 @@ VEC(bp_location_p) *moribund_locations = NULL;
 
 int breakpoint_count;
 
+/* Number of last tracepoint made.  */
+
+int tracepoint_count;
+
 /* Return whether a breakpoint is an active enabled breakpoint.  */
 static int
 breakpoint_enabled (struct breakpoint *b)
@@ -337,8 +408,7 @@ void
 set_breakpoint_count (int num)
 {
   breakpoint_count = num;
-  set_internalvar (lookup_internalvar ("bpnum"),
-                  value_from_longest (builtin_type_int32, (LONGEST) num));
+  set_internalvar_integer (lookup_internalvar ("bpnum"), num);
 }
 
 /* Used in run_command to zero the hit count when a new run starts. */
@@ -363,6 +433,8 @@ int default_breakpoint_valid;
 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.
@@ -390,16 +462,15 @@ get_number_trailer (char **pp, int trailer)
          to pass to lookup_internalvar().  */
       char *varname;
       char *start = ++p;
-      struct value *val;
+      LONGEST val;
 
       while (isalnum (*p) || *p == '_')
        p++;
       varname = (char *) alloca (p - start + 1);
       strncpy (varname, start, p - start);
       varname[p - start] = '\0';
-      val = value_of_internalvar (lookup_internalvar (varname));
-      if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
-       retval = (int) value_as_long (val);
+      if (get_internalvar_integer (lookup_internalvar (varname), &val))
+       retval = (int) val;
       else
        {
          printf_filtered (_("Convenience variable must have integer value.\n"));
@@ -521,6 +592,20 @@ get_number_or_range (char **pp)
   return last_retval;
 }
 
+/* Return the breakpoint with the specified number, or NULL
+   if the number does not refer to an existing breakpoint.  */
+
+struct breakpoint *
+get_breakpoint (int num)
+{
+  struct breakpoint *b;
+
+  ALL_BREAKPOINTS (b)
+    if (b->number == num)
+      return b;
+  
+  return NULL;
+}
 
 \f
 /* condition N EXP -- set break condition of breakpoint N to EXP.  */
@@ -566,7 +651,7 @@ condition_command (char *arg, int from_tty)
            arg = p;
            /* I don't know if it matters whether this is the string the user
               typed in or the decompiled expression.  */
-           b->cond_string = savestring (arg, strlen (arg));
+           b->cond_string = xstrdup (arg);
            b->condition_not_parsed = 0;
            for (loc = b->loc; loc; loc = loc->next)
              {
@@ -585,6 +670,17 @@ condition_command (char *arg, int from_tty)
   error (_("No breakpoint number %d."), bnum);
 }
 
+/* Set the command list of B to COMMANDS.  */
+
+void
+breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
+{
+  free_command_lines (&b->commands);
+  b->commands = commands;
+  breakpoints_changed ();
+  observer_notify_breakpoint_modified (b->number);
+}
+
 static void
 commands_command (char *arg, int from_tty)
 {
@@ -614,10 +710,7 @@ commands_command (char *arg, int from_tty)
        struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
        l = read_command_lines (tmpbuf, from_tty, 1);
        do_cleanups (cleanups);
-       free_command_lines (&b->commands);
-       b->commands = l;
-       breakpoints_changed ();
-       observer_notify_breakpoint_modified (b->number);
+       breakpoint_set_commands (b, l);
        return;
     }
   error (_("No breakpoint number %d."), bnum);
@@ -668,35 +761,99 @@ commands_from_control_command (char *arg, struct command_line *cmd)
       }
   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;
+    }
+
+  /* Now do full processing of the found relevant range of elements.  */
 
-  ALL_BP_LOCATIONS (b)
+  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
@@ -843,9 +1000,11 @@ update_watchpoint (struct breakpoint *b, int reparse)
   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;
@@ -853,12 +1012,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
   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)
@@ -866,12 +1020,23 @@ update_watchpoint (struct breakpoint *b, int reparse)
   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;
@@ -928,7 +1093,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
              b->type = bp_watchpoint;
            else
              {
-               int target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT
+               int target_resources_ok = target_can_use_hardware_watchpoint
                  (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
                if (target_resources_ok <= 0)
                  b->type = bp_watchpoint;
@@ -961,7 +1126,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
                  int len, type;
                  struct bp_location *loc, **tmp;
 
-                 addr = VALUE_ADDRESS (v) + value_offset (v);
+                 addr = value_address (v);
                  len = TYPE_LENGTH (value_type (v));
                  type = hw_write;
                  if (b->type == bp_read_watchpoint)
@@ -973,6 +1138,9 @@ update_watchpoint (struct breakpoint *b, int reparse)
                  for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
                    ;
                  *tmp = loc;
+                 loc->gdbarch = get_type_arch (value_type (v));
+
+                 loc->pspace = frame_pspace;
                  loc->address = addr;
                  loc->length = len;
                  loc->watchpoint_type = type;
@@ -1006,7 +1174,8 @@ in which its expression is valid.\n"),
     }
 
   /* 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));
 }
 
 
@@ -1024,6 +1193,22 @@ should_be_inserted (struct bp_location *bpt)
   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)
+    return 0;
+
   return 1;
 }
 
@@ -1047,6 +1232,7 @@ insert_bp_location (struct bp_location *bpt,
   /* 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)
@@ -1098,7 +1284,7 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
              else if (bpt->loc_type == bp_loc_software_breakpoint
                       && mr->attrib.mode != MEM_RW)        
                warning (_("cannot set software breakpoint at readonly address %s"),
-                        paddr (bpt->address));
+                        paddress (bpt->gdbarch, bpt->address));
            }
        }
         
@@ -1110,9 +1296,11 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
          /* No overlay handling: just set the breakpoint.  */
 
          if (bpt->loc_type == bp_loc_hardware_breakpoint)
-           val = target_insert_hw_breakpoint (&bpt->target_info);
+           val = target_insert_hw_breakpoint (bpt->gdbarch,
+                                              &bpt->target_info);
          else
-           val = target_insert_breakpoint (&bpt->target_info);
+           val = target_insert_breakpoint (bpt->gdbarch,
+                                           &bpt->target_info);
        }
       else
        {
@@ -1133,7 +1321,8 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
                  /* Set a software (trap) breakpoint at the LMA.  */
                  bpt->overlay_target_info = bpt->target_info;
                  bpt->overlay_target_info.placed_address = addr;
-                 val = target_insert_breakpoint (&bpt->overlay_target_info);
+                 val = target_insert_breakpoint (bpt->gdbarch,
+                                                 &bpt->overlay_target_info);
                  if (val != 0)
                    fprintf_unfiltered (tmp_error_stream,
                                        "Overlay breakpoint %d failed: in ROM?\n",
@@ -1145,9 +1334,11 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
            {
              /* Yes.  This overlay section is mapped into memory.  */
              if (bpt->loc_type == bp_loc_hardware_breakpoint)
-               val = target_insert_hw_breakpoint (&bpt->target_info);
+               val = target_insert_hw_breakpoint (bpt->gdbarch,
+                                                  &bpt->target_info);
              else
-               val = target_insert_breakpoint (&bpt->target_info);
+               val = target_insert_breakpoint (bpt->gdbarch,
+                                               &bpt->target_info);
            }
          else
            {
@@ -1160,7 +1351,7 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
       if (val)
        {
          /* Can't set the breakpoint.  */
-         if (solib_address (bpt->address))
+         if (solib_name_from_address (bpt->pspace, bpt->address))
            {
              /* See also: disable_breakpoints_in_shlibs. */
              val = 0;
@@ -1193,7 +1384,8 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
                                      bpt->owner->number);
                  fprintf_filtered (tmp_error_stream, 
                                    "Error accessing memory address ");
-                 fputs_filtered (paddress (bpt->address), tmp_error_stream);
+                 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
+                                 tmp_error_stream);
                  fprintf_filtered (tmp_error_stream, ": %s.\n",
                                    safe_strerror (val));
                }
@@ -1237,6 +1429,48 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
   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
@@ -1252,13 +1486,10 @@ insert_breakpoints (void)
 
   update_global_location_list (1);
 
-  if (!breakpoints_always_inserted_mode ()
-      && (target_has_execution
-         || (gdbarch_has_global_solist (target_gdbarch)
-             && target_supports_multi_process ())))
-    /* update_global_location_list does not insert breakpoints
-       when always_inserted_mode is not enabled.  Explicitly
-       insert them now.  */
+  /* update_global_location_list does not insert breakpoints when
+     always_inserted_mode is not enabled.  Explicitly insert them
+     now.  */
+  if (!breakpoints_always_inserted_mode ())
     insert_breakpoint_locations ();
 }
 
@@ -1271,7 +1502,7 @@ static void
 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;
@@ -1283,9 +1514,14 @@ insert_breakpoint_locations (void)
   /* 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;
 
@@ -1295,6 +1531,16 @@ insert_breakpoint_locations (void)
          && !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);
@@ -1319,7 +1565,7 @@ insert_breakpoint_locations (void)
        continue;
       
       for (loc = bpt->loc; loc; loc = loc->next)
-       if (!loc->inserted)
+       if (!loc->inserted && should_be_inserted (loc))
          {
            some_failed = 1;
            break;
@@ -1358,11 +1604,31 @@ You may have requested too many hardware breakpoints/watchpoints.\n");
 int
 remove_breakpoints (void)
 {
-  struct bp_location *b;
+  struct bp_location *b, **bp_tmp;
+  int val = 0;
+
+  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)
+  ALL_BP_LOCATIONS (b, b_tmp)
   {
+    if (b->pspace != inf->pspace)
+      continue;
+
     if (b->inserted)
       {
        val = remove_breakpoint (b, mark_uninserted);
@@ -1376,35 +1642,44 @@ remove_breakpoints (void)
 int
 remove_hw_watchpoints (void)
 {
-  struct bp_location *b;
-  int val;
+  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);
-       if (val != 0)
-         return val;
-      }
+      val |= remove_breakpoint (b, mark_uninserted);
   }
-  return 0;
+  return val;
 }
 
 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;
@@ -1421,12 +1696,102 @@ reattach_breakpoints (int pid)
   return 0;
 }
 
+static int internal_breakpoint_number = -1;
+
+static struct breakpoint *
+create_internal_breakpoint (struct gdbarch *gdbarch,
+                           CORE_ADDR address, enum bptype type)
+{
+  struct symtab_and_line sal;
+  struct breakpoint *b;
+
+  init_sal (&sal);             /* initialize to zeroes */
+
+  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--;
+  b->disposition = disp_donttouch;
+
+  return b;
+}
+
+static void
+create_overlay_event_breakpoint (char *func_name)
+{
+  struct objfile *objfile;
+
+  ALL_OBJFILES (objfile)
+    {
+      struct breakpoint *b;
+      struct minimal_symbol *m;
+
+      m = lookup_minimal_symbol_text (func_name, objfile);
+      if (m == NULL)
+        continue;
+
+      b = create_internal_breakpoint (get_objfile_arch (objfile),
+                                     SYMBOL_VALUE_ADDRESS (m),
+                                      bp_overlay_event);
+      b->addr_string = xstrdup (func_name);
+
+      if (overlay_debugging == ovly_auto)
+        {
+          b->enable_state = bp_enabled;
+          overlay_events_enabled = 1;
+        }
+      else
+       {
+         b->enable_state = bp_disabled;
+         overlay_events_enabled = 0;
+       }
+    }
+  update_global_location_list (1);
+}
+
+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;
+      struct minimal_symbol *m;
+
+      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 = create_internal_breakpoint (get_objfile_arch (objfile),
+                                     SYMBOL_VALUE_ADDRESS (m),
+                                      bp_longjmp_master);
+      b->addr_string = xstrdup (func_name);
+      b->enable_state = bp_disabled;
+    }
+  update_global_location_list (1);
+
+  do_cleanups (old_chain);
+}
+
 void
 update_breakpoints_after_exec (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
@@ -1436,11 +1801,15 @@ update_breakpoints_after_exec (void)
      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)
       {
@@ -1448,9 +1817,17 @@ update_breakpoints_after_exec (void)
        continue;
       }
 
+    /* JIT breakpoints must be explicitly reset after an exec(). */
+    if (b->type == bp_jit_event)
+      {
+       delete_breakpoint (b);
+       continue;
+      }
+
     /* Thread event breakpoints must be set anew after an exec(),
-       as must overlay event breakpoints.  */
-    if (b->type == bp_thread_event || b->type == bp_overlay_event)
+       as must overlay event and longjmp master breakpoints.  */
+    if (b->type == bp_thread_event || b->type == bp_overlay_event
+       || b->type == bp_longjmp_master)
       {
        delete_breakpoint (b);
        continue;
@@ -1522,40 +1899,48 @@ update_breakpoints_after_exec (void)
   }
   /* FIXME what about longjmp breakpoints?  Re-create them here?  */
   create_overlay_event_breakpoint ("_ovly_debug_event");
+  create_longjmp_master_breakpoint ("longjmp");
+  create_longjmp_master_breakpoint ("_longjmp");
+  create_longjmp_master_breakpoint ("siglongjmp");
+  create_longjmp_master_breakpoint ("_siglongjmp");
 }
 
 int
 detach_breakpoints (int pid)
 {
-  struct bp_location *b;
-  int val;
+  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);
-       if (val != 0)
-         {
-           do_cleanups (old_chain);
-           return val;
-         }
-      }
+      val |= remove_breakpoint_1 (b, mark_inserted);
   }
   do_cleanups (old_chain);
-  return 0;
+  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.  */
@@ -1580,9 +1965,9 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
          /* No overlay handling: just remove the breakpoint.  */
 
          if (b->loc_type == bp_loc_hardware_breakpoint)
-           val = target_remove_hw_breakpoint (&b->target_info);
+           val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
          else
-           val = target_remove_breakpoint (&b->target_info);
+           val = target_remove_breakpoint (b->gdbarch, &b->target_info);
        }
       else
        {
@@ -1596,9 +1981,11 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
                /* Ignore any failures: if the LMA is in ROM, we will
                   have already warned when we failed to insert it.  */
                if (b->loc_type == bp_loc_hardware_breakpoint)
-                 target_remove_hw_breakpoint (&b->overlay_target_info);
+                 target_remove_hw_breakpoint (b->gdbarch,
+                                              &b->overlay_target_info);
                else
-                 target_remove_breakpoint (&b->overlay_target_info);
+                 target_remove_breakpoint (b->gdbarch,
+                                           &b->overlay_target_info);
              }
          /* Did we set a breakpoint at the VMA? 
             If so, we will have marked the breakpoint 'inserted'.  */
@@ -1609,13 +1996,15 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
                 unmapped, but let's not rely on that being safe.  We
                 don't know what the overlay manager might do.  */
              if (b->loc_type == bp_loc_hardware_breakpoint)
-               val = target_remove_hw_breakpoint (&b->target_info);
+               val = target_remove_hw_breakpoint (b->gdbarch,
+                                                  &b->target_info);
 
              /* However, we should remove *software* breakpoints only
                 if the section is still mapped, or else we overwrite
                 wrong code with the saved shadow contents.  */
              else if (section_is_mapped (b->section))
-               val = target_remove_breakpoint (&b->target_info);
+               val = target_remove_breakpoint (b->gdbarch,
+                                               &b->target_info);
              else
                val = 0;
            }
@@ -1629,7 +2018,7 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
       /* 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_address (b->address))
+      if (val && solib_name_from_address (b->pspace, b->address))
        val = 0;
 
       if (val)
@@ -1665,15 +2054,40 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
   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
@@ -1692,20 +2106,27 @@ void
 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_solist (target_gdbarch))
+  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:
@@ -1748,6 +2169,11 @@ breakpoint_init_inferior (enum inf_context context)
   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
@@ -1759,12 +2185,12 @@ breakpoint_init_inferior (enum inf_context context)
      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)
@@ -1772,7 +2198,8 @@ breakpoint_here_p (CORE_ADDR pc)
 
       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) 
@@ -1791,36 +2218,38 @@ breakpoint_here_p (CORE_ADDR pc)
 /* 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) 
@@ -1837,12 +2266,12 @@ regular_breakpoint_inserted_here_p (CORE_ADDR pc)
    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;
@@ -1852,18 +2281,19 @@ breakpoint_inserted_here_p (CORE_ADDR pc)
    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) 
@@ -1875,7 +2305,7 @@ software_breakpoint_inserted_here_p (CORE_ADDR pc)
     }
 
   /* 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;
@@ -1885,31 +2315,56 @@ software_breakpoint_inserted_here_p (CORE_ADDR pc)
    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;
-  int thread;
-
-  thread = pid_to_thread_id (ptid);
-
-  ALL_BP_LOCATIONS (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, bptp_tmp)
     {
       if (bpt->loc_type != bp_loc_software_breakpoint
          && bpt->loc_type != bp_loc_hardware_breakpoint)
        continue;
 
-      if ((breakpoint_enabled (bpt->owner)
-          || bpt->owner->enable_state == bp_permanent)
-         && bpt->address == pc
-         && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
+      if (!breakpoint_enabled (bpt->owner)
+         && bpt->owner->enable_state != bp_permanent)
+       continue;
+
+      if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+                                    aspace, pc))
+       continue;
+
+      if (bpt->owner->thread != -1)
        {
-         if (overlay_debugging 
-             && section_is_overlay (bpt->section) 
-             && !section_is_mapped (bpt->section))
-           continue;           /* unmapped overlay -- can't be a match */
-         else
-           return 1;
+         /* This is a thread-specific breakpoint.  Check that ptid
+            matches that thread.  If thread hasn't been computed yet,
+            it is now time to do so.  */
+         if (thread == -1)
+           thread = pid_to_thread_id (ptid);
+         if (bpt->owner->thread != thread)
+           continue;
        }
+
+      if (bpt->owner->task != 0)
+        {
+         /* This is a task-specific breakpoint.  Check that ptid
+            matches that task.  If task hasn't been computed yet,
+            it is now time to do so.  */
+         if (task == 0)
+           task = ada_get_task_number (ptid);
+         if (bpt->owner->task != task)
+           continue;
+        }
+
+      if (overlay_debugging 
+         && section_is_overlay (bpt->section) 
+         && !section_is_mapped (bpt->section))
+       continue;           /* unmapped overlay -- can't be a match */
+
+      return 1;
     }
 
   return 0;
@@ -2026,10 +2481,10 @@ bpstat_find_step_resume_breakpoint (bpstat bsp)
 
   for (; bsp != NULL; bsp = bsp->next)
     {
-      if ((bsp->breakpoint_at != NULL) &&
-         (bsp->breakpoint_at->owner->type == bp_step_resume) &&
-         (bsp->breakpoint_at->owner->thread == current_thread || 
-          bsp->breakpoint_at->owner->thread == -1))
+      if ((bsp->breakpoint_at != NULL)
+         && (bsp->breakpoint_at->owner->type == bp_step_resume)
+         && (bsp->breakpoint_at->owner->thread == current_thread
+             || bsp->breakpoint_at->owner->thread == -1))
        return bsp->breakpoint_at->owner;
     }
 
@@ -2083,6 +2538,26 @@ bpstat_clear_actions (bpstat bs)
     }
 }
 
+/* Called when a command is about to proceed the inferior.  */
+
+static void
+breakpoint_about_to_proceed (void)
+{
+  if (!ptid_equal (inferior_ptid, null_ptid))
+    {
+      struct thread_info *tp = inferior_thread ();
+
+      /* Allow inferior function calls in breakpoint commands to not
+        interrupt the command list.  When the call finishes
+        successfully, the inferior will be standing at the same
+        breakpoint as if nothing happened.  */
+      if (tp->in_infcall)
+       return;
+    }
+
+  breakpoint_proceeded = 1;
+}
+
 /* Stub for cleaning up our state if we error-out of a breakpoint command */
 static void
 cleanup_executing_breakpoints (void *ignore)
@@ -2297,6 +2772,12 @@ print_it_typical (bpstat bs)
       result = PRINT_NOTHING;
       break;
 
+    case bp_longjmp_master:
+      /* These should never be enabled.  */
+      printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
+      result = PRINT_NOTHING;
+      break;
+
     case bp_watchpoint:
     case bp_hardware_watchpoint:
       annotate_watchpoint (b->number);
@@ -2387,6 +2868,8 @@ print_it_typical (bpstat bs)
     case bp_step_resume:
     case bp_watchpoint_scope:
     case bp_call_dummy:
+    case bp_tracepoint:
+    case bp_jit_event:
     default:
       result = PRINT_UNKNOWN;
       break;
@@ -2520,7 +3003,7 @@ bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */
 int
 watchpoints_triggered (struct target_waitstatus *ws)
 {
-  int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
+  int stopped_by_watchpoint = target_stopped_by_watchpoint ();
   CORE_ADDR addr;
   struct breakpoint *b;
 
@@ -2606,34 +3089,38 @@ watchpoint_check (void *p)
     within_current_scope = 1;
   else
     {
-      /* There is no current frame at this moment.  If we're going to have
-         any chance of handling watchpoints on local variables, we'll need
-         the frame chain (so we can determine if we're in scope).  */
-      reinit_frame_cache ();
+      struct frame_info *frame = get_current_frame ();
+      struct gdbarch *frame_arch = get_frame_arch (frame);
+      CORE_ADDR frame_pc = get_frame_pc (frame);
+
       fr = frame_find_by_id (b->watchpoint_frame);
       within_current_scope = (fr != NULL);
 
       /* If we've gotten confused in the unwinder, we might have
         returned a frame that can't describe this variable.  */
-      if (within_current_scope
-         && (block_linkage_function (b->exp_valid_block)
-             != get_frame_function (fr)))
-       within_current_scope = 0;
+      if (within_current_scope)
+       {
+         struct symbol *function;
+
+         function = get_frame_function (fr);
+         if (function == NULL
+             || !contained_in (b->exp_valid_block,
+                               SYMBOL_BLOCK_VALUE (function)))
+           within_current_scope = 0;
+       }
 
       /* in_function_epilogue_p() returns a non-zero value if we're still
         in the function but the stack frame has already been invalidated.
         Since we can't rely on the values of local variables after the
         stack has been destroyed, we are treating the watchpoint in that
-        state as `not changed' without further checking.
-        
-        vinschen/2003-09-04: The former implementation left out the case
-        that the watchpoint frame couldn't be found by frame_find_by_id()
-        because the current PC is currently in an epilogue.  Calling
-        gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
-      if ((!within_current_scope || fr == get_current_frame ())
-          && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
+        state as `not changed' without further checking.  Don't mark
+        watchpoints as changed if the current frame is in an epilogue -
+        even if they are in some other frame, our view of the stack
+        is likely to be wrong.  */
+      if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
        return WP_VALUE_NOT_CHANGED;
-      if (fr && within_current_scope)
+
+      if (within_current_scope)
        /* If we end up stopping, the current frame will get selected
           in normal_stop.  So this call to select_frame won't affect
           the user.  */
@@ -2707,7 +3194,8 @@ which its expression is valid.\n");
    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;
 
@@ -2718,7 +3206,8 @@ bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
       && 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) 
@@ -2867,7 +3356,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
   struct breakpoint *b = bl->owner;
 
   if (frame_id_p (b->frame_id)
-      && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
+      && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
     bs->stop = 0;
   else if (bs->stop)
     {
@@ -2882,15 +3371,26 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
       
       if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
        {
-         /* Need to select the frame, with all that implies
-            so that the conditions will have the right context.  */
+         /* We use value_mark and value_free_to_mark because it could
+            be a long time before we return to the command level and
+            call free_all_values.  We can't call free_all_values
+            because we might be in the middle of evaluating a
+            function call.  */
+         struct value *mark = value_mark ();
+
+         /* Need to select the frame, with all that implies so that
+            the conditions will have the right context.  Because we
+            use the frame, we will not see an inlined function's
+            variables when we arrive at a breakpoint at the start
+            of the inlined function; the current frame will be the
+            call site.  */
          select_frame (get_current_frame ());
          value_is_zero
            = catch_errors (breakpoint_cond_eval, (bl->cond),
                            "Error in testing breakpoint condition:\n",
                            RETURN_MASK_ALL);
          /* FIXME-someday, should give breakpoint # */
-         free_all_values ();
+         value_free_to_mark (mark);
        }
       if (bl->cond && value_is_zero)
        {
@@ -2931,19 +3431,20 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
    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);
@@ -2954,12 +3455,11 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
        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 */
@@ -2976,7 +3476,8 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
     if (!bs->stop)
       continue;
 
-    if (b->type == bp_thread_event || b->type == bp_overlay_event)
+    if (b->type == bp_thread_event || b->type == bp_overlay_event
+       || b->type == bp_longjmp_master)
       /* We do not stop for these.  */
       bs->stop = 0;
     else
@@ -2984,21 +3485,22 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
   
     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->commands = b->commands;
-       if (bs->commands &&
-           (strcmp ("silent", bs->commands->line) == 0
-            || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
+       if (bs->commands
+           && (strcmp ("silent", bs->commands->line) == 0
+               || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
          {
            bs->commands = bs->commands->next;
            bs->print = 0;
@@ -3011,9 +3513,14 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
       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.  */
@@ -3096,6 +3603,9 @@ bpstat_what (bpstat bs)
       /* We hit the shared library event breakpoint.  */
       shlib_event,
 
+      /* We hit the jit event breakpoint.  */
+      jit_event,
+
       /* This is just used to count how many enums there are.  */
       class_last
     };
@@ -3111,6 +3621,7 @@ bpstat_what (bpstat bs)
 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
 #define sr BPSTAT_WHAT_STEP_RESUME
 #define shl BPSTAT_WHAT_CHECK_SHLIBS
+#define jit BPSTAT_WHAT_CHECK_JIT
 
 /* "Can't happen."  Might want to print an error message.
    abort() is not out of the question, but chances are GDB is just
@@ -3131,12 +3642,13 @@ bpstat_what (bpstat bs)
      back and decide something of a lower priority is better.  The
      ordering is:
 
-     kc   < clr sgl shl slr sn sr ss
-     sgl  < shl slr sn sr ss
-     slr  < err shl sn sr ss
-     clr  < err shl sn sr ss
-     ss   < shl sn sr
-     sn   < shl sr
+     kc   < jit clr sgl shl slr sn sr ss
+     sgl  < jit shl slr sn sr ss
+     slr  < jit err shl sn sr ss
+     clr  < jit err shl sn sr ss
+     ss   < jit shl sn sr
+     sn   < jit shl sr
+     jit  < shl sr
      shl  < sr
      sr   <
 
@@ -3154,28 +3666,18 @@ bpstat_what (bpstat bs)
     table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
   {
   /*                              old action */
-  /*       kc    ss    sn    sgl    slr   clr   sr   shl
-   */
-/*no_effect */
-    {kc, ss, sn, sgl, slr, clr, sr, shl},
-/*wp_silent */
-    {ss, ss, sn, ss, ss, ss, sr, shl},
-/*wp_noisy */
-    {sn, sn, sn, sn, sn, sn, sr, shl},
-/*bp_nostop */
-    {sgl, ss, sn, sgl, slr, slr, sr, shl},
-/*bp_silent */
-    {ss, ss, sn, ss, ss, ss, sr, shl},
-/*bp_noisy */
-    {sn, sn, sn, sn, sn, sn, sr, shl},
-/*long_jump */
-    {slr, ss, sn, slr, slr, err, sr, shl},
-/*long_resume */
-    {clr, ss, sn, err, err, err, sr, shl},
-/*step_resume */
-    {sr, sr, sr, sr, sr, sr, sr, sr},
-/*shlib */
-    {shl, shl, shl, shl, shl, shl, sr, shl}
+  /*               kc   ss   sn   sgl  slr  clr  sr  shl  jit */
+/* no_effect */   {kc,  ss,  sn,  sgl, slr, clr, sr, shl, jit},
+/* wp_silent */   {ss,  ss,  sn,  ss,  ss,  ss,  sr, shl, jit},
+/* wp_noisy */    {sn,  sn,  sn,  sn,  sn,  sn,  sr, shl, jit},
+/* bp_nostop */   {sgl, ss,  sn,  sgl, slr, slr, sr, shl, jit},
+/* bp_silent */   {ss,  ss,  sn,  ss,  ss,  ss,  sr, shl, jit},
+/* bp_noisy */    {sn,  sn,  sn,  sn,  sn,  sn,  sr, shl, jit},
+/* long_jump */   {slr, ss,  sn,  slr, slr, err, sr, shl, jit},
+/* long_resume */ {clr, ss,  sn,  err, err, err, sr, shl, jit},
+/* step_resume */ {sr,  sr,  sr,  sr,  sr,  sr,  sr, sr,  sr },
+/* shlib */       {shl, shl, shl, shl, shl, shl, sr, shl, shl},
+/* jit_event */   {jit, jit, jit, jit, jit, jit, sr, jit, jit}
   };
 
 #undef kc
@@ -3188,6 +3690,7 @@ bpstat_what (bpstat bs)
 #undef sr
 #undef ts
 #undef shl
+#undef jit
   enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
   struct bpstat_what retval;
 
@@ -3258,8 +3761,12 @@ bpstat_what (bpstat bs)
        case bp_shlib_event:
          bs_class = shlib_event;
          break;
+       case bp_jit_event:
+         bs_class = jit_event;
+         break;
        case bp_thread_event:
        case bp_overlay_event:
+       case bp_longjmp_master:
          bs_class = bp_nostop;
          break;
        case bp_catchpoint:
@@ -3281,6 +3788,13 @@ bpstat_what (bpstat bs)
          bs_class = bp_silent;
          retval.call_dummy = 1;
          break;
+       case bp_tracepoint:
+         /* Tracepoint hits should not be reported back to GDB, and
+            if one got through somehow, it should have been filtered
+            out already.  */
+         internal_error (__FILE__, __LINE__,
+                         _("bpstat_what: bp_tracepoint encountered"));
+         break;
        }
       current_action = table[(int) bs_class][(int) current_action];
     }
@@ -3297,7 +3811,7 @@ bpstat_should_step (void)
 {
   struct breakpoint *b;
   ALL_BREAKPOINTS (b)
-    if (breakpoint_enabled (b) && b->type == bp_watchpoint)
+    if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
       return 1;
   return 0;
 }
@@ -3309,6 +3823,11 @@ static void print_breakpoint_location (struct breakpoint *b,
                                       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 
@@ -3344,6 +3863,8 @@ static void print_breakpoint_location (struct breakpoint *b,
       print_address_symbolic (loc->address, stb->stream, demangle, "");
       ui_out_field_stream (uiout, "at", stb);
     }
+
+  do_cleanups (old_chain);
 }
 
 /* Print B to gdb_stdout. */
@@ -3351,7 +3872,9 @@ static void
 print_one_breakpoint_location (struct breakpoint *b,
                               struct bp_location *loc,
                               int loc_number,
-                              CORE_ADDR *last_addr)
+                              struct bp_location **last_loc,
+                              int print_address_bits,
+                              int allflag)
 {
   struct command_line *l;
   struct symbol *sym;
@@ -3379,7 +3902,10 @@ print_one_breakpoint_location (struct breakpoint *b,
     {bp_shlib_event, "shlib events"},
     {bp_thread_event, "thread events"},
     {bp_overlay_event, "overlay events"},
+    {bp_longjmp_master, "longjmp master"},
     {bp_catchpoint, "catchpoint"},
+    {bp_tracepoint, "tracepoint"},
+    {bp_jit_event, "jit events"},
   };
   
   static char bpenables[] = "nynny";
@@ -3458,7 +3984,7 @@ print_one_breakpoint_location (struct breakpoint *b,
   strcpy (wrap_indent, "                           ");
   if (opts.addressprint)
     {
-      if (gdbarch_addr_bit (current_gdbarch) <= 32)
+      if (print_address_bits <= 32)
        strcat (wrap_indent, "           ");
       else
        strcat (wrap_indent, "                   ");
@@ -3471,7 +3997,7 @@ print_one_breakpoint_location (struct breakpoint *b,
         to get any nice result.  So, make sure there's
         just one location.  */
       gdb_assert (b->loc == NULL || b->loc->next == NULL);
-      b->ops->print_one (b, last_addr);
+      b->ops->print_one (b, last_loc);
     }
   else
     switch (b->type)
@@ -3506,6 +4032,9 @@ print_one_breakpoint_location (struct breakpoint *b,
       case bp_shlib_event:
       case bp_thread_event:
       case bp_overlay_event:
+      case bp_longjmp_master:
+      case bp_tracepoint:
+      case bp_jit_event:
        if (opts.addressprint)
          {
            annotate_field (4);
@@ -3514,22 +4043,61 @@ print_one_breakpoint_location (struct breakpoint *b,
            else if (b->loc == NULL || loc->shlib_disabled)
              ui_out_field_string (uiout, "addr", "<PENDING>");
            else
-             ui_out_field_core_addr (uiout, "addr", loc->address);
+             ui_out_field_core_addr (uiout, "addr",
+                                     loc->gdbarch, loc->address);
          }
        annotate_field (5);
        if (!header_of_multiple)
          print_breakpoint_location (b, loc, wrap_indent, stb);
        if (b->loc)
-         *last_addr = b->loc->address;
+         *last_loc = b->loc;
        break;
       }
 
-  if (!part_of_multiple && b->thread != -1)
+
+  /* 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)))
     {
-      /* FIXME: This seems to be redundant and lost here; see the
-        "stop only in" line a little further down. */
-      ui_out_text (uiout, " thread ");
-      ui_out_field_int (uiout, "thread", b->thread);
+      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)
+       {
+         /* FIXME: This seems to be redundant and lost here; see the
+            "stop only in" line a little further down. */
+         ui_out_text (uiout, " thread ");
+         ui_out_field_int (uiout, "thread", b->thread);
+       }
+      else if (b->task != 0)
+       {
+         ui_out_text (uiout, " task ");
+         ui_out_field_int (uiout, "task", b->task);
+       }
     }
   
   ui_out_text (uiout, "\n");
@@ -3540,7 +4108,8 @@ print_one_breakpoint_location (struct breakpoint *b,
       ui_out_text (uiout, "\tstop only in stack frame at ");
       /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
          the frame ID.  */
-      ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
+      ui_out_field_core_addr (uiout, "frame",
+                             b->gdbarch, b->frame_id.stack_addr);
       ui_out_text (uiout, "\n");
     }
   
@@ -3550,7 +4119,10 @@ print_one_breakpoint_location (struct breakpoint *b,
          because the condition is an internal implementation detail
          that we do not want to expose to the user.  */
       annotate_field (7);
-      ui_out_text (uiout, "\tstop only if ");
+      if (b->type == bp_tracepoint)
+       ui_out_text (uiout, "\ttrace only if ");
+      else
+       ui_out_text (uiout, "\tstop only if ");
       ui_out_field_string (uiout, "cond", b->cond_string);
       ui_out_text (uiout, "\n");
     }
@@ -3591,8 +4163,9 @@ print_one_breakpoint_location (struct breakpoint *b,
       ui_out_field_int (uiout, "ignore", b->ignore_count);
       ui_out_text (uiout, " hits\n");
     }
-  
-  if (!part_of_multiple && (l = b->commands))
+
+  l = b->commands;
+  if (!part_of_multiple && l)
     {
       struct cleanup *script_chain;
 
@@ -3602,6 +4175,34 @@ print_one_breakpoint_location (struct breakpoint *b,
       do_cleanups (script_chain);
     }
 
+  if (!part_of_multiple && b->pass_count)
+    {
+      annotate_field (10);
+      ui_out_text (uiout, "\tpass count ");
+      ui_out_field_int (uiout, "pass", b->pass_count);
+      ui_out_text (uiout, " \n");
+    }
+
+  if (!part_of_multiple && b->step_count)
+    {
+      annotate_field (11);
+      ui_out_text (uiout, "\tstep count ");
+      ui_out_field_int (uiout, "step", b->step_count);
+      ui_out_text (uiout, " \n");
+    }
+
+  if (!part_of_multiple && b->actions)
+    {
+      struct action_line *action;
+      annotate_field (12);
+      for (action = b->actions; action; action = action->next)
+       {
+         ui_out_text (uiout, "      A\t");
+         ui_out_text (uiout, action->action);
+         ui_out_text (uiout, "\n");
+       }
+    }
+
   if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
     {
       if (b->addr_string)
@@ -3616,9 +4217,11 @@ print_one_breakpoint_location (struct breakpoint *b,
 
 static void
 print_one_breakpoint (struct breakpoint *b,
-                     CORE_ADDR *last_addr)
+                     struct bp_location **last_loc, int print_address_bits,
+                     int allflag)
 {
-  print_one_breakpoint_location (b, NULL, 0, last_addr);
+  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
@@ -3641,11 +4244,27 @@ print_one_breakpoint (struct breakpoint *b,
          struct bp_location *loc;
          int n = 1;
          for (loc = b->loc; loc; loc = loc->next, ++n)
-           print_one_breakpoint_location (b, loc, n, last_addr);
+           print_one_breakpoint_location (b, loc, n, last_loc,
+                                          print_address_bits, allflag);
        }
     }
 }
 
+static int
+breakpoint_address_bits (struct breakpoint *b)
+{
+  int print_address_bits = 0;
+  struct bp_location *loc;
+
+  for (loc = b->loc; loc; loc = loc->next)
+    {
+      int addr_bit = gdbarch_addr_bit (b->gdbarch);
+      if (addr_bit > print_address_bits)
+       print_address_bits = addr_bit;
+    }
+
+  return print_address_bits;
+}
 
 struct captured_breakpoint_query_args
   {
@@ -3657,12 +4276,13 @@ do_captured_breakpoint_query (struct ui_out *uiout, void *data)
 {
   struct captured_breakpoint_query_args *args = data;
   struct breakpoint *b;
-  CORE_ADDR dummy_addr = 0;
+  struct bp_location *dummy_loc = NULL;
   ALL_BREAKPOINTS (b)
     {
       if (args->bnum == b->number)
        {
-         print_one_breakpoint (b, &dummy_addr);
+         int print_address_bits = breakpoint_address_bits (b);
+         print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
          return GDB_RC_OK;
        }
     }
@@ -3692,6 +4312,7 @@ user_settable_breakpoint (const struct breakpoint *b)
   return (b->type == bp_breakpoint
          || b->type == bp_catchpoint
          || b->type == bp_hardware_breakpoint
+         || b->type == bp_tracepoint
          || b->type == bp_watchpoint
          || b->type == bp_read_watchpoint
          || b->type == bp_access_watchpoint
@@ -3706,21 +4327,29 @@ static void
 breakpoint_1 (int bnum, int allflag)
 {
   struct breakpoint *b;
-  CORE_ADDR last_addr = (CORE_ADDR) -1;
+  struct bp_location *last_loc = NULL;
   int nr_printable_breakpoints;
   struct cleanup *bkpttbl_chain;
   struct value_print_options opts;
+  int print_address_bits = 0;
   
   get_user_print_options (&opts);
 
-  /* Compute the number of rows in the table. */
+  /* Compute the number of rows in the table, as well as the
+     size required for address fields.  */
   nr_printable_breakpoints = 0;
   ALL_BREAKPOINTS (b)
     if (bnum == -1
        || bnum == b->number)
       {
        if (allflag || user_settable_breakpoint (b))
-         nr_printable_breakpoints++;
+         {
+           int addr_bit = breakpoint_address_bits (b);
+           if (addr_bit > print_address_bits)
+             print_address_bits = addr_bit;
+
+           nr_printable_breakpoints++;
+         }
       }
 
   if (opts.addressprint)
@@ -3750,7 +4379,7 @@ breakpoint_1 (int bnum, int allflag)
        {
          if (nr_printable_breakpoints > 0)
            annotate_field (4);
-         if (gdbarch_addr_bit (current_gdbarch) <= 32)
+         if (print_address_bits <= 32)
            ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
          else
            ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
@@ -3769,7 +4398,7 @@ breakpoint_1 (int bnum, int allflag)
        /* We only print out user settable breakpoints unless the
           allflag is set. */
        if (allflag || user_settable_breakpoint (b))
-         print_one_breakpoint (b, &last_addr);
+         print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
       }
   
   do_cleanups (bkpttbl_chain);
@@ -3784,10 +4413,8 @@ breakpoint_1 (int bnum, int allflag)
     }
   else
     {
-      /* Compare against (CORE_ADDR)-1 in case some compiler decides
-        that a comparison of an unsigned with -1 is always false.  */
-      if (last_addr != (CORE_ADDR) -1 && !server_command)
-       set_next_address (current_gdbarch, last_addr);
+      if (last_loc && !server_command)
+       set_next_address (last_loc->gdbarch, last_loc->address);
     }
 
   /* FIXME? Should this be moved up so that it is only called when
@@ -3819,29 +4446,34 @@ maintenance_info_breakpoints (char *bnum_exp, int from_tty)
 
 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 (CORE_ADDR pc, struct obj_section *section,
-                           int thread)
+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)
@@ -3849,7 +4481,7 @@ describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
       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);
@@ -3858,8 +4490,9 @@ describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
            else if (b->thread != -1)
              printf_filtered (" (thread %d)", b->thread);
            printf_filtered ("%s%s ",
-                            ((b->enable_state == bp_disabled || 
-                              b->enable_state == bp_call_disabled) 
+                            ((b->enable_state == bp_disabled
+                              || b->enable_state == bp_call_disabled
+                              || b->enable_state == bp_startup_disabled)
                              ? " (disabled)"
                              : b->enable_state == bp_permanent 
                              ? " (permanent)"
@@ -3868,7 +4501,7 @@ describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
                             : ((others == 1) ? " and" : ""));
          }
       printf_filtered (_("also set at pc "));
-      fputs_filtered (paddress (pc), gdb_stdout);
+      fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
       printf_filtered (".\n");
     }
 }
@@ -3877,10 +4510,12 @@ describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
    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;
@@ -3892,9 +4527,8 @@ set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
    (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
@@ -3914,84 +4548,18 @@ breakpoint_address_is_meaningful (struct breakpoint *bpt)
          && 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->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->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
@@ -4016,9 +4584,10 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
    this function is simply the identity function.  */
 
 static CORE_ADDR
-adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
+adjust_breakpoint_address (struct gdbarch *gdbarch,
+                          CORE_ADDR bpaddr, enum bptype bptype)
 {
-  if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
+  if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
     {
       /* Very few targets need any kind of breakpoint adjustment.  */
       return bpaddr;
@@ -4039,8 +4608,7 @@ adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
 
       /* Some targets have architectural constraints on the placement
          of breakpoint instructions.  Obtain the adjusted address.  */
-      adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
-                                                           bpaddr);
+      adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
 
       /* An adjusted breakpoint address can significantly alter
          a user's expectations.  Print a warning if an adjustment
@@ -4070,6 +4638,7 @@ allocate_bp_location (struct breakpoint *bpt)
   switch (bpt->type)
     {
     case bp_breakpoint:
+    case bp_tracepoint:
     case bp_until:
     case bp_finish:
     case bp_longjmp:
@@ -4080,6 +4649,8 @@ allocate_bp_location (struct breakpoint *bpt)
     case bp_shlib_event:
     case bp_thread_event:
     case bp_overlay_event:
+    case bp_jit_event:
+    case bp_longjmp_master:
       loc->loc_type = bp_loc_software_breakpoint;
       break;
     case bp_hardware_breakpoint:
@@ -4114,9 +4685,11 @@ static void free_bp_location (struct bp_location *loc)
 
 /* Helper to set_raw_breakpoint below.  Creates a breakpoint
    that has type BPTYPE and has no locations as yet.  */
+/* This function is used in gdbtk sources and thus can not be made static.  */
 
 static struct breakpoint *
-set_raw_breakpoint_without_location (enum bptype bptype)
+set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
+                                    enum bptype bptype)
 {
   struct breakpoint *b, *b1;
 
@@ -4124,6 +4697,7 @@ set_raw_breakpoint_without_location (enum bptype bptype)
   memset (b, 0, sizeof (*b));
 
   b->type = bptype;
+  b->gdbarch = gdbarch;
   b->language = current_language->la_language;
   b->input_radix = input_radix;
   b->thread = -1;
@@ -4135,6 +4709,7 @@ set_raw_breakpoint_without_location (enum bptype bptype)
   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;
 
@@ -4159,7 +4734,8 @@ static void
 set_breakpoint_location_function (struct bp_location *loc)
 {
   if (loc->owner->type == bp_breakpoint
-      || loc->owner->type == bp_hardware_breakpoint)
+      || loc->owner->type == bp_hardware_breakpoint
+      || loc->owner->type == bp_tracepoint)
     {
       find_pc_partial_function (loc->address, &(loc->function_name), 
                                NULL, NULL);
@@ -4168,6 +4744,18 @@ set_breakpoint_location_function (struct bp_location *loc)
     }
 }
 
+/* Attempt to determine architecture of location identified by SAL.  */
+static struct gdbarch *
+get_sal_arch (struct symtab_and_line sal)
+{
+  if (sal.section)
+    return get_objfile_arch (sal.section->objfile);
+  if (sal.symtab)
+    return get_objfile_arch (sal.symtab->objfile);
+
+  return NULL;
+}
+
 /* set_raw_breakpoint is a low level routine for allocating and
    partially initializing a breakpoint of type BPTYPE.  The newly
    created breakpoint's address, section, source file name, and line
@@ -4184,10 +4772,19 @@ set_breakpoint_location_function (struct bp_location *loc)
    should happen, a bogus breakpoint will be left on the chain.  */
 
 struct breakpoint *
-set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
+set_raw_breakpoint (struct gdbarch *gdbarch,
+                   struct symtab_and_line sal, enum bptype bptype)
 {
-  struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
+  struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
   CORE_ADDR adjusted_address;
+  struct gdbarch *loc_gdbarch;
+
+  loc_gdbarch = get_sal_arch (sal);
+  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
@@ -4195,17 +4792,22 @@ set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
      breakpoint may cause target_read_memory() to be called and we do
      not want its scan of the location chain to find a breakpoint and
      location that's only been partially initialized.  */
-  adjusted_address = adjust_breakpoint_address (sal.pc, b->type);
+  adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
 
   b->loc = allocate_bp_location (b);
+  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;
   else
-    b->source_file = savestring (sal.symtab->filename,
-                                strlen (sal.symtab->filename));
+    b->source_file = xstrdup (sal.symtab->filename);
   b->loc->section = sal.section;
   b->line_number = sal.line;
 
@@ -4234,51 +4836,27 @@ make_breakpoint_permanent (struct breakpoint *b)
     bl->inserted = 1;
 }
 
-static struct breakpoint *
-create_internal_breakpoint (CORE_ADDR address, enum bptype type)
-{
-  static int internal_breakpoint_number = -1;
-  struct symtab_and_line sal;
-  struct breakpoint *b;
-
-  init_sal (&sal);             /* initialize to zeroes */
-
-  sal.pc = address;
-  sal.section = find_pc_overlay (sal.pc);
-
-  b = set_raw_breakpoint (sal, type);
-  b->number = internal_breakpoint_number--;
-  b->disposition = disp_donttouch;
-
-  return b;
-}
-
-
-static void
-create_longjmp_breakpoint (char *func_name)
-{
-  struct minimal_symbol *m;
-
-  if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
-    return;
-  set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
-  update_global_location_list (1);
-}
-
 /* Call this routine when stepping and nexting to enable a breakpoint
-   if we do a longjmp().  When we hit that breakpoint, call
+   if we do a longjmp() in THREAD.  When we hit that breakpoint, call
    set_longjmp_resume_breakpoint() to figure out where we are going. */
 
 void
-set_longjmp_breakpoint (void)
+set_longjmp_breakpoint (int thread)
 {
-  if (gdbarch_get_longjmp_target_p (current_gdbarch))
-    {
-      create_longjmp_breakpoint ("longjmp");
-      create_longjmp_breakpoint ("_longjmp");
-      create_longjmp_breakpoint ("siglongjmp");
-      create_longjmp_breakpoint ("_siglongjmp");
-    }
+  struct breakpoint *b, *temp;
+
+  /* To avoid having to rescan all objfile symbols at every step,
+     we maintain a list of continually-inserted but always disabled
+     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->pspace == current_program_space
+       && b->type == bp_longjmp_master)
+      {
+       struct breakpoint *clone = clone_momentary_breakpoint (b);
+       clone->type = bp_longjmp;
+       clone->thread = thread;
+      }
 }
 
 /* Delete all longjmp breakpoints from THREAD.  */
@@ -4295,40 +4873,6 @@ delete_longjmp_breakpoint (int thread)
       }
 }
 
-static void
-create_overlay_event_breakpoint_1 (char *func_name, struct objfile *objfile)
-{
-  struct breakpoint *b;
-  struct minimal_symbol *m;
-
-  if ((m = lookup_minimal_symbol_text (func_name, objfile)) == NULL)
-    return;
-  b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), 
-                                 bp_overlay_event);
-  b->addr_string = xstrdup (func_name);
-
-  if (overlay_debugging == ovly_auto)
-    {
-      b->enable_state = bp_enabled;
-      overlay_events_enabled = 1;
-    }
-  else 
-    {
-      b->enable_state = bp_disabled;
-      overlay_events_enabled = 0;
-    }
-  update_global_location_list (1);
-}
-
-static void
-create_overlay_event_breakpoint (char *func_name)
-{
-  struct objfile *objfile;
-  ALL_OBJFILES (objfile)
-    create_overlay_event_breakpoint_1 (func_name, objfile);
-}
-
 void
 enable_overlay_breakpoints (void)
 {
@@ -4358,15 +4902,16 @@ disable_overlay_breakpoints (void)
 }
 
 struct breakpoint *
-create_thread_event_breakpoint (CORE_ADDR address)
+create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 {
   struct breakpoint *b;
 
-  b = create_internal_breakpoint (address, bp_thread_event);
+  b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
   
   b->enable_state = bp_enabled;
   /* addr_string has to be used or breakpoint_re_set will delete me.  */
-  b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
+  b->addr_string
+    = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
 
   update_global_location_list_nothrow (1);
 
@@ -4379,7 +4924,8 @@ remove_thread_event_breakpoints (void)
   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);
 }
 
@@ -4397,6 +4943,17 @@ struct lang_and_radix
     int radix;
   };
 
+/* Create a breakpoint for JIT code registration and unregistration.  */
+
+struct breakpoint *
+create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
+{
+  struct breakpoint *b;
+
+  b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
+  update_global_location_list_nothrow (1);
+  return b;
+}
 
 void
 remove_solib_event_breakpoints (void)
@@ -4404,16 +4961,17 @@ remove_solib_event_breakpoints (void)
   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);
 }
 
 struct breakpoint *
-create_solib_event_breakpoint (CORE_ADDR address)
+create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 {
   struct breakpoint *b;
 
-  b = create_internal_breakpoint (address, bp_shlib_event);
+  b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
   update_global_location_list_nothrow (1);
   return b;
 }
@@ -4424,9 +4982,9 @@ create_solib_event_breakpoint (CORE_ADDR address)
 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
@@ -4434,12 +4992,15 @@ disable_breakpoints_in_shlibs (void)
        becomes enabled, or the duplicate is removed, gdb will try to insert
        all breakpoints.  If we don't set shlib_disabled here, we'll try
        to insert those breakpoints and fail.  */
-    if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
+    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_address (loc->address)
+       && solib_name_from_address (loc->pspace, loc->address)
 #endif
        )
       {
@@ -4454,7 +5015,7 @@ disable_breakpoints_in_shlibs (void)
 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
@@ -4465,33 +5026,28 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
       && 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)
-       && !loc->shlib_disabled)
+       && solib->pspace == loc->pspace
+       && !loc->shlib_disabled
+       && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
+       && solib_contains_address_p (solib, loc->address))
       {
-#ifdef PC_SOLIB
-       char *so_name = PC_SOLIB (loc->address);
-#else
-       char *so_name = solib_address (loc->address);
-#endif
-       if (so_name && !strcmp (so_name, solib->so_name))
-          {
-           loc->shlib_disabled = 1;
-           /* At this point, we cannot rely on remove_breakpoint
-              succeeding so we must mark the breakpoint as not inserted
-              to prevent future errors occurring in remove_breakpoints.  */
-           loc->inserted = 0;
-           if (!disabled_shlib_breaks)
-             {
-               target_terminal_ours_for_output ();
-               warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
-                         so_name);
-             }
-           disabled_shlib_breaks = 1;
+       loc->shlib_disabled = 1;
+       /* At this point, we cannot rely on remove_breakpoint
+          succeeding so we must mark the breakpoint as not inserted
+          to prevent future errors occurring in remove_breakpoints.  */
+       loc->inserted = 0;
+       if (!disabled_shlib_breaks)
+         {
+           target_terminal_ours_for_output ();
+           warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
+                    solib->so_name);
          }
+       disabled_shlib_breaks = 1;
       }
   }
 }
@@ -4537,7 +5093,7 @@ print_it_catch_fork (struct breakpoint *b)
 /* Implement the "print_one" breakpoint_ops method for fork catchpoints.  */
 
 static void
-print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr)
+print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct value_print_options opts;
 
@@ -4619,7 +5175,7 @@ print_it_catch_vfork (struct breakpoint *b)
 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints.  */
 
 static void
-print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr)
+print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct value_print_options opts;
 
@@ -4661,60 +5217,336 @@ static struct breakpoint_ops catch_vfork_breakpoint_ops =
   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 (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;
+  struct inferior *inf = current_inferior ();
 
-  init_sal (&sal);
-  sal.pc = 0;
-  sal.symtab = NULL;
-  sal.line = 0;
+  ++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);
+       }
+    }
 
-  b = set_raw_breakpoint (sal, bp_catchpoint);
-  set_breakpoint_count (breakpoint_count + 1);
-  b->number = breakpoint_count;
+  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));
+}
 
-  b->cond_string = (cond_string == NULL) ? 
-    NULL : savestring (cond_string, strlen (cond_string));
-  b->thread = -1;
-  b->addr_string = NULL;
-  b->enable_state = bp_enabled;
-  b->disposition = tempflag ? disp_del : disp_donttouch;
-  b->ops = ops;
+/* Implement the "remove" breakpoint_ops method for syscall
+   catchpoints.  */
 
-  mention (b);
-  update_global_location_list (1);
+static int
+remove_catch_syscall (struct breakpoint *b)
+{
+  struct inferior *inf = current_inferior ();
 
-  return b;
+  --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);
+        }
+    }
+
+  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));
 }
 
-static void
-create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
-                                    struct breakpoint_ops *ops)
+/* Implement the "breakpoint_hit" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static int
+breakpoint_hit_catch_syscall (struct breakpoint *b)
 {
-  struct breakpoint *b = create_catchpoint (tempflag, cond_string, ops);
+  /* 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;
 
-  /* FIXME: We should put this information in a breakpoint private data
-     area.  */
-  b->forked_inferior_pid = null_ptid;
-}
+  if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
+    return 0;
 
-/* Exec catchpoints.  */
+  /* 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;
+    }
 
-static void
-insert_catch_exec (struct breakpoint *b)
-{
-  target_insert_exec_catchpoint (PIDGET (inferior_ptid));
+  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
@@ -4739,7 +5571,7 @@ print_it_catch_exec (struct breakpoint *b)
 }
 
 static void
-print_one_catch_exec (struct breakpoint *b, CORE_ADDR *last_addr)
+print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct value_print_options opts;
 
@@ -4776,6 +5608,22 @@ static struct breakpoint_ops catch_exec_breakpoint_ops =
   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)
 {
@@ -4804,9 +5652,9 @@ hw_watchpoint_used_count (enum bptype type, int *other_type_used)
       {
        if (b->type == type)
          i++;
-       else if ((b->type == bp_hardware_watchpoint ||
-                 b->type == bp_read_watchpoint ||
-                 b->type == bp_access_watchpoint))
+       else if ((b->type == bp_hardware_watchpoint
+                 || b->type == bp_read_watchpoint
+                 || b->type == bp_access_watchpoint))
          *other_type_used = 1;
       }
   }
@@ -4851,17 +5699,74 @@ enable_watchpoints_after_interactive_call_stop (void)
   }
 }
 
+void
+disable_breakpoints_before_startup (void)
+{
+  struct breakpoint *b;
+  int found = 0;
+
+  ALL_BREAKPOINTS (b)
+    {
+      if (b->pspace != current_program_space)
+       continue;
+
+      if ((b->type == bp_breakpoint
+          || b->type == bp_hardware_breakpoint)
+         && breakpoint_enabled (b))
+       {
+         b->enable_state = bp_startup_disabled;
+         found = 1;
+       }
+    }
+
+  if (found)
+    update_global_location_list (0);
+
+  current_program_space->executing_startup = 1;
+}
+
+void
+enable_breakpoints_after_startup (void)
+{
+  struct breakpoint *b;
+  int found = 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)
+       {
+         b->enable_state = bp_enabled;
+         found = 1;
+       }
+    }
+
+  if (found)
+    breakpoint_re_set ();
+}
+
 
 /* Set a breakpoint that will evaporate an end of command
    at address specified by SAL.
    Restrict it to frame FRAME if FRAME is nonzero.  */
 
 struct breakpoint *
-set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
-                         enum bptype type)
+set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
+                         struct frame_id frame_id, enum bptype type)
 {
   struct breakpoint *b;
-  b = set_raw_breakpoint (sal, type);
+
+  /* If FRAME_ID is valid, it should be a real frame, not an inlined
+     one.  */
+  gdb_assert (!frame_id_inlined_p (frame_id));
+
+  b = set_raw_breakpoint (gdbarch, sal, type);
   b->enable_state = bp_enabled;
   b->disposition = disp_donttouch;
   b->frame_id = frame_id;
@@ -4877,8 +5782,49 @@ set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
   return b;
 }
 
+/* Make a deep copy of momentary breakpoint ORIG.  Returns NULL if
+   ORIG is NULL.  */
+
+struct breakpoint *
+clone_momentary_breakpoint (struct breakpoint *orig)
+{
+  struct breakpoint *copy;
+
+  /* If there's nothing to clone, then return nothing.  */
+  if (orig == NULL)
+    return NULL;
+
+  copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
+  copy->loc = allocate_bp_location (copy);
+  set_breakpoint_location_function (copy->loc);
+
+  copy->loc->gdbarch = orig->loc->gdbarch;
+  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;
+  else
+    copy->source_file = xstrdup (orig->source_file);
+
+  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;
+  copy->number = internal_breakpoint_number--;
+
+  update_global_location_list_nothrow (0);
+  return copy;
+}
+
 struct breakpoint *
-set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
+set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
+                               enum bptype type)
 {
   struct symtab_and_line sal;
 
@@ -4887,7 +5833,7 @@ set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
   sal.section = find_pc_overlay (pc);
   sal.explicit_pc = 1;
 
-  return set_momentary_breakpoint (sal, null_frame_id, type);
+  return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
 }
 \f
 
@@ -4970,6 +5916,16 @@ mention (struct breakpoint *b)
        printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
        say_where = 1;
        break;
+      case bp_tracepoint:
+       if (ui_out_is_mi_like_p (uiout))
+         {
+           say_where = 0;
+           break;
+         }
+       printf_filtered (_("Tracepoint"));
+       printf_filtered (_(" %d"), b->number);
+       say_where = 1;
+       break;
 
       case bp_until:
       case bp_finish:
@@ -4981,6 +5937,8 @@ mention (struct breakpoint *b)
       case bp_shlib_event:
       case bp_thread_event:
       case bp_overlay_event:
+      case bp_jit_event:
+      case bp_longjmp_master:
        break;
       }
 
@@ -4997,7 +5955,8 @@ mention (struct breakpoint *b)
          if (opts.addressprint || b->source_file == NULL)
            {
              printf_filtered (" at ");
-             fputs_filtered (paddress (b->loc->address), gdb_stdout);
+             fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
+                             gdb_stdout);
            }
          if (b->source_file)
            printf_filtered (": file %s, line %d.",
@@ -5030,8 +5989,14 @@ add_location_to_breakpoint (struct breakpoint *b,
   for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
     ;
   *tmp = loc;
+  loc->gdbarch = get_sal_arch (*sal);
+  if (!loc->gdbarch)
+    loc->gdbarch = b->gdbarch;
   loc->requested_address = sal->pc;
-  loc->address = adjust_breakpoint_address (loc->requested_address, b->type);
+  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);
@@ -5055,7 +6020,7 @@ bp_loc_is_permanent (struct bp_location *loc)
   gdb_assert (loc != NULL);
 
   addr = loc->address;
-  brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len);
+  brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
 
   /* Software breakpoints unsupported?  */
   if (brk == NULL)
@@ -5066,7 +6031,10 @@ bp_loc_is_permanent (struct bp_location *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)
@@ -5084,10 +6052,11 @@ bp_loc_is_permanent (struct bp_location *loc)
    as condition expression.  */
 
 static void
-create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
+create_breakpoint (struct gdbarch *gdbarch,
+                  struct symtabs_and_lines sals, char *addr_string,
                   char *cond_string,
                   enum bptype type, enum bpdisp disposition,
-                  int thread, int ignore_count, 
+                  int thread, int task, int ignore_count, 
                   struct breakpoint_ops *ops, int from_tty, int enabled)
 {
   struct breakpoint *b = NULL;
@@ -5097,7 +6066,7 @@ create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
     {
       int i = hw_breakpoint_used_count ();
       int target_resources_ok = 
-       TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 
+       target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 
                                            i + 1, 0);
       if (target_resources_ok == 0)
        error (_("No hardware breakpoint support in the target."));
@@ -5105,26 +6074,43 @@ create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
        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];
       struct bp_location *loc;
 
       if (from_tty)
-       describe_other_breakpoints (sal.pc, sal.section, thread);
+       {
+         struct gdbarch *loc_gdbarch = get_sal_arch (sal);
+         if (!loc_gdbarch)
+           loc_gdbarch = gdbarch;
+
+         describe_other_breakpoints (loc_gdbarch,
+                                     sal.pspace, sal.pc, sal.section, thread);
+       }
 
       if (i == 0)
        {
-         b = set_raw_breakpoint (sal, type);
+         b = set_raw_breakpoint (gdbarch, sal, type);
          set_breakpoint_count (breakpoint_count + 1);
          b->number = breakpoint_count;
          b->thread = thread;
+         b->task = task;
   
          b->cond_string = cond_string;
          b->ignore_count = ignore_count;
          b->enable_state = enabled ? bp_enabled : bp_disabled;
          b->disposition = disposition;
 
+         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;
+
          loc = b->loc;
        }
       else
@@ -5149,7 +6135,8 @@ create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
   else
     /* addr_string has to be used or breakpoint_re_set will delete
        me.  */
-    b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
+    b->addr_string
+      = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
 
   b->ops = ops;
   mention (b);
@@ -5169,20 +6156,19 @@ remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
   --(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)
 {
@@ -5191,6 +6177,7 @@ 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.  */
@@ -5203,9 +6190,16 @@ expand_line_sal_maybe (struct symtab_and_line sal)
     }
 
   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
@@ -5215,6 +6209,7 @@ expand_line_sal_maybe (struct symtab_and_line sal)
       expanded.sals = xmalloc (sizeof (struct symtab_and_line));
       sal.pc = original_pc;
       expanded.sals[0] = sal;
+      do_cleanups (old_chain);
       return expanded;      
     }
 
@@ -5225,11 +6220,16 @@ expand_line_sal_maybe (struct symtab_and_line sal)
        {
          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))
            {
-             if (this_function && 
-                 strcmp (this_function, original_function) != 0)
+             if (this_function
+                 && strcmp (this_function, original_function) != 0)
                {
                  remove_sal (&expanded, i);
                  --i;
@@ -5242,14 +6242,34 @@ expand_line_sal_maybe (struct symtab_and_line sal)
                  if (sym)
                    expanded.sals[i] = find_function_start_sal (sym, 1);
                  else
-                   expanded.sals[i].pc 
-                     = gdbarch_skip_prologue (current_gdbarch, pc);
+                   {
+                     /* Since find_pc_partial_function returned true,
+                        we should really always find the section here.  */
+                     struct obj_section *section = find_pc_section (pc);
+                     if (section)
+                       {
+                         struct gdbarch *gdbarch
+                           = get_objfile_arch (section->objfile);
+                         expanded.sals[i].pc
+                           = gdbarch_skip_prologue (gdbarch, pc);
+                       }
+                   }
                }
            }
        }
     }
+  else
+    {
+      for (i = 0; i < expanded.nelts; ++i)
+       {
+         /* If this SAL corresponds to a breakpoint inserted using a
+            line number, then skip the function prologue if necessary.  */
+         skip_prologue_sal (&expanded.sals[i]);
+       }
+    }
+
+  do_cleanups (old_chain);
 
-  
   if (expanded.nelts <= 1)
     {
       /* This is un ugly workaround. If we get zero
@@ -5294,10 +6314,11 @@ expand_line_sal_maybe (struct symtab_and_line sal)
    COND and SALS arrays and each of those arrays contents. */
 
 static void
-create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
+create_breakpoints (struct gdbarch *gdbarch,
+                   struct symtabs_and_lines sals, char **addr_string,
                    char *cond_string,
                    enum bptype type, enum bpdisp disposition,
-                   int thread, int ignore_count, 
+                   int thread, int task, int ignore_count, 
                    struct breakpoint_ops *ops, int from_tty,
                    int enabled)
 {
@@ -5307,12 +6328,10 @@ create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
       struct symtabs_and_lines expanded = 
        expand_line_sal_maybe (sals.sals[i]);
 
-      create_breakpoint (expanded, addr_string[i],
+      create_breakpoint (gdbarch, expanded, addr_string[i],
                         cond_string, type, disposition,
-                        thread, ignore_count, ops, from_tty, enabled);
+                        thread, task, ignore_count, ops, from_tty, enabled);
     }
-
-  update_global_location_list (1);
 }
 
 /* Parse ARG which is assumed to be a SAL specification possibly
@@ -5342,7 +6361,16 @@ parse_breakpoint_sals (char **address,
          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
+            the default_breakpoint_address.  So make sure to set
+            sal.explicit_pc to prevent GDB from trying to expand the list of
+            sals to include all other instances with the same symtab and line.
+          */
+         sal.explicit_pc = 1;
+
          sals->sals[0] = sal;
          sals->nelts = 1;
        }
@@ -5416,7 +6444,7 @@ do_captured_parse_breakpoint (struct ui_out *ui, void *data)
    If no thread is found, *THREAD is set to -1.  */
 static void 
 find_condition_and_thread (char *tok, CORE_ADDR pc, 
-                          char **cond_string, int *thread)
+                          char **cond_string, int *thread, int *task)
 {
   *cond_string = NULL;
   *thread = -1;
@@ -5459,6 +6487,18 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
          if (!valid_thread_id (*thread))
            error (_("Unknown thread %d."), *thread);
        }
+      else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
+       {
+         char *tmptok;
+
+         tok = end_tok + 1;
+         tmptok = tok;
+         *task = strtol (tok, &tok, 0);
+         if (tok == tmptok)
+           error (_("Junk after task keyword."));
+         if (!valid_task_id (*task))
+           error (_("Unknown task %d\n"), *task);
+       }
       else
        error (_("Junk at end of arguments."));
     }
@@ -5475,9 +6515,10 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
    parameters.  */
 
 static void
-break_command_really (char *arg, char *cond_string, int thread,
+break_command_really (struct gdbarch *gdbarch,
+                     char *arg, char *cond_string, int thread,
                      int parse_condition_and_thread,
-                     int tempflag, int hardwareflag, 
+                     int tempflag, int hardwareflag, int traceflag,
                      int ignore_count,
                      enum auto_boolean pending_break_support,
                      struct breakpoint_ops *ops,
@@ -5492,11 +6533,13 @@ break_command_really (char *arg, char *cond_string, int thread,
   char *addr_start = arg;
   char **addr_string;
   struct cleanup *old_chain;
-  struct cleanup *breakpoint_chain = NULL;
+  struct cleanup *bkpt_chain = NULL;
   struct captured_parse_breakpoint_args parse_args;
   int i;
   int pending = 0;
   int not_found = 0;
+  enum bptype type_wanted;
+  int task = 0;
 
   sals.sals = NULL;
   sals.nelts = 0;
@@ -5530,8 +6573,8 @@ break_command_really (char *arg, char *cond_string, int thread,
 
           /* If pending breakpoint support is auto query and the user
             selects no, then simply return the error code.  */
-         if (pending_break_support == AUTO_BOOLEAN_AUTO && 
-             !nquery ("Make breakpoint pending on future shared library load? "))
+         if (pending_break_support == AUTO_BOOLEAN_AUTO
+             && !nquery ("Make breakpoint pending on future shared library load? "))
            return;
 
          /* At this point, either the user was queried about setting
@@ -5568,12 +6611,11 @@ break_command_really (char *arg, char *cond_string, int thread,
   /* ----------------------------- SNIP -----------------------------
      Anything added to the cleanup chain beyond this point is assumed
      to be part of a breakpoint.  If the breakpoint create succeeds
-     then the memory is not reclaimed. */
-  breakpoint_chain = make_cleanup (null_cleanup, 0);
+     then the memory is not reclaimed.  */
+  bkpt_chain = make_cleanup (null_cleanup, 0);
 
   /* Mark the contents of the addr_string for cleanup.  These go on
-     the breakpoint_chain and only occure if the breakpoint create
-     fails. */
+     the bkpt_chain and only occur if the breakpoint create fails.  */
   for (i = 0; i < sals.nelts; i++)
     {
       if (addr_string[i] != NULL)
@@ -5585,6 +6627,10 @@ break_command_really (char *arg, char *cond_string, int thread,
   if (!pending)
     breakpoint_sals_to_pc (&sals, addr_start);
 
+  type_wanted = (traceflag
+                ? bp_tracepoint
+                : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
+
   /* Verify that condition can be parsed, before setting any
      breakpoints.  Allocate a separate condition expression for each
      breakpoint. */
@@ -5598,7 +6644,8 @@ break_command_really (char *arg, char *cond_string, int thread,
                re-parse it in context of each sal.  */
             cond_string = NULL;
             thread = -1;
-            find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
+            find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
+                                       &thread, &task);
             if (cond_string)
                 make_cleanup (xfree, cond_string);
         }
@@ -5611,11 +6658,9 @@ break_command_really (char *arg, char *cond_string, int thread,
                 make_cleanup (xfree, cond_string);
             }
         }
-      create_breakpoints (sals, addr_string, cond_string,
-                         hardwareflag ? bp_hardware_breakpoint 
-                         : bp_breakpoint,
+      create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted,
                          tempflag ? disp_del : disp_donttouch,
-                         thread, ignore_count, ops, from_tty, enabled);
+                         thread, task, ignore_count, ops, from_tty, enabled);
     }
   else
     {
@@ -5624,9 +6669,7 @@ break_command_really (char *arg, char *cond_string, int thread,
 
       make_cleanup (xfree, copy_arg);
 
-      b = set_raw_breakpoint_without_location (hardwareflag 
-                                              ? bp_hardware_breakpoint 
-                                              : bp_breakpoint);
+      b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
       set_breakpoint_count (breakpoint_count + 1);
       b->number = breakpoint_count;
       b->thread = -1;
@@ -5637,19 +6680,27 @@ break_command_really (char *arg, char *cond_string, int thread,
       b->condition_not_parsed = 1;
       b->ops = ops;
       b->enable_state = enabled ? bp_enabled : bp_disabled;
+      b->pspace = current_program_space;
+
+      if (enabled && b->pspace->executing_startup
+         && (b->type == bp_breakpoint
+             || b->type == bp_hardware_breakpoint))
+       b->enable_state = bp_startup_disabled;
 
-      update_global_location_list (1);
       mention (b);
     }
   
   if (sals.nelts > 1)
     warning (_("Multiple breakpoints were set.\n"
               "Use the \"delete\" command to delete unwanted breakpoints."));
-  /* That's it. Discard the cleanups for data inserted into the
-     breakpoint. */
-  discard_cleanups (breakpoint_chain);
-  /* But cleanup everything else. */
+  /* That's it.  Discard the cleanups for data inserted into the
+     breakpoint.  */
+  discard_cleanups (bkpt_chain);
+  /* But cleanup everything else.  */
   do_cleanups (old_chain);
+
+  /* error call may happen here - have BKPT_CHAIN already discarded.  */
+  update_global_location_list (1);
 }
 
 /* Set a breakpoint. 
@@ -5665,9 +6716,10 @@ break_command_1 (char *arg, int flag, int from_tty)
   int hardwareflag = flag & BP_HARDWAREFLAG;
   int tempflag = flag & BP_TEMPFLAG;
 
-  break_command_really (arg, 
+  break_command_really (get_current_arch (),
+                       arg,
                        NULL, 0, 1 /* parse arg */,
-                       tempflag, hardwareflag,
+                       tempflag, hardwareflag, 0 /* traceflag */,
                        0 /* Ignore count */,
                        pending_break_support, 
                        NULL /* breakpoint_ops */,
@@ -5677,14 +6729,16 @@ break_command_1 (char *arg, int flag, int from_tty)
 
 
 void
-set_breakpoint (char *address, char *condition,
+set_breakpoint (struct gdbarch *gdbarch,
+               char *address, char *condition,
                int hardwareflag, int tempflag,
                int thread, int ignore_count,
                int pending, int enabled)
 {
-  break_command_really (address, condition, thread,
+  break_command_really (gdbarch,
+                       address, condition, thread,
                        0 /* condition and thread are valid.  */,
-                       tempflag, hardwareflag,
+                       tempflag, hardwareflag, 0 /* traceflag */,
                        ignore_count,
                        pending 
                        ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
@@ -5693,22 +6747,33 @@ set_breakpoint (char *address, char *condition,
 
 /* Adjust SAL to the first instruction past the function prologue.
    The end of the prologue is determined using the line table from
-   the debugging information.
+   the debugging information.  explicit_pc and explicit_line are
+   not modified.
 
    If SAL is already past the prologue, then do nothing.  */
 
 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 ();
+
+  sym = find_pc_function (sal->pc);
+  if (sym != NULL)
+    {
+      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;
+       }
+    }
 
-  start_sal = find_function_start_sal (sym, 1);
-  if (sal->pc < start_sal.pc)
-    *sal = start_sal;
+  do_cleanups (old_chain);
 }
 
 /* Helper function for break_command_1 and disassemble_command.  */
@@ -5728,7 +6793,12 @@ resolve_sal_pc (struct symtab_and_line *sal)
       /* If this SAL corresponds to a breakpoint inserted using
          a line number, then skip the function prologue if necessary.  */
       if (sal->explicit_line)
-        skip_prologue_sal (sal);
+       {
+         /* Preserve the original line number.  */
+         int saved_line = sal->line;
+         skip_prologue_sal (sal);
+         sal->line = saved_line;
+       }
     }
 
   if (sal->section == 0 && sal->symtab != NULL)
@@ -5754,10 +6824,15 @@ resolve_sal_pc (struct symtab_and_line *sal)
                 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);
            }
        }
     }
@@ -5866,13 +6941,13 @@ stopat_command (char *arg, int from_tty)
 static void
 watch_command_1 (char *arg, int accessflag, int from_tty)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
   struct breakpoint *b, *scope_breakpoint = NULL;
   struct symtab_and_line sal;
   struct expression *exp;
   struct block *exp_valid_block;
   struct value *val, *mark;
   struct frame_info *frame;
-  struct frame_info *prev_frame = NULL;
   char *exp_start = NULL;
   char *exp_end = NULL;
   char *tok, *id_tok_start, *end_tok;
@@ -5948,6 +7023,8 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
         }
     }
 
+  sal.pspace = current_program_space;
+
   /* Parse the rest of the arguments.  */
   innermost_block = NULL;
   exp_start = arg;
@@ -5997,7 +7074,7 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
     {
       i = hw_watchpoint_used_count (bp_type, &other_type_used);
       target_resources_ok = 
-       TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, 
+       target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, 
                                            other_type_used);
       if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
        error (_("Target does not support this type of hardware watchpoint."));
@@ -6012,38 +7089,42 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
     bp_type = bp_watchpoint;
 
   frame = block_innermost_frame (exp_valid_block);
-  if (frame)
-    prev_frame = get_prev_frame (frame);
-  else
-    prev_frame = NULL;
 
   /* If the expression is "local", then set up a "watchpoint scope"
      breakpoint at the point where we've left the scope of the watchpoint
      expression.  Create the scope breakpoint before the watchpoint, so
      that we will encounter it first in bpstat_stop_status.  */
-  if (innermost_block && prev_frame)
+  if (innermost_block && frame)
     {
-      scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
-                                                    bp_watchpoint_scope);
-
-      scope_breakpoint->enable_state = bp_enabled;
-
-      /* Automatically delete the breakpoint when it hits.  */
-      scope_breakpoint->disposition = disp_del;
-
-      /* Only break in the proper frame (help with recursion).  */
-      scope_breakpoint->frame_id = get_frame_id (prev_frame);
-
-      /* Set the address at which we will stop.  */
-      scope_breakpoint->loc->requested_address
-       = get_frame_pc (prev_frame);
-      scope_breakpoint->loc->address
-       = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
-                                    scope_breakpoint->type);
+      if (frame_id_p (frame_unwind_caller_id (frame)))
+       {
+         scope_breakpoint
+           = create_internal_breakpoint (frame_unwind_caller_arch (frame),
+                                         frame_unwind_caller_pc (frame),
+                                         bp_watchpoint_scope);
+
+         scope_breakpoint->enable_state = bp_enabled;
+
+         /* Automatically delete the breakpoint when it hits.  */
+         scope_breakpoint->disposition = disp_del;
+
+         /* Only break in the proper frame (help with recursion).  */
+         scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
+
+         /* Set the address at which we will stop.  */
+         scope_breakpoint->loc->gdbarch
+           = frame_unwind_caller_arch (frame);
+         scope_breakpoint->loc->requested_address
+           = frame_unwind_caller_pc (frame);
+         scope_breakpoint->loc->address
+           = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
+                                        scope_breakpoint->loc->requested_address,
+                                        scope_breakpoint->type);
+       }
     }
 
   /* Now set up the breakpoint.  */
-  b = set_raw_breakpoint (sal, bp_type);
+  b = set_raw_breakpoint (gdbarch, sal, bp_type);
   set_breakpoint_count (breakpoint_count + 1);
   b->number = breakpoint_count;
   b->thread = thread;
@@ -6132,10 +7213,10 @@ can_use_hardware_watchpoint (struct value *v)
                  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
                      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
                {
-                 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
+                 CORE_ADDR vaddr = value_address (v);
                  int       len   = TYPE_LENGTH (value_type (v));
 
-                 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
+                 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
                    return 0;
                  else
                    found_memory_cnt++;
@@ -6220,7 +7301,6 @@ until_break_command (char *arg, int from_tty, int anywhere)
   struct symtabs_and_lines sals;
   struct symtab_and_line sal;
   struct frame_info *frame = get_selected_frame (NULL);
-  struct frame_info *prev_frame = get_prev_frame (frame);
   struct breakpoint *breakpoint;
   struct breakpoint *breakpoint2 = NULL;
   struct cleanup *old_chain;
@@ -6251,22 +7331,27 @@ until_break_command (char *arg, int from_tty, int anywhere)
   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 (sal, null_frame_id, bp_until);
+    breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
+                                          null_frame_id, bp_until);
   else
-    /* Otherwise, specify the current frame, because we want to stop only
+    /* Otherwise, specify the selected frame, because we want to stop only
        at the very same frame.  */
-    breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
+    breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
+                                          get_stack_frame_id (frame),
                                           bp_until);
 
   old_chain = make_cleanup_delete_breakpoint (breakpoint);
 
   /* Keep within the current frame, or in frames called by the current
      one.  */
-  if (prev_frame)
+
+  if (frame_id_p (frame_unwind_caller_id (frame)))
     {
-      sal = find_pc_line (get_frame_pc (prev_frame), 0);
-      sal.pc = get_frame_pc (prev_frame);
-      breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
+      sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
+      sal.pc = frame_unwind_caller_pc (frame);
+      breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
+                                             sal,
+                                             frame_unwind_caller_id (frame),
                                              bp_until);
       make_cleanup_delete_breakpoint (breakpoint2);
     }
@@ -6383,6 +7468,7 @@ catch_fork_kind;
 static void
 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
   char *cond_string = NULL;
   catch_fork_kind fork_kind;
   int tempflag;
@@ -6411,12 +7497,12 @@ catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
     {
     case catch_fork_temporary:
     case catch_fork_permanent:
-      create_fork_vfork_event_catchpoint (tempflag, cond_string,
+      create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
                                           &catch_fork_breakpoint_ops);
       break;
     case catch_vfork_temporary:
     case catch_vfork_permanent:
-      create_fork_vfork_event_catchpoint (tempflag, cond_string,
+      create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
                                           &catch_vfork_breakpoint_ops);
       break;
     default:
@@ -6428,6 +7514,7 @@ catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
 static void
 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   char *cond_string = NULL;
 
@@ -6449,7 +7536,8 @@ catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
 
   /* If this target supports it, create an exec catchpoint
      and enable reporting of such events. */
-  create_catchpoint (tempflag, cond_string, &catch_exec_breakpoint_ops);
+  create_catchpoint (gdbarch, tempflag, cond_string,
+                    &catch_exec_breakpoint_ops);
 }
 
 static enum print_stop_action
@@ -6464,7 +7552,7 @@ print_exception_catchpoint (struct breakpoint *b)
     breakpoint_adjustment_warning (b->loc->requested_address,
                                   b->loc->address,
                                   b->number, 1);
-  bp_temp = b->loc->owner->disposition == disp_del;
+  bp_temp = b->disposition == disp_del;
   ui_out_text (uiout, 
               bp_temp ? "Temporary catchpoint "
                       : "Catchpoint ");
@@ -6484,7 +7572,7 @@ print_exception_catchpoint (struct breakpoint *b)
 }
 
 static void
-print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
+print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc)
 {
   struct value_print_options opts;
   get_user_print_options (&opts);
@@ -6494,11 +7582,12 @@ print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
       if (b->loc == NULL || b->loc->shlib_disabled)
        ui_out_field_string (uiout, "addr", "<PENDING>");
       else
-       ui_out_field_core_addr (uiout, "addr", b->loc->address);
+       ui_out_field_core_addr (uiout, "addr",
+                               b->loc->gdbarch, b->loc->address);
     }
   annotate_field (5);
   if (b->loc)
-    *last_addr = b->loc->address;
+    *last_loc = b->loc;
   if (strstr (b->addr_string, "throw") != NULL)
     ui_out_field_string (uiout, "what", "exception throw");
   else
@@ -6511,7 +7600,7 @@ print_mention_exception_catchpoint (struct breakpoint *b)
   int bp_temp;
   int bp_throw;
 
-  bp_temp = b->loc->owner->disposition == disp_del;
+  bp_temp = b->disposition == disp_del;
   bp_throw = strstr (b->addr_string, "throw") != NULL;
   ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
                              : _("Catchpoint "));
@@ -6540,9 +7629,10 @@ handle_gnu_v3_exceptions (int tempflag, char *cond_string,
   else
     trigger_func_name = "__cxa_throw";
 
-  break_command_really (trigger_func_name, cond_string, -1,
+  break_command_really (get_current_arch (),
+                       trigger_func_name, cond_string, -1,
                        0 /* condition and thread are valid.  */,
-                       tempflag, 0,
+                       tempflag, 0, 0,
                        0,
                        AUTO_BOOLEAN_TRUE /* pending */,
                        &gnu_v3_exception_catchpoint_ops, from_tty,
@@ -6569,8 +7659,8 @@ catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
   if ((*arg != '\0') && !isspace (*arg))
     error (_("Junk at end of arguments."));
 
-  if ((ex_event != EX_EVENT_THROW) &&
-      (ex_event != EX_EVENT_CATCH))
+  if (ex_event != EX_EVENT_THROW
+      && ex_event != EX_EVENT_CATCH)
     error (_("Unsupported or unknown exception event; cannot catch it"));
 
   if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
@@ -6600,7 +7690,8 @@ catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
 /* Create a breakpoint struct for Ada exception catchpoints.  */
 
 static void
-create_ada_exception_breakpoint (struct symtab_and_line sal,
+create_ada_exception_breakpoint (struct gdbarch *gdbarch,
+                                struct symtab_and_line sal,
                                  char *addr_string,
                                  char *exp_string,
                                  char *cond_string,
@@ -6613,7 +7704,12 @@ create_ada_exception_breakpoint (struct symtab_and_line sal,
 
   if (from_tty)
     {
-      describe_other_breakpoints (sal.pc, sal.section, -1);
+      struct gdbarch *loc_gdbarch = get_sal_arch (sal);
+      if (!loc_gdbarch)
+       loc_gdbarch = gdbarch;
+
+      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.
@@ -6624,7 +7720,7 @@ create_ada_exception_breakpoint (struct symtab_and_line sal,
          enough for now, though.  */
     }
 
-  b = set_raw_breakpoint (sal, bp_breakpoint);
+  b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
   set_breakpoint_count (breakpoint_count + 1);
 
   b->enable_state = bp_enabled;
@@ -6649,6 +7745,7 @@ static void
 catch_ada_exception_command (char *arg, int from_tty,
                             struct cmd_list_element *command)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   struct symtab_and_line sal;
   enum bptype type;
@@ -6664,16 +7761,114 @@ catch_ada_exception_command (char *arg, int from_tty,
     arg = "";
   sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
                                        &cond_string, &cond, &ops);
-  create_ada_exception_breakpoint (sal, addr_string, exp_string,
+  create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
                                    cond_string, cond, ops, tempflag,
                                    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
 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   struct symtab_and_line sal;
   char *addr_string = NULL;
@@ -6684,8 +7879,8 @@ catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
   if (!arg)
     arg = "";
   sal = ada_decode_assert_location (arg, &addr_string, &ops);
-  create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
-                                   tempflag, from_tty);
+  create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
+                                  ops, tempflag, from_tty);
 }
 
 static void
@@ -6728,6 +7923,7 @@ clear_command (char *arg, int from_tty)
       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."));
 
@@ -6791,13 +7987,15 @@ clear_command (char *arg, int from_tty)
              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)
@@ -6865,14 +8063,80 @@ breakpoint_auto_delete (bpstat bs)
   }
 }
 
-/* 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
@@ -6894,49 +8158,66 @@ static void
 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 
@@ -6944,11 +8225,11 @@ update_global_location_list (int should_insert)
         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.  */
@@ -6959,37 +8240,49 @@ update_global_location_list (int should_insert)
              /* 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;
            }
@@ -7011,25 +8304,65 @@ update_global_location_list (int should_insert)
                 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
-      && (target_has_execution
-         || (gdbarch_has_global_solist (target_gdbarch)
-             && target_supports_multi_process ())))
+      && (have_live_inferiors ()
+         || (gdbarch_has_global_breakpoints (target_gdbarch))))
     insert_breakpoint_locations ();
 
   do_cleanups (cleanups);
@@ -7135,6 +8468,7 @@ delete_breakpoint (struct breakpoint *bpt)
     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?
@@ -7194,11 +8528,13 @@ delete_command (char *arg, int from_tty)
          have to be deleted with an explicit breakpoint number argument.  */
       ALL_BREAKPOINTS (b)
       {
-       if (b->type != bp_call_dummy &&
-           b->type != bp_shlib_event &&
-           b->type != bp_thread_event &&
-           b->type != bp_overlay_event &&
-           b->number >= 0)
+       if (b->type != bp_call_dummy
+           && b->type != bp_shlib_event
+           && b->type != bp_jit_event
+           && b->type != bp_thread_event
+           && b->type != bp_overlay_event
+           && b->type != bp_longjmp_master
+           && b->number >= 0)
          {
            breaks_to_delete = 1;
            break;
@@ -7211,11 +8547,13 @@ delete_command (char *arg, int from_tty)
        {
          ALL_BREAKPOINTS_SAFE (b, temp)
          {
-           if (b->type != bp_call_dummy &&
-               b->type != bp_shlib_event &&
-               b->type != bp_thread_event &&
-               b->type != bp_overlay_event &&
-               b->number >= 0)
+           if (b->type != bp_call_dummy
+               && b->type != bp_shlib_event
+               && b->type != bp_thread_event
+               && b->type != bp_jit_event
+               && b->type != bp_overlay_event
+               && b->type != bp_longjmp_master
+               && b->number >= 0)
              delete_breakpoint (b);
          }
        }
@@ -7320,9 +8658,7 @@ update_breakpoint_locations (struct breakpoint *b,
       if (sals.sals[i].symtab == NULL)
        b->source_file = NULL;
       else
-       b->source_file =
-         savestring (sals.sals[i].symtab->filename,
-                     strlen (sals.sals[i].symtab->filename));
+       b->source_file = xstrdup (sals.sals[i].symtab->filename);
 
       if (b->line_number == 0)
        b->line_number = sals.sals[i].line;
@@ -7350,7 +8686,8 @@ update_breakpoint_locations (struct breakpoint *b,
            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;
@@ -7387,12 +8724,12 @@ breakpoint_re_set_one (void *bint)
   int i;
   int not_found = 0;
   int *not_found_ptr = &not_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)
     {
@@ -7402,6 +8739,11 @@ breakpoint_re_set_one (void *bint)
       return 0;
     case bp_breakpoint:
     case bp_hardware_breakpoint:
+    case bp_tracepoint:
+      /* Do not attempt to re-set breakpoints disabled during startup.  */
+      if (b->enable_state == bp_startup_disabled)
+       return 0;
+
       if (b->addr_string == NULL)
        {
          /* Anything without a string can't be re-set. */
@@ -7412,6 +8754,10 @@ breakpoint_re_set_one (void *bint)
       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,
@@ -7445,26 +8791,31 @@ breakpoint_re_set_one (void *bint)
            }
        }
 
-      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;
-         find_condition_and_thread (s, sals.sals[0].pc, 
-                                    &cond_string, &thread);
-         if (cond_string)
-           b->cond_string = cond_string;
-         b->thread = thread;
-         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:
@@ -7507,9 +8858,10 @@ breakpoint_re_set_one (void *bint)
     default:
       printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
       /* fall through */
-      /* Delete overlay event breakpoints; they will be reset later by
-         breakpoint_re_set.  */
+      /* Delete overlay event and longjmp master breakpoints; they will be
+        reset later by breakpoint_re_set.  */
     case bp_overlay_event:
+    case bp_longjmp_master:
       delete_breakpoint (b);
       break;
 
@@ -7532,9 +8884,11 @@ breakpoint_re_set_one (void *bint)
     case bp_step_resume:
     case bp_longjmp:
     case bp_longjmp_resume:
+    case bp_jit_event:
       break;
     }
 
+  do_cleanups (cleanups);
   return 0;
 }
 
@@ -7545,9 +8899,12 @@ breakpoint_re_set (void)
   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 */
@@ -7559,8 +8916,16 @@ breakpoint_re_set (void)
   }
   set_language (save_language);
   input_radix = save_input_radix;
-  
+
+  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");
+  create_longjmp_master_breakpoint ("siglongjmp");
+  create_longjmp_master_breakpoint ("_siglongjmp");
 }
 \f
 /* Reset the thread number of this breakpoint:
@@ -7574,6 +8939,12 @@ breakpoint_re_set_thread (struct breakpoint *b)
     {
       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;
     }
 }
 
@@ -7767,6 +9138,7 @@ disable_command (char *args, int from_tty)
                 bpt->number);
        continue;
       case bp_breakpoint:
+      case bp_tracepoint:
       case bp_catchpoint:
       case bp_hardware_breakpoint:
       case bp_watchpoint:
@@ -7799,7 +9171,7 @@ do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
       int i;
       i = hw_breakpoint_used_count ();
       target_resources_ok = 
-       TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 
+       target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 
                                            i + 1, 0);
       if (target_resources_ok == 0)
        error (_("No hardware breakpoint support in the target."));
@@ -7807,10 +9179,10 @@ do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
        error (_("Hardware breakpoints used exceeds limit."));
     }
 
-  if (bpt->type == bp_watchpoint || 
-      bpt->type == bp_hardware_watchpoint ||
-      bpt->type == bp_read_watchpoint || 
-      bpt->type == bp_access_watchpoint)
+  if (bpt->type == bp_watchpoint
+      || bpt->type == bp_hardware_watchpoint
+      || bpt->type == bp_read_watchpoint
+      || bpt->type == bp_access_watchpoint)
     {
       struct gdb_exception e;
 
@@ -7859,6 +9231,7 @@ enable_command (char *args, int from_tty)
                 bpt->number);
        continue;
       case bp_breakpoint:
+      case bp_tracepoint:
       case bp_catchpoint:
       case bp_hardware_breakpoint:
       case bp_watchpoint:
@@ -7942,15 +9315,17 @@ decode_line_spec_1 (char *string, int funfirstline)
    someday.  */
 
 void *
-deprecated_insert_raw_breakpoint (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 (bp_tgt) != 0)
+
+  if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
     {
       /* Could not insert the breakpoint.  */
       xfree (bp_tgt);
@@ -7963,12 +9338,12 @@ deprecated_insert_raw_breakpoint (CORE_ADDR pc)
 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint.  */
 
 int
-deprecated_remove_raw_breakpoint (void *bp)
+deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
 {
   struct bp_target_info *bp_tgt = bp;
   int ret;
 
-  ret = target_remove_breakpoint (bp_tgt);
+  ret = target_remove_breakpoint (gdbarch, bp_tgt);
   xfree (bp_tgt);
 
   return ret;
@@ -7977,20 +9352,26 @@ deprecated_remove_raw_breakpoint (void *bp)
 /* One (or perhaps two) breakpoints used for software single stepping.  */
 
 static void *single_step_breakpoints[2];
+static struct gdbarch *single_step_gdbarch[2];
 
 /* Create and insert a breakpoint for software single step.  */
 
 void
-insert_single_step_breakpoint (CORE_ADDR next_pc)
+insert_single_step_breakpoint (struct gdbarch *gdbarch,
+                              struct address_space *aspace, CORE_ADDR next_pc)
 {
   void **bpt_p;
 
   if (single_step_breakpoints[0] == NULL)
-    bpt_p = &single_step_breakpoints[0];
+    {
+      bpt_p = &single_step_breakpoints[0];
+      single_step_gdbarch[0] = gdbarch;
+    }
   else
     {
       gdb_assert (single_step_breakpoints[1] == NULL);
       bpt_p = &single_step_breakpoints[1];
+      single_step_gdbarch[1] = gdbarch;
     }
 
   /* NOTE drow/2006-04-11: A future improvement to this function would be
@@ -8000,10 +9381,10 @@ insert_single_step_breakpoint (CORE_ADDR next_pc)
      corresponding changes elsewhere where single step breakpoints are
      handled, however.  So, for now, we use this.  */
 
-  *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
+  *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
   if (*bpt_p == NULL)
-    error (_("Could not insert single-step breakpoint at 0x%s"),
-            paddr_nz (next_pc));
+    error (_("Could not insert single-step breakpoint at %s"),
+            paddress (gdbarch, next_pc));
 }
 
 /* Remove and delete any breakpoints used for software single step.  */
@@ -8015,12 +9396,16 @@ remove_single_step_breakpoints (void)
 
   /* See insert_single_step_breakpoint for more about this deprecated
      call.  */
-  deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
+  deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
+                                   single_step_breakpoints[0]);
+  single_step_gdbarch[0] = NULL;
   single_step_breakpoints[0] = NULL;
 
   if (single_step_breakpoints[1] != NULL)
     {
-      deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
+      deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
+                                       single_step_breakpoints[1]);
+      single_step_gdbarch[1] = NULL;
       single_step_breakpoints[1] = NULL;
     }
 }
@@ -8028,20 +9413,396 @@ remove_single_step_breakpoints (void)
 /* 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.  */
+static void
+set_tracepoint_count (int num)
+{
+  tracepoint_count = num;
+  set_internalvar_integer (lookup_internalvar ("tpnum"), num);
+}
+
+void
+trace_command (char *arg, int from_tty)
+{
+  break_command_really (get_current_arch (),
+                       arg,
+                       NULL, 0, 1 /* parse arg */,
+                       0 /* tempflag */, 0 /* hardwareflag */,
+                       1 /* traceflag */,
+                       0 /* Ignore count */,
+                       pending_break_support, 
+                       NULL,
+                       from_tty,
+                       1 /* enabled */);
+  set_tracepoint_count (breakpoint_count);
+}
+
+/* Print information on tracepoint number TPNUM_EXP, or all if
+   omitted.  */
+
+static void
+tracepoints_info (char *tpnum_exp, int from_tty)
+{
+  struct breakpoint *b;
+  int tps_to_list = 0;
+
+  /* In the no-arguments case, say "No tracepoints" if none found.  */
+  if (tpnum_exp == 0)
+    {
+      ALL_TRACEPOINTS (b)
+      {
+       if (b->number >= 0)
+         {
+           tps_to_list = 1;
+           break;
+         }
+      }
+      if (!tps_to_list)
+       {
+         ui_out_message (uiout, 0, "No tracepoints.\n");
+         return;
+       }
+    }
+
+  /* Otherwise be the same as "info break".  */
+  breakpoints_info (tpnum_exp, from_tty);
+}
+
+/* The 'enable trace' command enables tracepoints.  
+   Not supported by all targets.  */
+static void
+enable_trace_command (char *args, int from_tty)
+{
+  enable_command (args, from_tty);
+}
+
+/* The 'disable trace' command disables tracepoints.  
+   Not supported by all targets.  */
+static void
+disable_trace_command (char *args, int from_tty)
+{
+  disable_command (args, from_tty);
+}
+
+/* Remove a tracepoint (or all if no argument) */
+static void
+delete_trace_command (char *arg, int from_tty)
+{
+  struct breakpoint *b, *temp;
+
+  dont_repeat ();
+
+  if (arg == 0)
+    {
+      int breaks_to_delete = 0;
+
+      /* Delete all breakpoints if no argument.
+         Do not delete internal or call-dummy breakpoints, these
+         have to be deleted with an explicit breakpoint number argument.  */
+      ALL_TRACEPOINTS (b)
+      {
+       if (b->number >= 0)
+         {
+           breaks_to_delete = 1;
+           break;
+         }
+      }
+
+      /* Ask user only if there are some breakpoints to delete.  */
+      if (!from_tty
+         || (breaks_to_delete && query (_("Delete all tracepoints? "))))
+       {
+         ALL_BREAKPOINTS_SAFE (b, temp)
+         {
+           if (b->type == bp_tracepoint
+               && b->number >= 0)
+             delete_breakpoint (b);
+         }
+       }
+    }
+  else
+    map_breakpoint_numbers (arg, delete_breakpoint);
+}
+
+/* Set passcount for tracepoint.
+
+   First command argument is passcount, second is tracepoint number.
+   If tracepoint number omitted, apply to most recently defined.
+   Also accepts special argument "all".  */
+
+static void
+trace_pass_command (char *args, int from_tty)
+{
+  struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
+  unsigned int count;
+  int all = 0;
+
+  if (args == 0 || *args == 0)
+    error (_("passcount command requires an argument (count + optional TP num)"));
+
+  count = strtoul (args, &args, 10);   /* Count comes first, then TP num. */
+
+  while (*args && isspace ((int) *args))
+    args++;
+
+  if (*args && strncasecmp (args, "all", 3) == 0)
+    {
+      args += 3;                       /* Skip special argument "all".  */
+      all = 1;
+      if (*args)
+       error (_("Junk at end of arguments."));
+    }
+  else
+    t1 = get_tracepoint_by_number (&args, 1, 1);
+
+  do
+    {
+      if (t1)
+       {
+         ALL_TRACEPOINTS (t2)
+           if (t1 == (struct breakpoint *) -1 || t1 == t2)
+             {
+               t2->pass_count = count;
+               observer_notify_tracepoint_modified (t2->number);
+               if (from_tty)
+                 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
+                                  t2->number, count);
+             }
+         if (! all && *args)
+           t1 = get_tracepoint_by_number (&args, 1, 0);
+       }
+    }
+  while (*args);
+}
+
+struct breakpoint *
+get_tracepoint (int num)
+{
+  struct breakpoint *t;
+
+  ALL_TRACEPOINTS (t)
+    if (t->number == num)
+      return t;
+
+  return NULL;
+}
+
+/* Utility: parse a tracepoint number and look it up in the list.
+   If MULTI_P is true, there might be a range of tracepoints in ARG.
+   if OPTIONAL_P is true, then if the argument is missing, the most
+   recent tracepoint (tracepoint_count) is returned.  */
+struct breakpoint *
+get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
+{
+  extern int tracepoint_count;
+  struct breakpoint *t;
+  int tpnum;
+  char *instring = arg == NULL ? NULL : *arg;
+
+  if (arg == NULL || *arg == NULL || ! **arg)
+    {
+      if (optional_p)
+       tpnum = tracepoint_count;
+      else
+       error_no_arg (_("tracepoint number"));
+    }
+  else
+    tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
+
+  if (tpnum <= 0)
+    {
+      if (instring && *instring)
+       printf_filtered (_("bad tracepoint number at or near '%s'\n"), 
+                        instring);
+      else
+       printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
+      return NULL;
+    }
+
+  ALL_TRACEPOINTS (t)
+    if (t->number == tpnum)
+    {
+      return t;
+    }
+
+  /* FIXME: if we are in the middle of a range we don't want to give
+     a message.  The current interface to get_number_or_range doesn't
+     allow us to discover this.  */
+  printf_unfiltered ("No tracepoint number %d.\n", tpnum);
+  return NULL;
+}
+
+/* save-tracepoints command */
+static void
+tracepoint_save_command (char *args, int from_tty)
+{
+  struct breakpoint *tp;
+  int any_tp = 0;
+  struct action_line *line;
+  FILE *fp;
+  char *i1 = "    ", *i2 = "      ";
+  char *indent, *actionline, *pathname;
+  char tmp[40];
+  struct cleanup *cleanup;
+
+  if (args == 0 || *args == 0)
+    error (_("Argument required (file name in which to save tracepoints)"));
+
+  /* See if we have anything to save.  */
+  ALL_TRACEPOINTS (tp)
+  {
+    any_tp = 1;
+    break;
+  }
+  if (!any_tp)
+    {
+      warning (_("save-tracepoints: no tracepoints to save."));
+      return;
+    }
+
+  pathname = tilde_expand (args);
+  cleanup = make_cleanup (xfree, pathname);
+  fp = fopen (pathname, "w");
+  if (!fp)
+    error (_("Unable to open file '%s' for saving tracepoints (%s)"),
+          args, safe_strerror (errno));
+  make_cleanup_fclose (fp);
+  
+  ALL_TRACEPOINTS (tp)
+  {
+    if (tp->addr_string)
+      fprintf (fp, "trace %s\n", tp->addr_string);
+    else
+      {
+       sprintf_vma (tmp, tp->loc->address);
+       fprintf (fp, "trace *0x%s\n", tmp);
+      }
+
+    if (tp->pass_count)
+      fprintf (fp, "  passcount %d\n", tp->pass_count);
+
+    if (tp->actions)
+      {
+       fprintf (fp, "  actions\n");
+       indent = i1;
+       for (line = tp->actions; line; line = line->next)
+         {
+           struct cmd_list_element *cmd;
+
+           QUIT;               /* allow user to bail out with ^C */
+           actionline = line->action;
+           while (isspace ((int) *actionline))
+             actionline++;
+
+           fprintf (fp, "%s%s\n", indent, actionline);
+           if (*actionline != '#')     /* skip for comment lines */
+             {
+               cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1);
+               if (cmd == 0)
+                 error (_("Bad action list item: %s"), actionline);
+               if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
+                 indent = i2;
+               else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
+                 indent = i1;
+             }
+         }
+      }
+  }
+  do_cleanups (cleanup);
+  if (from_tty)
+    printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
+  return;
+}
+
+/* Create a vector of all tracepoints.  */
+
+VEC(breakpoint_p) *
+all_tracepoints ()
+{
+  VEC(breakpoint_p) *tp_vec = 0;
+  struct breakpoint *tp;
+
+  ALL_TRACEPOINTS (tp)
+  {
+    VEC_safe_push (breakpoint_p, tp_vec, tp);
+  }
+
+  return tp_vec;
+}
+
 \f
 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
    It is defined as a macro to prevent duplication.
@@ -8074,6 +9835,8 @@ static void
 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)
 {
@@ -8083,11 +9846,23 @@ add_catch_command (char *name, char *docstring,
                     &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
@@ -8098,12 +9873,15 @@ _initialize_breakpoint (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
      before a breakpoint is set.  */
   breakpoint_count = 0;
 
+  tracepoint_count = 0;
+
   add_com ("ignore", class_breakpoint, ignore_command, _("\
 Set ignore-count of breakpoint number N to COUNT.\n\
 Usage is `ignore N COUNT'."));
@@ -8261,11 +10039,8 @@ BREAK_ARGS_HELP ("break")));
   add_com_alias ("bre", "break", class_run, 1);
   add_com_alias ("brea", "break", class_run, 1);
 
- if (xdb_commands)
-    {
-      add_com_alias ("ba", "break", class_breakpoint, 1);
-      add_com_alias ("bu", "ubreak", class_breakpoint, 1);
-    }
+  if (xdb_commands)
+   add_com_alias ("ba", "break", class_breakpoint, 1);
 
   if (dbx_commands)
     {
@@ -8362,36 +10137,53 @@ Set temporary catchpoints to catch events."),
 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);
 
@@ -8433,6 +10225,58 @@ hardware.)"),
 
   can_use_hw_watchpoints = 1;
 
+  /* Tracepoint manipulation commands.  */
+
+  c = add_com ("trace", class_breakpoint, trace_command, _("\
+Set a tracepoint at specified line or function.\n\
+\n"
+BREAK_ARGS_HELP ("trace") "\n\
+Do \"help tracepoints\" for info on other tracepoint commands."));
+  set_cmd_completer (c, location_completer);
+
+  add_com_alias ("tp", "trace", class_alias, 0);
+  add_com_alias ("tr", "trace", class_alias, 1);
+  add_com_alias ("tra", "trace", class_alias, 1);
+  add_com_alias ("trac", "trace", class_alias, 1);
+
+  add_info ("tracepoints", tracepoints_info, _("\
+Status of tracepoints, or tracepoint number NUMBER.\n\
+Convenience variable \"$tpnum\" contains the number of the\n\
+last tracepoint set."));
+
+  add_info_alias ("tp", "tracepoints", 1);
+
+  add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
+Delete specified tracepoints.\n\
+Arguments are tracepoint numbers, separated by spaces.\n\
+No argument means delete all tracepoints."),
+          &deletelist);
+
+  c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
+Disable specified tracepoints.\n\
+Arguments are tracepoint numbers, separated by spaces.\n\
+No argument means disable all tracepoints."),
+          &disablelist);
+  deprecate_cmd (c, "disable");
+
+  c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
+Enable specified tracepoints.\n\
+Arguments are tracepoint numbers, separated by spaces.\n\
+No argument means enable all tracepoints."),
+          &enablelist);
+  deprecate_cmd (c, "enable");
+
+  add_com ("passcount", class_trace, trace_pass_command, _("\
+Set the passcount for a tracepoint.\n\
+The trace will end when the tracepoint has been passed 'count' times.\n\
+Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
+if TPNUM is omitted, passcount refers to the last tracepoint defined."));
+
+  c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\
+Save current tracepoint definitions as a script.\n\
+Use the 'source' command in another debug session to restore them."));
+  set_cmd_completer (c, filename_completer);
+
   add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
 Breakpoint specific settings\n\
 Configure various breakpoint-specific variables such as\n\
@@ -8491,4 +10335,6 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
                           &breakpoint_show_cmdlist);
   
   automatic_hardware_breakpoints = 1;
+
+  observer_attach_about_to_proceed (breakpoint_about_to_proceed);
 }
This page took 0.098439 seconds and 4 git commands to generate.