Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Knezevic <daniel.knezevic@htecgroup.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Pedro Alves <pedro@palves.net>,
	Simon Marchi <simark@simark.ca>, Keith Seitz <keiths@redhat.com>
Subject: [PATCH v3] gdb/symtab.c Fix completion of template class members
Date: Tue, 3 Mar 2026 10:36:37 +0000	[thread overview]
Message-ID: <20260303103633.256157-1-daniel.knezevic@htecgroup.com> (raw)

This is v3 of:
https://inbox.sourceware.org/gdb-patches/20251113095559.404539-1-daniel.knezevic@htecgroup.com/raw

Do not break the symbol if it contains '<' or '>' characters.

This patch fixes formatting of the code and adds more tests for testing         
completion of nested template classes.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30202
---
 gdb/symtab.c                          |  3 ++-
 gdb/testsuite/gdb.cp/cpcompletion.cc  | 26 +++++++++++++++++++
 gdb/testsuite/gdb.cp/cpcompletion.exp | 36 +++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index a789b0f7593..5d5d1565a5d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5886,7 +5886,8 @@ default_collect_symbol_completion_matches_break_on
 	  while (p > text)
 	    {
 	      if (c_isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0'
-		  || p[-1] == ':' || strchr (break_on, p[-1]) != NULL)
+		  || p[-1] == ':' || p[-1] == '<' || p[-1] == '>'
+		  || strchr (break_on, p[-1]) != NULL)
 		--p;
 	      else
 		break;
diff --git a/gdb/testsuite/gdb.cp/cpcompletion.cc b/gdb/testsuite/gdb.cp/cpcompletion.cc
index b85f168928c..defbd75ad34 100644
--- a/gdb/testsuite/gdb.cp/cpcompletion.cc
+++ b/gdb/testsuite/gdb.cp/cpcompletion.cc
@@ -74,6 +74,28 @@ struct baz
   S s;
 };
 
+/* The Outer class is used to test completion of nested template classes*/
+template <typename T>
+struct Outer
+{
+  T value;
+
+  template <typename U>
+  struct Inner
+  {
+    U inner_value;
+    T outer_ref;
+  };
+
+  Inner<int> get_int_inner () const
+  {
+    Inner<int> i;
+    i.inner_value = 0;
+    i.outer_ref = value;
+    return i;
+  }
+};
+
 int main ()
 {
   baz<int> obj (2.3, 0.1);
@@ -84,5 +106,9 @@ int main ()
   Foo foo1;
   foo1.set_foo (42);		// Set breakpoint here.
   a.get();			// Prevent compiler from throwing 'a' away.
+  Outer<double> outer;
+  outer.value = 4.2;
+  auto inner = outer.get_int_inner();
+  Outer<double>::Inner<long> long_inner;
   return 0;
 }
diff --git a/gdb/testsuite/gdb.cp/cpcompletion.exp b/gdb/testsuite/gdb.cp/cpcompletion.exp
index 1fb9a6bf01d..9ae17026f7d 100644
--- a/gdb/testsuite/gdb.cp/cpcompletion.exp
+++ b/gdb/testsuite/gdb.cp/cpcompletion.exp
@@ -137,3 +137,39 @@ with_test_prefix "expression with namespace" {
 }
 
 test_gdb_complete_unique "break baz(int" "break baz(int, double)"
+
+# Test completion with a template class.
+test_gdb_complete_unique "p baz<int>::" "p baz<int>::baz<double>(int, double)"
+
+# Test completion of nested template classes
+with_test_prefix "nested template classes" {
+    # Unlike in linespecs, tab- and complete-command completion work a
+    # bit differently when completing around the scope operator.  The
+    # matches in the tab-completion case only show the part of the
+    # symbol after the scope, since ':' is a word break character.
+
+    set tab_completion_list {
+	"Inner<int>"
+	"Inner<long>"
+	"get_int_inner() const"
+    }
+    test_gdb_complete_tab_multiple "ptype Outer<double>:" ":" $tab_completion_list
+    test_gdb_complete_tab_multiple "ptype Outer<double>::" "" $tab_completion_list
+
+    # OTOH, the complete command must show the whole command, with
+    # qualified symbol displayed as entered by the user.
+    set cmd_completion_list {
+	"Outer<double>::Inner<int>"
+	"Outer<double>::Inner<long>"
+	"Outer<double>::get_int_inner() const"
+    }
+    test_gdb_complete_cmd_multiple "ptype " "Outer<double>:" $cmd_completion_list
+    test_gdb_complete_cmd_multiple "ptype " "Outer<double>::" $cmd_completion_list
+    test_gdb_complete_cmd_multiple "ptype " "Outer<double>::Inn" {
+	"Outer<double>::Inner<int>"
+	"Outer<double>::Inner<long>"
+    }
+
+    # Add a disambiguating character and we get a unique completion.
+    test_gdb_complete_unique "ptype Outer<double>::g" "ptype Outer<double>::get_int_inner() const"
+}
-- 
2.43.0

             reply	other threads:[~2026-03-03 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 10:36 Daniel Knezevic [this message]
2026-03-03 18:19 ` Keith Seitz
2026-04-20 12:03   ` Daniel Knezevic
2026-04-27 15:28     ` Keith Seitz

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=20260303103633.256157-1-daniel.knezevic@htecgroup.com \
    --to=daniel.knezevic@htecgroup.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    --cc=pedro@palves.net \
    --cc=simark@simark.ca \
    --cc=tom@tromey.com \
    /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