From: Daniel Knezevic <daniel.knezevic@htecgroup.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>,
Keith Seitz <keiths@redhat.com>,
Daniel Knezevic <daniel.knezevic@htecgroup.com>
Subject: [PATCH v3] gdb/symtab.c Fix completion of template class members
Date: Mon, 20 Apr 2026 12:03:19 +0000 [thread overview]
Message-ID: <20260420120310.64156-1-daniel.knezevic@htecgroup.com> (raw)
In-Reply-To: <44171ae9-cd60-4c6d-950d-30276cd489eb@redhat.com>
Hi,
Is there anything I need to change for this patch?
I have updated the patch based on Keith's comments that you can find bellow:
---
gdb/symtab.c | 3 ++-
gdb/testsuite/gdb.cp/cpcompletion.cc | 26 +++++++++++++++++++
gdb/testsuite/gdb.cp/cpcompletion.exp | 37 +++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cd3bf876551..0d349a0f5ad 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5937,7 +5937,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..92561d25405 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 555392b470a..679fb160182 100644
--- a/gdb/testsuite/gdb.cp/cpcompletion.exp
+++ b/gdb/testsuite/gdb.cp/cpcompletion.exp
@@ -137,3 +137,40 @@ 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
Best regards,
Daniel
next prev parent reply other threads:[~2026-04-20 12:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 10:36 Daniel Knezevic
2026-03-03 18:19 ` Keith Seitz
2026-04-20 12:03 ` Daniel Knezevic [this message]
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=20260420120310.64156-1-daniel.knezevic@htecgroup.com \
--to=daniel.knezevic@htecgroup.com \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
--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