Follow-up to Support style in 'frame|thread apply'
[deliverable/binutils-gdb.git] / gdb / exec.c
index 9b00c2e8980c8304524354a22600514d048c9cc8..7de92347f2eee516cb8db2aa6b70a89c7ffd8947 100644 (file)
@@ -1,6 +1,6 @@
 /* Work with executable files, for GDB. 
 
-   Copyright (C) 1988-2018 Free Software Foundation, Inc.
+   Copyright (C) 1988-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 void (*deprecated_file_changed_hook) (const char *);
 
+static const target_info exec_target_info = {
+  "exec",
+  N_("Local exec file"),
+  N_("Use an executable file as a target.\n\
+Specify the filename of the executable file.")
+};
+
 /* The target vector for executable files.  */
 
 struct exec_target final : public target_ops
 {
-  exec_target ()
-  { to_stratum = file_stratum; }
-
-  const char *shortname () override
-  { return "exec"; }
+  const target_info &info () const override
+  { return exec_target_info; }
 
-  const char *longname () override
-  { return _("Local exec file"); }
+  strata stratum () const override { return file_stratum; }
 
-  const char *doc () override
-  {
-    return _("\
-Use an executable file as a target.\n\
-Specify the filename of the executable file.");
-  }
-
-  void open (const char *, int) override;
   void close () override;
   enum target_xfer_status xfer_partial (enum target_object object,
                                        const char *annex,
@@ -80,7 +75,7 @@ Specify the filename of the executable file.");
   struct target_section_table *get_section_table () override;
   void files_info () override;
 
-  int has_memory () override;
+  bool has_memory () override;
   char *make_corefile_notes (bfd *, int *) override;
   int find_memory_regions (find_memory_region_ftype func, void *data) override;
 };
@@ -99,8 +94,8 @@ show_write_files (struct ui_file *file, int from_tty,
 }
 
 
-void
-exec_target::open (const char *args, int from_tty)
+static void
+exec_target_open (const char *args, int from_tty)
 {
   target_preopen (from_tty);
   exec_file_attach (args, from_tty);
@@ -153,10 +148,7 @@ void
 try_open_exec_file (const char *exec_file_host, struct inferior *inf,
                    symfile_add_flags add_flags)
 {
-  struct cleanup *old_chain;
-  struct gdb_exception prev_err = exception_none;
-
-  old_chain = make_cleanup (free_current_contents, &prev_err.message);
+  struct gdb_exception prev_err;
 
   /* exec_file_attach and symbol_file_add_main may throw an error if the file
      cannot be opened either locally or remotely.
@@ -169,40 +161,32 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
      Even without a symbol file, the remote-based debugging session should
      continue normally instead of ending abruptly.  Hence we catch thrown
      errors/exceptions in the following code.  */
-  TRY
+  try
     {
       /* We must do this step even if exec_file_host is NULL, so that
         exec_file_attach will clear state.  */
       exec_file_attach (exec_file_host, add_flags & SYMFILE_VERBOSE);
     }
-  CATCH (err, RETURN_MASK_ERROR)
+  catch (gdb_exception_error &err)
     {
       if (err.message != NULL)
-       warning ("%s", err.message);
-
-      prev_err = err;
+       warning ("%s", err.what ());
 
-      /* Save message so it doesn't get trashed by the catch below.  */
-      if (err.message != NULL)
-       prev_err.message = xstrdup (err.message);
+      prev_err = std::move (err);
     }
-  END_CATCH
 
   if (exec_file_host != NULL)
     {
-      TRY
+      try
        {
          symbol_file_add_main (exec_file_host, add_flags);
        }
-      CATCH (err, RETURN_MASK_ERROR)
+      catch (const gdb_exception_error &err)
        {
          if (!exception_print_same (prev_err, err))
-           warning ("%s", err.message);
+           warning ("%s", err.what ());
        }
-      END_CATCH
     }
-
-  do_cleanups (old_chain);
 }
 
 /* See gdbcore.h.  */
@@ -366,7 +350,7 @@ exec_file_attach (const char *filename, int from_tty)
          exec_close ();
          error (_("\"%s\": not in executable format: %s"),
                 scratch_pathname,
-                gdb_bfd_errmsg (bfd_get_error (), matching));
+                gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
        }
 
       if (build_section_table (exec_bfd, &sections, &sections_end))
@@ -1031,7 +1015,7 @@ exec_set_section_address (const char *filename, int index, CORE_ADDR address)
     }
 }
 
-int
+bool
 exec_target::has_memory ()
 {
   /* We can provide memory if we have any file/target sections to read
@@ -1090,5 +1074,5 @@ Show writing into executable and core files."), NULL,
                           show_write_files,
                           &setlist, &showlist);
 
-  add_target_with_completer (&exec_ops, filename_completer);
+  add_target (exec_target_info, exec_target_open, filename_completer);
 }
This page took 0.02532 seconds and 4 git commands to generate.