Rename common to gdbsupport
[deliverable/binutils-gdb.git] / gdb / gcore.c
index 24810a7dee9b33ecc8526142c74c088d3bec7bb0..eb108feb790c3c7d61c6c74fcfacdb2f20935f23 100644 (file)
@@ -1,6 +1,6 @@
 /* Generate a core file for the inferior process.
 
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
+   Copyright (C) 2001-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,8 +35,9 @@
 #include "gdb_bfd.h"
 #include "readline/tilde.h"
 #include <algorithm>
-#include "common/gdb_unlinker.h"
-#include "byte-vector.h"
+#include "gdbsupport/gdb_unlinker.h"
+#include "gdbsupport/byte-vector.h"
+#include "gdbsupport/scope-exit.h"
 
 /* The largest amount of memory to read from the target at once.  We
    must throttle it to limit the amount of memory used by GDB during
@@ -114,24 +115,9 @@ write_gcore_file_1 (bfd *obfd)
 void
 write_gcore_file (bfd *obfd)
 {
-  struct gdb_exception except = exception_none;
-
   target_prepare_to_generate_core ();
-
-  TRY
-    {
-      write_gcore_file_1 (obfd);
-    }
-  CATCH (e, RETURN_MASK_ALL)
-    {
-      except = e;
-    }
-  END_CATCH
-
-  target_done_generating_core ();
-
-  if (except.reason < 0)
-    throw_exception (except);
+  SCOPE_EXIT { target_done_generating_core (); };
+  write_gcore_file_1 (obfd);
 }
 
 /* gcore_command -- implements the 'gcore' command.
@@ -424,34 +410,34 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
     {
       /* See if this region of memory lies inside a known file on disk.
         If so, we can avoid copying its contents by clearing SEC_LOAD.  */
-      struct objfile *objfile;
       struct obj_section *objsec;
 
-      ALL_OBJSECTIONS (objfile, objsec)
-       {
-         bfd *abfd = objfile->obfd;
-         asection *asec = objsec->the_bfd_section;
-         bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
-                                                                   asec);
-         bfd_vma start = obj_section_addr (objsec) & -align;
-         bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
-
-         /* Match if either the entire memory region lies inside the
-            section (i.e. a mapping covering some pages of a large
-            segment) or the entire section lies inside the memory region
-            (i.e. a mapping covering multiple small sections).
-
-            This BFD was synthesized from reading target memory,
-            we don't want to omit that.  */
-         if (objfile->separate_debug_objfile_backlink == NULL
-             && ((vaddr >= start && vaddr + size <= end)
-                 || (start >= vaddr && end <= vaddr + size))
-             && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
-           {
-             flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
-             goto keep;        /* Break out of two nested for loops.  */
-           }
-       }
+      for (objfile *objfile : current_program_space->objfiles ())
+       ALL_OBJFILE_OSECTIONS (objfile, objsec)
+         {
+           bfd *abfd = objfile->obfd;
+           asection *asec = objsec->the_bfd_section;
+           bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
+                                                                     asec);
+           bfd_vma start = obj_section_addr (objsec) & -align;
+           bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
+
+           /* Match if either the entire memory region lies inside the
+              section (i.e. a mapping covering some pages of a large
+              segment) or the entire section lies inside the memory region
+              (i.e. a mapping covering multiple small sections).
+
+              This BFD was synthesized from reading target memory,
+              we don't want to omit that.  */
+           if (objfile->separate_debug_objfile_backlink == NULL
+               && ((vaddr >= start && vaddr + size <= end)
+                   || (start >= vaddr && end <= vaddr + size))
+               && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
+             {
+               flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
+               goto keep;      /* Break out of two nested for loops.  */
+             }
+         }
 
     keep:;
     }
@@ -489,36 +475,36 @@ objfile_find_memory_regions (struct target_ops *self,
                             find_memory_region_ftype func, void *obfd)
 {
   /* Use objfile data to create memory sections.  */
-  struct objfile *objfile;
   struct obj_section *objsec;
   bfd_vma temp_bottom, temp_top;
 
   /* Call callback function for each objfile section.  */
-  ALL_OBJSECTIONS (objfile, objsec)
-    {
-      bfd *ibfd = objfile->obfd;
-      asection *isec = objsec->the_bfd_section;
-      flagword flags = bfd_get_section_flags (ibfd, isec);
-
-      /* Separate debug info files are irrelevant for gcore.  */
-      if (objfile->separate_debug_objfile_backlink != NULL)
-       continue;
-
-      if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
-       {
-         int size = bfd_section_size (ibfd, isec);
-         int ret;
-
-         ret = (*func) (obj_section_addr (objsec), size, 
-                        1, /* All sections will be readable.  */
-                        (flags & SEC_READONLY) == 0, /* Writable.  */
-                        (flags & SEC_CODE) != 0, /* Executable.  */
-                        1, /* MODIFIED is unknown, pass it as true.  */
-                        obfd);
-         if (ret != 0)
-           return ret;
-       }
-    }
+  for (objfile *objfile : current_program_space->objfiles ())
+    ALL_OBJFILE_OSECTIONS (objfile, objsec)
+      {
+       bfd *ibfd = objfile->obfd;
+       asection *isec = objsec->the_bfd_section;
+       flagword flags = bfd_get_section_flags (ibfd, isec);
+
+       /* Separate debug info files are irrelevant for gcore.  */
+       if (objfile->separate_debug_objfile_backlink != NULL)
+         continue;
+
+       if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
+         {
+           int size = bfd_section_size (ibfd, isec);
+           int ret;
+
+           ret = (*func) (obj_section_addr (objsec), size, 
+                          1, /* All sections will be readable.  */
+                          (flags & SEC_READONLY) == 0, /* Writable.  */
+                          (flags & SEC_CODE) != 0, /* Executable.  */
+                          1, /* MODIFIED is unknown, pass it as true.  */
+                          obfd);
+           if (ret != 0)
+             return ret;
+         }
+      }
 
   /* Make a stack segment.  */
   if (derive_stack_segment (&temp_bottom, &temp_top))
This page took 0.029211 seconds and 4 git commands to generate.