diff --git a/gdb/completer.c b/gdb/completer.c index 370a57e6d7f..2793ce600b9 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -2372,23 +2372,30 @@ completion_tracker::build_completion_result (const char *text, if (m_lowest_common_denominator_unique) { - /* We don't rely on readline appending the quote char as - delimiter as then readline wouldn't append the ' ' after the - completion. */ - char buf[2] = { (char) quote_char () }; + bool completion_suppress_append; - match_list[0] = reconcat (match_list[0], match_list[0], - buf, (char *) NULL); - match_list[1] = NULL; + if (from_readline ()) + { + /* We don't rely on readline appending the quote char as + delimiter as then readline wouldn't append the ' ' after the + completion. */ + char buf[2] = { (char) quote_char (), '\0' }; - /* If the tracker wants to, or we already have a space at the - end of the match, tell readline to skip appending - another. */ - char *match = match_list[0]; - bool completion_suppress_append - = (suppress_append_ws () - || (match[0] != '\0' - && match[strlen (match) - 1] == ' ')); + match_list[0] = reconcat (match_list[0], match_list[0], buf, + (char *) nullptr); + + /* If the tracker wants to, or we already have a space at the end + of the match, tell readline to skip appending another. */ + char *match = match_list[0]; + completion_suppress_append + = (suppress_append_ws () + || (match[0] != '\0' + && match[strlen (match) - 1] == ' ')); + } + else + completion_suppress_append = false; + + match_list[1] = nullptr; return completion_result (match_list, 1, completion_suppress_append); } @@ -2510,21 +2517,14 @@ void completion_result::print_matches (const std::string &prefix, const char *word, int quote_char) { - if (this->number_matches == 1) - printf_unfiltered ("%s%s\n", prefix.c_str (), this->match_list[0]); - else - { - this->sort_match_list (); + this->sort_match_list (); - for (size_t i = 0; i < this->number_matches; i++) - { - printf_unfiltered ("%s%s", prefix.c_str (), - this->match_list[i + 1]); - if (quote_char) - printf_unfiltered ("%c", quote_char); - printf_unfiltered ("\n"); - } - } + char buf[2] = { (char) quote_char, '\0' }; + size_t off = this->number_matches == 1 ? 0 : 1; + + for (size_t i = 0; i < this->number_matches; i++) + printf_unfiltered ("%s%s%s\n", prefix.c_str (), + this->match_list[i + off], buf); if (this->number_matches == max_completions) { diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index c670637ad61..e8acd2f85cf 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -81,8 +81,25 @@ proc run_quoting_and_escaping_tests { root } { test_gdb_complete_none "$cmd ${qc}${root}/xx" \ "expand a non-existent filename" - test_gdb_complete_unique "$cmd ${qc}${root}/a" \ - "$cmd ${qc}${root}/aaa/" "" false \ + # The following test is split into separate cmd and tab calls + # so we can xfail the cmd version. The cmd version will add a + # closing quote, it shouldn't be doing this. This will be + # fixed in a later commit. + if { $qc ne "" } { + setup_xfail "*-*-*" + } + test_gdb_complete_cmd_unique "$cmd ${qc}${root}/a" \ + "$cmd ${qc}${root}/aaa/" \ + "expand a unique directory name" + + if { [readline_is_used] } { + test_gdb_complete_tab_unique "$cmd ${qc}${root}/a" \ + "$cmd ${qc}${root}/aaa/" "" \ + "expand a unique directory name" + } + + test_gdb_complete_unique "$cmd ${qc}${root}/cc2" \ + "$cmd ${qc}${root}/cc2${qc}" " " false \ "expand a unique filename" test_gdb_complete_multiple "$cmd ${qc}${root}/" \