gdb/mi: New commands to catch C++ exceptions
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 5bfa5b2b7b340054f480335b04a691550b12ec8e..ccd778b7a13ef8fe52d6e9dab44517d41988bf60 100644 (file)
 #include "common/array-view.h"
 #include "common/gdb_optional.h"
 
-/* Enums for exception-handling support.  */
-enum exception_event_kind
-{
-  EX_EVENT_THROW,
-  EX_EVENT_RETHROW,
-  EX_EVENT_CATCH
-};
-
 /* Prototypes for local functions.  */
 
 static void map_breakpoint_numbers (const char *,
@@ -941,10 +933,7 @@ condition_completer (struct cmd_list_element *cmd,
          xsnprintf (number, sizeof (number), "%d", b->number);
 
          if (strncmp (number, text, len) == 0)
-           {
-             gdb::unique_xmalloc_ptr<char> copy (xstrdup (number));
-             tracker.add_completion (std::move (copy));
-           }
+           tracker.add_completion (make_unique_xstrdup (number));
        }
 
       return;
@@ -2434,7 +2423,7 @@ insert_bp_location (struct bp_location *bl,
                    int *hw_breakpoint_error,
                    int *hw_bp_error_explained_already)
 {
-  gdb_exception bp_excpt = exception_none;
+  gdb_exception bp_excpt;
 
   if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
     return 0;
@@ -2545,9 +2534,9 @@ insert_bp_location (struct bp_location *bl,
              if (val)
                bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
            }
-         catch (const gdb_exception &e)
+         catch (gdb_exception &e)
            {
-             bp_excpt = e;
+             bp_excpt = std::move (e);
            }
        }
       else
@@ -2584,9 +2573,9 @@ insert_bp_location (struct bp_location *bl,
                        bp_excpt
                          = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
                    }
-                 catch (const gdb_exception &e)
+                 catch (gdb_exception &e)
                    {
-                     bp_excpt = e;
+                     bp_excpt = std::move (e);
                    }
 
                  if (bp_excpt.reason != 0)
@@ -2608,9 +2597,9 @@ insert_bp_location (struct bp_location *bl,
                  if (val)
                    bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
                }
-             catch (const gdb_exception &e)
+             catch (gdb_exception &e)
                {
-                 bp_excpt = e;
+                 bp_excpt = std::move (e);
                }
            }
          else
@@ -3156,7 +3145,8 @@ struct breakpoint_objfile_data
   std::vector<probe *> exception_probes;
 };
 
-static const struct objfile_data *breakpoint_objfile_key;
+static const struct objfile_key<breakpoint_objfile_data>
+  breakpoint_objfile_key;
 
 /* Minimal symbol not found sentinel.  */
 static struct minimal_symbol msym_not_found;
@@ -3177,25 +3167,12 @@ get_breakpoint_objfile_data (struct objfile *objfile)
 {
   struct breakpoint_objfile_data *bp_objfile_data;
 
-  bp_objfile_data = ((struct breakpoint_objfile_data *)
-                    objfile_data (objfile, breakpoint_objfile_key));
+  bp_objfile_data = breakpoint_objfile_key.get (objfile);
   if (bp_objfile_data == NULL)
-    {
-      bp_objfile_data = new breakpoint_objfile_data ();
-      set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
-    }
+    bp_objfile_data = breakpoint_objfile_key.emplace (objfile);
   return bp_objfile_data;
 }
 
-static void
-free_breakpoint_objfile_data (struct objfile *obj, void *data)
-{
-  struct breakpoint_objfile_data *bp_objfile_data
-    = (struct breakpoint_objfile_data *) data;
-
-  delete bp_objfile_data;
-}
-
 static void
 create_overlay_event_breakpoint (void)
 {
@@ -6349,13 +6326,19 @@ print_one_breakpoint_location (struct breakpoint *b,
     }
 }
 
+/* See breakpoint.h. */
+
+bool fix_multi_location_breakpoint_output_globally = false;
+
 static void
 print_one_breakpoint (struct breakpoint *b,
                      struct bp_location **last_loc, 
                      int allflag)
 {
   struct ui_out *uiout = current_uiout;
-  bool use_fixed_output = mi_multi_location_breakpoint_output_fixed (uiout);
+  bool use_fixed_output
+    = (uiout->test_flags (fix_multi_location_breakpoint_output)
+       || fix_multi_location_breakpoint_output_globally);
 
   gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
   print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
@@ -9253,7 +9236,7 @@ create_breakpoint (struct gdbarch *gdbarch,
             error.  */
 
          if (pending_break_support == AUTO_BOOLEAN_FALSE)
-           throw_exception (e);
+           throw;
 
          exception_print (gdb_stderr, e);
 
@@ -9271,7 +9254,7 @@ create_breakpoint (struct gdbarch *gdbarch,
          pending = 1;
        }
       else
-       throw_exception (e);
+       throw;
     }
 
   if (!pending && canonical.lsals.empty ())
@@ -10905,10 +10888,7 @@ watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
   if (arg
       && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
          || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
-    {
-      arg = skip_spaces (arg);
-      just_location = 1;
-    }
+    just_location = 1;
 
   watch_command_1 (arg, accessflag, from_tty, just_location, 0);
 }
@@ -13593,7 +13573,7 @@ static std::vector<symtab_and_line>
 location_to_sals (struct breakpoint *b, struct event_location *location,
                  struct program_space *search_pspace, int *found)
 {
-  struct gdb_exception exception = exception_none;
+  struct gdb_exception exception;
 
   gdb_assert (b->ops != NULL);
 
@@ -13603,12 +13583,10 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
     {
       sals = b->ops->decode_location (b, location, search_pspace);
     }
-  catch (const gdb_exception_error &e)
+  catch (gdb_exception_error &e)
     {
       int not_found_and_ok = 0;
 
-      exception = e;
-
       /* For pending breakpoints, it's expected that parsing will
         fail until the right shared library is loaded.  User has
         already told to create pending breakpoints and don't need
@@ -13635,8 +13613,10 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
             happens only when a binary has changed, I don't know
             which approach is better.  */
          b->enable_state = bp_disabled;
-         throw_exception (e);
+         throw;
        }
+
+      exception = std::move (e);
     }
 
   if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
@@ -15034,7 +15014,7 @@ save_breakpoints (const char *filename, int from_tty,
        catch (const gdb_exception &ex)
          {
          current_uiout->redirect (NULL);
-           throw_exception (ex);
+           throw;
          }
 
        current_uiout->redirect (NULL);
@@ -15123,7 +15103,7 @@ functions in all scopes.  For C++, this means in all namespaces and\n\
 classes.  For Ada, this means in all packages.  E.g., in C++,\n\
 \"func()\" matches \"A::func()\", \"A::B::func()\", etc.  The\n\
 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
-specified name as a complete fully-qualified name instead.\n"
+specified name as a complete fully-qualified name instead."
 
 /* This help string is used for the break, hbreak, tbreak and thbreak
    commands.  It is defined as a macro to prevent duplication.
@@ -15144,7 +15124,7 @@ 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" LOCATION_HELP_STRING "\n\
+\n" LOCATION_HELP_STRING "\n\n\
 Multiple breakpoints at one place are permitted, and useful if their\n\
 conditions are different.\n\
 \n\
@@ -15448,9 +15428,6 @@ _initialize_breakpoint (void)
   gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile);
   gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change);
 
-  breakpoint_objfile_key
-    = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data);
-
   breakpoint_chain = 0;
   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
      before a breakpoint is set.  */
@@ -15519,7 +15496,7 @@ With a subcommand you can enable temporarily."),
 Enable some breakpoints.\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\".\n"),
+May be abbreviated to simply \"enable\"."),
                   &enablebreaklist, "enable breakpoints ", 1, &enablelist);
 
   add_cmd ("once", no_class, enable_once_command, _("\
@@ -15595,7 +15572,7 @@ Argument may be a linespec, explicit, or address location as described below.\n\
 \n\
 With no argument, clears all breakpoints in the line that the selected frame\n\
 is executing in.\n"
-"\n" LOCATION_HELP_STRING "\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);
 
@@ -15795,7 +15772,7 @@ tracing library.  You can inspect it when analyzing the trace buffer,\n\
 by printing the $_sdata variable like any other convenience variable.\n\
 \n\
 CONDITION is a boolean expression.\n\
-\n" LOCATION_HELP_STRING "\n\
+\n" LOCATION_HELP_STRING "\n\n\
 Multiple tracepoints at one place are permitted, and useful if their\n\
 conditions are different.\n\
 \n\
This page took 0.030717 seconds and 4 git commands to generate.