public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Handle .gdb_index in ada language mode
@ 2020-05-13  9:41 Tom de Vries
  2020-05-19 20:32 ` Tom Tromey
  0 siblings, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2020-05-13  9:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Tom Tromey

Hi,

When running test-case gdb.base/with.exp with target board cc-with-gdb-index,
we have:
...
(gdb) PASS: gdb.base/with.exp: basics: show language
with language ada -- print g_s^M
'g_s' has unknown type; cast it to its declared type^M
(gdb) FAIL: gdb.base/with.exp: basics: with language ada -- print g_s
...

This is due to this bit in dw2_map_matching_symbols:
...
  if (dwarf2_per_objfile->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.  As Ada does not look for non-Ada symbols this
	 function should just return.  */
      return;
    }
...

While the reasoning in the comment may be sound from language perspective, it
does introduce an inconsistency in gdb behaviour between:
- having a .gdb_index section, and
- having a .gdb_names section, or a partial symtab, or -readnow.

Fix the inconsistency by completing implementation of
dw2_map_matching_symbols.

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

Any comments?

Thanks,
- Tom

[gdb/symtab] Handle .gdb_index in ada language mode

gdb/ChangeLog:

2020-05-13  Tom de Vries  <tdevries@suse.de>

	PR symtab/25833
	* dwarf2/read.c (dw2_map_matching_symbols): Handle .gdb_index.

gdb/testsuite/ChangeLog:

2020-05-13  Tom de Vries  <tdevries@suse.de>

	PR symtab/25833
	* gdb.base/with-mf-inc.c: New test.
	* gdb.base/with-mf-main.c: New test.
	* gdb.base/with-mf.exp: New file.

---
 gdb/dwarf2/read.c                     | 52 +++++++++++++++++++++++++++++------
 gdb/testsuite/gdb.base/with-mf-inc.c  | 35 +++++++++++++++++++++++
 gdb/testsuite/gdb.base/with-mf-main.c | 28 +++++++++++++++++++
 gdb/testsuite/gdb.base/with-mf.exp    | 34 +++++++++++++++++++++++
 4 files changed, 141 insertions(+), 8 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 27bf40a898..5297c107a6 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3649,6 +3649,20 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
     }
 }
 
+static void
+dw2_expand_symtabs_matching_symbol
+  (mapped_index_base &index,
+   const lookup_name_info &lookup_name_in,
+   gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+   enum search_domain kind,
+   gdb::function_view<bool (offset_type)> match_callback);
+
+static void
+dw2_expand_symtabs_matching_one
+  (struct dwarf2_per_cu_data *per_cu,
+   gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+   gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify);
+
 static void
 dw2_map_matching_symbols
   (struct objfile *objfile,
@@ -3661,19 +3675,41 @@ dw2_map_matching_symbols
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = get_dwarf2_per_objfile (objfile);
 
+  const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+
   if (dwarf2_per_objfile->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.  As Ada does not look for non-Ada symbols this
-	 function should just return.  */
-      return;
-    }
+	 using GNU index.  */
+      mapped_index &index = *dwarf2_per_objfile->index_table;
+
+      const char *match_name = name.ada ().lookup_name ().c_str ();
+      auto matcher = [&] (const char *symname)
+	{
+	  if (ordered_compare == nullptr)
+	    return true;
+	  return ordered_compare (symname, match_name) == 0;
+	};
+
+      dw2_expand_symtabs_matching_symbol (index, name, matcher, ALL_DOMAIN,
+					  [&] (offset_type namei)
+      {
+	struct dw2_symtab_iterator iter;
+	struct dwarf2_per_cu_data *per_cu;
 
-  /* We have -readnow: no .gdb_index, but no partial symtabs either.  So,
-     inline psym_map_matching_symbols here, assuming all partial symtabs have
-     been read in.  */
-  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+	dw2_symtab_iter_init (&iter, dwarf2_per_objfile, block_kind, domain,
+			      match_name);
+	while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
+	  dw2_expand_symtabs_matching_one (per_cu, nullptr, nullptr);
+	return true;
+      });
+    }
+  else
+    {
+      /* We have -readnow: no .gdb_index, but no partial symtabs either.  So,
+	 proceed assuming all symtabs have been read in.  */
+    }
 
   for (compunit_symtab *cust : objfile->compunits ())
     {
diff --git a/gdb/testsuite/gdb.base/with-mf-inc.c b/gdb/testsuite/gdb.base/with-mf-inc.c
new file mode 100644
index 0000000000..491be7fba2
--- /dev/null
+++ b/gdb/testsuite/gdb.base/with-mf-inc.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Non-main part of with.c.  */
+
+int xxx1 = 123;
+
+struct S
+{
+  int a;
+  int b;
+  int c;
+};
+
+struct S g_s = {1, 2, 3};
+
+void
+inc ()
+{
+  g_s.a++;;
+}
diff --git a/gdb/testsuite/gdb.base/with-mf-main.c b/gdb/testsuite/gdb.base/with-mf-main.c
new file mode 100644
index 0000000000..b50d98f2f2
--- /dev/null
+++ b/gdb/testsuite/gdb.base/with-mf-main.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Main part of with.c.  */
+
+extern void inc (void);
+
+int
+main ()
+{
+  inc ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/with-mf.exp b/gdb/testsuite/gdb.base/with-mf.exp
new file mode 100644
index 0000000000..6b3663c570
--- /dev/null
+++ b/gdb/testsuite/gdb.base/with-mf.exp
@@ -0,0 +1,34 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test .gdb_index in ada language mode.
+
+standard_testfile with-mf-main.c with-mf-inc.c
+
+if {[prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" \
+	 debug]} {
+    return -1
+}
+
+if { [ensure_gdb_index $binfile] == -1 } {
+    return -1
+}
+
+clean_restart $binfile
+
+gdb_test "with language ada -- print g_s" \
+    " = \\(a => 1, b => 2, c => 3\\)"

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-06-10 12:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13  9:41 [PATCH][gdb/symtab] Handle .gdb_index in ada language mode Tom de Vries
2020-05-19 20:32 ` Tom Tromey
2020-05-20  9:40   ` Tom de Vries
2020-05-22 20:31     ` Tom Tromey
2020-05-26 13:01       ` [PATCH][gdb/symtab] Make gold index workaround more precise Tom de Vries
2020-05-26 14:03         ` Tom de Vries
2020-05-27 15:22           ` Tom Tromey
2020-05-28 13:02             ` Tom de Vries
2020-05-27 15:21         ` Tom Tromey
2020-06-02 10:47       ` [PATCH][gdb/symtab] Handle .gdb_index in ada language mode Tom de Vries
2020-06-10 12:49         ` Tom de Vries

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).