Enable styling by default on Cygwin
[deliverable/binutils-gdb.git] / gdb / dwarf-index-write.c
index 9979ae44402fd7a6e3766f3c5bc59443cd48f35a..f2abe70e155414542599f835b0859a03461cbf8c 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF index writing support for GDB.
 
 /* DWARF index writing support for GDB.
 
-   Copyright (C) 1994-2019 Free Software Foundation, Inc.
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
    This file is part of GDB.
 
 
 #include "defs.h"
 
 
 #include "defs.h"
 
+#include "dwarf-index-write.h"
+
 #include "addrmap.h"
 #include "cli/cli-decode.h"
 #include "addrmap.h"
 #include "cli/cli-decode.h"
-#include "common/byte-vector.h"
-#include "common/filestuff.h"
-#include "common/gdb_unlinker.h"
-#include "common/pathstuff.h"
-#include "common/scoped_fd.h"
+#include "gdbsupport/byte-vector.h"
+#include "gdbsupport/filestuff.h"
+#include "gdbsupport/gdb_unlinker.h"
+#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/scoped_fd.h"
 #include "complaints.h"
 #include "dwarf-index-common.h"
 #include "dwarf2.h"
 #include "complaints.h"
 #include "dwarf-index-common.h"
 #include "dwarf2.h"
@@ -34,6 +36,7 @@
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "psympriv.h"
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "psympriv.h"
+#include "ada-lang.h"
 
 #include <algorithm>
 #include <cmath>
 
 #include <algorithm>
 #include <cmath>
@@ -56,7 +59,7 @@
     GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
   } while (0)
 
     GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
   } while (0)
 
-/* Ensure we don't use more than the alloted nuber of bits for the CU.  */
+/* Ensure we don't use more than the allotted number of bits for the CU.  */
 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
   do { \
     gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
   do { \
     gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
@@ -256,7 +259,7 @@ add_index_entry (struct mapped_symtab *symtab, const char *name,
      (which would allow us to avoid the duplication by only having to check
      the last entry pushed), but a symbol could have multiple kinds in one CU.
      To keep things simple we don't worry about the duplication here and
      (which would allow us to avoid the duplication by only having to check
      the last entry pushed), but a symbol could have multiple kinds in one CU.
      To keep things simple we don't worry about the duplication here and
-     sort and uniqufy the list after we've processed all symbols.  */
+     sort and uniquify the list after we've processed all symbols.  */
   slot.cu_indices.push_back (cu_index_and_attrs);
 }
 
   slot.cu_indices.push_back (cu_index_and_attrs);
 }
 
@@ -540,15 +543,16 @@ write_psymbols (struct mapped_symtab *symtab,
     {
       struct partial_symbol *psym = *psymp;
 
     {
       struct partial_symbol *psym = *psymp;
 
-      if (psym->ginfo.language == language_ada)
-       error (_("Ada is not currently supported by the index"));
+      if (psym->ginfo.language () == language_ada)
+       error (_("Ada is not currently supported by the index; "
+                "use the DWARF 5 index instead"));
 
       /* Only add a given psymbol once.  */
       if (psyms_seen.insert (psym).second)
        {
          gdb_index_symbol_kind kind = symbol_kind (psym);
 
 
       /* Only add a given psymbol once.  */
       if (psyms_seen.insert (psym).second)
        {
          gdb_index_symbol_kind kind = symbol_kind (psym);
 
-         add_index_entry (symtab, symbol_search_name (&psym->ginfo),
+         add_index_entry (symtab, psym->ginfo.search_name (),
                           is_static, kind, cu_index);
        }
     }
                           is_static, kind, cu_index);
        }
     }
@@ -684,7 +688,44 @@ public:
     const int dwarf_tag = psymbol_tag (psym);
     if (dwarf_tag == 0)
       return;
     const int dwarf_tag = psymbol_tag (psym);
     if (dwarf_tag == 0)
       return;
-    const char *const name = symbol_search_name (&psym->ginfo);
+    const char *name = psym->ginfo.search_name ();
+
+    if (psym->ginfo.language () == language_ada)
+      {
+       /* We want to ensure that the Ada main function's name appears
+          verbatim in the index.  However, this name will be of the
+          form "_ada_mumble", and will be rewritten by ada_decode.
+          So, recognize it specially here and add it to the index by
+          hand.  */
+       if (strcmp (main_name (), name) == 0)
+         {
+           const auto insertpair
+             = m_name_to_value_set.emplace (c_str_view (name),
+                                            std::set<symbol_value> ());
+           std::set<symbol_value> &value_set = insertpair.first->second;
+           value_set.emplace (symbol_value (dwarf_tag, cu_index, is_static,
+                                            kind));
+         }
+
+       /* In order for the index to work when read back into gdb, it
+          has to supply a funny form of the name: it should be the
+          encoded name, with any suffixes stripped.  Using the
+          ordinary encoded name will not work properly with the
+          searching logic in find_name_components_bounds; nor will
+          using the decoded name.  Furthermore, an Ada "verbatim"
+          name (of the form "<MumBle>") must be entered without the
+          angle brackets.  Note that the current index is unusual,
+          see PR symtab/24820 for details.  */
+       std::string decoded = ada_decode (name);
+       if (decoded[0] == '<')
+         name = (char *) obstack_copy0 (&m_string_obstack,
+                                        decoded.c_str () + 1,
+                                        decoded.length () - 2);
+       else
+         name = obstack_strdup (&m_string_obstack,
+                                ada_encode (decoded.c_str ()));
+      }
+
     const auto insertpair
       = m_name_to_value_set.emplace (c_str_view (name),
                                     std::set<symbol_value> ());
     const auto insertpair
       = m_name_to_value_set.emplace (c_str_view (name),
                                     std::set<symbol_value> ());
@@ -912,7 +953,7 @@ private:
   {
   public:
 
   {
   public:
 
-    /* Object costructor to be called for current DWARF2_PER_OBJFILE.
+    /* Object constructor to be called for current DWARF2_PER_OBJFILE.
        All .debug_str section strings are automatically stored.  */
     debug_str_lookup (struct dwarf2_per_objfile *dwarf2_per_objfile)
       : m_abfd (dwarf2_per_objfile->objfile->obfd),
        All .debug_str section strings are automatically stored.  */
     debug_str_lookup (struct dwarf2_per_objfile *dwarf2_per_objfile)
       : m_abfd (dwarf2_per_objfile->objfile->obfd),
@@ -1181,9 +1222,6 @@ private:
       {
        struct partial_symbol *psym = *psymp;
 
       {
        struct partial_symbol *psym = *psymp;
 
-       if (psym->ginfo.language == language_ada)
-         error (_("Ada is not currently supported by the index"));
-
        /* Only add a given psymbol once.  */
        if (psyms_seen.insert (psym).second)
          insert (psym, cu_index, is_static, kind);
        /* Only add a given psymbol once.  */
        if (psyms_seen.insert (psym).second)
          insert (psym, cu_index, is_static, kind);
@@ -1244,6 +1282,9 @@ private:
 
   /* .debug_names entry pool.  */
   data_buf m_entry_pool;
 
   /* .debug_names entry pool.  */
   data_buf m_entry_pool;
+
+  /* Temporary storage for Ada names.  */
+  auto_obstack m_string_obstack;
 };
 
 /* Return iff any of the needed offsets does not fit into 32-bit
 };
 
 /* Return iff any of the needed offsets does not fit into 32-bit
@@ -1638,7 +1679,7 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwarf2_per_objfile->using_index)
     error (_("Cannot use an index to create the index"));
 
   if (dwarf2_per_objfile->using_index)
     error (_("Cannot use an index to create the index"));
 
-  if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
+  if (dwarf2_per_objfile->types.size () > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
   if (!objfile->partial_symtabs->psymtabs
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
   if (!objfile->partial_symtabs->psymtabs
This page took 0.029363 seconds and 4 git commands to generate.