+2009-04-03 Ulrich Weigand <uweigand@de.ibm.com>
+
+ * remote-utils.c (prepare_resume_reply): Null-terminate packet.
+ * spu-low.c (current_tid): Rename to ...
+ (current_ptid): ... this.
+ (fetch_ppc_register, fetch_ppc_memory, store_ppc_memory,
+ spu_proc_xfer_spu, spu_resume, spu_request_interrupt): Use
+ ptid_get_lwp (current_ptid) instead of current_tid.
+ (spu_kill, spu_detach, spu_join, spu_wait): Use pid argument
+ instead of current_tid. Use find_process_pid to verify pid
+ argument is valid. Pass proper argument to remove_process.
+ (spu_thread_alive): Compare current_ptid instead of current_tid.
+ (spu_resume): Likewise.
+
2009-04-02 Pedro Alves <pedro@codesourcery.com>
* linux-low.c (usr_store_inferior_registers): Declare local `pid'
#define NR_spu_run 0x0116
/* Get current thread ID (Linux task ID). */
-#define current_tid ((struct inferior_list_entry *)current_inferior)->id
+#define current_ptid ((struct inferior_list_entry *)current_inferior)->id
/* These are used in remote-utils.c. */
int using_threads = 0;
{
PTRACE_TYPE_RET res;
- int tid = current_tid;
+ int tid = ptid_get_lwp (current_ptid);
#ifndef __powerpc64__
/* If running as a 32-bit process on a 64-bit system, we attempt
/ sizeof (PTRACE_TYPE_RET));
PTRACE_TYPE_RET *buffer;
- int tid = current_tid;
+ int tid = ptid_get_lwp (current_ptid);
buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
for (i = 0; i < count; i++, addr += sizeof (PTRACE_TYPE_RET))
/ sizeof (PTRACE_TYPE_RET));
PTRACE_TYPE_RET *buffer;
- int tid = current_tid;
+ int tid = ptid_get_lwp (current_ptid);
buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
if (!annex)
return 0;
- sprintf (buf, "/proc/%ld/fd/%s", current_tid, annex);
+ sprintf (buf, "/proc/%ld/fd/%s", ptid_get_lwp (current_ptid), annex);
fd = open (buf, writebuf? O_WRONLY : O_RDONLY);
if (fd <= 0)
return -1;
/* Kill the inferior process. */
static int
-spu_kill (int)
+spu_kill (int pid)
{
- ptrace (PTRACE_KILL, current_tid, 0, 0);
- remove_process (pid);
+ struct process_info *process = find_process_pid (pid);
+ if (process == NULL)
+ return -1;
+
+ ptrace (PTRACE_KILL, pid, 0, 0);
+ remove_process (process);
return 0;
}
static int
spu_detach (int pid)
{
- ptrace (PTRACE_DETACH, current_tid, 0, 0);
- remove_process (pid);
+ struct process_info *process = find_process_pid (pid);
+ if (process == NULL)
+ return -1;
+
+ ptrace (PTRACE_DETACH, pid, 0, 0);
+ remove_process (process);
return 0;
}
spu_join (int pid)
{
int status, ret;
+ struct process_info *process;
+
+ process = find_process_pid (pid);
+ if (process == NULL)
+ return;
do {
- ret = waitpid (current_tid, &status, 0);
+ ret = waitpid (pid, &status, 0);
if (WIFEXITED (status) || WIFSIGNALED (status))
break;
} while (ret != -1 || errno != ECHILD);
static int
spu_thread_alive (ptid_t ptid)
{
- return ptid_get_lwp (ptid) == current_tid;
+ return ptid_equal (ptid, current_ptid);
}
/* Resume process. */
for (i = 0; i < n; i++)
if (ptid_equal (resume_info[i].thread, minus_one_ptid)
- || ptid_get_lwp (resume_info[i].thread) == current_tid)
+ || ptid_equal (resume_info[i].thread, current_ptid))
break;
if (i == n)
regcache_invalidate ();
errno = 0;
- ptrace (PTRACE_CONT, current_tid, 0, resume_info[i].sig);
+ ptrace (PTRACE_CONT, ptid_get_lwp (current_ptid), 0, resume_info[i].sig);
if (errno)
perror_with_name ("ptrace");
}
static ptid_t
spu_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
- int tid = current_tid;
+ int pid = ptid_get_pid (ptid);
int w;
int ret;
while (1)
{
- ret = waitpid (tid, &w, WNOHANG | __WALL | __WNOTHREAD);
+ ret = waitpid (pid, &w, WNOHANG | __WALL | __WNOTHREAD);
if (ret == -1)
{
while (!parse_spufs_run (&fd, &addr))
{
- ptrace (PT_SYSCALL, tid, (PTRACE_TYPE_ARG3) 0, 0);
- waitpid (tid, NULL, __WALL | __WNOTHREAD);
+ ptrace (PT_SYSCALL, pid, (PTRACE_TYPE_ARG3) 0, 0);
+ waitpid (pid, NULL, __WALL | __WNOTHREAD);
}
}
- ret = current_tid;
-
if (WIFEXITED (w))
{
fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w));
ourstatus->kind = TARGET_WAITKIND_EXITED;
ourstatus->value.integer = WEXITSTATUS (w);
clear_inferiors ();
- remove_process (ret);
+ remove_process (find_process_pid (ret));
return pid_to_ptid (ret);
}
else if (!WIFSTOPPED (w))
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
ourstatus->value.sig = target_signal_from_host (WTERMSIG (w));
clear_inferiors ();
- remove_process (ret);
+ remove_process (find_process_pid (ret));
return pid_to_ptid (ret);
}
static void
spu_request_interrupt (void)
{
- syscall (SYS_tkill, current_tid, SIGINT);
+ syscall (SYS_tkill, ptid_get_lwp (current_ptid), SIGINT);
}
static struct target_ops spu_target_ops = {