Fix regression: expression completer and scope operator (PR gdb/22584)
I noticed this regression in the expression completer: "(gdb) p std::[TAB]" => "(gdb) p std::std::" obviously we should have not completed to "std::std::". The problem is that in the earlier big completer rework, I missed taking into account the fact that with expressions, the completion word point is not always at the start of the symbol name (it is with linespecs). The fix is to run the common prefix / LCD string (what readline uses to expand the input line) through make_completion_match_str too. New testcase included, exercising both TAB completion and the complete command. gdb/ChangeLog: 2017-12-13 Pedro Alves <palves@redhat.com> * completer.c (completion_tracker::maybe_add_completion): New 'text' and 'word' parameters. Use make_completion_match_str. (completion_tracker::add_completion): New 'text' and 'word' parameters. Pass down. (completion_tracker::recompute_lowest_common_denominator): Change parameter type to gdb::unique_xmalloc_ptr rval ref. Adjust. * completer.h (completion_tracker::add_completion): New 'text' and 'word' parameters. (completion_tracker::recompute_lowest_common_denominator): Change parameter type to gdb::unique_xmalloc_ptr rval ref. (completion_tracker::recompute_lowest_common_denominator): Change parameter type to gdb::unique_xmalloc_ptr rval ref. * symtab.c (completion_list_add_name): Pass down 'text' and 'word' as well. gdb/testsuite/ChangeLog: 2017-12-13 Pedro Alves <palves@redhat.com> * gdb.cp/cpcompletion.exp: Load completion-support.exp. ("expression with namespace"): New set of tests. * gdb.cp/pr9594.cc (Test_NS::foo, Test_NS::bar) (Nested::Test_NS::qux): New. * lib/completion-support.exp (test_gdb_complete_cmd_multiple): Add defaults to 'start_quote_char' and 'end_quote_char' parameters.
This commit is contained in:
parent
60a20c1907
commit
a22ecf7026
|
@ -1,3 +1,20 @@
|
||||||
|
2017-12-13 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* completer.c (completion_tracker::maybe_add_completion): New
|
||||||
|
'text' and 'word' parameters. Use make_completion_match_str.
|
||||||
|
(completion_tracker::add_completion): New 'text' and 'word'
|
||||||
|
parameters. Pass down.
|
||||||
|
(completion_tracker::recompute_lowest_common_denominator): Change
|
||||||
|
parameter type to gdb::unique_xmalloc_ptr rval ref. Adjust.
|
||||||
|
* completer.h (completion_tracker::add_completion): New 'text' and
|
||||||
|
'word' parameters.
|
||||||
|
(completion_tracker::recompute_lowest_common_denominator): Change
|
||||||
|
parameter type to gdb::unique_xmalloc_ptr rval ref.
|
||||||
|
(completion_tracker::recompute_lowest_common_denominator): Change
|
||||||
|
parameter type to gdb::unique_xmalloc_ptr rval ref.
|
||||||
|
* symtab.c (completion_list_add_name): Pass down 'text' and 'word'
|
||||||
|
as well.
|
||||||
|
|
||||||
2017-12-13 Pedro Alves <palves@redhat.com>
|
2017-12-13 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* cli/cli-decode.c (complete_on_cmdlist, complete_on_enum): Use
|
* cli/cli-decode.c (complete_on_cmdlist, complete_on_enum): Use
|
||||||
|
|
|
@ -1510,7 +1510,8 @@ completion_tracker::~completion_tracker ()
|
||||||
bool
|
bool
|
||||||
completion_tracker::maybe_add_completion
|
completion_tracker::maybe_add_completion
|
||||||
(gdb::unique_xmalloc_ptr<char> name,
|
(gdb::unique_xmalloc_ptr<char> name,
|
||||||
completion_match_for_lcd *match_for_lcd)
|
completion_match_for_lcd *match_for_lcd,
|
||||||
|
const char *text, const char *word)
|
||||||
{
|
{
|
||||||
void **slot;
|
void **slot;
|
||||||
|
|
||||||
|
@ -1531,7 +1532,10 @@ completion_tracker::maybe_add_completion
|
||||||
if (match_for_lcd_str == NULL)
|
if (match_for_lcd_str == NULL)
|
||||||
match_for_lcd_str = name.get ();
|
match_for_lcd_str = name.get ();
|
||||||
|
|
||||||
recompute_lowest_common_denominator (match_for_lcd_str);
|
gdb::unique_xmalloc_ptr<char> lcd
|
||||||
|
= make_completion_match_str (match_for_lcd_str, text, word);
|
||||||
|
|
||||||
|
recompute_lowest_common_denominator (std::move (lcd));
|
||||||
|
|
||||||
*slot = name.get ();
|
*slot = name.get ();
|
||||||
m_entries_vec.push_back (std::move (name));
|
m_entries_vec.push_back (std::move (name));
|
||||||
|
@ -1544,9 +1548,10 @@ completion_tracker::maybe_add_completion
|
||||||
|
|
||||||
void
|
void
|
||||||
completion_tracker::add_completion (gdb::unique_xmalloc_ptr<char> name,
|
completion_tracker::add_completion (gdb::unique_xmalloc_ptr<char> name,
|
||||||
completion_match_for_lcd *match_for_lcd)
|
completion_match_for_lcd *match_for_lcd,
|
||||||
|
const char *text, const char *word)
|
||||||
{
|
{
|
||||||
if (!maybe_add_completion (std::move (name), match_for_lcd))
|
if (!maybe_add_completion (std::move (name), match_for_lcd, text, word))
|
||||||
throw_error (MAX_COMPLETIONS_REACHED_ERROR, _("Max completions reached."));
|
throw_error (MAX_COMPLETIONS_REACHED_ERROR, _("Max completions reached."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1904,21 +1909,23 @@ completion_find_completion_word (completion_tracker &tracker, const char *text,
|
||||||
/* See completer.h. */
|
/* See completer.h. */
|
||||||
|
|
||||||
void
|
void
|
||||||
completion_tracker::recompute_lowest_common_denominator (const char *new_match)
|
completion_tracker::recompute_lowest_common_denominator
|
||||||
|
(gdb::unique_xmalloc_ptr<char> &&new_match_up)
|
||||||
{
|
{
|
||||||
if (m_lowest_common_denominator == NULL)
|
if (m_lowest_common_denominator == NULL)
|
||||||
{
|
{
|
||||||
/* We don't have a lowest common denominator yet, so simply take
|
/* We don't have a lowest common denominator yet, so simply take
|
||||||
the whole NEW_MATCH as being it. */
|
the whole NEW_MATCH_UP as being it. */
|
||||||
m_lowest_common_denominator = xstrdup (new_match);
|
m_lowest_common_denominator = new_match_up.release ();
|
||||||
m_lowest_common_denominator_unique = true;
|
m_lowest_common_denominator_unique = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Find the common denominator between the currently-known
|
/* Find the common denominator between the currently-known
|
||||||
lowest common denominator and NEW_MATCH. That becomes the
|
lowest common denominator and NEW_MATCH_UP. That becomes the
|
||||||
new lowest common denominator. */
|
new lowest common denominator. */
|
||||||
size_t i;
|
size_t i;
|
||||||
|
const char *new_match = new_match_up.get ();
|
||||||
|
|
||||||
for (i = 0;
|
for (i = 0;
|
||||||
(new_match[i] != '\0'
|
(new_match[i] != '\0'
|
||||||
|
|
|
@ -319,7 +319,8 @@ public:
|
||||||
it is not there already. If too many completions were already
|
it is not there already. If too many completions were already
|
||||||
found, this throws an error. */
|
found, this throws an error. */
|
||||||
void add_completion (gdb::unique_xmalloc_ptr<char> name,
|
void add_completion (gdb::unique_xmalloc_ptr<char> name,
|
||||||
completion_match_for_lcd *match_for_lcd = NULL);
|
completion_match_for_lcd *match_for_lcd = NULL,
|
||||||
|
const char *text = NULL, const char *word = NULL);
|
||||||
|
|
||||||
/* Add all completions matches in LIST. Elements are moved out of
|
/* Add all completions matches in LIST. Elements are moved out of
|
||||||
LIST. */
|
LIST. */
|
||||||
|
@ -406,7 +407,8 @@ private:
|
||||||
it is not there already. If false is returned, too many
|
it is not there already. If false is returned, too many
|
||||||
completions were found. */
|
completions were found. */
|
||||||
bool maybe_add_completion (gdb::unique_xmalloc_ptr<char> name,
|
bool maybe_add_completion (gdb::unique_xmalloc_ptr<char> name,
|
||||||
completion_match_for_lcd *match_for_lcd);
|
completion_match_for_lcd *match_for_lcd,
|
||||||
|
const char *text, const char *word);
|
||||||
|
|
||||||
/* Given a new match, recompute the lowest common denominator (LCD)
|
/* Given a new match, recompute the lowest common denominator (LCD)
|
||||||
to hand over to readline. Normally readline computes this itself
|
to hand over to readline. Normally readline computes this itself
|
||||||
|
@ -418,7 +420,8 @@ private:
|
||||||
"std::vector<..>::push_back", "std::string::push_back", etc., and
|
"std::vector<..>::push_back", "std::string::push_back", etc., and
|
||||||
in this case we want the lowest common denominator to be
|
in this case we want the lowest common denominator to be
|
||||||
"push_back" instead of "std::". */
|
"push_back" instead of "std::". */
|
||||||
void recompute_lowest_common_denominator (const char *new_match);
|
void recompute_lowest_common_denominator
|
||||||
|
(gdb::unique_xmalloc_ptr<char> &&new_match);
|
||||||
|
|
||||||
/* Completion match outputs returned by the symbol name matching
|
/* Completion match outputs returned by the symbol name matching
|
||||||
routines (see symbol_name_matcher_ftype). These results are only
|
routines (see symbol_name_matcher_ftype). These results are only
|
||||||
|
|
|
@ -4735,7 +4735,7 @@ completion_list_add_name (completion_tracker &tracker,
|
||||||
in this case we want the completion lowest common denominator
|
in this case we want the completion lowest common denominator
|
||||||
to be "push_back" instead of "std::". */
|
to be "push_back" instead of "std::". */
|
||||||
tracker.add_completion (std::move (completion),
|
tracker.add_completion (std::move (completion),
|
||||||
&match_res.match_for_lcd);
|
&match_res.match_for_lcd, text, word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
2017-12-13 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* gdb.cp/cpcompletion.exp: Load completion-support.exp.
|
||||||
|
("expression with namespace"): New set of tests.
|
||||||
|
* gdb.cp/pr9594.cc (Test_NS::foo, Test_NS::bar)
|
||||||
|
(Nested::Test_NS::qux): New.
|
||||||
|
* lib/completion-support.exp (test_gdb_complete_cmd_multiple): Add
|
||||||
|
defaults to 'start_quote_char' and 'end_quote_char' parameters.
|
||||||
|
|
||||||
2017-12-13 Joel Brobecker <brobecker@adacore.com>
|
2017-12-13 Joel Brobecker <brobecker@adacore.com>
|
||||||
|
|
||||||
* gdb.base/server-del-break.c: New file.
|
* gdb.base/server-del-break.c: New file.
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
# This file is part of the gdb testsuite.
|
# This file is part of the gdb testsuite.
|
||||||
|
|
||||||
|
load_lib completion-support.exp
|
||||||
|
|
||||||
# A helper procedure to test location completions restricted by
|
# A helper procedure to test location completions restricted by
|
||||||
# class.
|
# class.
|
||||||
proc test_class_complete {class expr name matches} {
|
proc test_class_complete {class expr name matches} {
|
||||||
|
@ -85,3 +87,43 @@ gdb_test "complete p foo1.Fo" "p foo1\\.Foofoo"
|
||||||
|
|
||||||
# Test completion with an anonymous struct.
|
# Test completion with an anonymous struct.
|
||||||
gdb_test "complete p a.g" "p a\\.get"
|
gdb_test "complete p a.g" "p a\\.get"
|
||||||
|
|
||||||
|
with_test_prefix "expression with namespace" {
|
||||||
|
# Before the scope operator, GDB shows all the symbols whose
|
||||||
|
# fully-qualified name matches the completion word.
|
||||||
|
test_gdb_complete_multiple "p " "Test_NS" "" {
|
||||||
|
"Test_NS"
|
||||||
|
"Test_NS::Nested"
|
||||||
|
"Test_NS::Nested::qux"
|
||||||
|
"Test_NS::bar"
|
||||||
|
"Test_NS::foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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 {
|
||||||
|
"Nested"
|
||||||
|
"Nested::qux"
|
||||||
|
"bar"
|
||||||
|
"foo"
|
||||||
|
}
|
||||||
|
test_gdb_complete_tab_multiple "p Test_NS:" ":" $tab_completion_list
|
||||||
|
test_gdb_complete_tab_multiple "p Test_NS::" "" $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 {
|
||||||
|
"Test_NS::Nested"
|
||||||
|
"Test_NS::Nested::qux"
|
||||||
|
"Test_NS::bar"
|
||||||
|
"Test_NS::foo"
|
||||||
|
}
|
||||||
|
test_gdb_complete_cmd_multiple "p " "Test_NS:" $cmd_completion_list
|
||||||
|
test_gdb_complete_cmd_multiple "p " "Test_NS::" $cmd_completion_list
|
||||||
|
|
||||||
|
# Add a disambiguating character and we get a unique completion.
|
||||||
|
test_gdb_complete_unique "p Test_NS::f" "p Test_NS::foo"
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,19 @@ void Foo::Foofoo ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Test_NS {
|
||||||
|
|
||||||
|
int foo;
|
||||||
|
int bar;
|
||||||
|
|
||||||
|
namespace Nested {
|
||||||
|
|
||||||
|
int qux;
|
||||||
|
|
||||||
|
} /* namespace Nested */
|
||||||
|
|
||||||
|
} /* namespace Test_NS */
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
// Anonymous struct with method.
|
// Anonymous struct with method.
|
||||||
|
|
|
@ -178,7 +178,7 @@ proc test_gdb_complete_cmd_unique { input_line complete_line_re } {
|
||||||
# complete command displays the COMPLETION_LIST completion list. Each
|
# complete command displays the COMPLETION_LIST completion list. Each
|
||||||
# entry in the list should be prefixed by CMD_PREFIX.
|
# entry in the list should be prefixed by CMD_PREFIX.
|
||||||
|
|
||||||
proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list start_quote_char end_quote_char } {
|
proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} } {
|
||||||
global gdb_prompt
|
global gdb_prompt
|
||||||
|
|
||||||
set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char]
|
set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char]
|
||||||
|
|
Loading…
Reference in New Issue