#include "source.h"
#include "gdbsupport/byte-vector.h"
#include "gdbsupport/gdb_optional.h"
+#include "safe-ctype.h"
/* Last specified output format. */
print_value (val, print_opts);
}
+/* Called from command completion function to skip over /FMT
+ specifications, allowing the rest of the line to be completed. Returns
+ true if the /FMT is at the end of the current line and there is nothing
+ left to complete, otherwise false is returned.
+
+ In either case *ARGS can be updated to point after any part of /FMT that
+ is present.
+
+ This function is designed so that trying to complete '/' will offer no
+ completions, the user needs to insert the format specification
+ themselves. Trying to complete '/FMT' (where FMT is any non-empty set
+ of alpha-numeric characters) will cause readline to insert a single
+ space, setting the user up to enter the expression. */
+
+static bool
+skip_over_slash_fmt (completion_tracker &tracker, const char **args)
+{
+ const char *text = *args;
+
+ if (text[0] == '/')
+ {
+ bool in_fmt;
+ tracker.set_use_custom_word_point (true);
+
+ if (ISALNUM (text[1]) || ISSPACE (text[1]))
+ {
+ /* Skip over the actual format specification. */
+ while (*text != '\0' && !ISSPACE (*text))
+ ++text;
+
+ if (*text == '\0')
+ {
+ in_fmt = true;
+ tracker.add_completion (make_unique_xstrdup (text));
+ }
+ else
+ {
+ in_fmt = false;
+ while (ISSPACE (*text))
+ ++text;
+ }
+ }
+ else if (text[1] == '\0')
+ {
+ in_fmt = true;
+ ++text;
+ }
+
+ tracker.advance_custom_word_point_by (text - *args);
+ *args = text;
+ return in_fmt;
+ }
+
+ return false;
+}
+
/* See valprint.h. */
void
(tracker, &text, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group))
return;
+ if (skip_over_slash_fmt (tracker, &text))
+ return;
+
const char *word = advance_to_expression_complete_word_point (tracker, text);
expression_completer (ignore, tracker, text, word);
}
set_internalvar (lookup_internalvar ("__"), last_examine_value.get ());
}
}
+
+/* Command completion for the 'display' and 'x' commands. */
+
+static void
+display_and_x_command_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /*word*/)
+{
+ if (skip_over_slash_fmt (tracker, &text))
+ return;
+
+ const char *word = advance_to_expression_complete_word_point (tracker, text);
+ expression_completer (ignore, tracker, text, word);
+}
+
\f
/* Add an expression to the auto-display chain.
Usage: info symbol ADDR\n\
Only for symbols with fixed locations (global or static scope)."));
- add_com ("x", class_vars, x_command, _("\
+ c = add_com ("x", class_vars, x_command, _("\
Examine memory: x/FMT ADDRESS.\n\
ADDRESS is an expression for the memory address to examine.\n\
FMT is a repeat count followed by a format letter and a size letter.\n\
Defaults for format and size letters are those previously used.\n\
Default count is 1. Default address is following last thing printed\n\
with this command or \"print\"."));
+ set_cmd_completer_handle_brkchars (c, display_and_x_command_completer);
add_info ("display", info_display_command, _("\
Expressions to display when program stops, with code numbers.\n\
Do \"info display\" to see current list of code numbers."),
&cmdlist);
- add_com ("display", class_vars, display_command, _("\
+ c = add_com ("display", class_vars, display_command, _("\
Print value of expression EXP each time the program stops.\n\
Usage: display[/FMT] EXP\n\
/FMT may be used before EXP as in the \"print\" command.\n\
and examining is done as in the \"x\" command.\n\n\
With no argument, display all currently requested auto-display expressions.\n\
Use \"undisplay\" to cancel display requests previously made."));
+ set_cmd_completer_handle_brkchars (c, display_and_x_command_completer);
add_cmd ("display", class_vars, enable_display_command, _("\
Enable some expressions to be displayed when program stops.\n\
return -1
}
+# The bulk of this test script pre-dates the completion-support
+# library, and should probably (where possible) be converted.
+# However, for now, new tests are being added using this library.
+load_lib completion-support.exp
+
set test "complete 'hfgfh'"
send_gdb "hfgfh\t"
gdb_test_multiple "" "$test" {
pass "$test"
}
}
+
+# Test completion of 'p', 'x', and 'display' all using a /FMT.
+foreach_with_prefix spc { " " "" } {
+ test_gdb_complete_multiple "p${spc}/d some_union_global." "" "f" {
+ "f1"
+ "f2"
+ }
+
+ test_gdb_complete_none "p${spc}/"
+ test_gdb_complete_unique "p${spc}/d" "p${spc}/d"
+
+ test_gdb_complete_unique "x${spc}/1w values\[0\].b"\
+ "x${spc}/1w values\[0\].b_field"
+
+ test_gdb_complete_unique "display${spc}/x values\[0\].z"\
+ "display${spc}/x values\[0\].z_field"
+}
+
+# Test 'p' using both options and /FMT.
+test_gdb_complete_multiple "p -array on -- /d some_union_global." \
+ "" "f" {
+ "f1"
+ "f2"
+ }