Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 04/28] Ada import functions not in index
Date: Wed, 02 Apr 2025 17:45:03 -0600	[thread overview]
Message-ID: <20250402-search-in-psyms-v2-4-ea91704487cb@tromey.com> (raw)
In-Reply-To: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com>

The cooked index does not currently contain entries for Ada import
functions.  This means that whether or not these are visible to
"break" depends on which CUs were previously expanded -- clearly a
bug.

This patch fixes the issue.  I think the comments in the patch explain
the fix reasonably well.

Perhaps one to-do item here is to change GNAT to use
DW_TAG_imported_declaration for these imports.  This may eventually
let us remove some of the current hacks.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32511
---
 gdb/dwarf2/abbrev.c              |  7 ++++++-
 gdb/dwarf2/abbrev.h              |  8 ++++++++
 gdb/dwarf2/cooked-indexer.c      |  6 ++++--
 gdb/dwarf2/read.c                |  9 +++------
 gdb/dwarf2/read.h                |  6 ++++++
 gdb/testsuite/gdb.ada/import.exp | 28 ++++++++++++++--------------
 6 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index 9f7ead88f1fa717985004709e73aa8e916acb1e1..5b7e99abd24ead974595993f72c7452ad0d2ce4c 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -242,7 +242,12 @@ abbrev_table::read (struct dwarf2_section_info *section,
 	}
       else if (has_hardcoded_declaration
 	       && (cur_abbrev->tag != DW_TAG_variable || !has_external))
-	cur_abbrev->interesting = false;
+	{
+	  cur_abbrev->interesting = false;
+	  if (cur_abbrev->tag == DW_TAG_subprogram && has_name
+	      && has_linkage_name)
+	    cur_abbrev->maybe_ada_import = true;
+	}
       else if (!tag_interesting_for_index (cur_abbrev->tag))
 	cur_abbrev->interesting = false;
       else
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
index 29914f9c86dfa46bbab90f5e87a7c248760d942d..41e60adb3aaafb9e70b525cc9fb671f7846a7168 100644
--- a/gdb/dwarf2/abbrev.h
+++ b/gdb/dwarf2/abbrev.h
@@ -51,6 +51,14 @@ struct abbrev_info
   /* True if the DIE has children.  */
   bool has_children;
   bool interesting;
+  /* In Ada, an imported subprogram DIE will be marked as a
+     declaration, but will have both a name and a linkage name.  This
+     declaration may be the only spot where that name is associated
+     with an object, so it has to show up in the index.  But, because
+     abbrevs are CU-independent, we can't check the language when
+     computing them and instead we keep a separate flag to indicate
+     that the scanner should check this DIE.  */
+  bool maybe_ada_import;
   unsigned short size_if_constant;
   unsigned short sibling_offset;
   /* Number of attributes.  */
diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c
index 1f3a2357958f04e75ba4674c17464ddc14b64dab..7b9ffa79fe8fd6575a7d8c57424895073e790fba 100644
--- a/gdb/dwarf2/cooked-indexer.c
+++ b/gdb/dwarf2/cooked-indexer.c
@@ -20,6 +20,7 @@
 #include "dwarf2/cooked-indexer.h"
 #include "dwarf2/cooked-index-worker.h"
 #include "dwarf2/error.h"
+#include "dwarf2/read.h"
 
 /* See cooked-indexer.h.  */
 
@@ -301,7 +302,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu *scanning_per_cu,
 	   || abbrev->tag == DW_TAG_namespace)
 	  && abbrev->has_children)
 	*flags |= IS_TYPE_DECLARATION;
-      else
+      else if (!is_ada_import_or_export (reader->cu (), *name, *linkage_name))
 	{
 	  *linkage_name = nullptr;
 	  *name = nullptr;
@@ -514,7 +515,8 @@ cooked_indexer::index_dies (cutu_reader *reader,
       /* If a DIE parent is a DW_TAG_subprogram, then the DIE is only
 	 interesting if it's a DW_TAG_subprogram or a DW_TAG_entry_point.  */
       bool die_interesting
-	= (abbrev->interesting
+	= ((abbrev->interesting
+	    || (m_language == language_ada && abbrev->maybe_ada_import))
 	   && (parent_entry == nullptr
 	       || parent_entry->tag != DW_TAG_subprogram
 	       || abbrev->tag == DW_TAG_subprogram
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 17f06ff134220d7753e7d9ac25e424965e9e55ed..ae8369266be1b1d7e5cc99cb1f44966a2392ec2b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -973,9 +973,6 @@ static void queue_comp_unit (dwarf2_per_cu *per_cu,
 
 static void process_queue (dwarf2_per_objfile *per_objfile);
 
-static bool is_ada_import_or_export (dwarf2_cu *cu, const char *name,
-				     const char *linkagename);
-
 /* Class, the destructor of which frees all allocated queue entries.  This
    will only have work to do if an error was thrown while processing the
    dwarf.  If no error was thrown then the queue entries should have all
@@ -16627,14 +16624,14 @@ add_ada_export_symbol (struct symbol *orig, const char *new_name,
   add_symbol_to_list (copy, list_to_add);
 }
 
-/* A helper function that decides if a given symbol is an Ada Pragma
-   Import or Pragma Export.  */
+/* See read.h.  */
 
-static bool
+bool
 is_ada_import_or_export (dwarf2_cu *cu, const char *name,
 			 const char *linkagename)
 {
   return (cu->lang () == language_ada
+	  && name != nullptr
 	  && linkagename != nullptr
 	  && !streq (name, linkagename)
 	  /* The following exclusions are necessary because symbols
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 7f56dac32f186a321978190c388885999a7ea3fd..c39945d7da4e5a4bd33292849437bcbe396fbb0a 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -1299,4 +1299,10 @@ extern int dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
 extern file_and_directory &find_file_and_directory (die_info *die,
 						    dwarf2_cu *cu);
 
+/* A helper function that decides if a given symbol is an Ada Pragma
+   Import or Pragma Export.  */
+
+extern bool is_ada_import_or_export (dwarf2_cu *cu, const char *name,
+				     const char *linkagename);
+
 #endif /* GDB_DWARF2_READ_H */
diff --git a/gdb/testsuite/gdb.ada/import.exp b/gdb/testsuite/gdb.ada/import.exp
index 04bb7e1a0d9f18e732855114b008a03348235086..6f1026f545fcfd5bc19d1f6e72321d05ffe12960 100644
--- a/gdb/testsuite/gdb.ada/import.exp
+++ b/gdb/testsuite/gdb.ada/import.exp
@@ -54,6 +54,9 @@ gdb_test "print pkg.imported_var_ada" " = 42"
 gdb_test "print pkg.exported_var_ada" " = 99"
 gdb_test "print exported_var_ada" " = 99"
 
+gdb_breakpoint "local_imported_func" message
+gdb_test "print copy" " = 42"
+
 # This passes with gcc 10 but fails with gcc 9.  With gcc 9, we have:
 #   <1><1659>: Abbrev Number: 4 (DW_TAG_subprogram)
 #      <165a>   DW_AT_external    : 1
@@ -76,19 +79,16 @@ gdb_test "print exported_var_ada" " = 99"
 # The fact that things start to work when adding the DW_AT_declaration is
 # consistent with what is described in commit ff9baa5f1c5, so xfail this
 # (without pinpointing it to a specific gcc PR or commit).
-if { [gcc_major_version] < 10 } {
-    setup_xfail *-*-*
-}
-gdb_breakpoint "pkg.imported_func_ada" message
-gdb_breakpoint "imported_func" message
-if { [gcc_major_version] < 10 } {
-    setup_xfail *-*-*
+foreach func {"pkg.imported_func_ada" "imported_func"} {
+    clean_restart $testfile
+    if { [gcc_major_version] < 10 } {
+	setup_xfail *-*-*
+    }
+    gdb_breakpoint $func message
 }
-gdb_breakpoint "imported_func_ada" message
 
-gdb_breakpoint "local_imported_func" message
-gdb_breakpoint "pkg.exported_func_ada" message
-gdb_breakpoint "exported_func_ada" message
-gdb_breakpoint "exported_func" message
-
-gdb_test "print copy" " = 42"
+foreach func {"imported_func_ada" "pkg.exported_func_ada" \
+		  "exported_func_ada" "exported_func"} {
+    clean_restart $testfile
+    gdb_breakpoint $func message
+}

-- 
2.46.1


  parent reply	other threads:[~2025-04-02 23:47 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02 23:44 [PATCH v2 00/28] Search symbols via quick API Tom Tromey
2025-04-02 23:45 ` [PATCH v2 01/28] Add another minor hack to cooked_index_entry::full_name Tom Tromey
2025-04-02 23:45 ` [PATCH v2 02/28] Change ada_decode to preserve upper-case in some situations Tom Tromey
2025-04-02 23:45 ` [PATCH v2 03/28] Emit some type declarations in .gdb_index Tom Tromey
2025-04-21  2:50   ` Simon Marchi
2025-04-21 14:50     ` Tom Tromey
2025-04-23  4:11       ` Simon Marchi
2025-04-23 20:54         ` Tom Tromey
2025-04-02 23:45 ` Tom Tromey [this message]
2025-04-02 23:45 ` [PATCH v2 05/28] Fix index's handling of DW_TAG_imported_declaration Tom Tromey
2025-04-02 23:45 ` [PATCH v2 06/28] Put all CTF symbols in global scope Tom Tromey
2025-04-02 23:45 ` [PATCH v2 07/28] Restore "ingestion" of .debug_str when writing .debug_names Tom Tromey
2025-04-02 23:45 ` [PATCH v2 08/28] Entries from anon-struct.exp not in cooked index Tom Tromey
2025-04-02 23:45 ` [PATCH v2 09/28] Remove dwarf2_per_cu_data::mark Tom Tromey
2025-04-21  3:09   ` Simon Marchi
2025-04-21 15:38     ` Tom Tromey
2025-04-23  4:12       ` Simon Marchi
2025-04-02 23:45 ` [PATCH v2 10/28] Have expand_symtabs_matching work for already-expanded CUs Tom Tromey
2025-04-23 15:53   ` Simon Marchi
2025-04-23 20:39     ` Tom Tromey
2025-04-23 20:57       ` Tom Tromey
2025-04-02 23:45 ` [PATCH v2 11/28] Rewrite the .gdb_index reader Tom Tromey
2025-04-23 17:22   ` Simon Marchi
2025-04-23 20:50     ` Tom Tromey
2025-04-24 14:37   ` Pedro Alves
2025-04-02 23:45 ` [PATCH v2 12/28] Convert default_collect_symbol_completion_matches_break_on Tom Tromey
2025-04-02 23:45 ` [PATCH v2 13/28] Convert gdbpy_lookup_static_symbols Tom Tromey
2025-04-02 23:45 ` [PATCH v2 14/28] Convert ada_add_global_exceptions Tom Tromey
2025-04-02 23:45 ` [PATCH v2 15/28] Convert ada_language_defn::collect_symbol_completion_matches Tom Tromey
2025-04-02 23:45 ` [PATCH v2 16/28] Convert ada-lang.c:map_matching_symbols Tom Tromey
2025-04-02 23:45 ` [PATCH v2 17/28] Remove expand_symtabs_matching Tom Tromey
2025-04-02 23:45 ` [PATCH v2 18/28] Simplify basic_lookup_transparent_type Tom Tromey
2025-04-02 23:45 ` [PATCH v2 19/28] Remove objfile::expand_symtabs_for_function Tom Tromey
2025-04-02 23:45 ` [PATCH v2 20/28] Convert linespec.c:iterate_over_all_matching_symtabs Tom Tromey
2025-04-02 23:45 ` [PATCH v2 21/28] Simplify block_lookup_symbol_primary Tom Tromey
2025-04-02 23:45 ` [PATCH v2 22/28] Pass lookup_name_info to block_lookup_symbol_primary Tom Tromey
2025-04-02 23:45 ` [PATCH v2 23/28] Simplify block_lookup_symbol Tom Tromey
2025-04-02 23:45 ` [PATCH v2 24/28] Add best_symbol_tracker Tom Tromey
2025-04-02 23:45 ` [PATCH v2 25/28] Convert lookup_symbol_via_quick_fns Tom Tromey
2025-04-02 23:45 ` [PATCH v2 26/28] Convert lookup_symbol_in_objfile Tom Tromey
2025-04-02 23:45 ` [PATCH v2 27/28] Make dw_expand_symtabs_matching_file_matcher static Tom Tromey
2025-04-23 20:00   ` Simon Marchi
2025-04-23 20:09     ` Tom Tromey
2025-04-23 20:44       ` Tom Tromey
2025-04-02 23:45 ` [PATCH v2 28/28] Remove enter_symbol_lookup Tom Tromey
2025-04-23 20:09 ` [PATCH v2 00/28] Search symbols via quick API Simon Marchi
2025-04-24 21:09   ` Tom Tromey
2025-04-28 14:07 ` Guinevere Larsen
2025-04-28 22:06   ` Tom Tromey
2025-04-29 19:31     ` Guinevere Larsen

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=20250402-search-in-psyms-v2-4-ea91704487cb@tromey.com \
    --to=tom@tromey.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