• R/O
  • HTTP
  • SSH
  • HTTPS

提交列表

标签
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


users/palves/format_strings-experiment
RSS
Rev. 时间 作者
ebcc5fb users/palves/format_strings-experiment 2019-07-01 22:07:58 Pedro Alves

string_field

fd5bce2 2019-07-01 21:46:27 Pedro Alves

down with .ptr()

74899ce 2019-07-01 21:25:15 Pedro Alves

Eliminate %pN

de45ea7 2019-07-01 20:56:22 Pedro Alves

printf_filtered

a718b6a 2019-06-08 03:39:44 Tom Tromey

make %pS and %pN work again

8ffa2c8 2019-06-08 03:27:52 Tom Tromey

Switch more styled output to use %ps

ad89c43 2019-06-07 01:35:18 Tom Tromey

Remove the ui_out_style_kind enum

This also converts a few more spots to use %ps, just to try it out.

52bf843 2019-06-06 05:30:46 Pedro Alves

Introduce %ps / styled_string

8f1d863 2019-06-06 04:44:54 Pedro Alves

Support %pS / %pN for styling

bef6254 2019-06-05 17:17:16 Pedro Alves

Make ui_out::message support %pF, %pS, %pN

5141b4c 2019-06-05 07:30:03 Pedro Alves

NEWS and manual changes for command options changes

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

* NEWS (New commands): Mention "maint test-options
require-delimiter", "maint test-options unknown-is-error", "maint
test-options unknown-is-operand" and "maint show
test-options-completion-result".
(New command options, command completion): New section.
(Completion improvements): New section.
Mention that you can abbreviate "unlimited".

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

* gdb.texinfo (Command Completion): Mention command options too.
(Command Options): New node.
(Threads): Add anchors. Extend descriptions of the "taas" and
"tfaas" commands.
(Backtrace): Describe new options of the "backtrace" command. Add
anchors.
(Frame Apply): Describe new options of the "frame apply" and
"faas" commands. Add anchors.
(Data): Describe new options of the "print" command. Add anchors.
(Compiling and Injecting Code): Mention options of the "compile
print" command.
(Maintenance Commands): Mention "maint test-options" subcommands
and the "maint show test-options-completion-result" command.

6677510 2019-06-05 07:30:03 Pedro Alves

Delete parse_flags/parse_flags_qcs

Now that "thread/frame apply" have been converted to the gdb::option
framework, these functions are no longer used.

For a while, I thought about keeping the unit tests, by making a local
version of parse_flags_qcs in the unit tests file. But all that would
really test that is used by GDB itself, is the validate_flags_qcs
function. So in the end, I went through all the unit tests, and
converted any that wasn't already covered to gdb.base/options.exp
tests. And those have all already been added in previous patches.

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

* cli/cli-utils.c (parse_flags, parse_flags_qcs): Delete.
* cli/cli-utils.h (parse_flags, parse_flags_qcs): Delete.
* unittests/cli-utils-selftests.c (test_parse_flags)
(test_parse_flags_qcs): Delete.
(test_cli_utils): Don't call deleted functions.

88efc23 2019-06-05 07:30:03 Pedro Alves

Make "thread apply" use the gdb::option framework

Similarly to the "frame apply" patch, this makes the "thread apply"
family of commands -- "thread apply TID", "thread apply all" and
"taas" use the gdb::option framework for '-'-style options.

No new options are added, but there are some user-visible changes:

- Can now abbreviate and complete "-ascending"

- We now have a completer for "thread apply" commands

Can now complete options ("thread apply all -[TAB]"), and also,
'thread apply all COMMAND[TAB]' now does what you'd expect, by
making use of the new complete_command routine.

- "help" output tweaked with auto-generated option descriptions:

~~~
Usage: thread apply all [OPTION]... COMMAND
Prints per-inferior thread number and target system's thread id
followed by COMMAND output.

By default, an error raised during the execution of COMMAND
aborts "thread apply".

Options:
-ascending
Call COMMAND for all threads in ascending order.
The default is descending order.

-q
Disables printing the thread information.

-c
Print any error raised by COMMAND and continue.

-s
Silently ignore any errors or empty output produced by COMMAND.
~~~

The "By default ..." sentence is new as well.

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

* thread.c: Include "cli/cli-option.h".
(tp_array_compar_ascending): Global.
(tp_array_compar): Delete function.
(tp_array_compar_ascending, tp_array_compar_descending): New
functions.
(ascending_option_def, qcs_flag_option_def)
(thr_qcs_flags_option_defs)
(make_thread_apply_all_options_def_group)
(make_thread_apply_options_def_group): New.
(thread_apply_all_command): Use gdb::option::process_options.
(thread_apply_command_completer)
(thread_apply_all_command_completer): New.
(thread_apply_command): Use gdb::option::process_options.
(_initialize_thread): Delete THREAD_APPLY_FLAGS_HELP, replace it
with a new THREAD_APPLY_OPTION_HELP. Use gdb::option::build_help
to generate help text of "thread apply". Adjust "taas"'s help.
* tid-parse.c (tid_range_parser::in_thread_range): New method.
* tid-parse.h (tid_range_parser::in_thread_range): New method.

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

* gdb.base/options.exp (test-thread-apply): New.
(top level): Call it.

e76fa16 2019-06-05 07:30:03 Pedro Alves

"thread apply 1 -- -" vs "frame apply level 0 -- -"

With the following patch, we'll be able to explicitly tell "thread
apply" where options end, using the "--" delimiter. A test added by
that patch caught a pre-existing inconsistency:

(gdb) thread apply 1 -- -
Invalid thread ID: -

(gdb) frame apply level 0 -- -
#0 main () at threads.c:55
Cannot enable the TUI when output is not a terminal

Above, "thread apply" did not try to run the command, while "frame
apply level" did. ("-" is a valid TUI command.)

That "-" is past "--", so it should have not been confused with an
invalid TID, in the "thread apply" case.

That error actually doesn't come from the TID parser, but instead from
thread_apply_command directly.

So that error/check needs tweaking. The next question is what to
tweak it to.

"-" is actually a valid TUI command:

(gdb) help -
Scroll window backward.
Usage: - [WIN] [N]

(gdb) frame apply level 0 -- -
#0 main () at threads.c:55
Cannot enable the TUI when output is not a terminal

While I don't imagine it being useful to use that "-" command with
"thread apply" or "frame apply level", the fact is that you can use it
with "frame apply level", but not with "thread apply". And since it's
an actual command, pedantically it seems right to allow it.

That's what this commit does.

Note: simply removing the "isalpha" check regresses
gdb.multi/tids.exp -- see related commit 3f5b7598805c.

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

* thread.c (thread_apply_command): Check for invalid TID with
isdigit instead of !isalpha.

9bec608 2019-06-05 07:30:03 Pedro Alves

Make "frame apply" support -OPT options

This adds support for '-'-style options to the "frame apply" family of
commands -- "frame apply COUNT", "frame apply level", "frame apply
all", "faas" and "tfaas".

The -q/-c/-s flags were already supported, -past-main/-past-entry is
new:

~~~
(gdb) help frame apply all
Apply a command to all frames.

Usage: frame apply all [OPTION]... COMMAND
Prints the frame location information followed by COMMAND output.

By default, an error raised during the execution of COMMAND
aborts "frame apply".

Options:
-q
Disables printing the frame location information.

-c
Print any error raised by COMMAND and continue.

-s
Silently ignore any errors or empty output produced by COMMAND.

-past-main [on|off]
Set whether backtraces should continue past "main".
Normally the caller of "main" is not of interest, so GDB will terminate
the backtrace at "main". Set this if you need to see the rest
of the stack trace.

-past-entry [on|off]
Set whether backtraces should continue past the entry point of a program.
Normally there are no callers beyond the entry point of a program, so GDB
will terminate the backtrace there. Set this if you need to see
the rest of the stack trace.
~~~

TAB completion of options is now supported. Also, TAB completion of
COMMAND in "frame apply all COMMAND" does the right thing now, making
use of complete_command, added by the previous patch. E.g.:

(gdb) thread apply all -ascending frame apply all -past-main print -[TAB]
-address -elements -pretty -symbol
-array -null-stop -repeats -union
-array-indexes -object -static-members -vtbl
(gdb) thread apply all -ascending frame apply all -past-main print glo[TAB]
global1 global2

The change to tfaas_command is necessary because otherwise you get
this:

(gdb) tfaas --
Unrecognized option at: frame apply all -s --

That's because the above is equivalent to:

(gdb) thread apply all -s frame apply all -s --

and the "--" instructs "thread apply" to consider everything up to
"--" as its command options. And from that view, "frame" is an
invalid option.

The change makes tfaas be equivalent to:

(gdb) thread apply all -s -- frame apply all -s --

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

* cli/cli-utils.c (parse_flags_qcs): Use validate_flags_qcs.
(validate_flags_qcs): New.
* cli/cli-utils.h (struct qcs_flags): Change field types to int.
(validate_flags_qcs): Declare.
* stack.c (qcs_flag_option_def, fr_qcs_flags_option_defs): New.
(make_frame_apply_options_def_group): New.
(frame_apply_command_count): Process options with
gdb::option::process_options.
(frame_apply_completer): New.
(frame_apply_level_completer, frame_apply_all_completer)
(frame_apply_completer): New.
(_initialize_stack): Update help of "frame apply", "frame apply
level", "frame apply all" and "faas" to mention supported options
and install command completers.
* stack.h (frame_apply_all_completer): Declare.
* thread.c: Include "stack.h".
(tfaas_command): Add "--".
(_initialize_thread): Update help "tfaas" to mention supported
options and install command completer.

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

* gdb.base/options.exp (test-frame-apply): New.
(top level): Test print commands with different "frame apply"
prefixes.

b40116b 2019-06-05 07:30:03 Pedro Alves

Introduce complete_nested_command_line

This adds a completion helper routine that makes it possible for a
command that takes another command as argument, such as "frame apply
all COMMAND" as "thread apply all COMMAND", to complete on COMMAND,
and have the completion machinery recurse and complete COMMAND as if
you tried to complete "(gdb) COMMAND". I.e., we'll be able to
complete like this, for example:

(gdb) thread apply all -[TAB]
-c -ascending -q -s
(gdb) thread apply all -ascending frame apply all -[TAB]
-c -limit -past-entry -past-main -q -s
(gdb) thread apply all -ascending frame apply all -past-main print -[TAB]
-address -elements -pretty -symbol
-array -null-stop -repeats -union
-array-indexes -object -static-members -vtbl
(gdb) thread apply all -ascending frame apply all -past-main print glo[TAB]
global1 global2

Above, the completer function understands that "thread apply all" is a
command, and then parses "-ascending" successfully and understand that
the rest of the string is "thread apply all"'s operand. And then, the
process repeats for the "frame apply" command, and on and on.

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

* completer.c (complete_nested_command_line): New.
(gdb_completion_word_break_characters_throw): Add assertion.
* completer.h (complete_nested_command_line): Declare.

9e835ee 2019-06-05 07:30:03 Pedro Alves

lib/completion-support.exp: Add test_gdb_completion_offers_commands

This adds a procedure to the collection of completion-testing
routines, that allows checking whether completion offers all commands
as completion candidates. This will be used for testing completing
"frame apply all [TAB]", "thread apply all [TAB]", etc.

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

* lib/completion-support.exp (test_gdb_complete_tab_multiple)
(test_gdb_complete_cmd_multiple, test_gdb_complete_multiple): Add
'max_completions' parameter and handle it.
(test_gdb_completion_offers_commands): New.

e62ef76 2019-06-05 07:30:03 Pedro Alves

"backtrace full/no-filters/hide" completer

"backtrace"'s completer now completes on command options:

(gdb) bt -[TAB]
-entry-values -full -no-filters -past-main
-frame-arguments -hide -past-entry -raw-frame-arguments

But it doesn't know how to complete on qualifiers:

(gdb) bt fu[TAB]
funlockfile futimens futimes.c
funlockfile.c futimens.c futimesat
futex-internal.h futimes futimesat.c

This commit fixes that:

(gdb) bt fu[TAB]ll
(gdb) bt n[TAB]o-filters
(gdb) bt h[TAB]ide

I considered teaching the gdb::option framework to handle non-'-'
options, but decided it wasn't worth it for this special case, and I'd
rather not make it easy to add new qualifier-like options.

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

* stack.c (parse_backtrace_qualifiers): New.
(backtrace_command): Use it.
(backtrace_command_completer): Complete on qualifiers.

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

* gdb.base/options.exp (test-backtrace): Test completing qualifiers.

9c89342 2019-06-05 07:30:03 Pedro Alves

Make "backtrace" support -OPT options

This adds support for comand options to the "backtrace" command. We'll get:

(gdb) bt -
-entry-values -hide -past-main
-frame-arguments -no-filters -raw-frame-arguments
-full -past-entry

~~~~
(gdb) help backtrace
Print backtrace of all stack frames, or innermost COUNT frames.
Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT]

Options:
-entry-values no|only|preferred|if-needed|both|compact|default
Set printing of function arguments at function entry
GDB can sometimes determine the values of function arguments at entry,
in addition to their current values. This option tells GDB whether
to print the current value, the value at entry (marked as val@entry),
or both. Note that one or both of these values may be <optimized out>.

-frame-arguments all|scalars|none
Set printing of non-scalar frame arguments

-raw-frame-arguments [on|off]
Set whether to print frame arguments in raw form.
If set, frame arguments are printed in raw form, bypassing any
pretty-printers for that value.

-past-main [on|off]
Set whether backtraces should continue past "main".
Normally the caller of "main" is not of interest, so GDB will terminate
the backtrace at "main". Set this if you need to see the rest
of the stack trace.

-past-entry [on|off]
Set whether backtraces should continue past the entry point of a program.
Normally there are no callers beyond the entry point of a program, so GDB
will terminate the backtrace there. Set this if you need to see
the rest of the stack trace.

-full
Print values of local variables.

-no-filters
Prohibit frame filters from executing on a backtrace.

-hide
Causes Python frame filter elided frames to not be printed.

For backward compatibility, the following qualifiers are supported:

full - same as -full option.
no-filters - same as -no-filters option.
hide - same as -hide.

With a negative COUNT, print outermost -COUNT frames.
~~~~

Implementation wise, this:

- Moves relevant options/settings globals to structures.
- Tweaks a number of functions to pass down references to such structures.
- Adds option_def structures describing the options/settings.
- Makes backtrace_command parse the options, with gdb::option::process_options.
- Tweaks "backtrace"'s help to describe the new options.
- Adds testcases.

Note that backtrace is a PROCESS_OPTIONS_UNKNOWN_IS_OPERAND command,
because of the "-COUNT" argument.

The COUNT/-COUNT argument is currently parsed as an expression. I
considered whether it would be prudent here to require "--", but
concluded that the risk of causing a significant breakage here is much
lower compared to "print", since printing the expression is not the
whole point of the "backtrace" command. Seems OK to me to require
typing "backtrace -past-main -- -p" if the user truly wants to refer
to the negative of a backtrace count stored in an inferior variable
called "p".

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

* frame.c: Include "cli/cli-option.h.
(user_set_backtrace_options): New.
(backtrace_past_main, backtrace_past_entry, backtrace_limit):
Delete.
(get_prev_frame): Adjust.
(boolean_option_def, uinteger_option_def)
(set_backtrace_option_defs): New.
(_initialize_frame): Adjust and use
gdb::option::add_setshow_cmds_for_options to install "set
backtrace past-main" and "set backtrace past-entry".
* frame.h: Include "cli/cli-option.h".
(struct frame_print_options): Forward declare.
(print_frame_arguments_all, print_frame_arguments_scalars)
(print_frame_arguments_none): Declare.
(print_entry_values): Delete declaration.
(struct frame_print_options, user_frame_print_options): New.
(struct set_backtrace_options): New.
(set_backtrace_option_defs, user_set_backtrace_options): Declare.
* mi/mi-cmd-stack.c (mi_cmd_stack_list_frames)
(mi_cmd_stack_list_locals, mi_cmd_stack_list_args)
(mi_cmd_stack_list_variables): Pass down USER_FRAME_PRINT_OPTIONS.
(list_args_or_locals): Add frame_print_options parameter.
(mi_cmd_stack_info_frame): Pass down USER_FRAME_PRINT_OPTIONS.
* python/py-framefilter.c (enumerate_args): Pass down
USER_FRAME_PRINT_OPTIONS.
* stack.c: Include "cli/cli-option.h".
(print_frame_arguments_all, print_frame_arguments_scalars)
(print_frame_arguments_none): Declare.
(print_raw_frame_arguments, print_entry_values): Delete.
(user_frame_print_options): New.
(boolean_option_def, enum_option_def, frame_print_option_defs):
New.
(struct backtrace_cmd_options): New.
(bt_flag_option_def): New.
(backtrace_command_option_defs): New.
(print_stack_frame): Pass down USER_FRAME_PRINT_OPTIONS.
(print_frame_arg, read_frame_arg, print_frame_args)
(print_frame_info, print_frame): Add frame_print_options parameter
and use it.
(info_frame_command_core): Pass down USER_FRAME_PRINT_OPTIONS.
(backtrace_command_1): Add frame_print_options and
backtrace_cmd_options parameters and use them.
(make_backtrace_options_def_group): New.
(backtrace_command): Process command options with
gdb::option::process_options.
(backtrace_command_completer): New.
(_initialize_stack): Extend "backtrace"'s help to mention
supported options. Install completer for "backtrace".
Install some settings commands with add_setshow_cmds_for_options.

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

* gdb.base/options.exp (test-backtrace): New.
(top level): Call it.

8ef80d1 2019-06-05 07:30:02 Pedro Alves

"set print raw frame-arguments" -> "set print raw-frame-arguments"

A following patch will introduce options for the "backtrace" command,
based on some "set print" and "set backtrace" settings. There's one
setting in particular that is a bit annoying if we want to describe
the backtrace options and the settings commands using the same data
structures:

"set print raw frame-arguments"

The problem is that space between "raw" and "frame-arguments".

Calling the option

"bt -raw frame-arguments"

would be odd. So I'm calling the option

"bt -raw-frame-arguments"

instead.

And for consistency, this patch renames the set/show commands to:

"set print raw-frame-arguments"
"show print raw-frame-arguments"

I.e., dash instead of space. The old commands are left in place, but
marked deprecated.

We need to adjust a couple testcases, because the relevant tests use
gdb_test_no_output and the old commands are no longer silent:

(gdb) set print raw frame-arguments on
Warning: command 'set print raw frame-arguments' is deprecated.
Use 'set print raw-frame-arguments'.

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

* NEWS (Changed commands): Mention set/show print raw-frame-arguments,
and that "set/show print raw frame-arguments" are now deprecated.

* cli/cli-decode.c (add_setshow_boolean_cmd): Now returns the
command.
* command.h (add_setshow_boolean_cmd): Return cmd_list_element *.
* stack.c (_initialize_stack): Install "set/show print
raw-frame-arguments", and deprecate "set/show print raw
frame-arguments".
* valprint.c (_initialize_valprint): Deprecate "set/show print
raw".

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

* gdb.texinfo (Print Settings): Document "set/show print
raw-frame-arguments" instead of "set/show print raw
frame-arguments".

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

* gdb.guile/scm-frame-args.exp: Use "set print
raw-frame-arguments" instead of "set print raw frame-arguments".
* gdb.python/py-frame-args.exp: Likewise.

1b45440 2019-06-05 07:30:02 Pedro Alves

Migrate rest of compile commands to new options framework

As I was in the neighbourhood, I converted the other "compile"
subcommands to the new options framework too. Specifically, "compile
code" and "compile file".

The user-visible changes are:

- All abbreviations of "-raw" are accepted now, instead of just -r.
Obviously that means "-ra" is now accepted.

- Option completion now works.

- "compile file" did not have a completer yet, and now it knows to
complete on filenames.

- You couldn't use "compile file" with a file named "-something".
You can now, with "compile file -- -something".

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

* compile/compile.c (struct compile_options): New.
(compile_flag_option_def, compile_command_option_defs)
(make_compile_options_def_group): New.
(compile_file_command): Handle options with
gdb::option::process_options.
(compile_file_command_completer): New function.
(compile_code_command): Handle options with
gdb::option::process_options.
(compile_code_command_completer): New function.
(_initialize_compiler): Install completers for "compile code" and
"compile file". Mention available options in "compile code" and
"compile code"'s help.
* completer.c (advance_to_completion_word): New, factored out from
...
(advance_to_expression_complete_word_point): ... this.
(advance_to_filename_complete_word_point): New.
* completer.h (advance_to_filename_complete_word_point): New
declaration.

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

* gdb.compile/compile.exp: Adjust expected output to option
processing changes.

55ff4e3 2019-06-05 07:30:02 Pedro Alves

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".

b6b79e4 2019-06-05 07:30:02 Pedro Alves

Introduce generic command options framework

This commit adds a generic command options framework, that makes it
easy enough to add '-'-style options to commands in a uniform way,
instead of each command implementing option parsing in its own way.

Options are defined in arrays of option_def objects (for option
definition), and the same options definitions are used for supporting
TAB completion, and also for generating the relevant help fragment of
the "help" command. See the gdb::options::build_help function, which
returns a string with the result of replacing %OPTIONS% in a template
string with an auto-generated "help" string fragment for all the
passed-in options.

Since most options in GDB are in the form of "-OPT", with a single
dash, this is the format that the framework supports.

I like to think of gdb's "-OPT" as the equivalent to getopt's long
options format ("--OPT"), and gdb's "/" as the equivalent to getopt's
short options format. getopt's short options format allows mixing
several one-character options, like "ls -als", kind of similar to
gdb's "x /FMT" and "disassemble /MOD", etc. While with gdb's "-"
options, the option is expected to have a full name, and to be
abbreviatable. E.g., "watch -location", "break -function main", etc.

This patch only deals with "-" options. The above comment serves more
to disclose why I don't think we should support mixing several
unrelated options in a single "-" option invocation, like "thread
apply -qcs" instead of "thread apply -q -c -s".

The following patches will add uses of the infrastructure to several
key commands. Most notably, "print", "compile print", "backtrace",
"frame apply" and "thread apply". I tried to add options to several
commands in order to make sure the framework didn't leave that many
open holes open.

Options use the same type as set commands -- enum var_types. So
boolean options are var_boolean, enum options are var_enum, etc. The
idea is to share code between settings commands and command options.
The "print" options will be based on the "set print" commands, and
their names will be the same. Actually, their definitions will be the
same too. There is a function to create "set/show" commands from an
array for option definitions:

/* Install set/show commands for options defined in OPTIONS. DATA is
a pointer to the structure that holds the data associated with the
OPTIONS array. */
extern void add_setshow_cmds_for_options (command_class cmd_class, void *data,
gdb::array_view<const option_def> options,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list);

That will be used by several following patches.

Other features:

- You can use the "--" delimiter to explicitly indicate end of
options. Several existing commands use this token sequence for
this effect already, so this just standardizes it.

- You can shorten option names, as long as unambiguous. Currently,
some commands allow this (e.g., break -function), while others do
not (thread apply all -ascending). As GDB allows abbreviating
command names and other things, it feels more GDB-ish to allow
abbreviating option names too, to me.

- For boolean options, 0/1 stands for off/on, just like with boolean
"set" commands.

- For boolean options, "true" is implied, just like with boolean "set
commands.

These are the option types supported, with a few examples:

- boolean options (var_boolean). The option's argument is optional.

(gdb) print -pretty on -- *obj
(gdb) print -pretty off -- *obj
(gdb) print -p -- *obj
(gdb) print -p 0 -- *obj

- flag options (like var_boolean, but no option argument (on/off))

(gdb) thread apply all -s COMMAND

- enum options (var_enum)

(gdb) bt -entry-values compact
(gdb) bt -e c

- uinteger options (var_uinteger)

(gdb) print -elements 100 -- *obj
(gdb) print -e 100 -- *obj
(gdb) print -elements unlimited -- *obj
(gdb) print -e u -- *obj

- zuinteger-unlimited options (var_zuinteger_unlimited)

(gdb) print -max-depth 100 -- obj
(gdb) print -max-depth -1 -- obj
(gdb) print -max-depth unlimited -- obj

Other var_types could be supported, of course. These were just the
types that I needed for the commands that I ported over, in the
following patches.

It was interesting (and unfortunate) to find that we need at least 3
different modes to cover the existing commands:

- Commands that require ending options with "--" if you specify any
option: "print" and "compile print".

- Commands that do not want to require "--", and want to error out if
you specify an unknown option (i.e., an unknown argument that starts
with '-'): "compile code" / "compile file".

- Commands that do not want to require "--", and want to process
unknown options themselves: "bt", because of "bt -COUNT",
"thread/frame apply", because "-" is a valid command.

The different behavior is encoded in the process_options_mode enum,
passed to process_options/complete_options.

For testing, this patch adds one representative maintenance command
for each of the process_options_mode values, that are used by the
testsuite to exercise the options framework:

(gdb) maint test-options require-delimiter
(gdb) maint test-options unknown-is-error
(gdb) maint test-options unknown-is-operand

and adds another command to help with TAB-completion testing:

(gdb) maint show test-options-completion-result

See their description at the top of the maint-test-options.c file.

Docs/NEWS are in a patch later in the series.

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

* Makefile.in (SUBDIR_CLI_SRCS): Add cli/cli-option.c.
(COMMON_SFILES): Add maint-test-settings.c.
* cli/cli-decode.c (boolean_enums): New global, factored out from
...
(add_setshow_boolean_cmd): ... here.
* cli/cli-decode.h (boolean_enums): Declare.
* cli/cli-option.c: New file.
* cli/cli-option.h: New file.
* cli/cli-setshow.c (parse_cli_boolean_value(const char **)): New,
factored out from ...
(parse_cli_boolean_value(const char *)): ... this.
(is_unlimited_literal): Change parameter type to pointer to
pointer. Adjust and advance ARG pointer.
(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
(parse_cli_var_enum): New, factored out from ...
(do_set_command): ... this. Adjust.
* cli/cli-setshow.h (parse_cli_boolean_value)
(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
(parse_cli_var_enum): Declare.
* cli/cli-utils.c: Include "cli/cli-option.h".
(get_ulongest): New.
* cli/cli-utils.h (get_ulongest): Declare.
(check_for_argument): New overloads.
* maint-test-options.c: New file.

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

* gdb.base/options.c: New file.
* gdb.base/options.exp: New file.

ecbe3a0 2019-06-05 07:30:02 Pedro Alves

number_or_range_parser::get_number, don't treat "1 -" as a range

While adding -OPT options to "frame apply level", I noticed that:

(gdb) frame apply level 0 -[TAB]

wasn't completing on the supported options. This commit fixes it.
We'll get instead:

(gdb) frame apply level 0 -
-c -past-entry -past-main -q -s

I added the isspace check because this case:

(gdb) frame apply level 0-

can't be an option.

Tests for this will be in a new gdb.base/options.exp file, in a
following patch. It will exercise all of:

(gdb) frame apply level 0-
(gdb) frame apply level 0 -
(gdb) frame apply level 0 --
(gdb) frame apply level 0 -- -

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

* cli/cli-utils.c (number_or_range_parser::get_number): Do not
parse a range if "-" is at the end of the string.

683f7a0 2019-06-05 07:30:02 Pedro Alves

boolean/auto-boolean commands, make "o" ambiguous

We currently accept "o" with boolean/auto-boolean commands, taking it
to mean "on". But "o" is ambiguous, between "on" and "off". I can't
imagine why assuming the user wanted to type "on" is a good idea, it
might have been a typo.

This commit makes gdb error out. We now get:

(gdb) maint test-settings set boolean o
"on" or "off" expected.

(gdb) maint test-settings set auto-boolean o
"on", "off" or "auto" expected.

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

* cli/cli-setshow.c (parse_auto_binary_operation)
(parse_cli_boolean_value): Don't allow "o".

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

* gdb.base/settings.exp (test-boolean, test-auto-boolean): Check
that "o" is ambiguous.

f388890 2019-06-05 07:30:02 Pedro Alves

New set/show testing framework (gdb.base/settings.exp)

This commit adds new representative commands for all types of settings
commands supported by gdb (enum var_types), and then uses them to
exercise settings parsing and completion.

(gdb) maint test-settings s[TAB]
set show

(gdb) maint test-settings set [TAB]
auto-boolean integer uinteger
boolean optional-filename zinteger
enum string zuinteger
filename string-noescape zuinteger-unlimited

(gdb) maint test-settings set enum [TAB]
xxx yyy zzz

etc.

This is basically unit testing, except that it goes fully via GDB. It
must be done this way in order to exercise TAB completion properly,
which must go via readline.

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

* Makefile.in (COMMON_SFILES): Add maint-test-settings.c.
* NEWS: Mention maint test-settings KIND.
* maint-test-settings.c: New file.

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

* gdb.texinfo (Maintenance Commands): Document "maint
test-settings" commands.

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

* gdb.base/settings.c: New file.
* gdb.base/settings.exp: New file.

c2cdb71 2019-06-05 07:30:02 Pedro Alves

gdb.base/completion.exp: Fix comment typo

Noticed this while writing the following patch. We cd to $srcdir, not $objdir.

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

* gdb.base/completion.exp: Fix comment typo.

4965a4a 2019-06-05 07:30:02 Pedro Alves

Remove "show" command completers, "set" command completers for string commands

The default command completer is symbol_completer, but it makes no
sense for a "show" command to complete on symbols, or anything else,
really.

I wonder whether we should instead make the default be no completer.
That seems like a much larger/complicated audit/change, so I'd like to
move forward with this version, as it'll be covered by tests. I
noticed this because a following patch will add a new
gdb.base/settings.exp testcase that exercises all sorts of details of
settings commands, including completing the show commands, using new
representative "maint test-settings <type or settings command>"
commands.

Also remove the completer for var_string and var_string_noescape
commands. No point in completing symbols when GDB is expecting a
string.

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

* cli/cli-decode.c (add_setshow_cmd_full): Remove "show"
completer.
(add_setshow_string_cmd, add_setshow_string_noescape_cmd): Remove
"set" completers.

d0e8b2c 2019-06-05 07:22:42 Pedro Alves

Fix "set enum-command value junk"

With enum commands, we currently fail to notice junk after the value.

Currently:

(gdb) set print entry-values compact foo
(gdb) show print entry-values foo
Printing of function arguments at function entry is "compact".

After this fix:

(gdb) set print entry-values compact foo
Junk after item "compact": foo

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

* cli/cli-setshow.c (do_set_command) <var_enum>: Detect junk
after item.

bd30787 2019-06-05 07:22:42 Pedro Alves

Allow "unlimited" abbreviations

Currently we can abbreviate "on/off/enable/disable/yes/no" in boolean
settings,

(gdb) set non-stop of
(gdb) set non-stop en

we can abbreviate the items of enumeration commands,

(gdb) set print frame-arguments scal
(gdb) set scheduler-locking rep

but we cannot abbreviate "unlimited" in integer commands.

(gdb) set print elements u
No symbol "u" in current context.

This commit fixes that.

Testcases will be in gdb.base/settings.exp and gdb.base/options.exp,
in following patches.

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

* cli/cli-setshow.c (is_unlimited_literal): Allow abbreviations.