gdb/fortran: Introduce fortran-operator.def file
[deliverable/binutils-gdb.git] / gdb / dwarf-index-write.c
index 4335c39074fec1bc908dcedc9e76f9cf19812dba..3f96ffdafb628bd297052daea3282afe37ce5a00 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF index writing support for GDB.
 
-   Copyright (C) 1994-2018 Free Software Foundation, Inc.
+   Copyright (C) 1994-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -474,8 +474,8 @@ write_address_map (struct objfile *objfile, data_buf &addr_vec,
   addrmap_index_data.objfile = objfile;
   addrmap_index_data.previous_valid = 0;
 
-  addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
-                  &addrmap_index_data);
+  addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap,
+                  add_address_entry_worker, &addrmap_index_data);
 
   /* It's highly unlikely the last entry (end address = 0xff...ff)
      is valid, but we should still handle it.
@@ -582,13 +582,13 @@ write_one_signatured_type (void **slot, void *d)
 
   write_psymbols (info->symtab,
                  info->psyms_seen,
-                 (info->objfile->global_psymbols.data ()
+                 (info->objfile->partial_symtabs->global_psymbols.data ()
                   + psymtab->globals_offset),
                  psymtab->n_global_syms, info->cu_index,
                  0);
   write_psymbols (info->symtab,
                  info->psyms_seen,
-                 (info->objfile->static_psymbols.data ()
+                 (info->objfile->partial_symtabs->static_psymbols.data ()
                   + psymtab->statics_offset),
                  psymtab->n_static_syms, info->cu_index,
                  1);
@@ -639,12 +639,14 @@ recursively_write_psymbols (struct objfile *objfile,
 
   write_psymbols (symtab,
                  psyms_seen,
-                 objfile->global_psymbols.data () + psymtab->globals_offset,
+                 (objfile->partial_symtabs->global_psymbols.data ()
+                  + psymtab->globals_offset),
                  psymtab->n_global_syms, cu_index,
                  0);
   write_psymbols (symtab,
                  psyms_seen,
-                 objfile->static_psymbols.data () + psymtab->statics_offset,
+                 (objfile->partial_symtabs->static_psymbols.data ()
+                  + psymtab->statics_offset),
                  psymtab->n_static_syms, cu_index,
                  1);
 }
@@ -835,10 +837,12 @@ public:
                                    psyms_seen, cu_index);
 
     write_psymbols (psyms_seen,
-                   objfile->global_psymbols.data () + psymtab->globals_offset,
+                   (objfile->partial_symtabs->global_psymbols.data ()
+                    + psymtab->globals_offset),
                    psymtab->n_global_syms, cu_index, false, unit_kind::cu);
     write_psymbols (psyms_seen,
-                   objfile->static_psymbols.data () + psymtab->statics_offset,
+                   (objfile->partial_symtabs->static_psymbols.data ()
+                    + psymtab->statics_offset),
                    psymtab->n_static_syms, cu_index, true, unit_kind::cu);
   }
 
@@ -1195,12 +1199,12 @@ private:
     struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
 
     write_psymbols (info->psyms_seen,
-                   (info->objfile->global_psymbols.data ()
+                   (info->objfile->partial_symtabs->global_psymbols.data ()
                     + psymtab->globals_offset),
                    psymtab->n_global_syms, info->cu_index, false,
                    unit_kind::tu);
     write_psymbols (info->psyms_seen,
-                   (info->objfile->static_psymbols.data ()
+                   (info->objfile->partial_symtabs->static_psymbols.data ()
                     + psymtab->statics_offset),
                    psymtab->n_static_syms, info->cu_index, true,
                    unit_kind::tu);
@@ -1554,7 +1558,8 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
-  if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
+  if (!objfile->partial_symtabs->psymtabs
+      || !objfile->partial_symtabs->psymtabs_addrmap)
     return;
 
   struct stat st;
@@ -1566,23 +1571,21 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
                           ? INDEX5_SUFFIX : INDEX4_SUFFIX));
   gdb::char_vector filename_temp = make_temp_filename (filename);
 
-  gdb::optional<scoped_fd> out_file_fd
-    (gdb::in_place, mkstemp (filename_temp.data ()));
-  if (out_file_fd->get () == -1)
+  /* Order matters here; we want FILE to be closed before
+     FILENAME_TEMP is unlinked, because on MS-Windows one cannot
+     delete a file that is still open.  So, we wrap the unlinker in an
+     optional and emplace it once we know the file name.  */
+  gdb::optional<gdb::unlinker> unlink_file;
+  scoped_fd out_file_fd (gdb_mkostemp_cloexec (filename_temp.data (),
+                                              O_BINARY));
+  if (out_file_fd.get () == -1)
     perror_with_name (("mkstemp"));
 
-  FILE *out_file = gdb_fopen_cloexec (filename_temp.data (), "wb").release ();
+  gdb_file_up out_file = out_file_fd.to_file ("wb");
   if (out_file == nullptr)
     error (_("Can't open `%s' for writing"), filename_temp.data ());
 
-  /* Order matters here; we want FILE to be closed before FILENAME_TEMP is
-     unlinked, because on MS-Windows one cannot delete a file that is
-     still open.  (Don't call anything here that might throw until
-     file_closer is created.)  We don't need OUT_FILE_FD anymore, so we might
-     as well close it now.  */
-  out_file_fd.reset ();
-  gdb::unlinker unlink_file (filename_temp.data ());
-  gdb_file_up close_out_file (out_file);
+  unlink_file.emplace (filename_temp.data ());
 
   if (index_kind == dw_index_kind::DEBUG_NAMES)
     {
@@ -1590,44 +1593,45 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
                                + basename + DEBUG_STR_SUFFIX);
       gdb::char_vector filename_str_temp = make_temp_filename (filename_str);
 
-      gdb::optional<scoped_fd> out_file_str_fd
-       (gdb::in_place, mkstemp (filename_str_temp.data ()));
-      if (out_file_str_fd->get () == -1)
+      /* As above, arrange to unlink the file only after the file
+        descriptor has been closed.  */
+      gdb::optional<gdb::unlinker> unlink_file_str;
+      scoped_fd out_file_str_fd
+       (gdb_mkostemp_cloexec (filename_str_temp.data (), O_BINARY));
+      if (out_file_str_fd.get () == -1)
         perror_with_name (("mkstemp"));
 
-      FILE *out_file_str
-       = gdb_fopen_cloexec (filename_str_temp.data (), "wb").release ();
+      gdb_file_up out_file_str = out_file_str_fd.to_file ("wb");
       if (out_file_str == nullptr)
        error (_("Can't open `%s' for writing"), filename_str_temp.data ());
 
-      out_file_str_fd.reset ();
-      gdb::unlinker unlink_file_str (filename_str_temp.data ());
-      gdb_file_up close_out_file_str (out_file_str);
+      unlink_file_str.emplace (filename_str_temp.data ());
 
       const size_t total_len
-       = write_debug_names (dwarf2_per_objfile, out_file, out_file_str);
-      assert_file_size (out_file, filename_temp.data (), total_len);
+       = write_debug_names (dwarf2_per_objfile, out_file.get (),
+                            out_file_str.get ());
+      assert_file_size (out_file.get (), filename_temp.data (), total_len);
 
       /* We want to keep the file .debug_str file too.  */
-      unlink_file_str.keep ();
+      unlink_file_str->keep ();
 
       /* Close and move the str file in place.  */
-      close_out_file_str.reset ();
+      out_file_str.reset ();
       if (rename (filename_str_temp.data (), filename_str.c_str ()) != 0)
        perror_with_name (("rename"));
     }
   else
     {
       const size_t total_len
-       = write_gdbindex (dwarf2_per_objfile, out_file);
-      assert_file_size (out_file, filename_temp.data (), total_len);
+       = write_gdbindex (dwarf2_per_objfile, out_file.get ());
+      assert_file_size (out_file.get (), filename_temp.data (), total_len);
     }
 
   /* We want to keep the file.  */
-  unlink_file.keep ();
+  unlink_file->keep ();
 
   /* Close and move the file in place.  */
-  close_out_file.reset ();
+  out_file.reset ();
   if (rename (filename_temp.data (), filename.c_str ()) != 0)
        perror_with_name (("rename"));
 }
@@ -1641,7 +1645,6 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static void
 save_gdb_index_command (const char *arg, int from_tty)
 {
-  struct objfile *objfile;
   const char dwarf5space[] = "-dwarf-5 ";
   dw_index_kind index_kind = dw_index_kind::GDB_INDEX;
 
@@ -1659,35 +1662,34 @@ save_gdb_index_command (const char *arg, int from_tty)
   if (!*arg)
     error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
 
-  ALL_OBJFILES (objfile)
-  {
-    struct stat st;
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      struct stat st;
 
-    /* If the objfile does not correspond to an actual file, skip it.  */
-    if (stat (objfile_name (objfile), &st) < 0)
-      continue;
+      /* If the objfile does not correspond to an actual file, skip it.  */
+      if (stat (objfile_name (objfile), &st) < 0)
+       continue;
 
-    struct dwarf2_per_objfile *dwarf2_per_objfile
-      = get_dwarf2_per_objfile (objfile);
+      struct dwarf2_per_objfile *dwarf2_per_objfile
+       = get_dwarf2_per_objfile (objfile);
 
-    if (dwarf2_per_objfile != NULL)
-      {
-       TRY
-         {
-           const char *basename = lbasename (objfile_name (objfile));
-           write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
-                                    index_kind);
-         }
-       CATCH (except, RETURN_MASK_ERROR)
-         {
-           exception_fprintf (gdb_stderr, except,
-                              _("Error while writing index for `%s': "),
-                              objfile_name (objfile));
-         }
-       END_CATCH
-      }
+      if (dwarf2_per_objfile != NULL)
+       {
+         try
+           {
+             const char *basename = lbasename (objfile_name (objfile));
+             write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
+                                      index_kind);
+           }
+         catch (const gdb_exception_error &except)
+           {
+             exception_fprintf (gdb_stderr, except,
+                                _("Error while writing index for `%s': "),
+                                objfile_name (objfile));
+           }
+           }
 
-  }
+    }
 }
 
 void
This page took 0.027114 seconds and 4 git commands to generate.