diff options
author | Pedro Alves <palves@redhat.com> | 2017-11-24 23:30:04 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-11-24 23:30:04 +0000 |
commit | 0662b6a7c1b3b04a4ca31a09af703c91c7aa9646 (patch) | |
tree | f4d2777ed27434ce96a3130325e36fd6dcc29b6f /gdb/utils.h | |
parent | 276da9b31bd6e3eb8d1dd814c867266f59f29093 (diff) | |
download | binutils-0662b6a7c1b3b04a4ca31a09af703c91c7aa9646.zip binutils-0662b6a7c1b3b04a4ca31a09af703c91c7aa9646.tar.gz binutils-0662b6a7c1b3b04a4ca31a09af703c91c7aa9646.tar.bz2 |
Make strcmp_iw NOT ignore whitespace in the middle of tokens
currently "b func tion" manages to set a breakpoint at "function" !
All these years I had never noticed this, but now that the linespec
completer actually works, this easily happens by accident, with:
"b func t<tab>"
expecting to get "thread", but getting instead:
"b func tion"
...
Also, this:
"b rettypefunc<int>"
manages to set a breakpoint on "rettype func<int>()".
These things happen due to strcmp_iw "magic".
Fix it by teaching strcmp_iw about when can it skip whitespace. This
required handling user-defined operators, and scope operators,
complicating the code a bit, unfortunately. I added unit tests for
all the corner cases I stumbled on, as I was developing this, and then
in the end wrote a testsuite testcase covering many of the same things
and more (to be added later).
gdb/ChangeLog:
2017-11-24 Pedro Alves <palves@redhat.com>
* cp-support.c (cp_symbol_name_matches_1): New, factored out from
cp_fq_symbol_name_matches. Pass language_cplus to
strncmp_with_mode.
(cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1.
(selftests::test_cp_symbol_name_cmp): New.
(_initialize_cp_support): Register "cp_symbol_name_matches"
selftests.
* language.c (default_symbol_name_matcher): Pass language_minimal
to strncmp_iw_with_mode.
* utils.c: Include "cp-support.h" and <algorithm>.
(valid_identifier_name_char, cp_skip_operator_token, skip_ws)
(cp_is_operator): New functions.
(strncmp_iw_with_mode): Use them. Add language parameter. Don't
skip whitespace in the symbol name when the lookup name doesn't
have spaces, and vice versa.
(strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode.
* utils.h (strncmp_iw_with_mode): Add language parameter.
Diffstat (limited to 'gdb/utils.h')
-rw-r--r-- | gdb/utils.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gdb/utils.h b/gdb/utils.h index e2fa430..dff4b17 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -48,17 +48,24 @@ enum class strncmp_iw_mode /* Helper for strcmp_iw and strncmp_iw. Exported so that languages can implement both NORMAL and MATCH_PARAMS variants in a single - function and defer part of the work to strncmp_iw_with_mode. */ + function and defer part of the work to strncmp_iw_with_mode. + LANGUAGE is used to implement some context-sensitive + language-specific comparisons. For example, for C++, + "string1=operator()" should not match "string2=operator" even in + MATCH_PARAMS mode. */ extern int strncmp_iw_with_mode (const char *string1, const char *string2, size_t string2_len, - strncmp_iw_mode mode); + strncmp_iw_mode mode, + enum language language); /* Do a strncmp() type operation on STRING1 and STRING2, ignoring any differences in whitespace. STRING2_LEN is STRING2's length. Returns 0 if STRING1 matches STRING2_LEN characters of STRING2, non-zero otherwise (slightly different than strncmp()'s range of - return values). */ + return values). Note: passes language_minimal to + strncmp_iw_with_mode, and should therefore be avoided if a more + suitable language is available. */ extern int strncmp_iw (const char *string1, const char *string2, size_t string2_len); @@ -70,7 +77,10 @@ extern int strncmp_iw (const char *string1, const char *string2, As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO". This "feature" is useful when searching for matching C++ function names (such as if the user types 'break FOO', where FOO is a - mangled C++ function). */ + mangled C++ function). + + Note: passes language_minimal to strncmp_iw_with_mode, and should + therefore be avoided if a more suitable language is available. */ extern int strcmp_iw (const char *string1, const char *string2); extern int strcmp_iw_ordered (const char *, const char *); |