gdb/mi: handle no condition argument case for -break-condition
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 5a9352c26fef592e293e4d5155780665e2c20151..dbbea6b8bff79016e25c0d92ec4b3f59477e184b 100644 (file)
@@ -1,6 +1,6 @@
 /* Everything about breakpoints, for GDB.
 
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -67,6 +67,7 @@
 #include "thread-fsm.h"
 #include "tid-parse.h"
 #include "cli/cli-style.h"
+#include "cli/cli-decode.h"
 
 /* readline include files */
 #include "readline/tilde.h"
@@ -89,7 +90,7 @@ static void map_breakpoint_numbers (const char *,
 static void breakpoint_re_set_default (struct breakpoint *);
 
 static void
-  create_sals_from_location_default (const struct event_location *location,
+  create_sals_from_location_default (struct event_location *location,
                                     struct linespec_result *canonical,
                                     enum bptype type_wanted);
 
@@ -104,7 +105,7 @@ static void create_breakpoints_sal_default (struct gdbarch *,
                                            int, int, int, unsigned);
 
 static std::vector<symtab_and_line> decode_location_default
-  (struct breakpoint *b, const struct event_location *location,
+  (struct breakpoint *b, struct event_location *location,
    struct program_space *search_pspace);
 
 static int can_use_hardware_watchpoint
@@ -135,7 +136,7 @@ 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);
+                                           enum bptype bptype);
 
 static void describe_other_breakpoints (struct gdbarch *,
                                        struct program_space *, CORE_ADDR,
@@ -144,6 +145,10 @@ static void describe_other_breakpoints (struct gdbarch *,
 static int watchpoint_locations_match (struct bp_location *loc1,
                                       struct bp_location *loc2);
 
+static int breakpoint_locations_match (struct bp_location *loc1,
+                                      struct bp_location *loc2,
+                                      bool sw_hw_bps_match = false);
+
 static int breakpoint_location_address_match (struct bp_location *bl,
                                              const struct address_space *aspace,
                                              CORE_ADDR addr);
@@ -168,8 +173,6 @@ static int hw_watchpoint_used_count_others (struct breakpoint *except,
 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
                                    int count);
 
-static void free_bp_location (struct bp_location *loc);
-static void incref_bp_location (struct bp_location *loc);
 static void decref_bp_location (struct bp_location **loc);
 
 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
@@ -221,8 +224,6 @@ static void set_tracepoint_count (int num);
 
 static bool is_masked_watchpoint (const struct breakpoint *b);
 
-static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
-
 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
    otherwise.  */
 
@@ -484,53 +485,109 @@ bool target_exact_watchpoints = false;
    ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
    current breakpoint.  */
 
-#define ALL_BREAKPOINTS(B)  for (B = breakpoint_chain; B; B = B->next)
-
 #define ALL_BREAKPOINTS_SAFE(B,TMP)    \
        for (B = breakpoint_chain;      \
             B ? (TMP=B->next, 1): 0;   \
             B = TMP)
 
-/* 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.  */
+/* Chains of all breakpoints defined.  */
 
-#define ALL_BP_LOCATIONS(B,BP_TMP)                                     \
-       for (BP_TMP = bp_locations;                                     \
-            BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
-            BP_TMP++)
+static struct breakpoint *breakpoint_chain;
 
-/* Iterates through locations with address ADDRESS for the currently selected
-   program space.  BP_LOCP_TMP points to each object.  BP_LOCP_START points
-   to where the loop should start from.
-   If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
-   appropriate location to start with.  */
+/* See breakpoint.h.  */
 
-#define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS)  \
-       for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
-            BP_LOCP_TMP = BP_LOCP_START;                               \
-            BP_LOCP_START                                              \
-            && (BP_LOCP_TMP < bp_locations + bp_locations_count        \
-            && (*BP_LOCP_TMP)->address == ADDRESS);                    \
-            BP_LOCP_TMP++)
+breakpoint_range
+all_breakpoints ()
+{
+  return breakpoint_range (breakpoint_chain);
+}
 
-/* Iterator for tracepoints only.  */
+/* See breakpoint.h.  */
 
-#define ALL_TRACEPOINTS(B)  \
-  for (B = breakpoint_chain; B; B = B->next)  \
-    if (is_tracepoint (B))
+breakpoint_safe_range
+all_breakpoints_safe ()
+{
+  return breakpoint_safe_range (all_breakpoints ());
+}
 
-/* Chains of all breakpoints defined.  */
+/* See breakpoint.h.  */
 
-static struct breakpoint *breakpoint_chain;
+tracepoint_range
+all_tracepoints ()
+{
+  return tracepoint_range (breakpoint_chain);
+}
 
 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS.  */
 
-static struct bp_location **bp_locations;
+static std::vector<bp_location *> bp_locations;
+
+/* See breakpoint.h.  */
+
+const std::vector<bp_location *> &
+all_bp_locations ()
+{
+  return bp_locations;
+}
+
+/* Range to iterate over breakpoint locations at a given address.  */
+
+struct bp_locations_at_addr_range
+{
+  using iterator = std::vector<bp_location *>::iterator;
+
+  bp_locations_at_addr_range (CORE_ADDR addr)
+  {
+    struct compare
+    {
+      bool operator() (const bp_location *loc, CORE_ADDR addr_) const
+      { return loc->address < addr_; }
+
+      bool operator() (CORE_ADDR addr_, const bp_location *loc) const
+      { return addr_ < loc->address; }
+    };
+
+    auto it_pair = std::equal_range (bp_locations.begin (), bp_locations.end (),
+                                    addr, compare ());
+
+    m_begin = it_pair.first;
+    m_end = it_pair.second;
+  }
+
+  iterator begin () const
+  { return m_begin; }
+
+  iterator end () const
+  { return m_end; }
+
+private:
+  iterator m_begin;
+  iterator m_end;
+};
+
+/* Return a range to iterate over all breakpoint locations exactly at address
+   ADDR.
+
+   If it's needed to iterate multiple times on the same range, it's possible
+   to save the range in a local variable and use it multiple times:
+
+     auto range = all_bp_locations_at_addr (addr);
+
+     for (bp_location *loc : range)
+       // use loc
 
-/* Number of elements of BP_LOCATIONS.  */
+     for (bp_location *loc : range)
+       // use loc
 
-static unsigned bp_locations_count;
+   This saves a bit of time, as it avoids re-doing the binary searches to find
+   the range's boundaries.  Just remember not to change the bp_locations vector
+   in the mean time, as it could make the range's iterators stale.  */
+
+static bp_locations_at_addr_range
+all_bp_locations_at_addr (CORE_ADDR addr)
+{
+  return bp_locations_at_addr_range (addr);
+}
 
 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
    ADDRESS for the current elements of BP_LOCATIONS which get a valid
@@ -577,15 +634,11 @@ struct breakpoint *
 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
                    void *user_data)
 {
-  struct breakpoint *b = NULL;
-
-  ALL_BREAKPOINTS (b)
-    {
-      if (func (b, user_data) != 0)
-       break;
-    }
+  for (breakpoint *b : all_breakpoints ())
+    if (func (b, user_data) != 0)
+      return b;
 
-  return b;
+  return nullptr;
 }
 
 /* Return whether a breakpoint is an active enabled breakpoint.  */
@@ -630,9 +683,7 @@ scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
 void
 clear_breakpoint_hit_counts (void)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     b->hit_count = 0;
 }
 
@@ -643,13 +694,11 @@ clear_breakpoint_hit_counts (void)
 struct breakpoint *
 get_breakpoint (int num)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->number == num)
       return b;
   
-  return NULL;
+  return nullptr;
 }
 
 \f
@@ -660,8 +709,6 @@ get_breakpoint (int num)
 static void
 mark_breakpoint_modified (struct breakpoint *b)
 {
-  struct bp_location *loc;
-
   /* This is only meaningful if the target is
      evaluating conditions and if the user has
      opted for condition evaluation on the target's
@@ -673,7 +720,7 @@ mark_breakpoint_modified (struct breakpoint *b)
   if (!is_breakpoint (b))
     return;
 
-  for (loc = b->loc; loc; loc = loc->next)
+  for (bp_location *loc : b->locations ())
     loc->condition_changed = condition_modified;
 }
 
@@ -726,7 +773,6 @@ set_condition_evaluation_mode (const char *args, int from_tty,
   /* Only update the mode if the user picked a different one.  */
   if (new_mode != old_mode)
     {
-      struct bp_location *loc, **loc_tmp;
       /* If the user switched to a different evaluation mode, we
         need to synch the changes with the target as follows:
 
@@ -738,15 +784,15 @@ set_condition_evaluation_mode (const char *args, int from_tty,
        {
          /* Mark everything modified and synch conditions with the
             target.  */
-         ALL_BP_LOCATIONS (loc, loc_tmp)
+         for (bp_location *loc : all_bp_locations ())
            mark_breakpoint_location_modified (loc);
-       }
+       }
       else
        {
          /* Manually mark non-duplicate locations to synch conditions
             with the target.  We do this to remove all the conditions the
             target knows about.  */
-         ALL_BP_LOCATIONS (loc, loc_tmp)
+         for (bp_location *loc : all_bp_locations ())
            if (is_breakpoint (loc->owner) && loc->inserted)
              loc->needs_update = 1;
        }
@@ -776,156 +822,252 @@ show_condition_evaluation_mode (struct ui_file *file, int from_tty,
                      value);
 }
 
-/* A comparison function for bp_location AP and BP that is used by
-   bsearch.  This comparison function only cares about addresses, unlike
-   the more general bp_location_is_less_than function.  */
-
-static int
-bp_locations_compare_addrs (const void *ap, const void *bp)
-{
-  const struct bp_location *a = *(const struct bp_location **) ap;
-  const struct bp_location *b = *(const struct bp_location **) bp;
-
-  if (a->address == b->address)
-    return 0;
-  else
-    return ((a->address > b->address) - (a->address < b->address));
-}
-
-/* Helper function to skip all bp_locations with addresses
-   less than ADDRESS.  It returns the first bp_location that
-   is greater than or equal to ADDRESS.  If none is found, just
-   return NULL.  */
+/* Parse COND_STRING in the context of LOC and set as the condition
+   expression of LOC.  BP_NUM is the number of LOC's owner, LOC_NUM is
+   the number of LOC within its owner.  In case of parsing error, mark
+   LOC as DISABLED_BY_COND.  In case of success, unset DISABLED_BY_COND.  */
 
-static struct bp_location **
-get_first_locp_gte_addr (CORE_ADDR address)
+static void
+set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
+                                  int bp_num, int loc_num)
 {
-  struct bp_location dummy_loc;
-  struct bp_location *dummy_locp = &dummy_loc;
-  struct bp_location **locp_found = NULL;
-
-  /* Initialize the dummy location's address field.  */
-  dummy_loc.address = address;
-
-  /* Find a close match to the first location at ADDRESS.  */
-  locp_found = ((struct bp_location **)
-               bsearch (&dummy_locp, bp_locations, bp_locations_count,
-                        sizeof (struct bp_location **),
-                        bp_locations_compare_addrs));
+  bool has_junk = false;
+  try
+    {
+      expression_up new_exp = parse_exp_1 (&cond_string, loc->address,
+                                          block_for_pc (loc->address), 0);
+      if (*cond_string != 0)
+       has_junk = true;
+      else
+       {
+         loc->cond = std::move (new_exp);
+         if (loc->disabled_by_cond && loc->enabled)
+           printf_filtered (_("Breakpoint %d's condition is now valid at "
+                              "location %d, enabling.\n"),
+                            bp_num, loc_num);
 
-  /* Nothing was found, nothing left to do.  */
-  if (locp_found == NULL)
-    return NULL;
+         loc->disabled_by_cond = false;
+       }
+    }
+  catch (const gdb_exception_error &e)
+    {
+      if (loc->enabled)
+       {
+         /* Warn if a user-enabled location is now becoming disabled-by-cond.
+            BP_NUM is 0 if the breakpoint is being defined for the first
+            time using the "break ... if ..." command, and non-zero if
+            already defined.  */
+         if (bp_num != 0)
+           warning (_("failed to validate condition at location %d.%d, "
+                      "disabling:\n  %s"), bp_num, loc_num, e.what ());
+         else
+           warning (_("failed to validate condition at location %d, "
+                      "disabling:\n  %s"), loc_num, e.what ());
+       }
 
-  /* We may have found a location that is at ADDRESS but is not the first in the
-     location's list.  Go backwards (if possible) and locate the first one.  */
-  while ((locp_found - 1) >= bp_locations
-        && (*(locp_found - 1))->address == address)
-    locp_found--;
+      loc->disabled_by_cond = true;
+    }
 
-  return locp_found;
+  if (has_junk)
+    error (_("Garbage '%s' follows condition"), cond_string);
 }
 
 void
 set_breakpoint_condition (struct breakpoint *b, const char *exp,
-                         int from_tty)
+                         int from_tty, bool force)
 {
-  xfree (b->cond_string);
-  b->cond_string = NULL;
-
-  if (is_watchpoint (b))
-    {
-      struct watchpoint *w = (struct watchpoint *) b;
-
-      w->cond_exp.reset ();
-    }
-  else
+  if (*exp == 0)
     {
-      struct bp_location *loc;
+      xfree (b->cond_string);
+      b->cond_string = nullptr;
 
-      for (loc = b->loc; loc; loc = loc->next)
+      if (is_watchpoint (b))
+       static_cast<watchpoint *> (b)->cond_exp.reset ();
+      else
        {
-         loc->cond.reset ();
-
-         /* No need to free the condition agent expression
-            bytecode (if we have one).  We will handle this
-            when we go through update_global_location_list.  */
+         int loc_num = 1;
+         for (bp_location *loc : b->locations ())
+           {
+             loc->cond.reset ();
+             if (loc->disabled_by_cond && loc->enabled)
+               printf_filtered (_("Breakpoint %d's condition is now valid at "
+                                  "location %d, enabling.\n"),
+                                b->number, loc_num);
+             loc->disabled_by_cond = false;
+             loc_num++;
+
+             /* No need to free the condition agent expression
+                bytecode (if we have one).  We will handle this
+                when we go through update_global_location_list.  */
+           }
        }
-    }
 
-  if (*exp == 0)
-    {
       if (from_tty)
        printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
     }
   else
     {
-      const 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))
        {
-         struct watchpoint *w = (struct watchpoint *) b;
-
          innermost_block_tracker tracker;
-         arg = exp;
-         w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
-         if (*arg)
+         const char *arg = exp;
+         expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
+         if (*arg != 0)
            error (_("Junk at end of expression"));
+         watchpoint *w = static_cast<watchpoint *> (b);
+         w->cond_exp = std::move (new_exp);
          w->cond_exp_valid_block = tracker.block ();
        }
       else
        {
-         struct bp_location *loc;
+         /* Parse and set condition expressions.  We make two passes.
+            In the first, we parse the condition string to see if it
+            is valid in at least one location.  If so, the condition
+            would be accepted.  So we go ahead and set the locations'
+            conditions.  In case no valid case is found, we throw
+            the error and the condition string will be rejected.
+            This two-pass approach is taken to avoid setting the
+            state of locations in case of a reject.  */
+         for (bp_location *loc : b->locations ())
+           {
+             try
+               {
+                 const char *arg = exp;
+                 parse_exp_1 (&arg, loc->address,
+                              block_for_pc (loc->address), 0);
+                 if (*arg != 0)
+                   error (_("Junk at end of expression"));
+                 break;
+               }
+             catch (const gdb_exception_error &e)
+               {
+                 /* Condition string is invalid.  If this happens to
+                    be the last loc, abandon (if not forced) or continue
+                    (if forced).  */
+                 if (loc->next == nullptr && !force)
+                   throw;
+               }
+           }
 
-         for (loc = b->loc; loc; loc = loc->next)
+         /* If we reach here, the condition is valid at some locations.  */
+         int loc_num = 1;
+         for (bp_location *loc : b->locations ())
            {
-             arg = exp;
-             loc->cond =
-               parse_exp_1 (&arg, loc->address,
-                            block_for_pc (loc->address), 0);
-             if (*arg)
-               error (_("Junk at end of expression"));
+             set_breakpoint_location_condition (exp, loc, b->number, loc_num);
+             loc_num++;
            }
        }
+
+      /* We know that the new condition parsed successfully.  The
+        condition string of the breakpoint can be safely updated.  */
+      xfree (b->cond_string);
+      b->cond_string = xstrdup (exp);
+      b->condition_not_parsed = 0;
     }
   mark_breakpoint_modified (b);
 
   gdb::observers::breakpoint_modified.notify (b);
 }
 
+/* See breakpoint.h.  */
+
+void
+set_breakpoint_condition (int bpnum, const char *exp, int from_tty,
+                         bool force)
+{
+  for (breakpoint *b : all_breakpoints ())
+    if (b->number == bpnum)
+      {
+       /* Check if this breakpoint has a "stop" method implemented in an
+          extension language.  This method and conditions entered into GDB
+          from the CLI are mutually exclusive.  */
+       const struct extension_language_defn *extlang
+         = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
+
+       if (extlang != NULL)
+         {
+           error (_("Only one stop condition allowed.  There is currently"
+                    " a %s stop condition defined for this breakpoint."),
+                  ext_lang_capitalized_name (extlang));
+         }
+       set_breakpoint_condition (b, exp, from_tty, force);
+
+       if (is_breakpoint (b))
+         update_global_location_list (UGLL_MAY_INSERT);
+
+       return;
+      }
+
+  error (_("No breakpoint number %d."), bpnum);
+}
+
+/* The options for the "condition" command.  */
+
+struct condition_command_opts
+{
+  /* For "-force".  */
+  bool force_condition = false;
+};
+
+static const gdb::option::option_def condition_command_option_defs[] = {
+
+  gdb::option::flag_option_def<condition_command_opts> {
+    "force",
+    [] (condition_command_opts *opts) { return &opts->force_condition; },
+    N_("Set the condition even if it is invalid for all current locations."),
+  },
+
+};
+
+/* Create an option_def_group for the "condition" options, with
+   CC_OPTS as context.  */
+
+static inline gdb::option::option_def_group
+make_condition_command_options_def_group (condition_command_opts *cc_opts)
+{
+  return {{condition_command_option_defs}, cc_opts};
+}
+
 /* Completion for the "condition" command.  */
 
 static void
 condition_completer (struct cmd_list_element *cmd,
                     completion_tracker &tracker,
-                    const char *text, const char *word)
+                    const char *text, const char * /*word*/)
 {
-  const char *space;
+  bool has_no_arguments = (*text == '\0');
+  condition_command_opts cc_opts;
+  const auto group = make_condition_command_options_def_group (&cc_opts);
+  if (gdb::option::complete_options
+      (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
+    return;
 
   text = skip_spaces (text);
-  space = skip_to_space (text);
+  const char *space = skip_to_space (text);
   if (*space == '\0')
     {
       int len;
-      struct breakpoint *b;
 
       if (text[0] == '$')
        {
+         tracker.advance_custom_word_point_by (1);
          /* We don't support completion of history indices.  */
          if (!isdigit (text[1]))
            complete_internalvar (tracker, &text[1]);
          return;
        }
 
+      /* Suggest the "-force" flag if no arguments are given.  If
+        arguments were passed, they either already include the flag,
+        or we are beyond the point of suggesting it because it's
+        positionally the first argument.  */
+      if (has_no_arguments)
+       gdb::option::complete_on_all_options (tracker, group);
+
       /* We're completing the breakpoint number.  */
       len = strlen (text);
 
-      ALL_BREAKPOINTS (b)
+      for (breakpoint *b : all_breakpoints ())
        {
          char number[50];
 
@@ -938,8 +1080,11 @@ condition_completer (struct cmd_list_element *cmd,
       return;
     }
 
-  /* We're completing the expression part.  */
-  text = skip_spaces (space);
+  /* We're completing the expression part.  Skip the breakpoint num.  */
+  const char *exp_start = skip_spaces (space);
+  tracker.advance_custom_word_point_by (exp_start - text);
+  text = exp_start;
+  const char *word = advance_to_expression_complete_word_point (tracker, text);
   expression_completer (cmd, tracker, text, word);
 }
 
@@ -948,7 +1093,6 @@ condition_completer (struct cmd_list_element *cmd,
 static void
 condition_command (const char *arg, int from_tty)
 {
-  struct breakpoint *b;
   const char *p;
   int bnum;
 
@@ -956,34 +1100,18 @@ condition_command (const char *arg, int from_tty)
     error_no_arg (_("breakpoint number"));
 
   p = arg;
+
+  /* Check if the "-force" flag was passed.  */
+  condition_command_opts cc_opts;
+  const auto group = make_condition_command_options_def_group (&cc_opts);
+  gdb::option::process_options
+    (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group);
+
   bnum = get_number (&p);
   if (bnum == 0)
     error (_("Bad breakpoint argument: '%s'"), arg);
 
-  ALL_BREAKPOINTS (b)
-    if (b->number == bnum)
-      {
-       /* Check if this breakpoint has a "stop" method implemented in an
-          extension language.  This method and conditions entered into GDB
-          from the CLI are mutually exclusive.  */
-       const struct extension_language_defn *extlang
-         = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
-
-       if (extlang != NULL)
-         {
-           error (_("Only one stop condition allowed.  There is currently"
-                    " a %s stop condition defined for this breakpoint."),
-                  ext_lang_capitalized_name (extlang));
-         }
-       set_breakpoint_condition (b, p, from_tty);
-
-       if (is_breakpoint (b))
-         update_global_location_list (UGLL_MAY_INSERT);
-
-       return;
-      }
-
-  error (_("No breakpoint number %d."), bnum);
+  set_breakpoint_condition (bnum, p, from_tty, cc_opts.force_condition);
 }
 
 /* Check that COMMAND do not contain commands that are suitable
@@ -1077,8 +1205,8 @@ validate_commands_for_breakpoint (struct breakpoint *b,
       struct command_line *while_stepping = 0;
 
       /* Reset the while-stepping step count.  The previous commands
-         might have included a while-stepping action, while the new
-         ones might not.  */
+        might have included a while-stepping action, while the new
+        ones might not.  */
       t->step_count = 0;
 
       /* We need to verify that each top-level element of commands is
@@ -1136,14 +1264,12 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 std::vector<breakpoint *>
 static_tracepoints_here (CORE_ADDR addr)
 {
-  struct breakpoint *b;
   std::vector<breakpoint *> found;
-  struct bp_location *loc;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->type == bp_static_tracepoint)
       {
-       for (loc = b->loc; loc; loc = loc->next)
+       for (bp_location *loc : b->locations ())
          if (loc->address == addr)
            found.push_back (b);
       }
@@ -1218,13 +1344,23 @@ commands_command_1 (const char *arg, int from_tty,
 
   if (arg == NULL || !*arg)
     {
+      /* Argument not explicitly given.  Synthesize it.  */
       if (breakpoint_count - prev_breakpoint_count > 1)
        new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
                                 breakpoint_count);
       else if (breakpoint_count > 0)
        new_arg = string_printf ("%d", breakpoint_count);
-      arg = new_arg.c_str ();
     }
+  else
+    {
+      /* Create a copy of ARG.  This is needed because the "commands"
+        command may be coming from a script.  In that case, the read
+        line buffer is going to be overwritten in the lambda of
+        'map_breakpoint_numbers' below when reading the next line
+        before we are are done parsing the breakpoint numbers.  */
+      new_arg = arg;
+    }
+  arg = new_arg.c_str ();
 
   map_breakpoint_numbers
     (arg, [&] (breakpoint *b)
@@ -1424,7 +1560,7 @@ breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
      report higher one.  */
 
   bc_l = 0;
-  bc_r = bp_locations_count;
+  bc_r = bp_locations.size ();
   while (bc_l + 1 < bc_r)
     {
       struct bp_location *bl;
@@ -1469,29 +1605,30 @@ breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
 
   /* Now do full processing of the found relevant range of elements.  */
 
-  for (bc = bc_l; bc < bp_locations_count; bc++)
-  {
-    struct bp_location *bl = bp_locations[bc];
+  for (bc = bc_l; bc < bp_locations.size (); bc++)
+    {
+      struct bp_location *bl = bp_locations[bc];
 
-    /* bp_location array has BL->OWNER always non-NULL.  */
-    if (bl->owner->type == bp_none)
-      warning (_("reading through apparently deleted breakpoint #%d?"),
-              bl->owner->number);
+      /* bp_location array has BL->OWNER always non-NULL.  */
+      if (bl->owner->type == bp_none)
+       warning (_("reading through apparently deleted breakpoint #%d?"),
+                bl->owner->number);
 
-    /* Performance optimization: any further element can no longer affect BUF
-       content.  */
+      /* Performance optimization: any further element can no longer affect BUF
+        content.  */
 
-    if (bl->address >= bp_locations_placed_address_before_address_max
-       && memaddr + len <= (bl->address
-                            - bp_locations_placed_address_before_address_max))
-      break;
+      if (bl->address >= bp_locations_placed_address_before_address_max
+         && (memaddr + len
+             <= (bl->address
+                 - bp_locations_placed_address_before_address_max)))
+       break;
 
-    if (!bp_location_has_shadow (bl))
-      continue;
+      if (!bp_location_has_shadow (bl))
+       continue;
 
-    one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
-                               memaddr, len, &bl->target_info, bl->gdbarch);
-  }
+      one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
+                                 memaddr, len, &bl->target_info, bl->gdbarch);
+    }
 }
 
 /* See breakpoint.h.  */
@@ -1698,10 +1835,10 @@ update_watchpoint (struct watchpoint *b, int reparse)
        return;
 
       /* Save the current frame's ID so we can restore it after
-         evaluating the watchpoint expression on its own frame.  */
+        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.  */
+        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));
 
@@ -1747,7 +1884,7 @@ update_watchpoint (struct watchpoint *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 (!target_has_execution)
+  if (!target_has_execution ())
     {
       /* Without execution, memory can't change.  No use to try and
         set watchpoint locations.  The watchpoint will be reset when
@@ -1763,12 +1900,12 @@ update_watchpoint (struct watchpoint *b, int reparse)
     }
   else if (within_current_scope && b->exp)
     {
-      int pc = 0;
       std::vector<value_ref_ptr> val_chain;
       struct value *v, *result;
       struct program_space *frame_pspace;
 
-      fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
+      fetch_subexp_value (b->exp.get (), b->exp->op.get (), &v, &result,
+                         &val_chain, false);
 
       /* Avoid setting b->val if it's already set.  The meaning of
         b->val is 'the last value' user saw, and we should update
@@ -1806,8 +1943,8 @@ update_watchpoint (struct watchpoint *b, int reparse)
                 for it explicitly, never if they just happen to
                 appear in the middle of some value chain.  */
              if (v == result
-                 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
-                     && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
+                 || (vtype->code () != TYPE_CODE_STRUCT
+                     && vtype->code () != TYPE_CODE_ARRAY))
                {
                  CORE_ADDR addr;
                  enum target_hw_bp_type type;
@@ -1847,7 +1984,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
                  for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
                    ;
                  *tmp = loc;
-                 loc->gdbarch = get_type_arch (value_type (v));
+                 loc->gdbarch = value_type (v)->arch ();
 
                  loc->pspace = frame_pspace;
                  loc->address = address_significant (loc->gdbarch, addr);
@@ -1873,7 +2010,6 @@ update_watchpoint (struct watchpoint *b, int reparse)
        {
          int reg_cnt;
          enum bp_loc_type loc_type;
-         struct bp_location *bl;
 
          reg_cnt = can_use_hardware_watchpoint (val_chain);
 
@@ -1949,7 +2085,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 
          loc_type = (b->type == bp_watchpoint? bp_loc_other
                      : bp_loc_hardware_watchpoint);
-         for (bl = b->loc; bl; bl = bl->next)
+         for (bp_location *bl : b->locations ())
            bl->loc_type = loc_type;
        }
 
@@ -1989,7 +2125,8 @@ should_be_inserted (struct bp_location *bl)
   if (bl->owner->disposition == disp_del_at_next_stop)
     return 0;
 
-  if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
+  if (!bl->enabled || bl->disabled_by_cond
+      || bl->shlib_disabled || bl->duplicate)
     return 0;
 
   if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
@@ -2024,13 +2161,8 @@ should_be_inserted (struct bp_location *bl)
       && !(bl->owner->type == bp_single_step
           && thread_is_stepping_over_breakpoint (bl->owner->thread)))
     {
-      if (debug_infrun)
-       {
-         fprintf_unfiltered (gdb_stdlog,
-                             "infrun: skipping breakpoint: "
-                             "stepping past insn at: %s\n",
-                             paddress (bl->gdbarch, bl->address));
-       }
+      infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
+                          paddress (bl->gdbarch, bl->address));
       return 0;
     }
 
@@ -2039,14 +2171,9 @@ should_be_inserted (struct bp_location *bl)
   if ((bl->loc_type == bp_loc_hardware_watchpoint)
       && stepping_past_nonsteppable_watchpoint ())
     {
-      if (debug_infrun)
-       {
-         fprintf_unfiltered (gdb_stdlog,
-                             "infrun: stepping past non-steppable watchpoint. "
-                             "skipping watchpoint at %s:%d\n",
-                             paddress (bl->gdbarch, bl->address),
-                             bl->length);
-       }
+      infrun_debug_printf ("stepping past non-steppable watchpoint. "
+                          "skipping watchpoint at %s:%d",
+                          paddress (bl->gdbarch, bl->address), bl->length);
       return 0;
     }
 
@@ -2108,10 +2235,8 @@ parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
 static void
 build_target_condition_list (struct bp_location *bl)
 {
-  struct bp_location **locp = NULL, **loc2p;
   int null_condition_or_parse_error = 0;
   int modified = bl->needs_update;
-  struct bp_location *loc;
 
   /* Release conditions left over from a previous insert.  */
   bl->target_info.conditions.clear ();
@@ -2124,14 +2249,19 @@ build_target_condition_list (struct bp_location *bl)
       || !target_supports_evaluation_of_breakpoint_conditions ())
     return;
 
+  auto loc_range = all_bp_locations_at_addr (bl->address);
+
   /* Do a first pass to check for locations with no assigned
-     conditions or conditions that fail to parse to a valid agent expression
-     bytecode.  If any of these happen, then it's no use to send conditions
-     to the target since this location will always trigger and generate a
-     response back to GDB.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
+     conditions or conditions that fail to parse to a valid agent
+     expression bytecode.  If any of these happen, then it's no use to
+     send conditions to the target since this location will always
+     trigger and generate a response back to GDB.  Note we consider
+     all locations at the same address irrespective of type, i.e.,
+     even if the locations aren't considered duplicates (e.g.,
+     software breakpoint and hardware breakpoint at the same
+     address).  */
+  for (bp_location *loc : loc_range)
     {
-      loc = (*loc2p);
       if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
        {
          if (modified)
@@ -2162,9 +2292,8 @@ build_target_condition_list (struct bp_location *bl)
      being evaluated by GDB or the remote stub.  */
   if (null_condition_or_parse_error)
     {
-      ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
+      for (bp_location *loc : loc_range)
        {
-         loc = (*loc2p);
          if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
            {
              /* Only go as far as the first NULL bytecode is
@@ -2177,22 +2306,24 @@ build_target_condition_list (struct bp_location *bl)
        }
     }
 
-  /* No NULL conditions or failed bytecode generation.  Build a condition list
-     for this location's address.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
-    {
-      loc = (*loc2p);
-      if (loc->cond
-         && is_breakpoint (loc->owner)
-         && loc->pspace->num == bl->pspace->num
-         && loc->owner->enable_state == bp_enabled
-         && loc->enabled)
-       {
-         /* Add the condition to the vector.  This will be used later
-            to send the conditions to the target.  */
-         bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
-       }
-    }
+  /* No NULL conditions or failed bytecode generation.  Build a
+     condition list for this location's address.  If we have software
+     and hardware locations at the same address, they aren't
+     considered duplicates, but we still marge all the conditions
+     anyway, as it's simpler, and doesn't really make a practical
+     difference.  */
+  for (bp_location *loc : loc_range)
+    if (loc->cond
+       && is_breakpoint (loc->owner)
+       && loc->pspace->num == bl->pspace->num
+       && loc->owner->enable_state == bp_enabled
+       && loc->enabled
+       && !loc->disabled_by_cond)
+      {
+       /* Add the condition to the vector.  This will be used later
+          to send the conditions to the target.  */
+       bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
+      }
 
   return;
 }
@@ -2281,10 +2412,8 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
 static void
 build_target_command_list (struct bp_location *bl)
 {
-  struct bp_location **locp = NULL, **loc2p;
   int null_command_or_parse_error = 0;
   int modified = bl->needs_update;
-  struct bp_location *loc;
 
   /* Clear commands left over from a previous insert.  */
   bl->target_info.tcommands.clear ();
@@ -2296,27 +2425,25 @@ build_target_command_list (struct bp_location *bl)
   if (dprintf_style != dprintf_style_agent)
     return;
 
-  /* For now, if we have any duplicate location that isn't a dprintf,
-     don't install the target-side commands, as that would make the
-     breakpoint not be reported to the core, and we'd lose
+  auto loc_range = all_bp_locations_at_addr (bl->address);
+
+  /* For now, if we have any location at the same address that isn't a
+     dprintf, don't install the target-side commands, as that would
+     make the breakpoint not be reported to the core, and we'd lose
      control.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
-    {
-      loc = (*loc2p);
-      if (is_breakpoint (loc->owner)
-         && loc->pspace->num == bl->pspace->num
-         && loc->owner->type != bp_dprintf)
-       return;
-    }
+  for (bp_location *loc : loc_range)
+    if (is_breakpoint (loc->owner)
+       && loc->pspace->num == bl->pspace->num
+       && loc->owner->type != bp_dprintf)
+      return;
 
   /* Do a first pass to check for locations with no assigned
      conditions or conditions that fail to parse to a valid agent expression
      bytecode.  If any of these happen, then it's no use to send conditions
      to the target since this location will always trigger and generate a
      response back to GDB.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
+  for (bp_location *loc : loc_range)
     {
-      loc = (*loc2p);
       if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
        {
          if (modified)
@@ -2344,38 +2471,40 @@ build_target_command_list (struct bp_location *bl)
      and so clean up.  */
   if (null_command_or_parse_error)
     {
-      ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
-       {
-         loc = (*loc2p);
-         if (is_breakpoint (loc->owner)
-             && loc->pspace->num == bl->pspace->num)
-           {
-             /* Only go as far as the first NULL bytecode is
-                located.  */
-             if (loc->cmd_bytecode == NULL)
-               return;
+      for (bp_location *loc : loc_range)
+       if (is_breakpoint (loc->owner)
+           && loc->pspace->num == bl->pspace->num)
+         {
+           /* Only go as far as the first NULL bytecode is
+              located.  */
+           if (loc->cmd_bytecode == NULL)
+             return;
 
-             loc->cmd_bytecode.reset ();
-           }
-       }
+           loc->cmd_bytecode.reset ();
+         }
     }
 
-  /* No NULL commands or failed bytecode generation.  Build a command list
-     for this location's address.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
-    {
-      loc = (*loc2p);
-      if (loc->owner->extra_string
-         && is_breakpoint (loc->owner)
-         && loc->pspace->num == bl->pspace->num
-         && loc->owner->enable_state == bp_enabled
-         && loc->enabled)
-       {
-         /* Add the command to the vector.  This will be used later
-            to send the commands to the target.  */
-         bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
-       }
-    }
+  /* No NULL commands or failed bytecode generation.  Build a command
+     list for all duplicate locations at this location's address.
+     Note that here we must care for whether the breakpoint location
+     types are considered duplicates, otherwise, say, if we have a
+     software and hardware location at the same address, the target
+     could end up running the commands twice.  For the moment, we only
+     support targets-side commands with dprintf, but it doesn't hurt
+     to be pedantically correct in case that changes.  */
+  for (bp_location *loc : loc_range)
+    if (breakpoint_locations_match (bl, loc)
+       && loc->owner->extra_string
+       && is_breakpoint (loc->owner)
+       && loc->pspace->num == bl->pspace->num
+       && loc->owner->enable_state == bp_enabled
+       && loc->enabled
+       && !loc->disabled_by_cond)
+      {
+       /* Add the command to the vector.  This will be used later
+          to send the commands to the target.  */
+       bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
+      }
 
   bl->target_info.persist = 0;
   /* Maybe flag this location as persistent.  */
@@ -2451,72 +2580,31 @@ insert_bp_location (struct bp_location *bl,
       bl->needs_update = 0;
     }
 
+  /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
+     set at a read-only address, then a breakpoint location will have
+     been changed to hardware breakpoint before we get here.  If it is
+     "off" however, error out before actually trying to insert the
+     breakpoint, with a nicer error message.  */
   if (bl->loc_type == bp_loc_software_breakpoint
-      || bl->loc_type == bp_loc_hardware_breakpoint)
+      && !automatic_hardware_breakpoints)
     {
-      if (bl->owner->type != bp_hardware_breakpoint)
-       {
-         /* If the explicitly specified breakpoint type
-            is not hardware breakpoint, check the memory map to see
-            if the breakpoint address is in read only memory or not.
-
-            Two important cases are:
-            - location type is not hardware breakpoint, memory
-            is readonly.  We change the type of the location to
-            hardware breakpoint.
-            - location type is hardware breakpoint, memory is
-            read-write.  This means we've previously made the
-            location hardware one, but then the memory map changed,
-            so we undo.
-            
-            When breakpoints are removed, remove_breakpoints will use
-            location types we've just set here, the only possible
-            problem is that memory map has changed during running
-            program, but it's not going to work anyway with current
-            gdb.  */
-         struct mem_region *mr 
-           = lookup_mem_region (bl->target_info.reqstd_address);
-         
-         if (mr)
-           {
-             if (automatic_hardware_breakpoints)
-               {
-                 enum bp_loc_type new_type;
-                 
-                 if (mr->attrib.mode != MEM_RW)
-                   new_type = bp_loc_hardware_breakpoint;
-                 else 
-                   new_type = bp_loc_software_breakpoint;
-                 
-                 if (new_type != bl->loc_type)
-                   {
-                     static int said = 0;
+      mem_region *mr = lookup_mem_region (bl->address);
 
-                     bl->loc_type = new_type;
-                     if (!said)
-                       {
-                         fprintf_filtered (gdb_stdout,
-                                           _("Note: automatically using "
-                                             "hardware breakpoints for "
-                                             "read-only addresses.\n"));
-                         said = 1;
-                       }
-                   }
-               }
-             else if (bl->loc_type == bp_loc_software_breakpoint
-                      && mr->attrib.mode != MEM_RW)
-               {
-                 fprintf_unfiltered (tmp_error_stream,
-                                     _("Cannot insert breakpoint %d.\n"
-                                       "Cannot set software breakpoint "
-                                       "at read-only address %s\n"),
-                                     bl->owner->number,
-                                     paddress (bl->gdbarch, bl->address));
-                 return 1;
-               }
-           }
+      if (mr != nullptr && mr->attrib.mode != MEM_RW)
+       {
+         fprintf_unfiltered (tmp_error_stream,
+                             _("Cannot insert breakpoint %d.\n"
+                               "Cannot set software breakpoint "
+                               "at read-only address %s\n"),
+                             bl->owner->number,
+                             paddress (bl->gdbarch, bl->address));
+         return 1;
        }
-        
+    }
+
+  if (bl->loc_type == bp_loc_software_breakpoint
+      || bl->loc_type == bp_loc_hardware_breakpoint)
+    {
       /* First check to see if we have to handle an overlay.  */
       if (overlay_debugging == ovly_off
          || bl->section == NULL
@@ -2587,17 +2675,17 @@ insert_bp_location (struct bp_location *bl,
            {
              /* Yes.  This overlay section is mapped into memory.  */
              try
-               {
+               {
                  int val;
 
-                 val = bl->owner->ops->insert_location (bl);
+                 val = bl->owner->ops->insert_location (bl);
                  if (val)
                    bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
-               }
+               }
              catch (gdb_exception &e)
-               {
+               {
                  bp_excpt = std::move (e);
-               }
+               }
            }
          else
            {
@@ -2611,6 +2699,14 @@ insert_bp_location (struct bp_location *bl,
        {
          /* Can't set the breakpoint.  */
 
+         /* If the target has closed then it will have deleted any
+            breakpoints inserted within the target inferior, as a result
+            any further attempts to interact with the breakpoint objects
+            is not possible.  Just rethrow the error.  */
+         if (bp_excpt.error == TARGET_CLOSE_ERROR)
+           throw bp_excpt;
+         gdb_assert (bl->owner != nullptr);
+
          /* In some cases, we might not be able to insert a
             breakpoint in a shared library that has already been
             removed, but we have not yet processed the shlib unload
@@ -2650,12 +2746,12 @@ insert_bp_location (struct bp_location *bl,
                {
                  *hw_breakpoint_error = 1;
                  *hw_bp_error_explained_already = bp_excpt.message != NULL;
-                  fprintf_unfiltered (tmp_error_stream,
-                                      "Cannot insert hardware breakpoint %d%s",
-                                      bl->owner->number,
+                 fprintf_unfiltered (tmp_error_stream,
+                                     "Cannot insert hardware breakpoint %d%s",
+                                     bl->owner->number,
                                      bp_excpt.message ? ":" : ".\n");
-                  if (bp_excpt.message != NULL)
-                    fprintf_unfiltered (tmp_error_stream, "%s.\n",
+                 if (bp_excpt.message != NULL)
+                   fprintf_unfiltered (tmp_error_stream, "%s.\n",
                                        bp_excpt.what ());
                }
              else
@@ -2705,12 +2801,10 @@ insert_bp_location (struct bp_location *bl,
         supported, try emulating one with an access watchpoint.  */
       if (val == 1 && bl->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)
+         for (bp_location *loc : all_bp_locations ())
            if (loc != bl
                && loc->watchpoint_type == hw_access
                && watchpoint_locations_match (bl, loc))
@@ -2775,19 +2869,14 @@ of catchpoint."), bl->owner->number);
 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);
-    }
+  for (breakpoint *b : all_breakpoints_safe ())
+    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)
+  for (bp_location *loc : all_bp_locations ())
     {
       struct bp_location *tmp;
 
@@ -2818,9 +2907,7 @@ breakpoint_program_space_exit (struct program_space *pspace)
 void
 insert_breakpoints (void)
 {
-  struct breakpoint *bpt;
-
-  ALL_BREAKPOINTS (bpt)
+  for (breakpoint *bpt : all_breakpoints ())
     if (is_hardware_watchpoint (bpt))
       {
        struct watchpoint *w = (struct watchpoint *) bpt;
@@ -2830,23 +2917,14 @@ insert_breakpoints (void)
 
   /* Updating watchpoints creates new locations, so update the global
      location list.  Explicitly tell ugll to insert locations and
-     ignore breakpoints_always_inserted_mode.  */
+     ignore breakpoints_always_inserted_mode.  Also,
+     update_global_location_list tries to "upgrade" software
+     breakpoints to hardware breakpoints to handle "set breakpoint
+     auto-hw", so we need to call it even if we don't have new
+     locations.  */
   update_global_location_list (UGLL_INSERT);
 }
 
-/* Invoke CALLBACK for each of bp_location.  */
-
-void
-iterate_over_bp_locations (walk_bp_location_callback callback)
-{
-  struct bp_location *loc, **loc_tmp;
-
-  ALL_BP_LOCATIONS (loc, loc_tmp)
-    {
-      callback (loc, NULL);
-    }
-}
-
 /* This is used when we need to synch breakpoint conditions between GDB and the
    target.  It is the case with deleting and disabling of breakpoints when using
    always-inserted mode.  */
@@ -2854,7 +2932,6 @@ iterate_over_bp_locations (walk_bp_location_callback callback)
 static void
 update_inserted_breakpoint_locations (void)
 {
-  struct bp_location *bl, **blp_tmp;
   int error_flag = 0;
   int val = 0;
   int disabled_breaks = 0;
@@ -2869,7 +2946,7 @@ update_inserted_breakpoint_locations (void)
 
   scoped_restore_current_pspace_and_thread restore_pspace_thread;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     {
       /* We only want to update software breakpoints and hardware
         breakpoints.  */
@@ -2889,7 +2966,7 @@ update_inserted_breakpoint_locations (void)
         if we aren't attached to any process yet, we should still
         insert breakpoints.  */
       if (!gdbarch_has_global_breakpoints (target_gdbarch ())
-         && (inferior_ptid == null_ptid || !target_has_execution))
+         && (inferior_ptid == null_ptid || !target_has_execution ()))
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -2910,8 +2987,6 @@ update_inserted_breakpoint_locations (void)
 static void
 insert_breakpoint_locations (void)
 {
-  struct breakpoint *bpt;
-  struct bp_location *bl, **blp_tmp;
   int error_flag = 0;
   int val = 0;
   int disabled_breaks = 0;
@@ -2926,7 +3001,7 @@ insert_breakpoint_locations (void)
 
   scoped_restore_current_pspace_and_thread restore_pspace_thread;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     {
       if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
        continue;
@@ -2945,7 +3020,7 @@ insert_breakpoint_locations (void)
         if we aren't attached to any process yet, we should still
         insert breakpoints.  */
       if (!gdbarch_has_global_breakpoints (target_gdbarch ())
-         && (inferior_ptid == null_ptid || !target_has_execution))
+         && (inferior_ptid == null_ptid || !target_has_execution ()))
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -2956,10 +3031,9 @@ insert_breakpoint_locations (void)
 
   /* If we failed to insert all locations of a watchpoint, remove
      them, as half-inserted watchpoint is of limited use.  */
-  ALL_BREAKPOINTS (bpt)  
+  for (breakpoint *bpt : all_breakpoints ())
     {
       int some_failed = 0;
-      struct bp_location *loc;
 
       if (!is_hardware_watchpoint (bpt))
        continue;
@@ -2970,15 +3044,16 @@ insert_breakpoint_locations (void)
       if (bpt->disposition == disp_del_at_next_stop)
        continue;
       
-      for (loc = bpt->loc; loc; loc = loc->next)
+      for (bp_location *loc : bpt->locations ())
        if (!loc->inserted && should_be_inserted (loc))
          {
            some_failed = 1;
            break;
          }
+
       if (some_failed)
        {
-         for (loc = bpt->loc; loc; loc = loc->next)
+         for (bp_location *loc : bpt->locations ())
            if (loc->inserted)
              remove_breakpoint (loc);
 
@@ -2993,7 +3068,7 @@ insert_breakpoint_locations (void)
   if (error_flag)
     {
       /* If a hardware breakpoint or watchpoint was inserted, add a
-         message about possibly exhausted resources.  */
+        message about possibly exhausted resources.  */
       if (hw_breakpoint_error && !hw_bp_error_explained_already)
        {
          tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
@@ -3011,14 +3086,12 @@ You may have requested too many hardware breakpoints/watchpoints.\n");
 int
 remove_breakpoints (void)
 {
-  struct bp_location *bl, **blp_tmp;
   int val = 0;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
-  {
+  for (bp_location *bl : all_bp_locations ())
     if (bl->inserted && !is_tracepoint (bl->owner))
       val |= remove_breakpoint (bl);
-  }
+
   return val;
 }
 
@@ -3028,9 +3101,7 @@ remove_breakpoints (void)
 static void
 remove_threaded_breakpoints (struct thread_info *tp, int silent)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     {
       if (b->thread == tp->global_num && user_breakpoint_p (b))
        {
@@ -3051,21 +3122,20 @@ Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\
 void
 remove_breakpoints_inf (inferior *inf)
 {
-  struct bp_location *bl, **blp_tmp;
   int val;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
-  {
-    if (bl->pspace != inf->pspace)
-      continue;
+  for (bp_location *bl : all_bp_locations ())
+    {
+      if (bl->pspace != inf->pspace)
+       continue;
 
-    if (bl->inserted && !bl->target_info.persist)
-      {
-       val = remove_breakpoint (bl);
-       if (val != 0)
-         return;
-      }
-  }
+      if (bl->inserted && !bl->target_info.persist)
+       {
+         val = remove_breakpoint (bl);
+         if (val != 0)
+           return;
+       }
+    }
 }
 
 static int internal_breakpoint_number = -1;
@@ -3201,264 +3271,329 @@ create_overlay_event_breakpoint (void)
        }
 
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
-      b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
-                                      bp_overlay_event,
+      b = create_internal_breakpoint (objfile->arch (), addr,
+                                     bp_overlay_event,
                                      &internal_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
       b->location = new_explicit_location (&explicit_loc);
 
       if (overlay_debugging == ovly_auto)
-        {
-          b->enable_state = bp_enabled;
-          overlay_events_enabled = 1;
-        }
+       {
+         b->enable_state = bp_enabled;
+         overlay_events_enabled = 1;
+       }
       else
        {
-         b->enable_state = bp_disabled;
-         overlay_events_enabled = 0;
+        b->enable_state = bp_disabled;
+        overlay_events_enabled = 0;
        }
     }
 }
 
-static void
-create_longjmp_master_breakpoint (void)
+/* Install a master longjmp breakpoint for OBJFILE using a probe.  Return
+   true if a breakpoint was installed.  */
+
+static bool
+create_longjmp_master_breakpoint_probe (objfile *objfile)
 {
-  struct program_space *pspace;
+  struct gdbarch *gdbarch = objfile->arch ();
+  struct breakpoint_objfile_data *bp_objfile_data
+    = get_breakpoint_objfile_data (objfile);
 
-  scoped_restore_current_program_space restore_pspace;
+  if (!bp_objfile_data->longjmp_searched)
+    {
+      std::vector<probe *> ret
+       = find_probes_in_objfile (objfile, "libc", "longjmp");
 
-  ALL_PSPACES (pspace)
-  {
-    set_current_program_space (pspace);
+      if (!ret.empty ())
+       {
+         /* We are only interested in checking one element.  */
+         probe *p = ret[0];
 
-    for (objfile *objfile : current_program_space->objfiles ())
-      {
-       int i;
-       struct gdbarch *gdbarch;
-       struct breakpoint_objfile_data *bp_objfile_data;
+         if (!p->can_evaluate_arguments ())
+           {
+             /* We cannot use the probe interface here,
+                because it does not know how to evaluate
+                arguments.  */
+             ret.clear ();
+           }
+       }
+      bp_objfile_data->longjmp_probes = ret;
+      bp_objfile_data->longjmp_searched = 1;
+    }
 
-       gdbarch = get_objfile_arch (objfile);
+  if (bp_objfile_data->longjmp_probes.empty ())
+    return false;
 
-       bp_objfile_data = get_breakpoint_objfile_data (objfile);
+  for (probe *p : bp_objfile_data->longjmp_probes)
+    {
+      struct breakpoint *b;
 
-       if (!bp_objfile_data->longjmp_searched)
-         {
-           std::vector<probe *> ret
-             = find_probes_in_objfile (objfile, "libc", "longjmp");
+      b = create_internal_breakpoint (gdbarch,
+                                     p->get_relocated_address (objfile),
+                                     bp_longjmp_master,
+                                     &internal_breakpoint_ops);
+      b->location = new_probe_location ("-probe-stap libc:longjmp");
+      b->enable_state = bp_disabled;
+    }
 
-           if (!ret.empty ())
-             {
-               /* We are only interested in checking one element.  */
-               probe *p = ret[0];
+  return true;
+}
 
-               if (!p->can_evaluate_arguments ())
-                 {
-                   /* We cannot use the probe interface here, because it does
-                      not know how to evaluate arguments.  */
-                   ret.clear ();
-                 }
-             }
-           bp_objfile_data->longjmp_probes = ret;
-           bp_objfile_data->longjmp_searched = 1;
-         }
+/* Install master longjmp breakpoints for OBJFILE using longjmp_names.
+   Return true if at least one breakpoint was installed.  */
 
-       if (!bp_objfile_data->longjmp_probes.empty ())
-         {
-           for (probe *p : bp_objfile_data->longjmp_probes)
-             {
-               struct breakpoint *b;
-
-               b = create_internal_breakpoint (gdbarch,
-                                               p->get_relocated_address (objfile),
-                                               bp_longjmp_master,
-                                               &internal_breakpoint_ops);
-               b->location = new_probe_location ("-probe-stap libc:longjmp");
-               b->enable_state = bp_disabled;
-             }
+static bool
+create_longjmp_master_breakpoint_names (objfile *objfile)
+{
+  struct gdbarch *gdbarch = objfile->arch ();
+  if (!gdbarch_get_longjmp_target_p (gdbarch))
+    return false;
 
-           continue;
-         }
+  struct breakpoint_objfile_data *bp_objfile_data
+    = get_breakpoint_objfile_data (objfile);
+  unsigned int installed_bp = 0;
 
-       if (!gdbarch_get_longjmp_target_p (gdbarch))
-         continue;
+  for (int i = 0; i < NUM_LONGJMP_NAMES; i++)
+    {
+      struct breakpoint *b;
+      const char *func_name;
+      CORE_ADDR addr;
+      struct explicit_location explicit_loc;
 
-       for (i = 0; i < NUM_LONGJMP_NAMES; i++)
-         {
-           struct breakpoint *b;
-           const char *func_name;
-           CORE_ADDR addr;
-           struct explicit_location explicit_loc;
+      if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
+       continue;
+
+      func_name = longjmp_names[i];
+      if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
+       {
+         struct bound_minimal_symbol m;
 
-           if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
+         m = lookup_minimal_symbol_text (func_name, objfile);
+         if (m.minsym == NULL)
+           {
+             /* Prevent future lookups in this objfile.  */
+             bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
              continue;
+           }
+         bp_objfile_data->longjmp_msym[i] = m;
+       }
 
-           func_name = longjmp_names[i];
-           if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
-             {
-               struct bound_minimal_symbol m;
+      addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
+      b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
+                                     &internal_breakpoint_ops);
+      initialize_explicit_location (&explicit_loc);
+      explicit_loc.function_name = ASTRDUP (func_name);
+      b->location = new_explicit_location (&explicit_loc);
+      b->enable_state = bp_disabled;
+      installed_bp++;
+    }
 
-               m = lookup_minimal_symbol_text (func_name, objfile);
-               if (m.minsym == NULL)
-                 {
-                   /* Prevent future lookups in this objfile.  */
-                   bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
-                   continue;
-                 }
-               bp_objfile_data->longjmp_msym[i] = m;
-             }
+  return installed_bp > 0;
+}
 
-           addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
-           b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
-                                           &internal_breakpoint_ops);
-           initialize_explicit_location (&explicit_loc);
-           explicit_loc.function_name = ASTRDUP (func_name);
-           b->location = new_explicit_location (&explicit_loc);
-           b->enable_state = bp_disabled;
-         }
-      }
-  }
+/* Create a master longjmp breakpoint.  */
+
+static void
+create_longjmp_master_breakpoint (void)
+{
+  scoped_restore_current_program_space restore_pspace;
+
+  for (struct program_space *pspace : program_spaces)
+    {
+      set_current_program_space (pspace);
+
+      for (objfile *obj : current_program_space->objfiles ())
+       {
+         /* Skip separate debug object, it's handled in the loop below.  */
+         if (obj->separate_debug_objfile_backlink != nullptr)
+           continue;
+
+         /* Try a probe kind breakpoint on main objfile.  */
+         if (create_longjmp_master_breakpoint_probe (obj))
+           continue;
+
+         /* Try longjmp_names kind breakpoints on main and separate_debug
+            objfiles.  */
+         for (objfile *debug_objfile : obj->separate_debug_objfiles ())
+           if (create_longjmp_master_breakpoint_names (debug_objfile))
+             break;
+       }
+    }
 }
 
 /* Create a master std::terminate breakpoint.  */
 static void
 create_std_terminate_master_breakpoint (void)
 {
-  struct program_space *pspace;
   const char *const func_name = "std::terminate()";
 
   scoped_restore_current_program_space restore_pspace;
 
-  ALL_PSPACES (pspace)
-  {
-    CORE_ADDR addr;
+  for (struct program_space *pspace : program_spaces)
+    {
+      CORE_ADDR addr;
 
-    set_current_program_space (pspace);
+      set_current_program_space (pspace);
 
-    for (objfile *objfile : current_program_space->objfiles ())
-      {
-       struct breakpoint *b;
-       struct breakpoint_objfile_data *bp_objfile_data;
-       struct explicit_location explicit_loc;
+      for (objfile *objfile : current_program_space->objfiles ())
+       {
+         struct breakpoint *b;
+         struct breakpoint_objfile_data *bp_objfile_data;
+         struct explicit_location explicit_loc;
 
-       bp_objfile_data = get_breakpoint_objfile_data (objfile);
+         bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
-       if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
-         continue;
+         if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
+           continue;
 
-       if (bp_objfile_data->terminate_msym.minsym == NULL)
-         {
-           struct bound_minimal_symbol m;
+         if (bp_objfile_data->terminate_msym.minsym == NULL)
+           {
+             struct bound_minimal_symbol m;
 
-           m = lookup_minimal_symbol (func_name, NULL, objfile);
-           if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
-                                    && MSYMBOL_TYPE (m.minsym) != mst_file_text))
-             {
-               /* Prevent future lookups in this objfile.  */
-               bp_objfile_data->terminate_msym.minsym = &msym_not_found;
-               continue;
-             }
-           bp_objfile_data->terminate_msym = m;
-         }
+             m = lookup_minimal_symbol (func_name, NULL, objfile);
+             if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
+                                      && MSYMBOL_TYPE (m.minsym) != mst_file_text))
+               {
+                 /* Prevent future lookups in this objfile.  */
+                 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
+                 continue;
+               }
+             bp_objfile_data->terminate_msym = m;
+           }
 
-       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
-       b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
-                                       bp_std_terminate_master,
-                                       &internal_breakpoint_ops);
-       initialize_explicit_location (&explicit_loc);
-       explicit_loc.function_name = ASTRDUP (func_name);
-       b->location = new_explicit_location (&explicit_loc);
-       b->enable_state = bp_disabled;
-      }
-  }
+         addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
+         b = create_internal_breakpoint (objfile->arch (), addr,
+                                         bp_std_terminate_master,
+                                         &internal_breakpoint_ops);
+         initialize_explicit_location (&explicit_loc);
+         explicit_loc.function_name = ASTRDUP (func_name);
+         b->location = new_explicit_location (&explicit_loc);
+         b->enable_state = bp_disabled;
+       }
+    }
 }
 
-/* Install a master breakpoint on the unwinder's debug hook.  */
+/* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
+   probe.  Return true if a breakpoint was installed.  */
 
-static void
-create_exception_master_breakpoint (void)
+static bool
+create_exception_master_breakpoint_probe (objfile *objfile)
 {
-  const char *const func_name = "_Unwind_DebugHook";
+  struct breakpoint *b;
+  struct gdbarch *gdbarch;
+  struct breakpoint_objfile_data *bp_objfile_data;
 
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      struct breakpoint *b;
-      struct gdbarch *gdbarch;
-      struct breakpoint_objfile_data *bp_objfile_data;
-      CORE_ADDR addr;
-      struct explicit_location explicit_loc;
+  bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
-      bp_objfile_data = get_breakpoint_objfile_data (objfile);
+  /* We prefer the SystemTap probe point if it exists.  */
+  if (!bp_objfile_data->exception_searched)
+    {
+      std::vector<probe *> ret
+       = find_probes_in_objfile (objfile, "libgcc", "unwind");
 
-      /* We prefer the SystemTap probe point if it exists.  */
-      if (!bp_objfile_data->exception_searched)
+      if (!ret.empty ())
        {
-         std::vector<probe *> ret
-           = find_probes_in_objfile (objfile, "libgcc", "unwind");
+         /* We are only interested in checking one element.  */
+         probe *p = ret[0];
 
-         if (!ret.empty ())
+         if (!p->can_evaluate_arguments ())
            {
-             /* We are only interested in checking one element.  */
-             probe *p = ret[0];
-
-             if (!p->can_evaluate_arguments ())
-               {
-                 /* We cannot use the probe interface here, because it does
-                    not know how to evaluate arguments.  */
-                 ret.clear ();
-               }
+             /* We cannot use the probe interface here, because it does
+                not know how to evaluate arguments.  */
+             ret.clear ();
            }
-         bp_objfile_data->exception_probes = ret;
-         bp_objfile_data->exception_searched = 1;
        }
+      bp_objfile_data->exception_probes = ret;
+      bp_objfile_data->exception_searched = 1;
+    }
 
-      if (!bp_objfile_data->exception_probes.empty ())
-       {
-         gdbarch = get_objfile_arch (objfile);
+  if (bp_objfile_data->exception_probes.empty ())
+    return false;
 
-         for (probe *p : bp_objfile_data->exception_probes)
-           {
-             b = create_internal_breakpoint (gdbarch,
-                                             p->get_relocated_address (objfile),
-                                             bp_exception_master,
-                                             &internal_breakpoint_ops);
-             b->location = new_probe_location ("-probe-stap libgcc:unwind");
-             b->enable_state = bp_disabled;
-           }
+  gdbarch = objfile->arch ();
 
-         continue;
-       }
+  for (probe *p : bp_objfile_data->exception_probes)
+    {
+      b = create_internal_breakpoint (gdbarch,
+                                     p->get_relocated_address (objfile),
+                                     bp_exception_master,
+                                     &internal_breakpoint_ops);
+      b->location = new_probe_location ("-probe-stap libgcc:unwind");
+      b->enable_state = bp_disabled;
+    }
 
-      /* Otherwise, try the hook function.  */
+  return true;
+}
 
-      if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
-       continue;
+/* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
+   _Unwind_DebugHook.  Return true if a breakpoint was installed.  */
 
-      gdbarch = get_objfile_arch (objfile);
+static bool
+create_exception_master_breakpoint_hook (objfile *objfile)
+{
+  const char *const func_name = "_Unwind_DebugHook";
+  struct breakpoint *b;
+  struct gdbarch *gdbarch;
+  struct breakpoint_objfile_data *bp_objfile_data;
+  CORE_ADDR addr;
+  struct explicit_location explicit_loc;
 
-      if (bp_objfile_data->exception_msym.minsym == NULL)
-       {
-         struct bound_minimal_symbol debug_hook;
+  bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
-         debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
-         if (debug_hook.minsym == NULL)
-           {
-             bp_objfile_data->exception_msym.minsym = &msym_not_found;
-             continue;
-           }
+  if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
+    return false;
+
+  gdbarch = objfile->arch ();
+
+  if (bp_objfile_data->exception_msym.minsym == NULL)
+    {
+      struct bound_minimal_symbol debug_hook;
 
-         bp_objfile_data->exception_msym = debug_hook;
+      debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
+      if (debug_hook.minsym == NULL)
+       {
+         bp_objfile_data->exception_msym.minsym = &msym_not_found;
+         return false;
        }
 
-      addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
-      addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
-                                                current_top_target ());
-      b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
-                                     &internal_breakpoint_ops);
-      initialize_explicit_location (&explicit_loc);
-      explicit_loc.function_name = ASTRDUP (func_name);
-      b->location = new_explicit_location (&explicit_loc);
-      b->enable_state = bp_disabled;
+      bp_objfile_data->exception_msym = debug_hook;
+    }
+
+  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
+  addr = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, addr, current_inferior ()->top_target ());
+  b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
+                                 &internal_breakpoint_ops);
+  initialize_explicit_location (&explicit_loc);
+  explicit_loc.function_name = ASTRDUP (func_name);
+  b->location = new_explicit_location (&explicit_loc);
+  b->enable_state = bp_disabled;
+
+  return true;
+}
+
+/* Install a master breakpoint on the unwinder's debug hook.  */
+
+static void
+create_exception_master_breakpoint (void)
+{
+  for (objfile *obj : current_program_space->objfiles ())
+    {
+      /* Skip separate debug object.  */
+      if (obj->separate_debug_objfile_backlink)
+       continue;
+
+      /* Try a probe kind breakpoint.  */
+      if (create_exception_master_breakpoint_probe (obj))
+       continue;
+
+      /* Iterate over main and separate debug objects and try an
+        _Unwind_DebugHook kind breakpoint.  */
+      for (objfile *debug_objfile : obj->separate_debug_objfiles ())
+       if (create_exception_master_breakpoint_hook (debug_objfile))
+         break;
     }
 }
 
@@ -3473,9 +3608,6 @@ breakpoint_event_location_empty_p (const struct breakpoint *b)
 void
 update_breakpoints_after_exec (void)
 {
-  struct breakpoint *b, *b_tmp;
-  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
      writing the breakpoints' "shadow contents" back into memory.  The
@@ -3484,118 +3616,117 @@ 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, bplocp_tmp)
+  for (bp_location *bploc : all_bp_locations ())
     if (bploc->pspace == current_program_space)
       gdb_assert (!bploc->inserted);
 
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
-  {
-    if (b->pspace != current_program_space)
-      continue;
-
-    /* Solib breakpoints must be explicitly reset after an exec().  */
-    if (b->type == bp_shlib_event)
-      {
-       delete_breakpoint (b);
+  for (breakpoint *b : all_breakpoints_safe ())
+    {
+      if (b->pspace != current_program_space)
        continue;
-      }
 
-    /* JIT breakpoints must be explicitly reset after an exec().  */
-    if (b->type == bp_jit_event)
-      {
-       delete_breakpoint (b);
-       continue;
-      }
+      /* Solib breakpoints must be explicitly reset after an exec().  */
+      if (b->type == bp_shlib_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_std_terminate_master
-       || b->type == bp_exception_master)
-      {
-       delete_breakpoint (b);
-       continue;
-      }
+      /* JIT breakpoints must be explicitly reset after an exec().  */
+      if (b->type == bp_jit_event)
+       {
+         delete_breakpoint (b);
+         continue;
+       }
 
-    /* Step-resume breakpoints are meaningless after an exec().  */
-    if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
-      {
-       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_std_terminate_master
+         || b->type == bp_exception_master)
+       {
+         delete_breakpoint (b);
+         continue;
+       }
 
-    /* Just like single-step breakpoints.  */
-    if (b->type == bp_single_step)
-      {
-       delete_breakpoint (b);
-       continue;
-      }
+      /* Step-resume breakpoints are meaningless after an exec().  */
+      if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
+       {
+         delete_breakpoint (b);
+         continue;
+       }
 
-    /* Longjmp and longjmp-resume breakpoints are also meaningless
-       after an exec.  */
-    if (b->type == bp_longjmp || b->type == bp_longjmp_resume
-       || b->type == bp_longjmp_call_dummy
-       || b->type == bp_exception || b->type == bp_exception_resume)
-      {
-       delete_breakpoint (b);
-       continue;
-      }
+      /* Just like single-step breakpoints.  */
+      if (b->type == bp_single_step)
+       {
+         delete_breakpoint (b);
+         continue;
+       }
 
-    if (b->type == bp_catchpoint)
-      {
-        /* For now, none of the bp_catchpoint breakpoints need to
-           do anything at this point.  In the future, if some of
-           the catchpoints need to something, we will need to add
-           a new method, and call this method from here.  */
-        continue;
-      }
+      /* Longjmp and longjmp-resume breakpoints are also meaningless
+        after an exec.  */
+      if (b->type == bp_longjmp || b->type == bp_longjmp_resume
+         || b->type == bp_longjmp_call_dummy
+         || b->type == bp_exception || b->type == bp_exception_resume)
+       {
+         delete_breakpoint (b);
+         continue;
+       }
 
-    /* bp_finish is a special case.  The only way we ought to be able
-       to see one of these when an exec() has happened, is if the user
-       caught a vfork, and then said "finish".  Ordinarily a finish just
-       carries them to the call-site of the current callee, by setting
-       a temporary bp there and resuming.  But in this case, the finish
-       will carry them entirely through the vfork & exec.
-
-       We don't want to allow a bp_finish to remain inserted now.  But
-       we can't safely delete it, 'cause finish_command has a handle to
-       the bp on a bpstat, and will later want to delete it.  There's a
-       chance (and I've seen it happen) that if we delete the bp_finish
-       here, that its storage will get reused by the time finish_command
-       gets 'round to deleting the "use to be a bp_finish" breakpoint.
-       We really must allow finish_command to delete a bp_finish.
-
-       In the absence of a general solution for the "how do we know
-       it's safe to delete something others may have handles to?"
-       problem, what we'll do here is just uninsert the bp_finish, and
-       let finish_command delete it.
-
-       (We know the bp_finish is "doomed" in the sense that it's
-       momentary, and will be deleted as soon as finish_command sees
-       the inferior stopped.  So it doesn't matter that the bp's
-       address is probably bogus in the new a.out, unlike e.g., the
-       solib breakpoints.)  */
-
-    if (b->type == bp_finish)
-      {
-       continue;
-      }
+      if (b->type == bp_catchpoint)
+       {
+         /* For now, none of the bp_catchpoint breakpoints need to
+            do anything at this point.  In the future, if some of
+            the catchpoints need to something, we will need to add
+            a new method, and call this method from here.  */
+         continue;
+       }
 
-    /* Without a symbolic address, we have little hope of the
-       pre-exec() address meaning the same thing in the post-exec()
-       a.out.  */
-    if (breakpoint_event_location_empty_p (b))
-      {
-       delete_breakpoint (b);
-       continue;
-      }
-  }
+      /* bp_finish is a special case.  The only way we ought to be able
+        to see one of these when an exec() has happened, is if the user
+        caught a vfork, and then said "finish".  Ordinarily a finish just
+        carries them to the call-site of the current callee, by setting
+        a temporary bp there and resuming.  But in this case, the finish
+        will carry them entirely through the vfork & exec.
+
+        We don't want to allow a bp_finish to remain inserted now.  But
+        we can't safely delete it, 'cause finish_command has a handle to
+        the bp on a bpstat, and will later want to delete it.  There's a
+        chance (and I've seen it happen) that if we delete the bp_finish
+        here, that its storage will get reused by the time finish_command
+        gets 'round to deleting the "use to be a bp_finish" breakpoint.
+        We really must allow finish_command to delete a bp_finish.
+
+        In the absence of a general solution for the "how do we know
+        it's safe to delete something others may have handles to?"
+        problem, what we'll do here is just uninsert the bp_finish, and
+        let finish_command delete it.
+
+        (We know the bp_finish is "doomed" in the sense that it's
+        momentary, and will be deleted as soon as finish_command sees
+        the inferior stopped.  So it doesn't matter that the bp's
+        address is probably bogus in the new a.out, unlike e.g., the
+        solib breakpoints.)  */
+
+      if (b->type == bp_finish)
+       {
+         continue;
+       }
+
+      /* Without a symbolic address, we have little hope of the
+        pre-exec() address meaning the same thing in the post-exec()
+        a.out.  */
+      if (breakpoint_event_location_empty_p (b))
+       {
+         delete_breakpoint (b);
+         continue;
+       }
+    }
 }
 
 int
 detach_breakpoints (ptid_t ptid)
 {
-  struct bp_location *bl, **blp_tmp;
   int val = 0;
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
   struct inferior *inf = current_inferior ();
@@ -3605,23 +3736,23 @@ detach_breakpoints (ptid_t ptid)
 
   /* Set inferior_ptid; remove_breakpoint_1 uses this global.  */
   inferior_ptid = ptid;
-  ALL_BP_LOCATIONS (bl, blp_tmp)
-  {
-    if (bl->pspace != inf->pspace)
-      continue;
-
-    /* This function must physically remove breakpoints locations
-       from the specified ptid, without modifying the breakpoint
-       package's state.  Locations of type bp_loc_other are only
-       maintained at GDB side.  So, there is no need to remove
-       these bp_loc_other locations.  Moreover, removing these
-       would modify the breakpoint package's state.  */
-    if (bl->loc_type == bp_loc_other)
-      continue;
-
-    if (bl->inserted)
-      val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
-  }
+  for (bp_location *bl : all_bp_locations ())
+    {
+      if (bl->pspace != inf->pspace)
+       continue;
+
+      /* This function must physically remove breakpoints locations
+        from the specified ptid, without modifying the breakpoint
+        package's state.  Locations of type bp_loc_other are only
+        maintained at GDB side.  So, there is no need to remove
+        these bp_loc_other locations.  Moreover, removing these
+        would modify the breakpoint package's state.  */
+      if (bl->loc_type == bp_loc_other)
+       continue;
+
+      if (bl->inserted)
+       val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
+    }
 
   return val;
 }
@@ -3762,8 +3893,8 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
                 bl->owner->number);
     }
   else if (bl->owner->type == bp_catchpoint
-           && breakpoint_enabled (bl->owner)
-           && !bl->duplicate)
+          && breakpoint_enabled (bl->owner)
+          && !bl->duplicate)
     {
       gdb_assert (bl->owner->ops != NULL
                  && bl->owner->ops->remove_location != NULL);
@@ -3800,9 +3931,7 @@ remove_breakpoint (struct bp_location *bl)
 void
 mark_breakpoints_out (void)
 {
-  struct bp_location *bl, **blp_tmp;
-
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     if (bl->pspace == current_program_space)
       bl->inserted = 0;
 }
@@ -3822,7 +3951,6 @@ mark_breakpoints_out (void)
 void
 breakpoint_init_inferior (enum inf_context context)
 {
-  struct breakpoint *b, *b_tmp;
   struct program_space *pspace = current_program_space;
 
   /* If breakpoint locations are shared across processes, then there's
@@ -3832,84 +3960,84 @@ breakpoint_init_inferior (enum inf_context context)
 
   mark_breakpoints_out ();
 
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
-  {
-    if (b->loc && b->loc->pspace != pspace)
-      continue;
+  for (breakpoint *b : all_breakpoints_safe ())
+    {
+      if (b->loc && b->loc->pspace != pspace)
+       continue;
 
-    switch (b->type)
-      {
-      case bp_call_dummy:
-      case bp_longjmp_call_dummy:
+      switch (b->type)
+       {
+       case bp_call_dummy:
+       case bp_longjmp_call_dummy:
 
-       /* 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.  */
+         /* 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.  */
 
-      case bp_watchpoint_scope:
+       case bp_watchpoint_scope:
 
-       /* Also get rid of scope breakpoints.  */
+         /* Also get rid of scope breakpoints.  */
 
-      case bp_shlib_event:
+       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.,
+         /* 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.
-       */
+            (gdb) file prog-linux
+            (gdb) run               # native linux target
+            ...
+            (gdb) kill
+            (gdb) file prog-win.exe
+            (gdb) tar rem :9999     # remote Windows gdbserver.
+         */
 
-      case bp_step_resume:
+       case bp_step_resume:
 
-       /* Also remove step-resume breakpoints.  */
+         /* Also remove step-resume breakpoints.  */
 
-      case bp_single_step:
+       case bp_single_step:
 
-       /* Also remove single-step breakpoints.  */
+         /* Also remove single-step breakpoints.  */
 
-       delete_breakpoint (b);
-       break;
+         delete_breakpoint (b);
+         break;
 
-      case bp_watchpoint:
-      case bp_hardware_watchpoint:
-      case bp_read_watchpoint:
-      case bp_access_watchpoint:
-       {
-         struct watchpoint *w = (struct watchpoint *) b;
+       case bp_watchpoint:
+       case bp_hardware_watchpoint:
+       case bp_read_watchpoint:
+       case bp_access_watchpoint:
+         {
+           struct watchpoint *w = (struct watchpoint *) b;
 
-         /* Likewise for watchpoints on local expressions.  */
-         if (w->exp_valid_block != NULL)
-           delete_breakpoint (b);
-         else
-           {
-             /* Get rid of existing locations, which are no longer
-                valid.  New ones will be created in
-                update_watchpoint, when the inferior is restarted.
-                The next update_global_location_list call will
-                garbage collect them.  */
-             b->loc = NULL;
-
-             if (context == inf_starting)
-               {
-                 /* Reset val field to force reread of starting value in
-                    insert_breakpoints.  */
-                 w->val.reset (nullptr);
-                 w->val_valid = false;
-               }
-           }
+           /* Likewise for watchpoints on local expressions.  */
+           if (w->exp_valid_block != NULL)
+             delete_breakpoint (b);
+           else
+             {
+               /* Get rid of existing locations, which are no longer
+                  valid.  New ones will be created in
+                  update_watchpoint, when the inferior is restarted.
+                  The next update_global_location_list call will
+                  garbage collect them.  */
+               b->loc = NULL;
+
+               if (context == inf_starting)
+                 {
+                   /* Reset val field to force reread of starting value in
+                      insert_breakpoints.  */
+                   w->val.reset (nullptr);
+                   w->val_valid = false;
+                 }
+             }
+         }
+         break;
+       default:
+         break;
        }
-       break;
-      default:
-       break;
-      }
-  }
+    }
 
   /* Get rid of the moribund locations.  */
   for (bp_location *bl : moribund_locations)
@@ -3935,10 +4063,9 @@ breakpoint_init_inferior (enum inf_context context)
 enum breakpoint_here
 breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
 {
-  struct bp_location *bl, **blp_tmp;
   int any_breakpoint_here = 0;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     {
       if (bl->loc_type != bp_loc_software_breakpoint
          && bl->loc_type != bp_loc_hardware_breakpoint)
@@ -3969,9 +4096,7 @@ int
 breakpoint_in_range_p (const address_space *aspace,
                       CORE_ADDR addr, ULONGEST len)
 {
-  struct bp_location *bl, **blp_tmp;
-
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     {
       if (bl->loc_type != bp_loc_software_breakpoint
          && bl->loc_type != bp_loc_hardware_breakpoint)
@@ -4035,12 +4160,8 @@ bp_location_inserted_here_p (struct bp_location *bl,
 int
 breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
 {
-  struct bp_location **blp, **blp_tmp = NULL;
-
-  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
+  for (bp_location *bl : all_bp_locations_at_addr (pc))
     {
-      struct bp_location *bl = *blp;
-
       if (bl->loc_type != bp_loc_software_breakpoint
          && bl->loc_type != bp_loc_hardware_breakpoint)
        continue;
@@ -4058,12 +4179,8 @@ int
 software_breakpoint_inserted_here_p (const address_space *aspace,
                                     CORE_ADDR pc)
 {
-  struct bp_location **blp, **blp_tmp = NULL;
-
-  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
+  for (bp_location *bl : all_bp_locations_at_addr (pc))
     {
-      struct bp_location *bl = *blp;
-
       if (bl->loc_type != bp_loc_software_breakpoint)
        continue;
 
@@ -4080,12 +4197,8 @@ int
 hardware_breakpoint_inserted_here_p (const address_space *aspace,
                                     CORE_ADDR pc)
 {
-  struct bp_location **blp, **blp_tmp = NULL;
-
-  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
+  for (bp_location *bl : all_bp_locations_at_addr (pc))
     {
-      struct bp_location *bl = *blp;
-
       if (bl->loc_type != bp_loc_hardware_breakpoint)
        continue;
 
@@ -4100,12 +4213,8 @@ int
 hardware_watchpoint_inserted_in_range (const address_space *aspace,
                                       CORE_ADDR addr, ULONGEST len)
 {
-  struct breakpoint *bpt;
-
-  ALL_BREAKPOINTS (bpt)
+  for (breakpoint *bpt : all_breakpoints ())
     {
-      struct bp_location *loc;
-
       if (bpt->type != bp_hardware_watchpoint
          && bpt->type != bp_access_watchpoint)
        continue;
@@ -4113,7 +4222,7 @@ hardware_watchpoint_inserted_in_range (const address_space *aspace,
       if (!breakpoint_enabled (bpt))
        continue;
 
-      for (loc = bpt->loc; loc; loc = loc->next)
+      for (bp_location *loc : bpt->locations ())
        if (loc->pspace->aspace == aspace && loc->inserted)
          {
            CORE_ADDR l, h;
@@ -4136,15 +4245,6 @@ is_catchpoint (struct breakpoint *b)
   return (b->type == bp_catchpoint);
 }
 
-/* Frees any storage that is part of a bpstat.  Does not walk the
-   'next' chain.  */
-
-bpstats::~bpstats ()
-{
-  if (bp_location_at != NULL)
-    decref_bp_location (&bp_location_at);
-}
-
 /* Clear a bpstat so that it says we are not at any breakpoint.
    Also free any storage that is part of a bpstat.  */
 
@@ -4177,7 +4277,6 @@ bpstats::bpstats (const bpstats &other)
 {
   if (other.old_val != NULL)
     old_val = release_value (value_copy (other.old_val.get ()));
-  incref_bp_location (bp_location_at);
 }
 
 /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
@@ -4361,14 +4460,14 @@ bpstat_do_actions_1 (bpstat *bsp)
 
       /* Take ownership of the BSP's command tree, if it has one.
 
-         The command tree could legitimately contain commands like
-         'step' and 'next', which call clear_proceed_status, which
-         frees stop_bpstat's command tree.  To make sure this doesn't
-         free the tree we're executing out from under us, we need to
-         take ownership of the tree ourselves.  Since a given bpstat's
-         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.  */
+        The command tree could legitimately contain commands like
+        'step' and 'next', which call clear_proceed_status, which
+        frees stop_bpstat's command tree.  To make sure this doesn't
+        free the tree we're executing out from under us, we need to
+        take ownership of the tree ourselves.  Since a given bpstat's
+        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.  */
       counted_command_line ccmd = bs->commands;
       bs->commands = NULL;
       if (ccmd != NULL)
@@ -4423,7 +4522,7 @@ bpstat_do_actions_1 (bpstat *bsp)
 static thread_info *
 get_bpstat_thread ()
 {
-  if (inferior_ptid == null_ptid || !target_has_execution)
+  if (inferior_ptid == null_ptid || !target_has_execution ())
     return NULL;
 
   thread_info *tp = inferior_thread ();
@@ -4516,7 +4615,7 @@ print_bp_stop_message (bpstat bs)
 
     case print_it_done:
       /* We still want to print the frame, but we already printed the
-         relevant messages.  */
+        relevant messages.  */
       return PRINT_SRC_AND_LOC;
       break;
 
@@ -4662,21 +4761,19 @@ breakpoint_cond_eval (expression *exp)
 
 bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer)
   : next (NULL),
-    bp_location_at (bl),
+    bp_location_at (bp_location_ref_ptr::new_reference (bl)),
     breakpoint_at (bl->owner),
     commands (NULL),
     print (0),
     stop (0),
     print_it (print_it_normal)
 {
-  incref_bp_location (bl);
   **bs_link_pointer = this;
   *bs_link_pointer = &next;
 }
 
 bpstats::bpstats ()
   : next (NULL),
-    bp_location_at (NULL),
     breakpoint_at (NULL),
     commands (NULL),
     print (0),
@@ -4693,13 +4790,12 @@ watchpoints_triggered (struct target_waitstatus *ws)
 {
   bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
   CORE_ADDR addr;
-  struct breakpoint *b;
 
   if (!stopped_by_watchpoint)
     {
       /* We were not stopped by a watchpoint.  Mark all watchpoints
         as not triggered.  */
-      ALL_BREAKPOINTS (b)
+      for (breakpoint *b : all_breakpoints ())
        if (is_hardware_watchpoint (b))
          {
            struct watchpoint *w = (struct watchpoint *) b;
@@ -4710,11 +4806,11 @@ watchpoints_triggered (struct target_waitstatus *ws)
       return 0;
     }
 
-  if (!target_stopped_data_address (current_top_target (), &addr))
+  if (!target_stopped_data_address (current_inferior ()->top_target (), &addr))
     {
       /* We were stopped by a watchpoint, but we don't know where.
         Mark all watchpoints as unknown.  */
-      ALL_BREAKPOINTS (b)
+      for (breakpoint *b : all_breakpoints ())
        if (is_hardware_watchpoint (b))
          {
            struct watchpoint *w = (struct watchpoint *) b;
@@ -4729,14 +4825,13 @@ watchpoints_triggered (struct target_waitstatus *ws)
      affected by this data address as triggered, and all others as not
      triggered.  */
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (is_hardware_watchpoint (b))
       {
        struct watchpoint *w = (struct watchpoint *) b;
-       struct bp_location *loc;
 
        w->watchpoint_triggered = watch_triggered_no;
-       for (loc = b->loc; loc; loc = loc->next)
+       for (bp_location *loc : b->locations ())
          {
            if (is_masked_watchpoint (b))
              {
@@ -4750,9 +4845,9 @@ watchpoints_triggered (struct target_waitstatus *ws)
                  }
              }
            /* Exact match not required.  Within range is sufficient.  */
-           else if (target_watchpoint_addr_within_range (current_top_target (),
-                                                        addr, loc->address,
-                                                        loc->length))
+           else if (target_watchpoint_addr_within_range
+                      (current_inferior ()->top_target (), addr, loc->address,
+                       loc->length))
              {
                w->watchpoint_triggered = watch_triggered_yes;
                break;
@@ -4848,11 +4943,10 @@ watchpoint_check (bpstat bs)
   if (within_current_scope)
     {
       /* We use value_{,free_to_}mark because it could be a *long*
-         time before we return to the command level and call
-         free_all_values.  We can't call free_all_values because we
-         might be in the middle of evaluating a function call.  */
+        time before we return to the command level and call
+        free_all_values.  We can't call free_all_values because we
+        might be in the middle of evaluating a function call.  */
 
-      int pc = 0;
       struct value *mark;
       struct value *new_val;
 
@@ -4863,7 +4957,8 @@ watchpoint_check (bpstat bs)
        return WP_VALUE_CHANGED;
 
       mark = value_mark ();
-      fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
+      fetch_subexp_value (b->exp.get (), b->exp->op.get (), &new_val,
+                         NULL, NULL, false);
 
       if (b->val_bitsize != 0)
        new_val = extract_bitfield_from_watchpoint_value (b, new_val);
@@ -4893,13 +4988,13 @@ watchpoint_check (bpstat bs)
   else
     {
       /* This seems like the only logical thing to do because
-         if we temporarily ignored the watchpoint, then when
-         we reenter the block in which it is valid it contains
-         garbage (in the case of a function, it may have two
-         garbage values, one before and one after the prologue).
-         So we can't even detect the first assignment to it and
-         watch after that (since the garbage may or may not equal
-         the first value assigned).  */
+        if we temporarily ignored the watchpoint, then when
+        we reenter the block in which it is valid it contains
+        garbage (in the case of a function, it may have two
+        garbage values, one before and one after the prologue).
+        So we can't even detect the first assignment to it and
+        watch after that (since the garbage may or may not equal
+        the first value assigned).  */
       /* We print all the stop information in
         breakpoint_ops->print_it, but in this case, by the time we
         call breakpoint_ops->print_it this bp will be deleted
@@ -4907,7 +5002,7 @@ watchpoint_check (bpstat bs)
         here.  */
 
       SWITCH_THRU_ALL_UIS ()
-        {
+       {
          struct ui_out *uiout = current_uiout;
 
          if (uiout->is_mi_like_p ())
@@ -4954,7 +5049,7 @@ bpstat_check_watchpoint (bpstat bs)
   struct watchpoint *b;
 
   /* BS is built for existing struct breakpoint.  */
-  bl = bs->bp_location_at;
+  bl = bs->bp_location_at.get ();
   gdb_assert (bl != NULL);
   b = (struct watchpoint *) bs->breakpoint_at;
   gdb_assert (b != NULL);
@@ -5055,9 +5150,7 @@ bpstat_check_watchpoint (bpstat bs)
 
                  if (bl->watchpoint_type == hw_read)
                    {
-                     struct breakpoint *other_b;
-
-                     ALL_BREAKPOINTS (other_b)
+                     for (breakpoint *other_b : all_breakpoints ())
                        if (other_b->type == bp_hardware_watchpoint
                            || other_b->type == bp_access_watchpoint)
                          {
@@ -5130,7 +5223,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
   gdb_assert (bs->stop);
 
   /* BS is built for existing struct breakpoint.  */
-  bl = bs->bp_location_at;
+  bl = bs->bp_location_at.get ();
   gdb_assert (bl != NULL);
   b = bs->breakpoint_at;
   gdb_assert (b != NULL);
@@ -5273,15 +5366,14 @@ bpstat
 build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
                    const struct target_waitstatus *ws)
 {
-  struct breakpoint *b;
   bpstat bs_head = NULL, *bs_link = &bs_head;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     {
       if (!breakpoint_enabled (b))
        continue;
 
-      for (bp_location *bl = b->loc; bl != NULL; bl = bl->next)
+      for (bp_location *bl : b->locations ())
        {
          /* For hardware watchpoints, we look only at the first
             location.  The watchpoint_check function will work on the
@@ -5291,7 +5383,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
          if (b->type == bp_hardware_watchpoint && bl != b->loc)
            break;
 
-         if (!bl->enabled || bl->shlib_disabled)
+         if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled)
            continue;
 
          if (!bpstat_check_location (bl, aspace, bp_addr, ws))
@@ -5454,22 +5546,25 @@ bpstat_stop_status (const address_space *aspace,
 }
 
 static void
-handle_jit_event (void)
+handle_jit_event (CORE_ADDR address)
 {
-  struct frame_info *frame;
   struct gdbarch *gdbarch;
 
-  if (debug_infrun)
-    fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
+  infrun_debug_printf ("handling bp_jit_event");
 
   /* Switch terminal for any messages produced by
      breakpoint_re_set.  */
   target_terminal::ours_for_output ();
 
-  frame = get_current_frame ();
-  gdbarch = get_frame_arch (frame);
-
-  jit_event_handler (gdbarch);
+  gdbarch = get_frame_arch (get_current_frame ());
+  /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
+     thus it is expected that its objectfile can be found through
+     minimal symbol lookup.  If it doesn't work (and assert fails), it
+     most likely means that `jit_breakpoint_re_set` was changes and this
+     function needs to be updated too.  */
+  bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address);
+  gdb_assert (jit_bp_sym.objfile != nullptr);
+  jit_event_handler (gdbarch, jit_bp_sym.objfile);
 
   target_terminal::inferior ();
 }
@@ -5670,7 +5765,7 @@ bpstat_run_callbacks (bpstat bs_head)
       switch (b->type)
        {
        case bp_jit_event:
-         handle_jit_event ();
+         handle_jit_event (bs->bp_location_at->address);
          break;
        case bp_gnu_ifunc_resolver:
          gnu_ifunc_resolver_stop (b);
@@ -5687,11 +5782,10 @@ bpstat_run_callbacks (bpstat bs_head)
 bool
 bpstat_should_step ()
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
       return true;
+
   return false;
 }
 
@@ -5749,7 +5843,6 @@ wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
 static const char *
 bp_condition_evaluator (struct breakpoint *b)
 {
-  struct bp_location *bl;
   char host_evals = 0;
   char target_evals = 0;
 
@@ -5763,7 +5856,7 @@ bp_condition_evaluator (struct breakpoint *b)
       || !target_supports_evaluation_of_breakpoint_conditions ())
     return condition_evaluation_host;
 
-  for (bl = b->loc; bl; bl = bl->next)
+  for (bp_location *bl : b->locations ())
     {
       if (bl->cond_bytecode)
        target_evals++;
@@ -5997,7 +6090,8 @@ print_one_breakpoint_location (struct breakpoint *b,
      breakpoints with single disabled location.  */
   if (loc == NULL 
       && (b->loc != NULL 
-         && (b->loc->next != NULL || !b->loc->enabled)))
+         && (b->loc->next != NULL
+             || !b->loc->enabled || b->loc->disabled_by_cond)))
     header_of_multiple = 1;
   if (loc == NULL)
     loc = b->loc;
@@ -6027,8 +6121,13 @@ print_one_breakpoint_location (struct breakpoint *b,
 
   /* 4 */
   annotate_field (3);
+  /* For locations that are disabled because of an invalid condition,
+     display "N*" on CLI, where "*" refers to a footnote below the
+     table.  For MI, simply display a "N" without a footnote.  */
+  const char *N = (uiout->is_mi_like_p ()) ? "N" : "N*";
   if (part_of_multiple)
-    uiout->field_string ("enabled", loc->enabled ? "y" : "n");
+    uiout->field_string ("enabled", (loc->disabled_by_cond ? N
+                                    : (loc->enabled ? "y" : "n")));
   else
     uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
 
@@ -6084,11 +6183,11 @@ print_one_breakpoint_location (struct breakpoint *b,
            inf_nums.push_back (inf->num);
        }
 
-        /* For backward compatibility, don't display inferiors in CLI unless
+       /* For backward compatibility, don't display inferiors in CLI unless
           there are several.  Always display for MI. */
        if (allflag
            || (!gdbarch_has_global_breakpoints (target_gdbarch ())
-               && (number_of_program_spaces () > 1
+               && (program_spaces.size () > 1
                    || number_of_inferiors () > 1)
                /* LOC is for existing B, it cannot be in
                   moribund_locations and thus having NULL OWNER.  */
@@ -6123,7 +6222,7 @@ print_one_breakpoint_location (struct breakpoint *b,
       annotate_field (6);
       uiout->text ("\tstop only in stack frame at ");
       /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
-         the frame ID.  */
+        the frame ID.  */
       uiout->field_core_addr ("frame",
                              b->gdbarch, b->frame_id.stack_addr);
       uiout->text ("\n");
@@ -6328,7 +6427,9 @@ print_one_breakpoint (struct breakpoint *b,
          && (!is_catchpoint (b) || is_exception_catchpoint (b)
              || is_ada_exception_catchpoint (b))
          && (allflag
-             || (b->loc && (b->loc->next || !b->loc->enabled))))
+             || (b->loc && (b->loc->next
+                            || !b->loc->enabled
+                            || b->loc->disabled_by_cond))))
        {
          gdb::optional<ui_out_emit_list> locations_list;
 
@@ -6339,11 +6440,12 @@ print_one_breakpoint (struct breakpoint *b,
            locations_list.emplace (uiout, "locations");
 
          int n = 1;
-         for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n)
+         for (bp_location *loc : b->locations ())
            {
              ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
              print_one_breakpoint_location (b, loc, n, last_loc,
                                             allflag, allflag);
+             n++;
            }
        }
     }
@@ -6353,14 +6455,13 @@ static int
 breakpoint_address_bits (struct breakpoint *b)
 {
   int print_address_bits = 0;
-  struct bp_location *loc;
 
   /* Software watchpoints that aren't watching memory don't have an
      address to print.  */
   if (is_no_memory_software_watchpoint (b))
     return 0;
 
-  for (loc = b->loc; loc; loc = loc->next)
+  for (bp_location *loc : b->locations ())
     {
       int addr_bit;
 
@@ -6415,20 +6516,20 @@ static int
 breakpoint_1 (const char *bp_num_list, bool show_internal,
              bool (*filter) (const struct breakpoint *))
 {
-  struct breakpoint *b;
   struct bp_location *last_loc = NULL;
   int nr_printable_breakpoints;
   struct value_print_options opts;
   int print_address_bits = 0;
   int print_type_col_width = 14;
   struct ui_out *uiout = current_uiout;
+  bool has_disabled_by_cond_location = false;
 
   get_user_print_options (&opts);
 
   /* Compute the number of rows in the table, as well as the size
      required for address fields.  */
   nr_printable_breakpoints = 0;
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     {
       /* If we have a filter, only list the breakpoints it accepts.  */
       if (filter && !filter (b))
@@ -6496,7 +6597,7 @@ breakpoint_1 (const char *bp_num_list, bool show_internal,
     if (nr_printable_breakpoints > 0)
       annotate_breakpoints_table ();
 
-    ALL_BREAKPOINTS (b)
+    for (breakpoint *b : all_breakpoints ())
       {
        QUIT;
        /* If we have a filter, only list the breakpoints it accepts.  */
@@ -6522,7 +6623,12 @@ breakpoint_1 (const char *bp_num_list, bool show_internal,
        /* We only print out user settable breakpoints unless the
           show_internal is set.  */
        if (show_internal || user_breakpoint_p (b))
-         print_one_breakpoint (b, &last_loc, show_internal);
+         {
+           print_one_breakpoint (b, &last_loc, show_internal);
+           for (bp_location *loc : b->locations ())
+             if (loc->disabled_by_cond)
+               has_disabled_by_cond_location = true;
+         }
       }
   }
 
@@ -6543,6 +6649,10 @@ breakpoint_1 (const char *bp_num_list, bool show_internal,
     {
       if (last_loc && !server_command)
        set_next_address (last_loc->gdbarch, last_loc->address);
+
+      if (has_disabled_by_cond_location && !uiout->is_mi_like_p ())
+       uiout->message (_("(*): Breakpoint condition is invalid at this "
+                         "location.\n"));
     }
 
   /* FIXME?  Should this be moved up so that it is only called when
@@ -6609,9 +6719,7 @@ 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)
+  for (bp_location *bl : b->locations ())
     {
       if (bl->pspace == pspace
          && bl->address == pc
@@ -6631,18 +6739,18 @@ describe_other_breakpoints (struct gdbarch *gdbarch,
                            struct obj_section *section, int thread)
 {
   int others = 0;
-  struct breakpoint *b;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     others += (user_breakpoint_p (b)
-               && breakpoint_has_pc (b, pspace, pc, section));
+              && breakpoint_has_pc (b, pspace, pc, section));
+
   if (others > 0)
     {
       if (others == 1)
        printf_filtered (_("Note: breakpoint "));
       else /* if (others == ???) */
        printf_filtered (_("Note: breakpoints "));
-      ALL_BREAKPOINTS (b)
+      for (breakpoint *b : all_breakpoints ())
        if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
          {
            others--;
@@ -6813,11 +6921,14 @@ tracepoint_locations_match (struct bp_location *loc1,
 
 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
    (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
-   the same location.  */
+   the same location.  If SW_HW_BPS_MATCH is true, then software
+   breakpoint locations and hardware breakpoint locations match,
+   otherwise they don't.  */
 
 static int
-breakpoint_locations_match (struct bp_location *loc1, 
-                           struct bp_location *loc2)
+breakpoint_locations_match (struct bp_location *loc1,
+                           struct bp_location *loc2,
+                           bool sw_hw_bps_match)
 {
   int hw_point1, hw_point2;
 
@@ -6835,15 +6946,18 @@ breakpoint_locations_match (struct bp_location *loc1,
   else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
     return tracepoint_locations_match (loc1, loc2);
   else
-    /* We compare bp_location.length in order to cover ranged breakpoints.  */
+    /* We compare bp_location.length in order to cover ranged
+       breakpoints.  Keep this in sync with
+       bp_location_is_less_than.  */
     return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
                                     loc2->pspace->aspace, loc2->address)
+           && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match)
            && loc1->length == loc2->length);
 }
 
 static void
 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
-                               int bnum, int have_bnum)
+                              int bnum, int have_bnum)
 {
   /* The longest string possibly returned by hex_string_custom
      is 50 chars.  These must be at least that big for safety.  */
@@ -6854,7 +6968,7 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
   strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
   if (have_bnum)
     warning (_("Breakpoint %d address previously adjusted from %s to %s."),
-             bnum, astr1, astr2);
+            bnum, astr1, astr2);
   else
     warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
 }
@@ -6875,7 +6989,7 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
       || bptype == bp_catchpoint)
     {
       /* Watchpoints and the various bp_catch_* eventpoints should not
-         have their addresses modified.  */
+        have their addresses modified.  */
       return bpaddr;
     }
   else if (bptype == bp_single_step)
@@ -6902,7 +7016,7 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
       adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
 
       /* An adjusted breakpoint address can significantly alter
-         a user's expectations.  Print a warning if an adjustment
+        a user's expectations.  Print a warning if an adjustment
         is required.  */
       if (adjusted_bpaddr != bpaddr)
        breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
@@ -6964,6 +7078,7 @@ bp_location::bp_location (breakpoint *owner, bp_loc_type type)
   this->cond_bytecode = NULL;
   this->shlib_disabled = 0;
   this->enabled = 1;
+  this->disabled_by_cond = false;
 
   this->loc_type = type;
 
@@ -6971,7 +7086,7 @@ bp_location::bp_location (breakpoint *owner, bp_loc_type type)
       || this->loc_type == bp_loc_hardware_breakpoint)
     mark_breakpoint_location_modified (this);
 
-  this->refc = 1;
+  incref ();
 }
 
 bp_location::bp_location (breakpoint *owner)
@@ -6988,30 +7103,13 @@ allocate_bp_location (struct breakpoint *bpt)
   return bpt->ops->allocate_location (bpt);
 }
 
-static void
-free_bp_location (struct bp_location *loc)
-{
-  delete loc;
-}
-
-/* Increment reference count.  */
-
-static void
-incref_bp_location (struct bp_location *bl)
-{
-  ++bl->refc;
-}
-
 /* Decrement reference count.  If the reference count reaches 0,
    destroy the bp_location.  Sets *BLP to NULL.  */
 
 static void
 decref_bp_location (struct bp_location **blp)
 {
-  gdb_assert ((*blp)->refc > 0);
-
-  if (--(*blp)->refc == 0)
-    free_bp_location (*blp);
+  bp_location_ref_policy::decref (*blp);
   *blp = NULL;
 }
 
@@ -7099,7 +7197,7 @@ set_breakpoint_location_function (struct bp_location *loc)
                 mess more complicated breakpoints with multiple locations.  */
              b->type = bp_gnu_ifunc_resolver;
              /* Remember the resolver's address for use by the return
-                breakpoint.  */
+                breakpoint.  */
              loc->related_address = loc->address;
            }
        }
@@ -7116,9 +7214,9 @@ struct gdbarch *
 get_sal_arch (struct symtab_and_line sal)
 {
   if (sal.section)
-    return get_objfile_arch (sal.section->objfile);
+    return sal.section->objfile->arch ();
   if (sal.symtab)
-    return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+    return SYMTAB_OBJFILE (sal.symtab)->arch ();
 
   return NULL;
 }
@@ -7183,14 +7281,13 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
 void
 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
 {
-  struct breakpoint *b, *b_tmp;
   int thread = tp->global_num;
 
   /* To avoid having to rescan all objfile symbols at every step,
      we maintain a list of continually-inserted but always disabled
      longjmp "master" breakpoints.  Here, we simply create momentary
      clones of those and enable them for the requested thread.  */
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->pspace == current_program_space
        && (b->type == bp_longjmp_master
            || b->type == bp_exception_master))
@@ -7212,9 +7309,7 @@ set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
 void
 delete_longjmp_breakpoint (int thread)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_longjmp || b->type == bp_exception)
       {
        if (b->thread == thread)
@@ -7225,9 +7320,7 @@ delete_longjmp_breakpoint (int thread)
 void
 delete_longjmp_breakpoint_at_next_stop (int thread)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_longjmp || b->type == bp_exception)
       {
        if (b->thread == thread)
@@ -7243,9 +7336,9 @@ delete_longjmp_breakpoint_at_next_stop (int thread)
 struct breakpoint *
 set_longjmp_breakpoint_for_call_dummy (void)
 {
-  struct breakpoint *b, *retval = NULL;
+  breakpoint *retval = nullptr;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->pspace == current_program_space && b->type == bp_longjmp_master)
       {
        struct breakpoint *new_b;
@@ -7273,9 +7366,10 @@ set_longjmp_breakpoint_for_call_dummy (void)
    TP.  Remove those which can no longer be found in the current frame
    stack.
 
-   You should call this function only at places where it is safe to currently
-   unwind the whole stack.  Failed stack unwind would discard live dummy
-   frames.  */
+   If the unwind fails then there is not sufficient information to discard
+   dummy frames.  In this case, elide the clean up and the dummy frames will
+   be cleaned up next time this function is called from a location where
+   unwinding is possible.  */
 
 void
 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
@@ -7287,12 +7381,55 @@ check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
       {
        struct breakpoint *dummy_b = b->related_breakpoint;
 
+       /* Find the bp_call_dummy breakpoint in the list of breakpoints
+          chained off b->related_breakpoint.  */
        while (dummy_b != b && dummy_b->type != bp_call_dummy)
          dummy_b = dummy_b->related_breakpoint;
+
+       /* If there was no bp_call_dummy breakpoint then there's nothing
+          more to do.  Or, if the dummy frame associated with the
+          bp_call_dummy is still on the stack then we need to leave this
+          bp_call_dummy in place.  */
        if (dummy_b->type != bp_call_dummy
            || frame_find_by_id (dummy_b->frame_id) != NULL)
          continue;
-       
+
+       /* We didn't find the dummy frame on the stack, this could be
+          because we have longjmp'd to a stack frame that is previous to
+          the dummy frame, or it could be because the stack unwind is
+          broken at some point between the longjmp frame and the dummy
+          frame.
+
+          Next we figure out why the stack unwind stopped.  If it looks
+          like the unwind is complete then we assume the dummy frame has
+          been jumped over, however, if the unwind stopped for an
+          unexpected reason then we assume the stack unwind is currently
+          broken, and that we will (eventually) return to the dummy
+          frame.
+
+          It might be tempting to consider using frame_id_inner here, but
+          that is not safe.   There is no guarantee that the stack frames
+          we are looking at here are even on the same stack as the
+          original dummy frame, hence frame_id_inner can't be used.  See
+          the comments on frame_id_inner for more details.  */
+       bool unwind_finished_unexpectedly = false;
+       for (struct frame_info *fi = get_current_frame (); fi != nullptr; )
+         {
+           struct frame_info *prev = get_prev_frame (fi);
+           if (prev == nullptr)
+             {
+               /* FI is the last stack frame.  Why did this frame not
+                  unwind further?  */
+               auto stop_reason = get_frame_unwind_stop_reason (fi);
+               if (stop_reason != UNWIND_NO_REASON
+                   && stop_reason != UNWIND_OUTERMOST)
+                 unwind_finished_unexpectedly = true;
+             }
+           fi = prev;
+         }
+       if (unwind_finished_unexpectedly)
+         continue;
+
        dummy_frame_discard (dummy_b->frame_id, tp);
 
        while (b->related_breakpoint != b)
@@ -7308,29 +7445,25 @@ check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
 void
 enable_overlay_breakpoints (void)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->type == bp_overlay_event)
-    {
-      b->enable_state = bp_enabled;
-      update_global_location_list (UGLL_MAY_INSERT);
-      overlay_events_enabled = 1;
-    }
+      {
+       b->enable_state = bp_enabled;
+       update_global_location_list (UGLL_MAY_INSERT);
+       overlay_events_enabled = 1;
+      }
 }
 
 void
 disable_overlay_breakpoints (void)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->type == bp_overlay_event)
-    {
-      b->enable_state = bp_disabled;
-      update_global_location_list (UGLL_DONT_INSERT);
-      overlay_events_enabled = 0;
-    }
+      {
+       b->enable_state = bp_disabled;
+       update_global_location_list (UGLL_DONT_INSERT);
+       overlay_events_enabled = 0;
+      }
 }
 
 /* Set an active std::terminate breakpoint for each std::terminate
@@ -7338,9 +7471,7 @@ disable_overlay_breakpoints (void)
 void
 set_std_terminate_breakpoint (void)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->pspace == current_program_space
        && b->type == bp_std_terminate_master)
       {
@@ -7353,9 +7484,7 @@ set_std_terminate_breakpoint (void)
 void
 delete_std_terminate_breakpoint (void)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_std_terminate)
       delete_breakpoint (b);
 }
@@ -7397,9 +7526,7 @@ create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 void
 remove_jit_event_breakpoints (void)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_jit_event
        && b->loc->pspace == current_program_space)
       delete_breakpoint (b);
@@ -7408,9 +7535,7 @@ remove_jit_event_breakpoints (void)
 void
 remove_solib_event_breakpoints (void)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_shlib_event
        && b->loc->pspace == current_program_space)
       delete_breakpoint (b);
@@ -7421,9 +7546,7 @@ remove_solib_event_breakpoints (void)
 void
 remove_solib_event_breakpoints_at_next_stop (void)
 {
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->type == bp_shlib_event
        && b->loc->pspace == current_program_space)
       b->disposition = disp_del_at_next_stop;
@@ -7475,30 +7598,28 @@ create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR add
 void
 disable_breakpoints_in_shlibs (void)
 {
-  struct bp_location *loc, **locp_tmp;
+  for (bp_location *loc : all_bp_locations ())
+    {
+      /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
+      struct breakpoint *b = loc->owner;
 
-  ALL_BP_LOCATIONS (loc, locp_tmp)
-  {
-    /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
-    struct breakpoint *b = loc->owner;
-
-    /* We apply the check to all breakpoints, including disabled for
-       those with loc->duplicate set.  This is so that when breakpoint
-       becomes enabled, or the duplicate is removed, gdb will try to
-       insert all breakpoints.  If we don't set shlib_disabled here,
-       we'll try to insert those breakpoints and fail.  */
-    if (((b->type == bp_breakpoint)
-        || (b->type == bp_jit_event)
-        || (b->type == bp_hardware_breakpoint)
-        || (is_tracepoint (b)))
-       && loc->pspace == current_program_space
-       && !loc->shlib_disabled
-       && solib_name_from_address (loc->pspace, loc->address)
-       )
-      {
-       loc->shlib_disabled = 1;
-      }
-  }
+      /* We apply the check to all breakpoints, including disabled for
+        those with loc->duplicate set.  This is so that when breakpoint
+        becomes enabled, or the duplicate is removed, gdb will try to
+        insert all breakpoints.  If we don't set shlib_disabled here,
+        we'll try to insert those breakpoints and fail.  */
+      if (((b->type == bp_breakpoint)
+          || (b->type == bp_jit_event)
+          || (b->type == bp_hardware_breakpoint)
+          || (is_tracepoint (b)))
+         && loc->pspace == current_program_space
+         && !loc->shlib_disabled
+         && solib_name_from_address (loc->pspace, loc->address)
+         )
+       {
+         loc->shlib_disabled = 1;
+       }
+    }
 }
 
 /* Disable any breakpoints and tracepoints that are in SOLIB upon
@@ -7508,43 +7629,42 @@ disable_breakpoints_in_shlibs (void)
 static void
 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
 {
-  struct bp_location *loc, **locp_tmp;
   int disabled_shlib_breaks = 0;
 
-  ALL_BP_LOCATIONS (loc, locp_tmp)
-  {
-    /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
-    struct breakpoint *b = loc->owner;
+  for (bp_location *loc : all_bp_locations ())
+    {
+      /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
+      struct breakpoint *b = loc->owner;
 
-    if (solib->pspace == loc->pspace
-       && !loc->shlib_disabled
-       && (((b->type == bp_breakpoint
-             || b->type == bp_jit_event
-             || b->type == bp_hardware_breakpoint)
-            && (loc->loc_type == bp_loc_hardware_breakpoint
-                || loc->loc_type == bp_loc_software_breakpoint))
-           || is_tracepoint (b))
-       && solib_contains_address_p (solib, loc->address))
-      {
-       loc->shlib_disabled = 1;
-       /* At this point, we cannot rely on remove_breakpoint
-          succeeding so we must mark the breakpoint as not inserted
-          to prevent future errors occurring in remove_breakpoints.  */
-       loc->inserted = 0;
+      if (solib->pspace == loc->pspace
+         && !loc->shlib_disabled
+         && (((b->type == bp_breakpoint
+               || b->type == bp_jit_event
+               || b->type == bp_hardware_breakpoint)
+              && (loc->loc_type == bp_loc_hardware_breakpoint
+                  || loc->loc_type == bp_loc_software_breakpoint))
+             || is_tracepoint (b))
+         && solib_contains_address_p (solib, loc->address))
+       {
+         loc->shlib_disabled = 1;
+         /* At this point, we cannot rely on remove_breakpoint
+            succeeding so we must mark the breakpoint as not inserted
+            to prevent future errors occurring in remove_breakpoints.  */
+         loc->inserted = 0;
 
-       /* This may cause duplicate notifications for the same breakpoint.  */
-       gdb::observers::breakpoint_modified.notify (b);
+         /* This may cause duplicate notifications for the same breakpoint.  */
+         gdb::observers::breakpoint_modified.notify (b);
 
-       if (!disabled_shlib_breaks)
-         {
-           target_terminal::ours_for_output ();
-           warning (_("Temporarily disabling breakpoints "
-                      "for unloaded shared library \"%s\""),
-                    solib->so_name);
-         }
-       disabled_shlib_breaks = 1;
-      }
-  }
+         if (!disabled_shlib_breaks)
+           {
+             target_terminal::ours_for_output ();
+             warning (_("Temporarily disabling breakpoints "
+                        "for unloaded shared library \"%s\""),
+                      solib->so_name);
+           }
+         disabled_shlib_breaks = 1;
+       }
+    }
 }
 
 /* Disable any breakpoints and tracepoints in OBJFILE upon
@@ -7554,8 +7674,6 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
 static void
 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
 {
-  struct breakpoint *b;
-
   if (objfile == NULL)
     return;
 
@@ -7574,15 +7692,14 @@ disable_breakpoints_in_freed_objfile (struct objfile *objfile)
       || (objfile->flags & OBJF_USERLOADED) == 0)
     return;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     {
-      struct bp_location *loc;
       int bp_modified = 0;
 
       if (!is_breakpoint (b) && !is_tracepoint (b))
        continue;
 
-      for (loc = b->loc; loc != NULL; loc = loc->next)
+      for (bp_location *loc : b->locations ())
        {
          CORE_ADDR loc_addr = loc->address;
 
@@ -7874,7 +7991,7 @@ struct solib_catchpoint : public breakpoint
   ~solib_catchpoint () override;
 
   /* True for "catch load", false for "catch unload".  */
-  unsigned char is_load;
+  bool is_load;
 
   /* Regular expression to match, if any.  COMPILED is only valid when
      REGEX is non-NULL.  */
@@ -7906,30 +8023,27 @@ breakpoint_hit_catch_solib (const struct bp_location *bl,
                            const struct target_waitstatus *ws)
 {
   struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
-  struct breakpoint *other;
 
   if (ws->kind == TARGET_WAITKIND_LOADED)
     return 1;
 
-  ALL_BREAKPOINTS (other)
-  {
-    struct bp_location *other_bl;
-
-    if (other == bl->owner)
-      continue;
+  for (breakpoint *other : all_breakpoints ())
+    {
+      if (other == bl->owner)
+       continue;
 
-    if (other->type != bp_shlib_event)
-      continue;
+      if (other->type != bp_shlib_event)
+       continue;
 
-    if (self->pspace != NULL && other->pspace != self->pspace)
-      continue;
+      if (self->pspace != NULL && other->pspace != self->pspace)
+       continue;
 
-    for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
-      {
-       if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
-         return 1;
-      }
-  }
+      for (bp_location *other_bl : other->locations ())
+       {
+         if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
+           return 1;
+       }
+    }
 
   return 0;
 }
@@ -8046,15 +8160,10 @@ print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
 
 static struct breakpoint_ops catch_solib_breakpoint_ops;
 
-/* Shared helper function (MI and CLI) for creating and installing
-   a shared object event catchpoint.  If IS_LOAD is non-zero then
-   the events to be caught are load events, otherwise they are
-   unload events.  If IS_TEMP is non-zero the catchpoint is a
-   temporary one.  If ENABLED is non-zero the catchpoint is
-   created in an enabled state.  */
+/* See breakpoint.h.  */
 
 void
-add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
+add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
 {
   struct gdbarch *gdbarch = get_current_arch ();
 
@@ -8087,12 +8196,10 @@ static void
 catch_load_or_unload (const char *arg, int from_tty, int is_load,
                      struct cmd_list_element *command)
 {
-  int tempflag;
   const int enabled = 1;
+  bool temp = command->context () == CATCH_TEMPORARY;
 
-  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
-
-  add_solib_catchpoint (arg, is_load, tempflag, enabled);
+  add_solib_catchpoint (arg, is_load, temp, enabled);
 }
 
 static void
@@ -8109,14 +8216,11 @@ catch_unload_command_1 (const char *arg, int from_tty,
   catch_load_or_unload (arg, from_tty, 0, command);
 }
 
-/* Initialize a new breakpoint of the bp_catchpoint kind.  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.  */
+/* See breakpoint.h.  */
 
 void
 init_catchpoint (struct breakpoint *b,
-                struct gdbarch *gdbarch, int tempflag,
+                struct gdbarch *gdbarch, bool temp,
                 const char *cond_string,
                 const struct breakpoint_ops *ops)
 {
@@ -8126,7 +8230,7 @@ init_catchpoint (struct breakpoint *b,
   init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
 
   b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
-  b->disposition = tempflag ? disp_del : disp_donttouch;
+  b->disposition = temp ? disp_del : disp_donttouch;
 }
 
 void
@@ -8146,12 +8250,12 @@ install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_
 
 static void
 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
-                                   int tempflag, const char *cond_string,
-                                    const struct breakpoint_ops *ops)
+                                   bool temp, const char *cond_string,
+                                   const struct breakpoint_ops *ops)
 {
   std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
 
-  init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops);
+  init_catchpoint (c.get (), gdbarch, temp, cond_string, ops);
 
   c->forked_inferior_pid = null_ptid;
 
@@ -8282,19 +8386,15 @@ static int
 hw_breakpoint_used_count (void)
 {
   int i = 0;
-  struct breakpoint *b;
-  struct bp_location *bl;
 
-  ALL_BREAKPOINTS (b)
-  {
+  for (breakpoint *b : all_breakpoints ())
     if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
-      for (bl = b->loc; bl; bl = bl->next)
+      for (bp_location *bl : b->locations ())
        {
          /* Special types of hardware breakpoints may use more than
             one register.  */
          i += b->ops->resources_needed (bl);
        }
-  }
 
   return i;
 }
@@ -8306,12 +8406,11 @@ static int
 hw_watchpoint_use_count (struct breakpoint *b)
 {
   int i = 0;
-  struct bp_location *bl;
 
   if (!breakpoint_enabled (b))
     return 0;
 
-  for (bl = b->loc; bl; bl = bl->next)
+  for (bp_location *bl : b->locations ())
     {
       /* Special types of hardware watchpoints may use more than
         one register.  */
@@ -8331,10 +8430,9 @@ hw_watchpoint_used_count_others (struct breakpoint *except,
                                 enum bptype type, int *other_type_used)
 {
   int i = 0;
-  struct breakpoint *b;
 
   *other_type_used = 0;
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     {
       if (b == except)
        continue;
@@ -8353,31 +8451,23 @@ hw_watchpoint_used_count_others (struct breakpoint *except,
 void
 disable_watchpoints_before_interactive_call_start (void)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
-  {
+  for (breakpoint *b : all_breakpoints ())
     if (is_watchpoint (b) && breakpoint_enabled (b))
       {
        b->enable_state = bp_call_disabled;
        update_global_location_list (UGLL_DONT_INSERT);
       }
-  }
 }
 
 void
 enable_watchpoints_after_interactive_call_stop (void)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
-  {
+  for (breakpoint *b : all_breakpoints ())
     if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
       {
        b->enable_state = bp_enabled;
        update_global_location_list (UGLL_MAY_INSERT);
       }
-  }
 }
 
 void
@@ -8517,6 +8607,61 @@ mention (struct breakpoint *b)
 
 static bool bp_loc_is_permanent (struct bp_location *loc);
 
+/* Handle "set breakpoint auto-hw on".
+
+   If the explicitly specified breakpoint type is not hardware
+   breakpoint, check the memory map to see whether the breakpoint
+   address is in read-only memory.
+
+   - location type is not hardware breakpoint, memory is read-only.
+   We change the type of the location to hardware breakpoint.
+
+   - location type is hardware breakpoint, memory is read-write.  This
+   means we've previously made the location hardware one, but then the
+   memory map changed, so we undo.
+*/
+
+static void
+handle_automatic_hardware_breakpoints (bp_location *bl)
+{
+  if (automatic_hardware_breakpoints
+      && bl->owner->type != bp_hardware_breakpoint
+      && (bl->loc_type == bp_loc_software_breakpoint
+         || bl->loc_type == bp_loc_hardware_breakpoint))
+    {
+      /* When breakpoints are removed, remove_breakpoints will use
+        location types we've just set here, the only possible problem
+        is that memory map has changed during running program, but
+        it's not going to work anyway with current gdb.  */
+      mem_region *mr = lookup_mem_region (bl->address);
+
+      if (mr != nullptr)
+       {
+         enum bp_loc_type new_type;
+
+         if (mr->attrib.mode != MEM_RW)
+           new_type = bp_loc_hardware_breakpoint;
+         else
+           new_type = bp_loc_software_breakpoint;
+
+         if (new_type != bl->loc_type)
+           {
+             static bool said = false;
+
+             bl->loc_type = new_type;
+             if (!said)
+               {
+                 fprintf_filtered (gdb_stdout,
+                                   _("Note: automatically using "
+                                     "hardware breakpoints for "
+                                     "read-only addresses.\n"));
+                 said = true;
+               }
+           }
+       }
+    }
+}
+
 static struct bp_location *
 add_location_to_breakpoint (struct breakpoint *b,
                            const struct symtab_and_line *sal)
@@ -8672,13 +8817,9 @@ static void
 update_dprintf_commands (const char *args, int from_tty,
                         struct cmd_list_element *c)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
-    {
-      if (b->type == bp_dprintf)
+  for (breakpoint *b : all_breakpoints ())
+    if (b->type == bp_dprintf)
        update_dprintf_command_list (b);
-    }
 }
 
 /* Create a breakpoint with SAL as location.  Use LOCATION
@@ -8791,15 +8932,9 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
            loc->inserted = 1;
        }
 
-      if (b->cond_string)
-       {
-         const char *arg = b->cond_string;
-
-         loc->cond = parse_exp_1 (&arg, loc->address,
-                                  block_for_pc (loc->address), 0);
-         if (*arg)
-              error (_("Garbage '%s' follows condition"), arg);
-       }
+      /* Do not set breakpoint locations conditions yet.  As locations
+        are inserted, they get sorted based on their addresses.  Let
+        the list stabilize to have reliable location numbers.  */
 
       /* Dynamic printf requires and uses additional arguments on the
         command line, otherwise it's an error.  */
@@ -8814,6 +8949,19 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
        error (_("Garbage '%s' at end of command"), b->extra_string);
     }
 
+
+  /* The order of the locations is now stable.  Set the location
+     condition using the location's number.  */
+  int loc_num = 1;
+  for (bp_location *loc : b->locations ())
+    {
+      if (b->cond_string != nullptr)
+       set_breakpoint_location_condition (b->cond_string, loc, b->number,
+                                          loc_num);
+
+      ++loc_num;
+    }
+
   b->display_canonical = display_canonical;
   if (location != NULL)
     b->location = std::move (location);
@@ -8910,7 +9058,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
    the caller's responsibility to free them.  */
 
 static void
-parse_breakpoint_sals (const struct event_location *location,
+parse_breakpoint_sals (struct event_location *location,
                       struct linespec_result *canonical)
 {
   struct symtab_and_line cursal;
@@ -9041,6 +9189,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
   *thread = -1;
   *task = 0;
   *rest = NULL;
+  bool force = false;
 
   while (tok && *tok)
     {
@@ -9064,10 +9213,25 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
       if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
        {
          tok = cond_start = end_tok + 1;
-         parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
+         try
+           {
+             parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
+           }
+         catch (const gdb_exception_error &)
+           {
+             if (!force)
+               throw;
+             else
+               tok = tok + strlen (tok);
+           }
          cond_end = tok;
          *cond_string = savestring (cond_start, cond_end - cond_start);
        }
+      else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
+       {
+         tok = tok + toklen;
+         force = true;
+       }
       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
        {
          const char *tmptok;
@@ -9102,6 +9266,50 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
     }
 }
 
+/* Call 'find_condition_and_thread' for each sal in SALS until a parse
+   succeeds.  The parsed values are written to COND_STRING, THREAD,
+   TASK, and REST.  See the comment of 'find_condition_and_thread'
+   for the description of these parameters and INPUT.  */
+
+static void
+find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
+                                   const char *input, char **cond_string,
+                                   int *thread, int *task, char **rest)
+{
+  int num_failures = 0;
+  for (auto &sal : sals)
+    {
+      char *cond = nullptr;
+      int thread_id = 0;
+      int task_id = 0;
+      char *remaining = nullptr;
+
+      /* Here we want to parse 'arg' to separate condition from thread
+        number.  But because parsing happens in a context and the
+        contexts of sals might be different, try each until there is
+        success.  Finding one successful parse is sufficient for our
+        goal.  When setting the breakpoint we'll re-parse the
+        condition in the context of each sal.  */
+      try
+       {
+         find_condition_and_thread (input, sal.pc, &cond, &thread_id,
+                                    &task_id, &remaining);
+         *cond_string = cond;
+         *thread = thread_id;
+         *task = task_id;
+         *rest = remaining;
+         break;
+       }
+      catch (const gdb_exception_error &e)
+       {
+         num_failures++;
+         /* If no sal remains, do not continue.  */
+         if (num_failures == sals.size ())
+           throw;
+       }
+    }
+}
+
 /* Decode a static tracepoint marker spec.  */
 
 static std::vector<symtab_and_line>
@@ -9175,10 +9383,10 @@ breakpoint_ops_for_event_location (const struct event_location *location,
 
 int
 create_breakpoint (struct gdbarch *gdbarch,
-                  const struct event_location *location,
+                  struct event_location *location,
                   const char *cond_string,
                   int thread, const char *extra_string,
-                  int parse_extra,
+                  bool force_condition, int parse_extra,
                   int tempflag, enum bptype type_wanted,
                   int ignore_count,
                   enum auto_boolean pending_break_support,
@@ -9215,7 +9423,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 
          exception_print (gdb_stderr, e);
 
-          /* If pending breakpoint support is auto query and the user
+         /* If pending breakpoint support is auto query and the user
             selects no, then simply return the error code.  */
          if (pending_break_support == AUTO_BOOLEAN_AUTO
              && !nquery (_("Make %s pending on future shared library load? "),
@@ -9259,35 +9467,57 @@ create_breakpoint (struct gdbarch *gdbarch,
       gdb::unique_xmalloc_ptr<char> extra_string_copy;
 
       if (parse_extra)
-        {
+       {
          char *rest;
          char *cond;
 
          const linespec_sals &lsal = canonical.lsals[0];
 
-         /* Here we only parse 'arg' to separate condition
-            from thread number, so parsing in context of first
-            sal is OK.  When setting the breakpoint we'll
-            re-parse it in context of each sal.  */
-
-         find_condition_and_thread (extra_string, lsal.sals[0].pc,
-                                    &cond, &thread, &task, &rest);
+         find_condition_and_thread_for_sals (lsal.sals, extra_string,
+                                             &cond, &thread, &task, &rest);
          cond_string_copy.reset (cond);
          extra_string_copy.reset (rest);
-        }
+       }
       else
-        {
+       {
          if (type_wanted != bp_dprintf
              && extra_string != NULL && *extra_string != '\0')
                error (_("Garbage '%s' at end of location"), extra_string);
 
+         /* Check the validity of the condition.  We should error out
+            if the condition is invalid at all of the locations and
+            if it is not forced.  In the PARSE_EXTRA case above, this
+            check is done when parsing the EXTRA_STRING.  */
+         if (cond_string != nullptr && !force_condition)
+           {
+             int num_failures = 0;
+             const linespec_sals &lsal = canonical.lsals[0];
+             for (const auto &sal : lsal.sals)
+               {
+                 const char *cond = cond_string;
+                 try
+                   {
+                     parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0);
+                     /* One success is sufficient to keep going.  */
+                     break;
+                   }
+                 catch (const gdb_exception_error &)
+                   {
+                     num_failures++;
+                     /* If this is the last sal, error out.  */
+                     if (num_failures == lsal.sals.size ())
+                       throw;
+                   }
+               }
+           }
+
          /* Create a private copy of condition string.  */
          if (cond_string)
            cond_string_copy.reset (xstrdup (cond_string));
          /* Create a private copy of any extra string.  */
          if (extra_string)
            extra_string_copy.reset (xstrdup (extra_string));
-        }
+       }
 
       ops->create_breakpoints_sal (gdbarch, &canonical,
                                   std::move (cond_string_copy),
@@ -9320,7 +9550,7 @@ create_breakpoint (struct gdbarch *gdbarch,
       b->condition_not_parsed = 1;
       b->enable_state = enabled ? bp_enabled : bp_disabled;
       if ((type_wanted != bp_breakpoint
-           && type_wanted != bp_hardware_breakpoint) || thread != -1)
+          && type_wanted != bp_hardware_breakpoint) || thread != -1)
        b->pspace = current_program_space;
 
       install_breakpoint (internal, std::move (b), 0);
@@ -9359,7 +9589,7 @@ break_command_1 (const char *arg, int flag, int from_tty)
 
   create_breakpoint (get_current_arch (),
                     location.get (),
-                    NULL, 0, arg, 1 /* parse arg */,
+                    NULL, 0, arg, false, 1 /* parse arg */,
                     tempflag, type_wanted,
                     0 /* Ignore count */,
                     pending_break_support,
@@ -9385,7 +9615,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
       sal->pc = pc;
 
       /* If this SAL corresponds to a breakpoint inserted using a line
-         number, then skip the function prologue if necessary.  */
+        number, then skip the function prologue if necessary.  */
       if (sal->explicit_line)
        skip_prologue_sal (sal);
     }
@@ -9404,22 +9634,21 @@ resolve_sal_pc (struct symtab_and_line *sal)
          if (sym != NULL)
            {
              fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
-             sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
-                                                sym);
+             sal->section = sym->obj_section (SYMTAB_OBJFILE (sal->symtab));
            }
          else
            {
              /* It really is worthwhile to have the section, so we'll
-                just have to look harder. This case can be executed
-                if we have line numbers but no functions (as can
-                happen in assembly source).  */
+                just have to look harder. This case can be executed
+                if we have line numbers but no functions (as can
+                happen in assembly source).  */
 
              scoped_restore_current_pspace_and_thread restore_pspace_thread;
              switch_to_program_space_and_thread (sal->pspace);
 
              bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
              if (msym.minsym)
-               sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
+               sal->section = msym.obj_section ();
            }
        }
     }
@@ -9470,8 +9699,8 @@ stopin_command (const char *arg, int from_tty)
       int hasColon = 0;
 
       /* Look for a ':'.  If this is a line number specification, then
-         say it is bad, otherwise, it should be an address or
-         function/method name.  */
+        say it is bad, otherwise, it should be an address or
+        function/method name.  */
       while (*argptr && !hasColon)
        {
          hasColon = (*argptr == ':');
@@ -9503,7 +9732,7 @@ stopat_command (const char *arg, int from_tty)
       int hasColon = 0;
 
       /* Look for a ':'.  If there is a '::' then get out, otherwise
-         it is probably a line number.  */
+        it is probably a line number.  */
       while (*argptr && !hasColon)
        {
          hasColon = (*argptr == ':');
@@ -9547,7 +9776,7 @@ dprintf_command (const char *arg, int from_tty)
 
   create_breakpoint (get_current_arch (),
                     location.get (),
-                    NULL, 0, arg, 1 /* parse arg */,
+                    NULL, 0, arg, false, 1 /* parse arg */,
                     0, bp_dprintf,
                     0 /* Ignore count */,
                     pending_break_support,
@@ -9837,122 +10066,20 @@ break_range_command (const char *arg, int from_tty)
   b->location_range_end = std::move (end_location);
   b->loc->length = length;
 
-  mention (b);
-  gdb::observers::breakpoint_created.notify (b);
-  update_global_location_list (UGLL_MAY_INSERT);
-}
-
-/*  Return non-zero if EXP is verified as constant.  Returned zero
-    means EXP is variable.  Also the constant detection may fail for
-    some constant expressions and in such case still falsely return
-    zero.  */
-
-static int
-watchpoint_exp_is_const (const struct expression *exp)
-{
-  int i = exp->nelts;
-
-  while (i > 0)
-    {
-      int oplenp, argsp;
-
-      /* We are only interested in the descriptor of each element.  */
-      operator_length (exp, i, &oplenp, &argsp);
-      i -= oplenp;
-
-      switch (exp->elts[i].opcode)
-       {
-       case BINOP_ADD:
-       case BINOP_SUB:
-       case BINOP_MUL:
-       case BINOP_DIV:
-       case BINOP_REM:
-       case BINOP_MOD:
-       case BINOP_LSH:
-       case BINOP_RSH:
-       case BINOP_LOGICAL_AND:
-       case BINOP_LOGICAL_OR:
-       case BINOP_BITWISE_AND:
-       case BINOP_BITWISE_IOR:
-       case BINOP_BITWISE_XOR:
-       case BINOP_EQUAL:
-       case BINOP_NOTEQUAL:
-       case BINOP_LESS:
-       case BINOP_GTR:
-       case BINOP_LEQ:
-       case BINOP_GEQ:
-       case BINOP_REPEAT:
-       case BINOP_COMMA:
-       case BINOP_EXP:
-       case BINOP_MIN:
-       case BINOP_MAX:
-       case BINOP_INTDIV:
-       case BINOP_CONCAT:
-       case TERNOP_COND:
-       case TERNOP_SLICE:
-
-       case OP_LONG:
-       case OP_FLOAT:
-       case OP_LAST:
-       case OP_COMPLEX:
-       case OP_STRING:
-       case OP_ARRAY:
-       case OP_TYPE:
-       case OP_TYPEOF:
-       case OP_DECLTYPE:
-       case OP_TYPEID:
-       case OP_NAME:
-       case OP_OBJC_NSSTRING:
-
-       case UNOP_NEG:
-       case UNOP_LOGICAL_NOT:
-       case UNOP_COMPLEMENT:
-       case UNOP_ADDR:
-       case UNOP_HIGH:
-       case UNOP_CAST:
-
-       case UNOP_CAST_TYPE:
-       case UNOP_REINTERPRET_CAST:
-       case UNOP_DYNAMIC_CAST:
-         /* Unary, binary and ternary operators: We have to check
-            their operands.  If they are constant, then so is the
-            result of that operation.  For instance, if A and B are
-            determined to be constants, then so is "A + B".
-
-            UNOP_IND is one exception to the rule above, because the
-            value of *ADDR is not necessarily a constant, even when
-            ADDR is.  */
-         break;
-
-       case OP_VAR_VALUE:
-         /* Check whether the associated symbol is a constant.
-
-            We use SYMBOL_CLASS rather than TYPE_CONST because it's
-            possible that a buggy compiler could mark a variable as
-            constant even when it is not, and TYPE_CONST would return
-            true in this case, while SYMBOL_CLASS wouldn't.
-
-            We also have to check for function symbols because they
-            are always constant.  */
-         {
-           struct symbol *s = exp->elts[i + 2].symbol;
-
-           if (SYMBOL_CLASS (s) != LOC_BLOCK
-               && SYMBOL_CLASS (s) != LOC_CONST
-               && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
-             return 0;
-           break;
-         }
-
-       /* The default action is to return 0 because we are using
-          the optimistic approach here: If we don't know something,
-          then it is not a constant.  */
-       default:
-         return 0;
-       }
-    }
+  mention (b);
+  gdb::observers::breakpoint_created.notify (b);
+  update_global_location_list (UGLL_MAY_INSERT);
+}
 
-  return 1;
+/*  Return non-zero if EXP is verified as constant.  Returned zero
+    means EXP is variable.  Also the constant detection may fail for
+    some constant expressions and in such case still falsely return
+    zero.  */
+
+static bool
+watchpoint_exp_is_const (const struct expression *exp)
+{
+  return exp->op->constant_p ();
 }
 
 /* Watchpoint destructor.  */
@@ -10268,7 +10395,7 @@ remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
   struct watchpoint *w = (struct watchpoint *) bl->owner;
 
   return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
-                                       bl->watchpoint_type);
+                                       bl->watchpoint_type);
 }
 
 /* Implement the "resources_needed" breakpoint_ops method for
@@ -10400,7 +10527,6 @@ static void
 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
 {
   struct watchpoint *w = (struct watchpoint *) b;
-  char tmp[40];
 
   switch (b->type)
     {
@@ -10418,8 +10544,8 @@ print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
                      _("Invalid hardware watchpoint type."));
     }
 
-  sprintf_vma (tmp, w->hw_wp_mask);
-  fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
+  fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string,
+                     phex (w->hw_wp_mask, sizeof (CORE_ADDR)));
   print_recreate_thread (b, fp);
 }
 
@@ -10436,11 +10562,11 @@ is_masked_watchpoint (const struct breakpoint *b)
 }
 
 /* accessflag:  hw_write:  watch write, 
-                hw_read:   watch read, 
+               hw_read:   watch read, 
                hw_access: watch access (read or write) */
 static void
 watch_command_1 (const char *arg, int accessflag, int from_tty,
-                int just_location, int internal)
+                bool just_location, bool internal)
 {
   struct breakpoint *scope_breakpoint = NULL;
   const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
@@ -10454,10 +10580,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
   const char *cond_end = NULL;
   enum bptype bp_type;
   int thread = -1;
-  int pc = 0;
   /* Flag to indicate whether we are going to use masks for
      the hardware watchpoint.  */
-  int use_mask = 0;
+  bool use_mask = false;
   CORE_ADDR mask = 0;
 
   /* Make sure that we actually have parameters to parse.  */
@@ -10524,7 +10649,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
              if (use_mask)
                error(_("You can specify only one mask."));
 
-             use_mask = just_location = 1;
+             use_mask = just_location = true;
 
              mark = value_mark ();
              mask_value = parse_to_comma_and_eval (&value_start);
@@ -10571,7 +10696,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
   exp_valid_block = tracker.block ();
   struct value *mark = value_mark ();
   struct value *val_as_value = nullptr;
-  fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL,
+  fetch_subexp_value (exp.get (), exp->op.get (), &val_as_value, &result, NULL,
                      just_location);
 
   if (val_as_value != NULL && just_location)
@@ -10640,7 +10765,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
          gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
          CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
 
-         scope_breakpoint
+         scope_breakpoint
            = create_internal_breakpoint (caller_arch, caller_pc,
                                          bp_watchpoint_scope,
                                          &momentary_breakpoint_ops);
@@ -10698,7 +10823,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
       CORE_ADDR addr = value_as_address (val.get ());
 
       w->exp_string_reparse
-       = current_language->la_watch_location_expression (t, addr).release ();
+       = current_language->watch_location_expression (t, addr).release ();
 
       w->exp_string = xstrprintf ("-location %.*s",
                                  (int) (exp_end - exp_start), exp_start);
@@ -10802,15 +10927,15 @@ can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
          else
            {
              /* Ahh, memory we actually used!  Check if we can cover
-                 it with hardware watchpoints.  */
+                it with hardware watchpoints.  */
              struct type *vtype = check_typedef (value_type (v));
 
              /* We only watch structs and arrays if user asked for it
                 explicitly, never if they just happen to appear in a
                 middle of some value chain.  */
              if (v == head
-                 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
-                     && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
+                 || (vtype->code () != TYPE_CODE_STRUCT
+                     && vtype->code () != TYPE_CODE_ARRAY))
                {
                  CORE_ADDR vaddr = value_address (v);
                  int len;
@@ -10841,25 +10966,79 @@ can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
 }
 
 void
-watch_command_wrapper (const char *arg, int from_tty, int internal)
+watch_command_wrapper (const char *arg, int from_tty, bool internal)
 {
   watch_command_1 (arg, hw_write, from_tty, 0, internal);
 }
 
+/* Options for the watch, awatch, and rwatch commands.  */
+
+struct watch_options
+{
+  /* For -location.  */
+  bool location = false;
+};
+
+/* Definitions of options for the "watch", "awatch", and "rwatch" commands.
+
+   Historically GDB always accepted both '-location' and '-l' flags for
+   these commands (both flags being synonyms).  When converting to the
+   newer option scheme only '-location' is added here.  That's fine (for
+   backward compatibility) as any non-ambiguous prefix of a flag will be
+   accepted, so '-l', '-loc', are now all accepted.
+
+   What this means is that, if in the future, we add any new flag here
+   that starts with '-l' then this will break backward compatibility, so
+   please, don't do that!  */
+
+static const gdb::option::option_def watch_option_defs[] = {
+  gdb::option::flag_option_def<watch_options> {
+    "location",
+    [] (watch_options *opt) { return &opt->location; },
+    N_("\
+This evaluates EXPRESSION and watches the memory to which is refers.\n\
+-l can be used as a short form of -location."),
+  },
+};
+
+/* Returns the option group used by 'watch', 'awatch', and 'rwatch'
+   commands.  */
+
+static gdb::option::option_def_group
+make_watch_options_def_group (watch_options *opts)
+{
+  return {{watch_option_defs}, opts};
+}
+
 /* A helper function that looks for the "-location" argument and then
    calls watch_command_1.  */
 
 static void
 watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
 {
-  int just_location = 0;
+  watch_options opts;
+  auto grp = make_watch_options_def_group (&opts);
+  gdb::option::process_options
+    (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
+  if (arg != nullptr && *arg == '\0')
+    arg = nullptr;
 
-  if (arg
-      && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
-         || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
-    just_location = 1;
+  watch_command_1 (arg, accessflag, from_tty, opts.location, false);
+}
+
+/* Command completion for 'watch', 'awatch', and 'rwatch' commands.   */
+static void
+watch_command_completer (struct cmd_list_element *ignore,
+                        completion_tracker &tracker,
+                        const char *text, const char * /*word*/)
+{
+  const auto group = make_watch_options_def_group (nullptr);
+  if (gdb::option::complete_options
+      (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
+    return;
 
-  watch_command_1 (arg, accessflag, from_tty, just_location, 0);
+  const char *word = advance_to_expression_complete_word_point (tracker, text);
+  expression_completer (ignore, tracker, text, word);
 }
 
 static void
@@ -10869,7 +11048,7 @@ watch_command (const char *arg, int from_tty)
 }
 
 void
-rwatch_command_wrapper (const char *arg, int from_tty, int internal)
+rwatch_command_wrapper (const char *arg, int from_tty, bool internal)
 {
   watch_command_1 (arg, hw_read, from_tty, 0, internal);
 }
@@ -10881,7 +11060,7 @@ rwatch_command (const char *arg, int from_tty)
 }
 
 void
-awatch_command_wrapper (const char *arg, int from_tty, int internal)
+awatch_command_wrapper (const char *arg, int from_tty, bool internal)
 {
   watch_command_1 (arg, hw_access, from_tty, 0, internal);
 }
@@ -10902,20 +11081,15 @@ struct until_break_fsm : public thread_fsm
   /* The thread that was current when the command was executed.  */
   int thread;
 
-  /* The breakpoint set at the destination location.  */
-  breakpoint_up location_breakpoint;
-
-  /* Breakpoint set at the return address in the caller frame.  May be
-     NULL.  */
-  breakpoint_up caller_breakpoint;
+  /* The breakpoint set at the return address in the caller frame,
+     plus breakpoints at all the destination locations.  */
+  std::vector<breakpoint_up> breakpoints;
 
   until_break_fsm (struct interp *cmd_interp, int thread,
-                  breakpoint_up &&location_breakpoint,
-                  breakpoint_up &&caller_breakpoint)
+                  std::vector<breakpoint_up> &&breakpoints)
     : thread_fsm (cmd_interp),
       thread (thread),
-      location_breakpoint (std::move (location_breakpoint)),
-      caller_breakpoint (std::move (caller_breakpoint))
+      breakpoints (std::move (breakpoints))
   {
   }
 
@@ -10930,12 +11104,13 @@ struct until_break_fsm : public thread_fsm
 bool
 until_break_fsm::should_stop (struct thread_info *tp)
 {
-  if (bpstat_find_breakpoint (tp->control.stop_bpstat,
-                             location_breakpoint.get ()) != NULL
-      || (caller_breakpoint != NULL
-         && bpstat_find_breakpoint (tp->control.stop_bpstat,
-                                    caller_breakpoint.get ()) != NULL))
-    set_finished ();
+  for (const breakpoint_up &bp : breakpoints)
+    if (bpstat_find_breakpoint (tp->control.stop_bpstat,
+                               bp.get ()) != NULL)
+      {
+       set_finished ();
+       break;
+      }
 
   return true;
 }
@@ -10947,8 +11122,7 @@ void
 until_break_fsm::clean_up (struct thread_info *)
 {
   /* Clean up our temporary breakpoints.  */
-  location_breakpoint.reset ();
-  caller_breakpoint.reset ();
+  breakpoints.clear ();
   delete_longjmp_breakpoint (thread);
 }
 
@@ -10986,16 +11160,12 @@ until_break_command (const char *arg, int from_tty, int anywhere)
        : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
                        NULL, NULL, 0));
 
-  if (sals.size () != 1)
+  if (sals.empty ())
     error (_("Couldn't get information on specified line."));
 
-  symtab_and_line &sal = sals[0];
-
   if (*arg)
     error (_("Junk at end of arguments."));
 
-  resolve_sal_pc (&sal);
-
   tp = inferior_thread ();
   thread = tp->global_num;
 
@@ -11012,7 +11182,7 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   /* Keep within the current frame, or in frames called by the current
      one.  */
 
-  breakpoint_up caller_breakpoint;
+  std::vector<breakpoint_up> breakpoints;
 
   gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter;
 
@@ -11024,10 +11194,11 @@ until_break_command (const char *arg, int from_tty, int anywhere)
       sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
       sal2.pc = frame_unwind_caller_pc (frame);
       caller_gdbarch = frame_unwind_caller_arch (frame);
-      caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
-                                                   sal2,
-                                                   caller_frame_id,
-                                                   bp_until);
+
+      breakpoint_up caller_breakpoint
+       = set_momentary_breakpoint (caller_gdbarch, sal2,
+                                   caller_frame_id, bp_until);
+      breakpoints.emplace_back (std::move (caller_breakpoint));
 
       set_longjmp_breakpoint (tp, caller_frame_id);
       lj_deleter.emplace (thread);
@@ -11036,21 +11207,24 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   /* set_momentary_breakpoint could invalidate FRAME.  */
   frame = NULL;
 
-  breakpoint_up location_breakpoint;
-  if (anywhere)
-    /* If the user told us to continue until a specified location,
-       we don't specify a frame at which we need to stop.  */
-    location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
-                                                   null_frame_id, bp_until);
-  else
-    /* Otherwise, specify the selected frame, because we want to stop
-       only at the very same frame.  */
-    location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
-                                                   stack_frame_id, bp_until);
+  /* If the user told us to continue until a specified location, we
+     don't specify a frame at which we need to stop.  Otherwise,
+     specify the selected frame, because we want to stop only at the
+     very same frame.  */
+  frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id;
+
+  for (symtab_and_line &sal : sals)
+    {
+      resolve_sal_pc (&sal);
+
+      breakpoint_up location_breakpoint
+       = set_momentary_breakpoint (frame_gdbarch, sal,
+                                   stop_frame_id, bp_until);
+      breakpoints.emplace_back (std::move (location_breakpoint));
+    }
 
   tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num,
-                                       std::move (location_breakpoint),
-                                       std::move (caller_breakpoint));
+                                       std::move (breakpoints));
 
   if (lj_deleter)
     lj_deleter->release ();
@@ -11106,11 +11280,10 @@ catch_fork_command_1 (const char *arg, int from_tty,
   struct gdbarch *gdbarch = get_current_arch ();
   const char *cond_string = NULL;
   catch_fork_kind fork_kind;
-  int tempflag;
 
-  fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
-  tempflag = (fork_kind == catch_fork_temporary
-             || fork_kind == catch_vfork_temporary);
+  fork_kind = (catch_fork_kind) (uintptr_t) command->context ();
+  bool temp = (fork_kind == catch_fork_temporary
+              || fork_kind == catch_vfork_temporary);
 
   if (!arg)
     arg = "";
@@ -11132,13 +11305,13 @@ catch_fork_command_1 (const char *arg, int from_tty,
     {
     case catch_fork_temporary:
     case catch_fork_permanent:
-      create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
-                                          &catch_fork_breakpoint_ops);
+      create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string,
+                                         &catch_fork_breakpoint_ops);
       break;
     case catch_vfork_temporary:
     case catch_vfork_permanent:
-      create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
-                                          &catch_vfork_breakpoint_ops);
+      create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string,
+                                         &catch_vfork_breakpoint_ops);
       break;
     default:
       error (_("unsupported or unknown fork kind; cannot catch it"));
@@ -11151,10 +11324,8 @@ catch_exec_command_1 (const char *arg, int from_tty,
                      struct cmd_list_element *command)
 {
   struct gdbarch *gdbarch = get_current_arch ();
-  int tempflag;
   const char *cond_string = NULL;
-
-  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+  bool temp = command->context () == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
@@ -11171,7 +11342,7 @@ catch_exec_command_1 (const char *arg, int from_tty,
     error (_("Junk at end of arguments."));
 
   std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
-  init_catchpoint (c.get (), gdbarch, tempflag, cond_string,
+  init_catchpoint (c.get (), gdbarch, temp, cond_string,
                   &catch_exec_breakpoint_ops);
   c->exec_pathname = NULL;
 
@@ -11197,13 +11368,13 @@ init_ada_exception_breakpoint (struct breakpoint *b,
       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.
-         In this case, a "breakpoint ... also set at..." warning is
-         unproductive.  Besides, the warning phrasing is also a bit
-         inappropriate, we should use the word catchpoint, and tell
-         the user what type of catchpoint it is.  The above is good
-         enough for now, though.  */
+        version for exception catchpoints, because two catchpoints
+        used for different exception names will use the same address.
+        In this case, a "breakpoint ... also set at..." warning is
+        unproductive.  Besides, the warning phrasing is also a bit
+        inappropriate, we should use the word catchpoint, and tell
+        the user what type of catchpoint it is.  The above is good
+        enough for now, though.  */
     }
 
   init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
@@ -11215,19 +11386,8 @@ init_ada_exception_breakpoint (struct breakpoint *b,
   b->language = language_ada;
 }
 
-static void
-catch_command (const char *arg, int from_tty)
-{
-  error (_("Catch requires an event name."));
-}
 \f
 
-static void
-tcatch_command (const char *arg, int from_tty)
-{
-  error (_("Catch requires an event name."));
-}
-
 /* Compare two breakpoints and return a strcmp-like result.  */
 
 static int
@@ -11253,7 +11413,6 @@ compare_breakpoints (const breakpoint *a, const breakpoint *b)
 static void
 clear_command (const char *arg, int from_tty)
 {
-  struct breakpoint *b;
   int default_match;
 
   std::vector<symtab_and_line> decoded_sals;
@@ -11309,29 +11468,28 @@ clear_command (const char *arg, int from_tty)
       const char *sal_fullname;
 
       /* If exact pc given, clear bpts at that pc.
-         If line given (pc == 0), clear all bpts on specified line.
-         If defaulting, clear all bpts on default line
-         or at default pc.
+        If line given (pc == 0), clear all bpts on specified line.
+        If defaulting, clear all bpts on default line
+        or at default pc.
 
-         defaulting    sal.pc != 0    tests to do
+        defaulting    sal.pc != 0    tests to do
 
-         0              1             pc
-         1              1             pc _and_ line
-         0              0             line
-         1              0             <can't happen> */
+        0              1             pc
+        1              1             pc _and_ line
+        0              0             line
+        1              0             <can't happen> */
 
       sal_fullname = (sal.symtab == NULL
                      ? NULL : symtab_to_fullname (sal.symtab));
 
       /* Find all matching breakpoints and add them to 'found'.  */
-      ALL_BREAKPOINTS (b)
+      for (breakpoint *b : all_breakpoints ())
        {
          int match = 0;
          /* Are we going to delete b?  */
          if (b->type != bp_none && !is_watchpoint (b))
            {
-             struct bp_location *loc = b->loc;
-             for (; loc; loc = loc->next)
+             for (bp_location *loc : b->locations ())
                {
                  /* If the user specified file:line, don't allow a PC
                     match.  This matches historical gdb behavior.  */
@@ -11414,19 +11572,15 @@ clear_command (const char *arg, int from_tty)
 void
 breakpoint_auto_delete (bpstat bs)
 {
-  struct breakpoint *b, *b_tmp;
-
   for (; bs; bs = bs->next)
     if (bs->breakpoint_at
        && bs->breakpoint_at->disposition == disp_del
        && bs->stop)
       delete_breakpoint (bs->breakpoint_at);
 
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
-  {
+  for (breakpoint *b : all_breakpoints_safe ())
     if (b->disposition == disp_del_at_next_stop)
       delete_breakpoint (b);
-  }
 }
 
 /* A comparison function for bp_location AP and BP being interfaced to
@@ -11452,6 +11606,18 @@ bp_location_is_less_than (const bp_location *a, const bp_location *b)
   if (a->permanent != b->permanent)
     return a->permanent > b->permanent;
 
+  /* Sort by type in order to make duplicate determination easier.
+     See update_global_location_list.  This is kept in sync with
+     breakpoint_locations_match.  */
+  if (a->loc_type < b->loc_type)
+    return true;
+
+  /* Likewise, for range-breakpoints, sort by length.  */
+  if (a->loc_type == bp_loc_hardware_breakpoint
+      && b->loc_type == bp_loc_hardware_breakpoint
+      && a->length < b->length)
+    return true;
+
   /* Make the internal GDB representation stable across GDB runs
      where A and B memory inside GDB can differ.  Breakpoint locations of
      the same type at the same address can be sorted in arbitrary order.  */
@@ -11469,12 +11635,10 @@ bp_location_is_less_than (const bp_location *a, const bp_location *b)
 static void
 bp_locations_target_extensions_update (void)
 {
-  struct bp_location *bl, **blp_tmp;
-
   bp_locations_placed_address_before_address_max = 0;
   bp_locations_shadow_len_after_address_max = 0;
 
-  ALL_BP_LOCATIONS (bl, blp_tmp)
+  for (bp_location *bl : all_bp_locations ())
     {
       CORE_ADDR start, end, addr;
 
@@ -11503,14 +11667,12 @@ bp_locations_target_extensions_update (void)
 static void
 download_tracepoint_locations (void)
 {
-  struct breakpoint *b;
   enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
 
   scoped_restore_current_pspace_and_thread restore_pspace_thread;
 
-  ALL_TRACEPOINTS (b)
+  for (breakpoint *b : all_tracepoints ())
     {
-      struct bp_location *bl;
       struct tracepoint *t;
       int bp_location_downloaded = 0;
 
@@ -11530,7 +11692,7 @@ download_tracepoint_locations (void)
       if (can_download_tracepoint == TRIBOOL_FALSE)
        break;
 
-      for (bl = b->loc; bl; bl = bl->next)
+      for (bp_location *bl : b->locations ())
        {
          /* In tracepoint, locations are _never_ duplicated, so
             should_be_inserted is equivalent to
@@ -11586,8 +11748,6 @@ swap_insertion (struct bp_location *left, struct bp_location *right)
 static void
 force_breakpoint_reinsertion (struct bp_location *bl)
 {
-  struct bp_location **locp = NULL, **loc2p;
-  struct bp_location *loc;
   CORE_ADDR address = 0;
   int pspace_num;
 
@@ -11606,10 +11766,8 @@ force_breakpoint_reinsertion (struct bp_location *bl)
      the same program space as the location
      as "its condition has changed".  We need to
      update the conditions on the target's side.  */
-  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
+  for (bp_location *loc : all_bp_locations_at_addr (address))
     {
-      loc = *loc2p;
-
       if (!is_breakpoint (loc->owner)
          || pspace_num != loc->pspace->num)
        continue;
@@ -11626,6 +11784,7 @@ force_breakpoint_reinsertion (struct bp_location *bl)
       loc->cond_bytecode.reset ();
     }
 }
+
 /* Called whether new breakpoints are created, or existing breakpoints
    deleted, to update the global location list and recompute which
    locations are duplicate of which.
@@ -11637,8 +11796,6 @@ force_breakpoint_reinsertion (struct bp_location *bl)
 static void
 update_global_location_list (enum ugll_insert_mode insert_mode)
 {
-  struct breakpoint *b;
-  struct bp_location **locp, *loc;
   /* Last breakpoint location address that was marked for update.  */
   CORE_ADDR last_addr = 0;
   /* Last breakpoint location program space that was marked for update.  */
@@ -11657,24 +11814,22 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
 
   /* Saved former bp_locations array which we compare against the newly
      built bp_locations from the current state of ALL_BREAKPOINTS.  */
-  struct bp_location **old_locp;
-  unsigned old_locations_count;
-  gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations);
-
-  old_locations_count = bp_locations_count;
-  bp_locations = NULL;
-  bp_locations_count = 0;
-
-  ALL_BREAKPOINTS (b)
-    for (loc = b->loc; loc; loc = loc->next)
-      bp_locations_count++;
-
-  bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
-  locp = bp_locations;
-  ALL_BREAKPOINTS (b)
-    for (loc = b->loc; loc; loc = loc->next)
-      *locp++ = loc;
-  std::sort (bp_locations, bp_locations + bp_locations_count,
+  std::vector<bp_location *> old_locations = std::move (bp_locations);
+  bp_locations.clear ();
+
+  for (breakpoint *b : all_breakpoints ())
+    for (bp_location *loc : b->locations ())
+      bp_locations.push_back (loc);
+
+  /* See if we need to "upgrade" a software breakpoint to a hardware
+     breakpoint.  Do this before deciding whether locations are
+     duplicates.  Also do this before sorting because sorting order
+     depends on location type.  */
+  for (bp_location *loc : bp_locations)
+    if (!loc->inserted && should_be_inserted (loc))
+       handle_automatic_hardware_breakpoints (loc);
+
+  std::sort (bp_locations.begin (), bp_locations.end (),
             bp_location_is_less_than);
 
   bp_locations_target_extensions_update ();
@@ -11689,14 +11844,9 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
      LOCP is kept in sync with OLD_LOCP, each pointing to the current
      and former bp_location array state respectively.  */
 
-  locp = bp_locations;
-  for (old_locp = old_locations.get ();
-       old_locp < old_locations.get () + old_locations_count;
-       old_locp++)
+  size_t loc_i = 0;
+  for (bp_location *old_loc : old_locations)
     {
-      struct bp_location *old_loc = *old_locp;
-      struct bp_location **loc2p;
-
       /* Tells if 'old_loc' is found among the new locations.  If
         not, we have to free it.  */
       int found_object = 0;
@@ -11706,28 +11856,28 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
 
       /* Skip LOCP entries which will definitely never be needed.
         Stop either at or being the one matching OLD_LOC.  */
-      while (locp < bp_locations + bp_locations_count
-            && (*locp)->address < old_loc->address)
-       locp++;
+      while (loc_i < bp_locations.size ()
+            && bp_locations[loc_i]->address < old_loc->address)
+       loc_i++;
 
-      for (loc2p = locp;
-          (loc2p < bp_locations + bp_locations_count
-           && (*loc2p)->address == old_loc->address);
-          loc2p++)
+      for (size_t loc2_i = loc_i;
+          (loc2_i < bp_locations.size ()
+           && bp_locations[loc2_i]->address == old_loc->address);
+          loc2_i++)
        {
          /* Check if this is a new/duplicated location or a duplicated
             location that had its condition modified.  If so, we want to send
             its condition to the target if evaluation of conditions is taking
             place there.  */
-         if ((*loc2p)->condition_changed == condition_modified
+         if (bp_locations[loc2_i]->condition_changed == condition_modified
              && (last_addr != old_loc->address
                  || last_pspace_num != old_loc->pspace->num))
            {
-             force_breakpoint_reinsertion (*loc2p);
+             force_breakpoint_reinsertion (bp_locations[loc2_i]);
              last_pspace_num = old_loc->pspace->num;
            }
 
-         if (*loc2p == old_loc)
+         if (bp_locations[loc2_i] == old_loc)
            found_object = 1;
        }
 
@@ -11770,12 +11920,15 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
              /* OLD_LOC comes from existing struct breakpoint.  */
              if (bl_address_is_meaningful (old_loc))
                {
-                 for (loc2p = locp;
-                      (loc2p < bp_locations + bp_locations_count
-                       && (*loc2p)->address == old_loc->address);
-                      loc2p++)
+                 for (size_t loc2_i = loc_i;
+                      (loc2_i < bp_locations.size ()
+                       && bp_locations[loc2_i]->address == old_loc->address);
+                      loc2_i++)
                    {
-                     struct bp_location *loc2 = *loc2p;
+                     bp_location *loc2 = bp_locations[loc2_i];
+
+                     if (loc2 == old_loc)
+                       continue;
 
                      if (breakpoint_locations_match (loc2, old_loc))
                        {
@@ -11791,8 +11944,7 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
                          /* loc2 is a duplicated location. We need to check
                             if it should be inserted in case it will be
                             unduplicated.  */
-                         if (loc2 != old_loc
-                             && unduplicated_should_be_inserted (loc2))
+                         if (unduplicated_should_be_inserted (loc2))
                            {
                              swap_insertion (old_loc, loc2);
                              keep_in_target = 1;
@@ -11911,12 +12063,13 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
   wp_loc_first = NULL;
   awp_loc_first = NULL;
   rwp_loc_first = NULL;
-  ALL_BP_LOCATIONS (loc, locp)
+
+  for (bp_location *loc : all_bp_locations ())
     {
       /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
         non-NULL.  */
       struct bp_location **loc_first_p;
-      b = loc->owner;
+      breakpoint *b = loc->owner;
 
       if (!unduplicated_should_be_inserted (loc)
          || !bl_address_is_meaningful (loc)
@@ -12128,6 +12281,13 @@ breakpoint::~breakpoint ()
   xfree (this->extra_string);
 }
 
+/* See breakpoint.h.  */
+
+bp_locations_range breakpoint::locations ()
+{
+  return bp_locations_range (this->loc);
+}
+
 static struct bp_location *
 base_breakpoint_allocate_location (struct breakpoint *self)
 {
@@ -12216,7 +12376,7 @@ base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
 
 static void
 base_breakpoint_create_sals_from_location
-  (const struct event_location *location,
+  (struct event_location *location,
    struct linespec_result *canonical,
    enum bptype type_wanted)
 {
@@ -12241,7 +12401,7 @@ base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
 
 static std::vector<symtab_and_line>
 base_breakpoint_decode_location (struct breakpoint *b,
-                                const struct event_location *location,
+                                struct event_location *location,
                                 struct program_space *search_pspace)
 {
   internal_error_pure_virtual_called ();
@@ -12380,7 +12540,7 @@ bkpt_print_it (bpstat bs)
 
   gdb_assert (bs->bp_location_at != NULL);
 
-  bl = bs->bp_location_at;
+  bl = bs->bp_location_at.get ();
   b = bs->breakpoint_at;
 
   bp_temp = b->disposition == disp_del;
@@ -12464,7 +12624,7 @@ bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
 }
 
 static void
-bkpt_create_sals_from_location (const struct event_location *location,
+bkpt_create_sals_from_location (struct event_location *location,
                                struct linespec_result *canonical,
                                enum bptype type_wanted)
 {
@@ -12495,7 +12655,7 @@ bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
 
 static std::vector<symtab_and_line>
 bkpt_decode_location (struct breakpoint *b,
-                     const struct event_location *location,
+                     struct event_location *location,
                      struct program_space *search_pspace)
 {
   return decode_location_default (b, location, search_pspace);
@@ -12518,7 +12678,7 @@ internal_bkpt_re_set (struct breakpoint *b)
       break;
 
       /* This breakpoint is special, it's set up when the inferior
-         starts and we really don't want to touch it.  */
+        starts and we really don't want to touch it.  */
     case bp_shlib_event:
 
       /* Like bp_shlib_event, this breakpoint type is special.  Once
@@ -12668,7 +12828,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
 }
 
 static void
-bkpt_probe_create_sals_from_location (const struct event_location *location,
+bkpt_probe_create_sals_from_location (struct event_location *location,
                                      struct linespec_result *canonical,
                                      enum bptype type_wanted)
 {
@@ -12682,7 +12842,7 @@ bkpt_probe_create_sals_from_location (const struct event_location *location,
 
 static std::vector<symtab_and_line>
 bkpt_probe_decode_location (struct breakpoint *b,
-                           const struct event_location *location,
+                           struct event_location *location,
                            struct program_space *search_pspace)
 {
   std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
@@ -12776,7 +12936,7 @@ tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
 }
 
 static void
-tracepoint_create_sals_from_location (const struct event_location *location,
+tracepoint_create_sals_from_location (struct event_location *location,
                                      struct linespec_result *canonical,
                                      enum bptype type_wanted)
 {
@@ -12807,7 +12967,7 @@ tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
 
 static std::vector<symtab_and_line>
 tracepoint_decode_location (struct breakpoint *b,
-                           const struct event_location *location,
+                           struct event_location *location,
                            struct program_space *search_pspace)
 {
   return decode_location_default (b, location, search_pspace);
@@ -12819,7 +12979,7 @@ struct breakpoint_ops tracepoint_breakpoint_ops;
 
 static void
 tracepoint_probe_create_sals_from_location
-  (const struct event_location *location,
+  (struct event_location *location,
    struct linespec_result *canonical,
    enum bptype type_wanted)
 {
@@ -12829,7 +12989,7 @@ tracepoint_probe_create_sals_from_location
 
 static std::vector<symtab_and_line>
 tracepoint_probe_decode_location (struct breakpoint *b,
-                                 const struct event_location *location,
+                                 struct event_location *location,
                                  struct program_space *search_pspace)
 {
   /* We use the same method for breakpoint on probes.  */
@@ -12910,7 +13070,7 @@ dprintf_after_condition_true (struct bpstats *bs)
    markers (`-m').  */
 
 static void
-strace_marker_create_sals_from_location (const struct event_location *location,
+strace_marker_create_sals_from_location (struct event_location *location,
                                         struct linespec_result *canonical,
                                         enum bptype type_wanted)
 {
@@ -12980,7 +13140,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
 
 static std::vector<symtab_and_line>
 strace_marker_decode_location (struct breakpoint *b,
-                              const struct event_location *location,
+                              struct event_location *location,
                               struct program_space *search_pspace)
 {
   struct tracepoint *tp = (struct tracepoint *) b;
@@ -13011,8 +13171,6 @@ strace_marker_p (struct breakpoint *b)
 void
 delete_breakpoint (struct breakpoint *bpt)
 {
-  struct breakpoint *b;
-
   gdb_assert (bpt != NULL);
 
   /* Has this bp already been deleted?  This can happen because
@@ -13067,12 +13225,12 @@ delete_breakpoint (struct breakpoint *bpt)
   if (breakpoint_chain == bpt)
     breakpoint_chain = bpt->next;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     if (b->next == bpt)
-    {
-      b->next = bpt->next;
-      break;
-    }
+      {
+       b->next = bpt->next;
+       break;
+      }
 
   /* Be sure no bpstat's are pointing at the breakpoint after it's
      been freed.  */
@@ -13138,8 +13296,6 @@ iterate_over_related_breakpoints (struct breakpoint *b,
 static void
 delete_command (const char *arg, int from_tty)
 {
-  struct breakpoint *b, *b_tmp;
-
   dont_repeat ();
 
   if (arg == 0)
@@ -13147,9 +13303,9 @@ delete_command (const char *arg, int from_tty)
       int breaks_to_delete = 0;
 
       /* Delete all breakpoints if no argument.  Do not delete
-         internal breakpoints, these have to be deleted with an
-         explicit breakpoint number argument.  */
-      ALL_BREAKPOINTS (b)
+        internal breakpoints, these have to be deleted with an
+        explicit breakpoint number argument.  */
+      for (breakpoint *b : all_breakpoints ())
        if (user_breakpoint_p (b))
          {
            breaks_to_delete = 1;
@@ -13159,11 +13315,9 @@ delete_command (const char *arg, int from_tty)
       /* Ask user only if there are some breakpoints to delete.  */
       if (!from_tty
          || (breaks_to_delete && query (_("Delete all breakpoints? "))))
-       {
-         ALL_BREAKPOINTS_SAFE (b, b_tmp)
-           if (user_breakpoint_p (b))
-             delete_breakpoint (b);
-       }
+       for (breakpoint *b : all_breakpoints_safe ())
+         if (user_breakpoint_p (b))
+           delete_breakpoint (b);
     }
   else
     map_breakpoint_numbers
@@ -13180,9 +13334,7 @@ delete_command (const char *arg, int from_tty)
 static int
 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
 {
-  struct bp_location *loc;
-
-  for (loc = b->loc; loc != NULL; loc = loc->next)
+  for (bp_location *loc : b->locations ())
     if ((pspace == NULL
         || loc->pspace == pspace)
        && !loc->shlib_disabled
@@ -13199,8 +13351,8 @@ static int
 ambiguous_names_p (struct bp_location *loc)
 {
   struct bp_location *l;
-  htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL,
-                                  xcalloc, xfree);
+  htab_up htab (htab_create_alloc (13, htab_hash_string, htab_eq_string, NULL,
+                                  xcalloc, xfree));
 
   for (l = loc; l != NULL; l = l->next)
     {
@@ -13211,19 +13363,15 @@ ambiguous_names_p (struct bp_location *loc)
       if (name == NULL)
        continue;
 
-      slot = (const char **) htab_find_slot (htab, (const void *) name,
+      slot = (const char **) htab_find_slot (htab.get (), (const void *) name,
                                             INSERT);
       /* NOTE: We can assume slot != NULL here because xcalloc never
         returns NULL.  */
       if (*slot != NULL)
-       {
-         htab_delete (htab);
-         return 1;
-       }
+       return 1;
       *slot = name;
     }
 
-  htab_delete (htab);
   return 0;
 }
 
@@ -13368,6 +13516,9 @@ locations_are_equal (struct bp_location *a, struct bp_location *b)
       if (a->enabled != b->enabled)
        return 0;
 
+      if (a->disabled_by_cond != b->disabled_by_cond)
+       return 0;
+
       a = a->next;
       b = b->next;
     }
@@ -13475,10 +13626,7 @@ update_breakpoint_locations (struct breakpoint *b,
            }
          catch (const gdb_exception_error &e)
            {
-             warning (_("failed to reevaluate condition "
-                        "for breakpoint %d: %s"), 
-                      b->number, e.what ());
-             new_loc->enabled = 0;
+             new_loc->disabled_by_cond = true;
            }
        }
 
@@ -13503,25 +13651,35 @@ update_breakpoint_locations (struct breakpoint *b,
 
     for (; e; e = e->next)
       {
-       if (!e->enabled && e->function_name)
+       if ((!e->enabled || e->disabled_by_cond) && e->function_name)
          {
-           struct bp_location *l = b->loc;
            if (have_ambiguous_names)
              {
-               for (; l; l = l->next)
-                 if (breakpoint_locations_match (e, l))
-                   {
-                     l->enabled = 0;
-                     break;
-                   }
+               for (bp_location *l : b->locations ())
+                 {
+                   /* Ignore software vs hardware location type at
+                      this point, because with "set breakpoint
+                      auto-hw", after a re-set, locations that were
+                      hardware can end up as software, or vice versa.
+                      As mentioned above, this is an heuristic and in
+                      practice should give the correct answer often
+                      enough.  */
+                   if (breakpoint_locations_match (e, l, true))
+                     {
+                       l->enabled = e->enabled;
+                       l->disabled_by_cond = e->disabled_by_cond;
+                       break;
+                     }
+                 }
              }
            else
              {
-               for (; l; l = l->next)
+               for (bp_location *l : b->locations ())
                  if (l->function_name
                      && strcmp (e->function_name, l->function_name) == 0)
                    {
-                     l->enabled = 0;
+                     l->enabled = e->enabled;
+                     l->disabled_by_cond = e->disabled_by_cond;
                      break;
                    }
              }
@@ -13595,9 +13753,9 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
          char *cond_string, *extra_string;
          int thread, task;
 
-         find_condition_and_thread (b->extra_string, sals[0].pc,
-                                    &cond_string, &thread, &task,
-                                    &extra_string);
+         find_condition_and_thread_for_sals (sals, b->extra_string,
+                                             &cond_string, &thread,
+                                             &task, &extra_string);
          gdb_assert (b->cond_string == NULL);
          if (cond_string)
            b->cond_string = cond_string;
@@ -13654,7 +13812,7 @@ breakpoint_re_set_default (struct breakpoint *b)
    calls parse_breakpoint_sals.  Return 1 for success, zero for failure.  */
 
 static void
-create_sals_from_location_default (const struct event_location *location,
+create_sals_from_location_default (struct event_location *location,
                                   struct linespec_result *canonical,
                                   enum bptype type_wanted)
 {
@@ -13691,7 +13849,7 @@ create_breakpoints_sal_default (struct gdbarch *gdbarch,
 
 static std::vector<symtab_and_line>
 decode_location_default (struct breakpoint *b,
-                        const struct event_location *location,
+                        struct event_location *location,
                         struct program_space *search_pspace)
 {
   struct linespec_result canonical;
@@ -13728,8 +13886,6 @@ breakpoint_re_set_one (breakpoint *b)
 void
 breakpoint_re_set (void)
 {
-  struct breakpoint *b, *b_tmp;
-
   {
     scoped_restore_current_language save_language;
     scoped_restore save_input_radix = make_scoped_restore (&input_radix);
@@ -13753,7 +13909,7 @@ breakpoint_re_set (void)
        breakpoint 1, we'd insert the locations of breakpoint 2, which
        hadn't been re-set yet, and thus may have stale locations.  */
 
-    ALL_BREAKPOINTS_SAFE (b, b_tmp)
+    for (breakpoint *b : all_breakpoints_safe ())
       {
        try
          {
@@ -13805,40 +13961,38 @@ breakpoint_re_set_thread (struct breakpoint *b)
 void
 set_ignore_count (int bptnum, int count, int from_tty)
 {
-  struct breakpoint *b;
-
   if (count < 0)
     count = 0;
 
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     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)
-       {
-         if (count == 0)
-           printf_filtered (_("Will stop next time "
-                              "breakpoint %d is reached."),
-                            bptnum);
-         else if (count == 1)
-           printf_filtered (_("Will ignore next crossing of breakpoint %d."),
-                            bptnum);
-         else
-           printf_filtered (_("Will ignore next %d "
-                              "crossings of breakpoint %d."),
-                            count, bptnum);
-       }
-      gdb::observers::breakpoint_modified.notify (b);
-      return;
-    }
+      {
+       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)
+         {
+           if (count == 0)
+             printf_filtered (_("Will stop next time "
+                                "breakpoint %d is reached."),
+                              bptnum);
+           else if (count == 1)
+             printf_filtered (_("Will ignore next crossing of breakpoint %d."),
+                              bptnum);
+           else
+             printf_filtered (_("Will ignore next %d "
+                                "crossings of breakpoint %d."),
+                              count, bptnum);
+         }
+       gdb::observers::breakpoint_modified.notify (b);
+       return;
+      }
 
   error (_("No breakpoint number %d."), bptnum);
 }
@@ -13882,13 +14036,11 @@ map_breakpoint_number_range (std::pair<int, int> bp_num_range,
     }
   else
     {
-      struct breakpoint *b, *tmp;
-
       for (int i = bp_num_range.first; i <= bp_num_range.second; i++)
        {
          bool match = false;
 
-         ALL_BREAKPOINTS_SAFE (b, tmp)
+         for (breakpoint *b : all_breakpoints_safe ())
            if (b->number == i)
              {
                match = true;
@@ -13926,13 +14078,7 @@ map_breakpoint_numbers (const char *args,
 static struct bp_location *
 find_location_by_number (int bp_num, int loc_num)
 {
-  struct breakpoint *b;
-
-  ALL_BREAKPOINTS (b)
-    if (b->number == bp_num)
-      {
-       break;
-      }
+  breakpoint *b = get_breakpoint (bp_num);
 
   if (!b || b->number != bp_num)
     error (_("Bad breakpoint number '%d'"), bp_num);
@@ -13941,7 +14087,7 @@ find_location_by_number (int bp_num, int loc_num)
     error (_("Bad breakpoint location number '%d'"), loc_num);
 
   int n = 0;
-  for (bp_location *loc = b->loc; loc != NULL; loc = loc->next)
+  for (bp_location *loc : b->locations ())
     if (++n == loc_num)
       return loc;
 
@@ -14082,6 +14228,10 @@ enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
   struct bp_location *loc = find_location_by_number (bp_num, loc_num);
   if (loc != NULL)
     {
+      if (loc->disabled_by_cond && enable)
+       error (_("Breakpoint %d's condition is invalid at location %d, "
+                "cannot enable."), bp_num, loc_num);
+
       if (loc->enabled != enable)
        {
          loc->enabled = enable;
@@ -14133,9 +14283,7 @@ disable_breakpoint (struct breakpoint *bpt)
   if (target_supports_enable_disable_tracepoint ()
       && current_trace_status ()->running && is_tracepoint (bpt))
     {
-      struct bp_location *location;
-     
-      for (location = bpt->loc; location; location = location->next)
+      for (bp_location *location : bpt->locations ())
        target_disable_tracepoint (location);
     }
 
@@ -14154,9 +14302,7 @@ enable_disable_command (const char *args, int from_tty, bool enable)
 {
   if (args == 0)
     {
-      struct breakpoint *bpt;
-
-      ALL_BREAKPOINTS (bpt)
+      for (breakpoint *bpt : all_breakpoints ())
        if (user_breakpoint_p (bpt))
          {
            if (enable)
@@ -14256,9 +14402,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
   if (target_supports_enable_disable_tracepoint ()
       && current_trace_status ()->running && is_tracepoint (bpt))
     {
-      struct bp_location *location;
-
-      for (location = bpt->loc; location; location = location->next)
+      for (bp_location *location : bpt->locations ())
        target_enable_tracepoint (location);
     }
 
@@ -14336,16 +14480,6 @@ enable_delete_command (const char *args, int from_tty)
      });
 }
 \f
-static void
-set_breakpoint_cmd (const char *args, int from_tty)
-{
-}
-
-static void
-show_breakpoint_cmd (const 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.  */
@@ -14355,9 +14489,7 @@ invalidate_bp_value_on_memory_change (struct inferior *inferior,
                                      CORE_ADDR addr, ssize_t len,
                                      const bfd_byte *data)
 {
-  struct breakpoint *bp;
-
-  ALL_BREAKPOINTS (bp)
+  for (breakpoint *bp : all_breakpoints ())
     if (bp->enable_state == bp_enabled
        && bp->type == bp_hardware_watchpoint)
       {
@@ -14365,9 +14497,7 @@ invalidate_bp_value_on_memory_change (struct inferior *inferior,
 
        if (wp->val_valid && wp->val != nullptr)
          {
-           struct bp_location *loc;
-
-           for (loc = bp->loc; loc != NULL; loc = loc->next)
+           for (bp_location *loc : bp->locations ())
              if (loc->loc_type == bp_loc_hardware_watchpoint
                  && loc->address + loc->length > addr
                  && addr + len > loc->address)
@@ -14436,9 +14566,7 @@ breakpoint_has_location_inserted_here (struct breakpoint *bp,
                                       const address_space *aspace,
                                       CORE_ADDR pc)
 {
-  struct bp_location *loc;
-
-  for (loc = bp->loc; loc != NULL; loc = loc->next)
+  for (bp_location *loc : bp->locations ())
     if (loc->inserted
        && breakpoint_location_address_match (loc, aspace, pc))
       return 1;
@@ -14453,9 +14581,7 @@ int
 single_step_breakpoint_inserted_here_p (const address_space *aspace,
                                        CORE_ADDR pc)
 {
-  struct breakpoint *bpt;
-
-  ALL_BREAKPOINTS (bpt)
+  for (breakpoint *bpt : all_breakpoints ())
     {
       if (bpt->type == bp_single_step
          && breakpoint_has_location_inserted_here (bpt, aspace, pc))
@@ -14484,7 +14610,7 @@ trace_command (const char *arg, int from_tty)
 
   create_breakpoint (get_current_arch (),
                     location.get (),
-                    NULL, 0, arg, 1 /* parse arg */,
+                    NULL, 0, arg, false, 1 /* parse arg */,
                     0 /* tempflag */,
                     bp_tracepoint /* type_wanted */,
                     0 /* Ignore count */,
@@ -14502,7 +14628,7 @@ ftrace_command (const char *arg, int from_tty)
                                                         current_language);
   create_breakpoint (get_current_arch (),
                     location.get (),
-                    NULL, 0, arg, 1 /* parse arg */,
+                    NULL, 0, arg, false, 1 /* parse arg */,
                     0 /* tempflag */,
                     bp_fast_tracepoint /* type_wanted */,
                     0 /* Ignore count */,
@@ -14536,7 +14662,7 @@ strace_command (const char *arg, int from_tty)
 
   create_breakpoint (get_current_arch (),
                     location.get (),
-                    NULL, 0, arg, 1 /* parse arg */,
+                    NULL, 0, arg, false, 1 /* parse arg */,
                     0 /* tempflag */,
                     bp_static_tracepoint /* type_wanted */,
                     0 /* Ignore count */,
@@ -14606,6 +14732,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
   if (!create_breakpoint (get_current_arch (),
                          location.get (),
                          utp->cond_string.get (), -1, addr_str,
+                         false /* force_condition */,
                          0 /* parse cond/thread */,
                          0 /* tempflag */,
                          utp->type /* type_wanted */,
@@ -14700,8 +14827,6 @@ disable_trace_command (const char *args, int from_tty)
 static void
 delete_trace_command (const char *arg, int from_tty)
 {
-  struct breakpoint *b, *b_tmp;
-
   dont_repeat ();
 
   if (arg == 0)
@@ -14709,11 +14834,11 @@ delete_trace_command (const char *arg, int from_tty)
       int breaks_to_delete = 0;
 
       /* Delete all breakpoints if no argument.
-         Do not delete internal or call-dummy breakpoints, these
-         have to be deleted with an explicit breakpoint number 
+        Do not delete internal or call-dummy breakpoints, these
+        have to be deleted with an explicit breakpoint number 
         argument.  */
-      ALL_TRACEPOINTS (b)
-       if (is_tracepoint (b) && user_breakpoint_p (b))
+      for (breakpoint *tp : all_tracepoints ())
+       if (is_tracepoint (tp) && user_breakpoint_p (tp))
          {
            breaks_to_delete = 1;
            break;
@@ -14723,7 +14848,7 @@ delete_trace_command (const char *arg, int from_tty)
       if (!from_tty
          || (breaks_to_delete && query (_("Delete all tracepoints? "))))
        {
-         ALL_BREAKPOINTS_SAFE (b, b_tmp)
+         for (breakpoint *b : all_breakpoints_safe ())
            if (is_tracepoint (b) && user_breakpoint_p (b))
              delete_breakpoint (b);
        }
@@ -14769,17 +14894,15 @@ trace_pass_command (const char *args, int from_tty)
   args = skip_spaces (args);
   if (*args && strncasecmp (args, "all", 3) == 0)
     {
-      struct breakpoint *b;
-
       args += 3;                       /* Skip special argument "all".  */
       if (*args)
        error (_("Junk at end of arguments."));
 
-      ALL_TRACEPOINTS (b)
-      {
-       t1 = (struct tracepoint *) b;
-       trace_pass_set_count (t1, count, from_tty);
-      }
+      for (breakpoint *b : all_tracepoints ())
+       {
+         t1 = (struct tracepoint *) b;
+         trace_pass_set_count (t1, count, from_tty);
+       }
     }
   else if (*args == '\0')
     {
@@ -14802,9 +14925,7 @@ trace_pass_command (const char *args, int from_tty)
 struct tracepoint *
 get_tracepoint (int num)
 {
-  struct breakpoint *t;
-
-  ALL_TRACEPOINTS (t)
+  for (breakpoint *t : all_tracepoints ())
     if (t->number == num)
       return (struct tracepoint *) t;
 
@@ -14818,9 +14939,7 @@ get_tracepoint (int num)
 struct tracepoint *
 get_tracepoint_by_number_on_target (int num)
 {
-  struct breakpoint *b;
-
-  ALL_TRACEPOINTS (b)
+  for (breakpoint *b : all_tracepoints ())
     {
       struct tracepoint *t = (struct tracepoint *) b;
 
@@ -14840,7 +14959,6 @@ struct tracepoint *
 get_tracepoint_by_number (const char **arg,
                          number_or_range_parser *parser)
 {
-  struct breakpoint *t;
   int tpnum;
   const char *instring = arg == NULL ? NULL : *arg;
 
@@ -14864,11 +14982,9 @@ get_tracepoint_by_number (const char **arg,
       return NULL;
     }
 
-  ALL_TRACEPOINTS (t)
+  for (breakpoint *t : all_tracepoints ())
     if (t->number == tpnum)
-    {
       return (struct tracepoint *) t;
-    }
 
   printf_unfiltered ("No tracepoint number %d.\n", tpnum);
   return NULL;
@@ -14895,7 +15011,6 @@ static void
 save_breakpoints (const char *filename, int from_tty,
                  bool (*filter) (const struct breakpoint *))
 {
-  struct breakpoint *tp;
   int any = 0;
   int extra_trace_bits = 0;
 
@@ -14903,26 +15018,26 @@ save_breakpoints (const char *filename, int from_tty,
     error (_("Argument required (file name in which to save)"));
 
   /* See if we have anything to save.  */
-  ALL_BREAKPOINTS (tp)
-  {
-    /* Skip internal and momentary breakpoints.  */
-    if (!user_breakpoint_p (tp))
-      continue;
+  for (breakpoint *tp : all_breakpoints ())
+    {
+      /* Skip internal and momentary breakpoints.  */
+      if (!user_breakpoint_p (tp))
+       continue;
 
-    /* If we have a filter, only save the breakpoints it accepts.  */
-    if (filter && !filter (tp))
-      continue;
+      /* If we have a filter, only save the breakpoints it accepts.  */
+      if (filter && !filter (tp))
+       continue;
 
-    any = 1;
+      any = 1;
 
-    if (is_tracepoint (tp))
-      {
-       extra_trace_bits = 1;
+      if (is_tracepoint (tp))
+       {
+         extra_trace_bits = 1;
 
-       /* We can stop searching.  */
-       break;
-      }
-  }
+         /* We can stop searching.  */
+         break;
+       }
+    }
 
   if (!any)
     {
@@ -14941,63 +15056,66 @@ save_breakpoints (const char *filename, int from_tty,
   if (extra_trace_bits)
     save_trace_state_variables (&fp);
 
-  ALL_BREAKPOINTS (tp)
-  {
-    /* Skip internal and momentary breakpoints.  */
-    if (!user_breakpoint_p (tp))
-      continue;
+  for (breakpoint *tp : all_breakpoints ())
+    {
+      /* Skip internal and momentary breakpoints.  */
+      if (!user_breakpoint_p (tp))
+       continue;
 
-    /* If we have a filter, only save the breakpoints it accepts.  */
-    if (filter && !filter (tp))
-      continue;
+      /* If we have a filter, only save the breakpoints it accepts.  */
+      if (filter && !filter (tp))
+       continue;
 
-    tp->ops->print_recreate (tp, &fp);
+      tp->ops->print_recreate (tp, &fp);
 
-    /* Note, we can't rely on tp->number for anything, as we can't
-       assume the recreated breakpoint numbers will match.  Use $bpnum
-       instead.  */
+      /* 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)
-      fp.printf ("  condition $bpnum %s\n", tp->cond_string);
+      if (tp->cond_string)
+       fp.printf ("  condition $bpnum %s\n", tp->cond_string);
 
-    if (tp->ignore_count)
-      fp.printf ("  ignore $bpnum %d\n", tp->ignore_count);
+      if (tp->ignore_count)
+       fp.printf ("  ignore $bpnum %d\n", tp->ignore_count);
+
+      if (tp->type != bp_dprintf && tp->commands)
+       {
+         fp.puts ("  commands\n");
+
+         current_uiout->redirect (&fp);
+         try
+           {
+             print_command_lines (current_uiout, tp->commands.get (), 2);
+           }
+         catch (const gdb_exception &ex)
+           {
+           current_uiout->redirect (NULL);
+             throw;
+           }
 
-    if (tp->type != bp_dprintf && tp->commands)
-      {
-       fp.puts ("  commands\n");
-       
-       current_uiout->redirect (&fp);
-       try
-         {
-           print_command_lines (current_uiout, tp->commands.get (), 2);
-         }
-       catch (const gdb_exception &ex)
-         {
          current_uiout->redirect (NULL);
-           throw;
-         }
+         fp.puts ("  end\n");
+       }
 
-       current_uiout->redirect (NULL);
-       fp.puts ("  end\n");
-      }
+      if (tp->enable_state == bp_disabled)
+       fp.puts ("disable $bpnum\n");
 
-    if (tp->enable_state == bp_disabled)
-      fp.puts ("disable $bpnum\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)
+       {
+         int n = 1;
 
-    /* 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 (bp_location *loc : tp->locations ())
+           {
+             if (!loc->enabled)
+               fp.printf ("disable $bpnum.%d\n", n);
 
-       for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
-         if (!loc->enabled)
-           fp.printf ("disable $bpnum.%d\n", n);
-      }
-  }
+             n++;
+           }
+       }
+    }
 
   if (extra_trace_bits && *default_collect)
     fp.printf ("set default-collect %s\n", default_collect);
@@ -15022,22 +15140,6 @@ save_tracepoints_command (const char *args, int from_tty)
   save_breakpoints (args, from_tty, is_tracepoint);
 }
 
-/* Create a vector of all tracepoints.  */
-
-std::vector<breakpoint *>
-all_tracepoints (void)
-{
-  std::vector<breakpoint *> tp_vec;
-  struct breakpoint *tp;
-
-  ALL_TRACEPOINTS (tp)
-  {
-    tp_vec.push_back (tp);
-  }
-
-  return tp_vec;
-}
-
 \f
 /* This help string is used to consolidate all the help string for specifying
    locations used by several commands.  */
@@ -15072,7 +15174,8 @@ specified name as a complete fully-qualified name instead."
    command.  */
 
 #define BREAK_ARGS_HELP(command) \
-command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
+command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
+\t[-force-condition] [if CONDITION]\n\
 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
 probe point.  Accepted values are `-probe' (for a generic, automatically\n\
 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
@@ -15085,6 +15188,9 @@ stack frame.  This is useful for breaking on return to a stack frame.\n\
 \n\
 THREADNUM is the number from \"info threads\".\n\
 CONDITION is a boolean expression.\n\
+\n\
+With the \"-force-condition\" flag, the condition is defined even when\n\
+it is invalid for all current locations.\n\
 \n" LOCATION_HELP_STRING "\n\n\
 Multiple breakpoints at one place are permitted, and useful if their\n\
 conditions are different.\n\
@@ -15109,38 +15215,16 @@ add_catch_command (const char *name, const char *docstring,
   command = add_cmd (name, class_breakpoint, docstring,
                     &catch_cmdlist);
   set_cmd_sfunc (command, sfunc);
-  set_cmd_context (command, user_data_catch);
+  command->set_context (user_data_catch);
   set_cmd_completer (command, completer);
 
   command = add_cmd (name, class_breakpoint, docstring,
                     &tcatch_cmdlist);
   set_cmd_sfunc (command, sfunc);
-  set_cmd_context (command, user_data_tcatch);
+  command->set_context (user_data_tcatch);
   set_cmd_completer (command, completer);
 }
 
-static void
-save_command (const char *arg, int from_tty)
-{
-  printf_unfiltered (_("\"save\" must be followed by "
-                      "the name of a save subcommand.\n"));
-  help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
-}
-
-struct breakpoint *
-iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback)
-{
-  struct breakpoint *b, *b_tmp;
-
-  ALL_BREAKPOINTS_SAFE (b, b_tmp)
-    {
-      if (callback (b))
-       return b;
-    }
-
-  return NULL;
-}
-
 /* Zero if any of the breakpoint's locations could be a location where
    functions have been inlined, nonzero otherwise.  */
 
@@ -15162,15 +15246,12 @@ int
 pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
                           const struct target_waitstatus *ws)
 {
-  struct breakpoint *b;
-  struct bp_location *bl;
-
-  ALL_BREAKPOINTS (b)
+  for (breakpoint *b : all_breakpoints ())
     {
       if (!is_non_inline_function (b))
        continue;
 
-      for (bl = b->loc; bl != NULL; bl = bl->next)
+      for (bp_location *bl : b->locations ())
        {
          if (!bl->shlib_disabled
              && bpstat_check_location (bl, aspace, pc, ws))
@@ -15186,9 +15267,7 @@ pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
 void
 breakpoint_free_objfile (struct objfile *objfile)
 {
-  struct bp_location **locp, *loc;
-
-  ALL_BP_LOCATIONS (loc, locp)
+  for (bp_location *loc : all_bp_locations ())
     if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
       loc->symtab = NULL;
 }
@@ -15385,9 +15464,12 @@ _initialize_breakpoint ()
 
   initialize_breakpoint_ops ();
 
-  gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib);
-  gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile);
-  gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change);
+  gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib,
+                                        "breakpoint");
+  gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile,
+                                      "breakpoint");
+  gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change,
+                                        "breakpoint");
 
   breakpoint_chain = 0;
   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
@@ -15412,11 +15494,19 @@ Type a line containing \"end\" to indicate the end of them.\n\
 Give \"silent\" as the first line to make the breakpoint silent;\n\
 then no output is printed when it is hit, except what the commands print."));
 
-  c = add_com ("condition", class_breakpoint, condition_command, _("\
+  const auto cc_opts = make_condition_command_options_def_group (nullptr);
+  static std::string condition_command_help
+    = gdb::option::build_help (_("\
 Specify breakpoint number N to break only if COND is true.\n\
-Usage is `condition N COND', where N is an integer and COND is an\n\
-expression to be evaluated whenever breakpoint N is reached."));
-  set_cmd_completer (c, condition_completer);
+Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
+is an expression to be evaluated whenever breakpoint N is reached.\n\
+\n\
+Options:\n\
+%OPTIONS%"), cc_opts);
+
+  c = add_com ("condition", class_breakpoint, condition_command,
+              condition_command_help.c_str ());
+  set_cmd_completer_handle_brkchars (c, condition_completer);
 
   c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
 Set a temporary breakpoint.\n\
@@ -15443,16 +15533,17 @@ so it will be deleted when hit.\n\
 BREAK_ARGS_HELP ("thbreak")));
   set_cmd_completer (c, location_completer);
 
-  add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
+  cmd_list_element *enable_cmd
+    = add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
 Enable all or some breakpoints.\n\
 Usage: enable [BREAKPOINTNUM]...\n\
 Give breakpoint numbers (separated by spaces) as arguments.\n\
 With no subcommand, breakpoints are enabled until you command otherwise.\n\
 This is used to cancel the effect of the \"disable\" command.\n\
 With a subcommand you can enable temporarily."),
-                 &enablelist, "enable ", 1, &cmdlist);
+                     &enablelist, 1, &cmdlist);
 
-  add_com_alias ("en", "enable", class_breakpoint, 1);
+  add_com_alias ("en", enable_cmd, class_breakpoint, 1);
 
   add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
 Enable all or some breakpoints.\n\
@@ -15460,7 +15551,7 @@ Usage: enable breakpoints [BREAKPOINTNUM]...\n\
 Give breakpoint numbers (separated by spaces) as arguments.\n\
 This is used to cancel the effect of the \"disable\" command.\n\
 May be abbreviated to simply \"enable\"."),
-                  &enablebreaklist, "enable breakpoints ", 1, &enablelist);
+                  &enablebreaklist, 1, &enablelist);
 
   add_cmd ("once", no_class, enable_once_command, _("\
 Enable some breakpoints for one hit.\n\
@@ -15500,17 +15591,18 @@ If a breakpoint is hit while enabled in this fashion,\n\
 the count is decremented; when it reaches zero, the breakpoint is disabled."),
           &enablelist);
 
-  add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
+  cmd_list_element *disable_cmd
+    = add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
 Disable all or some breakpoints.\n\
 Usage: disable [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
 To disable all breakpoints, give no argument.\n\
 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
-                 &disablelist, "disable ", 1, &cmdlist);
-  add_com_alias ("dis", "disable", class_breakpoint, 1);
-  add_com_alias ("disa", "disable", class_breakpoint, 1);
+                     &disablelist, 1, &cmdlist);
+  add_com_alias ("dis", disable_cmd, class_breakpoint, 1);
+  add_com_alias ("disa", disable_cmd, class_breakpoint, 1);
 
-  add_cmd ("breakpoints", class_alias, disable_command, _("\
+  add_cmd ("breakpoints", class_breakpoint, disable_command, _("\
 Disable all or some breakpoints.\n\
 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
@@ -15519,18 +15611,19 @@ A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
 This command may be abbreviated \"disable\"."),
           &disablelist);
 
-  add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
+  cmd_list_element *delete_cmd
+    = add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
 Delete all or some breakpoints.\n\
 Usage: delete [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
 To delete all breakpoints, give no argument.\n\
 \n\
 Also a prefix command for deletion of other GDB objects."),
-                 &deletelist, "delete ", 1, &cmdlist);
-  add_com_alias ("d", "delete", class_breakpoint, 1);
-  add_com_alias ("del", "delete", class_breakpoint, 1);
+                     &deletelist, 1, &cmdlist);
+  add_com_alias ("d", delete_cmd, class_breakpoint, 1);
+  add_com_alias ("del", delete_cmd, class_breakpoint, 1);
 
-  add_cmd ("breakpoints", class_alias, delete_command, _("\
+  add_cmd ("breakpoints", class_breakpoint, delete_command, _("\
 Delete all or some breakpoints or auto-display expressions.\n\
 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
@@ -15538,7 +15631,8 @@ To delete all breakpoints, give no argument.\n\
 This command may be abbreviated \"delete\"."),
           &deletelist);
 
-  add_com ("clear", class_breakpoint, clear_command, _("\
+  cmd_list_element *clear_cmd
+   = add_com ("clear", class_breakpoint, clear_command, _("\
 Clear breakpoint at specified location.\n\
 Argument may be a linespec, explicit, or address location as described below.\n\
 \n\
@@ -15546,23 +15640,24 @@ With no argument, clears all breakpoints in the line that the selected frame\n\
 is executing in.\n"
 "\n" LOCATION_HELP_STRING "\n\n\
 See also the \"delete\" command which clears breakpoints by number."));
-  add_com_alias ("cl", "clear", class_breakpoint, 1);
+  add_com_alias ("cl", clear_cmd, class_breakpoint, 1);
 
-  c = add_com ("break", class_breakpoint, break_command, _("\
+  cmd_list_element *break_cmd
+    = add_com ("break", class_breakpoint, break_command, _("\
 Set breakpoint at specified location.\n"
 BREAK_ARGS_HELP ("break")));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (break_cmd, location_completer);
 
-  add_com_alias ("b", "break", class_run, 1);
-  add_com_alias ("br", "break", class_run, 1);
-  add_com_alias ("bre", "break", class_run, 1);
-  add_com_alias ("brea", "break", class_run, 1);
+  add_com_alias ("b", break_cmd, class_run, 1);
+  add_com_alias ("br", break_cmd, class_run, 1);
+  add_com_alias ("bre", break_cmd, class_run, 1);
+  add_com_alias ("brea", break_cmd, class_run, 1);
 
   if (dbx_commands)
     {
       add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
 Break in function/address or break at a line in the current file."),
-                            &stoplist, "stop ", 1, &cmdlist);
+                            &stoplist, 1, &cmdlist);
       add_cmd ("in", class_breakpoint, stopin_command,
               _("Break in function or address."), &stoplist);
       add_cmd ("at", class_breakpoint, stopat_command,
@@ -15584,7 +15679,8 @@ Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."));
     }
 
-  add_info ("breakpoints", info_breakpoints_command, _("\
+  cmd_list_element *info_breakpoints_cmd
+    = add_info ("breakpoints", info_breakpoints_command, _("\
 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
 The \"Type\" column indicates one of:\n\
 \tbreakpoint     - normal breakpoint\n\
@@ -15600,7 +15696,7 @@ is prefixed with \"server \".\n\n\
 Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."));
 
-  add_info_alias ("b", "breakpoints", 1);
+  add_info_alias ("b", info_breakpoints_cmd, 1);
 
   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
 Status of all breakpoints, or breakpoint number NUMBER.\n\
@@ -15623,29 +15719,29 @@ Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."),
           &maintenanceinfolist);
 
-  add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
+  add_basic_prefix_cmd ("catch", class_breakpoint, _("\
 Set catchpoints to catch events."),
-                 &catch_cmdlist, "catch ",
-                 0/*allow-unknown*/, &cmdlist);
+                       &catch_cmdlist,
+                       0/*allow-unknown*/, &cmdlist);
 
-  add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
+  add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\
 Set temporary catchpoints to catch events."),
-                 &tcatch_cmdlist, "tcatch ",
-                 0/*allow-unknown*/, &cmdlist);
+                       &tcatch_cmdlist,
+                       0/*allow-unknown*/, &cmdlist);
 
   add_catch_command ("fork", _("Catch calls to fork."),
                     catch_fork_command_1,
-                     NULL,
+                    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,
+                    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,
+                    NULL,
                     CATCH_PERMANENT,
                     CATCH_TEMPORARY);
   add_catch_command ("load", _("Catch loads of shared libraries.\n\
@@ -15663,32 +15759,46 @@ If REGEX is given, only stop for libraries matching the regular expression."),
                     CATCH_PERMANENT,
                     CATCH_TEMPORARY);
 
-  c = add_com ("watch", class_breakpoint, watch_command, _("\
-Set a watchpoint for an expression.\n\
-Usage: watch [-l|-location] EXPRESSION\n\
-A watchpoint stops execution of your program whenever the value of\n\
-an expression changes.\n\
-If -l or -location is given, this evaluates EXPRESSION and watches\n\
-the memory to which it refers."));
-  set_cmd_completer (c, expression_completer);
-
-  c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
-Set a read watchpoint for an expression.\n\
-Usage: rwatch [-l|-location] EXPRESSION\n\
-A watchpoint stops execution of your program whenever the value of\n\
-an expression is read.\n\
-If -l or -location is given, this evaluates EXPRESSION and watches\n\
-the memory to which it refers."));
-  set_cmd_completer (c, expression_completer);
-
-  c = add_com ("awatch", class_breakpoint, awatch_command, _("\
-Set a watchpoint for an expression.\n\
-Usage: awatch [-l|-location] EXPRESSION\n\
+  const auto opts = make_watch_options_def_group (nullptr);
+
+  static const std::string watch_help = gdb::option::build_help (_("\
+Set a watchpoint for EXPRESSION.\n\
+Usage: watch [-location] EXPRESSION\n\
+\n\
+Options:\n\
+%OPTIONS%\n\
+\n\
 A watchpoint stops execution of your program whenever the value of\n\
-an expression is either read or written.\n\
-If -l or -location is given, this evaluates EXPRESSION and watches\n\
-the memory to which it refers."));
-  set_cmd_completer (c, expression_completer);
+an expression changes."), opts);
+  c = add_com ("watch", class_breakpoint, watch_command,
+              watch_help.c_str ());
+  set_cmd_completer_handle_brkchars (c, watch_command_completer);
+
+  static const std::string rwatch_help = gdb::option::build_help (_("\
+Set a read watchpoint for EXPRESSION.\n\
+Usage: rwatch [-location] EXPRESSION\n\
+\n\
+Options:\n\
+%OPTIONS%\n\
+\n\
+A read watchpoint stops execution of your program whenever the value of\n\
+an expression is read."), opts);
+  c = add_com ("rwatch", class_breakpoint, rwatch_command,
+              rwatch_help.c_str ());
+  set_cmd_completer_handle_brkchars (c, watch_command_completer);
+
+  static const std::string awatch_help = gdb::option::build_help (_("\
+Set an access watchpoint for EXPRESSION.\n\
+Usage: awatch [-location] EXPRESSION\n\
+\n\
+Options:\n\
+%OPTIONS%\n\
+\n\
+An access watchpoint stops execution of your program whenever the value\n\
+of an expression is either read or written."), opts);
+  c = add_com ("awatch", class_breakpoint, awatch_command,
+              awatch_help.c_str ());
+  set_cmd_completer_handle_brkchars (c, watch_command_completer);
 
   add_info ("watchpoints", info_watchpoints_command, _("\
 Status of specified watchpoints (all watchpoints if no argument)."));
@@ -15711,17 +15821,18 @@ hardware.)"),
 
   /* Tracepoint manipulation commands.  */
 
-  c = add_com ("trace", class_breakpoint, trace_command, _("\
+  cmd_list_element *trace_cmd
+    = add_com ("trace", class_breakpoint, trace_command, _("\
 Set a tracepoint at specified location.\n\
 \n"
 BREAK_ARGS_HELP ("trace") "\n\
 Do \"help tracepoints\" for info on other tracepoint commands."));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (trace_cmd, location_completer);
 
-  add_com_alias ("tp", "trace", class_alias, 0);
-  add_com_alias ("tr", "trace", class_alias, 1);
-  add_com_alias ("tra", "trace", class_alias, 1);
-  add_com_alias ("trac", "trace", class_alias, 1);
+  add_com_alias ("tp", trace_cmd, class_breakpoint, 0);
+  add_com_alias ("tr", trace_cmd, class_breakpoint, 1);
+  add_com_alias ("tra", trace_cmd, class_breakpoint, 1);
+  add_com_alias ("trac", trace_cmd, class_breakpoint, 1);
 
   c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
 Set a fast tracepoint at specified location.\n\
@@ -15752,19 +15863,21 @@ Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
 Do \"help tracepoints\" for info on other tracepoint commands."));
   set_cmd_completer (c, location_completer);
 
-  add_info ("tracepoints", info_tracepoints_command, _("\
+  cmd_list_element *info_tracepoints_cmd
+    = add_info ("tracepoints", info_tracepoints_command, _("\
 Status of specified tracepoints (all tracepoints if no argument).\n\
 Convenience variable \"$tpnum\" contains the number of the\n\
 last tracepoint set."));
 
-  add_info_alias ("tp", "tracepoints", 1);
+  add_info_alias ("tp", info_tracepoints_cmd, 1);
 
-  add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
+  cmd_list_element *delete_tracepoints_cmd
+    = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
 Delete specified tracepoints.\n\
 Arguments are tracepoint numbers, separated by spaces.\n\
 No argument means delete all tracepoints."),
           &deletelist);
-  add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
+  add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist);
 
   c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
 Disable specified tracepoints.\n\
@@ -15786,10 +15899,10 @@ 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."));
 
-  add_prefix_cmd ("save", class_breakpoint, save_command,
-                 _("Save breakpoint definitions as a script."),
-                 &save_cmdlist, "save ",
-                 0/*allow-unknown*/, &cmdlist);
+  add_basic_prefix_cmd ("save", class_breakpoint,
+                       _("Save breakpoint definitions as a script."),
+                       &save_cmdlist,
+                       0/*allow-unknown*/, &cmdlist);
 
   c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
 Save current breakpoint definitions as a script.\n\
@@ -15799,27 +15912,28 @@ session to restore them."),
               &save_cmdlist);
   set_cmd_completer (c, filename_completer);
 
-  c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
+  cmd_list_element *save_tracepoints_cmd
+    = 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."),
               &save_cmdlist);
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (save_tracepoints_cmd, filename_completer);
 
-  c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
+  c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0);
   deprecate_cmd (c, "save tracepoints");
 
-  add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
+  add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\
 Breakpoint specific settings.\n\
 Configure various breakpoint-specific variables such as\n\
 pending breakpoint behavior."),
-                 &breakpoint_set_cmdlist, "set breakpoint ",
-                 0/*allow-unknown*/, &setlist);
-  add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
+                       &breakpoint_set_cmdlist,
+                       0/*allow-unknown*/, &setlist);
+  add_show_prefix_cmd ("breakpoint", class_maintenance, _("\
 Breakpoint specific settings.\n\
 Configure various breakpoint-specific variables such as\n\
 pending breakpoint behavior."),
-                 &breakpoint_show_cmdlist, "show breakpoint ",
-                 0/*allow-unknown*/, &showlist);
+                      &breakpoint_show_cmdlist,
+                      0/*allow-unknown*/, &showlist);
 
   add_setshow_auto_boolean_cmd ("pending", no_class,
                                &pending_break_support, _("\
@@ -15873,7 +15987,7 @@ breakpoint conditions will be downloaded to the target (if the target\n\
 supports such feature) and conditions will be evaluated on the target's side.\n\
 If this is set to \"auto\" (default), this will be automatically set to\n\
 \"target\" if it supports condition evaluation, otherwise it will\n\
-be set to \"gdb\""),
+be set to \"host\"."),
                           &set_condition_evaluation_mode,
                           &show_condition_evaluation_mode,
                           &breakpoint_set_cmdlist,
@@ -15886,7 +16000,7 @@ where START-LOCATION and END-LOCATION can be one of the following:\n\
   LINENUM, for that line in the current file,\n\
   FILE:LINENUM, for that line in that file,\n\
   +OFFSET, for that number of lines after the current line\n\
-           or the start of the range\n\
+          or the start of the range\n\
   FUNCTION, for the first line in that function,\n\
   FILE:FUNCTION, to distinguish among like-named static functions.\n\
   *ADDRESS, for the instruction at that address.\n\
@@ -15949,6 +16063,8 @@ This is useful for formatted output in user-defined commands."));
 
   automatic_hardware_breakpoints = true;
 
-  gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed);
-  gdb::observers::thread_exit.attach (remove_threaded_breakpoints);
+  gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed,
+                                          "breakpoint");
+  gdb::observers::thread_exit.attach (remove_threaded_breakpoints,
+                                     "breakpoint");
 }
This page took 0.21196 seconds and 4 git commands to generate.