diff options
author | Michael Snyder <msnyder@vmware.com> | 2000-05-05 20:56:10 +0000 |
---|---|---|
committer | Michael Snyder <msnyder@vmware.com> | 2000-05-05 20:56:10 +0000 |
commit | 103b3ef54f8d3711039fe1dfe18b109e5dac322b (patch) | |
tree | 40b86899df0c0c1a233c429184b53327fdd2b96c /gdb | |
parent | b8d39351ea5eabfa364474f006b1556f40f0f636 (diff) | |
download | gdb-103b3ef54f8d3711039fe1dfe18b109e5dac322b.zip gdb-103b3ef54f8d3711039fe1dfe18b109e5dac322b.tar.gz gdb-103b3ef54f8d3711039fe1dfe18b109e5dac322b.tar.bz2 |
2000-05-05 Michael Snyder <msnyder@seadog.cygnus.com>
* procfs.c: Cleanup of procfs tracing. Move defines and
prototypes to proc-utils.h
* proc-utils.h: Define tracing macros. Declare trace functions.
* proc-api.c: Make procfs tracing a runtime option.
(prepare_to_trace): New function, abstracted out of several
places. Open a trace file if one is required.
(ioctl_with_trace, write_with_trace, open_with_trace,
close_with_trace, wait_with_trace, lseek_with_trace):
Report errno if an error occurs in a system call.
(write_with_trace): Make 2nd arg void *, to agree with write.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 13 | ||||
-rw-r--r-- | gdb/proc-api.c | 152 | ||||
-rw-r--r-- | gdb/proc-utils.h | 48 | ||||
-rw-r--r-- | gdb/procfs.c | 45 |
4 files changed, 145 insertions, 113 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 987431d..77102a2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2000-05-05 Michael Snyder <msnyder@seadog.cygnus.com> + + * procfs.c: Cleanup of procfs tracing. Move defines and + prototypes to proc-utils.h + * proc-utils.h: Define tracing macros. Declare trace functions. + * proc-api.c: Make procfs tracing a runtime option. + (prepare_to_trace): New function, abstracted out of several + places. Open a trace file if one is required. + (ioctl_with_trace, write_with_trace, open_with_trace, + close_with_trace, wait_with_trace, lseek_with_trace): + Report errno if an error occurs in a system call. + (write_with_trace): Make 2nd arg void *, to agree with write. + 2000-05-05 Elena Zannoni <ezannoni@kwikemart.cygnus.com> * elfread.c (elf_symtab_read): The calculation of 'offset' diff --git a/gdb/proc-api.c b/gdb/proc-api.c index 7ee9bf3..771a28e 100644 --- a/gdb/proc-api.c +++ b/gdb/proc-api.c @@ -53,12 +53,20 @@ struct trans { 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 from_tty; @@ -218,11 +226,10 @@ ioctl_with_trace (fd, opcode, ptr, file, line) { 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; @@ -364,13 +371,15 @@ ioctl_with_trace (fd, opcode, ptr, file, line) 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); } @@ -438,22 +447,21 @@ static struct trans rw_table[] = { 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; @@ -582,13 +590,15 @@ write_with_trace (fd, arg, len, file, line) 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); } @@ -607,34 +617,15 @@ lseek_with_trace (fd, offset, whence, file, line) { 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); } @@ -651,24 +642,37 @@ open_with_trace (filename, mode, file, line) 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); } @@ -682,18 +686,22 @@ close_with_trace (fd, file, line) 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); } @@ -701,7 +709,7 @@ close_with_trace (fd, file, line) return ret; } -int +pid_t wait_with_trace (wstat, file, line) int *wstat; char *file; @@ -709,11 +717,9 @@ wait_with_trace (wstat, file, line) { 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); @@ -722,11 +728,16 @@ wait_with_trace (wstat, 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); } @@ -742,11 +753,9 @@ procfs_note (msg, file, line) 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); @@ -763,11 +772,9 @@ proc_prettyfprint_status (flags, why, what, thread) 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); @@ -791,7 +798,7 @@ _initialize_proc_api () 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; @@ -802,9 +809,4 @@ _initialize_proc_api () 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 } diff --git a/gdb/proc-utils.h b/gdb/proc-utils.h index cdab0c3..08b0cc7 100644 --- a/gdb/proc-utils.h +++ b/gdb/proc-utils.h @@ -18,12 +18,18 @@ along with this program; if not, write to the Free Software Foundation, 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); @@ -43,10 +49,46 @@ extern void 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 diff --git a/gdb/procfs.c b/gdb/procfs.c index 9f1dc10..7961458 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -38,8 +38,6 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <signal.h> #include <ctype.h> -#include "proc-utils.h" - /* * PROCFS.C * @@ -85,6 +83,13 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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" =================== */ /* @@ -154,8 +159,8 @@ init_procfs_ops () 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; @@ -167,36 +172,6 @@ init_procfs_ops () /* =================== 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: * * Put any typedefs, defines etc. here that are required for @@ -4460,7 +4435,7 @@ unconditionally_kill_inferior (pi) } #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); |