• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisión55ff4e382699e4f414b91067764f49d3e31da398 (tree)
Tiempo2019-06-05 07:30:02
AutorPedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

Make "print" and "compile print" support -OPT options

This patch adds support for "print -option optval --", etc.
Likewise for "compile print".

We'll get:


(gdb) help print
Print value of expression EXP.
Usage: print [[OPTION]... --] [/FMT] [EXP]

Options:

-address [on|off]
Set printing of addresses.
-array [on|off]
Set pretty formatting of arrays.
-array-indexes [on|off]
Set printing of array indexes.
-elements NUMBER|unlimited
Set limit on string chars or array elements to print.
"unlimited" causes there to be no limit.
-max-depth NUMBER|unlimited
Set maximum print depth for nested structures, unions and arrays.
When structures, unions, or arrays are nested beyond this depth then they
will be replaced with either '{...}' or '(...)' depending on the language.
Use "unlimited" to print the complete structure.
-null-stop [on|off]
Set printing of char arrays to stop at first null char.
-object [on|off]
Set printing of C++ virtual function tables.
-pretty [on|off]
Set pretty formatting of structures.
-repeats NUMBER|unlimited
Set threshold for repeated print elements.
"unlimited" causes all elements to be individually printed.
-static-members [on|off]
Set printing of C++ static members.
-symbol [on|off]
Set printing of symbol names when printing pointers.
-union [on|off]
Set printing of unions interior to structures.
-vtbl [on|off]
Set printing of C++ virtual function tables.

Note: because this command accepts arbitrary expressions, if you
specify any command option, you must use a double dash ("--")
to mark the end of option processing. E.g.: "print -o -- myobj".

I want to highlight the comment above about "--".

At first, I thought we could make the print command parse the options,
and if the option wasn't recognized, fallback to parsing as an
expression. Then, if the user wanted to disambiguate, he'd use the
"--" option delimiter. For example, if you had a variable called
"object" and you wanted to print its negative, you'd have to do:

(gdb) print -- -object

After getting that working, I saw that gdb.pascal/floats.exp
regressed, in these tests:

gdb_test "print -r" " = -1\\.2(499.*|5|500.*)"
gdb_test "print -(r)" " = -1.2(499.*|5|500.*)"
gdb_test "print -(r + s)" " = -3\\.4(499.*|5|500.*)"

It's the first one that I found most concerning. It regressed because
"-r" is the abbreviation of "-raw". I realized then that the behavior
change was a bit risker than I'd like, considering scripts, wrappers
around gdb, etc., and even user expectation. So instead, I made the
print command _require_ the "--" options delimiter if you want to
specify any option. So:

(gdb) print -r

is parsed as an expression, and

(gdb) print -r --

is parsed as an option.

I noticed that that's also what lldb's expr (the equivalent of print)
does to handle the same problem.

Going back the options themselves, note that:

- you can shorten option names, as long as unambiguous.
- For boolean options, 0/1 stand for off/on.
- For boolean options, "true" is implied.

So these are all equivalent:

(gdb) print -object on -static-members off -pretty on -- foo
(gdb) print -object -static-members off -pretty -- foo
(gdb) print -object -static-members 0 -pretty -- foo
(gdb) print -o -st 0 -p -- foo

TAB completion is fully supported:

(gdb) p -[TAB]
-address -elements -pretty -symbol
-array -null-stop -repeats -union
-array-indexes -object -static-members -vtbl

Note that the code is organized such that some of the options and the
"set/show" commands code is shared. In particular, the "print"
options and the corresponding "set print" commands are defined with
the same structures. The commands are installed with the
gdb::option::add_setshow_cmds_for_options function.

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>

* compile/compile.c: Include "cli/cli-option.h".
(compile_print_value): Scope data pointer is now a
value_print_options pointer; adjust.
(compile_print_command): Process options. Scope data pointer is
now a value_print_options pointer; adjust.
(_initialize_compile): Update "compile print"'s help to include
supported options. Install a completer for "compile print".
* cp-valprint.c (show_vtblprint, show_objectprint)
(show_static_field_print): Delete.
(_initialize_cp_valprint): Don't install "set print
static-members", "set print vtbl", "set print object" here.
* printcmd.c: Include "cli/cli-option.h" and
"common/gdb_optional.h".
(print_command_parse_format): Rework to fill in a
value_print_options instead of a format_data.
(print_value): Change parameter type from format_data pointer to
value_print_options reference. Adjust.
(print_command_1): Process options. Adjust to pass down a
value_print_options.
(print_command_completer): New.
(_initialize_printcmd): Install print_command_completer as
handle_brkchars completer for the "print" command. Update
"print"'s help to include supported options.
* valprint.c: Include "cli/cli-option.h".
(show_vtblprint, show_objectprint, show_static_field_print): Moved
here from cp-valprint.c.
(boolean_option_def, uinteger_option_def)
(value_print_option_defs, make_value_print_options_def_group):
New. Use gdb::option::add_setshow_cmds_for_options to install
"set print elements", "set print null-stop", "set print repeats",
"set print pretty", "set print union", "set print array", "set
print address", "set print symbol", "set print array-indexes".
* valprint.h: Include <string> and "cli/cli-option.h".
(make_value_print_options_def_group): Declare.
(print_value): Change parameter type from format_data pointer to
value_print_options reference.
(print_command_completer): Declare.

gdb/testsuite/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>

* gdb.base/options.exp: Build executable.
(test-print): New procedure.
(top level): Call it, once for "print" and another for "compile
print".

Cambiar Resumen

Diferencia incremental

--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -23,6 +23,7 @@
2323 #include "command.h"
2424 #include "cli/cli-script.h"
2525 #include "cli/cli-utils.h"
26+#include "cli/cli-option.h"
2627 #include "completer.h"
2728 #include "gdbcmd.h"
2829 #include "compile.h"
@@ -328,9 +329,9 @@ compile_code_command (const char *arg, int from_tty)
328329 void
329330 compile_print_value (struct value *val, void *data_voidp)
330331 {
331- const struct format_data *fmtp = (const struct format_data *) data_voidp;
332+ const value_print_options *print_opts = (value_print_options *) data_voidp;
332333
333- print_value (val, fmtp);
334+ print_value (val, *print_opts);
334335 }
335336
336337 /* Handle the input from the 'compile print' command. The "compile
@@ -342,22 +343,30 @@ static void
342343 compile_print_command (const char *arg, int from_tty)
343344 {
344345 enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
345- struct format_data fmt;
346+ value_print_options print_opts;
346347
347348 scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
348349
349- /* Passing &FMT as SCOPE_DATA is safe as do_module_cleanup will not
350- touch the stale pointer if compile_object_run has already quit. */
351- print_command_parse_format (&arg, "compile print", &fmt);
350+ get_user_print_options (&print_opts);
351+ /* Override global settings with explicit options, if any. */
352+ auto group = make_value_print_options_def_group (&print_opts);
353+ gdb::option::process_options
354+ (&arg, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group);
355+
356+ print_command_parse_format (&arg, "compile print", &print_opts);
357+
358+ /* Passing &PRINT_OPTS as SCOPE_DATA is safe as do_module_cleanup
359+ will not touch the stale pointer if compile_object_run has
360+ already quit. */
352361
353362 if (arg && *arg)
354- eval_compile_command (NULL, arg, scope, &fmt);
363+ eval_compile_command (NULL, arg, scope, &print_opts);
355364 else
356365 {
357366 counted_command_line l = get_command_line (compile_control, "");
358367
359368 l->control_u.compile.scope = scope;
360- l->control_u.compile.scope_data = &fmt;
369+ l->control_u.compile.scope_data = &print_opts;
361370 execute_control_command_untraced (l.get ());
362371 }
363372 }
@@ -946,11 +955,19 @@ Usage: compile file [-r|-raw] [FILENAME]\n\
946955 &compile_command_list);
947956 set_cmd_completer (c, filename_completer);
948957
949- add_cmd ("print", class_obscure, compile_print_command,
950- _("\
958+ const auto compile_print_opts = make_value_print_options_def_group (nullptr);
959+
960+ static const std::string compile_print_help
961+ = gdb::option::build_help (N_("\
951962 Evaluate EXPR by using the compiler and print result.\n\
952963 \n\
953-Usage: compile print[/FMT] [EXPR]\n\
964+Usage: compile print [[OPTION]... --] [/FMT] [EXPR]\n\
965+\n\
966+Options:\n\
967+%OPTIONS%\
968+Note: because this command accepts arbitrary expressions, if you\n\
969+specify any command option, you must use a double dash (\"--\")\n\
970+to mark the end of option processing. E.g.: \"compile print -o -- myobj\".\n\
954971 \n\
955972 The expression may be specified on the same line as the command, e.g.:\n\
956973 \n\
@@ -963,7 +980,12 @@ indicate the end of the expression.\n\
963980 \n\
964981 EXPR may be preceded with /FMT, where FMT is a format letter\n\
965982 but no count or size letter (see \"x\" command)."),
966- &compile_command_list);
983+ compile_print_opts);
984+
985+ c = add_cmd ("print", class_obscure, compile_print_command,
986+ compile_print_help.c_str (),
987+ &compile_command_list);
988+ set_cmd_completer_handle_brkchars (c, print_command_completer);
967989
968990 add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
969991 Set compile command debugging."), _("\
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -37,39 +37,6 @@
3737 #include "typeprint.h"
3838 #include "common/byte-vector.h"
3939
40-/* Controls printing of vtbl's. */
41-static void
42-show_vtblprint (struct ui_file *file, int from_tty,
43- struct cmd_list_element *c, const char *value)
44-{
45- fprintf_filtered (file, _("\
46-Printing of C++ virtual function tables is %s.\n"),
47- value);
48-}
49-
50-/* Controls looking up an object's derived type using what we find in
51- its vtables. */
52-static void
53-show_objectprint (struct ui_file *file, int from_tty,
54- struct cmd_list_element *c,
55- const char *value)
56-{
57- fprintf_filtered (file, _("\
58-Printing of object's derived type based on vtable info is %s.\n"),
59- value);
60-}
61-
62-static void
63-show_static_field_print (struct ui_file *file, int from_tty,
64- struct cmd_list_element *c,
65- const char *value)
66-{
67- fprintf_filtered (file,
68- _("Printing of C++ static members is %s.\n"),
69- value);
70-}
71-
72-
7340 static struct obstack dont_print_vb_obstack;
7441 static struct obstack dont_print_statmem_obstack;
7542 static struct obstack dont_print_stat_array_obstack;
@@ -821,30 +788,6 @@ cp_print_class_member (const gdb_byte *valaddr, struct type *type,
821788 void
822789 _initialize_cp_valprint (void)
823790 {
824- add_setshow_boolean_cmd ("static-members", class_support,
825- &user_print_options.static_field_print, _("\
826-Set printing of C++ static members."), _("\
827-Show printing of C++ static members."), NULL,
828- NULL,
829- show_static_field_print,
830- &setprintlist, &showprintlist);
831-
832- add_setshow_boolean_cmd ("vtbl", class_support,
833- &user_print_options.vtblprint, _("\
834-Set printing of C++ virtual function tables."), _("\
835-Show printing of C++ virtual function tables."), NULL,
836- NULL,
837- show_vtblprint,
838- &setprintlist, &showprintlist);
839-
840- add_setshow_boolean_cmd ("object", class_support,
841- &user_print_options.objectprint, _("\
842-Set printing of object's derived type based on vtable info."), _("\
843-Show printing of object's derived type based on vtable info."), NULL,
844- NULL,
845- show_objectprint,
846- &setprintlist, &showprintlist);
847-
848791 obstack_begin (&dont_print_stat_array_obstack,
849792 32 * sizeof (struct type *));
850793 obstack_begin (&dont_print_statmem_obstack,
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -45,11 +45,13 @@
4545 #include "charset.h"
4646 #include "arch-utils.h"
4747 #include "cli/cli-utils.h"
48+#include "cli/cli-option.h"
4849 #include "cli/cli-script.h"
4950 #include "cli/cli-style.h"
5051 #include "common/format.h"
5152 #include "source.h"
5253 #include "common/byte-vector.h"
54+#include "common/gdb_optional.h"
5355
5456 /* Last specified output format. */
5557
@@ -1117,40 +1119,41 @@ validate_format (struct format_data fmt, const char *cmdname)
11171119 fmt.format, cmdname);
11181120 }
11191121
1120-/* Parse print command format string into *FMTP and update *EXPP.
1122+/* Parse print command format string into *OPTS and update *EXPP.
11211123 CMDNAME should name the current command. */
11221124
11231125 void
11241126 print_command_parse_format (const char **expp, const char *cmdname,
1125- struct format_data *fmtp)
1127+ value_print_options *opts)
11261128 {
11271129 const char *exp = *expp;
11281130
11291131 if (exp && *exp == '/')
11301132 {
1133+ format_data fmt;
1134+
11311135 exp++;
1132- *fmtp = decode_format (&exp, last_format, 0);
1133- validate_format (*fmtp, cmdname);
1134- last_format = fmtp->format;
1136+ fmt = decode_format (&exp, last_format, 0);
1137+ validate_format (fmt, cmdname);
1138+ last_format = fmt.format;
1139+
1140+ opts->format = fmt.format;
1141+ opts->raw = fmt.raw;
11351142 }
11361143 else
11371144 {
1138- fmtp->count = 1;
1139- fmtp->format = 0;
1140- fmtp->size = 0;
1141- fmtp->raw = 0;
1145+ opts->format = 0;
1146+ opts->raw = 0;
11421147 }
11431148
11441149 *expp = exp;
11451150 }
11461151
1147-/* Print VAL to console according to *FMTP, including recording it to
1148- the history. */
1152+/* See valprint.h. */
11491153
11501154 void
1151-print_value (struct value *val, const struct format_data *fmtp)
1155+print_value (value *val, const value_print_options &opts)
11521156 {
1153- struct value_print_options opts;
11541157 int histindex = record_latest_value (val);
11551158
11561159 annotate_value_history_begin (histindex, value_type (val));
@@ -1159,28 +1162,31 @@ print_value (struct value *val, const struct format_data *fmtp)
11591162
11601163 annotate_value_history_value ();
11611164
1162- get_formatted_print_options (&opts, fmtp->format);
1163- opts.raw = fmtp->raw;
1164-
1165- print_formatted (val, fmtp->size, &opts, gdb_stdout);
1165+ print_formatted (val, 0, &opts, gdb_stdout);
11661166 printf_filtered ("\n");
11671167
11681168 annotate_value_history_end ();
11691169 }
11701170
1171-/* Evaluate string EXP as an expression in the current language and
1172- print the resulting value. EXP may contain a format specifier as the
1173- first argument ("/x myvar" for example, to print myvar in hex). */
1171+/* Implementation of the "print" and "call" commands. */
11741172
11751173 static void
1176-print_command_1 (const char *exp, int voidprint)
1174+print_command_1 (const char *args, int voidprint)
11771175 {
11781176 struct value *val;
1179- struct format_data fmt;
1177+ value_print_options print_opts;
1178+
1179+ get_user_print_options (&print_opts);
1180+ /* Override global settings with explicit options, if any. */
1181+ auto group = make_value_print_options_def_group (&print_opts);
1182+ gdb::option::process_options
1183+ (&args, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group);
1184+
1185+ print_command_parse_format (&args, "print", &print_opts);
11801186
1181- print_command_parse_format (&exp, "print", &fmt);
1187+ const char *exp = args;
11821188
1183- if (exp && *exp)
1189+ if (exp != nullptr && *exp)
11841190 {
11851191 expression_up expr = parse_expression (exp);
11861192 val = evaluate_expression (expr.get ());
@@ -1190,7 +1196,23 @@ print_command_1 (const char *exp, int voidprint)
11901196
11911197 if (voidprint || (val && value_type (val) &&
11921198 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
1193- print_value (val, &fmt);
1199+ print_value (val, print_opts);
1200+}
1201+
1202+/* See valprint.h. */
1203+
1204+void
1205+print_command_completer (struct cmd_list_element *ignore,
1206+ completion_tracker &tracker,
1207+ const char *text, const char * /*word*/)
1208+{
1209+ const auto group = make_value_print_options_def_group (nullptr);
1210+ if (gdb::option::complete_options
1211+ (tracker, &text, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group))
1212+ return;
1213+
1214+ const char *word = advance_to_expression_complete_word_point (tracker, text);
1215+ expression_completer (ignore, tracker, text, word);
11941216 }
11951217
11961218 static void
@@ -2761,7 +2783,7 @@ Usage: call EXP\n\
27612783 The argument is the function name and arguments, in the notation of the\n\
27622784 current working language. The result is printed and saved in the value\n\
27632785 history, if it is not void."));
2764- set_cmd_completer (c, expression_completer);
2786+ set_cmd_completer_handle_brkchars (c, print_command_completer);
27652787
27662788 add_cmd ("variable", class_vars, set_command, _("\
27672789 Evaluate expression EXP and assign result to variable VAR\n\
@@ -2775,9 +2797,18 @@ This may usually be abbreviated to simply \"set\"."),
27752797 &setlist);
27762798 add_alias_cmd ("var", "variable", class_vars, 0, &setlist);
27772799
2778- c = add_com ("print", class_vars, print_command, _("\
2800+ const auto print_opts = make_value_print_options_def_group (nullptr);
2801+
2802+ static const std::string print_help = gdb::option::build_help (N_("\
27792803 Print value of expression EXP.\n\
2780-Usage: print[/FMT] EXP\n\
2804+Usage: print [[OPTION]... --] [/FMT] [EXP]\n\
2805+\n\
2806+Options:\n\
2807+%OPTIONS%\
2808+Note: because this command accepts arbitrary expressions, if you\n\
2809+specify any command option, you must use a double dash (\"--\")\n\
2810+to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\
2811+\n\
27812812 Variables accessible are those of the lexical environment of the selected\n\
27822813 stack frame, plus all those whose scope is global or an entire file.\n\
27832814 \n\
@@ -2797,8 +2828,11 @@ where FOO is stored, etc. FOO must be an expression whose value\n\
27972828 resides in memory.\n\
27982829 \n\
27992830 EXP may be preceded with /FMT, where FMT is a format letter\n\
2800-but no count or size letter (see \"x\" command)."));
2801- set_cmd_completer (c, expression_completer);
2831+but no count or size letter (see \"x\" command)."),
2832+ print_opts);
2833+
2834+ c = add_com ("print", class_vars, print_command, print_help.c_str ());
2835+ set_cmd_completer_handle_brkchars (c, print_command_completer);
28022836 add_com_alias ("p", "print", class_vars, 1);
28032837 add_com_alias ("inspect", "print", class_vars, 1);
28042838
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -19,9 +19,18 @@
1919
2020 # The test uses the "maintenance test-options" subcommands to exercise
2121 # TAB-completion and option processing.
22+#
23+# It also tests option integration in various commands, including
24+# "print" and "compile print".
2225
2326 load_lib completion-support.exp
2427
28+standard_testfile .c
29+
30+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
31+ return -1
32+}
33+
2534 clean_restart
2635
2736 if { ![readline_is_used] } {
@@ -117,6 +126,111 @@ set all_options {
117126 "-zuinteger-unlimited"
118127 }
119128
129+# Basic option-machinery + "print" command integration tests.
130+proc_with_prefix test-print {{prefix ""}} {
131+ clean_restart
132+
133+ # Completing "print" with no argument completes on symbols only,
134+ # no options are offered. Since we haven't loaded any symbols,
135+ # the match list should be empty.
136+ test_gdb_complete_none "${prefix}print "
137+
138+ # OTOH, completing at "-" should list all options.
139+ test_gdb_complete_multiple "${prefix}print " "-" "" {
140+ "-address"
141+ "-array"
142+ "-array-indexes"
143+ "-elements"
144+ "-max-depth"
145+ "-null-stop"
146+ "-object"
147+ "-pretty"
148+ "-repeats"
149+ "-static-members"
150+ "-symbol"
151+ "-union"
152+ "-vtbl"
153+ }
154+
155+ global binfile
156+ clean_restart $binfile
157+
158+ if ![runto_main] {
159+ fail "cannot run to main"
160+ return
161+ }
162+
163+ # Mix options and format.
164+ gdb_test "${prefix}print -pretty -- /x 1" " = 0x1"
165+
166+ # Smoke test that options actually work.
167+ gdb_test "${prefix}print -pretty -- g_s" \
168+ [multi_line \
169+ " = {" \
170+ " a = 1," \
171+ " b = 2," \
172+ " c = 3" \
173+ "}"]
174+
175+ test_gdb_complete_unique \
176+ "${prefix}print xxx" \
177+ "${prefix}print xxx1"
178+ test_gdb_complete_unique \
179+ "${prefix}print -- xxx" \
180+ "${prefix}print -- xxx1"
181+
182+ # Error messages when testing with "compile" are different from
183+ # the error messages gdb's internal parser throws. This procedure
184+ # hides the difference. EXPECTED_RE is only considered when not
185+ # testing with "compile".
186+ proc test_invalid_expression {cmd expected_re} {
187+ upvar prefix prefix
188+
189+ if {$prefix != "compile "} {
190+ gdb_test $cmd $expected_re
191+ } else {
192+ # Error messages depend on compiler version, so we just
193+ # look for the last line indicating a failure.
194+ gdb_test $cmd "Compilation failed\\."
195+ }
196+ }
197+
198+ # Check that '-XXX' without a "--" is handled as an
199+ # expression.
200+ gdb_test "${prefix}print -1" " = -1"
201+ test_invalid_expression \
202+ "${prefix}print --1" \
203+ "Left operand of assignment is not an lvalue\\."
204+ test_invalid_expression \
205+ "${prefix}print -object" \
206+ "No symbol \"object\".*"
207+
208+ # Test printing with options and no expression.
209+ set test "${prefix}print -object --"
210+ if {$prefix != "compile "} {
211+ # Regular "print" repeats the last history value.
212+ gdb_test $test " = -1"
213+ } else {
214+ # "compile print" starts a multiline expression.
215+ gdb_test_multiple $test $test {
216+ -re ">$" {
217+ gdb_test "-1\nend" " = -1" \
218+ $test
219+ }
220+ }
221+ }
222+
223+ # Check that everything after "-- " is treated as an
224+ # expression, not confused with an option.
225+ test_invalid_expression \
226+ "${prefix}print -- -address" \
227+ "No symbol.*"
228+ gdb_test "${prefix}print -- -1" " = -1"
229+ test_invalid_expression \
230+ "${prefix}print -- --1" \
231+ "Left operand of assignment is not an lvalue\\."
232+}
233+
120234 # Miscellaneous tests.
121235 proc_with_prefix test-misc {variant} {
122236 global all_options
@@ -552,3 +666,11 @@ foreach_with_prefix cmd {
552666 }
553667 test-enum $cmd
554668 }
669+
670+# Run the print integration tests.
671+test-print ""
672+
673+# Same for "compile print".
674+if ![skip_compile_feature_tests] {
675+ test-print "compile "
676+}
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -36,6 +36,7 @@
3636 #include <ctype.h>
3737 #include <algorithm>
3838 #include "common/byte-vector.h"
39+#include "cli/cli-option.h"
3940
4041 /* Maximum number of wchars returned from wchar_iterate. */
4142 #define MAX_WCHARS 4
@@ -3069,7 +3070,181 @@ show_print_raw (const char *args, int from_tty)
30693070 cmd_show_list (showprintrawlist, from_tty, "");
30703071 }
30713072
3073+/* Controls printing of vtbl's. */
3074+static void
3075+show_vtblprint (struct ui_file *file, int from_tty,
3076+ struct cmd_list_element *c, const char *value)
3077+{
3078+ fprintf_filtered (file, _("\
3079+Printing of C++ virtual function tables is %s.\n"),
3080+ value);
3081+}
3082+
3083+/* Controls looking up an object's derived type using what we find in
3084+ its vtables. */
3085+static void
3086+show_objectprint (struct ui_file *file, int from_tty,
3087+ struct cmd_list_element *c,
3088+ const char *value)
3089+{
3090+ fprintf_filtered (file, _("\
3091+Printing of object's derived type based on vtable info is %s.\n"),
3092+ value);
3093+}
3094+
3095+static void
3096+show_static_field_print (struct ui_file *file, int from_tty,
3097+ struct cmd_list_element *c,
3098+ const char *value)
3099+{
3100+ fprintf_filtered (file,
3101+ _("Printing of C++ static members is %s.\n"),
3102+ value);
3103+}
3104+
30723105
3106+
3107+/* A couple typedefs to make writing the options a bit more
3108+ convenient. */
3109+using boolean_option_def
3110+ = gdb::option::boolean_option_def<value_print_options>;
3111+using uinteger_option_def
3112+ = gdb::option::uinteger_option_def<value_print_options>;
3113+using zuinteger_unlimited_option_def
3114+ = gdb::option::zuinteger_unlimited_option_def<value_print_options>;
3115+
3116+/* Definions of options for the "print" and "compile print"
3117+ commands. */
3118+static const gdb::option::option_def value_print_option_defs[] = {
3119+
3120+ boolean_option_def {
3121+ "address",
3122+ [] (value_print_options *opt) { return &opt->addressprint; },
3123+ show_addressprint, /* show_cmd_cb */
3124+ N_("Set printing of addresses."),
3125+ N_("Show printing of addresses."),
3126+ NULL, /* help_doc */
3127+ },
3128+
3129+ boolean_option_def {
3130+ "array",
3131+ [] (value_print_options *opt) { return &opt->prettyformat_arrays; },
3132+ show_prettyformat_arrays, /* show_cmd_cb */
3133+ N_("Set pretty formatting of arrays."),
3134+ N_("Show pretty formatting of arrays."),
3135+ NULL, /* help_doc */
3136+ },
3137+
3138+ boolean_option_def {
3139+ "array-indexes",
3140+ [] (value_print_options *opt) { return &opt->print_array_indexes; },
3141+ show_print_array_indexes, /* show_cmd_cb */
3142+ N_("Set printing of array indexes."),
3143+ N_("Show printing of array indexes"),
3144+ NULL, /* help_doc */
3145+ },
3146+
3147+ uinteger_option_def {
3148+ "elements",
3149+ [] (value_print_options *opt) { return &opt->print_max; },
3150+ show_print_max, /* show_cmd_cb */
3151+ N_("Set limit on string chars or array elements to print."),
3152+ N_("Show limit on string chars or array elements to print."),
3153+ N_("\"unlimited\" causes there to be no limit."),
3154+ },
3155+
3156+ zuinteger_unlimited_option_def {
3157+ "max-depth",
3158+ [] (value_print_options *opt) { return &opt->max_depth; },
3159+ show_print_max_depth, /* show_cmd_cb */
3160+ N_("Set maximum print depth for nested structures, unions and arrays."),
3161+ N_("Show maximum print depth for nested structures, unions, and arrays."),
3162+ N_("When structures, unions, or arrays are nested beyond this depth then they\n\
3163+will be replaced with either '{...}' or '(...)' depending on the language.\n\
3164+Use \"unlimited\" to print the complete structure.")
3165+ },
3166+
3167+ boolean_option_def {
3168+ "null-stop",
3169+ [] (value_print_options *opt) { return &opt->stop_print_at_null; },
3170+ show_stop_print_at_null, /* show_cmd_cb */
3171+ N_("Set printing of char arrays to stop at first null char."),
3172+ N_("Show printing of char arrays to stop at first null char."),
3173+ NULL, /* help_doc */
3174+ },
3175+
3176+ boolean_option_def {
3177+ "object",
3178+ [] (value_print_options *opt) { return &opt->objectprint; },
3179+ show_objectprint, /* show_cmd_cb */
3180+ _("Set printing of C++ virtual function tables."),
3181+ _("Show printing of C++ virtual function tables."),
3182+ NULL, /* help_doc */
3183+ },
3184+
3185+ boolean_option_def {
3186+ "pretty",
3187+ [] (value_print_options *opt) { return &opt->prettyformat_structs; },
3188+ show_prettyformat_structs, /* show_cmd_cb */
3189+ N_("Set pretty formatting of structures."),
3190+ N_("Show pretty formatting of structures."),
3191+ NULL, /* help_doc */
3192+ },
3193+
3194+ uinteger_option_def {
3195+ "repeats",
3196+ [] (value_print_options *opt) { return &opt->repeat_count_threshold; },
3197+ show_repeat_count_threshold, /* show_cmd_cb */
3198+ N_("Set threshold for repeated print elements."),
3199+ N_("Show threshold for repeated print elements."),
3200+ N_("\"unlimited\" causes all elements to be individually printed."),
3201+ },
3202+
3203+ boolean_option_def {
3204+ "static-members",
3205+ [] (value_print_options *opt) { return &opt->static_field_print; },
3206+ show_static_field_print, /* show_cmd_cb */
3207+ N_("Set printing of C++ static members."),
3208+ N_("Show printing of C++ static members."),
3209+ NULL, /* help_doc */
3210+ },
3211+
3212+ boolean_option_def {
3213+ "symbol",
3214+ [] (value_print_options *opt) { return &opt->symbol_print; },
3215+ show_symbol_print, /* show_cmd_cb */
3216+ N_("Set printing of symbol names when printing pointers."),
3217+ N_("Show printing of symbol names when printing pointers."),
3218+ NULL, /* help_doc */
3219+ },
3220+
3221+ boolean_option_def {
3222+ "union",
3223+ [] (value_print_options *opt) { return &opt->unionprint; },
3224+ show_unionprint, /* show_cmd_cb */
3225+ N_("Set printing of unions interior to structures."),
3226+ N_("Show printing of unions interior to structures."),
3227+ NULL, /* help_doc */
3228+ },
3229+
3230+ boolean_option_def {
3231+ "vtbl",
3232+ [] (value_print_options *opt) { return &opt->vtblprint; },
3233+ show_vtblprint, /* show_cmd_cb */
3234+ N_("Set printing of C++ virtual function tables."),
3235+ N_("Show printing of C++ virtual function tables."),
3236+ NULL, /* help_doc */
3237+ },
3238+};
3239+
3240+/* See valprint.h. */
3241+
3242+gdb::option::option_def_group
3243+make_value_print_options_def_group (value_print_options *opts)
3244+{
3245+ return {{value_print_option_defs}, opts};
3246+}
3247+
30733248 void
30743249 _initialize_valprint (void)
30753250 {
@@ -3094,71 +3269,9 @@ Generic command for setting what things to print in \"raw\" mode."),
30943269 _("Generic command for showing \"print raw\" settings."),
30953270 &showprintrawlist, "show print raw ", 0, &showprintlist);
30963271
3097- add_setshow_uinteger_cmd ("elements", no_class,
3098- &user_print_options.print_max, _("\
3099-Set limit on string chars or array elements to print."), _("\
3100-Show limit on string chars or array elements to print."), _("\
3101-\"set print elements unlimited\" causes there to be no limit."),
3102- NULL,
3103- show_print_max,
3104- &setprintlist, &showprintlist);
3105-
3106- add_setshow_boolean_cmd ("null-stop", no_class,
3107- &user_print_options.stop_print_at_null, _("\
3108-Set printing of char arrays to stop at first null char."), _("\
3109-Show printing of char arrays to stop at first null char."), NULL,
3110- NULL,
3111- show_stop_print_at_null,
3112- &setprintlist, &showprintlist);
3113-
3114- add_setshow_uinteger_cmd ("repeats", no_class,
3115- &user_print_options.repeat_count_threshold, _("\
3116-Set threshold for repeated print elements."), _("\
3117-Show threshold for repeated print elements."), _("\
3118-\"set print repeats unlimited\" causes all elements to be individually printed."),
3119- NULL,
3120- show_repeat_count_threshold,
3121- &setprintlist, &showprintlist);
3122-
3123- add_setshow_boolean_cmd ("pretty", class_support,
3124- &user_print_options.prettyformat_structs, _("\
3125-Set pretty formatting of structures."), _("\
3126-Show pretty formatting of structures."), NULL,
3127- NULL,
3128- show_prettyformat_structs,
3129- &setprintlist, &showprintlist);
3130-
3131- add_setshow_boolean_cmd ("union", class_support,
3132- &user_print_options.unionprint, _("\
3133-Set printing of unions interior to structures."), _("\
3134-Show printing of unions interior to structures."), NULL,
3135- NULL,
3136- show_unionprint,
3137- &setprintlist, &showprintlist);
3138-
3139- add_setshow_boolean_cmd ("array", class_support,
3140- &user_print_options.prettyformat_arrays, _("\
3141-Set pretty formatting of arrays."), _("\
3142-Show pretty formatting of arrays."), NULL,
3143- NULL,
3144- show_prettyformat_arrays,
3145- &setprintlist, &showprintlist);
3146-
3147- add_setshow_boolean_cmd ("address", class_support,
3148- &user_print_options.addressprint, _("\
3149-Set printing of addresses."), _("\
3150-Show printing of addresses."), NULL,
3151- NULL,
3152- show_addressprint,
3153- &setprintlist, &showprintlist);
3154-
3155- add_setshow_boolean_cmd ("symbol", class_support,
3156- &user_print_options.symbol_print, _("\
3157-Set printing of symbol names when printing pointers."), _("\
3158-Show printing of symbol names when printing pointers."),
3159- NULL, NULL,
3160- show_symbol_print,
3161- &setprintlist, &showprintlist);
3272+ gdb::option::add_setshow_cmds_for_options
3273+ (class_support, &user_print_options, value_print_option_defs,
3274+ &setprintlist, &showprintlist);
31623275
31633276 add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
31643277 _("\
@@ -3192,20 +3305,4 @@ Without an argument, sets both radices back to the default value of 10."),
31923305 Show the default input and output number radices.\n\
31933306 Use 'show input-radix' or 'show output-radix' to independently show each."),
31943307 &showlist);
3195-
3196- add_setshow_boolean_cmd ("array-indexes", class_support,
3197- &user_print_options.print_array_indexes, _("\
3198-Set printing of array indexes."), _("\
3199-Show printing of array indexes"), NULL, NULL, show_print_array_indexes,
3200- &setprintlist, &showprintlist);
3201-
3202- add_setshow_zuinteger_unlimited_cmd ("max-depth", class_support,
3203- &user_print_options.max_depth, _("\
3204-Set maximum print depth for nested structures, unions and arrays."), _("\
3205-Show maximum print depth for nested structures, unions, and arrays."), _("\
3206-When structures, unions, or arrays are nested beyond this depth then they\n\
3207-will be replaced with either '{...}' or '(...)' depending on the language.\n\
3208-Use 'set print max-depth unlimited' to print the complete structure."),
3209- NULL, show_print_max_depth,
3210- &setprintlist, &showprintlist);
32113308 }
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -20,6 +20,8 @@
2020 #ifndef VALPRINT_H
2121 #define VALPRINT_H
2222
23+#include "cli/cli-option.h"
24+
2325 /* This is used to pass formatting options to various value-printing
2426 functions. */
2527 struct value_print_options
@@ -100,6 +102,11 @@ struct value_print_options
100102 int finish_print;
101103 };
102104
105+/* Create an option_def_group for the value_print options, with OPTS
106+ as context. */
107+extern gdb::option::option_def_group make_value_print_options_def_group
108+ (value_print_options *opts);
109+
103110 /* The global print options set by the user. In general this should
104111 not be directly accessed, except by set/show commands. Ordinary
105112 code should call get_user_print_options instead. */
@@ -233,8 +240,17 @@ struct format_data
233240 };
234241
235242 extern void print_command_parse_format (const char **expp, const char *cmdname,
236- struct format_data *fmtp);
237-extern void print_value (struct value *val, const struct format_data *fmtp);
243+ value_print_options *opts);
244+
245+/* Print VAL to console according to OPTS, including recording it to
246+ the history. */
247+extern void print_value (value *val, const value_print_options &opts);
248+
249+/* Completer for the "print", "call", and "compile print"
250+ commands. */
251+extern void print_command_completer (struct cmd_list_element *ignore,
252+ completion_tracker &tracker,
253+ const char *text, const char *word);
238254
239255 /* Given an address ADDR return all the elements needed to print the
240256 address in a symbolic form. NAME can be mangled or not depending