#include <signal.h>
#include <ctype.h>
-#include "proc-utils.h"
-
/*
* PROCFS.C
*
#include <unistd.h> /* for "X_OK" */
#include "gdb_stat.h" /* for struct stat */
+/* Note: procfs-utils.h must be included after the above system header
+ files, because it redefines various system calls using macros.
+ This may be incompatible with the prototype declarations. */
+
+#include "proc-utils.h"
+
/* =================== TARGET_OPS "MODULE" =================== */
/*
procfs_ops.to_thread_alive = procfs_thread_alive;
procfs_ops.to_pid_to_str = procfs_pid_to_str;
+ procfs_ops.to_has_all_memory = 1;
+ procfs_ops.to_has_memory = 1;
procfs_ops.to_has_execution = 1;
procfs_ops.to_has_stack = 1;
procfs_ops.to_has_registers = 1;
/* =================== END, TARGET_OPS "MODULE" =================== */
-/*
- * Temporary debugging code:
- *
- * These macros allow me to trace the system calls that we make
- * to control the child process. This is quite handy for comparing
- * with the older version of procfs.
- */
-
-#ifdef TRACE_PROCFS
-#ifdef NEW_PROC_API
-extern int write_with_trace PARAMS ((int, void *, size_t, char *, int));
-extern off_t lseek_with_trace PARAMS ((int, off_t, int, char *, int));
-#define write(X,Y,Z) write_with_trace (X, Y, Z, __FILE__, __LINE__)
-#define lseek(X,Y,Z) lseek_with_trace (X, Y, Z, __FILE__, __LINE__)
-#else
-extern int ioctl_with_trace PARAMS ((int, long, void *, char *, int));
-#define ioctl(X,Y,Z) ioctl_with_trace (X, Y, Z, __FILE__, __LINE__)
-#endif
-#define open(X,Y) open_with_trace (X, Y, __FILE__, __LINE__)
-#define close(X) close_with_trace (X, __FILE__, __LINE__)
-#define wait(X) wait_with_trace (X, __FILE__, __LINE__)
-#define PROCFS_NOTE(X) procfs_note (X, __FILE__, __LINE__)
-#define PROC_PRETTYFPRINT_STATUS(X,Y,Z,T) \
-proc_prettyfprint_status (X, Y, Z, T)
-#else
-#define PROCFS_NOTE(X)
-#define PROC_PRETTYFPRINT_STATUS(X,Y,Z,T)
-#endif
-
-
/*
* World Unification:
*
* Function: create_procinfo
*
* Allocate a data structure and link it into the procinfo list.
- * (First tries to find a pre-existing one (FIXME: why???)
+ * (First tries to find a pre-existing one (FIXME: why?)
*
* Return: pointer to new procinfo struct.
*/
else
{
#ifdef NEW_PROC_API
- int cmd = PCSTOP;
+ long cmd = PCSTOP;
win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
#else /* ioctl method */
win = (ioctl (pi->ctl_fd, PIOCSTOP, &pi->prstatus) >= 0);
#ifdef NEW_PROC_API
{
- int cmd = PCWSTOP;
+ long cmd = PCWSTOP;
win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
/* We been runnin' and we stopped -- need to update status. */
pi->status_valid = 0;
#ifdef NEW_PROC_API
{
- int cmd[2];
+ long cmd[2];
cmd[0] = PCRUN;
cmd[1] = runflags;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sigset[sizeof (sigset_t)];
} arg;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char fltset[sizeof (fltset_t)];
} arg;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sysset[sizeof (sysset_t)];
} arg;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sysset[sizeof (sysset_t)];
} arg;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char hold[sizeof (sigset_t)];
} arg;
#ifdef NEW_PROC_API
{
- int cmd = PCCFAULT;
+ long cmd = PCCFAULT;
win = (write (pi->ctl_fd, (void *) &cmd, sizeof (cmd)) == sizeof (cmd));
}
#else
{
int win;
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sinfo[sizeof (struct siginfo)];
} arg;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sinfo[sizeof (struct siginfo)];
} arg;
{
#ifdef NEW_PROC_API
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char gregs[sizeof (gdb_gregset_t)];
} arg;
{
#ifdef NEW_PROC_API
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char fpregs[sizeof (gdb_fpregset_t)];
} arg;
else
{
#ifdef NEW_PROC_API
- int cmd[2];
+ long cmd[2];
cmd[0] = PCKILL;
cmd[1] = signo;
int
proc_set_watchpoint (pi, addr, len, wflags)
- procinfo *pi;
- void *addr;
+ procinfo *pi;
+ CORE_ADDR addr;
int len;
int wflags;
{
return 0;
#else
struct {
- int cmd;
+ long cmd;
char watch[sizeof (prwatch_t)];
} arg;
prwatch_t *pwatch;
* is resumed.
*/
+/* These could go in a header file, but the many and various
+ definitions of gregset_t would make it tricky and ugly. Several
+ different native operating systems (notably Solaris and Linux) have
+ various different definitions for gregset_t and fpregset_t. We
+ have been kludging around this problem for a while, it would be
+ nice if someday we came up with a prettier way of handling it
+ (FIXME). */
+
+extern void fill_gregset (gdb_gregset_t *, int);
+extern void fill_fpregset (gdb_fpregset_t *, int);
+extern void supply_gregset (gdb_gregset_t *);
+extern void supply_fpregset (gdb_fpregset_t *);
+
static void
procfs_fetch_registers (regno)
int regno;
supply_gregset (gregs);
-#if defined (FP0_REGNUM) /* need floating point? */
- if ((regno >= 0 && regno < FP0_REGNUM) ||
- regno == PC_REGNUM ||
-#ifdef NPC_REGNUM
- regno == NPC_REGNUM ||
-#endif
- regno == FP_REGNUM ||
- regno == SP_REGNUM)
- return; /* not a floating point register */
+ if (FP0_REGNUM >= 0) /* need floating point? */
+ {
+ if ((regno >= 0 && regno < FP0_REGNUM) ||
+ regno == PC_REGNUM ||
+ (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
+ regno == FP_REGNUM ||
+ regno == SP_REGNUM)
+ return; /* not a floating point register */
- if ((fpregs = proc_get_fpregs (pi)) == NULL)
- proc_error (pi, "fetch_registers, get_fpregs", __LINE__);
+ if ((fpregs = proc_get_fpregs (pi)) == NULL)
+ proc_error (pi, "fetch_registers, get_fpregs", __LINE__);
- supply_fpregset (fpregs);
-#endif
+ supply_fpregset (fpregs);
+ }
}
/* Get ready to modify the registers array. On machines which store
if (!proc_set_gregs (pi))
proc_error (pi, "store_registers, set_gregs", __LINE__);
-#if defined (FP0_REGNUM) /* need floating point? */
- if ((regno >= 0 && regno < FP0_REGNUM) ||
- regno == PC_REGNUM ||
-#ifdef NPC_REGNUM
- regno == NPC_REGNUM ||
-#endif
- regno == FP_REGNUM ||
- regno == SP_REGNUM)
- return; /* not a floating point register */
-
- if ((fpregs = proc_get_fpregs (pi)) == NULL)
- proc_error (pi, "store_registers, get_fpregs", __LINE__);
-
- fill_fpregset (fpregs, regno);
- if (!proc_set_fpregs (pi))
- proc_error (pi, "store_registers, set_fpregs", __LINE__);
-#endif
+ if (FP0_REGNUM >= 0) /* need floating point? */
+ {
+ if ((regno >= 0 && regno < FP0_REGNUM) ||
+ regno == PC_REGNUM ||
+ (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
+ regno == FP_REGNUM ||
+ regno == SP_REGNUM)
+ return; /* not a floating point register */
+
+ if ((fpregs = proc_get_fpregs (pi)) == NULL)
+ proc_error (pi, "store_registers, get_fpregs", __LINE__);
+
+ fill_fpregset (fpregs, regno);
+ if (!proc_set_fpregs (pi))
+ proc_error (pi, "store_registers, set_fpregs", __LINE__);
+ }
}
/*
return a "success" exit code. Bogus: what if
it returns something else? */
wstat = 0;
- retval = inferior_pid; /* ??? */
+ retval = inferior_pid; /* ? ? ? */
}
else
{
{
printf_filtered ("%ld syscall arguments:\n", nsysargs);
for (i = 0; i < nsysargs; i++)
- printf_filtered ("#%ld: 0x%08x\n",
+ printf_filtered ("#%ld: 0x%08lx\n",
i, sysargs[i]);
}
{
printf_filtered ("%ld syscall arguments:\n", nsysargs);
for (i = 0; i < nsysargs; i++)
- printf_filtered ("#%ld: 0x%08x\n",
+ printf_filtered ("#%ld: 0x%08lx\n",
i, sysargs[i]);
}
}
if (!proc_set_gregs (pi)) /* flush gregs cache */
proc_warn (pi, "target_resume, set_gregs",
__LINE__);
-#ifdef FP0_REGNUM
- if (pi->fpregs_dirty)
- if (parent == NULL ||
- proc_get_current_thread (parent) != pi->tid)
- if (!proc_set_fpregs (pi)) /* flush fpregs cache */
- proc_warn (pi, "target_resume, set_fpregs",
- __LINE__);
-#endif
+ if (FP0_REGNUM >= 0)
+ if (pi->fpregs_dirty)
+ if (parent == NULL ||
+ proc_get_current_thread (parent) != pi->tid)
+ if (!proc_set_fpregs (pi)) /* flush fpregs cache */
+ proc_warn (pi, "target_resume, set_fpregs",
+ __LINE__);
#endif
if (parent != NULL)
}
#else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
if (!proc_kill (pi, SIGKILL))
- proc_warn (pi, "unconditionally_kill, proc_kill", __LINE__);
+ proc_error (pi, "unconditionally_kill, proc_kill", __LINE__);
#endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
destroy_procinfo (pi);
}
-int
-mapping_test (fd, core_addr)
- int fd;
- CORE_ADDR core_addr;
-{
- printf ("File descriptor %d, base address 0x%08x\n", fd, core_addr);
- if (fd > 0)
- close (fd);
- return 0;
-}
-
-void
-test_mapping_cmd (args, from_tty)
- char *args;
- int from_tty;
-{
- int ret;
- ret = proc_iterate_over_mappings (mapping_test);
- printf ("iterate_over_mappings returned %d.\n", ret);
-}
-
void
_initialize_procfs ()
{
"Cancel a trace of entries into the syscall.");
add_com ("proc-untrace-exit", no_class, proc_untrace_sysexit_cmd,
"Cancel a trace of exits from the syscall.");
-
- add_com ("test-mapping", no_class, test_mapping_cmd,
- "test iterate-over-mappings");
}
/* =================== END, GDB "MODULE" =================== */
else
return -1;
}
-
-int
-procfs_get_pid_fd (pid)
- int pid;
-{
- procinfo *pi;
-
- if (pid == -1 && inferior_pid != 0)
- pi = find_procinfo (PIDGET (inferior_pid), 0);
- else
- pi = find_procinfo (PIDGET (pid), 0);
-
- if (pi)
- return pi->ctl_fd;
- else
- return -1;
-}