Remove cleanups from solib-target.c
[deliverable/binutils-gdb.git] / gdb / corelow.c
index ed20b531beed7432dbd3782fd61d32d5412241d2..ab32e09828b078de551e284f330f0aa2239dbfdf 100644 (file)
@@ -1,6 +1,6 @@
 /* Core dump and executable file functions below target vector, for GDB.
 
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -31,6 +31,7 @@
 #include "command.h"
 #include "bfd.h"
 #include "target.h"
+#include "process-stratum-target.h"
 #include "gdbcore.h"
 #include "gdbthread.h"
 #include "regcache.h"
@@ -61,7 +62,7 @@ static const target_info core_target_info = {
   N_("Use a core file as a target.  Specify the filename of the core file.")
 };
 
-class core_target final : public target_ops
+class core_target final : public process_stratum_target
 {
 public:
   core_target ();
@@ -89,9 +90,12 @@ public:
 
   const char *thread_name (struct thread_info *) override;
 
+  bool has_all_memory () override { return false; }
   bool has_memory () override;
   bool has_stack () override;
   bool has_registers () override;
+  bool has_execution (ptid_t) override { return false; }
+
   bool info_proc (const char *, enum info_proc_what) override;
 
   /* A few helpers.  */
@@ -106,7 +110,7 @@ public:
   void get_core_register_section (struct regcache *regcache,
                                  const struct regset *regset,
                                  const char *name,
-                                 int min_size,
+                                 int section_min_size,
                                  int which,
                                  const char *human_name,
                                  bool required);
@@ -132,8 +136,6 @@ private: /* per-core data */
 
 core_target::core_target ()
 {
-  to_stratum = process_stratum;
-
   m_core_gdbarch = gdbarch_from_bfd (core_bfd);
 
   /* Find a suitable core file handler to munch on core_bfd */
@@ -310,7 +312,7 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
       inf->fake_pid_p = fake_pid_p;
     }
 
-  ptid = ptid_build (pid, lwpid, 0);
+  ptid = ptid_t (pid, lwpid, 0);
 
   add_thread (ptid);
 
@@ -358,7 +360,6 @@ core_target_open (const char *arg, int from_tty)
 {
   const char *p;
   int siggy;
-  struct cleanup *old_chain;
   int scratch_chan;
   int flags;
 
@@ -422,12 +423,6 @@ core_target_open (const char *arg, int from_tty)
   push_target (target);
   target_holder.release ();
 
-  /* Do this before acknowledging the inferior, so if
-     post_create_inferior throws (can happen easilly if you're loading
-     a core file with the wrong exec), we aren't left with threads
-     from the previous inferior.  */
-  init_thread_list ();
-
   inferior_ptid = null_ptid;
 
   /* Need to flush the register cache (and the frame cache) from a
@@ -444,7 +439,7 @@ core_target_open (const char *arg, int from_tty)
   bfd_map_over_sections (core_bfd, add_to_thread_list,
                         bfd_get_section_by_name (core_bfd, ".reg"));
 
-  if (ptid_equal (inferior_ptid, null_ptid))
+  if (inferior_ptid == null_ptid)
     {
       /* Either we found no .reg/NN section, and hence we have a
         non-threaded core (single-threaded, from gdb's perspective),
@@ -457,7 +452,7 @@ core_target_open (const char *arg, int from_tty)
       if (thread == NULL)
        {
          inferior_appeared (current_inferior (), CORELOW_PID);
-         inferior_ptid = pid_to_ptid (CORELOW_PID);
+         inferior_ptid = ptid_t (CORELOW_PID);
          add_thread_silent (inferior_ptid);
        }
       else
@@ -570,7 +565,7 @@ void
 core_target::get_core_register_section (struct regcache *regcache,
                                        const struct regset *regset,
                                        const char *name,
-                                       int min_size,
+                                       int section_min_size,
                                        int which,
                                        const char *human_name,
                                        bool required)
@@ -593,13 +588,13 @@ core_target::get_core_register_section (struct regcache *regcache,
     }
 
   size = bfd_section_size (core_bfd, section);
-  if (size < min_size)
+  if (size < section_min_size)
     {
       warning (_("Section `%s' in core file too small."),
               section_name.c_str ());
       return;
     }
-  if (size != min_size && !variable_size_section)
+  if (size != section_min_size && !variable_size_section)
     {
       warning (_("Unexpected size of section `%s' in core file."),
               section_name.c_str ());
@@ -637,12 +632,17 @@ struct get_core_registers_cb_data
    register note section. */
 
 static void
-get_core_registers_cb (const char *sect_name, int size,
+get_core_registers_cb (const char *sect_name, int supply_size, int collect_size,
                       const struct regset *regset,
                       const char *human_name, void *cb_data)
 {
   auto *data = (get_core_registers_cb_data *) cb_data;
   bool required = false;
+  bool variable_size_section = (regset != NULL
+                               && regset->flags & REGSET_VARIABLE_SIZE);
+
+  if (!variable_size_section)
+    gdb_assert (supply_size == collect_size);
 
   if (strcmp (sect_name, ".reg") == 0)
     {
@@ -659,7 +659,8 @@ get_core_registers_cb (const char *sect_name, int size,
   /* The 'which' parameter is only used when no regset is provided.
      Thus we just set it to -1. */
   data->target->get_core_register_section (data->regcache, regset, sect_name,
-                                          size, -1, human_name, required);
+                                          supply_size, -1, human_name,
+                                          required);
 }
 
 /* Get the registers out of a core file.  This is the machine-
@@ -1005,9 +1006,9 @@ core_target::pid_to_str (ptid_t ptid)
      "process", with normal_pid_to_str.  */
 
   /* Try the LWPID field first.  */
-  pid = ptid_get_lwp (ptid);
+  pid = ptid.lwp ();
   if (pid != 0)
-    return normal_pid_to_str (pid_to_ptid (pid));
+    return normal_pid_to_str (ptid_t (pid));
 
   /* Otherwise, this isn't a "threaded" core -- use the PID field, but
      only if it isn't a fake PID.  */
This page took 0.027122 seconds and 4 git commands to generate.