This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] Fix for thread apply
- To: gdb-patches at sources dot redhat dot com
- Subject: [RFA] Fix for thread apply
- From: Christopher Faylor <cgf at redhat dot com>
- Date: Wed, 8 Nov 2000 15:33:02 -0500
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?
(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 */
}
}
}