public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v2 3/4] Improve Ada support in .gdb_index
Date: Fri, 14 Oct 2022 10:08:48 -0600	[thread overview]
Message-ID: <20221014160849.919621-4-tromey@adacore.com> (raw)
In-Reply-To: <20221014160849.919621-1-tromey@adacore.com>

The cooked index work changed how .gdb_index is constructed, and in
the process broke .gdb_index support.  This is PR symtab/29179.

This patch partially fixes the problem.  It arranges for Ada names to
be encoded in the form expected by the index code.  In particular,
linkage names for Ada are emitted, including the "main" name; names
are Ada-encoded; and names are no longer case-folded, something that
prevented operator names from round-tripping correctly.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29179
---
 gdb/ada-lang.c           |  8 +++++---
 gdb/ada-lang.h           |  2 +-
 gdb/dwarf2/index-write.c | 44 ++++++++++++++++++++++++++++++++--------
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0e3f0daa416..ff9beb47cfd 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1146,12 +1146,14 @@ ada_fold_name (gdb::string_view name, bool throw_on_error = false)
   return fold_storage.c_str ();
 }
 
-/* The "encoded" form of DECODED, according to GNAT conventions.  */
+/* The "encoded" form of DECODED, according to GNAT conventions.  If
+   FOLD is true (the default), case-fold any ordinary symbol.  Symbols
+   with <...> quoting are not folded in any case.  */
 
 std::string
-ada_encode (const char *decoded)
+ada_encode (const char *decoded, bool fold)
 {
-  if (decoded[0] != '<')
+  if (fold && decoded[0] != '<')
     decoded = ada_fold_name (decoded);
   return ada_encode_1 (decoded, true);
 }
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index df648c2297e..84c691b94ee 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -316,7 +316,7 @@ extern struct type *ada_get_base_type (struct type *);
 
 extern struct type *ada_check_typedef (struct type *);
 
-extern std::string ada_encode (const char *);
+extern std::string ada_encode (const char *, bool fold = true);
 
 extern const char *ada_enum_name (const char *);
 
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 4f89dfb65f7..6b4052c3467 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1109,22 +1109,48 @@ write_cooked_index (cooked_index_vector *table,
   htab_up var_names (htab_create_alloc (10, htab_hash_string, htab_eq_string,
 					nullptr, xcalloc, xfree));
 
+  const char *main_for_ada = main_name ();
+
   for (const cooked_index_entry *entry : table->all_entries ())
     {
-      /* GDB never put C++ linkage names into .gdb_index.  The theory
-	 here is that a linkage name will normally be in the minimal
-	 symbols anyway, so including it in the index is usually
-	 redundant -- and the cases where it would not be redundant
-	 are rare and not worth supporting.  */
-      if (entry->per_cu->lang () == language_cplus
-	  && (entry->flags & IS_LINKAGE) != 0)
-	continue;
-
       const auto it = cu_index_htab.find (entry->per_cu);
       gdb_assert (it != cu_index_htab.cend ());
 
       const char *name = entry->full_name (&symtab->m_string_obstack);
 
+      if (entry->per_cu->lang () == 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 (entry->tag == DW_TAG_subprogram
+	      && strcmp (main_for_ada, name) == 0)
+	    {
+	      /* Leave it alone.  */
+	    }
+	  else
+	    {
+	      /* In order for the index to work when read back into
+		 gdb, it has to use the encoded name, with any
+		 suffixes stripped.  */
+	      std::string encoded = ada_encode (name, false);
+	      name = obstack_strdup (&symtab->m_string_obstack,
+				     encoded.c_str ());
+	    }
+	}
+      else if (entry->per_cu->lang () == language_cplus
+	       && (entry->flags & IS_LINKAGE) != 0)
+	{
+	  /* GDB never put C++ linkage names into .gdb_index.  The
+	     theory here is that a linkage name will normally be in
+	     the minimal symbols anyway, so including it in the index
+	     is usually redundant -- and the cases where it would not
+	     be redundant are rare and not worth supporting.  */
+	  continue;
+	}
+
       gdb_index_symbol_kind kind;
       if (entry->tag == DW_TAG_subprogram)
 	kind = GDB_INDEX_SYMBOL_KIND_FUNCTION;
-- 
2.34.3


  parent reply	other threads:[~2022-10-14 16:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 16:08 [PATCH v2 0/4] Fix .gdb_index with Ada Tom Tromey
2022-10-14 16:08 ` [PATCH v2 1/4] Fix regression in c-linkage-name.exp with gdb index Tom Tromey
2022-10-14 16:08 ` [PATCH v2 2/4] Don't add type linkage names to cooked index Tom Tromey
2022-10-14 16:08 ` Tom Tromey [this message]
2022-10-14 16:08 ` [PATCH v2 4/4] Change .gdb_index de-duplication implementation Tom Tromey
2022-10-17  4:01 ` [PATCH v2 0/4] Fix .gdb_index with Ada Tom de Vries
2022-10-17 16:03   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221014160849.919621-4-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).