This is the mail archive of the
rda@sourceware.org
mailing list for the rda project.
[commit] Fix thread related problem for am33 software singlestep
- From: Kevin Buettner <kevinb at redhat dot com>
- To: rda at sources dot redhat dot com
- Date: Tue, 8 Nov 2005 19:10:41 -0700
- Subject: [commit] Fix thread related problem for am33 software singlestep
- Organization: Red Hat
I've just committed the patch below. As indicated by the ChangeLog message,
the am33 software singlestep code was occasionally trying to use the pid
associated with an already running thread for accessing memory. The
associated ptrace() call would fail when this was attempted.
* linux-target.c (am33_singlestep_okay): Use `pid', not
`process->pid' when reading and writing memory since the
latter may refer to an already running thread.
Index: linux-target.c
===================================================================
RCS file: /cvs/src/src/rda/unix/linux-target.c,v
retrieving revision 1.20
diff -u -p -r1.20 linux-target.c
--- linux-target.c 8 Nov 2005 21:58:36 -0000 1.20
+++ linux-target.c 8 Nov 2005 22:19:39 -0000
@@ -3694,6 +3694,7 @@ am33_singlestep (struct gdbserv *serv, p
int displ;
static char bp_inst = 0xff;
static int hw_singlestep_okay = 1;
+ pid_t save_pid;
if (hw_singlestep_okay)
{
@@ -3719,6 +3720,12 @@ am33_singlestep (struct gdbserv *serv, p
/* Fall through into software singlestep code. */
}
+ /* In a multi-threaded program, process->pid might be a running thread
+ and we can't read / write into running threads. So set process->pid
+ to the lwp. */
+ save_pid = process->pid;
+ process->pid = pid;
+
pc = am33_get_register (serv, pid, PC_REGNUM);
opcode = am33_read_byte (serv, pc);
@@ -3910,6 +3917,9 @@ am33_singlestep (struct gdbserv *serv, p
if (errno)
fprintf (stderr, "PTRACE_CONT (am33) error: %s in %d\n",
strerror (errno), pid);
+
+ /* Restore the saved pid. */
+ process->pid = save_pid;
}
#endif