From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 04/19] Implement completion limiting for add_filename_to_list.
Date: Thu, 06 Aug 2015 19:58:00 -0000 [thread overview]
Message-ID: <20150806191537.32159.4525.stgit@valrhona.uglyboxes.com> (raw)
In-Reply-To: <20150806191404.32159.50755.stgit@valrhona.uglyboxes.com>
Differences in this revision:
1. Remove partial copy code from add_filename_to_list.
---
This patch converts add_filename_to_list to implement completion limiting.
This function is used by both make_source_files_completion_list
and maybe_add_partial_symbol. Tests have been added for both code
pathways.
gdb/ChangeLog
* symtab.c (add_filename_to_list): Add completer_data argument and
update all callers.
Use add_completion.
gdb/testsuite/ChangeLog
* gdb.base/filesym.c (filesym2): Add external declaration.
* gdb.base/filesym.exp: Compile newly added files.
Add tests for completion limiting.
* gdb.base/filesym2.c, gdb.base/filesym3.c, gdb.base/filesym4.c,
gdb.base/filesym5.c: New files.
---
gdb/symtab.c | 40 +++++------------
gdb/testsuite/gdb.base/filesym.c | 4 +-
gdb/testsuite/gdb.base/filesym.exp | 84 +++++++++++++++++++++++++++++++++++-
gdb/testsuite/gdb.base/filesym2.c | 24 ++++++++++
gdb/testsuite/gdb.base/filesym3.c | 24 ++++++++++
gdb/testsuite/gdb.base/filesym4.c | 24 ++++++++++
gdb/testsuite/gdb.base/filesym5.c | 22 +++++++++
7 files changed, 189 insertions(+), 33 deletions(-)
create mode 100644 gdb/testsuite/gdb.base/filesym2.c
create mode 100644 gdb/testsuite/gdb.base/filesym3.c
create mode 100644 gdb/testsuite/gdb.base/filesym4.c
create mode 100644 gdb/testsuite/gdb.base/filesym5.c
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 34eb6d7..e24de89 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5679,33 +5679,11 @@ make_file_symbol_completion_list (struct completer_data *cdata,
list as necessary. */
static void
-add_filename_to_list (const char *fname, const char *text, const char *word,
+add_filename_to_list (struct completer_data *cdata, const char *fname,
+ const char *text, const char *word,
VEC (char_ptr) **list)
{
- char *newobj;
- size_t fnlen = strlen (fname);
-
- if (word == text)
- {
- /* Return exactly fname. */
- newobj = xmalloc (fnlen + 5);
- strcpy (newobj, fname);
- }
- else if (word > text)
- {
- /* Return some portion of fname. */
- newobj = xmalloc (fnlen + 5);
- strcpy (newobj, fname + (word - text));
- }
- else
- {
- /* Return some of TEXT plus fname. */
- newobj = xmalloc (fnlen + (text - word) + 5);
- strncpy (newobj, word, text - word);
- newobj[text - word] = '\0';
- strcat (newobj, fname);
- }
- VEC_safe_push (char_ptr, *list, newobj);
+ (void) add_completion (cdata, list, fname, text, word);
}
static int
@@ -5754,7 +5732,8 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname,
{
/* This file matches for a completion; add it to the
current list of matches. */
- add_filename_to_list (filename, data->text, data->word, data->list);
+ add_filename_to_list (data->completer_data, filename, data->text,
+ data->word, data->list);
}
else
{
@@ -5763,7 +5742,10 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname,
if (base_name != filename
&& !filename_seen (data->filename_seen_cache, base_name, 1)
&& filename_ncmp (base_name, data->text, data->text_len) == 0)
- add_filename_to_list (base_name, data->text, data->word, data->list);
+ {
+ add_filename_to_list (data->completer_data, base_name, data->text,
+ data->word, data->list);
+ }
}
}
@@ -5804,7 +5786,7 @@ make_source_files_completion_list (struct completer_data *cdata,
{
/* This file matches for a completion; add it to the current
list of matches. */
- add_filename_to_list (s->filename, text, word, &list);
+ add_filename_to_list (cdata, s->filename, text, word, &list);
}
else
{
@@ -5816,7 +5798,7 @@ make_source_files_completion_list (struct completer_data *cdata,
if (base_name != s->filename
&& !filename_seen (filename_seen_cache, base_name, 1)
&& filename_ncmp (base_name, text, text_len) == 0)
- add_filename_to_list (base_name, text, word, &list);
+ add_filename_to_list (cdata, base_name, text, word, &list);
}
}
diff --git a/gdb/testsuite/gdb.base/filesym.c b/gdb/testsuite/gdb.base/filesym.c
index 59093a4..39bf9af 100644
--- a/gdb/testsuite/gdb.base/filesym.c
+++ b/gdb/testsuite/gdb.base/filesym.c
@@ -15,10 +15,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+extern int filesym2 (int arg);
+
int
filesym (int arg)
{
- return arg;
+ return filesym2 (arg);
}
int
diff --git a/gdb/testsuite/gdb.base/filesym.exp b/gdb/testsuite/gdb.base/filesym.exp
index 8084710..3b0ede4 100644
--- a/gdb/testsuite/gdb.base/filesym.exp
+++ b/gdb/testsuite/gdb.base/filesym.exp
@@ -16,9 +16,10 @@
# This series of completion tests checks the completion output
# on a name which is potentially both a symbol name and a file name.
-standard_testfile
+standard_testfile filesym.c filesym2.c filesym3.c filesym4.c filesym5.c
-if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+if {[prepare_for_testing $testfile.exp $testfile \
+ [list $srcfile $srcfile2 $srcfile3 $srcfile4 $srcfile5] debug]} {
return -1
}
@@ -40,9 +41,20 @@ gdb_test_multiple "" $tst {
# Now ask for the completion list
set tst "completion list for \"filesym\""
+
+ set expected {\x07\r\n}
+ for {set i 1} {$i <= 5} {incr i} {
+ if {$i == 1} {
+ append expected "filesym\[ \t\]+"
+ append expected "filesym\\\.c\[ \t\]+"
+ } else {
+ append expected "filesym$i\[ \t\]+"
+ append expected "filesym${i}\\\.c\[ \t\]+"
+ }
+ }
send_gdb "\t\t"
gdb_test_multiple "" $tst {
- -re "\\\x07\r\nfilesym\[ \t\]+filesym.c\[ \t\]+\r\n$gdb_prompt " {
+ -re "$expected\r\n$gdb_prompt " {
pass $tst
# Flush the rest of the output by creating the breakpoint.
@@ -54,4 +66,70 @@ gdb_test_multiple "" $tst {
}
}
+# Test completion limiting.
+#
+# We cannot assume any order when completion
+# limiting is in effect. All we know is symbol names are completed
+# first and file names next. If max-completions is set greater than
+# the number of symbols, we will have all of the symbols and
+# (max-completions - 5) file names in the completion list.
+# We also cannot know which file names will be mentioned -- only the number
+# of source files that should be mentioned.
+
+# The number of symbols/files defined in this test.
+set number_of_symbols 5
+
+# The number of completions to attempt
+set max_completions 7; # This will give all (5) files and 2 file names
+
+# List of seen files
+set files_seen {}
+
+# List of seen symbols
+set syms_seen {}
+
+# Set the maximum completions.
+gdb_test_no_output "set max-completions $max_completions"
+
+# The terminal at the end of the complete command
+set end "\\\*\\\*\\\* List may be truncated, "
+append end "max-completions reached\\\. \\\*\\\*\\\*"
+
+with_test_prefix "completion limit on files" {
+ gdb_test_multiple "complete break filesy" "" {
+ "complete break filesy" { exp_continue }
+
+ -re "break filesym(\[2-$number_of_symbols\])?(\\\.c)?\r\n" {
+ set name [string trim $expect_out(0,string) \r\n]
+ #send_log "seen: $name -- "
+ if {[string match "*.c" $name]} {
+ #send_log "is file\n"
+ lappend files_seen $name
+ } else {
+ #send_log "is symbol\n"
+ lappend syms_seen $name
+ }
+ exp_continue
+ }
+
+ -re "break filesy $end\r\n$gdb_prompt $" {
+ set n [llength $syms_seen]
+ if {$n == $number_of_symbols} {
+ pass "symbols seen"
+ } else {
+ fail "symbols seen ($n/$number_of_symbols)"
+ }
+
+ if {[llength $files_seen] \
+ == [expr {$max_completions - $number_of_symbols}]} {
+ pass "files seen"
+ } else {
+ set n [llength $files_seen]
+ set m [expr {$max_completions - $number_of_symbols}]
+ fail "files seen ($n/$m)"
+ }
+ }
+ }
+}
+
unset -nocomplain tst
diff --git a/gdb/testsuite/gdb.base/filesym2.c b/gdb/testsuite/gdb.base/filesym2.c
new file mode 100644
index 0000000..e16bb53
--- /dev/null
+++ b/gdb/testsuite/gdb.base/filesym2.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern int filesym3 (int arg);
+
+int
+filesym2 (int arg)
+{
+ return filesym3 (arg);
+}
diff --git a/gdb/testsuite/gdb.base/filesym3.c b/gdb/testsuite/gdb.base/filesym3.c
new file mode 100644
index 0000000..846a488
--- /dev/null
+++ b/gdb/testsuite/gdb.base/filesym3.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern int filesym4 (int arg);
+
+int
+filesym3 (int arg)
+{
+ return filesym4 (arg);
+}
diff --git a/gdb/testsuite/gdb.base/filesym4.c b/gdb/testsuite/gdb.base/filesym4.c
new file mode 100644
index 0000000..2d6e506
--- /dev/null
+++ b/gdb/testsuite/gdb.base/filesym4.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern int filesym5 (int arg);
+
+int
+filesym4 (int arg)
+{
+ return filesym5 (arg);
+}
diff --git a/gdb/testsuite/gdb.base/filesym5.c b/gdb/testsuite/gdb.base/filesym5.c
new file mode 100644
index 0000000..e192da8
--- /dev/null
+++ b/gdb/testsuite/gdb.base/filesym5.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+filesym5 (int arg)
+{
+ return arg;
+}
next prev parent reply other threads:[~2015-08-06 19:58 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 2:37 [PATCH v3 00/19] New completer API Keith Seitz
2015-08-06 19:18 ` [PATCH v3 09/19] Implement completion limiting for interpreter_completer Keith Seitz
2015-08-23 4:03 ` Doug Evans
2015-08-06 19:20 ` [PATCH v3 12/19] Implement completion limiting for sim_command_completer Keith Seitz
2015-08-23 4:11 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 19/19] Remove the vector return result from the completion API Keith Seitz
2015-08-23 18:03 ` Doug Evans
2015-08-06 19:58 ` Keith Seitz [this message]
2015-08-23 1:07 ` [PATCH v3 04/19] Implement completion limiting for add_filename_to_list Doug Evans
2015-08-06 19:58 ` [PATCH v3 06/19] Implement completion limiting for condition_completer Keith Seitz
2015-08-23 3:53 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 18/19] Use the hashtable to accumulate completion results Keith Seitz
2015-08-23 17:53 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 02/19] Remove completion_tracker_t from the public completion API Keith Seitz
2015-08-23 1:02 ` Doug Evans
2015-08-24 16:06 ` Doug Evans
2015-08-06 20:03 ` [PATCH v3 01/19] Add struct completer_data to the " Keith Seitz
2015-08-23 0:29 ` Doug Evans
2015-08-06 21:06 ` [PATCH v3 05/19] Implement completion limiting for ada_make_symbol_completion_list Keith Seitz
2015-08-23 3:47 ` Doug Evans
2015-08-06 21:06 ` [PATCH v3 17/19] Make the completion API completely opaque Keith Seitz
2015-08-23 15:14 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 08/19] Implement completion limiting for signal_completer Keith Seitz
2015-08-23 3:59 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 07/19] Implement completion limiting for filename_completer Keith Seitz
2015-08-23 3:58 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 11/19] Implement completion limiting for reg_or_group_completer Keith Seitz
2015-08-23 4:09 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 13/19] Implement completion limiting for complete_on_enum Keith Seitz
2015-08-23 4:19 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 16/19] Implement completion limiting for tui_reggroup_completer Keith Seitz
2015-08-23 4:25 ` Doug Evans
2015-08-06 22:12 ` [PATCH v3 10/19] Implement completion limiting for cmdpy_completer Keith Seitz
2015-08-23 4:07 ` Doug Evans
2015-08-06 22:12 ` [PATCH v3 14/19] Implement completion limiting in add_struct_fields Keith Seitz
2015-08-23 4:23 ` Doug Evans
2015-08-06 22:36 ` [PATCH v3 03/19] Implement completion-limiting for complete_on_cmdlist Keith Seitz
2015-08-23 1:05 ` Doug Evans
2015-08-07 2:37 ` [PATCH v3 15/19] Implement completion limiting for scmcmd_add_completion Keith Seitz
2015-08-23 4:24 ` Doug Evans
2015-08-07 22:57 ` [PATCH v3 00/19] New completer API Andrew Burgess
2015-08-08 0:04 ` Keith Seitz
2015-08-08 6:44 ` Andrew Burgess
2015-08-08 16:25 ` Keith Seitz
2015-08-22 22:25 ` Doug Evans
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=20150806191537.32159.4525.stgit@valrhona.uglyboxes.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).