From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 14/18] Implement completion limiting in add_struct_fields.
Date: Mon, 13 Apr 2015 19:23:00 -0000 [thread overview]
Message-ID: <20150413192336.29172.40145.stgit@valrhona.uglyboxes.com> (raw)
In-Reply-To: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com>
This patch converts add_struct_fields (used by expression_completer) to use
maybe_add_completion and adds (coverage) tests for this new behavior.
break.exp contains two overly greedy regexp patterns which required
tweaking, too.
gdb/ChangeLog
* completer.c (add_struct_fields): Use maybe_add_completion.
gdb/testsuite/ChangeLog
* gdb.base/break.c (struct field_test): New structure.
(field_test_global): New global variable.
* gdb.base/break.exp: Add srcfile to otherwise too greedy regexp
for tests "check disable with history value" and "check disable
with convenience values".
* gdb.base/completion.exp: Add completion limiting tests for
add_struct_fields using the print command.
* gdb.cp/cpcompletion.exp (test_completion_limit): New procedure.
Add completion limiting tests for C++-specific parts of
add_struct_fields using the print command.
* gdb.cp/pr9694.cc (class Foo) <repeated1, repeated2, repeated3,
repeated4, repeated5, repeated6, repeated7, repeated8>: New members.
(Foo::Foo): Add initializer for new members.
(main): Add new methods method1, method2, method3, method4, method5,
method6, method7, and method8 to anonymous structure and make
sure they are not optimized away.
---
gdb/completer.c | 45 +++++++++++++++++++++++++--
gdb/testsuite/gdb.base/break.c | 14 ++++++++
gdb/testsuite/gdb.base/break.exp | 4 +-
gdb/testsuite/gdb.base/completion.exp | 4 ++
gdb/testsuite/gdb.cp/cpcompletion.exp | 55 +++++++++++++++++++++++++++++++++
gdb/testsuite/gdb.cp/pr9594.cc | 28 ++++++++++++++++-
6 files changed, 144 insertions(+), 6 deletions(-)
diff --git a/gdb/completer.c b/gdb/completer.c
index b112c2c..45170e3 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -384,8 +384,27 @@ add_struct_fields (struct completer_data *cdata,
{
if (! strncmp (TYPE_FIELD_NAME (type, i),
fieldname, namelen))
- VEC_safe_push (char_ptr, *output,
- xstrdup (TYPE_FIELD_NAME (type, i)));
+ {
+ char *match = xstrdup (TYPE_FIELD_NAME (type, i));
+ enum maybe_add_completion_enum add_status;
+
+ add_status = maybe_add_completion (cdata, match);
+ switch (add_status)
+ {
+ case MAYBE_ADD_COMPLETION_OK:
+ VEC_safe_push (char_ptr, *output, match);
+ break;
+ case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+ VEC_safe_push (char_ptr, *output, match);
+ return;
+ case MAYBE_ADD_COMPLETION_MAX_REACHED:
+ xfree (match);
+ return;
+ case MAYBE_ADD_COMPLETION_DUPLICATE:
+ xfree (match);
+ break;
+ }
+ }
}
else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
{
@@ -409,7 +428,27 @@ add_struct_fields (struct completer_data *cdata,
}
/* Omit constructors from the completion list. */
if (!type_name || strcmp (type_name, name))
- VEC_safe_push (char_ptr, *output, xstrdup (name));
+ {
+ char *match = xstrdup (name);
+ enum maybe_add_completion_enum add_status;
+
+ add_status = maybe_add_completion (cdata, match);
+ switch (add_status)
+ {
+ case MAYBE_ADD_COMPLETION_OK:
+ VEC_safe_push (char_ptr, *output, match);
+ break;
+ case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+ VEC_safe_push (char_ptr, *output, match);
+ return;
+ case MAYBE_ADD_COMPLETION_MAX_REACHED:
+ xfree (match);
+ return;
+ case MAYBE_ADD_COMPLETION_DUPLICATE:
+ xfree (match);
+ break;
+ }
+ }
}
}
}
diff --git a/gdb/testsuite/gdb.base/break.c b/gdb/testsuite/gdb.base/break.c
index d017a91..8ee11b1 100644
--- a/gdb/testsuite/gdb.base/break.c
+++ b/gdb/testsuite/gdb.base/break.c
@@ -30,6 +30,20 @@ void *need_malloc ()
return malloc (1);
}
+/* A structure for testing add_struct_fields. */
+struct field_test
+{
+ int a1_field;
+ int a2_field;
+ int a3_field;
+ int a4_field;
+ int a5_field;
+ int a6_field;
+ int a7_field;
+};
+
+struct field_test field_test_global = {1, 2, 3, 4, 5, 6, 7};
+
/*
* This simple classical example of recursion is useful for
* testing stack backtraces and such.
diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp
index f879bc8..5344533 100644
--- a/gdb/testsuite/gdb.base/break.exp
+++ b/gdb/testsuite/gdb.base/break.exp
@@ -249,7 +249,7 @@ set see5 0
set see6 0
gdb_test_multiple "info break" "check disable with history values" {
- -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
+ -re "1\[\t \]+breakpoint *keep y.* at .*$srcfile:$main_line\[\r\n\]*" {
set see1 1
exp_continue
}
@@ -295,7 +295,7 @@ set see5 0
set see6 0
gdb_test_multiple "info break" "check disable with convenience values" {
- -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
+ -re "1\[\t \]+breakpoint *keep y.* in main at .*$srcfile:$main_line\[^\r\n\]*" {
set see1 1
exp_continue
}
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 516975c..0466dfb 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -1053,3 +1053,7 @@ if {$signal_to_use != ""} {
"handle signal $signal_to_use n\[a-z\]+" \
$max_completions
}
+
+# Test add_struct_fields.
+test_completion_limit "print field_test_global.a" \
+ "print field_test_global\\\.a\[1-9\]_field" $max_completions
diff --git a/gdb/testsuite/gdb.cp/cpcompletion.exp b/gdb/testsuite/gdb.cp/cpcompletion.exp
index 023c261..a1bc6d8 100644
--- a/gdb/testsuite/gdb.cp/cpcompletion.exp
+++ b/gdb/testsuite/gdb.cp/cpcompletion.exp
@@ -85,3 +85,58 @@ gdb_test "complete p foo1.Fo" "p foo1\\.Foofoo"
# Test completion with an anonymous struct.
gdb_test "complete p a.g" "p a\\.get"
+
+# Test completion limiting (add_struct_fields)
+set max_completions 3
+gdb_test_no_output "set max-completions $max_completions"
+
+# A convenience function for testing completion limiting.
+# CMD is a GDB command to to run with "complete".
+# PATTERN is a regexp pattern matching the expected output
+# of completion items "seen" in the output.
+# NUM is the number of maximum completions expected.
+#
+# The test will use the test name "limit complete CMD"
+# and will only count the number of completion items matching
+# PATTERN. No assumptions are made on the order of the items
+# seen in GDB's output.
+#
+# If NUM items are seen before the truncation message, the test
+# passes, otherwise it fails. The test can also fail if no
+# truncation message is seen at all, in which case the test
+# failure message will say "(unlimited)".
+
+proc test_completion_limit {cmd pattern num} {
+ global gdb_prompt
+
+ # The terminal at the end of the complete command
+ set end "\\\*\\\*\\\* List may be truncated, "
+ append end "max-completions reached\\\. \\\*\\\*\\\*"
+
+ set cmdr [string_to_regexp $cmd]
+ set seen 0
+ gdb_test_multiple "complete $cmd" "limit complete $cmd" {
+ "complete $cmdr" { exp_continue }
+ -re "$pattern\r\n" {
+ incr seen
+ exp_continue
+ }
+ -re ".*$end\r\n$gdb_prompt $" {
+ if {$seen == $num} {
+ pass "limit complete $cmd"
+ } else {
+ fail "limit complete $cmd ($seen/$num)"
+ }
+ }
+ -re ".*$gdb_prompt $" {
+ fail "limit complete $cmd (unlimited)"
+ }
+ }
+}
+
+# Completion limiting tests for add_struct_fields.
+test_completion_limit "print a.meth" "print a\\\.method\[1-8\]" \
+ $max_completions
+
+test_completion_limit "print foo1.repeat" \
+ "print foo1\\\.repeated\[1-8\]" $max_completions
diff --git a/gdb/testsuite/gdb.cp/pr9594.cc b/gdb/testsuite/gdb.cp/pr9594.cc
index 8fdee84..e4b49ce 100644
--- a/gdb/testsuite/gdb.cp/pr9594.cc
+++ b/gdb/testsuite/gdb.cp/pr9594.cc
@@ -11,9 +11,19 @@ class Foo : public Base
private:
int foo_value;
+ int repeated1;
+ int repeated2;
+ int repeated3;
+ int repeated4;
+ int repeated5;
+ int repeated6;
+ int repeated7;
+ int repeated8;
public:
- Foo () { foo_value = 0;}
+ Foo () : foo_value (0), repeated1 (1), repeated2 (2), repeated3 (3),
+ repeated4 (4), repeated5 (5), repeated6 (6), repeated7 (7),
+ repeated8 (8) {}
Foo (int i) { foo_value = i;}
~Foo () { }
void set_foo (int value);
@@ -44,9 +54,25 @@ int main ()
// Anonymous struct with method.
struct {
int get() { return 5; }
+ int method1 (void) { return 1; }
+ int method2 (void) { return 2; }
+ int method3 (void) { return 3; }
+ int method4 (void) { return 4; }
+ int method5 (void) { return 5; }
+ int method6 (void) { return 6; }
+ int method7 (void) { return 7; }
+ int method8 (void) { return 8; }
} a;
Foo foo1;
foo1.set_foo (42); // Set breakpoint here.
a.get(); // Prevent compiler from throwing 'a' away.
+ a.method1 ();
+ a.method2 ();
+ a.method3 ();
+ a.method4 ();
+ a.method5 ();
+ a.method6 ();
+ a.method7 ();
+ a.method8 ();
return 0;
}
next prev parent reply other threads:[~2015-04-13 19:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 19:23 [PATCH 00/18] Implement full completer limiting Keith Seitz
2015-04-13 19:23 ` [PATCH 05/18] Implement completion limiting for ada_make_symbol_completion_list Keith Seitz
2015-04-13 19:23 ` [PATCH 08/18] Implement completion limiting for signal_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 11/18] Implement completion limiting for reg_or_group_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 03/18] Implement completion limiting for complete_on_cmdlist Keith Seitz
2015-04-13 19:23 ` [PATCH 01/18] Add struct completer_data to the completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 04/18] Implement completion limiting for add_filename_to_list Keith Seitz
2015-04-13 19:23 ` [PATCH 18/18] Remove the vector return result from the completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 06/18] Implement completion limiting for condition_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 16/18] Make the completion API completely opaque Keith Seitz
2015-04-13 19:23 ` [PATCH 09/18] Implement completion limiting for interpreter_completer Keith Seitz
2015-04-13 19:23 ` Keith Seitz [this message]
2015-04-13 19:23 ` [PATCH 07/18] Implement completion limiting for filename_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 17/18] Use the hashtable to accumulate completion results Keith Seitz
2015-04-13 19:23 ` [PATCH 02/18] Remove completion_tracker_t from the public completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 15/18] Implement completion limiting for scmcmd_add_completion Keith Seitz
2015-04-13 19:23 ` [PATCH 10/18] Implement completion limiting for cmdpy_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 12/18] Implement completion limiting for sim_command_completer Keith Seitz
2015-04-14 15:28 ` Mike Frysinger
2015-05-05 15:03 ` Keith Seitz
2015-05-05 15:34 ` Mike Frysinger
2015-05-05 15:53 ` Keith Seitz
2015-04-13 19:23 ` [PATCH 13/18] Implement completion limiting for complete_on_enum Keith Seitz
2015-04-20 3:21 ` [PATCH 00/18] Implement full completer limiting Doug Evans
2015-04-29 19:19 ` Keith Seitz
2015-04-30 0:26 ` 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=20150413192336.29172.40145.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