diff options
author | Keith Seitz <keiths@redhat.com> | 2018-02-23 10:07:29 -0800 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2018-02-23 10:07:29 -0800 |
commit | b1ecccc4cd06b922c2ea916f2902868de87f8a09 (patch) | |
tree | 24cc4fe619bd848a37e43a0e80256cfdd0d693a4 /gdb/utils.c | |
parent | f79a0082509f184f852a7976dc254ce5368279fc (diff) | |
download | binutils-users/keiths/template-completion.zip binutils-users/keiths/template-completion.tar.gz binutils-users/keiths/template-completion.tar.bz2 |
Support template lookups in strncmp_iw_with_modeusers/keiths/template-completion
This patch adds support for wild template parameter list matches, similar
to how ABI tags or function overloads are now handled.
With this patch, users will be able to "gloss over" the details of matching
template parameter lists. This is accomplished by adding (yet more) logic
to strncmp_iw_with_mode to skip parameter lists if none is explicitly given
by the user.
Here's a simple example using gdb.linespec/cpls-ops.exp:
Before
------
(gdb) ptype test_op_call
type = struct test_op_call {
public:
void operator()(void);
void operator()(int);
void operator()(long);
void operator()<int>(int *);
}
(gdb) b test_op_call::operator()
Breakpoint 1 at 0x400583: test_op_call::operator(). (3 locations)
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x400583 in test_op_call::operator()(int)
at cpls-ops.cc:43
1.2 y 0x40058e in test_op_call::operator()()
at cpls-ops.cc:47
1.3 y 0x40059e in test_op_call::operator()(long)
at cpls-ops.cc:51
The breakpoint at test_op_call::operator()<int> was never set.
After
-----
(gdb) b test_op_call::operator()
Breakpoint 1 at 0x400583: test_op_call::operator(). (4 locations)
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x400583 in test_op_call::operator()(int)
at cpls-ops.cc:43
1.2 y 0x40058e in test_op_call::operator()()
at cpls-ops.cc:47
1.3 y 0x40059e in test_op_call::operator()(long)
at cpls-ops.cc:51
1.4 y 0x4008d0 in test_op_call::operator()<int>(int*)
at cpls-ops.cc:57
Similar to how scope lookups work, passing "-qualified" to the break command
will cause a literal lookup of the symbol. In the example immediately above,
this will cause GDB to only find the three non-template functions.
gdb/ChangeLog:
* NEWS: Mention new template parameter support for
locations/completion.
* cp-support.c (cp_search_name_hash): Break on template parameter
lists.
(cp_symbol_name_matches_1): Tell strncmp_iw_with_mode to ignore
template parameter lists.
* utils.c (skip_template_parameter_list): New function.
(strncmp_iw_with_mode): Support "ignoring" of template parameter lists.
* utils.h (strncmp_iw_with_mode): Add new parameter
`ignore_template_params'.
gdb/doc/ChangeLog:
* gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints
in templates.
gdb/testsuite/ChangeLog:
* gdb.cp/templates.cc (Foozle, operator<, operator<<): New.
(main): Add uses of new functions/types.
* gdb.cp/templates.exp: Add template parameter list tests.
* gdb.linespec/cpcompletion.exp: Load data-structures.exp.
(consume, maket, makearg, makefoo, test_makefoo_1, test_makefoo)
(maketype, makem, test_makem_1, test_makem, template-class-with-method)
(template-function-foo): New procedures.
(template-ret-type): Split range completion to account for template
names completing without template parameter list.
Change "setting breakpoint without template parameter test" to pass.
(test_driver): Call template-function-foo test procedure.
* gdb.linespec/cpls-ops.exp (test_operator_ambiguous): Remove
template restriction.
Add new whitespace tests for template functions.
* gdb.linespec/cpls.cc (foo, a, b, c, d, A, B, NA, NB): New
template definitions.
(template_function_foo): New function.
(main): Call template_function_foo.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 0a072fe..6222f26 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2271,13 +2271,45 @@ skip_abi_tag (const char **name) return false; } +/* If *NAME points at a template parameter list, skip it and return true. + Otherwise do nothing and return false. */ + +static bool +skip_template_parameter_list (const char **name) +{ + const char *p = *name; + + if (*p == '<') + { + const char *template_param_list_end = find_toplevel_char (p + 1, '>'); + + if (template_param_list_end == NULL) + return false; + + p = template_param_list_end + 1; + + /* Skip any whitespace that might occur after the closing of the + parameter list, but only if it is the end of parameter list. */ + const char *q = p; + while (isspace (*q)) + ++q; + if (*q == '>') + p = q; + *name = p; + return true; + } + + return false; +} + /* See utils.h. */ int strncmp_iw_with_mode (const char *string1, const char *string2, size_t string2_len, strncmp_iw_mode mode, enum language language, - completion_match_for_lcd *match_for_lcd) + completion_match_for_lcd *match_for_lcd, + bool ignore_template_params) { const char *string1_start = string1; const char *end_str2 = string2 + string2_len; @@ -2327,6 +2359,48 @@ strncmp_iw_with_mode (const char *string1, const char *string2, string1++; } + /* Skip template parameters in STRING1 if STRING2 does not contain + any. E.g.: + + Case 1: User is looking for all functions named "foo". + string1: foo <...> (...) + string2: foo + + Case 2: User is looking for all methods named "foo" in all template + class instantiations. + string1: Foo<...>::foo <...> (...) + string2: Foo::foo (...) + + Case 3: User is looking for a specific overload of a template + function or method. + string1: foo<...> + string2: foo(...) + + Case 4: User is looking for a specific overload of a specific + template instantiation. + string1: foo<A> (...) + string2: foo<B> (...) + + Case 5: User is looking wild parameter match. + string1: foo<A<a<b<...> > > > (...) + string2: foo<A + */ + if (language == language_cplus && ignore_template_params + && *string1 == '<' && *string2 != '<') + { + /* Skip any parameter list in STRING1. */ + const char *template_start = string1; + + if (skip_template_parameter_list (&string1)) + { + /* Don't mark the parameter list ignored if the user didn't + try to ignore it. [Case #5 above] */ + if (*string2 != '\0' + && match_for_lcd != NULL && template_start != string1) + match_for_lcd->mark_ignored_range (template_start, string1); + } + } + if (*string1 == '\0' || string2 == end_str2) break; @@ -2435,6 +2509,12 @@ strncmp_iw_with_mode (const char *string1, const char *string2, break; if (*string1 == '(' || *string2 == '(') break; + + /* If STRING1 or STRING2 starts with a template + parameter list, break out of operator processing. */ + skip_ws (string1, string2, end_str2); + if (*string1 == '<' || *string2 == '<') + break; } continue; |