public inbox for rda@sourceware.org
 help / color / mirror / Atom feed
* [commit] Fix thread related problem for am33 software singlestep
@ 2005-11-09  2:10 Kevin Buettner
  0 siblings, 0 replies; only message in thread
From: Kevin Buettner @ 2005-11-09  2:10 UTC (permalink / raw)
  To: rda

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
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-11-09  2:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-09  2:10 [commit] Fix thread related problem for am33 software singlestep Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).