* read.c (cons_worker): Detect and reject unexpected string argument.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index cbcc7df4377d1cf74098443f3f14b7c7e2e58407..3dca17ec9b74009907ed644313ce5193dcbf280b 100644 (file)
@@ -2,7 +2,7 @@
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 2009 Free Software Foundation, Inc.
+   2008, 2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -59,6 +59,8 @@
 #include "top.h"
 #include "wrapper.h"
 #include "valprint.h"
+#include "jit.h"
+#include "xml-syscall.h"
 
 /* readline include files */
 #include "readline/readline.h"
 
 static void enable_delete_command (char *, int);
 
-static void enable_delete_breakpoint (struct breakpoint *);
-
 static void enable_once_command (char *, int);
 
-static void enable_once_breakpoint (struct breakpoint *);
-
 static void disable_command (char *, int);
 
 static void enable_command (char *, int);
 
-static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
+static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
+                                                     void *),
+                                   void *);
 
 static void ignore_command (char *, int);
 
@@ -105,24 +105,34 @@ static void break_command_1 (char *, int, int);
 
 static void mention (struct breakpoint *);
 
-static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
+/* 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 check_duplicates (struct breakpoint *);
-
 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
                                            CORE_ADDR bpaddr,
                                             enum bptype bptype);
 
-static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR,
+static void describe_other_breakpoints (struct gdbarch *,
+                                       struct program_space *, CORE_ADDR,
                                        struct obj_section *, int);
 
+static int breakpoint_address_match (struct address_space *aspace1,
+                                    CORE_ADDR addr1,
+                                    struct address_space *aspace2,
+                                    CORE_ADDR addr2);
+
+static int watchpoint_locations_match (struct bp_location *loc1,
+                                      struct bp_location *loc2);
+
 static void breakpoints_info (char *, int);
 
-static void breakpoint_1 (int, int);
+static void watchpoints_info (char *, int);
+
+static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
 
 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
 
@@ -136,8 +146,6 @@ static void condition_command (char *, int);
 
 static int get_number_trailer (char **, int);
 
-void set_breakpoint_count (int);
-
 typedef enum
   {
     mark_inserted,
@@ -146,6 +154,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);
 
@@ -179,8 +188,6 @@ static void stopat_command (char *arg, int from_tty);
 
 static char *ep_parse_optional_if_clause (char **arg);
 
-static char *ep_parse_optional_filename (char **arg);
-
 static void catch_exception_command_1 (enum exception_event_kind ex_event, 
                                       char *arg, int tempflag, int from_tty);
 
@@ -188,7 +195,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);
 
@@ -198,10 +206,14 @@ static void update_global_location_list (int);
 
 static void update_global_location_list_nothrow (int);
 
-static int is_hardware_watchpoint (struct breakpoint *bpt);
+static int is_hardware_watchpoint (const struct breakpoint *bpt);
+
+static int is_watchpoint (const 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);
@@ -212,8 +224,22 @@ static void disable_trace_command (char *, int);
 
 static void trace_pass_command (char *, int);
 
-static void skip_prologue_sal (struct symtab_and_line *sal);
+/* A reference-counted struct command_line.  This lets multiple
+   breakpoints share a single command list.  */
+struct counted_command_line
+{
+  /* The reference count.  */
+  int refc;
 
+  /* The command list.  */
+  struct command_line *commands;
+};
+
+struct command_line *
+breakpoint_commands (struct breakpoint *b)
+{
+  return b->commands ? b->commands->commands : NULL;
+}
 
 /* Flag indicating that a command has proceeded the inferior past the
    current breakpoint.  */
@@ -329,39 +355,70 @@ static int overlay_events_enabled;
             B ? (TMP=B->next, 1): 0;   \
             B = TMP)
 
-/* Similar iterators for the low-level breakpoints.  */
-
-#define ALL_BP_LOCATIONS(B)  for (B = bp_location_chain; B; B = B->global_next)
+/* 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_SAFE(B,TMP)   \
-       for (B = bp_location_chain;     \
-            B ? (TMP=B->global_next, 1): 0;    \
-            B = TMP)
+#define ALL_BP_LOCATIONS(B,BP_TMP)                                     \
+       for (BP_TMP = bp_location;                                      \
+            BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
+            BP_TMP++)
 
 /* Iterator for tracepoints only.  */
 
 #define ALL_TRACEPOINTS(B)  \
   for (B = breakpoint_chain; B; B = B->next)  \
-    if ((B)->type == bp_tracepoint)
+    if (is_tracepoint (B))
 
 /* 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;
 
 /* Number of last breakpoint made.  */
 
-int breakpoint_count;
+static int breakpoint_count;
+
+/* The value of `breakpoint_count' before the last command that
+   created breakpoints.  If the last (break-like) command created more
+   than one breakpoint, then the difference between BREAKPOINT_COUNT
+   and PREV_BREAKPOINT_COUNT is more than one.  */
+static int prev_breakpoint_count;
 
 /* Number of last tracepoint made.  */
 
-int tracepoint_count;
+static int tracepoint_count;
+
+static struct cmd_list_element *breakpoint_set_cmdlist;
+static struct cmd_list_element *breakpoint_show_cmdlist;
+static struct cmd_list_element *save_cmdlist;
 
 /* Return whether a breakpoint is an active enabled breakpoint.  */
 static int
@@ -372,13 +429,36 @@ breakpoint_enabled (struct breakpoint *b)
 
 /* Set breakpoint count to NUM.  */
 
-void
+static void
 set_breakpoint_count (int num)
 {
+  prev_breakpoint_count = breakpoint_count;
   breakpoint_count = num;
   set_internalvar_integer (lookup_internalvar ("bpnum"), num);
 }
 
+/* Used by `start_rbreak_breakpoints' below, to record the current
+   breakpoint count before "rbreak" creates any breakpoint.  */
+static int rbreak_start_breakpoint_count;
+
+/* Called at the start an "rbreak" command to record the first
+   breakpoint made.  */
+
+void
+start_rbreak_breakpoints (void)
+{
+  rbreak_start_breakpoint_count = breakpoint_count;
+}
+
+/* Called at the end of an "rbreak" command to record the last
+   breakpoint made.  */
+
+void
+end_rbreak_breakpoints (void)
+{
+  prev_breakpoint_count = rbreak_start_breakpoint_count;
+}
+
 /* Used in run_command to zero the hit count when a new run starts. */
 
 void
@@ -390,6 +470,63 @@ clear_breakpoint_hit_counts (void)
     b->hit_count = 0;
 }
 
+/* Allocate a new counted_command_line with reference count of 1.
+   The new structure owns COMMANDS.  */
+
+static struct counted_command_line *
+alloc_counted_command_line (struct command_line *commands)
+{
+  struct counted_command_line *result
+    = xmalloc (sizeof (struct counted_command_line));
+  result->refc = 1;
+  result->commands = commands;
+  return result;
+}
+
+/* Increment reference count.  This does nothing if CMD is NULL.  */
+
+static void
+incref_counted_command_line (struct counted_command_line *cmd)
+{
+  if (cmd)
+    ++cmd->refc;
+}
+
+/* Decrement reference count.  If the reference count reaches 0,
+   destroy the counted_command_line.  Sets *CMDP to NULL.  This does
+   nothing if *CMDP is NULL.  */
+
+static void
+decref_counted_command_line (struct counted_command_line **cmdp)
+{
+  if (*cmdp)
+    {
+      if (--(*cmdp)->refc == 0)
+       {
+         free_command_lines (&(*cmdp)->commands);
+         xfree (*cmdp);
+       }
+      *cmdp = NULL;
+    }
+}
+
+/* A cleanup function that calls decref_counted_command_line.  */
+
+static void
+do_cleanup_counted_command_line (void *arg)
+{
+  decref_counted_command_line (arg);
+}
+
+/* Create a cleanup that calls decref_counted_command_line on the
+   argument.  */
+
+static struct cleanup *
+make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
+{
+  return make_cleanup (do_cleanup_counted_command_line, cmdp);
+}
+
 /* Default address, symtab and line to put a breakpoint at
    for "break" command with no arg.
    if default_breakpoint_valid is zero, the other three are
@@ -401,6 +538,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.
@@ -558,8 +697,77 @@ 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
+
+void
+set_breakpoint_condition (struct breakpoint *b, char *exp,
+                         int from_tty)
+{
+  struct bp_location *loc = b->loc;
+
+  for (; loc; loc = loc->next)
+    {
+      xfree (loc->cond);
+      loc->cond = NULL;
+    }
+  xfree (b->cond_string);
+  b->cond_string = NULL;
+  xfree (b->cond_exp);
+  b->cond_exp = NULL;
+
+  if (*exp == 0)
+    {
+      if (from_tty)
+       printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
+    }
+  else
+    {
+      char *arg = exp;
+      /* I don't know if it matters whether this is the string the user
+        typed in or the decompiled expression.  */
+      b->cond_string = xstrdup (arg);
+      b->condition_not_parsed = 0;
+
+      if (is_watchpoint (b))
+       {
+         innermost_block = NULL;
+         arg = exp;
+         b->cond_exp = parse_exp_1 (&arg, 0, 0);
+         if (*arg)
+           error (_("Junk at end of expression"));
+         b->cond_exp_valid_block = innermost_block;
+       }
+      else
+       {
+         for (loc = b->loc; loc; loc = loc->next)
+           {
+             arg = exp;
+             loc->cond =
+               parse_exp_1 (&arg, block_for_pc (loc->address), 0);
+             if (*arg)
+               error (_("Junk at end of expression"));
+           }
+       }
+    }
+  breakpoints_changed ();
+  observer_notify_breakpoint_modified (b->number);
+}
+
 /* condition N EXP -- set break condition of breakpoint N to EXP.  */
 
 static void
@@ -580,84 +788,240 @@ condition_command (char *arg, int from_tty)
   ALL_BREAKPOINTS (b)
     if (b->number == bnum)
       {
-       struct bp_location *loc = b->loc;
-       for (; loc; loc = loc->next)
-         {
-           if (loc->cond)
-             {
-               xfree (loc->cond);
-               loc->cond = 0;
-             }
-         }
-       if (b->cond_string != NULL)
-         xfree (b->cond_string);
-
-       if (*p == 0)
-         {
-           b->cond_string = NULL;
-           if (from_tty)
-             printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
-         }
-       else
-         {
-           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 = xstrdup (arg);
-           b->condition_not_parsed = 0;
-           for (loc = b->loc; loc; loc = loc->next)
-             {
-               arg = p;
-               loc->cond =
-                 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
-               if (*arg)
-                 error (_("Junk at end of expression"));
-             }
-         }
-       breakpoints_changed ();
-       observer_notify_breakpoint_modified (b->number);
+       set_breakpoint_condition (b, p, from_tty);
        return;
       }
 
   error (_("No breakpoint number %d."), bnum);
 }
 
+/* Check that COMMAND do not contain commands that are suitable
+   only for tracepoints and not suitable for ordinary breakpoints.
+   Throw if any such commands is found.
+*/
 static void
-commands_command (char *arg, int from_tty)
+check_no_tracepoint_commands (struct command_line *commands)
 {
-  struct breakpoint *b;
-  char *p;
-  int bnum;
-  struct command_line *l;
+  struct command_line *c;
+  for (c = commands; c; c = c->next)
+    {
+      int i;
 
-  /* If we allowed this, we would have problems with when to
-     free the storage, if we change the commands currently
-     being read from.  */
+      if (c->control_type == while_stepping_control)
+       error (_("The 'while-stepping' command can only be used for tracepoints"));
 
-  if (executing_breakpoint_commands)
-    error (_("Can't use the \"commands\" command among a breakpoint's commands."));
+      for (i = 0; i < c->body_count; ++i)
+       check_no_tracepoint_commands ((c->body_list)[i]);
 
-  p = arg;
-  bnum = get_number (&p);
+      /* Not that command parsing removes leading whitespace and comment
+        lines and also empty lines. So, we only need to check for
+        command directly.  */
+      if (strstr (c->line, "collect ") == c->line)
+       error (_("The 'collect' command can only be used for tracepoints"));
+
+      if (strstr (c->line, "teval ") == c->line)
+       error (_("The 'teval' command can only be used for tracepoints"));
+    }
+}
 
-  if (p && *p)
-    error (_("Unexpected extra arguments following breakpoint number."));
+/* Encapsulate tests for different types of tracepoints.  */
 
-  ALL_BREAKPOINTS (b)
-    if (b->number == bnum)
-      {
-       char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", 
-                                bnum);
-       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);
-       return;
+int
+is_tracepoint (const struct breakpoint *b)
+{
+  return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint);
+}
+  
+/* A helper function that validsates that COMMANDS are valid for a
+   breakpoint.  This function will throw an exception if a problem is
+   found.  */
+
+static void
+validate_commands_for_breakpoint (struct breakpoint *b,
+                                 struct command_line *commands)
+{
+  if (is_tracepoint (b))
+    {
+      /* We need to verify that each top-level element of commands
+        is valid for tracepoints, that there's at most one while-stepping
+        element, and that while-stepping's body has valid tracing commands
+        excluding nested while-stepping.  */
+      struct command_line *c;
+      struct command_line *while_stepping = 0;
+      for (c = commands; c; c = c->next)
+       {
+         char *l = c->line;
+         if (c->control_type == while_stepping_control)
+           {
+             if (b->type == bp_fast_tracepoint)
+               error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
+
+             if (while_stepping)
+               error (_("The 'while-stepping' command can be used only once"));
+             else
+               while_stepping = c;
+           }
+       }
+      if (while_stepping)
+       {
+         struct command_line *c2;
+
+         gdb_assert (while_stepping->body_count == 1);
+         c2 = while_stepping->body_list[0];
+         for (; c2; c2 = c2->next)
+           {
+             char *l = c2->line;
+             if (c2->control_type == while_stepping_control)
+               error (_("The 'while-stepping' command cannot be nested"));
+           }
+       }
+    }
+  else
+    {
+      check_no_tracepoint_commands (commands);
+    }
+}
+
+/* Set the command list of B to COMMANDS.  If breakpoint is tracepoint,
+   validate that only allowed commands are included.
+*/
+
+void
+breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
+{
+  validate_commands_for_breakpoint (b, commands);
+
+  decref_counted_command_line (&b->commands);
+  b->commands = alloc_counted_command_line (commands);
+  breakpoints_changed ();
+  observer_notify_breakpoint_modified (b->number);
+}
+
+void
+check_tracepoint_command (char *line, void *closure)
+{
+  struct breakpoint *b = closure;
+  validate_actionline (&line, b);
+}
+
+/* A structure used to pass information through
+   map_breakpoint_numbers.  */
+
+struct commands_info
+{
+  /* True if the command was typed at a tty.  */
+  int from_tty;
+
+  /* The breakpoint range spec.  */
+  char *arg;
+
+  /* Non-NULL if the body of the commands are being read from this
+     already-parsed command.  */
+  struct command_line *control;
+
+  /* The command lines read from the user, or NULL if they have not
+     yet been read.  */
+  struct counted_command_line *cmd;
+};
+
+/* A callback for map_breakpoint_numbers that sets the commands for
+   commands_command.  */
+
+static void
+do_map_commands_command (struct breakpoint *b, void *data)
+{
+  struct commands_info *info = data;
+
+  if (info->cmd == NULL)
+    {
+      struct command_line *l;
+
+      if (info->control != NULL)
+       l = copy_command_lines (info->control->body_list[0]);
+      else
+       {
+         struct cleanup *old_chain;
+         char *str;
+
+         str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
+                           info->arg);
+
+         old_chain = make_cleanup (xfree, str);
+
+         l = read_command_lines (str,
+                                 info->from_tty, 1,
+                                 (is_tracepoint (b)
+                                  ? check_tracepoint_command : 0),
+                                 b);
+
+         do_cleanups (old_chain);
+       }
+
+      info->cmd = alloc_counted_command_line (l);
+    }
+
+  /* If a breakpoint was on the list more than once, we don't need to
+     do anything.  */
+  if (b->commands != info->cmd)
+    {
+      validate_commands_for_breakpoint (b, info->cmd->commands);
+      incref_counted_command_line (info->cmd);
+      decref_counted_command_line (&b->commands);
+      b->commands = info->cmd;
+      breakpoints_changed ();
+      observer_notify_breakpoint_modified (b->number);
     }
-  error (_("No breakpoint number %d."), bnum);
+}
+
+static void
+commands_command_1 (char *arg, int from_tty, struct command_line *control)
+{
+  struct cleanup *cleanups;
+  struct commands_info info;
+
+  info.from_tty = from_tty;
+  info.control = control;
+  info.cmd = NULL;
+  /* If we read command lines from the user, then `info' will hold an
+     extra reference to the commands that we must clean up.  */
+  cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
+
+  if (arg == NULL || !*arg)
+    {
+      if (breakpoint_count - prev_breakpoint_count > 1)
+       arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count);
+      else if (breakpoint_count > 0)
+       arg = xstrprintf ("%d", breakpoint_count);
+      else
+       {
+         /* So that we don't try to free the incoming non-NULL
+            argument in the cleanup below.  Mapping breakpoint
+            numbers will fail in this case.  */
+         arg = NULL;
+       }
+    }
+  else
+    /* The command loop has some static state, so we need to preserve
+       our argument.  */
+    arg = xstrdup (arg);
+
+  if (arg != NULL)
+    make_cleanup (xfree, arg);
+
+  info.arg = arg;
+
+  map_breakpoint_numbers (arg, do_map_commands_command, &info);
+
+  if (info.cmd == NULL)
+    error (_("No breakpoints specified."));
+
+  do_cleanups (cleanups);
+}
+
+static void
+commands_command (char *arg, int from_tty)
+{
+  commands_command_1 (arg, from_tty, NULL);
 }
 
 /* Like commands_command, but instead of reading the commands from
@@ -668,72 +1032,102 @@ commands_command (char *arg, int from_tty)
 enum command_control_type
 commands_from_control_command (char *arg, struct command_line *cmd)
 {
-  struct breakpoint *b;
-  char *p;
-  int bnum;
-
-  /* If we allowed this, we would have problems with when to
-     free the storage, if we change the commands currently
-     being read from.  */
-
-  if (executing_breakpoint_commands)
-    error (_("Can't use the \"commands\" command among a breakpoint's commands."));
-
-  /* An empty string for the breakpoint number means the last
-     breakpoint, but get_number expects a NULL pointer.  */
-  if (arg && !*arg)
-    p = NULL;
-  else
-    p = arg;
-  bnum = get_number (&p);
+  commands_command_1 (arg, 0, cmd);
+  return simple_control;
+}
 
-  if (p && *p)
-    error (_("Unexpected extra arguments following breakpoint number."));
+/* Return non-zero if BL->TARGET_INFO contains valid information.  */
 
-  ALL_BREAKPOINTS (b)
-    if (b->number == bnum)
-      {
-       free_command_lines (&b->commands);
-       if (cmd->body_count != 1)
-         error (_("Invalid \"commands\" block structure."));
-       /* We need to copy the commands because if/while will free the
-          list after it finishes execution.  */
-       b->commands = copy_command_lines (cmd->body_list[0]);
-       breakpoints_changed ();
-       observer_notify_breakpoint_modified (b->number);
-       return simple_control;
-      }
-  error (_("No breakpoint number %d."), bnum);
+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;
 }
-\f
+
 /* 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;
 
-  ALL_BP_LOCATIONS (b)
+  /* 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.  */
+
+  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
@@ -779,14 +1173,26 @@ insert_catchpoint (struct ui_out *uo, void *args)
   b->ops->insert (b);
 }
 
+/* Return true if BPT is of any hardware watchpoint kind.  */
+
 static int
-is_hardware_watchpoint (struct breakpoint *bpt)
+is_hardware_watchpoint (const struct breakpoint *bpt)
 {
   return (bpt->type == bp_hardware_watchpoint
          || bpt->type == bp_read_watchpoint
          || bpt->type == bp_access_watchpoint);
 }
 
+/* Return true if BPT is of any watchpoint kind, hardware or
+   software.  */
+
+static int
+is_watchpoint (const struct breakpoint *bpt)
+{
+  return (is_hardware_watchpoint (bpt)
+         || bpt->type == bp_watchpoint);
+}
+
 /* Find the current value of a watchpoint on EXP.  Return the value in
    *VALP and *RESULTP and the chain of intermediate and final values
    in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
@@ -865,6 +1271,24 @@ fetch_watchpoint_value (struct expression *exp, struct value **valp,
     }
 }
 
+/* Assuming that B is a watchpoint: returns true if the current thread
+   and its running state are safe to evaluate or update watchpoint B.
+   Watchpoints on local expressions need to be evaluated in the
+   context of the thread that was current when the watchpoint was
+   created, and, that thread needs to be stopped to be able to select
+   the correct frame context.  Watchpoints on global expressions can
+   be evaluated on any thread, and in any state.  It is presently left
+   to the target allowing memory accesses when threads are
+   running.  */
+
+static int
+watchpoint_in_thread_scope (struct breakpoint *b)
+{
+  return (ptid_equal (b->watchpoint_thread, null_ptid)
+         || (ptid_equal (inferior_ptid, b->watchpoint_thread)
+             && !is_executing (inferior_ptid)));
+}
+
 /* Assuming that B is a watchpoint:
    - Reparse watchpoint expression, if REPARSE is non-zero
    - Evaluate expression and store the result in B->val
@@ -873,16 +1297,62 @@ fetch_watchpoint_value (struct expression *exp, struct value **valp,
    - Update the list of values that must be watched in B->loc.
 
    If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
-   If this is local watchpoint that is out of scope, delete it.  */
+   If this is local watchpoint that is out of scope, delete it.
+
+   Even with `set breakpoint always-inserted on' the watchpoints are removed
+   + inserted on each stop here.  Normal breakpoints must never be removed
+   because they might be missed by a running thread when debugging in non-stop
+   mode.  On the other hand, hardware watchpoints (is_hardware_watchpoint;
+   processed here) are specific to each LWP since they are stored in each LWP's
+   hardware debug registers.  Therefore, such LWP must be stopped first in
+   order to be able to modify its hardware watchpoints.
+
+   Hardware watchpoints must be reset exactly once after being presented to the
+   user.  It cannot be done sooner, because it would reset the data used to
+   present the watchpoint hit to the user.  And it must not be done later
+   because it could display the same single watchpoint hit during multiple GDB
+   stops.  Note that the latter is relevant only to the hardware watchpoint
+   types bp_read_watchpoint and bp_access_watchpoint.  False hit by
+   bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
+   memory content has not changed.
+
+   The following constraints influence the location where we can reset hardware
+   watchpoints:
+
+   * target_stopped_by_watchpoint and target_stopped_data_address are called
+     several times when GDB stops.
+
+   [linux]
+   * Multiple hardware watchpoints can be hit at the same time, causing GDB to
+     stop.  GDB only presents one hardware watchpoint hit at a time as the
+     reason for stopping, and all the other hits are presented later, one after
+     the other, each time the user requests the execution to be resumed.
+     Execution is not resumed for the threads still having pending hit event
+     stored in LWP_INFO->STATUS.  While the watchpoint is already removed from
+     the inferior on the first stop the thread hit event is kept being reported
+     from its cached value by linux_nat_stopped_data_address until the real
+     thread resume happens after the watchpoint gets presented and thus its
+     LWP_INFO->STATUS gets reset.
+
+   Therefore the hardware watchpoint hit can get safely reset on the watchpoint
+   removal from inferior.  */
+
 static void
 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;
 
-  /* We don't free locations.  They are stored in bp_location_chain and
+  /* If this is a local watchpoint, we only want to check if the
+     watchpoint frame is in scope if the current thread is the thread
+     that was used to create the watchpoint.  */
+  if (!watchpoint_in_thread_scope (b))
+    return;
+
+  /* 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;
@@ -890,12 +1360,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)
@@ -903,6 +1368,15 @@ 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)
@@ -926,6 +1400,21 @@ update_watchpoint (struct breakpoint *b, int reparse)
       value_free (b->val);
       b->val = NULL;
       b->val_valid = 0;
+
+      /* Note that unlike with breakpoints, the watchpoint's condition
+        expression is stored in the breakpoint object, not in the
+        locations (re)created below.  */
+      if (b->cond_string != NULL)
+       {
+         if (b->cond_exp != NULL)
+           {
+             xfree (b->cond_exp);
+             b->cond_exp = NULL;
+           }
+
+         s = b->cond_string;
+         b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
+       }
     }
 
   /* If we failed to parse the expression, for example because
@@ -933,9 +1422,16 @@ update_watchpoint (struct breakpoint *b, int reparse)
      don't try to insert watchpoint.  We don't automatically delete
      such watchpoint, though, since failure to parse expression
      is different from out-of-scope watchpoint.  */
-  if (within_current_scope && b->exp)
+  if ( !target_has_execution)
+    {
+      /* Without execution, memory can't change.  No use to try and
+        set watchpoint locations.  The watchpoint will be reset when
+        the target gains execution, through breakpoint_re_set.  */
+    }
+  else if (within_current_scope && b->exp)
     {
       struct value *val_chain, *v, *result, *next;
+      struct program_space *frame_pspace;
 
       fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
 
@@ -957,6 +1453,13 @@ update_watchpoint (struct breakpoint *b, int reparse)
          {
            int i, mem_cnt, other_type_used;
 
+           /* We need to determine how many resources are already used
+              for all other hardware watchpoints to see if we still have
+              enough resources to also fit this watchpoint in as well.
+              To avoid the hw_watchpoint_used_count call below from counting
+              this watchpoint, make sure that it is marked as a software
+              watchpoint.  */
+           b->type = bp_watchpoint;
            i = hw_watchpoint_used_count (bp_hardware_watchpoint,
                                          &other_type_used);
            mem_cnt = can_use_hardware_watchpoint (val_chain);
@@ -974,6 +1477,8 @@ update_watchpoint (struct breakpoint *b, int reparse)
              }
          }
 
+      frame_pspace = get_frame_program_space (get_selected_frame (NULL));
+
       /* Look at each value on the value chain.  */
       for (v = val_chain; v; v = next)
        {
@@ -1011,6 +1516,8 @@ update_watchpoint (struct breakpoint *b, int reparse)
                    ;
                  *tmp = loc;
                  loc->gdbarch = get_type_arch (value_type (v));
+
+                 loc->pspace = frame_pspace;
                  loc->address = addr;
                  loc->length = len;
                  loc->watchpoint_type = type;
@@ -1022,14 +1529,17 @@ update_watchpoint (struct breakpoint *b, int reparse)
            value_free (v);
        }
 
-      /* We just regenerated the list of breakpoint locations.
-         The new location does not have its condition field set to anything
-         and therefore, we must always reparse the cond_string, independently
-         of the value of the reparse flag.  */
-      if (b->cond_string != NULL)
+      /* If a software watchpoint is not watching any memory, then the
+        above left it without any location set up.  But,
+        bpstat_stop_status requires a location to be able to report
+        stops, so make sure there's at least a dummy one.  */
+      if (b->type == bp_watchpoint && b->loc == NULL)
        {
-         char *s = b->cond_string;
-         b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
+         b->loc = allocate_bp_location (b);
+         b->loc->pspace = frame_pspace;
+         b->loc->address = -1;
+         b->loc->length = -1;
+         b->loc->watchpoint_type = -1;
        }
     }
   else if (!within_current_scope)
@@ -1039,12 +1549,17 @@ Watchpoint %d deleted because the program has left the block \n\
 in which its expression is valid.\n"),
                       b->number);
       if (b->related_breakpoint)
-       b->related_breakpoint->disposition = disp_del_at_next_stop;
+       {
+         b->related_breakpoint->disposition = disp_del_at_next_stop;
+         b->related_breakpoint->related_breakpoint = NULL;
+         b->related_breakpoint= NULL;
+       }
       b->disposition = disp_del_at_next_stop;
     }
 
   /* 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));
 }
 
 
@@ -1062,9 +1577,20 @@ 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)
+  if (is_tracepoint (bpt->owner))
     return 0;
 
   return 1;
@@ -1090,6 +1616,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)
@@ -1208,7 +1735,7 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
       if (val)
        {
          /* Can't set the breakpoint.  */
-         if (solib_name_from_address (bpt->address))
+         if (solib_name_from_address (bpt->pspace, bpt->address))
            {
              /* See also: disable_breakpoints_in_shlibs. */
              val = 0;
@@ -1260,10 +1787,43 @@ Note: automatically using hardware breakpoints for read-only addresses.\n"));
              watchpoints.  It's not clear that it's necessary... */
           && bpt->owner->disposition != disp_del_at_next_stop)
     {
-      val = target_insert_watchpoint (bpt->address, 
+      val = target_insert_watchpoint (bpt->address,
                                      bpt->length,
                                      bpt->watchpoint_type);
-      bpt->inserted = (val != -1);
+
+      /* If trying to set a read-watchpoint, and it turns out it's not
+        supported, try emulating one with an access watchpoint.  */
+      if (val == 1 && bpt->watchpoint_type == hw_read)
+       {
+         struct bp_location *loc, **loc_temp;
+
+         /* But don't try to insert it, if there's already another
+            hw_access location that would be considered a duplicate
+            of this one.  */
+         ALL_BP_LOCATIONS (loc, loc_temp)
+           if (loc != bpt
+               && loc->watchpoint_type == hw_access
+               && watchpoint_locations_match (bpt, loc))
+             {
+               bpt->duplicate = 1;
+               bpt->inserted = 1;
+               bpt->target_info = loc->target_info;
+               bpt->watchpoint_type = hw_access;
+               val = 0;
+               break;
+             }
+
+         if (val == 1)
+           {
+             val = target_insert_watchpoint (bpt->address,
+                                             bpt->length,
+                                             hw_access);
+             if (val == 0)
+               bpt->watchpoint_type = hw_access;
+           }
+       }
+
+      bpt->inserted = (val == 0);
     }
 
   else if (bpt->owner->type == bp_catchpoint)
@@ -1286,6 +1846,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
@@ -1317,7 +1919,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;
@@ -1329,9 +1931,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;
 
@@ -1341,6 +1948,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);
@@ -1365,7 +1982,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;
@@ -1404,11 +2021,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);
@@ -1422,35 +2059,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;
@@ -1480,6 +2126,7 @@ create_internal_breakpoint (struct gdbarch *gdbarch,
 
   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--;
@@ -1522,29 +2169,73 @@ create_overlay_event_breakpoint (char *func_name)
 }
 
 static void
-create_longjmp_master_breakpoint (char *func_name)
+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);
+}
+
+/* Create a master std::terminate breakpoint.  The actual function
+   looked for is named FUNC_NAME.  */
+static void
+create_std_terminate_master_breakpoint (const char *func_name)
 {
+  struct program_space *pspace;
   struct objfile *objfile;
+  struct cleanup *old_chain;
 
-  ALL_OBJFILES (objfile)
+  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)
+      m = lookup_minimal_symbol (func_name, NULL, objfile);
+      if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
+                       && MSYMBOL_TYPE (m) != mst_file_text))
         continue;
 
       b = create_internal_breakpoint (get_objfile_arch (objfile),
                                      SYMBOL_VALUE_ADDRESS (m),
-                                      bp_longjmp_master);
+                                      bp_std_terminate_master);
       b->addr_string = xstrdup (func_name);
       b->enable_state = bp_disabled;
     }
   update_global_location_list (1);
+
+  do_cleanups (old_chain);
 }
 
 void
@@ -1552,7 +2243,7 @@ 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
@@ -1562,11 +2253,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)
       {
@@ -1574,10 +2269,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 and longjmp master breakpoints.  */
     if (b->type == bp_thread_event || b->type == bp_overlay_event
-       || b->type == bp_longjmp_master)
+       || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
       {
        delete_breakpoint (b);
        continue;
@@ -1653,40 +2355,45 @@ update_breakpoints_after_exec (void)
   create_longjmp_master_breakpoint ("_longjmp");
   create_longjmp_master_breakpoint ("siglongjmp");
   create_longjmp_master_breakpoint ("_siglongjmp");
+  create_std_terminate_master_breakpoint ("std::terminate()");
 }
 
 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.  */
@@ -1764,7 +2471,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_name_from_address (b->address))
+      if (val && solib_name_from_address (b->pspace, b->address))
        val = 0;
 
       if (val)
@@ -1800,15 +2507,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
@@ -1827,30 +2559,55 @@ 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_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:
-      case bp_watchpoint_scope:
 
        /* If the call dummy breakpoint is at the entry point it will
-          cause problems when the inferior is rerun, so we better
-          get rid of it. 
+          cause problems when the inferior is rerun, so we better get
+          rid of it.  */
+
+      case bp_watchpoint_scope:
+
+       /* Also get rid of scope breakpoints.  */
+
+      case bp_shlib_event:
+
+       /* Also remove solib event breakpoints.  Their addresses may
+          have changed since the last time we ran the program.
+          Actually we may now be debugging against different target;
+          and so the solib backend that installed this breakpoint may
+          not be used in by the target.  E.g.,
+
+          (gdb) file prog-linux
+          (gdb) run               # native linux target
+          ...
+          (gdb) kill
+          (gdb) file prog-win.exe
+          (gdb) tar rem :9999     # remote Windows gdbserver.
+       */
 
-          Also get rid of scope breakpoints.  */
        delete_breakpoint (b);
        break;
 
@@ -1883,6 +2640,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
@@ -1894,12 +2656,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)
@@ -1907,7 +2669,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) 
@@ -1926,36 +2689,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) 
@@ -1972,12 +2737,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;
@@ -1987,18 +2752,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) 
@@ -2010,24 +2776,57 @@ 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;
 }
 
+int
+hardware_watchpoint_inserted_in_range (struct address_space *aspace,
+                                      CORE_ADDR addr, ULONGEST len)
+{
+  struct breakpoint *bpt;
+
+  ALL_BREAKPOINTS (bpt)
+    {
+      struct bp_location *loc;
+
+      if (bpt->type != bp_hardware_watchpoint
+         && bpt->type != bp_access_watchpoint)
+       continue;
+
+      if (!breakpoint_enabled (bpt))
+       continue;
+
+      for (loc = bpt->loc; loc; loc = loc->next)
+       if (loc->pspace->aspace == aspace && loc->inserted)
+         {
+           CORE_ADDR l, h;
+
+           /* Check for intersection.  */
+           l = max (loc->address, addr);
+           h = min (loc->address + loc->length, addr + len);
+           if (l < h)
+             return 1;
+         }
+    }
+  return 0;
+}
+
 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
    PC is valid for process/thread PTID.  */
 
 int
-breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
+breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
+                        ptid_t ptid)
 {
-  const struct bp_location *bpt;
+  struct bp_location *bpt, **bptp_tmp;
   /* The thread and task IDs associated to PTID, computed lazily.  */
   int thread = -1;
   int task = 0;
   
-  ALL_BP_LOCATIONS (bpt)
+  ALL_BP_LOCATIONS (bpt, bptp_tmp)
     {
       if (bpt->loc_type != bp_loc_software_breakpoint
          && bpt->loc_type != bp_loc_hardware_breakpoint)
@@ -2037,7 +2836,8 @@ breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
          && bpt->owner->enable_state != bp_permanent)
        continue;
 
-      if (bpt->address != pc)
+      if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
+                                    aspace, pc))
        continue;
 
       if (bpt->owner->thread != -1)
@@ -2088,7 +2888,7 @@ bpstat_free (bpstat bs)
 {
   if (bs->old_val != NULL)
     value_free (bs->old_val);
-  free_command_lines (&bs->commands);
+  decref_counted_command_line (&bs->commands);
   xfree (bs);
 }
 
@@ -2130,8 +2930,7 @@ bpstat_copy (bpstat bs)
     {
       tmp = (bpstat) xmalloc (sizeof (*tmp));
       memcpy (tmp, bs, sizeof (*tmp));
-      if (bs->commands != NULL)
-       tmp->commands = copy_command_lines (bs->commands);
+      incref_counted_command_line (tmp->commands);
       if (bs->old_val != NULL)
        {
          tmp->old_val = value_copy (bs->old_val);
@@ -2165,36 +2964,6 @@ bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
   return NULL;
 }
 
-/* Find a step_resume breakpoint associated with this bpstat.
-   (If there are multiple step_resume bp's on the list, this function
-   will arbitrarily pick one.)
-
-   It is an error to use this function if BPSTAT doesn't contain a
-   step_resume breakpoint.
-
-   See wait_for_inferior's use of this function.  */
-struct breakpoint *
-bpstat_find_step_resume_breakpoint (bpstat bsp)
-{
-  int current_thread;
-
-  gdb_assert (bsp != NULL);
-
-  current_thread = pid_to_thread_id (inferior_ptid);
-
-  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))
-       return bsp->breakpoint_at->owner;
-    }
-
-  internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
-}
-
-
 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
    at.  *BSP upon return is a bpstat which points to the remaining
    breakpoints stopped at (but which is not guaranteed to be good for
@@ -2232,7 +3001,8 @@ bpstat_clear_actions (bpstat bs)
 {
   for (; bs != NULL; bs = bs->next)
     {
-      free_command_lines (&bs->commands);
+      decref_counted_command_line (&bs->commands);
+      bs->commands_left = NULL;
       if (bs->old_val != NULL)
        {
          value_free (bs->old_val);
@@ -2298,6 +3068,7 @@ bpstat_do_actions_1 (bpstat *bsp)
   breakpoint_proceeded = 0;
   for (; bs != NULL; bs = bs->next)
     {
+      struct counted_command_line *ccmd;
       struct command_line *cmd;
       struct cleanup *this_cmd_tree_chain;
 
@@ -2311,9 +3082,12 @@ bpstat_do_actions_1 (bpstat *bsp)
          commands are only executed once, we don't need to copy it; we
          can clear the pointer in the bpstat, and make sure we free
          the tree when we're done.  */
-      cmd = bs->commands;
-      bs->commands = 0;
-      this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
+      ccmd = bs->commands;
+      bs->commands = NULL;
+      this_cmd_tree_chain
+       = make_cleanup_decref_counted_command_line (&ccmd);
+      cmd = bs->commands_left;
+      bs->commands_left = NULL;
 
       while (cmd != NULL)
        {
@@ -2481,6 +3255,12 @@ print_it_typical (bpstat bs)
       result = PRINT_NOTHING;
       break;
 
+    case bp_std_terminate_master:
+      /* These should never be enabled.  */
+      printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
+      result = PRINT_NOTHING;
+      break;
+
     case bp_watchpoint:
     case bp_hardware_watchpoint:
       annotate_watchpoint (b->number);
@@ -2571,7 +3351,10 @@ print_it_typical (bpstat bs)
     case bp_step_resume:
     case bp_watchpoint_scope:
     case bp_call_dummy:
+    case bp_std_terminate:
     case bp_tracepoint:
+    case bp_fast_tracepoint:
+    case bp_jit_event:
     default:
       result = PRINT_UNKNOWN;
       break;
@@ -2694,6 +3477,7 @@ bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */
   bs->breakpoint_at = bl;
   /* If the condition is false, etc., don't do the commands.  */
   bs->commands = NULL;
+  bs->commands_left = NULL;
   bs->old_val = NULL;
   bs->print_it = print_it_normal;
   return bs;
@@ -2714,9 +3498,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
       /* We were not stopped by a watchpoint.  Mark all watchpoints
         as not triggered.  */
       ALL_BREAKPOINTS (b)
-       if (b->type == bp_hardware_watchpoint
-           || b->type == bp_read_watchpoint
-           || b->type == bp_access_watchpoint)
+       if (is_hardware_watchpoint (b))
          b->watchpoint_triggered = watch_triggered_no;
 
       return 0;
@@ -2727,9 +3509,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
       /* We were stopped by a watchpoint, but we don't know where.
         Mark all watchpoints as unknown.  */
       ALL_BREAKPOINTS (b)
-       if (b->type == bp_hardware_watchpoint
-           || b->type == bp_read_watchpoint
-           || b->type == bp_access_watchpoint)
+       if (is_hardware_watchpoint (b))
          b->watchpoint_triggered = watch_triggered_unknown;
 
       return stopped_by_watchpoint;
@@ -2740,9 +3520,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
      triggered.  */
 
   ALL_BREAKPOINTS (b)
-    if (b->type == bp_hardware_watchpoint
-       || b->type == bp_read_watchpoint
-       || b->type == bp_access_watchpoint)
+    if (is_hardware_watchpoint (b))
       {
        struct bp_location *loc;
        struct value *v;
@@ -2771,11 +3549,16 @@ watchpoints_triggered (struct target_waitstatus *ws)
 #define WP_VALUE_CHANGED 2
 /* The value has not changed.  */
 #define WP_VALUE_NOT_CHANGED 3
+/* Ignore this watchpoint, no matter if the value changed or not.  */
+#define WP_IGNORE 4
 
 #define BP_TEMPFLAG 1
 #define BP_HARDWAREFLAG 2
 
-/* Check watchpoint condition.  */
+/* Evaluate watchpoint condition expression and check if its value changed.
+
+   P should be a pointer to struct bpstat, but is defined as a void *
+   in order for this function to be usable with catch_errors.  */
 
 static int
 watchpoint_check (void *p)
@@ -2787,6 +3570,12 @@ watchpoint_check (void *p)
 
   b = bs->breakpoint_at->owner;
 
+  /* If this is a local watchpoint, we only want to check if the
+     watchpoint frame is in scope if the current thread is the thread
+     that was used to create the watchpoint.  */
+  if (!watchpoint_in_thread_scope (b))
+    return WP_IGNORE;
+
   if (b->exp_valid_block == NULL)
     within_current_scope = 1;
   else
@@ -2795,6 +3584,17 @@ watchpoint_check (void *p)
       struct gdbarch *frame_arch = get_frame_arch (frame);
       CORE_ADDR frame_pc = get_frame_pc (frame);
 
+      /* 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.  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 and frame_find_by_id could error out.  */
+      if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
+       return WP_IGNORE;
+
       fr = frame_find_by_id (b->watchpoint_frame);
       within_current_scope = (fr != NULL);
 
@@ -2811,17 +3611,6 @@ watchpoint_check (void *p)
            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.  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 (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
@@ -2840,8 +3629,12 @@ watchpoint_check (void *p)
       struct value *new_val;
 
       fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
+
+      /* We use value_equal_contents instead of value_equal because the latter
+        coerces an array to a pointer, thus comparing just the address of the
+        array instead of its contents.  This is not what we want.  */
       if ((b->val != NULL) != (new_val != NULL)
-         || (b->val != NULL && !value_equal (b->val, new_val)))
+         || (b->val != NULL && !value_equal_contents (b->val, new_val)))
        {
          if (new_val != NULL)
            {
@@ -2851,14 +3644,12 @@ watchpoint_check (void *p)
          bs->old_val = b->val;
          b->val = new_val;
          b->val_valid = 1;
-         /* We will stop here */
          return WP_VALUE_CHANGED;
        }
       else
        {
-         /* Nothing changed, don't do anything.  */
+         /* Nothing changed.  */
          value_free_to_mark (mark);
-         /* We won't stop here */
          return WP_VALUE_NOT_CHANGED;
        }
     }
@@ -2885,7 +3676,11 @@ watchpoint_check (void *p)
 which its expression is valid.\n");     
 
       if (b->related_breakpoint)
-       b->related_breakpoint->disposition = disp_del_at_next_stop;
+       {
+         b->related_breakpoint->disposition = disp_del_at_next_stop;
+         b->related_breakpoint->related_breakpoint = NULL;
+         b->related_breakpoint = NULL;
+       }
       b->disposition = disp_del_at_next_stop;
 
       return WP_DELETED;
@@ -2896,35 +3691,37 @@ 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;
 
-  if (b->type != bp_watchpoint
-      && b->type != bp_hardware_watchpoint
-      && b->type != bp_read_watchpoint
-      && b->type != bp_access_watchpoint
+  /* By definition, the inferior does not report stops at
+     tracepoints.  */
+  if (is_tracepoint (b))
+    return 0;
+
+  if (!is_watchpoint (b)
       && 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) 
          && !section_is_mapped (bl->section))
        return 0;
     }
-  
+
   /* Continuable hardware watchpoints are treated as non-existent if the
      reason we stopped wasn't a hardware watchpoint (we didn't stop on
      some data address).  Otherwise gdb won't stop on a break instruction
      in the code (not from a breakpoint) when a hardware watchpoint has
      been defined.  Also skip watchpoints which we know did not trigger
      (did not match the data address).  */
-  
-  if ((b->type == bp_hardware_watchpoint
-       || b->type == bp_read_watchpoint
-       || b->type == bp_access_watchpoint)
+
+  if (is_hardware_watchpoint (b)
       && b->watchpoint_triggered == watch_triggered_no)
     return 0;
   
@@ -2957,10 +3754,7 @@ bpstat_check_watchpoint (bpstat bs)
   const struct bp_location *bl = bs->breakpoint_at;
   struct breakpoint *b = bl->owner;
 
-  if (b->type == bp_watchpoint
-      || b->type == bp_read_watchpoint
-      || b->type == bp_access_watchpoint
-      || b->type == bp_hardware_watchpoint)
+  if (is_watchpoint (b))
     {
       CORE_ADDR addr;
       struct value *v;
@@ -2998,14 +3792,74 @@ bpstat_check_watchpoint (bpstat bs)
              bs->print_it = print_it_done;
              /* Stop.  */
              break;
+           case WP_IGNORE:
+             bs->print_it = print_it_noop;
+             bs->stop = 0;
+             break;
            case WP_VALUE_CHANGED:
              if (b->type == bp_read_watchpoint)
                {
-                 /* Don't stop: read watchpoints shouldn't fire if
-                    the value has changed.  This is for targets
-                    which cannot set read-only watchpoints.  */
-                 bs->print_it = print_it_noop;
-                 bs->stop = 0;
+                 /* There are two cases to consider here:
+
+                    1. we're watching the triggered memory for reads.
+                    In that case, trust the target, and always report
+                    the watchpoint hit to the user.  Even though
+                    reads don't cause value changes, the value may
+                    have changed since the last time it was read, and
+                    since we're not trapping writes, we will not see
+                    those, and as such we should ignore our notion of
+                    old value.
+
+                    2. we're watching the triggered memory for both
+                    reads and writes.  There are two ways this may
+                    happen:
+
+                    2.1. this is a target that can't break on data
+                    reads only, but can break on accesses (reads or
+                    writes), such as e.g., x86.  We detect this case
+                    at the time we try to insert read watchpoints.
+
+                    2.2. otherwise, the target supports read
+                    watchpoints, but, the user set an access or write
+                    watchpoint watching the same memory as this read
+                    watchpoint.
+
+                    If we're watching memory writes as well as reads,
+                    ignore watchpoint hits when we find that the
+                    value hasn't changed, as reads don't cause
+                    changes.  This still gives false positives when
+                    the program writes the same value to memory as
+                    what there was already in memory (we will confuse
+                    it for a read), but it's much better than
+                    nothing.  */
+
+                 int other_write_watchpoint = 0;
+
+                 if (bl->watchpoint_type == hw_read)
+                   {
+                     struct breakpoint *other_b;
+
+                     ALL_BREAKPOINTS (other_b)
+                       if ((other_b->type == bp_hardware_watchpoint
+                            || other_b->type == bp_access_watchpoint)
+                           && (other_b->watchpoint_triggered
+                               == watch_triggered_yes))
+                         {
+                           other_write_watchpoint = 1;
+                           break;
+                         }
+                   }
+
+                 if (other_write_watchpoint
+                     || bl->watchpoint_type == hw_access)
+                   {
+                     /* We're watching the same memory for writes,
+                        and the value changed since the last time we
+                        updated it, so this trap must be for a write.
+                        Ignore it.  */
+                     bs->print_it = print_it_noop;
+                     bs->stop = 0;
+                   }
                }
              break;
            case WP_VALUE_NOT_CHANGED:
@@ -3061,16 +3915,24 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
   else if (bs->stop)
     {
       int value_is_zero = 0;
-      
+      struct expression *cond;
+
       /* If this is a scope breakpoint, mark the associated
         watchpoint as triggered so that we will handle the
         out-of-scope event.  We'll get to the watchpoint next
         iteration.  */
       if (b->type == bp_watchpoint_scope)
        b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
-      
-      if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
+
+      if (is_watchpoint (b))
+       cond = b->cond_exp;
+      else
+       cond = bl->cond;
+
+      if (cond && bl->owner->disposition != disp_del_at_next_stop)
        {
+         int within_current_scope = 1;
+
          /* 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
@@ -3084,15 +3946,50 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
             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);
+         if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
+           select_frame (get_current_frame ());
+         else
+           {
+             struct frame_info *frame;
+
+             /* For local watchpoint expressions, which particular
+                instance of a local is being watched matters, so we
+                keep track of the frame to evaluate the expression
+                in.  To evaluate the condition however, it doesn't
+                really matter which instantiation of the function
+                where the condition makes sense triggers the
+                watchpoint.  This allows an expression like "watch
+                global if q > 10" set in `func', catch writes to
+                global on all threads that call `func', or catch
+                writes on all recursive calls of `func' by a single
+                thread.  We simply always evaluate the condition in
+                the innermost frame that's executing where it makes
+                sense to evaluate the condition.  It seems
+                intuitive.  */
+             frame = block_innermost_frame (b->cond_exp_valid_block);
+             if (frame != NULL)
+               select_frame (frame);
+             else
+               within_current_scope = 0;
+           }
+         if (within_current_scope)
+           value_is_zero
+             = catch_errors (breakpoint_cond_eval, cond,
+                             "Error in testing breakpoint condition:\n",
+                             RETURN_MASK_ALL);
+         else
+           {
+             warning (_("Watchpoint condition cannot be tested "
+                        "in the current scope"));
+             /* If we failed to set the right context for this
+                watchpoint, unconditionally report it.  */
+             value_is_zero = 0;
+           }
          /* FIXME-someday, should give breakpoint # */
          value_free_to_mark (mark);
        }
-      if (bl->cond && value_is_zero)
+
+      if (cond && value_is_zero)
        {
          bs->stop = 0;
        }
@@ -3131,10 +4028,11 @@ 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];
@@ -3143,78 +4041,90 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
   int ix;
   int need_remove_insert;
 
-  ALL_BP_LOCATIONS (bl)
-  {
-    b = bl->owner;
-    gdb_assert (b);
-    if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
-      continue;
+  /* ALL_BP_LOCATIONS iteration would break across
+     update_global_location_list possibly executed by
+     bpstat_check_breakpoint_conditions's inferior call.  */
 
-    /* For hardware watchpoints, we look only at the first location.
-       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
-     */
-    if (b->type == bp_hardware_watchpoint && bl != b->loc)
-      continue;
+  ALL_BREAKPOINTS (b)
+    {
+      if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
+       continue;
 
-    if (!bpstat_check_location (bl, bp_addr))
-      continue;
+      for (bl = b->loc; bl != NULL; bl = bl->next)
+       {
+         /* For hardware watchpoints, we look only at the first location.
+            The watchpoint_check function will work on the entire expression,
+            not the individual locations.  For read watchpoints, the
+            watchpoints_triggered function has checked all locations
+            already.  */
+         if (b->type == bp_hardware_watchpoint && bl != b->loc)
+           break;
 
-    /* Come here if it's a watchpoint, or if the break address matches */
+         if (bl->shlib_disabled)
+           continue;
 
-    bs = bpstat_alloc (bl, bs);        /* Alloc a bpstat to explain stop */
+         if (!bpstat_check_location (bl, aspace, bp_addr))
+           continue;
 
-    /* Assume we stop.  Should we find watchpoint that is not actually
-       triggered, or if condition of breakpoint is false, we'll reset
-       'stop' to 0.  */
-    bs->stop = 1;
-    bs->print = 1;
+         /* Come here if it's a watchpoint, or if the break address matches */
 
-    bpstat_check_watchpoint (bs);
-    if (!bs->stop)
-      continue;
+         bs = bpstat_alloc (bl, bs);   /* Alloc a bpstat to explain stop */
 
-    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
-      bpstat_check_breakpoint_conditions (bs, ptid);
-  
-    if (bs->stop)
-      {
-       ++(b->hit_count);
+         /* Assume we stop.  Should we find watchpoint that is not actually
+            triggered, or if condition of breakpoint is false, we'll reset
+            'stop' to 0.  */
+         bs->stop = 1;
+         bs->print = 1;
 
-       /* 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);
-         }
-       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)))
-         {
-           bs->commands = bs->commands->next;
-           bs->print = 0;
-         }
-       bs->commands = copy_command_lines (bs->commands);
-      }
+         bpstat_check_watchpoint (bs);
+         if (!bs->stop)
+           continue;
 
-    /* Print nothing for this entry if we dont stop or if we dont print.  */
-    if (bs->stop == 0 || bs->print == 0)
-      bs->print_it = print_it_noop;
-  }
+         if (b->type == bp_thread_event || b->type == bp_overlay_event
+             || b->type == bp_longjmp_master
+             || b->type == bp_std_terminate_master)
+           /* We do not stop for these.  */
+           bs->stop = 0;
+         else
+           bpstat_check_breakpoint_conditions (bs, ptid);
+       
+         if (bs->stop)
+           {
+             ++(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);
+               }
+             if (b->silent)
+               bs->print = 0;
+             bs->commands = b->commands;
+             incref_counted_command_line (bs->commands);
+             bs->commands_left = bs->commands ? bs->commands->commands : NULL;
+             if (bs->commands_left
+                 && (strcmp ("silent", bs->commands_left->line) == 0
+                     || (xdb_commands
+                         && strcmp ("Q",
+                                    bs->commands_left->line) == 0)))
+               {
+                 bs->commands_left = bs->commands_left->next;
+                 bs->print = 0;
+               }
+           }
+
+         /* Print nothing for this entry if we dont stop or dont print.  */
+         if (bs->stop == 0 || bs->print == 0)
+           bs->print_it = print_it_noop;
+       }
+    }
 
   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.  */
@@ -3225,37 +4135,27 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
     }
 
   bs->next = NULL;             /* Terminate the chain */
-  bs = root_bs->next;          /* Re-grab the head of the chain */
 
   /* If we aren't stopping, the value of some hardware watchpoint may
      not have changed, but the intermediate memory locations we are
      watching may have.  Don't bother if we're stopping; this will get
      done later.  */
-  for (bs = root_bs->next; bs != NULL; bs = bs->next)
-    if (bs->stop)
-      break;
-
   need_remove_insert = 0;
-  if (bs == NULL)
+  if (! bpstat_causes_stop (root_bs->next))
     for (bs = root_bs->next; bs != NULL; bs = bs->next)
       if (!bs->stop
          && bs->breakpoint_at->owner
-         && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
-             || bs->breakpoint_at->owner->type == bp_read_watchpoint
-             || bs->breakpoint_at->owner->type == bp_access_watchpoint))
+         && is_hardware_watchpoint (bs->breakpoint_at->owner))
        {
-         /* remove/insert can invalidate bs->breakpoint_at, if this
-            location is no longer used by the watchpoint.  Prevent
-            further code from trying to use it.  */
+         update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */);
+         /* Updating watchpoints invalidates bs->breakpoint_at.
+            Prevent further code from trying to use it.  */
          bs->breakpoint_at = NULL;
          need_remove_insert = 1;
        }
 
   if (need_remove_insert)
-    {
-      remove_breakpoints ();
-      insert_breakpoints ();
-    }
+    update_global_location_list (1);
 
   return root_bs->next;
 }
@@ -3297,6 +4197,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
     };
@@ -3312,6 +4215,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
@@ -3332,12 +4236,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   <
 
@@ -3355,28 +4260,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
@@ -3389,10 +4284,11 @@ 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;
 
-  retval.call_dummy = 0;
+  retval.call_dummy = STOP_NONE;
   for (; bs != NULL; bs = bs->next)
     {
       enum class bs_class = no_effect;
@@ -3459,9 +4355,13 @@ 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:
+       case bp_std_terminate_master:
          bs_class = bp_nostop;
          break;
        case bp_catchpoint:
@@ -3481,14 +4381,21 @@ bpstat_what (bpstat bs)
          /* Make sure the action is stop (silent or noisy),
             so infrun.c pops the dummy frame.  */
          bs_class = bp_silent;
-         retval.call_dummy = 1;
+         retval.call_dummy = STOP_STACK_DUMMY;
+         break;
+       case bp_std_terminate:
+         /* Make sure the action is stop (silent or noisy),
+            so infrun.c pops the dummy frame.  */
+         bs_class = bp_silent;
+         retval.call_dummy = STOP_STD_TERMINATE;
          break;
        case bp_tracepoint:
+       case bp_fast_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"));
+                         _("bpstat_what: tracepoint encountered"));
          break;
        }
       current_action = table[(int) bs_class][(int) current_action];
@@ -3511,14 +4418,34 @@ bpstat_should_step (void)
   return 0;
 }
 
+int
+bpstat_causes_stop (bpstat bs)
+{
+  for (; bs != NULL; bs = bs->next)
+    if (bs->stop)
+      return 1;
+
+  return 0;
+}
+
 \f
 
+/* Print the LOC location out of the list of B->LOC locations.  */
+
 static void print_breakpoint_location (struct breakpoint *b,
                                       struct bp_location *loc,
                                       char *wrap_indent,
                                       struct ui_stream *stb)
 {
-  if (b->source_file)
+  struct cleanup *old_chain = save_current_program_space ();
+
+  if (loc != NULL && loc->shlib_disabled)
+    loc = NULL;
+
+  if (loc != NULL)
+    set_current_program_space (loc->pspace);
+
+  if (b->source_file && loc)
     {
       struct symbol *sym 
        = find_pc_sect_function (loc->address, loc->section);
@@ -3544,15 +4471,16 @@ static void print_breakpoint_location (struct breakpoint *b,
       
       ui_out_field_int (uiout, "line", b->line_number);
     }
-  else if (!b->loc)
-    {
-      ui_out_field_string (uiout, "pending", b->addr_string);
-    }
-  else
+  else if (loc)
     {
-      print_address_symbolic (loc->address, stb->stream, demangle, "");
+      print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
+                             demangle, "");
       ui_out_field_stream (uiout, "at", stb);
     }
+  else
+    ui_out_field_string (uiout, "pending", b->addr_string);
+
+  do_cleanups (old_chain);
 }
 
 /* Print B to gdb_stdout. */
@@ -3561,7 +4489,8 @@ print_one_breakpoint_location (struct breakpoint *b,
                               struct bp_location *loc,
                               int loc_number,
                               struct bp_location **last_loc,
-                              int print_address_bits)
+                              int print_address_bits,
+                              int allflag)
 {
   struct command_line *l;
   struct symbol *sym;
@@ -3586,12 +4515,16 @@ print_one_breakpoint_location (struct breakpoint *b,
     {bp_step_resume, "step resume"},
     {bp_watchpoint_scope, "watchpoint scope"},
     {bp_call_dummy, "call dummy"},
+    {bp_std_terminate, "std::terminate"},
     {bp_shlib_event, "shlib events"},
     {bp_thread_event, "thread events"},
     {bp_overlay_event, "overlay events"},
     {bp_longjmp_master, "longjmp master"},
+    {bp_std_terminate_master, "std::terminate master"},
     {bp_catchpoint, "catchpoint"},
     {bp_tracepoint, "tracepoint"},
+    {bp_fast_tracepoint, "fast tracepoint"},
+    {bp_jit_event, "jit events"},
   };
   
   static char bpenables[] = "nynny";
@@ -3715,11 +4648,15 @@ print_one_breakpoint_location (struct breakpoint *b,
       case bp_step_resume:
       case bp_watchpoint_scope:
       case bp_call_dummy:
+      case bp_std_terminate:
       case bp_shlib_event:
       case bp_thread_event:
       case bp_overlay_event:
       case bp_longjmp_master:
+      case bp_std_terminate_master:
       case bp_tracepoint:
+      case bp_fast_tracepoint:
+      case bp_jit_event:
        if (opts.addressprint)
          {
            annotate_field (4);
@@ -3739,6 +4676,36 @@ print_one_breakpoint_location (struct breakpoint *b,
        break;
       }
 
+
+  /* For backward compatibility, don't display inferiors unless there
+     are several.  */
+  if (loc != NULL
+      && !header_of_multiple
+      && (allflag
+         || (!gdbarch_has_global_breakpoints (target_gdbarch)
+             && (number_of_program_spaces () > 1
+                 || number_of_inferiors () > 1)
+             && loc->owner->type != bp_catchpoint)))
+    {
+      struct inferior *inf;
+      int first = 1;
+
+      for (inf = inferior_list; inf != NULL; inf = inf->next)
+       {
+         if (inf->pspace == loc->pspace)
+           {
+             if (first)
+               {
+                 first = 0;
+                 ui_out_text (uiout, " inf ");
+               }
+             else
+               ui_out_text (uiout, ", ");
+             ui_out_text (uiout, plongest (inf->num));
+           }
+       }
+    }
+
   if (!part_of_multiple)
     {
       if (b->thread != -1)
@@ -3774,7 +4741,7 @@ 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);
-      if (b->type == bp_tracepoint)
+      if (is_tracepoint (b))
        ui_out_text (uiout, "\ttrace only if ");
       else
        ui_out_text (uiout, "\tstop only if ");
@@ -3819,7 +4786,7 @@ print_one_breakpoint_location (struct breakpoint *b,
       ui_out_text (uiout, " hits\n");
     }
 
-  l = b->commands;
+  l = b->commands ? b->commands->commands : NULL;
   if (!part_of_multiple && l)
     {
       struct cleanup *script_chain;
@@ -3838,26 +4805,6 @@ print_one_breakpoint_location (struct breakpoint *b,
       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)
@@ -3872,9 +4819,11 @@ print_one_breakpoint_location (struct breakpoint *b,
 
 static void
 print_one_breakpoint (struct breakpoint *b,
-                     struct bp_location **last_loc, int print_address_bits)
+                     struct bp_location **last_loc, int print_address_bits,
+                     int allflag)
 {
-  print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits);
+  print_one_breakpoint_location (b, NULL, 0, last_loc,
+                                print_address_bits, allflag);
 
   /* If this breakpoint has custom print function,
      it's already printed.  Otherwise, print individual
@@ -3898,7 +4847,7 @@ print_one_breakpoint (struct breakpoint *b,
          int n = 1;
          for (loc = b->loc; loc; loc = loc->next, ++n)
            print_one_breakpoint_location (b, loc, n, last_loc,
-                                          print_address_bits);
+                                          print_address_bits, allflag);
        }
     }
 }
@@ -3911,7 +4860,14 @@ breakpoint_address_bits (struct breakpoint *b)
 
   for (loc = b->loc; loc; loc = loc->next)
     {
-      int addr_bit = gdbarch_addr_bit (b->gdbarch);
+      int addr_bit;
+
+      /* Software watchpoints that aren't watching memory don't have
+        an address to print.  */
+      if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
+       continue;
+
+      addr_bit = gdbarch_addr_bit (loc->gdbarch);
       if (addr_bit > print_address_bits)
        print_address_bits = addr_bit;
     }
@@ -3935,7 +4891,7 @@ do_captured_breakpoint_query (struct ui_out *uiout, void *data)
       if (args->bnum == b->number)
        {
          int print_address_bits = breakpoint_address_bits (b);
-         print_one_breakpoint (b, &dummy_loc, print_address_bits);
+         print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
          return GDB_RC_OK;
        }
     }
@@ -3965,19 +4921,19 @@ 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
-         || b->type == bp_hardware_watchpoint);
+         || is_tracepoint (b)
+         || is_watchpoint (b));
 }
        
 /* Print information on user settable breakpoint (watchpoint, etc)
-   number BNUM.  If BNUM is -1 print all user settable breakpoints.
-   If ALLFLAG is non-zero, include non- user settable breakpoints. */
+   number BNUM.  If BNUM is -1 print all user-settable breakpoints.
+   If ALLFLAG is non-zero, include non-user-settable breakpoints.  If
+   FILTER is non-NULL, call it on each breakpoint and only include the
+   ones for which it returns non-zero.  Return the total number of
+   breakpoints listed.  */
 
-static void
-breakpoint_1 (int bnum, int allflag)
+static int
+breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
 {
   struct breakpoint *b;
   struct bp_location *last_loc = NULL;
@@ -3995,6 +4951,10 @@ breakpoint_1 (int bnum, int allflag)
     if (bnum == -1
        || bnum == b->number)
       {
+       /* If we have a filter, only list the breakpoints it accepts.  */
+       if (filter && !filter (b))
+         continue;
+       
        if (allflag || user_settable_breakpoint (b))
          {
            int addr_bit = breakpoint_address_bits (b);
@@ -4045,24 +5005,35 @@ breakpoint_1 (int bnum, int allflag)
     annotate_breakpoints_table ();
 
   ALL_BREAKPOINTS (b)
+  {
+    QUIT;
     if (bnum == -1
        || bnum == b->number)
       {
+       /* If we have a filter, only list the breakpoints it accepts.  */
+       if (filter && !filter (b))
+         continue;
+       
        /* We only print out user settable breakpoints unless the
           allflag is set. */
        if (allflag || user_settable_breakpoint (b))
-         print_one_breakpoint (b, &last_loc, print_address_bits);
+         print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
       }
+  }
   
   do_cleanups (bkpttbl_chain);
 
   if (nr_printable_breakpoints == 0)
     {
-      if (bnum == -1)
-       ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
-      else
-       ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
-                       bnum);
+      /* If there's a filter, let the caller decide how to report empty list.  */
+      if (!filter)
+       {
+         if (bnum == -1)
+           ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
+         else
+           ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
+                           bnum);
+       }
     }
   else
     {
@@ -4073,8 +5044,29 @@ breakpoint_1 (int bnum, int allflag)
   /* FIXME? Should this be moved up so that it is only called when
      there have been breakpoints? */
   annotate_breakpoints_table_end ();
+
+  return nr_printable_breakpoints;
 }
 
+/* Display the value of default-collect in a way that is generally
+   compatible with the breakpoint list.  */
+
+static void
+default_collect_info (void)
+{
+  /* If it has no value (which is frequently the case), say nothing; a
+     message like "No default-collect." gets in user's face when it's
+     not wanted.  */
+  if (!*default_collect)
+    return;
+
+  /* The following phrase lines up nicely with per-tracepoint collect
+     actions.  */
+  ui_out_text (uiout, "default collect ");
+  ui_out_field_string (uiout, "default-collect", default_collect);
+  ui_out_text (uiout, " \n");
+}
+  
 static void
 breakpoints_info (char *bnum_exp, int from_tty)
 {
@@ -4083,7 +5075,28 @@ breakpoints_info (char *bnum_exp, int from_tty)
   if (bnum_exp)
     bnum = parse_and_eval_long (bnum_exp);
 
-  breakpoint_1 (bnum, 0);
+  breakpoint_1 (bnum, 0, NULL);
+
+  default_collect_info ();
+}
+
+static void
+watchpoints_info (char *wpnum_exp, int from_tty)
+{
+  int wpnum = -1, num_printed;
+
+  if (wpnum_exp)
+    wpnum = parse_and_eval_long (wpnum_exp);
+
+  num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
+
+  if (num_printed == 0)
+    {
+      if (wpnum == -1)
+       ui_out_message (uiout, 0, "No watchpoints.\n");
+      else
+       ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
+    }
 }
 
 static void
@@ -4094,34 +5107,41 @@ maintenance_info_breakpoints (char *bnum_exp, int from_tty)
   if (bnum_exp)
     bnum = parse_and_eval_long (bnum_exp);
 
-  breakpoint_1 (bnum, 1);
+  breakpoint_1 (bnum, 1, NULL);
+
+  default_collect_info ();
 }
 
 static int
 breakpoint_has_pc (struct breakpoint *b,
+                  struct program_space *pspace,
                   CORE_ADDR pc, struct obj_section *section)
 {
   struct bp_location *bl = b->loc;
   for (; bl; bl = bl->next)
     {
-      if (bl->address == pc
+      if (bl->pspace == pspace
+         && bl->address == pc
          && (!overlay_debugging || bl->section == section))
        return 1;         
     }
   return 0;
 }
 
-/* Print a message describing any breakpoints set at PC.  */
+/* Print a message describing any breakpoints set at PC.  This
+   concerns with logical breakpoints, so we match program spaces, not
+   address spaces.  */
 
 static void
-describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
+describe_other_breakpoints (struct gdbarch *gdbarch,
+                           struct program_space *pspace, CORE_ADDR pc,
                            struct obj_section *section, int thread)
 {
   int others = 0;
   struct breakpoint *b;
 
   ALL_BREAKPOINTS (b)
-    others += breakpoint_has_pc (b, pc, section);
+    others += breakpoint_has_pc (b, pspace, pc, section);
   if (others > 0)
     {
       if (others == 1)
@@ -4129,7 +5149,7 @@ describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
       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);
@@ -4139,7 +5159,8 @@ describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
              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_call_disabled
+                              || b->enable_state == bp_startup_disabled)
                              ? " (disabled)"
                              : b->enable_state == bp_permanent 
                              ? " (permanent)"
@@ -4157,10 +5178,12 @@ describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
    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;
@@ -4172,106 +5195,71 @@ 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
-      bp_read_watchpoint
-      bp_access_watchpoint
-      bp_catchpoint */
+      bp_catchpoint
+
+*/
 
 static int
 breakpoint_address_is_meaningful (struct breakpoint *bpt)
 {
   enum bptype type = bpt->type;
 
-  return (type != bp_watchpoint
-         && type != bp_hardware_watchpoint
-         && type != bp_read_watchpoint
-         && type != bp_access_watchpoint
-         && type != bp_catchpoint);
+  return (type != bp_watchpoint && type != bp_catchpoint);
 }
 
-/* Rescan breakpoints at the same address and section as BPT,
-   marking the first one as "first" and any others as "duplicates".
-   This is so that the bpt instruction is only inserted once.
-   If we have a permanent breakpoint at the same place as BPT, make
-   that one the official one, and the rest as duplicates.  */
-
-static void
-check_duplicates_for (CORE_ADDR address, struct obj_section *section)
-{
-  struct bp_location *b;
-  int count = 0;
-  struct bp_location *perm_bp = 0;
-
-  ALL_BP_LOCATIONS (b)
-    if (b->owner->enable_state != bp_disabled
-       && b->owner->enable_state != bp_call_disabled
-       && b->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;
+/* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
+   true if LOC1 and LOC2 represent the same watchpoint location.  */
 
-      /* Permanent breakpoint should always be inserted.  */
-      if (! perm_bp->inserted)
-       internal_error (__FILE__, __LINE__,
-                       _("allegedly permanent breakpoint is not "
-                       "actually inserted"));
+static int
+watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
+{
+  /* Note that this checks the owner's type, not the location's.  In
+     case the target does not support read watchpoints, but does
+     support access watchpoints, we'll have bp_read_watchpoint
+     watchpoints with hw_access locations.  Those should be considered
+     duplicates of hw_read locations.  The hw_read locations will
+     become hw_access locations later.  */
+  return (loc1->owner->type == loc2->owner->type
+         && loc1->pspace->aspace == loc2->pspace->aspace
+         && loc1->address == loc2->address
+         && loc1->length == loc2->length);
+}
 
-      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"));
+/* 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.  */
 
-               b->duplicate = 1;
-             }
-         }
-    }
+static int
+breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
+                         struct address_space *aspace2, CORE_ADDR addr2)
+{
+  return ((gdbarch_has_global_breakpoints (target_gdbarch)
+          || aspace1 == aspace2)
+         && addr1 == addr2);
 }
 
-static void
-check_duplicates (struct breakpoint *bpt)
-{
-  struct bp_location *bl = bpt->loc;
+/* Assuming LOC1 and LOC2's types' have meaningful target addresses
+   (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
+   represent the same location.  */
 
-  if (! breakpoint_address_is_meaningful (bpt))
-    return;
+static int
+breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
+{
+  int hw_point1 = is_hardware_watchpoint (loc1->owner);
+  int hw_point2 = is_hardware_watchpoint (loc2->owner);
 
-  for (; bl; bl = bl->next)
-    check_duplicates_for (bl->address, bl->section);    
+  if (hw_point1 != hw_point2)
+    return 0;
+  else if (hw_point1)
+    return watchpoint_locations_match (loc1, loc2);
+  else
+    return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
+                                    loc2->pspace->aspace, loc2->address);
 }
 
 static void
@@ -4350,7 +5338,6 @@ allocate_bp_location (struct breakpoint *bpt)
   switch (bpt->type)
     {
     case bp_breakpoint:
-    case bp_tracepoint:
     case bp_until:
     case bp_finish:
     case bp_longjmp:
@@ -4358,10 +5345,13 @@ allocate_bp_location (struct breakpoint *bpt)
     case bp_step_resume:
     case bp_watchpoint_scope:
     case bp_call_dummy:
+    case bp_std_terminate:
     case bp_shlib_event:
     case bp_thread_event:
     case bp_overlay_event:
+    case bp_jit_event:
     case bp_longjmp_master:
+    case bp_std_terminate_master:
       loc->loc_type = bp_loc_software_breakpoint;
       break;
     case bp_hardware_breakpoint:
@@ -4374,6 +5364,8 @@ allocate_bp_location (struct breakpoint *bpt)
       break;
     case bp_watchpoint:
     case bp_catchpoint:
+    case bp_tracepoint:
+    case bp_fast_tracepoint:
       loc->loc_type = bp_loc_other;
       break;
     default:
@@ -4396,6 +5388,7 @@ 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 (struct gdbarch *gdbarch,
@@ -4419,6 +5412,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
   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;
 
@@ -4444,7 +5438,7 @@ set_breakpoint_location_function (struct bp_location *loc)
 {
   if (loc->owner->type == bp_breakpoint
       || loc->owner->type == bp_hardware_breakpoint
-      || loc->owner->type == bp_tracepoint)
+      || is_tracepoint (loc->owner))
     {
       find_pc_partial_function (loc->address, &(loc->function_name), 
                                NULL, NULL);
@@ -4480,7 +5474,7 @@ get_sal_arch (struct symtab_and_line sal)
    prior to completing the initialization of the breakpoint.  If this
    should happen, a bogus breakpoint will be left on the chain.  */
 
-static struct breakpoint *
+struct breakpoint *
 set_raw_breakpoint (struct gdbarch *gdbarch,
                    struct symtab_and_line sal, enum bptype bptype)
 {
@@ -4492,6 +5486,9 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
   if (!loc_gdbarch)
     loc_gdbarch = b->gdbarch;
 
+  if (bptype != bp_catchpoint)
+    gdb_assert (sal.pspace != NULL);
+
   /* Adjust the breakpoint's address prior to allocating a location.
      Once we call allocate_bp_location(), that mostly uninitialized
      location will be placed on the location chain.  Adjustment of the
@@ -4504,6 +5501,11 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
   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;
@@ -4551,7 +5553,8 @@ set_longjmp_breakpoint (int thread)
      longjmp "master" breakpoints.  Here, we simply create momentary
      clones of those and enable them for the requested thread.  */
   ALL_BREAKPOINTS_SAFE (b, temp)
-    if (b->type == bp_longjmp_master)
+    if (b->pspace == current_program_space
+       && b->type == bp_longjmp_master)
       {
        struct breakpoint *clone = clone_momentary_breakpoint (b);
        clone->type = bp_longjmp;
@@ -4601,6 +5604,33 @@ disable_overlay_breakpoints (void)
     }
 }
 
+/* Set an active std::terminate breakpoint for each std::terminate
+   master breakpoint.  */
+void
+set_std_terminate_breakpoint (void)
+{
+  struct breakpoint *b, *temp;
+
+  ALL_BREAKPOINTS_SAFE (b, temp)
+    if (b->pspace == current_program_space
+       && b->type == bp_std_terminate_master)
+      {
+       struct breakpoint *clone = clone_momentary_breakpoint (b);
+       clone->type = bp_std_terminate;
+      }
+}
+
+/* Delete all the std::terminate breakpoints.  */
+void
+delete_std_terminate_breakpoint (void)
+{
+  struct breakpoint *b, *temp;
+
+  ALL_BREAKPOINTS_SAFE (b, temp)
+    if (b->type == bp_std_terminate)
+      delete_breakpoint (b);
+}
+
 struct breakpoint *
 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 {
@@ -4624,7 +5654,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);
 }
 
@@ -4642,6 +5673,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)
@@ -4649,7 +5691,8 @@ 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);
 }
 
@@ -4669,9 +5712,9 @@ create_solib_event_breakpoint (struct gdbarch *gdbarch, 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
@@ -4680,13 +5723,15 @@ disable_breakpoints_in_shlibs (void)
        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_jit_event)
         || (b->type == bp_hardware_breakpoint)
-        || (b->type == bp_tracepoint))
+        || (is_tracepoint (b)))
+       && loc->pspace == current_program_space
        && !loc->shlib_disabled
 #ifdef PC_SOLIB
        && PC_SOLIB (loc->address)
 #else
-       && solib_name_from_address (loc->address)
+       && solib_name_from_address (loc->pspace, loc->address)
 #endif
        )
       {
@@ -4701,7 +5746,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
@@ -4712,13 +5757,16 @@ 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)
+       && solib->pspace == loc->pspace
        && !loc->shlib_disabled
-       && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
+       && (b->type == bp_breakpoint
+           || b->type == bp_jit_event
+           || b->type == bp_hardware_breakpoint)
        && solib_contains_address_p (solib, loc->address))
       {
        loc->shlib_disabled = 1;
@@ -4809,6 +5857,15 @@ print_mention_catch_fork (struct breakpoint *b)
   printf_filtered (_("Catchpoint %d (fork)"), b->number);
 }
 
+/* Implement the "print_recreate" breakpoint_ops method for fork
+   catchpoints.  */
+
+static void
+print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
+{
+  fprintf_unfiltered (fp, "catch fork");
+}
+
 /* The breakpoint_ops structure to be used in fork catchpoints.  */
 
 static struct breakpoint_ops catch_fork_breakpoint_ops =
@@ -4818,7 +5875,8 @@ static struct breakpoint_ops catch_fork_breakpoint_ops =
   breakpoint_hit_catch_fork,
   print_it_catch_fork,
   print_one_catch_fork,
-  print_mention_catch_fork
+  print_mention_catch_fork,
+  print_recreate_catch_fork
 };
 
 /* Implement the "insert" breakpoint_ops method for vfork catchpoints.  */
@@ -4890,6 +5948,15 @@ print_mention_catch_vfork (struct breakpoint *b)
   printf_filtered (_("Catchpoint %d (vfork)"), b->number);
 }
 
+/* Implement the "print_recreate" breakpoint_ops method for vfork
+   catchpoints.  */
+
+static void
+print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
+{
+  fprintf_unfiltered (fp, "catch vfork");
+}
+
 /* The breakpoint_ops structure to be used in vfork catchpoints.  */
 
 static struct breakpoint_ops catch_vfork_breakpoint_ops =
@@ -4899,10 +5966,298 @@ static struct breakpoint_ops catch_vfork_breakpoint_ops =
   breakpoint_hit_catch_vfork,
   print_it_catch_vfork,
   print_one_catch_vfork,
-  print_mention_catch_vfork
+  print_mention_catch_vfork,
+  print_recreate_catch_vfork
 };
 
-/* Create a new breakpoint of the bp_catchpoint kind and return it.
+/* Implement the "insert" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static void
+insert_catch_syscall (struct breakpoint *b)
+{
+  struct inferior *inf = current_inferior ();
+
+  ++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);
+       }
+    }
+
+  target_set_syscall_catchpoint (PIDGET (inferior_ptid),
+                                inf->total_syscalls_count != 0,
+                                inf->any_syscall_count,
+                                VEC_length (int, inf->syscalls_counts),
+                                VEC_address (int, inf->syscalls_counts));
+}
+
+/* Implement the "remove" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static int
+remove_catch_syscall (struct breakpoint *b)
+{
+  struct inferior *inf = current_inferior ();
+
+  --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));
+}
+
+/* Implement the "breakpoint_hit" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static int
+breakpoint_hit_catch_syscall (struct breakpoint *b)
+{
+  /* We must check if we are catching specific syscalls in this breakpoint.
+     If we are, then we must guarantee that the called syscall is the same
+     syscall we are catching.  */
+  int syscall_number = 0;
+
+  if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
+    return 0;
+
+  /* Now, checking if the syscall is the same.  */
+  if (b->syscalls_to_be_caught)
+    {
+      int i, iter;
+      for (i = 0;
+           VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+           i++)
+       if (syscall_number == iter)
+         break;
+      /* Not the same.  */
+      if (!iter)
+       return 0;
+    }
+
+  return 1;
+}
+
+/* Implement the "print_it" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static enum print_stop_action
+print_it_catch_syscall (struct breakpoint *b)
+{
+  /* These are needed because we want to know in which state a
+     syscall is.  It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
+     or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
+     must print "called syscall" or "returned from syscall".  */
+  ptid_t ptid;
+  struct target_waitstatus last;
+  struct syscall s;
+  struct cleanup *old_chain;
+  char *syscall_id;
+
+  get_last_target_status (&ptid, &last);
+
+  get_syscall_by_number (last.value.syscall_number, &s);
+
+  annotate_catchpoint (b->number);
+
+  if (s.name == NULL)
+    syscall_id = xstrprintf ("%d", last.value.syscall_number);
+  else
+    syscall_id = xstrprintf ("'%s'", s.name);
+
+  old_chain = make_cleanup (xfree, syscall_id);
+
+  if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
+    printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
+                     b->number, syscall_id);
+  else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
+    printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
+                     b->number, syscall_id);
+
+  do_cleanups (old_chain);
+
+  return PRINT_SRC_AND_LOC;
+}
+
+/* Implement the "print_one" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static void
+print_one_catch_syscall (struct breakpoint *b,
+                         struct bp_location **last_loc)
+{
+  struct value_print_options opts;
+
+  get_user_print_options (&opts);
+  /* Field 4, the address, is omitted (which makes the columns
+     not line up too nicely with the headers, but the effect
+     is relatively readable).  */
+  if (opts.addressprint)
+    ui_out_field_skip (uiout, "addr");
+  annotate_field (5);
+
+  if (b->syscalls_to_be_caught
+      && VEC_length (int, b->syscalls_to_be_caught) > 1)
+    ui_out_text (uiout, "syscalls \"");
+  else
+    ui_out_text (uiout, "syscall \"");
+
+  if (b->syscalls_to_be_caught)
+    {
+      int i, iter;
+      char *text = xstrprintf ("%s", "");
+      for (i = 0;
+           VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+           i++)
+        {
+          char *x = text;
+          struct syscall s;
+          get_syscall_by_number (iter, &s);
+
+          if (s.name != NULL)
+            text = xstrprintf ("%s%s, ", text, s.name);
+          else
+            text = xstrprintf ("%s%d, ", text, iter);
+
+          /* We have to xfree the last 'text' (now stored at 'x')
+             because xstrprintf dinamically allocates new space for it
+             on every call.  */
+         xfree (x);
+        }
+      /* Remove the last comma.  */
+      text[strlen (text) - 2] = '\0';
+      ui_out_field_string (uiout, "what", text);
+    }
+  else
+    ui_out_field_string (uiout, "what", "<any syscall>");
+  ui_out_text (uiout, "\" ");
+}
+
+/* Implement the "print_mention" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static void
+print_mention_catch_syscall (struct breakpoint *b)
+{
+  if (b->syscalls_to_be_caught)
+    {
+      int i, iter;
+
+      if (VEC_length (int, b->syscalls_to_be_caught) > 1)
+        printf_filtered (_("Catchpoint %d (syscalls"), b->number);
+      else
+        printf_filtered (_("Catchpoint %d (syscall"), b->number);
+
+      for (i = 0;
+           VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
+           i++)
+        {
+          struct syscall s;
+          get_syscall_by_number (iter, &s);
+
+          if (s.name)
+            printf_filtered (" '%s' [%d]", s.name, s.number);
+          else
+            printf_filtered (" %d", s.number);
+        }
+      printf_filtered (")");
+    }
+  else
+    printf_filtered (_("Catchpoint %d (any syscall)"),
+                     b->number);
+}
+
+/* Implement the "print_recreate" breakpoint_ops method for syscall
+   catchpoints.  */
+
+static void
+print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
+{
+  fprintf_unfiltered (fp, "catch syscall");
+
+  if (b->syscalls_to_be_caught)
+    {
+      int i, iter;
+
+      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)
+            fprintf_unfiltered (fp, " %s", s.name);
+          else
+            fprintf_unfiltered (fp, " %d", s.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,
+  print_recreate_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.
@@ -4910,27 +6265,43 @@ static struct breakpoint_ops catch_vfork_breakpoint_ops =
    to the catchpoint.  */
 
 static struct breakpoint *
-create_catchpoint (struct gdbarch *gdbarch, int tempflag,
-                  char *cond_string, struct breakpoint_ops *ops)
+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.pc = 0;
-  sal.symtab = NULL;
-  sal.line = 0;
+  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;
+  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);
@@ -5008,6 +6379,15 @@ print_mention_catch_exec (struct breakpoint *b)
   printf_filtered (_("Catchpoint %d (exec)"), b->number);
 }
 
+/* Implement the "print_recreate" breakpoint_ops method for exec
+   catchpoints.  */
+
+static void
+print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
+{
+  fprintf_unfiltered (fp, "catch exec");
+}
+
 static struct breakpoint_ops catch_exec_breakpoint_ops =
 {
   insert_catch_exec,
@@ -5015,9 +6395,26 @@ static struct breakpoint_ops catch_exec_breakpoint_ops =
   breakpoint_hit_catch_exec,
   print_it_catch_exec,
   print_one_catch_exec,
-  print_mention_catch_exec
+  print_mention_catch_exec,
+  print_recreate_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)
 {
@@ -5046,9 +6443,7 @@ 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 (is_hardware_watchpoint (b))
          *other_type_used = 1;
       }
   }
@@ -5062,11 +6457,7 @@ disable_watchpoints_before_interactive_call_start (void)
 
   ALL_BREAKPOINTS (b)
   {
-    if (((b->type == bp_watchpoint)
-        || (b->type == bp_hardware_watchpoint)
-        || (b->type == bp_read_watchpoint)
-        || (b->type == bp_access_watchpoint))
-       && breakpoint_enabled (b))
+    if (is_watchpoint (b) && breakpoint_enabled (b))
       {
        b->enable_state = bp_call_disabled;
        update_global_location_list (0);
@@ -5081,11 +6472,7 @@ enable_watchpoints_after_interactive_call_stop (void)
 
   ALL_BREAKPOINTS (b)
   {
-    if (((b->type == bp_watchpoint)
-        || (b->type == bp_hardware_watchpoint)
-        || (b->type == bp_read_watchpoint)
-        || (b->type == bp_access_watchpoint))
-       && (b->enable_state == bp_call_disabled))
+    if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
       {
        b->enable_state = bp_enabled;
        update_global_location_list (1);
@@ -5093,6 +6480,58 @@ 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.
@@ -5144,6 +6583,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   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;
@@ -5153,6 +6593,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
   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;
@@ -5266,6 +6707,16 @@ mention (struct breakpoint *b)
        printf_filtered (_(" %d"), b->number);
        say_where = 1;
        break;
+      case bp_fast_tracepoint:
+       if (ui_out_is_mi_like_p (uiout))
+         {
+           say_where = 0;
+           break;
+         }
+       printf_filtered (_("Fast tracepoint"));
+       printf_filtered (_(" %d"), b->number);
+       say_where = 1;
+       break;
 
       case bp_until:
       case bp_finish:
@@ -5273,11 +6724,14 @@ mention (struct breakpoint *b)
       case bp_longjmp_resume:
       case bp_step_resume:
       case bp_call_dummy:
+      case bp_std_terminate:
       case bp_watchpoint_scope:
       case bp_shlib_event:
       case bp_thread_event:
       case bp_overlay_event:
+      case bp_jit_event:
       case bp_longjmp_master:
+      case bp_std_terminate_master:
        break;
       }
 
@@ -5334,6 +6788,8 @@ add_location_to_breakpoint (struct breakpoint *b,
   loc->requested_address = sal->pc;
   loc->address = adjust_breakpoint_address (loc->gdbarch,
                                            loc->requested_address, b->type);
+  loc->pspace = sal->pspace;
+  gdb_assert (loc->pspace != NULL);
   loc->section = sal->section;
 
   set_breakpoint_location_function (loc);
@@ -5368,7 +6824,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)
@@ -5386,12 +6845,12 @@ bp_loc_is_permanent (struct bp_location *loc)
    as condition expression.  */
 
 static void
-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 task, int ignore_count, 
-                  struct breakpoint_ops *ops, int from_tty, int enabled)
+create_breakpoint_sal (struct gdbarch *gdbarch,
+                      struct symtabs_and_lines sals, char *addr_string,
+                      char *cond_string,
+                      enum bptype type, enum bpdisp disposition,
+                      int thread, int task, int ignore_count,
+                      struct breakpoint_ops *ops, int from_tty, int enabled)
 {
   struct breakpoint *b = NULL;
   int i;
@@ -5408,6 +6867,8 @@ create_breakpoint (struct gdbarch *gdbarch,
        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];
@@ -5420,7 +6881,7 @@ create_breakpoint (struct gdbarch *gdbarch,
            loc_gdbarch = gdbarch;
 
          describe_other_breakpoints (loc_gdbarch,
-                                     sal.pc, sal.section, thread);
+                                     sal.pspace, sal.pc, sal.section, thread);
        }
 
       if (i == 0)
@@ -5436,6 +6897,13 @@ create_breakpoint (struct gdbarch *gdbarch,
          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
@@ -5481,20 +6949,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)
 {
@@ -5503,6 +6970,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.  */
@@ -5515,18 +6983,27 @@ 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
-        processing, just return the original sal.  */
+      /* We had one sal, we got one sal.  Return that sal, adjusting it
+         past the function prologue if necessary.  */
       xfree (expanded.sals);
       expanded.nelts = 1;
       expanded.sals = xmalloc (sizeof (struct symtab_and_line));
       sal.pc = original_pc;
       expanded.sals[0] = sal;
+      skip_prologue_sal (&expanded.sals[0]);
+      do_cleanups (old_chain);
       return expanded;      
     }
 
@@ -5537,6 +7014,11 @@ 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))
            {
@@ -5546,41 +7028,16 @@ expand_line_sal_maybe (struct symtab_and_line sal)
                  remove_sal (&expanded, i);
                  --i;
                }
-             else if (func_addr == pc)     
-               {            
-                 /* We're at beginning of a function, and should
-                    skip prologue.  */
-                 struct symbol *sym = find_pc_function (pc);
-                 if (sym)
-                   expanded.sals[i] = find_function_start_sal (sym, 1);
-                 else
-                   {
-                     /* 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]);
-       }
-    }
 
-  
+  /* Skip the function prologue if necessary.  */
+  for (i = 0; i < expanded.nelts; ++i)
+    skip_prologue_sal (&expanded.sals[i]);
+
+  do_cleanups (old_chain);
+
   if (expanded.nelts <= 1)
     {
       /* This is un ugly workaround. If we get zero
@@ -5625,13 +7082,13 @@ expand_line_sal_maybe (struct symtab_and_line sal)
    COND and SALS arrays and each of those arrays contents. */
 
 static void
-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 task, int ignore_count, 
-                   struct breakpoint_ops *ops, int from_tty,
-                   int enabled)
+create_breakpoints_sal (struct gdbarch *gdbarch,
+                       struct symtabs_and_lines sals, char **addr_string,
+                       char *cond_string,
+                       enum bptype type, enum bpdisp disposition,
+                       int thread, int task, int ignore_count,
+                       struct breakpoint_ops *ops, int from_tty,
+                       int enabled)
 {
   int i;
   for (i = 0; i < sals.nelts; ++i)
@@ -5639,9 +7096,9 @@ create_breakpoints (struct gdbarch *gdbarch,
       struct symtabs_and_lines expanded = 
        expand_line_sal_maybe (sals.sals[i]);
 
-      create_breakpoint (gdbarch, expanded, addr_string[i],
-                        cond_string, type, disposition,
-                        thread, task, ignore_count, ops, from_tty, enabled);
+      create_breakpoint_sal (gdbarch, expanded, addr_string[i],
+                            cond_string, type, disposition,
+                            thread, task, ignore_count, ops, from_tty, enabled);
     }
 }
 
@@ -5672,6 +7129,7 @@ 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
@@ -5737,6 +7195,38 @@ breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
     resolve_sal_pc (&sals->sals[i]);
 }
 
+/* Fast tracepoints may have restrictions on valid locations.  For
+   instance, a fast tracepoint using a jump instead of a trap will
+   likely have to overwrite more bytes than a trap would, and so can
+   only be placed where the instruction is longer than the jump, or a
+   multi-instruction sequence does not have a jump into the middle of
+   it, etc.  */
+
+static void
+check_fast_tracepoint_sals (struct gdbarch *gdbarch,
+                           struct symtabs_and_lines *sals)
+{
+  int i, rslt;
+  struct symtab_and_line *sal;
+  char *msg;
+  struct cleanup *old_chain;
+
+  for (i = 0; i < sals->nelts; i++)
+    {
+      sal = &sals->sals[i];
+
+      rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
+                                              NULL, &msg);
+      old_chain = make_cleanup (xfree, msg);
+
+      if (!rslt)
+       error (_("May not have a fast tracepoint at 0x%s%s"),
+              paddress (gdbarch, sal->pc), (msg ? msg : ""));
+
+      do_cleanups (old_chain);
+    }
+}
+
 static void
 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
 {
@@ -5807,33 +7297,32 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
          if (tok == tmptok)
            error (_("Junk after task keyword."));
          if (!valid_task_id (*task))
-           error (_("Unknown task %d\n"), *task);
+           error (_("Unknown task %d."), *task);
        }
       else
        error (_("Junk at end of arguments."));
     }
 }
 
-/* Set a breakpoint.  This function is shared between
-   CLI and MI functions for setting a breakpoint.
-   This function has two major modes of operations,
-   selected by the PARSE_CONDITION_AND_THREAD parameter.
-   If non-zero, the function will parse arg, extracting
-   breakpoint location, address and thread. Otherwise,
-   ARG is just the location of breakpoint, with condition
-   and thread specified by the COND_STRING and THREAD
-   parameters.  */
+/* Set a breakpoint.  This function is shared between CLI and MI
+   functions for setting a breakpoint.  This function has two major
+   modes of operations, selected by the PARSE_CONDITION_AND_THREAD
+   parameter.  If non-zero, the function will parse arg, extracting
+   breakpoint location, address and thread. Otherwise, ARG is just the
+   location of breakpoint, with condition and thread specified by the
+   COND_STRING and THREAD parameters.  Returns true if any breakpoint
+   was created; false otherwise.  */
 
-static void
-break_command_really (struct gdbarch *gdbarch,
-                     char *arg, char *cond_string, int thread,
-                     int parse_condition_and_thread,
-                     int tempflag, int hardwareflag, int traceflag,
-                     int ignore_count,
-                     enum auto_boolean pending_break_support,
-                     struct breakpoint_ops *ops,
-                     int from_tty,
-                     int enabled)
+int
+create_breakpoint (struct gdbarch *gdbarch,
+                  char *arg, char *cond_string, int thread,
+                  int parse_condition_and_thread,
+                  int tempflag, int hardwareflag, int traceflag,
+                  int ignore_count,
+                  enum auto_boolean pending_break_support,
+                  struct breakpoint_ops *ops,
+                  int from_tty,
+                  int enabled)
 {
   struct gdb_exception e;
   struct symtabs_and_lines sals;
@@ -5850,6 +7339,7 @@ break_command_really (struct gdbarch *gdbarch,
   int not_found = 0;
   enum bptype type_wanted;
   int task = 0;
+  int prev_bkpt_count = breakpoint_count;
 
   sals.sals = NULL;
   sals.nelts = 0;
@@ -5885,7 +7375,7 @@ break_command_really (struct gdbarch *gdbarch,
             selects no, then simply return the error code.  */
          if (pending_break_support == AUTO_BOOLEAN_AUTO
              && !nquery ("Make breakpoint pending on future shared library load? "))
-           return;
+           return 0;
 
          /* At this point, either the user was queried about setting
             a pending breakpoint and selected yes, or pending
@@ -5903,7 +7393,7 @@ break_command_really (struct gdbarch *gdbarch,
        }
     default:
       if (!sals.nelts)
-       return;
+       return 0;
     }
 
   /* Create a chain of things that always need to be cleaned up. */
@@ -5938,9 +7428,13 @@ break_command_really (struct gdbarch *gdbarch,
     breakpoint_sals_to_pc (&sals, addr_start);
 
   type_wanted = (traceflag
-                ? bp_tracepoint
+                ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint)
                 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
 
+  /* Fast tracepoints may have additional restrictions on location.  */
+  if (type_wanted == bp_fast_tracepoint)
+    check_fast_tracepoint_sals (gdbarch, &sals);
+
   /* Verify that condition can be parsed, before setting any
      breakpoints.  Allocate a separate condition expression for each
      breakpoint. */
@@ -5968,9 +7462,10 @@ break_command_really (struct gdbarch *gdbarch,
                 make_cleanup (xfree, cond_string);
             }
         }
-      create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted,
-                         tempflag ? disp_del : disp_donttouch,
-                         thread, task, ignore_count, ops, from_tty, enabled);
+      create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
+                             type_wanted, tempflag ? disp_del : disp_donttouch,
+                             thread, task, ignore_count, ops, from_tty,
+                             enabled);
     }
   else
     {
@@ -5990,13 +7485,23 @@ break_command_really (struct gdbarch *gdbarch,
       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;
 
       mention (b);
     }
   
   if (sals.nelts > 1)
-    warning (_("Multiple breakpoints were set.\n"
-              "Use the \"delete\" command to delete unwanted breakpoints."));
+    {
+      warning (_("Multiple breakpoints were set.\n"
+                "Use the \"delete\" command to delete unwanted breakpoints."));
+      prev_breakpoint_count = prev_bkpt_count;
+    }
+
   /* That's it.  Discard the cleanups for data inserted into the
      breakpoint.  */
   discard_cleanups (bkpt_chain);
@@ -6005,6 +7510,8 @@ break_command_really (struct gdbarch *gdbarch,
 
   /* error call may happen here - have BKPT_CHAIN already discarded.  */
   update_global_location_list (1);
+
+  return 1;
 }
 
 /* Set a breakpoint. 
@@ -6020,59 +7527,18 @@ break_command_1 (char *arg, int flag, int from_tty)
   int hardwareflag = flag & BP_HARDWAREFLAG;
   int tempflag = flag & BP_TEMPFLAG;
 
-  break_command_really (get_current_arch (),
-                       arg,
-                       NULL, 0, 1 /* parse arg */,
-                       tempflag, hardwareflag, 0 /* traceflag */,
-                       0 /* Ignore count */,
-                       pending_break_support, 
-                       NULL /* breakpoint_ops */,
-                       from_tty,
-                       1 /* enabled */);
-}
-
-
-void
-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 (gdbarch,
-                       address, condition, thread,
-                       0 /* condition and thread are valid.  */,
-                       tempflag, hardwareflag, 0 /* traceflag */,
-                       ignore_count,
-                       pending 
-                       ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
-                       NULL, 0, enabled);
+  create_breakpoint (get_current_arch (),
+                    arg,
+                    NULL, 0, 1 /* parse arg */,
+                    tempflag, hardwareflag, 0 /* traceflag */,
+                    0 /* Ignore count */,
+                    pending_break_support,
+                    NULL /* breakpoint_ops */,
+                    from_tty,
+                    1 /* enabled */);
 }
 
-/* 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.  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 symtab_and_line start_sal;
-
-  if (sym == NULL)
-    return;
 
-  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;
-    }
-}
 
 /* Helper function for break_command_1 and disassemble_command.  */
 
@@ -6091,12 +7557,7 @@ 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)
-       {
-         /* Preserve the original line number.  */
-         int saved_line = sal->line;
-         skip_prologue_sal (sal);
-         sal->line = saved_line;
-       }
+       skip_prologue_sal (sal);
     }
 
   if (sal->section == 0 && sal->symtab != NULL)
@@ -6122,10 +7583,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);
            }
        }
     }
@@ -6236,9 +7702,8 @@ 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 block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
   struct value *val, *mark;
   struct frame_info *frame;
   char *exp_start = NULL;
@@ -6247,14 +7712,11 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
   int toklen;
   char *cond_start = NULL;
   char *cond_end = NULL;
-  struct expression *cond = NULL;
   int i, other_type_used, target_resources_ok = 0;
   enum bptype bp_type;
   int mem_cnt = 0;
   int thread = -1;
 
-  init_sal (&sal);             /* initialize to zeroes */
-
   /* Make sure that we actually have parameters to parse.  */
   if (arg != NULL && arg[0] != '\0')
     {
@@ -6344,8 +7806,17 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
   toklen = end_tok - tok;
   if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
     {
+      struct expression *cond;
+
+      innermost_block = NULL;
       tok = cond_start = end_tok + 1;
       cond = parse_exp_1 (&tok, 0, 0);
+
+      /* The watchpoint expression may not be local, but the condition
+        may still be.  E.g.: `watch global if local > 0'.  */
+      cond_exp_valid_block = innermost_block;
+
+      xfree (cond);
       cond_end = tok;
     }
   if (*tok)
@@ -6385,7 +7856,7 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
      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 && frame)
+  if (exp_valid_block && frame)
     {
       if (frame_id_p (frame_unwind_caller_id (frame)))
        {
@@ -6415,26 +7886,32 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
     }
 
   /* Now set up the breakpoint.  */
-  b = set_raw_breakpoint (gdbarch, sal, bp_type);
+  b = set_raw_breakpoint_without_location (NULL, bp_type);
   set_breakpoint_count (breakpoint_count + 1);
   b->number = breakpoint_count;
   b->thread = thread;
   b->disposition = disp_donttouch;
   b->exp = exp;
   b->exp_valid_block = exp_valid_block;
+  b->cond_exp_valid_block = cond_exp_valid_block;
   b->exp_string = savestring (exp_start, exp_end - exp_start);
   b->val = val;
   b->val_valid = 1;
-  b->loc->cond = cond;
   if (cond_start)
     b->cond_string = savestring (cond_start, cond_end - cond_start);
   else
     b->cond_string = 0;
 
   if (frame)
-    b->watchpoint_frame = get_frame_id (frame);
+    {
+      b->watchpoint_frame = get_frame_id (frame);
+      b->watchpoint_thread = inferior_ptid;
+    }
   else
-    b->watchpoint_frame = null_frame_id;
+    {
+      b->watchpoint_frame = null_frame_id;
+      b->watchpoint_thread = null_ptid;
+    }
 
   if (scope_breakpoint != NULL)
     {
@@ -6445,6 +7922,11 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
     }
 
   value_free_to_mark (mark);
+
+  /* Finally update the new watchpoint.  This creates the locations
+     that should be inserted.  */
+  update_watchpoint (b, 1);
+
   mention (b);
   update_global_location_list (1);
 }
@@ -6710,42 +8192,6 @@ ep_parse_optional_if_clause (char **arg)
   return cond_string;
 }
 
-/* This function attempts to parse an optional filename from the arg
-   string.  If one is not found, it returns NULL.
-
-   Else, it returns a pointer to the parsed filename.  (This function
-   makes no attempt to verify that a file of that name exists, or is
-   accessible.)  And, it updates arg to point to the first character
-   following the parsed filename in the arg string.
-
-   Note that clients needing to preserve the returned filename for
-   future access should copy it to their own buffers. */
-static char *
-ep_parse_optional_filename (char **arg)
-{
-  static char filename[1024];
-  char *arg_p = *arg;
-  int i;
-  char c;
-
-  if ((*arg_p == '\0') || isspace (*arg_p))
-    return NULL;
-
-  for (i = 0;; i++)
-    {
-      c = *arg_p;
-      if (isspace (c))
-       c = '\0';
-      filename[i] = c;
-      if (c == '\0')
-       break;
-      arg_p++;
-    }
-  *arg = arg_p;
-
-  return filename;
-}
-
 /* Commands to deal with catching events, such as signals, exceptions,
    process start/exit, etc.  */
 
@@ -6900,13 +8346,29 @@ print_mention_exception_catchpoint (struct breakpoint *b)
                               : _(" (catch)"));
 }
 
+/* Implement the "print_recreate" breakpoint_ops method for throw and
+   catch catchpoints.  */
+
+static void
+print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
+{
+  int bp_temp;
+  int bp_throw;
+
+  bp_temp = b->disposition == disp_del;
+  bp_throw = strstr (b->addr_string, "throw") != NULL;
+  fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
+  fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
+}
+
 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
   NULL, /* insert */
   NULL, /* remove */
   NULL, /* breakpoint_hit */
   print_exception_catchpoint,
   print_one_exception_catchpoint,
-  print_mention_exception_catchpoint
+  print_mention_exception_catchpoint,
+  print_recreate_exception_catchpoint
 };
 
 static int
@@ -6920,14 +8382,14 @@ handle_gnu_v3_exceptions (int tempflag, char *cond_string,
   else
     trigger_func_name = "__cxa_throw";
 
-  break_command_really (get_current_arch (),
-                       trigger_func_name, cond_string, -1,
-                       0 /* condition and thread are valid.  */,
-                       tempflag, 0, 0,
-                       0,
-                       AUTO_BOOLEAN_TRUE /* pending */,
-                       &gnu_v3_exception_catchpoint_ops, from_tty,
-                       1 /* enabled */);
+  create_breakpoint (get_current_arch (),
+                    trigger_func_name, cond_string, -1,
+                    0 /* condition and thread are valid.  */,
+                    tempflag, 0, 0,
+                    0,
+                    AUTO_BOOLEAN_TRUE /* pending */,
+                    &gnu_v3_exception_catchpoint_ops, from_tty,
+                    1 /* enabled */);
 
   return 1;
 }
@@ -6999,7 +8461,8 @@ create_ada_exception_breakpoint (struct gdbarch *gdbarch,
       if (!loc_gdbarch)
        loc_gdbarch = gdbarch;
 
-      describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1);
+      describe_other_breakpoints (loc_gdbarch,
+                                 sal.pspace, sal.pc, sal.section, -1);
       /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
          version for exception catchpoints, because two catchpoints
          used for different exception names will use the same address.
@@ -7056,6 +8519,103 @@ catch_ada_exception_command (char *arg, int from_tty,
                                    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
@@ -7116,6 +8676,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."));
 
@@ -7170,22 +8731,20 @@ clear_command (char *arg, int from_tty)
        {
          int match = 0;
          /* Are we going to delete b? */
-         if (b->type != bp_none
-             && b->type != bp_watchpoint
-             && b->type != bp_hardware_watchpoint
-             && b->type != bp_read_watchpoint
-             && b->type != bp_access_watchpoint)
+         if (b->type != bp_none && !is_watchpoint (b))
            {
              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)
@@ -7253,14 +8812,71 @@ breakpoint_auto_delete (bpstat bs)
   }
 }
 
-/* A cleanup function which destroys a vector.  */
+/* A comparison function for bp_location AP and BP 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 (const void *ap, const void *bp)
+{
+  struct bp_location *a = *(void **) ap;
+  struct bp_location *b = *(void **) bp;
+  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);
+}
+
+/* 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
@@ -7282,49 +8898,85 @@ 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);
+  /* Used in the duplicates detection below.  When iterating over all
+     bp_locations, points to the first bp_location of a given address.
+     Breakpoints and watchpoints of different types are never
+     duplicates of each other.  Keep one pointer for each type of
+     breakpoint/watchpoint, so we only need to loop over all locations
+     once.  */
+  struct bp_location *bp_loc_first;  /* breakpoint */
+  struct bp_location *wp_loc_first;  /* hardware watchpoint */
+  struct bp_location *awp_loc_first; /* access watchpoint */
+  struct bp_location *rwp_loc_first; /* read watchpoint */
+
+  /* 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);
+
+  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;
+      struct bp_location **loc2p;
+
+      /* Tells if 'old_loc' is found amoung the new locations.  If not, we
         have to free it.  */
       int found_object = 0;
       /* 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
+            && (*locp)->address < old_loc->address)
+       locp++;
+
+      for (loc2p = locp;
+          (loc2p < bp_location + bp_location_count
+           && (*loc2p)->address == old_loc->address);
+          loc2p++)
+       {
+         if (*loc2p == old_loc)
+           {
+             found_object = 1;
+             break;
+           }
+       }
 
       /* 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 
@@ -7332,11 +8984,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.  */
@@ -7347,37 +8999,57 @@ 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))
+               {
+                 for (loc2p = locp;
+                      (loc2p < bp_location + bp_location_count
+                       && (*loc2p)->address == old_loc->address);
+                      loc2p++)
+                   {
+                     struct bp_location *loc2 = *loc2p;
+
+                     if (breakpoint_locations_match (loc2, old_loc))
+                       {
+                         /* For the sake of should_be_inserted.
+                            Duplicates check below will fix up this later.  */
+                         loc2->duplicate = 0;
+
+                         /* Read watchpoint locations are switched to
+                            access watchpoints, if the former are not
+                            supported, but the latter are.  */
+                         if (is_hardware_watchpoint (old_loc->owner))
+                           {
+                             gdb_assert (is_hardware_watchpoint (loc2->owner));
+                             loc2->watchpoint_type = old_loc->watchpoint_type;
+                           }
+
+                         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;
            }
@@ -7385,33 +9057,124 @@ update_global_location_list (int should_insert)
 
       if (!found_object)
        {
-         if (removed && non_stop)
+         if (removed && non_stop
+             && breakpoint_address_is_meaningful (old_loc->owner)
+             && !is_hardware_watchpoint (old_loc->owner))
            {
-             /* This location was removed from the targets.  In non-stop mode,
-                a race condition is possible where we've removed a breakpoint,
-                but stop events for that breakpoint are already queued and will
-                arrive later.  To suppress spurious SIGTRAPs reported to user,
-                we keep this breakpoint location for a bit, and will retire it
-                after we see 3 * thread_count events.
-                The theory here is that reporting of events should,
-                "on the average", be fair, so after that many event we'll see
-                events from all threads that have anything of interest, and no
-                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;
-
-             VEC_safe_push (bp_location_p, moribund_locations, loc);
+             /* This location was removed from the target.  In
+                non-stop mode, a race condition is possible where
+                we've removed a breakpoint, but stop events for that
+                breakpoint are already queued and will arrive later.
+                We apply an heuristic to be able to distinguish such
+                SIGTRAPs from other random SIGTRAPs: we keep this
+                breakpoint location for a bit, and will retire it
+                after we see some number of events.  The theory here
+                is that reporting of events should, "on the average",
+                be fair, so after a while we'll see events from all
+                threads that have anything of interest, and no longer
+                need to keep this breakpoint location around.  We
+                don't hold locations forever so to reduce chances of
+                mistaking a non-breakpoint SIGTRAP for a breakpoint
+                SIGTRAP.
+
+                The heuristic failing can be disastrous on
+                decr_pc_after_break targets.
+
+                On decr_pc_after_break targets, like e.g., x86-linux,
+                if we fail to recognize a late breakpoint SIGTRAP,
+                because events_till_retirement has reached 0 too
+                soon, we'll fail to do the PC adjustment, and report
+                a random SIGTRAP to the user.  When the user resumes
+                the inferior, it will most likely immediately crash
+                with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
+                corrupted, because of being resumed e.g., in the
+                middle of a multi-byte instruction, or skipped a
+                one-byte instruction.  This was actually seen happen
+                on native x86-linux, and should be less rare on
+                targets that do not support new thread events, like
+                remote, due to the heuristic depending on
+                thread_count.
+
+                Mistaking a random SIGTRAP for a breakpoint trap
+                causes similar symptoms (PC adjustment applied when
+                it shouldn't), but then again, playing with SIGTRAPs
+                behind the debugger's back is asking for trouble.
+
+                Since hardware watchpoint traps are always
+                distinguishable from other traps, so we don't need to
+                apply keep hardware watchpoint moribund locations
+                around.  We simply always ignore hardware watchpoint
+                traps we can no longer explain.  */
+
+             old_loc->events_till_retirement = 3 * (thread_count () + 1);
+             old_loc->owner = NULL;
+
+             VEC_safe_push (bp_location_p, moribund_locations, old_loc);
            }
          else
-           free_bp_location (loc);
+           free_bp_location (old_loc);
        }
     }
 
-  ALL_BREAKPOINTS (b)
-    {
-      check_duplicates (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.
+
+     Do the same for hardware watchpoints, but also considering the
+     watchpoint's type (regular/access/read) and length.  */
+
+  bp_loc_first = NULL;
+  wp_loc_first = NULL;
+  awp_loc_first = NULL;
+  rwp_loc_first = NULL;
+  ALL_BP_LOCATIONS (loc, locp)
+    {
+      struct breakpoint *b = loc->owner;
+      struct bp_location **loc_first_p;
+
+      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)
+         || is_tracepoint (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 (b->type == bp_hardware_watchpoint)
+       loc_first_p = &wp_loc_first;
+      else if (b->type == bp_read_watchpoint)
+       loc_first_p = &rwp_loc_first;
+      else if (b->type == bp_access_watchpoint)
+       loc_first_p = &awp_loc_first;
+      else
+       loc_first_p = &bp_loc_first;
+
+      if (*loc_first_p == NULL
+         || (overlay_debugging && loc->section != (*loc_first_p)->section)
+         || !breakpoint_locations_match (loc, *loc_first_p))
+       {
+         *loc_first_p = loc;
+         loc->duplicate = 0;
+         continue;
+       }
+
+      loc->duplicate = 1;
+
+      if ((*loc_first_p)->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
@@ -7495,6 +9258,16 @@ delete_breakpoint (struct breakpoint *bpt)
   if (bpt->type == bp_none)
     return;
 
+  /* At least avoid this stale reference until the reference counting of
+     breakpoints gets resolved.  */
+  if (bpt->related_breakpoint != NULL)
+    {
+      gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
+      bpt->related_breakpoint->disposition = disp_del_at_next_stop;
+      bpt->related_breakpoint->related_breakpoint = NULL;
+      bpt->related_breakpoint = NULL;
+    }
+
   observer_notify_breakpoint_deleted (bpt->number);
 
   if (breakpoint_chain == bpt)
@@ -7507,21 +9280,16 @@ delete_breakpoint (struct breakpoint *bpt)
       break;
     }
 
-  free_command_lines (&bpt->commands);
-  if (bpt->cond_string != NULL)
-    xfree (bpt->cond_string);
-  if (bpt->addr_string != NULL)
-    xfree (bpt->addr_string);
-  if (bpt->exp != NULL)
-    xfree (bpt->exp);
-  if (bpt->exp_string != NULL)
-    xfree (bpt->exp_string);
-  if (bpt->val != NULL)
-    value_free (bpt->val);
-  if (bpt->source_file != NULL)
-    xfree (bpt->source_file);
-  if (bpt->exec_pathname != NULL)
-    xfree (bpt->exec_pathname);
+  decref_counted_command_line (&bpt->commands);
+  xfree (bpt->cond_string);
+  xfree (bpt->cond_exp);
+  xfree (bpt->addr_string);
+  xfree (bpt->exp);
+  xfree (bpt->exp_string);
+  value_free (bpt->val);
+  xfree (bpt->source_file);
+  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?
@@ -7565,6 +9333,15 @@ make_cleanup_delete_breakpoint (struct breakpoint *b)
   return make_cleanup (do_delete_breakpoint_cleanup, b);
 }
 
+/* A callback for map_breakpoint_numbers that calls
+   delete_breakpoint.  */
+
+static void
+do_delete_breakpoint (struct breakpoint *b, void *ignore)
+{
+  delete_breakpoint (b);
+}
+
 void
 delete_command (char *arg, int from_tty)
 {
@@ -7582,10 +9359,13 @@ delete_command (char *arg, int from_tty)
       ALL_BREAKPOINTS (b)
       {
        if (b->type != bp_call_dummy
+           && b->type != bp_std_terminate
            && 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->type != bp_std_terminate_master
            && b->number >= 0)
          {
            breaks_to_delete = 1;
@@ -7600,17 +9380,20 @@ delete_command (char *arg, int from_tty)
          ALL_BREAKPOINTS_SAFE (b, temp)
          {
            if (b->type != bp_call_dummy
+               && b->type != bp_std_terminate
                && 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->type != bp_std_terminate_master
                && b->number >= 0)
              delete_breakpoint (b);
          }
        }
     }
   else
-    map_breakpoint_numbers (arg, delete_breakpoint);
+    map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
 }
 
 static int
@@ -7737,7 +9520,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;
@@ -7774,12 +9558,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)
     {
@@ -7790,6 +9574,11 @@ breakpoint_re_set_one (void *bint)
     case bp_breakpoint:
     case bp_hardware_breakpoint:
     case bp_tracepoint:
+    case bp_fast_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. */
@@ -7800,6 +9589,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,
@@ -7833,29 +9626,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;
-         int task = 0;
-
-         find_condition_and_thread (s, sals.sals[0].pc, 
-                                    &cond_string, &thread, &task);
-         if (cond_string)
-           b->cond_string = cond_string;
-         b->thread = thread;
-         b->task = task;
-         b->condition_not_parsed = 0;
+         gdb_assert (sals.nelts == 1);
+
+         resolve_sal_pc (&sals.sals[0]);
+         if (b->condition_not_parsed && s && s[0])
+           {
+             char *cond_string = 0;
+             int thread = -1;
+             int task = 0;
+
+             find_condition_and_thread (s, sals.sals[0].pc,
+                                        &cond_string, &thread, &task);
+             if (cond_string)
+               b->cond_string = cond_string;
+             b->thread = thread;
+             b->task = task;
+             b->condition_not_parsed = 0;
+           }
+
+         expanded = expand_line_sal_maybe (sals.sals[0]);
        }
-      expanded = expand_line_sal_maybe (sals.sals[0]);
-      cleanups = make_cleanup (xfree, sals.sals);
+
+      make_cleanup (xfree, sals.sals);
       update_breakpoint_locations (b, expanded);
-      do_cleanups (cleanups);
       break;
 
     case bp_watchpoint:
@@ -7902,6 +9697,7 @@ breakpoint_re_set_one (void *bint)
         reset later by breakpoint_re_set.  */
     case bp_overlay_event:
     case bp_longjmp_master:
+    case bp_std_terminate_master:
       delete_breakpoint (b);
       break;
 
@@ -7921,12 +9717,15 @@ breakpoint_re_set_one (void *bint)
     case bp_finish:
     case bp_watchpoint_scope:
     case bp_call_dummy:
+    case bp_std_terminate:
     case bp_step_resume:
     case bp_longjmp:
     case bp_longjmp_resume:
+    case bp_jit_event:
       break;
     }
 
+  do_cleanups (cleanups);
   return 0;
 }
 
@@ -7937,9 +9736,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 */
@@ -7952,11 +9754,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");
+  create_std_terminate_master_breakpoint ("std::terminate()");
 }
 \f
 /* Reset the thread number of this breakpoint:
@@ -7970,6 +9777,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;
     }
 }
 
@@ -7988,6 +9801,14 @@ set_ignore_count (int bptnum, int count, int from_tty)
   ALL_BREAKPOINTS (b)
     if (b->number == bptnum)
     {
+      if (is_tracepoint (b))
+       {
+         if (from_tty && count != 0)
+           printf_filtered (_("Ignore count ignored for tracepoint %d."),
+                            bptnum);
+         return;
+       }
+      
       b->ignore_count = count;
       if (from_tty)
        {
@@ -8044,7 +9865,9 @@ ignore_command (char *args, int from_tty)
    whose numbers are given in ARGS.  */
 
 static void
-map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
+map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
+                                                     void *),
+                       void *data)
 {
   char *p = args;
   char *p1;
@@ -8072,9 +9895,9 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
              {
                struct breakpoint *related_breakpoint = b->related_breakpoint;
                match = 1;
-               function (b);
+               function (b, data);
                if (related_breakpoint)
-                 function (related_breakpoint);
+                 function (related_breakpoint, data);
                break;
              }
          if (match == 0)
@@ -8150,6 +9973,15 @@ disable_breakpoint (struct breakpoint *bpt)
   observer_notify_breakpoint_modified (bpt->number);
 }
 
+/* A callback for map_breakpoint_numbers that calls
+   disable_breakpoint.  */
+
+static void
+do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
+{
+  disable_breakpoint (b);
+}
+
 static void
 disable_command (char *args, int from_tty)
 {
@@ -8164,6 +9996,7 @@ disable_command (char *args, int from_tty)
        continue;
       case bp_breakpoint:
       case bp_tracepoint:
+      case bp_fast_tracepoint:
       case bp_catchpoint:
       case bp_hardware_breakpoint:
       case bp_watchpoint:
@@ -8182,7 +10015,7 @@ disable_command (char *args, int from_tty)
       update_global_location_list (0);
     }
   else
-    map_breakpoint_numbers (args, disable_breakpoint);
+    map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
 }
 
 static void
@@ -8204,10 +10037,7 @@ 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 (is_watchpoint (bpt))
     {
       struct gdb_exception e;
 
@@ -8239,6 +10069,15 @@ enable_breakpoint (struct breakpoint *bpt)
   do_enable_breakpoint (bpt, bpt->disposition);
 }
 
+/* A callback for map_breakpoint_numbers that calls
+   enable_breakpoint.  */
+
+static void
+do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
+{
+  enable_breakpoint (b);
+}
+
 /* The enable command enables the specified breakpoints (or all defined
    breakpoints) so they once again become (or continue to be) effective
    in stopping the inferior.  */
@@ -8257,6 +10096,7 @@ enable_command (char *args, int from_tty)
        continue;
       case bp_breakpoint:
       case bp_tracepoint:
+      case bp_fast_tracepoint:
       case bp_catchpoint:
       case bp_hardware_breakpoint:
       case bp_watchpoint:
@@ -8275,11 +10115,11 @@ enable_command (char *args, int from_tty)
       update_global_location_list (1);
     }
   else
-    map_breakpoint_numbers (args, enable_breakpoint);
+    map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
 }
 
 static void
-enable_once_breakpoint (struct breakpoint *bpt)
+enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
 {
   do_enable_breakpoint (bpt, disp_disable);
 }
@@ -8287,11 +10127,11 @@ enable_once_breakpoint (struct breakpoint *bpt)
 static void
 enable_once_command (char *args, int from_tty)
 {
-  map_breakpoint_numbers (args, enable_once_breakpoint);
+  map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
 }
 
 static void
-enable_delete_breakpoint (struct breakpoint *bpt)
+enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
 {
   do_enable_breakpoint (bpt, disp_del);
 }
@@ -8299,7 +10139,7 @@ enable_delete_breakpoint (struct breakpoint *bpt)
 static void
 enable_delete_command (char *args, int from_tty)
 {
-  map_breakpoint_numbers (args, enable_delete_breakpoint);
+  map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
 }
 \f
 static void
@@ -8312,6 +10152,35 @@ show_breakpoint_cmd (char *args, int from_tty)
 {
 }
 
+/* Invalidate last known value of any hardware watchpoint if
+   the memory which that value represents has been written to by
+   GDB itself.  */
+
+static void
+invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
+                                     const bfd_byte *data)
+{
+  struct breakpoint *bp;
+
+  ALL_BREAKPOINTS (bp)
+    if (bp->enable_state == bp_enabled
+       && bp->type == bp_hardware_watchpoint
+       && bp->val_valid && bp->val)
+      {
+       struct bp_location *loc;
+
+       for (loc = bp->loc; loc != NULL; loc = loc->next)
+         if (loc->loc_type == bp_loc_hardware_watchpoint
+             && loc->address + loc->length > addr
+             && addr + len > loc->address)
+           {
+             value_free (bp->val);
+             bp->val = NULL;
+             bp->val_valid = 0;
+           }
+      }
+}
+
 /* Use default_breakpoint_'s, or nothing if they aren't valid.  */
 
 struct symtabs_and_lines
@@ -8340,14 +10209,16 @@ decode_line_spec_1 (char *string, int funfirstline)
    someday.  */
 
 void *
-deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
+deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
+                                 struct address_space *aspace, CORE_ADDR pc)
 {
   struct bp_target_info *bp_tgt;
 
-  bp_tgt = xmalloc (sizeof (struct bp_target_info));
-  memset (bp_tgt, 0, sizeof (struct bp_target_info));
+  bp_tgt = XZALLOC (struct bp_target_info);
 
+  bp_tgt->placed_address_space = aspace;
   bp_tgt->placed_address = pc;
+
   if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
     {
       /* Could not insert the breakpoint.  */
@@ -8380,7 +10251,8 @@ static struct gdbarch *single_step_gdbarch[2];
 /* Create and insert a breakpoint for software single step.  */
 
 void
-insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc)
+insert_single_step_breakpoint (struct gdbarch *gdbarch,
+                              struct address_space *aspace, CORE_ADDR next_pc)
 {
   void **bpt_p;
 
@@ -8403,7 +10275,7 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch, 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 (gdbarch, next_pc);
+  *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
   if (*bpt_p == NULL)
     error (_("Could not insert single-step breakpoint at %s"),
             paddress (gdbarch, next_pc));
@@ -8435,20 +10307,77 @@ 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.  */
@@ -8462,48 +10391,155 @@ set_tracepoint_count (int 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);
+  if (create_breakpoint (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);
+}
+
+void
+ftrace_command (char *arg, int from_tty)
+{
+  if (create_breakpoint (get_current_arch (),
+                        arg,
+                        NULL, 0, 1 /* parse arg */,
+                        0 /* tempflag */, 1 /* hardwareflag */,
+                        1 /* traceflag */,
+                        0 /* Ignore count */,
+                        pending_break_support,
+                        NULL,
+                        from_tty,
+                        1 /* enabled */))
+    set_tracepoint_count (breakpoint_count);
+}
+
+/* Set up a fake reader function that gets command lines from a linked
+   list that was acquired during tracepoint uploading.  */
+
+static struct uploaded_tp *this_utp;
+static int next_cmd;
+
+static char *
+read_uploaded_action (void)
+{
+  char *rslt;
+
+  VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
+
+  next_cmd++;
+
+  return rslt;
 }
 
+/* Given information about a tracepoint as recorded on a target (which
+   can be either a live system or a trace file), attempt to create an
+   equivalent GDB tracepoint.  This is not a reliable process, since
+   the target does not necessarily have all the information used when
+   the tracepoint was originally defined.  */
+  
+struct breakpoint *
+create_tracepoint_from_upload (struct uploaded_tp *utp)
+{
+  char *addr_str, small_buf[100];
+  struct breakpoint *tp;
+
+  if (utp->at_string)
+    addr_str = utp->at_string;
+  else
+    {
+      /* In the absence of a source location, fall back to raw
+        address.  Since there is no way to confirm that the address
+        means the same thing as when the trace was started, warn the
+        user.  */
+      warning (_("Uploaded tracepoint %d has no source location, using raw address"),
+              utp->number);
+      sprintf (small_buf, "*%s", hex_string (utp->addr));
+      addr_str = small_buf;
+    }
+
+  /* There's not much we can do with a sequence of bytecodes.  */
+  if (utp->cond && !utp->cond_string)
+    warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
+            utp->number);
+
+  if (!create_breakpoint (get_current_arch (),
+                         addr_str,
+                         utp->cond_string, -1, 0 /* parse cond/thread */,
+                         0 /* tempflag */,
+                         (utp->type == bp_fast_tracepoint) /* hardwareflag */,
+                         1 /* traceflag */,
+                         0 /* Ignore count */,
+                         pending_break_support,
+                         NULL,
+                         0 /* from_tty */,
+                         utp->enabled /* enabled */))
+    return NULL;
+
+  set_tracepoint_count (breakpoint_count);
+  
+  /* Get the tracepoint we just created.  */
+  tp = get_tracepoint (tracepoint_count);
+  gdb_assert (tp != NULL);
+
+  if (utp->pass > 0)
+    {
+      sprintf (small_buf, "%d %d", utp->pass, tp->number);
+
+      trace_pass_command (small_buf, 0);
+    }
+
+  /* If we have uploaded versions of the original commands, set up a
+     special-purpose "reader" function and call the usual command line
+     reader, then pass the result to the breakpoint command-setting
+     function.  */
+  if (!VEC_empty (char_ptr, utp->cmd_strings))
+    {
+      struct command_line *cmd_list;
+
+      this_utp = utp;
+      next_cmd = 0;
+
+      cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
+
+      breakpoint_set_commands (tp, cmd_list);
+    }
+  else if (!VEC_empty (char_ptr, utp->actions)
+          || !VEC_empty (char_ptr, utp->step_actions))
+    warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
+            utp->number);
+
+  return tp;
+  }
+  
 /* 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;
+  int tpnum = -1, num_printed;
 
-  /* In the no-arguments case, say "No tracepoints" if none found.  */
-  if (tpnum_exp == 0)
+  if (tpnum_exp)
+    tpnum = parse_and_eval_long (tpnum_exp);
+
+  num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
+
+  if (num_printed == 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;
-       }
+      if (tpnum == -1)
+       ui_out_message (uiout, 0, "No tracepoints.\n");
+      else
+       ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
     }
 
-  /* Otherwise be the same as "info break".  */
-  breakpoints_info (tpnum_exp, from_tty);
+  default_collect_info ();
 }
 
 /* The 'enable trace' command enables tracepoints.  
@@ -8552,14 +10588,14 @@ delete_trace_command (char *arg, int from_tty)
        {
          ALL_BREAKPOINTS_SAFE (b, temp)
          {
-           if (b->type == bp_tracepoint
+           if (is_tracepoint (b)
                && b->number >= 0)
              delete_breakpoint (b);
          }
        }
     }
   else
-    map_breakpoint_numbers (arg, delete_breakpoint);
+    map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
 }
 
 /* Set passcount for tracepoint.
@@ -8625,6 +10661,22 @@ get_tracepoint (int num)
   return NULL;
 }
 
+/* Find the tracepoint with the given target-side number (which may be
+   different from the tracepoint number after disconnecting and
+   reconnecting).  */
+
+struct breakpoint *
+get_tracepoint_by_number_on_target (int num)
+{
+  struct breakpoint *t;
+
+  ALL_TRACEPOINTS (t)
+    if (t->number_on_target == 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
@@ -8670,86 +10722,195 @@ get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
   return NULL;
 }
 
-/* save-tracepoints command */
+/* Save information on user settable breakpoints (watchpoints, etc) to
+   a new script file named FILENAME.  If FILTER is non-NULL, call it
+   on each breakpoint and only include the ones for which it returns
+   non-zero.  */
+
 static void
-tracepoint_save_command (char *args, int from_tty)
+save_breakpoints (char *filename, int from_tty,
+                 int (*filter) (const struct breakpoint *))
 {
   struct breakpoint *tp;
-  int any_tp = 0;
-  struct action_line *line;
-  FILE *fp;
-  char *i1 = "    ", *i2 = "      ";
-  char *indent, *actionline, *pathname;
-  char tmp[40];
+  int any = 0;
+  char *pathname;
   struct cleanup *cleanup;
+  struct ui_file *fp;
+  int extra_trace_bits = 0;
 
-  if (args == 0 || *args == 0)
-    error (_("Argument required (file name in which to save tracepoints)"));
+  if (filename == 0 || *filename == 0)
+    error (_("Argument required (file name in which to save)"));
 
   /* See if we have anything to save.  */
-  ALL_TRACEPOINTS (tp)
+  ALL_BREAKPOINTS (tp)
   {
-    any_tp = 1;
-    break;
+    /* Skip internal and momentary breakpoints.  */
+    if (!user_settable_breakpoint (tp))
+      continue;
+
+    /* If we have a filter, only save the breakpoints it accepts.  */
+    if (filter && !filter (tp))
+      continue;
+
+    any = 1;
+
+    if (is_tracepoint (tp))
+      {
+       extra_trace_bits = 1;
+
+       /* We can stop searching.  */
+       break;
+      }
   }
-  if (!any_tp)
+
+  if (!any)
     {
-      warning (_("save-tracepoints: no tracepoints to save."));
+      warning (_("Nothing to save."));
       return;
     }
 
-  pathname = tilde_expand (args);
+  pathname = tilde_expand (filename);
   cleanup = make_cleanup (xfree, pathname);
-  fp = fopen (pathname, "w");
+  fp = gdb_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)
+    error (_("Unable to open file '%s' for saving (%s)"),
+          filename, safe_strerror (errno));
+  make_cleanup_ui_file_delete (fp);
+
+  if (extra_trace_bits)
+    save_trace_state_variables (fp);
+
+  ALL_BREAKPOINTS (tp)
   {
-    if (tp->addr_string)
-      fprintf (fp, "trace %s\n", tp->addr_string);
+    /* Skip internal and momentary breakpoints.  */
+    if (!user_settable_breakpoint (tp))
+      continue;
+
+    /* If we have a filter, only save the breakpoints it accepts.  */
+    if (filter && !filter (tp))
+      continue;
+
+    if (tp->ops != NULL)
+      (tp->ops->print_recreate) (tp, fp);
     else
       {
-       sprintf_vma (tmp, tp->loc->address);
-       fprintf (fp, "trace *0x%s\n", tmp);
+       if (tp->type == bp_fast_tracepoint)
+         fprintf_unfiltered (fp, "ftrace");
+       else if (tp->type == bp_tracepoint)
+         fprintf_unfiltered (fp, "trace");
+       else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
+         fprintf_unfiltered (fp, "tbreak");
+       else if (tp->type == bp_breakpoint)
+         fprintf_unfiltered (fp, "break");
+       else if (tp->type == bp_hardware_breakpoint
+                && tp->disposition == disp_del)
+         fprintf_unfiltered (fp, "thbreak");
+       else if (tp->type == bp_hardware_breakpoint)
+         fprintf_unfiltered (fp, "hbreak");
+       else if (tp->type == bp_watchpoint)
+         fprintf_unfiltered (fp, "watch");
+       else if (tp->type == bp_hardware_watchpoint)
+         fprintf_unfiltered (fp, "watch");
+       else if (tp->type == bp_read_watchpoint)
+         fprintf_unfiltered (fp, "rwatch");
+       else if (tp->type == bp_access_watchpoint)
+         fprintf_unfiltered (fp, "awatch");
+       else
+         internal_error (__FILE__, __LINE__,
+                         _("unhandled breakpoint type %d"), (int) tp->type);
+
+       if (tp->exp_string)
+         fprintf_unfiltered (fp, " %s", tp->exp_string);
+       else if (tp->addr_string)
+         fprintf_unfiltered (fp, " %s", tp->addr_string);
+       else
+         {
+           char tmp[40];
+
+           sprintf_vma (tmp, tp->loc->address);
+           fprintf_unfiltered (fp, " *0x%s", tmp);
+         }
       }
 
+    if (tp->thread != -1)
+      fprintf_unfiltered (fp, " thread %d", tp->thread);
+
+    if (tp->task != 0)
+      fprintf_unfiltered (fp, " task %d", tp->task);
+
+    fprintf_unfiltered (fp, "\n");
+
+    /* Note, we can't rely on tp->number for anything, as we can't
+       assume the recreated breakpoint numbers will match.  Use $bpnum
+       instead.  */
+
+    if (tp->cond_string)
+      fprintf_unfiltered (fp, "  condition $bpnum %s\n", tp->cond_string);
+
+    if (tp->ignore_count)
+      fprintf_unfiltered (fp, "  ignore $bpnum %d\n", tp->ignore_count);
+
     if (tp->pass_count)
-      fprintf (fp, "  passcount %d\n", tp->pass_count);
+      fprintf_unfiltered (fp, "  passcount %d\n", tp->pass_count);
 
-    if (tp->actions)
+    if (tp->commands)
       {
-       fprintf (fp, "  actions\n");
-       indent = i1;
-       for (line = tp->actions; line; line = line->next)
+       volatile struct gdb_exception ex;       
+
+       fprintf_unfiltered (fp, "  commands\n");
+       
+       ui_out_redirect (uiout, fp);
+       TRY_CATCH (ex, RETURN_MASK_ERROR)
          {
-           struct cmd_list_element *cmd;
+           print_command_lines (uiout, tp->commands->commands, 2);
+         }
+       ui_out_redirect (uiout, NULL);
 
-           QUIT;               /* allow user to bail out with ^C */
-           actionline = line->action;
-           while (isspace ((int) *actionline))
-             actionline++;
+       if (ex.reason < 0)
+         throw_exception (ex);
 
-           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;
-             }
-         }
+       fprintf_unfiltered (fp, "  end\n");
+      }
+
+    if (tp->enable_state == bp_disabled)
+      fprintf_unfiltered (fp, "disable\n");
+
+    /* If this is a multi-location breakpoint, check if the locations
+       should be individually disabled.  Watchpoint locations are
+       special, and not user visible.  */
+    if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
+      {
+       struct bp_location *loc;
+       int n = 1;
+
+       for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
+         if (!loc->enabled)
+           fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
       }
   }
+
+  if (extra_trace_bits && *default_collect)
+    fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
+
   do_cleanups (cleanup);
   if (from_tty)
-    printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
-  return;
+    printf_filtered (_("Saved to file '%s'.\n"), filename);
+}
+
+/* The `save breakpoints' command.  */
+
+static void
+save_breakpoints_command (char *args, int from_tty)
+{
+  save_breakpoints (args, from_tty, NULL);
+}
+
+/* The `save tracepoints' command.  */
+
+static void
+save_tracepoints_command (char *args, int from_tty)
+{
+  save_breakpoints (args, from_tty, is_tracepoint);
 }
 
 /* Create a vector of all tracepoints.  */
@@ -8800,6 +10961,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)
 {
@@ -8809,21 +10972,39 @@ 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 (struct inferior *inf)
+{
+  inf->total_syscalls_count = 0;
+  inf->any_syscall_count = 0;
+  VEC_free (int, inf->syscalls_counts);
+}
+
+static void
+save_command (char *arg, int from_tty)
+{
+  printf_unfiltered (_("\
+\"save\" must be followed by the name of a save subcommand.\n"));
+  help_list (save_cmdlist, "save ", -1, gdb_stdout);
 }
 
 void
 _initialize_breakpoint (void)
 {
-  static struct cmd_list_element *breakpoint_set_cmdlist;
-  static struct cmd_list_element *breakpoint_show_cmdlist;
   struct cmd_list_element *c;
 
   observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
+  observer_attach_inferior_exit (clear_syscall_counts);
+  observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
 
   breakpoint_chain = 0;
   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
@@ -9034,6 +11215,8 @@ is prefixed with \"server \".\n\n\
 Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."));
 
+  add_info_alias ("b", "breakpoints", 1);
+
   if (xdb_commands)
     add_com ("lb", class_breakpoint, breakpoints_info, _("\
 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
@@ -9087,36 +11270,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);
 
@@ -9138,8 +11338,9 @@ A watchpoint stops execution of your program whenever the value of\n\
 an expression is either read or written."));
   set_cmd_completer (c, expression_completer);
 
-  add_info ("watchpoints", breakpoints_info,
-           _("Synonym for ``info breakpoints''."));
+  add_info ("watchpoints", watchpoints_info, _("\
+Status of watchpoints, or watchpoint number NUMBER."));
+
 
 
   /* XXX: cagney/2005-02-23: This should be a boolean, and should
@@ -9172,6 +11373,13 @@ Do \"help tracepoints\" for info on other tracepoint commands."));
   add_com_alias ("tra", "trace", class_alias, 1);
   add_com_alias ("trac", "trace", class_alias, 1);
 
+  c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
+Set a fast tracepoint at specified line or function.\n\
+\n"
+BREAK_ARGS_HELP ("ftrace") "\n\
+Do \"help tracepoints\" for info on other tracepoint commands."));
+  set_cmd_completer (c, location_completer);
+
   add_info ("tracepoints", tracepoints_info, _("\
 Status of tracepoints, or tracepoint number NUMBER.\n\
 Convenience variable \"$tpnum\" contains the number of the\n\
@@ -9205,11 +11413,28 @@ 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, _("\
+  add_prefix_cmd ("save", class_breakpoint, save_command,
+                 _("Save breakpoint definitions as a script."),
+                 &save_cmdlist, "save ",
+                 0/*allow-unknown*/, &cmdlist);
+
+  c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
+Save current breakpoint definitions as a script.\n\
+This includes all types of breakpoints (breakpoints, watchpoints, \n\
+catchpoints, tracepoints).  Use the 'source' command in another debug\n\
+session to restore them."),
+              &save_cmdlist);
+  set_cmd_completer (c, filename_completer);
+
+  c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
 Save current tracepoint definitions as a script.\n\
-Use the 'source' command in another debug session to restore them."));
+Use the 'source' command in another debug session to restore them."),
+              &save_cmdlist);
   set_cmd_completer (c, filename_completer);
 
+  c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
+  deprecate_cmd (c, "save tracepoints");
+
   add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
 Breakpoint specific settings\n\
 Configure various breakpoint-specific variables such as\n\
This page took 0.101884 seconds and 4 git commands to generate.