/* Machine independent support for SVR4 /proc (process file system) for GDB.
- Copyright (C) 1991 Free Software Foundation, Inc.
+ Copyright 1991, 1992 Free Software Foundation, Inc.
Written by Fred Fish at Cygnus Support.
This file is part of GDB.
proc_address_to_fd PARAMS ((CORE_ADDR, int));
static int
-open_proc_file PARAMS ((int, struct procinfo *));
+open_proc_file PARAMS ((int, struct procinfo *, int));
static void
close_proc_file PARAMS ((struct procinfo *));
free (locbuf);
}
locbuf = xmalloc (strlen (prefix) + 16);
- (void) sprintf (locbuf, "%s %u", prefix, val);
+ sprintf (locbuf, "%s %u", prefix, val);
name = locbuf;
}
return (name);
}
if (name == NULL)
{
- (void) sprintf (locbuf, "sigcode %u", sip -> si_signo);
+ sprintf (locbuf, "sigcode %u", sip -> si_signo);
name = locbuf;
}
return (name);
}
else
{
- (void) sprintf (locbuf, "syscall %u", syscallnum);
+ sprintf (locbuf, "syscall %u", syscallnum);
rtnval = locbuf;
}
return (rtnval);
int signo;
signo = SIGKILL;
- (void) ioctl (pi.fd, PIOCKILL, &signo);
+ ioctl (pi.fd, PIOCKILL, &signo);
close_proc_file (&pi);
wait ((int *) 0);
}
{
if (regno != -1)
{
- (void) ioctl (pi.fd, PIOCGREG, &pi.gregset);
+ ioctl (pi.fd, PIOCGREG, &pi.gregset);
}
fill_gregset (&pi.gregset, regno);
- (void) ioctl (pi.fd, PIOCSREG, &pi.gregset);
+ ioctl (pi.fd, PIOCSREG, &pi.gregset);
#if defined (FP0_REGNUM)
if (regno != -1)
{
- (void) ioctl (pi.fd, PIOCGFPREG, &pi.fpregset);
+ ioctl (pi.fd, PIOCGFPREG, &pi.fpregset);
}
fill_fpregset (&pi.fpregset, regno);
- (void) ioctl (pi.fd, PIOCSFPREG, &pi.fpregset);
+ ioctl (pi.fd, PIOCSFPREG, &pi.fpregset);
#endif /* FP0_REGNUM */
inferior_proc_init (pid)
int pid;
{
- if (!open_proc_file (pid, &pi))
+ if (!open_proc_file (pid, &pi, O_RDWR))
{
proc_init_failed ("can't open process file");
}
else
{
- (void) memset ((char *) &pi.prrun, 0, sizeof (pi.prrun));
+ memset ((char *) &pi.prrun, 0, sizeof (pi.prrun));
prfillset (&pi.prrun.pr_trace);
proc_signal_handling_change ();
prfillset (&pi.prrun.pr_fault);
auto char procname[32];
int fd;
- (void) sprintf (procname, PROC_NAME_FMT, getpid ());
+ sprintf (procname, PROC_NAME_FMT, getpid ());
if ((fd = open (procname, O_RDWR)) < 0)
{
perror (procname);
{
long pr_flags;
pr_flags = PR_FORK;
- (void) ioctl (fd, PIOCRESET, &pr_flags);
+ ioctl (fd, PIOCRESET, &pr_flags);
}
#else
#if defined (PIOCRFORK) /* Original method */
- (void) ioctl (fd, PIOCRFORK, NULL);
+ ioctl (fd, PIOCRFORK, NULL);
+#endif
+#endif
+
+ /* Turn on run-on-last-close flag so that this process will not hang
+ if GDB goes away for some reason. */
+
+#if defined (PIOCSET) /* New method */
+ {
+ long pr_flags;
+ pr_flags = PR_RLC;
+ (void) ioctl (fd, PIOCSET, &pr_flags);
+ }
+#else
+#if defined (PIOCSRLC) /* Original method */
+ (void) ioctl (fd, PIOCSRLC, 0);
#endif
#endif
}
The option of stopping at attach time is specific to the /proc
versions of gdb. Versions using ptrace force the attachee
- to stop.
+ to stop. (I have changed this version to do so, too. All you
+ have to do is "continue" to make it go on. -- gnu@cygnus.com)
*/
attach (pid)
int pid;
{
- if (!open_proc_file (pid, &pi))
+ int result;
+
+ if (!open_proc_file (pid, &pi, O_RDWR))
{
perror_with_name (pi.pathname);
/* NOTREACHED */
else
{
pi.was_stopped = 0;
- if (query ("Process is currently running, stop it? "))
+ if (1 || query ("Process is currently running, stop it? "))
{
+ /* Make it run again when we close it. */
+#if defined (PIOCSET) /* New method */
+ {
+ long pr_flags;
+ pr_flags = PR_RLC;
+ result = ioctl (pi.fd, PIOCSET, &pr_flags);
+ }
+#else
+#if defined (PIOCSRLC) /* Original method */
+ result = ioctl (pi.fd, PIOCSRLC, 0);
+#endif
+#endif
+ if (result < 0)
+ {
+ print_sys_errmsg (pi.pathname, errno);
+ close_proc_file (&pi);
+ error ("PIOCSRLC or PIOCSET failed");
+ }
if (ioctl (pi.fd, PIOCSTOP, &pi.prstatus) < 0)
{
print_sys_errmsg (pi.pathname, errno);
printf ("Ok, gdb will wait for process %u to stop.\n", pid);
}
}
-
+
/* Remember some things about the inferior that we will, or might, change
so that we can restore them when we detach. */
- (void) ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace);
- (void) ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold);
- (void) ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset);
- (void) ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset);
- (void) ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset);
+ ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace);
+ ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold);
+ ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset);
+ ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset);
+ ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset);
/* Set up trace and fault sets, as gdb expects them. */
- (void) memset (&pi.prrun, 0, sizeof (pi.prrun));
+ memset (&pi.prrun, 0, sizeof (pi.prrun));
prfillset (&pi.prrun.pr_trace);
proc_signal_handling_change ();
prfillset (&pi.prrun.pr_fault);
detach (signal)
int signal;
{
+ int result;
+
if (signal)
{
set_proc_siginfo (&pi, signal);
if (signal || !pi.was_stopped ||
query ("Was stopped when attached, make it runnable again? "))
{
- (void) memset (&pi.prrun, 0, sizeof (pi.prrun));
- pi.prrun.pr_flags = PRCFAULT;
- if (ioctl (pi.fd, PIOCRUN, &pi.prrun))
+ /* Clear any fault that might have stopped it. */
+ if (ioctl (pi.fd, PIOCCFAULT, 0))
+ {
+ print_sys_errmsg (pi.pathname, errno);
+ printf ("PIOCCFAULT failed.\n");
+ }
+
+ /* Make it run again when we close it. */
+#if defined (PIOCSET) /* New method */
+ {
+ long pr_flags;
+ pr_flags = PR_RLC;
+ result = ioctl (pi.fd, PIOCSET, &pr_flags);
+ }
+#else
+#if defined (PIOCSRLC) /* Original method */
+ result = ioctl (pi.fd, PIOCSRLC, 0);
+#endif
+#endif
+ if (result)
{
print_sys_errmsg (pi.pathname, errno);
- printf ("PIOCRUN failed.\n");
+ printf ("PIOCSRLC or PIOCSET failed.\n");
}
}
}
}
else
{
- (void) memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
+ memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
sip = &newsiginfo;
sip -> si_signo = signo;
sip -> si_code = 0;
}
else
{
- (void) memcpy ((char *) &pi.gregset, core_reg_sect,
- sizeof (pi.gregset));
+ memcpy ((char *) &pi.gregset, core_reg_sect, sizeof (pi.gregset));
supply_gregset (&pi.gregset);
}
}
}
else
{
- (void) memcpy ((char *) &pi.fpregset, core_reg_sect,
- sizeof (pi.fpregset));
+ memcpy ((char *) &pi.fpregset, core_reg_sect, sizeof (pi.fpregset));
#if defined (FP0_REGNUM)
supply_fpregset (&pi.fpregset);
#endif
char *why;
{
print_sys_errmsg (pi.pathname, errno);
- (void) kill (pi.pid, SIGKILL);
+ kill (pi.pid, SIGKILL);
close_proc_file (&pi);
error (why);
/* NOTREACHED */
pip -> pid = 0;
if (pip -> valid)
{
- (void) close (pip -> fd);
+ close (pip -> fd);
}
pip -> fd = -1;
if (pip -> pathname)
SYNOPSIS
- static int open_proc_file (pid, struct procinfo *pip)
+ static int open_proc_file (int pid, struct procinfo *pip, int mode)
DESCRIPTION
- Given a process id, close the existing open /proc entry (if any)
- and open one for the new process id. Once it is open, then
- mark the local process information structure as valid, which
- guarantees that the pid, fd, and pathname fields match an open
- /proc entry. Returns zero if the open fails, nonzero otherwise.
+ Given a process id and a mode, close the existing open /proc
+ entry (if any) and open one for the new process id, in the
+ specified mode. Once it is open, then mark the local process
+ information structure as valid, which guarantees that the pid,
+ fd, and pathname fields match an open /proc entry. Returns
+ zero if the open fails, nonzero otherwise.
Note that the pathname is left intact, even when the open fails,
so that callers can use it to construct meaningful error messages
*/
static int
-open_proc_file (pid, pip)
+open_proc_file (pid, pip, mode)
int pid;
struct procinfo *pip;
+ int mode;
{
- pip -> valid = 0;
+ pip -> valid = 0; /* FIXME, what is this? ?! */
if (pip -> valid)
{
- (void) close (pip -> fd);
+ close (pip -> fd);
}
if (pip -> pathname == NULL)
{
pip -> pathname = xmalloc (32);
}
sprintf (pip -> pathname, PROC_NAME_FMT, pid);
- if ((pip -> fd = open (pip -> pathname, O_RDWR)) >= 0)
+ if ((pip -> fd = open (pip -> pathname, mode)) >= 0)
{
pip -> valid = 1;
pip -> pid = pid;
{
pid = pii.pid;
pip = &pii;
- (void) memset (&pii, 0, sizeof (pii));
- if (!open_proc_file (pid, pip))
+ memset (&pii, 0, sizeof (pii));
+ if (!open_proc_file (pid, pip, O_RDONLY))
{
perror_with_name (pip -> pathname);
/* NOTREACHED */