This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] Fix for thread apply
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: Re: [RFA] Fix for thread apply
- From: Michael Snyder <msnyder at redhat dot com>
- Date: Mon, 20 Nov 2000 16:13:48 -0800
- Newsgroups: cygnus.patches.gdb
- Organization: Red Hat, Inc.
- References: <20001108153302.A17473@redhat.com>
Christopher Faylor wrote:
>
> The problem below was suggested by a net contributor.
>
> Here is their description of the problem:
>
> There is a bug in the 'thread apply' command: it does not save
> the command string before switching the thread and executing
> the command on it. There effect is that when you do:
>
> thread apply all x/i $pc
>
> to disassemble one instruction for each thread, the PC is not
> changed between threads. This is because the first time the
> command is executed, the command string is modified and a \0
> is inserted before the '$pc'. Execution on other threads will
> then to a 'x/i' which means to use the previous disassembly
> position.
>
> The fix for this is pretty simple. Ok to apply?
Excuse the delay. The fix is approved, modulo your
discretion as to whether to use malloc or alloca.
Michael
>
> (A test suite addition to test for this problem is being prepared
> separately)
>
> cgf
>
> 2000-11-08 Christopher Faylor <cgf@redhat.com>
>
> * thread.c (thread_apply_all_command): Save the command before
> executing it because it may be modified. Restore the saved command so
> that the same command is executed on next thread.
> (thread_apply_command): Same correction.
>
> Index: thread.c
> ===================================================================
> RCS file: /cvs/uberbaum/gdb/thread.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 thread.c
> --- thread.c 2000/10/28 22:15:09 1.7
> +++ thread.c 2000/11/08 20:15:04
> @@ -517,6 +517,7 @@ thread_apply_all_command (char *cmd, int
> {
> struct thread_info *tp;
> struct cleanup *old_chain;
> + char *saved_cmd;
>
> if (cmd == NULL || *cmd == '\000')
> error ("Please specify a command following the thread ID list");
> @@ -527,9 +528,14 @@ thread_apply_all_command (char *cmd, int
> traversing it for "thread apply all". MVS */
> target_find_new_threads ();
>
> + /* Save a copy of the command in case it is clobbered by
> + execute_command */
> + saved_cmd = alloca (strlen (cmd) + 1);
> + strcpy (saved_cmd, cmd);
> for (tp = thread_list; tp; tp = tp->next)
> if (thread_alive (tp))
> {
> + struct cleanup *chain;
> switch_to_thread (tp->pid);
> #ifdef HPUXHPPA
> printf_filtered ("\nThread %d (%s):\n",
> @@ -540,6 +546,8 @@ thread_apply_all_command (char *cmd, int
> target_pid_to_str (inferior_pid));
> #endif
> execute_command (cmd, from_tty);
> +
> + strcpy (cmd, saved_cmd); /* Restore exact command used previously */
> }
>
> do_cleanups (old_chain);
> @@ -551,6 +559,7 @@ thread_apply_command (char *tidlist, int
> char *cmd;
> char *p;
> struct cleanup *old_chain;
> + char *saved_cmd;
>
> if (tidlist == NULL || *tidlist == '\000')
> error ("Please specify a thread ID list");
> @@ -562,6 +571,10 @@ thread_apply_command (char *tidlist, int
>
> old_chain = make_cleanup_restore_current_thread (inferior_pid);
>
> + /* Save a copy of the command in case it is clobbered by
> + execute_command */
> + saved_cmd = alloca (strlen (cmd) + 1);
> + strcpy (saved_cmd, cmd);
> while (tidlist < cmd)
> {
> struct thread_info *tp;
> @@ -608,6 +621,7 @@ thread_apply_command (char *tidlist, int
> target_pid_to_str (inferior_pid));
> #endif
> execute_command (cmd, from_tty);
> + strcpy (cmd, saved_cmd); /* Restore exact command used previously */
> }
> }
> }