2006-11-23 01:34:15 +08:00
|
|
|
/* Low level interface to SPUs, for the remote server for GDB.
|
2009-01-03 13:58:08 +08:00
|
|
|
Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
2006-11-23 01:34:15 +08:00
|
|
|
|
|
|
|
Contributed by Ulrich Weigand <uweigand@de.ibm.com>.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-24 02:08:50 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2006-11-23 01:34:15 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-24 02:08:50 +08:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2006-11-23 01:34:15 +08:00
|
|
|
|
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
|
|
/* Some older glibc versions do not define this. */
|
|
|
|
#ifndef __WNOTHREAD
|
|
|
|
#define __WNOTHREAD 0x20000000 /* Don't wait on children of other
|
* i387-fp.c, linux-arm-low.c, linux-cris-low.c,
linux-crisv32-low.c, linux-i386-low.c, linux-low.c,
linux-mips-low.c, linux-s390-low.c, linux-sparc-low.c,
linux-x86-64-low.c, linux-xtensa-low.c, proc-service.c,
regcache.c, remote-utils.c, server.c, spu-low.c, target.h,
thread-db.c, win32-low.c, xtensa-xtregs.c, gdbreplay.c,
Makefile.in, configure.ac: Fix whitespace throughout.
* configure: Regenerate.
2009-03-23 07:57:10 +08:00
|
|
|
threads in this group */
|
2006-11-23 01:34:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PTRACE_TYPE_RET long
|
|
|
|
#define PTRACE_TYPE_ARG3 long
|
|
|
|
|
|
|
|
/* Number of registers. */
|
|
|
|
#define SPU_NUM_REGS 130
|
|
|
|
#define SPU_NUM_CORE_REGS 128
|
|
|
|
|
|
|
|
/* Special registers. */
|
|
|
|
#define SPU_ID_REGNUM 128
|
|
|
|
#define SPU_PC_REGNUM 129
|
|
|
|
|
|
|
|
/* PPU side system calls. */
|
|
|
|
#define INSTR_SC 0x44000002
|
|
|
|
#define NR_spu_run 0x0116
|
|
|
|
|
|
|
|
/* Get current thread ID (Linux task ID). */
|
|
|
|
#define current_tid ((struct inferior_list_entry *)current_inferior)->id
|
|
|
|
|
|
|
|
/* These are used in remote-utils.c. */
|
|
|
|
int using_threads = 0;
|
|
|
|
|
2008-02-27 11:27:40 +08:00
|
|
|
/* Defined in auto-generated file reg-spu.c. */
|
|
|
|
void init_registers_spu (void);
|
|
|
|
|
2006-11-23 01:34:15 +08:00
|
|
|
|
|
|
|
/* Fetch PPU register REGNO. */
|
|
|
|
static CORE_ADDR
|
|
|
|
fetch_ppc_register (int regno)
|
|
|
|
{
|
|
|
|
PTRACE_TYPE_RET res;
|
|
|
|
|
|
|
|
int tid = current_tid;
|
|
|
|
|
|
|
|
#ifndef __powerpc64__
|
|
|
|
/* If running as a 32-bit process on a 64-bit system, we attempt
|
|
|
|
to get the full 64-bit register content of the target process.
|
|
|
|
If the PPC special ptrace call fails, we're on a 32-bit system;
|
|
|
|
just fall through to the regular ptrace call in that case. */
|
|
|
|
{
|
|
|
|
char buf[8];
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ptrace (PPC_PTRACE_PEEKUSR_3264, tid,
|
|
|
|
(PTRACE_TYPE_ARG3) (regno * 8), buf);
|
|
|
|
if (errno == 0)
|
|
|
|
ptrace (PPC_PTRACE_PEEKUSR_3264, tid,
|
|
|
|
(PTRACE_TYPE_ARG3) (regno * 8 + 4), buf + 4);
|
|
|
|
if (errno == 0)
|
|
|
|
return (CORE_ADDR) *(unsigned long long *)buf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
res = ptrace (PT_READ_U, tid,
|
* i387-fp.c, linux-arm-low.c, linux-cris-low.c,
linux-crisv32-low.c, linux-i386-low.c, linux-low.c,
linux-mips-low.c, linux-s390-low.c, linux-sparc-low.c,
linux-x86-64-low.c, linux-xtensa-low.c, proc-service.c,
regcache.c, remote-utils.c, server.c, spu-low.c, target.h,
thread-db.c, win32-low.c, xtensa-xtregs.c, gdbreplay.c,
Makefile.in, configure.ac: Fix whitespace throughout.
* configure: Regenerate.
2009-03-23 07:57:10 +08:00
|
|
|
(PTRACE_TYPE_ARG3) (regno * sizeof (PTRACE_TYPE_RET)), 0);
|
2006-11-23 01:34:15 +08:00
|
|
|
if (errno != 0)
|
|
|
|
{
|
|
|
|
char mess[128];
|
|
|
|
sprintf (mess, "reading PPC register #%d", regno);
|
|
|
|
perror_with_name (mess);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (CORE_ADDR) (unsigned long) res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch WORD from PPU memory at (aligned) MEMADDR in thread TID. */
|
|
|
|
static int
|
|
|
|
fetch_ppc_memory_1 (int tid, CORE_ADDR memaddr, PTRACE_TYPE_RET *word)
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
#ifndef __powerpc64__
|
|
|
|
if (memaddr >> 32)
|
|
|
|
{
|
|
|
|
unsigned long long addr_8 = (unsigned long long) memaddr;
|
|
|
|
ptrace (PPC_PTRACE_PEEKTEXT_3264, tid, (PTRACE_TYPE_ARG3) &addr_8, word);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
*word = ptrace (PT_READ_I, tid, (PTRACE_TYPE_ARG3) (size_t) memaddr, 0);
|
|
|
|
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store WORD into PPU memory at (aligned) MEMADDR in thread TID. */
|
|
|
|
static int
|
|
|
|
store_ppc_memory_1 (int tid, CORE_ADDR memaddr, PTRACE_TYPE_RET word)
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
#ifndef __powerpc64__
|
|
|
|
if (memaddr >> 32)
|
|
|
|
{
|
|
|
|
unsigned long long addr_8 = (unsigned long long) memaddr;
|
|
|
|
ptrace (PPC_PTRACE_POKEDATA_3264, tid, (PTRACE_TYPE_ARG3) &addr_8, word);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ptrace (PT_WRITE_D, tid, (PTRACE_TYPE_ARG3) (size_t) memaddr, word);
|
|
|
|
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch LEN bytes of PPU memory at MEMADDR to MYADDR. */
|
|
|
|
static int
|
|
|
|
fetch_ppc_memory (CORE_ADDR memaddr, char *myaddr, int len)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_TYPE_RET);
|
|
|
|
int count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
|
|
|
|
/ sizeof (PTRACE_TYPE_RET));
|
|
|
|
PTRACE_TYPE_RET *buffer;
|
|
|
|
|
|
|
|
int tid = current_tid;
|
|
|
|
|
|
|
|
buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
|
|
|
|
for (i = 0; i < count; i++, addr += sizeof (PTRACE_TYPE_RET))
|
|
|
|
if ((ret = fetch_ppc_memory_1 (tid, addr, &buffer[i])) != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memcpy (myaddr,
|
|
|
|
(char *) buffer + (memaddr & (sizeof (PTRACE_TYPE_RET) - 1)),
|
|
|
|
len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store LEN bytes from MYADDR to PPU memory at MEMADDR. */
|
|
|
|
static int
|
|
|
|
store_ppc_memory (CORE_ADDR memaddr, char *myaddr, int len)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_TYPE_RET);
|
|
|
|
int count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
|
|
|
|
/ sizeof (PTRACE_TYPE_RET));
|
|
|
|
PTRACE_TYPE_RET *buffer;
|
|
|
|
|
|
|
|
int tid = current_tid;
|
|
|
|
|
|
|
|
buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
|
|
|
|
|
|
|
|
if (addr != memaddr || len < (int) sizeof (PTRACE_TYPE_RET))
|
|
|
|
if ((ret = fetch_ppc_memory_1 (tid, addr, &buffer[0])) != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (count > 1)
|
|
|
|
if ((ret = fetch_ppc_memory_1 (tid, addr + (count - 1)
|
|
|
|
* sizeof (PTRACE_TYPE_RET),
|
|
|
|
&buffer[count - 1])) != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_TYPE_RET) - 1)),
|
* i387-fp.c, linux-arm-low.c, linux-cris-low.c,
linux-crisv32-low.c, linux-i386-low.c, linux-low.c,
linux-mips-low.c, linux-s390-low.c, linux-sparc-low.c,
linux-x86-64-low.c, linux-xtensa-low.c, proc-service.c,
regcache.c, remote-utils.c, server.c, spu-low.c, target.h,
thread-db.c, win32-low.c, xtensa-xtregs.c, gdbreplay.c,
Makefile.in, configure.ac: Fix whitespace throughout.
* configure: Regenerate.
2009-03-23 07:57:10 +08:00
|
|
|
myaddr, len);
|
2006-11-23 01:34:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++, addr += sizeof (PTRACE_TYPE_RET))
|
|
|
|
if ((ret = store_ppc_memory_1 (tid, addr, buffer[i])) != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If the PPU thread is currently stopped on a spu_run system call,
|
|
|
|
return to FD and ADDR the file handle and NPC parameter address
|
|
|
|
used with the system call. Return non-zero if successful. */
|
* i387-fp.c, linux-arm-low.c, linux-cris-low.c,
linux-crisv32-low.c, linux-i386-low.c, linux-low.c,
linux-mips-low.c, linux-s390-low.c, linux-sparc-low.c,
linux-x86-64-low.c, linux-xtensa-low.c, proc-service.c,
regcache.c, remote-utils.c, server.c, spu-low.c, target.h,
thread-db.c, win32-low.c, xtensa-xtregs.c, gdbreplay.c,
Makefile.in, configure.ac: Fix whitespace throughout.
* configure: Regenerate.
2009-03-23 07:57:10 +08:00
|
|
|
static int
|
2006-11-23 01:34:15 +08:00
|
|
|
parse_spufs_run (int *fd, CORE_ADDR *addr)
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
CORE_ADDR pc = fetch_ppc_register (32); /* nip */
|
|
|
|
|
|
|
|
/* Fetch instruction preceding current NIP. */
|
|
|
|
if (fetch_ppc_memory (pc-4, buf, 4) != 0)
|
|
|
|
return 0;
|
|
|
|
/* It should be a "sc" instruction. */
|
|
|
|
if (*(unsigned int *)buf != INSTR_SC)
|
|
|
|
return 0;
|
|
|
|
/* System call number should be NR_spu_run. */
|
|
|
|
if (fetch_ppc_register (0) != NR_spu_run)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Register 3 contains fd, register 4 the NPC param pointer. */
|
|
|
|
*fd = fetch_ppc_register (34); /* orig_gpr3 */
|
|
|
|
*addr = fetch_ppc_register (4);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy LEN bytes at OFFSET in spufs file ANNEX into/from READBUF or WRITEBUF,
|
|
|
|
using the /proc file system. */
|
|
|
|
static int
|
|
|
|
spu_proc_xfer_spu (const char *annex, unsigned char *readbuf,
|
|
|
|
const unsigned char *writebuf,
|
|
|
|
CORE_ADDR offset, int len)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int fd = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!annex)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sprintf (buf, "/proc/%ld/fd/%s", current_tid, annex);
|
|
|
|
fd = open (buf, writebuf? O_WRONLY : O_RDONLY);
|
|
|
|
if (fd <= 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (offset != 0
|
|
|
|
&& lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
|
|
|
|
{
|
|
|
|
close (fd);
|
2007-06-12 22:31:26 +08:00
|
|
|
return 0;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (writebuf)
|
|
|
|
ret = write (fd, writebuf, (size_t) len);
|
|
|
|
else if (readbuf)
|
|
|
|
ret = read (fd, readbuf, (size_t) len);
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Start an inferior process and returns its pid.
|
|
|
|
ALLARGS is a vector of program-name and args. */
|
|
|
|
static int
|
|
|
|
spu_create_inferior (char *program, char **allargs)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
pid = fork ();
|
|
|
|
if (pid < 0)
|
|
|
|
perror_with_name ("fork");
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
ptrace (PTRACE_TRACEME, 0, 0, 0);
|
|
|
|
|
|
|
|
setpgid (0, 0);
|
|
|
|
|
2007-06-21 02:54:21 +08:00
|
|
|
execv (program, allargs);
|
|
|
|
if (errno == ENOENT)
|
|
|
|
execvp (program, allargs);
|
2006-11-23 01:34:15 +08:00
|
|
|
|
|
|
|
fprintf (stderr, "Cannot exec %s: %s.\n", program,
|
|
|
|
strerror (errno));
|
|
|
|
fflush (stderr);
|
|
|
|
_exit (0177);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_thread (pid, NULL, pid);
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach to an inferior process. */
|
|
|
|
int
|
|
|
|
spu_attach (unsigned long pid)
|
|
|
|
{
|
|
|
|
if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Cannot attach to process %ld: %s (%d)\n", pid,
|
|
|
|
strerror (errno), errno);
|
|
|
|
fflush (stderr);
|
|
|
|
_exit (0177);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_thread (pid, NULL, pid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Kill the inferior process. */
|
|
|
|
static void
|
|
|
|
spu_kill (void)
|
|
|
|
{
|
|
|
|
ptrace (PTRACE_KILL, current_tid, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach from inferior process. */
|
2007-05-11 05:33:31 +08:00
|
|
|
static int
|
2006-11-23 01:34:15 +08:00
|
|
|
spu_detach (void)
|
|
|
|
{
|
|
|
|
ptrace (PTRACE_DETACH, current_tid, 0, 0);
|
2007-05-11 05:33:31 +08:00
|
|
|
return 0;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
2007-05-11 05:05:15 +08:00
|
|
|
static void
|
|
|
|
spu_join (void)
|
|
|
|
{
|
|
|
|
int status, ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = waitpid (current_tid, &status, 0);
|
|
|
|
if (WIFEXITED (status) || WIFSIGNALED (status))
|
|
|
|
break;
|
|
|
|
} while (ret != -1 || errno != ECHILD);
|
|
|
|
}
|
|
|
|
|
2006-11-23 01:34:15 +08:00
|
|
|
/* Return nonzero if the given thread is still alive. */
|
|
|
|
static int
|
|
|
|
spu_thread_alive (unsigned long tid)
|
|
|
|
{
|
|
|
|
return tid == current_tid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resume process. */
|
|
|
|
static void
|
2009-04-02 06:29:33 +08:00
|
|
|
spu_resume (struct thread_resume *resume_info, size_t n)
|
2006-11-23 01:34:15 +08:00
|
|
|
{
|
2009-04-02 06:29:33 +08:00
|
|
|
size_t i;
|
2006-11-23 01:34:15 +08:00
|
|
|
|
2009-04-02 06:29:33 +08:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
if (resume_info[i].thread == -1
|
|
|
|
|| resume_info[i].thread == current_tid)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == n)
|
2006-11-23 01:34:15 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* We don't support hardware single-stepping right now, assume
|
|
|
|
GDB knows to use software single-stepping. */
|
Non-stop mode support.
* server.h (non_stop): Declare.
(gdb_client_data, handler_func): Declare.
(delete_file_handler, add_file_handler, start_event_loop):
Declare.
(handle_serial_event, handle_target_event, push_event)
(putpkt_notif): Declare.
* target.h (enum resume_kind): New.
(struct thread_resume): Replace `step' field by `kind' field.
(TARGET_WNOHANG): Define.
(struct target_ops) <wait>: Add `options' argument.
<supports_non_stop, async, start_non_stop>: New fields.
(target_supports_non_stop, target_async): New.
(start_non_stop): Declare.
(mywait): Add `options' argument.
* target.c (mywait): Add `options' argument. Print child exit
notifications here.
(start_non_stop): New.
* server.c (non_stop, own_buf, mem_buf): New globals.
(struct vstop_notif): New.
(notif_queue): New global.
(queue_stop_reply, push_event, discard_queued_stop_replies)
(send_next_stop_reply): New.
(start_inferior): Adjust to use resume_kind. Adjust to mywait
interface changes.
(attach_inferior): In non-stop mode, don't wait for the target
here.
(handle_general_set): Handle QNonStop.
(handle_query): When handling qC, return the current general
thread, instead of the first thread of the list.
(handle_query): If the backend supports non-stop mode, include
QNonStop+ in the qSupported query response.
(handle_v_cont): Adjust to use resume_kind. Handle resume_stop
and non-stop mode.
(handle_v_attach, handle_v_run): Handle non-stop mode.
(handle_v_stopped): New.
(handle_v_requests): Report support for vCont;t. Handle vStopped.
(myresume): Adjust to use resume_kind. Handle non-stop.
(queue_stop_reply_callback): New.
(handle_status): Handle non-stop mode.
(main): Clear non_stop flag on reconnection. Use the event-loop.
Refactor serial protocol handling from here ...
(process_serial_event): ... to this new function. When GDB
selects any thread, select one here. In non-stop mode, wait until
GDB acks all pending events before exiting.
(handle_serial_event, handle_target_event): New.
* remote-utils.c (remote_open): Install remote_desc in the event
loop.
(remote_close): Remove remote_desc from the event loop.
(putpkt_binary): Rename to...
(putpkt_binary_1): ... this. Add `is_notic' argument. Handle it.
(putpkt_binary): New as wrapper around putpkt_binary_1.
(putpkt_notif): New.
(prepare_resume_reply): In non-stop mode, don't change the
general_thread.
* event-loop.c: New.
* Makefile.in (OBJ): Add event-loop.o.
(event-loop.o): New rule.
* linux-low.h (pid_of): Moved here.
(lwpid_of): New.
(get_lwp_thread): Use lwpid_of.
(struct lwp_info): Delete `lwpid' field. Add `suspended' field.
* linux-low.c (pid_of): Delete.
(inferior_pid): Use lwpid_of.
(linux_event_pipe): New.
(target_is_async_p): New.
(delete_lwp): New.
(handle_extended_wait): Use lwpid_of.
(add_lwp): Don't set lwpid field.
(linux_attach_lwp): Adjust debug output. Use lwpid_of.
(linux_kill_one_lwp): If killing a running lwp, stop it first.
Use lwpid_of. Adjust to linux_wait_for_event interface changes.
(linux_detach_one_lwp): If detaching from a running lwp, stop it
first. Adjust to linux_wait_for_event interface changes. Use
lwpid_of.
(linux_detach): Don't delete the main lwp here.
(linux_join): Use my_waitpid. Avoid signal_pid. Use lwpid_of.
(status_pending_p): Don't consider explicitly suspended lwps.
(linux_wait_for_lwp): Take an integer pid instead of a lwp_info
pointer. Add OPTIONS argument. Change return type to int. Use
my_waitpid instead of sleeping. Handle WNOHANG. Use lwpid_of.
(linux_wait_for_event): Take an integer pid instead of a lwp_info
pointer. Add status pointer argument. Return a pid instead of a
status. Use lwpid_of. Adjust to linux_wait_for_lwp interface
changes. In non-stop mode, don't switch to a random thread.
(linux_wait): Rename to...
(linux_wait_1): ... this. Add target_options argument, and handle
it. Adjust to use resume_kind. Use lwpid_of. In non-stop mode,
don't handle the continue thread. Handle TARGET_WNOHANG. Merge
clean exit and signal exit code. Don't stop all threads in
non-stop mode. In all-stop mode, only stop all threads when
reporting a stop to GDB. Handle explicit thread stop requests.
(async_file_flush, async_file_mark): New.
(linux_wait): New.
(send_sigstop): Use lwpid_of.
(wait_for_sigstop): Use lwpid_of. Adjust to linux_wait_for_event
interface changes. In non-stop mode, don't switch to a random
thread.
(linux_resume_one_lwp): Use lwpid_of.
(linux_continue_one_thread, linux_queue_one_thread): Merge into ...
(linux_resume_one_thread): ... this. Handle resume_stop. In
non-stop mode, don't look for pending flag in all threads.
(resume_status_pending_p): Don't consider explicitly suspended
threads.
(my_waitpid): Reimplement. Emulate __WALL.
(linux_request_interrupt, linux_read_offsets, linux_xfer_siginfo):
Use lwpid_of.
(sigchld_handler, linux_supports_non_stop, linux_async)
(linux_start_non_stop): New.
(linux_target_ops): Register linux_supports_non_stop, linux_async
and linux_start_non_stop.
(initialize_low): Install SIGCHLD handler.
* thread-db.c (thread_db_create_event, find_one_thread)
(thread_db_get_tls_address): Use lwpid_of.
* win32-low.c (win32_detach): Adjust to use resume_kind.
(win32_wait): Add `options' argument.
* spu-low.c (spu_resume): Adjust to use resume_kind.
(spu_wait): Add `options' argument.
2009-04-02 06:48:05 +08:00
|
|
|
if (resume_info[i].kind == resume_step)
|
2006-11-23 01:34:15 +08:00
|
|
|
fprintf (stderr, "Hardware single-step not supported.\n");
|
|
|
|
|
|
|
|
regcache_invalidate ();
|
|
|
|
|
|
|
|
errno = 0;
|
2009-04-02 06:29:33 +08:00
|
|
|
ptrace (PTRACE_CONT, current_tid, 0, resume_info[i].sig);
|
2006-11-23 01:34:15 +08:00
|
|
|
if (errno)
|
|
|
|
perror_with_name ("ptrace");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for process, returns status. */
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
static unsigned long
|
Non-stop mode support.
* server.h (non_stop): Declare.
(gdb_client_data, handler_func): Declare.
(delete_file_handler, add_file_handler, start_event_loop):
Declare.
(handle_serial_event, handle_target_event, push_event)
(putpkt_notif): Declare.
* target.h (enum resume_kind): New.
(struct thread_resume): Replace `step' field by `kind' field.
(TARGET_WNOHANG): Define.
(struct target_ops) <wait>: Add `options' argument.
<supports_non_stop, async, start_non_stop>: New fields.
(target_supports_non_stop, target_async): New.
(start_non_stop): Declare.
(mywait): Add `options' argument.
* target.c (mywait): Add `options' argument. Print child exit
notifications here.
(start_non_stop): New.
* server.c (non_stop, own_buf, mem_buf): New globals.
(struct vstop_notif): New.
(notif_queue): New global.
(queue_stop_reply, push_event, discard_queued_stop_replies)
(send_next_stop_reply): New.
(start_inferior): Adjust to use resume_kind. Adjust to mywait
interface changes.
(attach_inferior): In non-stop mode, don't wait for the target
here.
(handle_general_set): Handle QNonStop.
(handle_query): When handling qC, return the current general
thread, instead of the first thread of the list.
(handle_query): If the backend supports non-stop mode, include
QNonStop+ in the qSupported query response.
(handle_v_cont): Adjust to use resume_kind. Handle resume_stop
and non-stop mode.
(handle_v_attach, handle_v_run): Handle non-stop mode.
(handle_v_stopped): New.
(handle_v_requests): Report support for vCont;t. Handle vStopped.
(myresume): Adjust to use resume_kind. Handle non-stop.
(queue_stop_reply_callback): New.
(handle_status): Handle non-stop mode.
(main): Clear non_stop flag on reconnection. Use the event-loop.
Refactor serial protocol handling from here ...
(process_serial_event): ... to this new function. When GDB
selects any thread, select one here. In non-stop mode, wait until
GDB acks all pending events before exiting.
(handle_serial_event, handle_target_event): New.
* remote-utils.c (remote_open): Install remote_desc in the event
loop.
(remote_close): Remove remote_desc from the event loop.
(putpkt_binary): Rename to...
(putpkt_binary_1): ... this. Add `is_notic' argument. Handle it.
(putpkt_binary): New as wrapper around putpkt_binary_1.
(putpkt_notif): New.
(prepare_resume_reply): In non-stop mode, don't change the
general_thread.
* event-loop.c: New.
* Makefile.in (OBJ): Add event-loop.o.
(event-loop.o): New rule.
* linux-low.h (pid_of): Moved here.
(lwpid_of): New.
(get_lwp_thread): Use lwpid_of.
(struct lwp_info): Delete `lwpid' field. Add `suspended' field.
* linux-low.c (pid_of): Delete.
(inferior_pid): Use lwpid_of.
(linux_event_pipe): New.
(target_is_async_p): New.
(delete_lwp): New.
(handle_extended_wait): Use lwpid_of.
(add_lwp): Don't set lwpid field.
(linux_attach_lwp): Adjust debug output. Use lwpid_of.
(linux_kill_one_lwp): If killing a running lwp, stop it first.
Use lwpid_of. Adjust to linux_wait_for_event interface changes.
(linux_detach_one_lwp): If detaching from a running lwp, stop it
first. Adjust to linux_wait_for_event interface changes. Use
lwpid_of.
(linux_detach): Don't delete the main lwp here.
(linux_join): Use my_waitpid. Avoid signal_pid. Use lwpid_of.
(status_pending_p): Don't consider explicitly suspended lwps.
(linux_wait_for_lwp): Take an integer pid instead of a lwp_info
pointer. Add OPTIONS argument. Change return type to int. Use
my_waitpid instead of sleeping. Handle WNOHANG. Use lwpid_of.
(linux_wait_for_event): Take an integer pid instead of a lwp_info
pointer. Add status pointer argument. Return a pid instead of a
status. Use lwpid_of. Adjust to linux_wait_for_lwp interface
changes. In non-stop mode, don't switch to a random thread.
(linux_wait): Rename to...
(linux_wait_1): ... this. Add target_options argument, and handle
it. Adjust to use resume_kind. Use lwpid_of. In non-stop mode,
don't handle the continue thread. Handle TARGET_WNOHANG. Merge
clean exit and signal exit code. Don't stop all threads in
non-stop mode. In all-stop mode, only stop all threads when
reporting a stop to GDB. Handle explicit thread stop requests.
(async_file_flush, async_file_mark): New.
(linux_wait): New.
(send_sigstop): Use lwpid_of.
(wait_for_sigstop): Use lwpid_of. Adjust to linux_wait_for_event
interface changes. In non-stop mode, don't switch to a random
thread.
(linux_resume_one_lwp): Use lwpid_of.
(linux_continue_one_thread, linux_queue_one_thread): Merge into ...
(linux_resume_one_thread): ... this. Handle resume_stop. In
non-stop mode, don't look for pending flag in all threads.
(resume_status_pending_p): Don't consider explicitly suspended
threads.
(my_waitpid): Reimplement. Emulate __WALL.
(linux_request_interrupt, linux_read_offsets, linux_xfer_siginfo):
Use lwpid_of.
(sigchld_handler, linux_supports_non_stop, linux_async)
(linux_start_non_stop): New.
(linux_target_ops): Register linux_supports_non_stop, linux_async
and linux_start_non_stop.
(initialize_low): Install SIGCHLD handler.
* thread-db.c (thread_db_create_event, find_one_thread)
(thread_db_get_tls_address): Use lwpid_of.
* win32-low.c (win32_detach): Adjust to use resume_kind.
(win32_wait): Add `options' argument.
* spu-low.c (spu_resume): Adjust to use resume_kind.
(spu_wait): Add `options' argument.
2009-04-02 06:48:05 +08:00
|
|
|
spu_wait (struct target_waitstatus *ourstatus, int options)
|
2006-11-23 01:34:15 +08:00
|
|
|
{
|
|
|
|
int tid = current_tid;
|
|
|
|
int w;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
ret = waitpid (tid, &w, WNOHANG | __WALL | __WNOTHREAD);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
if (errno != ECHILD)
|
|
|
|
perror_with_name ("waitpid");
|
|
|
|
}
|
|
|
|
else if (ret > 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
usleep (1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* On the first wait, continue running the inferior until we are
|
|
|
|
blocked inside an spu_run system call. */
|
|
|
|
if (!server_waiting)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
while (!parse_spufs_run (&fd, &addr))
|
|
|
|
{
|
|
|
|
ptrace (PT_SYSCALL, tid, (PTRACE_TYPE_ARG3) 0, 0);
|
|
|
|
waitpid (tid, NULL, __WALL | __WNOTHREAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
ret = current_tid;
|
|
|
|
|
2006-11-23 01:34:15 +08:00
|
|
|
if (WIFEXITED (w))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w));
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
ourstatus->kind = TARGET_WAITKIND_EXITED;
|
|
|
|
ourstatus->value.integer = WEXITSTATUS (w);
|
2006-11-23 01:34:15 +08:00
|
|
|
clear_inferiors ();
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
return ret;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
else if (!WIFSTOPPED (w))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "\nChild terminated with signal = %x \n", WTERMSIG (w));
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
|
|
|
|
ourstatus->value.sig = target_signal_from_host (WTERMSIG (w));
|
2006-11-23 01:34:15 +08:00
|
|
|
clear_inferiors ();
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
return ret;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* After attach, we may have received a SIGSTOP. Do not return this
|
|
|
|
as signal to GDB, or else it will try to continue with SIGSTOP ... */
|
|
|
|
if (!server_waiting)
|
|
|
|
{
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
ourstatus->kind = TARGET_WAITKIND_STOPPED;
|
|
|
|
ourstatus->value.sig = TARGET_SIGNAL_0;
|
|
|
|
return ret;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
Decouple target code from remote protocol.
* target.h (enum target_waitkind): New.
(struct target_waitstatus): New.
(struct target_ops) <wait>: Return an unsigned long. Take a
target_waitstatus pointer instead of a char pointer.
(mywait): Likewise.
* target.c (mywait): Change prototype to return an unsigned long.
Take a target_waitstatus pointer instead of a char pointer. Adjust.
* server.h (thread_from_wait, old_thread_from_wait): Delete
declarations.
(prepare_resume_reply): Change prototype to take a
target_waitstatus.
* server.c (thread_from_wait, old_thread_from_wait): Delete.
(last_status, last_ptid): New.
(start_inferior): Remove "statusptr" argument. Adjust. Return a
pid instead of a signal.
(attach_inferior): Remove "status" and "signal" parameters.
Adjust.
(handle_query): For qGetTLSAddr, parse the thread id with strtol,
not as an address.
(handle_v_cont, handle_v_attach, handle_v_run, handle_v_kill)
(handle_v_requests, myresume): Remove "status" and "signal"
parameters. Adjust.
(handle_status): New.
(main): Delete local `status'. Adjust.
* remote-utils.c: Include target.h.
(prepare_resume_reply): Change prototype to take a
target_waitstatus. Adjust.
* linux-low.c (linux_wait): Adjust to new target_ops->wait
interface.
* spu-low.c (spu_wait): Adjust.
* win32-low.c (enum target_waitkind, struct target_waitstatus):
Delete.
(win32_wait): Adjust.
2009-04-02 06:31:45 +08:00
|
|
|
ourstatus->kind = TARGET_WAITKIND_STOPPED;
|
|
|
|
ourstatus->value.sig = target_signal_from_host (WSTOPSIG (w));
|
|
|
|
return ret;
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch inferior registers. */
|
|
|
|
static void
|
|
|
|
spu_fetch_registers (int regno)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
/* ??? Some callers use 0 to mean all registers. */
|
|
|
|
if (regno == 0)
|
|
|
|
regno = -1;
|
|
|
|
|
|
|
|
/* We must be stopped on a spu_run system call. */
|
|
|
|
if (!parse_spufs_run (&fd, &addr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The ID register holds the spufs file handle. */
|
|
|
|
if (regno == -1 || regno == SPU_ID_REGNUM)
|
|
|
|
supply_register (SPU_ID_REGNUM, (char *)&fd);
|
|
|
|
|
|
|
|
/* The NPC register is found at ADDR. */
|
|
|
|
if (regno == -1 || regno == SPU_PC_REGNUM)
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
if (fetch_ppc_memory (addr, buf, 4) == 0)
|
|
|
|
supply_register (SPU_PC_REGNUM, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The GPRs are found in the "regs" spufs file. */
|
|
|
|
if (regno == -1 || (regno >= 0 && regno < SPU_NUM_CORE_REGS))
|
|
|
|
{
|
|
|
|
unsigned char buf[16*SPU_NUM_CORE_REGS];
|
|
|
|
char annex[32];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sprintf (annex, "%d/regs", fd);
|
|
|
|
if (spu_proc_xfer_spu (annex, buf, NULL, 0, sizeof buf) == sizeof buf)
|
|
|
|
for (i = 0; i < SPU_NUM_CORE_REGS; i++)
|
|
|
|
supply_register (i, buf + i*16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store inferior registers. */
|
|
|
|
static void
|
|
|
|
spu_store_registers (int regno)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
/* ??? Some callers use 0 to mean all registers. */
|
|
|
|
if (regno == 0)
|
|
|
|
regno = -1;
|
|
|
|
|
|
|
|
/* We must be stopped on a spu_run system call. */
|
|
|
|
if (!parse_spufs_run (&fd, &addr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The NPC register is found at ADDR. */
|
|
|
|
if (regno == -1 || regno == SPU_PC_REGNUM)
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
collect_register (SPU_PC_REGNUM, buf);
|
|
|
|
store_ppc_memory (addr, buf, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The GPRs are found in the "regs" spufs file. */
|
|
|
|
if (regno == -1 || (regno >= 0 && regno < SPU_NUM_CORE_REGS))
|
|
|
|
{
|
|
|
|
unsigned char buf[16*SPU_NUM_CORE_REGS];
|
|
|
|
char annex[32];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < SPU_NUM_CORE_REGS; i++)
|
|
|
|
collect_register (i, buf + i*16);
|
|
|
|
|
|
|
|
sprintf (annex, "%d/regs", fd);
|
|
|
|
spu_proc_xfer_spu (annex, NULL, buf, 0, sizeof buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy LEN bytes from inferior's memory starting at MEMADDR
|
|
|
|
to debugger memory starting at MYADDR. */
|
|
|
|
static int
|
|
|
|
spu_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
char annex[32];
|
|
|
|
|
|
|
|
/* We must be stopped on a spu_run system call. */
|
|
|
|
if (!parse_spufs_run (&fd, &addr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Use the "mem" spufs file to access SPU local store. */
|
|
|
|
sprintf (annex, "%d/mem", fd);
|
|
|
|
ret = spu_proc_xfer_spu (annex, myaddr, NULL, memaddr, len);
|
|
|
|
return ret == len ? 0 : EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy LEN bytes of data from debugger memory at MYADDR
|
|
|
|
to inferior's memory at MEMADDR.
|
|
|
|
On failure (cannot write the inferior)
|
|
|
|
returns the value of errno. */
|
|
|
|
static int
|
|
|
|
spu_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
char annex[32];
|
|
|
|
|
|
|
|
/* We must be stopped on a spu_run system call. */
|
|
|
|
if (!parse_spufs_run (&fd, &addr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Use the "mem" spufs file to access SPU local store. */
|
|
|
|
sprintf (annex, "%d/mem", fd);
|
|
|
|
ret = spu_proc_xfer_spu (annex, NULL, myaddr, memaddr, len);
|
|
|
|
return ret == len ? 0 : EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up special symbols -- unneded here. */
|
|
|
|
static void
|
|
|
|
spu_look_up_symbols (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send signal to inferior. */
|
|
|
|
static void
|
2007-02-26 01:59:43 +08:00
|
|
|
spu_request_interrupt (void)
|
2006-11-23 01:34:15 +08:00
|
|
|
{
|
2007-02-26 01:59:43 +08:00
|
|
|
syscall (SYS_tkill, current_tid, SIGINT);
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct target_ops spu_target_ops = {
|
|
|
|
spu_create_inferior,
|
|
|
|
spu_attach,
|
|
|
|
spu_kill,
|
|
|
|
spu_detach,
|
2007-05-11 05:05:15 +08:00
|
|
|
spu_join,
|
2006-11-23 01:34:15 +08:00
|
|
|
spu_thread_alive,
|
|
|
|
spu_resume,
|
|
|
|
spu_wait,
|
|
|
|
spu_fetch_registers,
|
|
|
|
spu_store_registers,
|
|
|
|
spu_read_memory,
|
|
|
|
spu_write_memory,
|
|
|
|
spu_look_up_symbols,
|
2007-02-26 01:59:43 +08:00
|
|
|
spu_request_interrupt,
|
2006-11-23 01:34:15 +08:00
|
|
|
NULL,
|
2007-02-23 01:41:37 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-06-12 22:38:32 +08:00
|
|
|
spu_proc_xfer_spu,
|
2008-02-01 08:08:25 +08:00
|
|
|
hostio_last_error_from_errno,
|
2006-11-23 01:34:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
initialize_low (void)
|
|
|
|
{
|
|
|
|
static const unsigned char breakpoint[] = { 0x00, 0x00, 0x3f, 0xff };
|
|
|
|
|
|
|
|
set_target_ops (&spu_target_ops);
|
|
|
|
set_breakpoint_data (breakpoint, sizeof breakpoint);
|
2008-02-27 11:27:40 +08:00
|
|
|
init_registers_spu ();
|
2006-11-23 01:34:15 +08:00
|
|
|
}
|