Merge remote-tracking branch 'origin/master' into amd-common
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 31f4005ec7f9c7c07aada509f42c0630ed9f4425..9e8291b4af0d2084731d801ec3990899ba633d13 100644 (file)
@@ -1,6 +1,7 @@
 /* Everything about breakpoints, for GDB.
 
-   Copyright (C) 1986-2019 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
 
    This file is part of GDB.
 
@@ -246,6 +247,9 @@ struct breakpoint_ops bkpt_breakpoint_ops;
 /* Breakpoints set on probes.  */
 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
 
+/* Tracepoints set on probes.  */
+static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
+
 /* Dynamic printf class type.  */
 struct breakpoint_ops dprintf_breakpoint_ops;
 
@@ -364,7 +368,10 @@ show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
    breakpoints until the next resume, and removes them again when the
    target fully stops.  This is a bit safer in case GDB crashes while
    processing user input.  */
-static bool always_inserted_mode = false;
+/* FIXME: this is a temporary workaround to make sure waves created while
+   all known threads are stopped, and the gdb prompt is presented, do not
+   execute past the enabled breakpoints.  */
+static bool always_inserted_mode = true;
 
 static void
 show_always_inserted_mode (struct ui_file *file, int from_tty,
@@ -386,7 +393,7 @@ breakpoints_should_be_inserted_now (void)
         no threads under GDB's control yet.  */
       return 1;
     }
-  else if (target_has_execution)
+  else
     {
       if (always_inserted_mode)
        {
@@ -395,8 +402,10 @@ breakpoints_should_be_inserted_now (void)
          return 1;
        }
 
-      if (threads_are_executing ())
-       return 1;
+      for (inferior *inf : all_inferiors ())
+       if (inf->has_execution ()
+           && threads_are_executing (inf->process_target ()))
+         return 1;
 
       /* Don't remove breakpoints yet if, even though all threads are
         stopped, we still have events to process.  */
@@ -517,9 +526,9 @@ bool target_exact_watchpoints = false;
 
 /* Chains of all breakpoints defined.  */
 
-struct breakpoint *breakpoint_chain;
+static struct breakpoint *breakpoint_chain;
 
-/* Array is sorted by bp_locations_compare - primarily by the ADDRESS.  */
+/* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS.  */
 
 static struct bp_location **bp_locations;
 
@@ -773,7 +782,7 @@ show_condition_evaluation_mode (struct ui_file *file, int from_tty,
 
 /* 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_locations_compare function.  */
+   the more general bp_location_is_less_than function.  */
 
 static int
 bp_locations_compare_addrs (const void *ap, const void *bp)
@@ -2884,7 +2893,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)
+         && (inferior_ptid == null_ptid || !target_has_execution))
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -2940,7 +2949,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)
+         && (inferior_ptid == null_ptid || !target_has_execution))
        continue;
 
       val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
@@ -5818,7 +5827,7 @@ print_breakpoint_location (struct breakpoint *b,
       if (sym)
        {
          uiout->text ("in ");
-         uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
+         uiout->field_string ("func", sym->print_name (),
                               function_name_style.style ());
          uiout->text (" ");
          uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
@@ -7085,7 +7094,7 @@ set_breakpoint_location_function (struct bp_location *loc)
        {
          struct breakpoint *b = loc->owner;
 
-         function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol);
+         function_name = loc->msymbol->linkage_name ();
 
          if (b->type == bp_breakpoint && b->loc == loc
              && loc->next == NULL && b->related_breakpoint == b)
@@ -8506,7 +8515,9 @@ static void
 mention (struct breakpoint *b)
 {
   b->ops->print_mention (b);
-  current_uiout->text ("\n");
+  if (current_uiout->is_mi_like_p ())
+    return;
+  printf_filtered ("\n");
 }
 \f
 
@@ -9163,6 +9174,41 @@ decode_static_tracepoint_spec (const char **arg_p)
   return sals;
 }
 
+/* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
+   according to IS_TRACEPOINT.  */
+
+static const struct breakpoint_ops *
+breakpoint_ops_for_event_location_type (enum event_location_type location_type,
+                                       bool is_tracepoint)
+{
+  if (is_tracepoint)
+    {
+      if (location_type == PROBE_LOCATION)
+       return &tracepoint_probe_breakpoint_ops;
+      else
+       return &tracepoint_breakpoint_ops;
+    }
+  else
+    {
+      if (location_type == PROBE_LOCATION)
+       return &bkpt_probe_breakpoint_ops;
+      else
+       return &bkpt_breakpoint_ops;
+    }
+}
+
+/* See breakpoint.h.  */
+
+const struct breakpoint_ops *
+breakpoint_ops_for_event_location (const struct event_location *location,
+                                  bool is_tracepoint)
+{
+  if (location != nullptr)
+    return breakpoint_ops_for_event_location_type
+      (event_location_type (location), is_tracepoint);
+  return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops;
+}
+
 /* See breakpoint.h.  */
 
 int
@@ -9344,16 +9390,10 @@ break_command_1 (const char *arg, int flag, int from_tty)
   enum bptype type_wanted = (flag & BP_HARDWAREFLAG
                             ? bp_hardware_breakpoint
                             : bp_breakpoint);
-  struct breakpoint_ops *ops;
 
   event_location_up location = string_to_event_location (&arg, current_language);
-
-  /* Matching breakpoints on probes.  */
-  if (location != NULL
-      && event_location_type (location.get ()) == PROBE_LOCATION)
-    ops = &bkpt_probe_breakpoint_ops;
-  else
-    ops = &bkpt_breakpoint_ops;
+  const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
+    (location.get (), false /* is_tracepoint */);
 
   create_breakpoint (get_current_arch (),
                     location.get (),
@@ -11428,41 +11468,36 @@ breakpoint_auto_delete (bpstat bs)
 }
 
 /* A comparison function for bp_location AP and BP being interfaced to
-   qsort.  Sort elements primarily by their ADDRESS (no matter what
+   std::sort.  Sort elements primarily by their ADDRESS (no matter what
    bl_address_is_meaningful says), secondarily by ordering first
    permanent elements and terciarily just ensuring the array is sorted
-   stable way despite qsort being an unstable algorithm.  */
+   stable way despite std::sort being an unstable algorithm.  */
 
 static int
-bp_locations_compare (const void *ap, const void *bp)
+bp_location_is_less_than (const bp_location *a, const bp_location *b)
 {
-  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 (a->address > b->address) - (a->address < b->address);
+    return a->address < b->address;
 
   /* Sort locations at the same address by their pspace number, keeping
      locations of the same inferior (in a multi-inferior environment)
      grouped.  */
 
   if (a->pspace->num != b->pspace->num)
-    return ((a->pspace->num > b->pspace->num)
-           - (a->pspace->num < b->pspace->num));
+    return a->pspace->num < b->pspace->num;
 
   /* Sort permanent breakpoints first.  */
   if (a->permanent != b->permanent)
-    return (a->permanent < b->permanent) - (a->permanent > b->permanent);
+    return a->permanent > b->permanent;
 
   /* 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.  */
 
   if (a->owner->number != b->owner->number)
-    return ((a->owner->number > b->owner->number)
-           - (a->owner->number < b->owner->number));
+    return a->owner->number < b->owner->number;
 
-  return (a > b) - (a < b);
+  return a < b;
 }
 
 /* Set bp_locations_placed_address_before_address_max and
@@ -11677,8 +11712,8 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
   ALL_BREAKPOINTS (b)
     for (loc = b->loc; loc; loc = loc->next)
       *locp++ = loc;
-  qsort (bp_locations, bp_locations_count, sizeof (*bp_locations),
-        bp_locations_compare);
+  std::sort (bp_locations, bp_locations + bp_locations_count,
+            bp_location_is_less_than);
 
   bp_locations_target_extensions_update ();
 
@@ -11876,7 +11911,18 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
                 around.  We simply always ignore hardware watchpoint
                 traps we can no longer explain.  */
 
-             old_loc->events_till_retirement = 3 * (thread_count () + 1);
+             process_stratum_target *proc_target = nullptr;
+             for (inferior *inf : all_inferiors ())
+               if (inf->pspace == old_loc->pspace)
+                 {
+                   proc_target = inf->process_target ();
+                   break;
+                 }
+             if (proc_target != nullptr)
+               old_loc->events_till_retirement
+                 = 3 * (thread_count (proc_target) + 1);
+             else
+               old_loc->events_till_retirement = 1;
              old_loc->owner = NULL;
 
              moribund_locations.push_back (old_loc);
@@ -12807,8 +12853,7 @@ tracepoint_decode_location (struct breakpoint *b,
 
 struct breakpoint_ops tracepoint_breakpoint_ops;
 
-/* The breakpoint_ops structure to be use on tracepoints placed in a
-   static probe.  */
+/* Virtual table for tracepoints on static probes.  */
 
 static void
 tracepoint_probe_create_sals_from_location
@@ -12829,8 +12874,6 @@ tracepoint_probe_decode_location (struct breakpoint *b,
   return bkpt_probe_decode_location (b, location, search_pspace);
 }
 
-static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
-
 /* Dprintf breakpoint_ops methods.  */
 
 static void
@@ -13309,7 +13352,7 @@ 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", sym->print_name (),
                                   function_name_style.style ());
              uiout->text (" at ");
            }
@@ -14472,15 +14515,10 @@ set_tracepoint_count (int num)
 static void
 trace_command (const char *arg, int from_tty)
 {
-  struct breakpoint_ops *ops;
-
   event_location_up location = string_to_event_location (&arg,
                                                         current_language);
-  if (location != NULL
-      && event_location_type (location.get ()) == PROBE_LOCATION)
-    ops = &tracepoint_probe_breakpoint_ops;
-  else
-    ops = &tracepoint_breakpoint_ops;
+  const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
+    (location.get (), true /* is_tracepoint */);
 
   create_breakpoint (get_current_arch (),
                     location.get (),
@@ -15128,14 +15166,13 @@ save_command (const char *arg, int from_tty)
 }
 
 struct breakpoint *
-iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
-                         void *data)
+iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback)
 {
   struct breakpoint *b, *b_tmp;
 
   ALL_BREAKPOINTS_SAFE (b, b_tmp)
     {
-      if ((*callback) (b, data))
+      if (callback (b))
        return b;
     }
 
This page took 0.032469 seconds and 4 git commands to generate.