[gdb/symtab] Enable ada .gdb_index
authorTom de Vries <tdevries@suse.de>
Wed, 10 Jun 2020 12:46:53 +0000 (14:46 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 10 Jun 2020 12:46:53 +0000 (14:46 +0200)
Currently the .gdb_index is not enabled for ada executables (PR24713).

Fix this by adding the required support in write_psymbols, similar to how that
is done for .debug_names in debug_names::insert.

Tested on x86_64-linux, with native and target board cc-with-gdb-index.

gdb/ChangeLog:

2020-06-10  Tom de Vries  <tdevries@suse.de>

PR ada/24713
* dwarf2/index-write.c (struct mapped_symtab): Add m_string_obstack.
(write_psymbols): Enable .gdb_index for ada.
* dwarf2/read.c: Remove comment stating .gdb_index is unsupported for
ada.

gdb/testsuite/ChangeLog:

2020-06-10  Tom de Vries  <tdevries@suse.de>

* gdb.ada/ptype_union.exp: Remove PR24713 workaround.

gdb/ChangeLog
gdb/dwarf2/index-write.c
gdb/dwarf2/read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/ptype_union.exp

index 40ce7bb546cc2d4ac7d1aa9e49ad6661afe9931e..91315fafb44f92072df6744eb3773dbeba9b76a8 100644 (file)
@@ -1,3 +1,11 @@
+2020-06-10  Tom de Vries  <tdevries@suse.de>
+
+       PR ada/24713
+       * dwarf2/index-write.c (struct mapped_symtab): Add m_string_obstack.
+       (write_psymbols): Enable .gdb_index for ada.
+       * dwarf2/read.c: Remove comment stating .gdb_index is unsupported for
+       ada.
+
 2020-06-10  Tom de Vries  <tdevries@suse.de>
 
        * dwarf2/read.c (dw2_symtab_iter_init_common): Factor out of ...
index eabb67fd88dfc454361e1a0583d8709e94435663..97b2310656ca3f784f234946eb6e50c82e1bf636 100644 (file)
@@ -184,6 +184,9 @@ struct mapped_symtab
 
   offset_type n_elements = 0;
   std::vector<symtab_index_entry> data;
+
+  /* Temporary storage for Ada names.  */
+  auto_obstack m_string_obstack;
 };
 
 /* Find a slot in SYMTAB for the symbol NAME.  Returns a reference to
@@ -543,18 +546,47 @@ write_psymbols (struct mapped_symtab *symtab,
   for (; count-- > 0; ++psymp)
     {
       struct partial_symbol *psym = *psymp;
+      const char *name = psym->ginfo.search_name ();
 
       if (psym->ginfo.language () == language_ada)
-       error (_("Ada is not currently supported by the index; "
-                "use the DWARF 5 index instead"));
+       {
+         /* 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)
+           {
+             gdb_index_symbol_kind kind = symbol_kind (psym);
+
+             add_index_entry (symtab, name, is_static, kind, cu_index);
+           }
+
+         /* 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 (&symtab->m_string_obstack,
+                                          decoded.c_str () + 1,
+                                          decoded.length () - 2);
+         else
+           name = obstack_strdup (&symtab->m_string_obstack,
+                                  ada_encode (decoded.c_str ()));
+       }
 
       /* Only add a given psymbol once.  */
       if (psyms_seen.insert (psym).second)
        {
          gdb_index_symbol_kind kind = symbol_kind (psym);
 
-         add_index_entry (symtab, psym->ginfo.search_name (),
-                          is_static, kind, cu_index);
+         add_index_entry (symtab, name, is_static, kind, cu_index);
        }
     }
 }
index c33f0a1e682408cf52977cbca5cc277a1dff1fd6..e3073fe43ce35c58e1de56173ea3b0f1b3b87cee 100644 (file)
@@ -3778,9 +3778,6 @@ dw2_map_matching_symbols
 
   if (per_objfile->per_bfd->index_table != nullptr)
     {
-      /* Ada currently doesn't support .gdb_index (see PR24713).  We can get
-        here though if the current language is Ada for a non-Ada objfile
-        using GNU index.  */
       mapped_index &index = *per_objfile->per_bfd->index_table;
 
       const char *match_name = name.ada ().lookup_name ().c_str ();
index dd003656d14d2db9fb017c8d54fb96d8e925e55e..e8306bd87fc9717ba90544d7411c154b49afb34c 100644 (file)
@@ -1,3 +1,7 @@
+2020-06-10  Tom de Vries  <tdevries@suse.de>
+
+       * gdb.ada/ptype_union.exp: Remove PR24713 workaround.
+
 2020-06-09  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdb.base/index-cache.exp (test_cache_disabled): Add test_prefix
index 470f9b550c662521a3de2099df55ab9bdc681b6b..c85e5f4b4b6e6682e13fac71cc43794994808d17 100644 (file)
@@ -19,11 +19,6 @@ if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} {
     return -1
 }
 
-if {[exec_has_index_section $binfile]} {
-    unsupported "Ada is not currently supported by the index (PR 24713)"
-    return -1
-}
-
 # The test case is written in C, because it was easy to make the
 # required type there; but the bug itself only happens in Ada.
 gdb_test "set lang ada" ""
This page took 0.03604 seconds and 4 git commands to generate.