aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2019-07-03 16:57:48 +0100
committerPedro Alves <palves@redhat.com>2019-07-03 16:58:30 +0100
commit41fc454c915057d9c5536617370c5eb2a5f71323 (patch)
treee4c833f477121ca24ce4b069c857374eb2603437 /gdb/cli
parentb2b2a2159876fa8db57ce017b949cafc6f1a32df (diff)
downloadgdb-41fc454c915057d9c5536617370c5eb2a5f71323.zip
gdb-41fc454c915057d9c5536617370c5eb2a5f71323.tar.gz
gdb-41fc454c915057d9c5536617370c5eb2a5f71323.tar.bz2
Make gdb::option::complete_options save processed arguments too
Currently, gdb::option::complete_options just discards any processed option argument, because no completer needs that data. When completing "pipe -d XXX gdbcmd XXX" however, the completer needs to know about -d's argument (XXX), in order to know where input is already past the gdb command and the delimiter. In this commit, the fix for that is the factoring out of the save_option_value_in_ctx function and calling it in complete_options. For testing, this makes "maint show test-options-completion-result" show the processed options too, like what the "maint test-options" subcommands output when run. Then, of course, gdb.base/options.exp is adjusted. Doing this exposed a couple latent bugs, which is what the other gdb changes in the patch are for: - in the var_enum case, without the change, we'd end up with a null enum argument, and print: "-enum (null)" - The get_ulongest change is necessary to avoid advancing PP in a case where we end up throwing an error, e.g., when parsing "11x". Without the change the operand pointer shown by "maint show test-options-completion-result" would be left pointing at "x" instead of "11x". gdb/ChangeLog: 2019-07-03 Pedro Alves <palves@redhat.com> * cli/cli-option.c (parse_option) <var_enum>: Don't return an option_value with a null enumeration. (complete_options): Save the option values in the context. (save_option_value_in_ctx): New, factored out from ... (process_options): ... here. * cli/cli-utils.c (get_ulongest): Don't advance PP until the end of the function. * maint-test-options.c (test_options_opts::dump): New, factored out from ... (maintenance_test_options_command_mode): ... here. (maintenance_test_options_command_completion_result): Delete. (maintenance_test_options_command_completion_text): Update comment. (maintenance_show_test_options_completion_result): Change prototype. Just print maintenance_test_options_command_completion_text. (save_completion_result): New. (maintenance_test_options_completer_mode): Pass options context to complete_options, and then save a dump. (_initialize_maint_test_options): Use add_cmd to install "maint show test-options-completion-result". gdb/testsuite/ChangeLog: 2019-07-03 Pedro Alves <palves@redhat.com> * gdb.base/options.exp (test-misc, test-flag, test-boolean) (test-uinteger, test-enum): Adjust res_test_gdb_... calls to pass the expected output in the success.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-option.c70
-rw-r--r--gdb/cli/cli-utils.c7
2 files changed, 47 insertions, 30 deletions
diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c
index 9a53ec0..8f28446 100644
--- a/gdb/cli/cli-option.c
+++ b/gdb/cli/cli-option.c
@@ -58,6 +58,8 @@ struct option_def_and_value
gdb::optional<option_value> value;
};
+static void save_option_value_in_ctx (gdb::optional<option_def_and_value> &ov);
+
/* Info passed around when handling completion. */
struct parse_option_completion_info
{
@@ -349,11 +351,12 @@ parse_option (gdb::array_view<const option_def_group> options_group,
{
complete_on_enum (completion->tracker,
match->enums, *args, *args);
- *args = after_arg;
+ if (completion->tracker.have_completions ())
+ return {};
- option_value val;
- val.enumeration = nullptr;
- return option_def_and_value {*match, match_ctx, val};
+ /* If we don't have completions, let the
+ non-completion path throw on invalid enum value
+ below, so that completion processing stops. */
}
}
@@ -456,6 +459,11 @@ complete_options (completion_tracker &tracker,
(*args - text);
return true;
}
+
+ /* If the caller passed in a context, then it is
+ interested in the option argument values. */
+ if (ov && ov->ctx != nullptr)
+ save_option_value_in_ctx (ov);
}
else
{
@@ -499,6 +507,36 @@ complete_options (completion_tracker &tracker,
return false;
}
+/* Save the parsed value in the option's context. */
+
+static void
+save_option_value_in_ctx (gdb::optional<option_def_and_value> &ov)
+{
+ switch (ov->option.type)
+ {
+ case var_boolean:
+ {
+ bool value = ov->value.has_value () ? ov->value->boolean : true;
+ *ov->option.var_address.boolean (ov->option, ov->ctx) = value;
+ }
+ break;
+ case var_uinteger:
+ *ov->option.var_address.uinteger (ov->option, ov->ctx)
+ = ov->value->uinteger;
+ break;
+ case var_zuinteger_unlimited:
+ *ov->option.var_address.integer (ov->option, ov->ctx)
+ = ov->value->integer;
+ break;
+ case var_enum:
+ *ov->option.var_address.enumeration (ov->option, ov->ctx)
+ = ov->value->enumeration;
+ break;
+ default:
+ gdb_assert_not_reached ("unhandled option type");
+ }
+}
+
/* See cli-option.h. */
bool
@@ -534,29 +572,7 @@ process_options (const char **args,
processed_any = true;
- switch (ov->option.type)
- {
- case var_boolean:
- {
- bool value = ov->value.has_value () ? ov->value->boolean : true;
- *ov->option.var_address.boolean (ov->option, ov->ctx) = value;
- }
- break;
- case var_uinteger:
- *ov->option.var_address.uinteger (ov->option, ov->ctx)
- = ov->value->uinteger;
- break;
- case var_zuinteger_unlimited:
- *ov->option.var_address.integer (ov->option, ov->ctx)
- = ov->value->integer;
- break;
- case var_enum:
- *ov->option.var_address.enumeration (ov->option, ov->ctx)
- = ov->value->enumeration;
- break;
- default:
- gdb_assert_not_reached ("unhandled option type");
- }
+ save_option_value_in_ctx (ov);
}
}
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f5d47ae..333a86a 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -60,13 +60,14 @@ get_ulongest (const char **pp, int trailer)
}
else
{
- retval = strtoulst (p, pp, 0);
- if (p == *pp)
+ const char *end = p;
+ retval = strtoulst (p, &end, 0);
+ if (p == end)
{
/* There is no number here. (e.g. "cond a == b"). */
error (_("Expected integer at: %s"), p);
}
- p = *pp;
+ p = end;
}
if (!(isspace (*p) || *p == '\0' || *p == trailer))