Make "thread apply" use the gdb::option framework
authorPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:06:54 +0000 (00:06 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:23:25 +0000 (00:23 +0100)
commit6665660a411ead049daa85cac5c629d637e22044
tree7a28a95777f94ced2128db5f8fd0067021eda951
parentf7e13587eaf1e2d433e21ac0a9e413a98e53652d
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:
2019-06-13  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:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp (test-thread-apply): New.
(top level): Call it.
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/options.exp
gdb/thread.c
gdb/tid-parse.c
gdb/tid-parse.h