public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU
@ 2024-05-08 20:22 Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 2/4] gdb/symtab: reuse last segment lookup name info by creating it outside the loop Dmitry Neverov
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Dmitry Neverov @ 2024-05-08 20:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: dmitry.neverov

From: "Dmitry.Neverov" <dmitry.neverov@jetbrains.com>

The added check fixes the case when an unqualified lookup
name without template arguments causes expansion of many CUs
which contain the name with template arguments.

This is similar to what dw2_expand_symtabs_matching_symbol does
before expanding the CU.

In the referenced issue the lookup name was wxObjectDataPtr and many
CUs had names like wxObjectDataPtr<wxBitmapBundleImpl>. This caused
their expansion and the lookup took around a minute. The added check
helps to avoid the expansion and makes the symbol lookup to return in
a second or so.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30520
---
 gdb/dwarf2/read.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 049ee4d52ff..16b9fd34522 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16694,9 +16694,25 @@ cooked_index_functions::expand_symtabs_matching
 		= lookup_name_without_params.match_type ();
 	      if ((match_type == symbol_name_match_type::FULL
 		   || (lang != language_ada
-		       && match_type == symbol_name_match_type::EXPRESSION))
-		  && parent != nullptr)
-		continue;
+		       && match_type == symbol_name_match_type::EXPRESSION)))
+		{
+		  if (parent != nullptr)
+		    continue;
+
+		  if (entry->lang != language_unknown)
+		    {
+		      const language_defn *lang_def = language_def (entry->lang);
+		      lookup_name_info last_segment_lookup_name
+			(last_name.data (), symbol_name_match_type::FULL, false,
+			 true);
+		      symbol_name_matcher_ftype *name_matcher
+			= (lang_def->get_symbol_name_matcher
+			     (last_segment_lookup_name));
+		      if (!name_matcher (entry->canonical,
+					 last_segment_lookup_name, nullptr))
+			continue;
+		    }
+	      }
 	    }
 	  else
 	    {
-- 
2.40.1


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

* [PATCH v3][PR symtab/30520 v2 2/4] gdb/symtab: reuse last segment lookup name info by creating it outside the loop
  2024-05-08 20:22 [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Dmitry Neverov
@ 2024-05-08 20:22 ` Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 3/4] gdb/symtab: compute match_type " Dmitry Neverov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Neverov @ 2024-05-08 20:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: dmitry.neverov

---
 gdb/dwarf2/read.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 16b9fd34522..8da0af01d72 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16643,6 +16643,9 @@ cooked_index_functions::expand_symtabs_matching
 	= lookup_name_without_params.split_name (lang);
       std::string last_name (name_vec.back ());
 
+      lookup_name_info last_segment_lookup_name
+	(last_name, symbol_name_match_type::FULL, completing, true);
+
       for (const cooked_index_entry *entry : table->find (last_name,
 							  completing))
 	{
@@ -16702,9 +16705,6 @@ cooked_index_functions::expand_symtabs_matching
 		  if (entry->lang != language_unknown)
 		    {
 		      const language_defn *lang_def = language_def (entry->lang);
-		      lookup_name_info last_segment_lookup_name
-			(last_name.data (), symbol_name_match_type::FULL, false,
-			 true);
 		      symbol_name_matcher_ftype *name_matcher
 			= (lang_def->get_symbol_name_matcher
 			     (last_segment_lookup_name));
-- 
2.40.1


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

* [PATCH v3][PR symtab/30520 v2 3/4] gdb/symtab: compute match_type outside the loop
  2024-05-08 20:22 [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 2/4] gdb/symtab: reuse last segment lookup name info by creating it outside the loop Dmitry Neverov
@ 2024-05-08 20:22 ` Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 4/4] gdb/symtab: use symbol name matcher for all segments in a qualified name Dmitry Neverov
  2024-05-10 18:39 ` [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Tom Tromey
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Neverov @ 2024-05-08 20:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: dmitry.neverov

It will be used for all segments in a qualified name,
not only the last one.
---
 gdb/dwarf2/read.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8da0af01d72..48d5dc11d1d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16637,6 +16637,9 @@ cooked_index_functions::expand_symtabs_matching
     language_ada
   };
 
+  symbol_name_match_type match_type
+    = lookup_name_without_params.match_type ();
+
   for (enum language lang : unique_styles)
     {
       std::vector<std::string_view> name_vec
@@ -16693,8 +16696,6 @@ cooked_index_functions::expand_symtabs_matching
 	     "x::a::b".  */
 	  if (symbol_matcher == nullptr)
 	    {
-	      symbol_name_match_type match_type
-		= lookup_name_without_params.match_type ();
 	      if ((match_type == symbol_name_match_type::FULL
 		   || (lang != language_ada
 		       && match_type == symbol_name_match_type::EXPRESSION)))
-- 
2.40.1


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

* [PATCH v3][PR symtab/30520 v2 4/4] gdb/symtab: use symbol name matcher for all segments in a qualified name
  2024-05-08 20:22 [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 2/4] gdb/symtab: reuse last segment lookup name info by creating it outside the loop Dmitry Neverov
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 3/4] gdb/symtab: compute match_type " Dmitry Neverov
@ 2024-05-08 20:22 ` Dmitry Neverov
  2024-05-10 18:39 ` [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Tom Tromey
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Neverov @ 2024-05-08 20:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: dmitry.neverov

---
 gdb/dwarf2/read.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 48d5dc11d1d..f9cf76c613d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16644,12 +16644,16 @@ cooked_index_functions::expand_symtabs_matching
     {
       std::vector<std::string_view> name_vec
 	= lookup_name_without_params.split_name (lang);
-      std::string last_name (name_vec.back ());
-
-      lookup_name_info last_segment_lookup_name
-	(last_name, symbol_name_match_type::FULL, completing, true);
+      std::vector<std::string> name_str_vec (name_vec.begin (), name_vec.end ());
+      std::vector<lookup_name_info> segment_lookup_names;
+      segment_lookup_names.reserve (name_vec.size ());
+      for (auto &segment_name : name_str_vec)
+	{
+	  segment_lookup_names.emplace_back
+	    (segment_name, symbol_name_match_type::FULL, completing, true);
+	}
 
-      for (const cooked_index_entry *entry : table->find (last_name,
+      for (const cooked_index_entry *entry : table->find (name_str_vec.back (),
 							  completing))
 	{
 	  QUIT;
@@ -16678,13 +16682,24 @@ cooked_index_functions::expand_symtabs_matching
 	    {
 	      /* If we ran out of entries, or if this segment doesn't
 		 match, this did not match.  */
-	      if (parent == nullptr
-		  || strncmp (parent->name, name_vec[i - 1].data (),
-			      name_vec[i - 1].length ()) != 0)
+	      if (parent == nullptr)
 		{
 		  found = false;
 		  break;
 		}
+	      if (parent->lang != language_unknown)
+		{
+		  const language_defn *lang_def = language_def (parent->lang);
+		  symbol_name_matcher_ftype *name_matcher
+		    = (lang_def->get_symbol_name_matcher
+			 (segment_lookup_names[i-1]));
+		  if (!name_matcher (parent->canonical,
+				     segment_lookup_names[i-1], nullptr))
+		    {
+		      found = false;
+		      break;
+		    }
+		}
 
 	      parent = parent->get_parent ();
 	    }
@@ -16708,9 +16723,9 @@ cooked_index_functions::expand_symtabs_matching
 		      const language_defn *lang_def = language_def (entry->lang);
 		      symbol_name_matcher_ftype *name_matcher
 			= (lang_def->get_symbol_name_matcher
-			     (last_segment_lookup_name));
+			     (segment_lookup_names.back ()));
 		      if (!name_matcher (entry->canonical,
-					 last_segment_lookup_name, nullptr))
+					 segment_lookup_names.back (), nullptr))
 			continue;
 		    }
 	      }
-- 
2.40.1


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

* Re: [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU
  2024-05-08 20:22 [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Dmitry Neverov
                   ` (2 preceding siblings ...)
  2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 4/4] gdb/symtab: use symbol name matcher for all segments in a qualified name Dmitry Neverov
@ 2024-05-10 18:39 ` Tom Tromey
  2024-05-17 14:01   ` Tom Tromey
  3 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2024-05-10 18:39 UTC (permalink / raw)
  To: Dmitry Neverov; +Cc: gdb-patches

>>>>> "Dmitry" == Dmitry Neverov <dmitry.neverov@jetbrains.com> writes:

Dmitry> From: "Dmitry.Neverov" <dmitry.neverov@jetbrains.com>
Dmitry> The added check fixes the case when an unqualified lookup
Dmitry> name without template arguments causes expansion of many CUs
Dmitry> which contain the name with template arguments.

These all look reasonable to me... what is the status of the copyright
assignment now?  I'm wondering if we can land them.

Tom

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

* Re: [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU
  2024-05-10 18:39 ` [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Tom Tromey
@ 2024-05-17 14:01   ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2024-05-17 14:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Dmitry Neverov, gdb-patches

Dmitry> From: "Dmitry.Neverov" <dmitry.neverov@jetbrains.com>
Dmitry> The added check fixes the case when an unqualified lookup
Dmitry> name without template arguments causes expansion of many CUs
Dmitry> which contain the name with template arguments.

Tom> These all look reasonable to me... what is the status of the copyright
Tom> assignment now?  I'm wondering if we can land them.

This came through.  I'm going to apply the series in the name of
expediency; but Dmitry, if you plan to send more gdb patches, please
email me and I'll get you set up with write-after-approval access.

Tom

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

end of thread, other threads:[~2024-05-17 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 20:22 [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Dmitry Neverov
2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 2/4] gdb/symtab: reuse last segment lookup name info by creating it outside the loop Dmitry Neverov
2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 3/4] gdb/symtab: compute match_type " Dmitry Neverov
2024-05-08 20:22 ` [PATCH v3][PR symtab/30520 v2 4/4] gdb/symtab: use symbol name matcher for all segments in a qualified name Dmitry Neverov
2024-05-10 18:39 ` [PATCH v3][PR symtab/30520 v2 1/4] gdb/symtab: check name matches before expanding a CU Tom Tromey
2024-05-17 14:01   ` Tom Tromey

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