Fix tracepoint.c:parse_tracepoint_definition leak (and one more)
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 00c538e989e31470b68c8b54afc052c54943c200..2ab8a76326c413688afa428ef9a383af8378d2ff 100644 (file)
@@ -1,6 +1,6 @@
 /* Everything about breakpoints, for GDB.
 
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -68,6 +68,7 @@
 #include "format.h"
 #include "thread-fsm.h"
 #include "tid-parse.h"
+#include "cli/cli-style.h"
 
 /* readline include files */
 #include "readline/readline.h"
@@ -400,8 +401,6 @@ breakpoints_should_be_inserted_now (void)
     }
   else if (target_has_execution)
     {
-      struct thread_info *tp;
-
       if (always_inserted_mode)
        {
          /* The user wants breakpoints inserted even if all threads
@@ -414,7 +413,7 @@ breakpoints_should_be_inserted_now (void)
 
       /* Don't remove breakpoints yet if, even though all threads are
         stopped, we still have events to process.  */
-      ALL_NON_EXITED_THREADS (tp)
+      for (thread_info *tp : all_non_exited_threads ())
        if (tp->resumed
            && tp->suspend.waitstatus_pending_p)
          return 1;
@@ -560,7 +559,7 @@ static CORE_ADDR bp_locations_shadow_len_after_address_max;
 /* The locations that no longer correspond to any breakpoint, unlinked
    from the bp_locations array, but for which a hit may still be
    reported by a target.  */
-VEC(bp_location_p) *moribund_locations = NULL;
+static std::vector<bp_location *> moribund_locations;
 
 /* Number of last breakpoint made.  */
 
@@ -1009,8 +1008,6 @@ check_no_tracepoint_commands (struct command_line *commands)
 
   for (c = commands; c; c = c->next)
     {
-      int i;
-
       if (c->control_type == while_stepping_control)
        error (_("The 'while-stepping' command can "
                 "only be used for tracepoints"));
@@ -1145,11 +1142,11 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 /* Return a vector of all the static tracepoints set at ADDR.  The
    caller is responsible for releasing the vector.  */
 
-VEC(breakpoint_p) *
+std::vector<breakpoint *>
 static_tracepoints_here (CORE_ADDR addr)
 {
   struct breakpoint *b;
-  VEC(breakpoint_p) *found = 0;
+  std::vector<breakpoint *> found;
   struct bp_location *loc;
 
   ALL_BREAKPOINTS (b)
@@ -1157,7 +1154,7 @@ static_tracepoints_here (CORE_ADDR addr)
       {
        for (loc = b->loc; loc; loc = loc->next)
          if (loc->address == addr)
-           VEC_safe_push(breakpoint_p, found, b);
+           found.push_back (b);
       }
 
   return found;
@@ -1221,6 +1218,10 @@ commands_command_1 (const char *arg, int from_tty,
                    struct command_line *control)
 {
   counted_command_line cmd;
+  /* cmd_read will be true once we have read cmd.  Note that cmd might still be
+     NULL after the call to read_command_lines if the user provides an empty
+     list of command by just typing "end".  */
+  bool cmd_read = false;
 
   std::string new_arg;
 
@@ -1237,8 +1238,9 @@ commands_command_1 (const char *arg, int from_tty,
   map_breakpoint_numbers
     (arg, [&] (breakpoint *b)
      {
-       if (cmd == NULL)
+       if (!cmd_read)
         {
+          gdb_assert (cmd == NULL);
           if (control != NULL)
             cmd = control->body_list_0;
           else
@@ -1258,6 +1260,7 @@ commands_command_1 (const char *arg, int from_tty,
 
               cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
             }
+          cmd_read = true;
         }
 
        /* If a breakpoint was on the list more than once, we don't need to
@@ -1546,9 +1549,9 @@ static int
 watchpoint_in_thread_scope (struct watchpoint *b)
 {
   return (b->pspace == current_program_space
-         && (ptid_equal (b->watchpoint_thread, null_ptid)
-             || (ptid_equal (inferior_ptid, b->watchpoint_thread)
-                 && !is_executing (inferior_ptid))));
+         && (b->watchpoint_thread == null_ptid
+             || (inferior_ptid == b->watchpoint_thread
+                 && !inferior_thread ()->executing)));
 }
 
 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
@@ -1775,7 +1778,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
     {
       int pc = 0;
       std::vector<value_ref_ptr> val_chain;
-      struct value *v, *result, *next;
+      struct value *v, *result;
       struct program_space *frame_pspace;
 
       fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
@@ -2408,7 +2411,7 @@ breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
       struct thread_info *thr = find_thread_global_id (bl->owner->thread);
       struct regcache *regcache;
 
-      regcache = get_thread_regcache (thr->ptid);
+      regcache = get_thread_regcache (thr);
 
       return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
                                                         regcache, addr);
@@ -2894,7 +2897,7 @@ update_inserted_breakpoint_locations (void)
       /* We only want to update locations that are already inserted
         and need updating.  This is to avoid unwanted insertion during
         deletion of breakpoints.  */
-      if (!bl->inserted || (bl->inserted && !bl->needs_update))
+      if (!bl->inserted || !bl->needs_update)
        continue;
 
       switch_to_program_space_and_thread (bl->pspace);
@@ -2904,7 +2907,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 ())
-         && ptid_equal (inferior_ptid, null_ptid))
+         && inferior_ptid == null_ptid)
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -2960,7 +2963,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 ())
-         && ptid_equal (inferior_ptid, null_ptid))
+         && inferior_ptid == null_ptid)
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -3061,14 +3064,13 @@ Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\
     }
 }
 
-/* Remove breakpoints of process PID.  */
+/* Remove breakpoints of inferior INF.  */
 
 int
-remove_breakpoints_pid (int pid)
+remove_breakpoints_inf (inferior *inf)
 {
   struct bp_location *bl, **blp_tmp;
   int val;
-  struct inferior *inf = find_inferior_pid (pid);
 
   ALL_BP_LOCATIONS (bl, blp_tmp)
   {
@@ -3201,10 +3203,9 @@ free_breakpoint_objfile_data (struct objfile *obj, void *data)
 static void
 create_overlay_event_breakpoint (void)
 {
-  struct objfile *objfile;
   const char *const func_name = "_ovly_debug_event";
 
-  ALL_OBJFILES (objfile)
+  for (objfile *objfile : all_objfiles (current_program_space))
     {
       struct breakpoint *b;
       struct breakpoint_objfile_data *bp_objfile_data;
@@ -3260,97 +3261,93 @@ create_longjmp_master_breakpoint (void)
 
   ALL_PSPACES (pspace)
   {
-    struct objfile *objfile;
-
     set_current_program_space (pspace);
 
-    ALL_OBJFILES (objfile)
-    {
-      int i;
-      struct gdbarch *gdbarch;
-      struct breakpoint_objfile_data *bp_objfile_data;
-
-      gdbarch = get_objfile_arch (objfile);
+    for (objfile *objfile : all_objfiles (current_program_space))
+      {
+       int i;
+       struct gdbarch *gdbarch;
+       struct breakpoint_objfile_data *bp_objfile_data;
 
-      bp_objfile_data = get_breakpoint_objfile_data (objfile);
+       gdbarch = get_objfile_arch (objfile);
 
-      if (!bp_objfile_data->longjmp_searched)
-       {
-         std::vector<probe *> ret
-           = find_probes_in_objfile (objfile, "libc", "longjmp");
+       bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
-         if (!ret.empty ())
-           {
-             /* We are only interested in checking one element.  */
-             probe *p = ret[0];
+       if (!bp_objfile_data->longjmp_searched)
+         {
+           std::vector<probe *> ret
+             = find_probes_in_objfile (objfile, "libc", "longjmp");
 
-             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;
-       }
+           if (!ret.empty ())
+             {
+               /* We are only interested in checking one element.  */
+               probe *p = ret[0];
 
-      if (!bp_objfile_data->longjmp_probes.empty ())
-       {
-         struct gdbarch *gdbarch = get_objfile_arch (objfile);
+               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;
+         }
 
-         for (probe *p : bp_objfile_data->longjmp_probes)
-           {
-             struct breakpoint *b;
+       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;
+             }
 
-             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;
-           }
+           continue;
+         }
 
+       if (!gdbarch_get_longjmp_target_p (gdbarch))
          continue;
-       }
 
-      if (!gdbarch_get_longjmp_target_p (gdbarch))
-       continue;
-
-      for (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;
+           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;
+           func_name = longjmp_names[i];
+           if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
+             {
+               struct bound_minimal_symbol m;
 
-             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;
-           }
+               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;
+             }
 
-         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;
-       }
-    }
+           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;
+         }
+      }
   }
 }
 
@@ -3365,46 +3362,45 @@ create_std_terminate_master_breakpoint (void)
 
   ALL_PSPACES (pspace)
   {
-    struct objfile *objfile;
     CORE_ADDR addr;
 
     set_current_program_space (pspace);
 
-    ALL_OBJFILES (objfile)
-    {
-      struct breakpoint *b;
-      struct breakpoint_objfile_data *bp_objfile_data;
-      struct explicit_location explicit_loc;
+    for (objfile *objfile : all_objfiles (current_program_space))
+      {
+       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 (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;
+      }
   }
 }
 
@@ -3413,10 +3409,9 @@ create_std_terminate_master_breakpoint (void)
 static void
 create_exception_master_breakpoint (void)
 {
-  struct objfile *objfile;
   const char *const func_name = "_Unwind_DebugHook";
 
-  ALL_OBJFILES (objfile)
+  for (objfile *objfile : all_objfiles (current_program_space))
     {
       struct breakpoint *b;
       struct gdbarch *gdbarch;
@@ -3450,12 +3445,10 @@ create_exception_master_breakpoint (void)
 
       if (!bp_objfile_data->exception_probes.empty ())
        {
-         struct gdbarch *gdbarch = get_objfile_arch (objfile);
+         gdbarch = get_objfile_arch (objfile);
 
          for (probe *p : bp_objfile_data->exception_probes)
            {
-             struct breakpoint *b;
-
              b = create_internal_breakpoint (gdbarch,
                                              p->get_relocated_address (objfile),
                                              bp_exception_master,
@@ -3489,7 +3482,8 @@ create_exception_master_breakpoint (void)
        }
 
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
-      addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, target_stack);
+      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);
@@ -3637,7 +3631,7 @@ detach_breakpoints (ptid_t ptid)
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
   struct inferior *inf = current_inferior ();
 
-  if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
+  if (ptid.pid () == inferior_ptid.pid ())
     error (_("Cannot detach breakpoints of inferior_ptid"));
 
   /* Set inferior_ptid; remove_breakpoint_1 uses this global.  */
@@ -3860,8 +3854,6 @@ void
 breakpoint_init_inferior (enum inf_context context)
 {
   struct breakpoint *b, *b_tmp;
-  struct bp_location *bl;
-  int ix;
   struct program_space *pspace = current_program_space;
 
   /* If breakpoint locations are shared across processes, then there's
@@ -3951,9 +3943,9 @@ breakpoint_init_inferior (enum inf_context context)
   }
 
   /* Get rid of the moribund locations.  */
-  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
+  for (bp_location *bl : moribund_locations)
     decref_bp_location (&bl);
-  VEC_free (bp_location_p, moribund_locations);
+  moribund_locations.clear ();
 }
 
 /* These functions concern about actual breakpoints inserted in the
@@ -4041,10 +4033,7 @@ breakpoint_in_range_p (const address_space *aspace,
 int
 moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
 {
-  struct bp_location *loc;
-  int ix;
-
-  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
+  for (bp_location *loc : moribund_locations)
     if (breakpoint_location_address_match (loc, aspace, pc))
       return 1;
 
@@ -4328,16 +4317,12 @@ bpstat_num (bpstat *bsp, int *num)
 void
 bpstat_clear_actions (void)
 {
-  struct thread_info *tp;
   bpstat bs;
 
-  if (ptid_equal (inferior_ptid, null_ptid))
-    return;
-
-  tp = find_thread_ptid (inferior_ptid);
-  if (tp == NULL)
+  if (inferior_ptid == null_ptid)
     return;
 
+  thread_info *tp = inferior_thread ();
   for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
     {
       bs->commands = NULL;
@@ -4350,7 +4335,7 @@ bpstat_clear_actions (void)
 static void
 breakpoint_about_to_proceed (void)
 {
-  if (!ptid_equal (inferior_ptid, null_ptid))
+  if (inferior_ptid != null_ptid)
     {
       struct thread_info *tp = inferior_thread ();
 
@@ -4465,22 +4450,37 @@ bpstat_do_actions_1 (bpstat *bsp)
   return again;
 }
 
+/* Helper for bpstat_do_actions.  Get the current thread, if there's
+   one, is alive and has execution.  Return NULL otherwise.  */
+
+static thread_info *
+get_bpstat_thread ()
+{
+  if (inferior_ptid == null_ptid || !target_has_execution)
+    return NULL;
+
+  thread_info *tp = inferior_thread ();
+  if (tp->state == THREAD_EXITED || tp->executing)
+    return NULL;
+  return tp;
+}
+
 void
 bpstat_do_actions (void)
 {
   struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
+  thread_info *tp;
 
   /* Do any commands attached to breakpoint we are stopped at.  */
-  while (!ptid_equal (inferior_ptid, null_ptid)
-        && target_has_execution
-        && !is_exited (inferior_ptid)
-        && !is_executing (inferior_ptid))
-    /* Since in sync mode, bpstat_do_actions may resume the inferior,
-       and only return when it is stopped at the next breakpoint, we
-       keep doing breakpoint actions until it returns false to
-       indicate the inferior was not resumed.  */
-    if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
-      break;
+  while ((tp = get_bpstat_thread ()) != NULL)
+    {
+      /* Since in sync mode, bpstat_do_actions may resume the
+        inferior, and only return when it is stopped at the next
+        breakpoint, we keep doing breakpoint actions until it returns
+        false to indicate the inferior was not resumed.  */
+      if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
+       break;
+    }
 
   discard_cleanups (cleanup_if_error);
 }
@@ -4743,7 +4743,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
       return 0;
     }
 
-  if (!target_stopped_data_address (target_stack, &addr))
+  if (!target_stopped_data_address (current_top_target (), &addr))
     {
       /* We were stopped by a watchpoint, but we don't know where.
         Mark all watchpoints as unknown.  */
@@ -4783,7 +4783,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
                  }
              }
            /* Exact match not required.  Within range is sufficient.  */
-           else if (target_watchpoint_addr_within_range (target_stack,
+           else if (target_watchpoint_addr_within_range (current_top_target (),
                                                         addr, loc->address,
                                                         loc->length))
              {
@@ -5153,7 +5153,7 @@ bpstat_check_watchpoint (bpstat bs)
    breakpoint, set BS->stop to 0.  */
 
 static void
-bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
+bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
 {
   const struct bp_location *bl;
   struct breakpoint *b;
@@ -5183,9 +5183,8 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
   /* If this is a thread/task-specific breakpoint, don't waste cpu
      evaluating the condition if this isn't the specified
      thread/task.  */
-  if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
-      || (b->task != 0 && b->task != ada_get_task_number (ptid)))
-
+  if ((b->thread != -1 && b->thread != thread->global_num)
+      || (b->task != 0 && b->task != ada_get_task_number (thread)))
     {
       bs->stop = 0;
       return;
@@ -5362,10 +5361,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
   if (!target_supports_stopped_by_sw_breakpoint ()
       || !target_supports_stopped_by_hw_breakpoint ())
     {
-      bp_location *loc;
-
-      for (int ix = 0;
-          VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
+      for (bp_location *loc : moribund_locations)
        {
          if (breakpoint_location_address_match (loc, aspace, bp_addr)
              && need_moribund_for_location_type (loc))
@@ -5386,7 +5382,7 @@ build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
 
 bpstat
 bpstat_stop_status (const address_space *aspace,
-                   CORE_ADDR bp_addr, ptid_t ptid,
+                   CORE_ADDR bp_addr, thread_info *thread,
                    const struct target_waitstatus *ws,
                    bpstat stop_chain)
 {
@@ -5434,7 +5430,7 @@ bpstat_stop_status (const address_space *aspace,
       b->ops->check_status (bs);
       if (bs->stop)
        {
-         bpstat_check_breakpoint_conditions (bs, ptid);
+         bpstat_check_breakpoint_conditions (bs, thread);
 
          if (bs->stop)
            {
@@ -5857,19 +5853,18 @@ print_breakpoint_location (struct breakpoint *b,
     {
       const struct symbol *sym = loc->symbol;
 
-      if (sym == NULL)
-       sym = find_pc_sect_function (loc->address, loc->section);
-
       if (sym)
        {
          uiout->text ("in ");
-         uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
+         uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
+                              ui_out_style_kind::FUNCTION);
          uiout->text (" ");
          uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
          uiout->text ("at ");
        }
       uiout->field_string ("file",
-                          symtab_to_filename_for_display (loc->symtab));
+                          symtab_to_filename_for_display (loc->symtab),
+                          ui_out_style_kind::FILE);
       uiout->text (":");
 
       if (uiout->is_mi_like_p ())
@@ -6041,16 +6036,9 @@ print_one_breakpoint_location (struct breakpoint *b,
   /* 1 */
   annotate_field (0);
   if (part_of_multiple)
-    {
-      char *formatted;
-      formatted = xstrprintf ("%d.%d", b->number, loc_number);
-      uiout->field_string ("number", formatted);
-      xfree (formatted);
-    }
+    uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
   else
-    {
-      uiout->field_int ("number", b->number);
-    }
+    uiout->field_int ("number", b->number);
 
   /* 2 */
   annotate_field (1);
@@ -6066,16 +6054,13 @@ print_one_breakpoint_location (struct breakpoint *b,
   else
     uiout->field_string ("disp", bpdisp_text (b->disposition));
 
-
   /* 4 */
   annotate_field (3);
   if (part_of_multiple)
     uiout->field_string ("enabled", loc->enabled ? "y" : "n");
   else
     uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
-  uiout->spaces (2);
 
-  
   /* 5 and 6 */
   if (b->ops != NULL && b->ops->print_one != NULL)
     {
@@ -6160,11 +6145,10 @@ print_one_breakpoint_location (struct breakpoint *b,
 
   if (loc != NULL && !header_of_multiple)
     {
-      struct inferior *inf;
       std::vector<int> inf_nums;
       int mi_only = 1;
 
-      ALL_INFERIORS (inf)
+      for (inferior *inf : all_inferiors ())
        {
          if (inf->pspace == loc->pspace)
            inf_nums.push_back (inf->num);
@@ -7315,7 +7299,7 @@ set_longjmp_breakpoint_for_call_dummy (void)
        new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
                                                  &momentary_breakpoint_ops,
                                                  1);
-       new_b->thread = ptid_to_global_thread_id (inferior_ptid);
+       new_b->thread = inferior_thread ()->global_num;
 
        /* Link NEW_B into the chain of RETVAL breakpoints.  */
 
@@ -7355,7 +7339,7 @@ check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
            || frame_find_by_id (dummy_b->frame_id) != NULL)
          continue;
        
-       dummy_frame_discard (dummy_b->frame_id, tp->ptid);
+       dummy_frame_discard (dummy_b->frame_id, tp);
 
        while (b->related_breakpoint != b)
          {
@@ -7702,7 +7686,7 @@ struct fork_catchpoint : public breakpoint
 static int
 insert_catch_fork (struct bp_location *bl)
 {
-  return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_insert_fork_catchpoint (inferior_ptid.pid ());
 }
 
 /* Implement the "remove" breakpoint_ops method for fork
@@ -7711,7 +7695,7 @@ insert_catch_fork (struct bp_location *bl)
 static int
 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
 {
-  return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_remove_fork_catchpoint (inferior_ptid.pid ());
 }
 
 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
@@ -7754,7 +7738,7 @@ print_it_catch_fork (bpstat bs)
     }
   uiout->field_int ("bkptno", b->number);
   uiout->text (" (forked process ");
-  uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
+  uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
   uiout->text ("), ");
   return PRINT_SRC_AND_LOC;
 }
@@ -7778,10 +7762,10 @@ print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
     uiout->field_skip ("addr");
   annotate_field (5);
   uiout->text ("fork");
-  if (!ptid_equal (c->forked_inferior_pid, null_ptid))
+  if (c->forked_inferior_pid != null_ptid)
     {
       uiout->text (", process ");
-      uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
+      uiout->field_int ("what", c->forked_inferior_pid.pid ());
       uiout->spaces (1);
     }
 
@@ -7818,7 +7802,7 @@ static struct breakpoint_ops catch_fork_breakpoint_ops;
 static int
 insert_catch_vfork (struct bp_location *bl)
 {
-  return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_insert_vfork_catchpoint (inferior_ptid.pid ());
 }
 
 /* Implement the "remove" breakpoint_ops method for vfork
@@ -7827,7 +7811,7 @@ insert_catch_vfork (struct bp_location *bl)
 static int
 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
 {
-  return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_remove_vfork_catchpoint (inferior_ptid.pid ());
 }
 
 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
@@ -7870,7 +7854,7 @@ print_it_catch_vfork (bpstat bs)
     }
   uiout->field_int ("bkptno", b->number);
   uiout->text (" (vforked process ");
-  uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
+  uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
   uiout->text ("), ");
   return PRINT_SRC_AND_LOC;
 }
@@ -7893,10 +7877,10 @@ print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
     uiout->field_skip ("addr");
   annotate_field (5);
   uiout->text ("vfork");
-  if (!ptid_equal (c->forked_inferior_pid, null_ptid))
+  if (c->forked_inferior_pid != null_ptid)
     {
       uiout->text (", process ");
-      uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
+      uiout->field_int ("what", c->forked_inferior_pid.pid ());
       uiout->spaces (1);
     }
 
@@ -8051,7 +8035,6 @@ print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
   struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
-  char *msg;
 
   get_user_print_options (&opts);
   /* Field 4, the address, is omitted (which makes the columns not
@@ -8063,23 +8046,23 @@ print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
       uiout->field_skip ("addr");
     }
 
+  std::string msg;
   annotate_field (5);
   if (self->is_load)
     {
       if (self->regex)
-       msg = xstrprintf (_("load of library matching %s"), self->regex);
+       msg = string_printf (_("load of library matching %s"), self->regex);
       else
-       msg = xstrdup (_("load of library"));
+       msg = _("load of library");
     }
   else
     {
       if (self->regex)
-       msg = xstrprintf (_("unload of library matching %s"), self->regex);
+       msg = string_printf (_("unload of library matching %s"), self->regex);
       else
-       msg = xstrdup (_("unload of library"));
+       msg = _("unload of library");
     }
   uiout->field_string ("what", msg);
-  xfree (msg);
 
   if (uiout->is_mi_like_p ())
     uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
@@ -8247,13 +8230,13 @@ exec_catchpoint::~exec_catchpoint ()
 static int
 insert_catch_exec (struct bp_location *bl)
 {
-  return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_insert_exec_catchpoint (inferior_ptid.pid ());
 }
 
 static int
 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
 {
-  return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
+  return target_remove_exec_catchpoint (inferior_ptid.pid ());
 }
 
 static int
@@ -8496,11 +8479,7 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
   b->disposition = disp_donttouch;
   b->frame_id = frame_id;
 
-  /* If we're debugging a multi-threaded program, then we want
-     momentary breakpoints to be active in only a single thread of
-     control.  */
-  if (in_thread_list (inferior_ptid))
-    b->thread = ptid_to_global_thread_id (inferior_ptid);
+  b->thread = inferior_thread ()->global_num;
 
   update_global_location_list_nothrow (UGLL_MAY_INSERT);
 
@@ -9600,7 +9579,7 @@ stopat_command (const char *arg, int from_tty)
     }
 
   if (badInput)
-    printf_filtered (_("Usage: stop at <line>\n"));
+    printf_filtered (_("Usage: stop at LINE\n"));
   else
     break_command_1 (arg, 0, from_tty);
 }
@@ -10527,7 +10506,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 {
   struct breakpoint *scope_breakpoint = NULL;
   const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
-  struct value *mark, *result;
+  struct value *result;
   int saved_bitpos = 0, saved_bitsize = 0;
   const char *exp_start = NULL;
   const char *exp_end = NULL;
@@ -10652,7 +10631,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
     }
 
   exp_valid_block = innermost_block.block ();
-  mark = value_mark ();
+  struct value *mark = value_mark ();
   struct value *val_as_value = nullptr;
   fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL,
                      just_location);
@@ -11503,14 +11482,14 @@ clear_command (const char *arg, int from_tty)
 
   /* Remove duplicates from the vec.  */
   std::sort (found.begin (), found.end (),
-            [] (const breakpoint *a, const breakpoint *b)
+            [] (const breakpoint *bp_a, const breakpoint *bp_b)
             {
-              return compare_breakpoints (a, b) < 0;
+              return compare_breakpoints (bp_a, bp_b) < 0;
             });
   found.erase (std::unique (found.begin (), found.end (),
-                           [] (const breakpoint *a, const breakpoint *b)
+                           [] (const breakpoint *bp_a, const breakpoint *bp_b)
                            {
-                             return compare_breakpoints (a, b) == 0;
+                             return compare_breakpoints (bp_a, bp_b) == 0;
                            }),
               found.end ());
 
@@ -12009,7 +11988,7 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
              old_loc->events_till_retirement = 3 * (thread_count () + 1);
              old_loc->owner = NULL;
 
-             VEC_safe_push (bp_location_p, moribund_locations, old_loc);
+             moribund_locations.push_back (old_loc);
            }
          else
            {
@@ -12112,16 +12091,16 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
 void
 breakpoint_retire_moribund (void)
 {
-  struct bp_location *loc;
-  int ix;
-
-  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
-    if (--(loc->events_till_retirement) == 0)
-      {
-       decref_bp_location (&loc);
-       VEC_unordered_remove (bp_location_p, moribund_locations, ix);
-       --ix;
-      }
+  for (int ix = 0; ix < moribund_locations.size (); ++ix)
+    {
+      struct bp_location *loc = moribund_locations[ix];
+      if (--(loc->events_till_retirement) == 0)
+       {
+         decref_bp_location (&loc);
+         unordered_remove (moribund_locations, ix);
+         --ix;
+       }
+    }
 }
 
 static void
@@ -12212,9 +12191,14 @@ say_where (struct breakpoint *b)
          /* If there is a single location, we can print the location
             more nicely.  */
          if (b->loc->next == NULL)
-           printf_filtered (": file %s, line %d.",
-                            symtab_to_filename_for_display (b->loc->symtab),
-                            b->loc->line_number);
+           {
+             puts_filtered (": file ");
+             fputs_styled (symtab_to_filename_for_display (b->loc->symtab),
+                           file_name_style.style (),
+                           gdb_stdout);
+             printf_filtered (", line %d.",
+                              b->loc->line_number);
+           }
          else
            /* This is not ideal, but each location may have a
               different file name, and this at least reflects the
@@ -13299,9 +13283,9 @@ delete_command (const char *arg, int from_tty)
     }
   else
     map_breakpoint_numbers
-      (arg, [&] (breakpoint *b)
+      (arg, [&] (breakpoint *br)
        {
-        iterate_over_related_breakpoints (b, delete_breakpoint);
+        iterate_over_related_breakpoints (br, delete_breakpoint);
        });
 }
 
@@ -13446,11 +13430,13 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
          uiout->text ("Now in ");
          if (sym)
            {
-             uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
+             uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
+                                  ui_out_style_kind::FUNCTION);
              uiout->text (" at ");
            }
          uiout->field_string ("file",
-                              symtab_to_filename_for_display (sal2.symtab));
+                              symtab_to_filename_for_display (sal2.symtab),
+                              ui_out_style_kind::FILE);
          uiout->text (":");
 
          if (uiout->is_mi_like_p ())
@@ -13922,8 +13908,7 @@ breakpoint_re_set_thread (struct breakpoint *b)
 {
   if (b->thread != -1)
     {
-      if (in_thread_list (inferior_ptid))
-       b->thread = ptid_to_global_thread_id (inferior_ptid);
+      b->thread = inferior_thread ()->global_num;
 
       /* We're being called after following a fork.  The new fork is
         selected as current, and unless this was a vfork will have a
@@ -14228,6 +14213,8 @@ enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
        target_disable_tracepoint (loc);
     }
   update_global_location_list (UGLL_DONT_INSERT);
+
+  gdb::observers::breakpoint_modified.notify (loc->owner);
 }
 
 /* Enable or disable a range of breakpoint locations.  BP_NUM is the
@@ -14699,7 +14686,7 @@ read_uploaded_action (void)
 
   if (next_cmd < this_utp->cmd_strings.size ())
     {
-      rslt = this_utp->cmd_strings[next_cmd];
+      rslt = this_utp->cmd_strings[next_cmd].get ();
       next_cmd++;
     }
 
@@ -14720,7 +14707,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
   struct tracepoint *tp;
 
   if (utp->at_string)
-    addr_str = utp->at_string;
+    addr_str = utp->at_string.get ();
   else
     {
       /* In the absence of a source location, fall back to raw
@@ -14744,7 +14731,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
                                                         current_language);
   if (!create_breakpoint (get_current_arch (),
                          location.get (),
-                         utp->cond_string, -1, addr_str,
+                         utp->cond_string.get (), -1, addr_str,
                          0 /* parse cond/thread */,
                          0 /* tempflag */,
                          utp->type /* type_wanted */,
@@ -14869,9 +14856,9 @@ delete_trace_command (const char *arg, int from_tty)
     }
   else
     map_breakpoint_numbers
-      (arg, [&] (breakpoint *b)
+      (arg, [&] (breakpoint *br)
        {
-        iterate_over_related_breakpoints (b, delete_breakpoint);
+        iterate_over_related_breakpoints (br, delete_breakpoint);
        });
 }
 
@@ -15164,15 +15151,15 @@ save_tracepoints_command (const char *args, int from_tty)
 
 /* Create a vector of all tracepoints.  */
 
-VEC(breakpoint_p) *
+std::vector<breakpoint *>
 all_tracepoints (void)
 {
-  VEC(breakpoint_p) *tp_vec = 0;
+  std::vector<breakpoint *> tp_vec;
   struct breakpoint *tp;
 
   ALL_TRACEPOINTS (tp)
   {
-    VEC_safe_push (breakpoint_p, tp_vec, tp);
+    tp_vec.push_back (tp);
   }
 
   return tp_vec;
@@ -15514,6 +15501,10 @@ initialize_breakpoint_ops (void)
 
 static struct cmd_list_element *enablebreaklist = NULL;
 
+/* See breakpoint.h.  */
+
+cmd_list_element *commands_cmd_element = nullptr;
+
 void
 _initialize_breakpoint (void)
 {
@@ -15539,7 +15530,8 @@ _initialize_breakpoint (void)
 Set ignore-count of breakpoint number N to COUNT.\n\
 Usage is `ignore N COUNT'."));
 
-  add_com ("commands", class_breakpoint, commands_command, _("\
+  commands_cmd_element = add_com ("commands", class_breakpoint,
+                                 commands_command, _("\
 Set commands to be executed when the given breakpoints are hit.\n\
 Give a space-separated breakpoint list as argument after \"commands\".\n\
 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
This page took 0.046772 seconds and 4 git commands to generate.