char *desc; /* Short description of value */
};
-static int procfs_trace = 1;
-/*static int info_verbose = 1;*/ /* kludge */
+static int procfs_trace = 0;
static FILE *procfs_file = NULL;
static char *procfs_filename = "procfs_trace";
+static void
+prepare_to_trace (void)
+{
+ if (procfs_trace) /* if procfs tracing turned on */
+ if (procfs_file == NULL) /* if output file not yet open */
+ if (procfs_filename != NULL) /* if output filename known */
+ procfs_file = fopen (procfs_filename, "a"); /* open output file */
+}
+
static void
set_procfs_trace_cmd (args, from_tty, c)
char *args;
{
int i, ret, arg1;
+ prepare_to_trace ();
+
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
for (i = 0; ioctl_table[i].name != NULL; i++)
if (ioctl_table[i].value == opcode)
break;
if (procfs_file)
fflush (procfs_file);
}
+ errno = 0;
ret = ioctl (fd, opcode, ptr);
if (procfs_trace && ret < 0)
{
fprintf (procfs_file ? procfs_file : stdout,
- "[ioctl (%s) FAILED!]\n",
+ "[ioctl (%s) FAILED! (%s)]\n",
ioctl_table[i].name != NULL ?
- ioctl_table[i].name : "<unknown>");
+ ioctl_table[i].name : "<unknown>",
+ safe_strerror (errno));
if (procfs_file)
fflush (procfs_file);
}
static off_t lseek_offset;
int
-write_with_trace (fd, arg, len, file, line)
+write_with_trace (fd, varg, len, file, line)
int fd;
- long *arg;
+ void *varg;
size_t len;
char *file;
int line;
{
int i;
int ret;
- long opcode = arg[0];
+ long *arg = (long *) varg;
+ prepare_to_trace ();
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
+ long opcode = arg[0];
for (i = 0; rw_table[i].name != NULL; i++)
if (rw_table[i].value == opcode)
break;
if (procfs_file)
fflush (procfs_file);
}
+ errno = 0;
ret = write (fd, (void *) arg, len);
if (procfs_trace && ret != len)
{
fprintf (procfs_file ? procfs_file : stdout,
- "[write (%s) FAILED!\n",
+ "[write (%s) FAILED! (%s)]\n",
rw_table[i].name != NULL ?
- rw_table[i].name : "<unknown>");
+ rw_table[i].name : "<unknown>",
+ safe_strerror (errno));
if (procfs_file)
fflush (procfs_file);
}
{
off_t ret;
-#if 0 /* don't need output, just need address */
- if (procfs_trace)
- {
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
- if (info_verbose)
- fprintf (procfs_file ? procfs_file : stdout,
- "%s:%d -- ", file, line);
- fprintf (procfs_file ? procfs_file : stdout,
- "lseek (0x%08x, %s) \n", offset,
- whence == SEEK_SET ? "SEEK_SET" :
- whence == SEEK_CUR ? "SEEK_CUR" :
- whence == SEEK_END ? "SEEK_END" :
- "<unknown whence>");
- if (procfs_file)
- fflush (procfs_file);
- }
-#endif
+ prepare_to_trace ();
+ errno = 0;
ret = lseek (fd, offset, whence);
lseek_offset = ret;
- if (procfs_trace && ret == -1)
+ if (procfs_trace && (ret == -1 || errno != 0))
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
fprintf (procfs_file ? procfs_file : stdout,
- "[lseek (0x%08lx) FAILED!\n", (unsigned long) offset);
+ "[lseek (0x%08lx) FAILED! (%s)]\n",
+ (unsigned long) offset, safe_strerror (errno));
if (procfs_file)
fflush (procfs_file);
}
char *file;
int line;
{
- int ret = open (filename, mode);
+ int ret;
+ prepare_to_trace ();
+ errno = 0;
+ ret = open (filename, mode);
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
if (info_verbose)
fprintf (procfs_file ? procfs_file : stdout,
"%s:%d -- ", file, line);
- fprintf (procfs_file ? procfs_file : stdout,
- "%d = open (%s, ", ret, filename);
- if (mode == O_RDONLY)
- fprintf (procfs_file ? procfs_file : stdout, "O_RDONLY) %d\n", line);
- else if (mode == O_WRONLY)
- fprintf (procfs_file ? procfs_file : stdout, "O_WRONLY) %d\n", line);
- else if (mode == O_RDWR)
- fprintf (procfs_file ? procfs_file : stdout, "O_RDWR) %d\n", line);
+
+ if (errno)
+ {
+ fprintf (procfs_file ? procfs_file : stdout,
+ "[open FAILED! (%s) line %d]\\n",
+ safe_strerror (errno), line);
+ }
+ else
+ {
+ fprintf (procfs_file ? procfs_file : stdout,
+ "%d = open (%s, ", ret, filename);
+ if (mode == O_RDONLY)
+ fprintf (procfs_file ? procfs_file : stdout, "O_RDONLY) %d\n",
+ line);
+ else if (mode == O_WRONLY)
+ fprintf (procfs_file ? procfs_file : stdout, "O_WRONLY) %d\n",
+ line);
+ else if (mode == O_RDWR)
+ fprintf (procfs_file ? procfs_file : stdout, "O_RDWR) %d\n",
+ line);
+ }
if (procfs_file)
fflush (procfs_file);
}
char *file;
int line;
{
- int ret = close (fd);
+ int ret;
+ prepare_to_trace ();
+ errno = 0;
+ ret = close (fd);
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
if (info_verbose)
fprintf (procfs_file ? procfs_file : stdout,
"%s:%d -- ", file, line);
- fprintf (procfs_file ? procfs_file : stdout,
- "%d = close (%d)\n", ret, fd);
+ if (errno)
+ fprintf (procfs_file ? procfs_file : stdout,
+ "[close FAILED! (%s)]\n", safe_strerror (errno));
+ else
+ fprintf (procfs_file ? procfs_file : stdout,
+ "%d = close (%d)\n", ret, fd);
if (procfs_file)
fflush (procfs_file);
}
return ret;
}
-int
+pid_t
wait_with_trace (wstat, file, line)
int *wstat;
char *file;
{
int ret, lstat = 0;
+ prepare_to_trace ();
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
if (info_verbose)
fprintf (procfs_file ? procfs_file : stdout,
"%s:%d -- ", file, line);
if (procfs_file)
fflush (procfs_file);
}
+ errno = 0;
ret = wait (&lstat);
if (procfs_trace)
{
- fprintf (procfs_file ? procfs_file : stdout,
- "returned pid %d, status 0x%x\n", ret, lstat);
+ if (errno)
+ fprintf (procfs_file ? procfs_file : stdout,
+ "[wait FAILED! (%s)]\n", safe_strerror (errno));
+ else
+ fprintf (procfs_file ? procfs_file : stdout,
+ "returned pid %d, status 0x%x\n", ret, lstat);
if (procfs_file)
fflush (procfs_file);
}
char *file;
int line;
{
+ prepare_to_trace ();
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
if (info_verbose)
fprintf (procfs_file ? procfs_file : stdout,
"%s:%d -- ", file, line);
int what;
int thread;
{
+ prepare_to_trace ();
if (procfs_trace)
{
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-
if (thread)
fprintf (procfs_file ? procfs_file : stdout,
"Thread %d: ", thread);
c = add_set_cmd ("procfs-trace", no_class,
var_boolean, (char *) &procfs_trace,
- "Set tracing for /proc ioctl calls.\n", &setlist);
+ "Set tracing for /proc api calls.\n", &setlist);
add_show_from_set (c, &showlist);
c->function.sfunc = set_procfs_trace_cmd;
add_show_from_set (c, &showlist);
c->function.sfunc = set_procfs_file_cmd;
-
-#ifdef TRACE_PROCFS
- if (procfs_file == NULL && procfs_filename != NULL)
- procfs_file = fopen (procfs_filename, "a");
-#endif
}
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/*
+ * Pretty-print functions for /proc data
+ */
+
extern void
proc_prettyprint_why (unsigned long why, unsigned long what, int verbose);
-extern void proc_prettyprint_syscalls (sysset_t *sysset, int verbose);
+extern void
+proc_prettyprint_syscalls (sysset_t *sysset, int verbose);
-extern void proc_prettyprint_syscall (int num, int verbose);
+extern void
+proc_prettyprint_syscall (int num, int verbose);
extern void proc_prettyprint_flags (unsigned long flags, int verbose);
proc_prettyfprint_flags (FILE *file, unsigned long flags, int verbose);
extern void
-proc_prettyfprint_why (FILE *file, unsigned long why, unsigned long what, int verbose);
+proc_prettyfprint_why (FILE *file, unsigned long why,
+ unsigned long what, int verbose);
extern void
proc_prettyfprint_fault (FILE *file, int faultno, int verbose);
extern void
proc_prettyfprint_syscalls (FILE *file, sysset_t *sysset, int verbose);
+
+extern void
+proc_prettyfprint_status (long, int, int, int);
+
+/*
+ * Trace functions for /proc api.
+ */
+
+extern int write_with_trace (int, void *, size_t, char *, int);
+extern off_t lseek_with_trace (int, off_t, int, char *, int);
+extern int ioctl_with_trace (int, long, void *, char *, int);
+extern pid_t wait_with_trace (int *, char *, int);
+extern int open_with_trace (char *, int, char *, int);
+extern int close_with_trace (int, char *, int);
+extern void procfs_note (char *, char *, int);
+
+#ifdef PROCFS_TRACE
+/*
+ * 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.
+ */
+
+#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__)
+#define ioctl(X,Y,Z) ioctl_with_trace (X, Y, Z, __FILE__, __LINE__)
+#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)
+#endif
#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. */
+
+#define PROCFS_TRACE
+#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_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:
*
}
#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);