[PATCH][fix for gdb/15853] 'thread apply all inetrrupt&' shows inefficiency on remote targets
Muhammad Bilal
mbilal@codesourcery.com
Wed Sep 4 12:35:00 GMT 2013
On 08/27/2013 07:00 PM, Muhammad Bilal wrote:
> Hi,
> While I was playing with non-stop thread debugging, I have observed that.
>
> In the case of 'interrupt -a&' command gdb sends only one packet to
> stop all threads as $vCont;t#b9...
>
> But in case of 'thread apply all interrupt&' GDB issues individual
> packet for each thread.I think that In non-stop mode
> 'interrupt -a&' and 'thread apply all interrupt&' commands are equals
> but time efficiency of later command is less.
>
> Also,
>
> If user issues a command like 'thread apply all interrupt -a&'
> GDB accepts it and GDB will stop all threads on first vcount;t
> packets but due to loops iteration on all threads,
> GDB sends vcount;t packet for all remaining threads although GDB has
> already stop all thread so IMO it is a bug.
>
>
> 2013-08-28 Muhammad Bilal <mbilal@codesourcery.com>
>
> PR gdb/15853
> * thread.c (thread_apply_all_command): Lookup 'interrupt' command
> using 'lookup_cmd_composition', 'find_command_name_length'
> functions and execute single command for all threads.
> * infcmd.c (interrupt_target_command): Issue a warning on
> 'thread apply all interrupt -a&' command.
> (interrupt_all_threads): Define as global.
> (all_threads): Removed.
> * inferior.h (interrupt_all_threads): Declare.
> * cli/cli-decode.c (find_cmd): Change definition from
> static to global.
> (lookup_cmd_composition): Check command ambiguousness
> with 'nfound' instead of CMD_LIST_AMBIGUOUS.
> * command.h (find_command_name_length): Declare.
> ---
> gdb/cli/cli-decode.c | 4 ++--
> gdb/command.h | 2 ++
> gdb/infcmd.c | 13 +++++++++----
> gdb/inferior.h | 3 +++
> gdb/thread.c | 15 +++++++++++++++
> 5 files changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
> index 2fdd9e4..a1a3510 100644
> --- a/gdb/cli/cli-decode.c
> +++ b/gdb/cli/cli-decode.c
> @@ -1232,7 +1232,7 @@ find_cmd (const char *command, int len, struct
> cmd_list_element *clist,
> return found;
> }
>
> -static int
> +int
> find_command_name_length (const char *text)
> {
> const char *p = text;
> @@ -1729,7 +1729,7 @@ lookup_cmd_composition (const char *text,
> *cmd = find_cmd (command, len, cur_list, 1, &nfound);
> }
>
> - if (*cmd == CMD_LIST_AMBIGUOUS)
> + if (nfound > 1)CMD_LIST_AMBIGUOUS
> {
> return 0; /* ambiguous */
> }
> diff --git a/gdb/command.h b/gdb/command.h
> index 81edc43..83040a3 100644
> --- a/gdb/command.h
> +++ b/gdb/command.h
> @@ -397,4 +397,6 @@ extern int cmd_func_p (struct cmd_list_element *cmd);
> extern void cmd_func (struct cmd_list_element *cmd,
> char *args, int from_tty);
>
> +extern int find_command_name_length (const char *text);
> +
> #endif /* !defined (COMMAND_H) */
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index 154cde2..9bc0999 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -2776,23 +2776,28 @@ interrupt_target_1 (int all_threads)
> if the `-a' switch is used. */
>
> /* interrupt [-a] */
> +int interrupt_all_threads = 0;
> static void
> interrupt_target_command (char *args, int from_tty)
> {
> if (target_can_async_p ())
> {
> - int all_threads = 0;
>
> dont_repeat (); /* Not for the faint of heart. */
>
> if (args != NULL
> && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
> - all_threads = 1;
> + {
> + if (interrupt_all_threads)
> + error (_("-a is meaningless in thread apply all command."));
> + interrupt_all_threads = 1;
> + }
>
> - if (!non_stop && all_threads)
> + if (!non_stop && interrupt_all_threads)
> error (_("-a is meaningless in all-stop mode."));
>
> - interrupt_target_1 (all_threads);
> + interrupt_target_1 (interrupt_all_threads);
> + interrupt_all_threads = 0;
> }
> }
>
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index 2a5770d..464511a 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -128,6 +128,9 @@ extern int detach_fork;
> system's address space randomization feature when starting an
> inferior. */
> extern int disable_randomization;
>
> +/* If set, in non_stop 'interrupt' command will be apply on all
> threads. */
> +extern int interrupt_all_threads;
> +
> extern void generic_mourn_inferior (void);
>
> extern void terminal_save_ours (void);
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 78851e4..fea6aed 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -1216,6 +1216,9 @@ thread_apply_all_command (char *cmd, int from_tty)
> char *saved_cmd;
> int tc;
> struct thread_array_cleanup ta_cleanup;
> + struct cmd_list_element *alias = NULL;
> + struct cmd_list_element *prefix_cmd = NULL;
> + struct cmd_list_element *command = NULL;
>
> if (cmd == NULL || *cmd == '\000')
> error (_("Please specify a command following the thread ID list"));
> @@ -1224,6 +1227,18 @@ thread_apply_all_command (char *cmd, int from_tty)
>
> old_chain = make_cleanup_restore_current_thread ();
>
> + /* If there is 'interrupt' command in non-stop mode. */
> + if (non_stop
> + && lookup_cmd_composition (cmd, &alias, &prefix_cmd, &command)
> + && !strncmp (cmd, "interrupt", find_command_name_length(cmd)))
> + {
> + interrupt_all_threads = 1;
> + execute_command (cmd, from_tty);
> + do_cleanups (old_chain);
> + interrupt_all_threads = 0;
> + return;
> + }
> +
> /* Save a copy of the command in case it is clobbered by
> execute_command. */
> saved_cmd = xstrdup (cmd);
ping
Thanks,
-Bilal
More information about the Gdb-patches
mailing list