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/proc-api.c | |
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/proc-api.c')
-rw-r--r-- | gdb/proc-api.c | 152 |
1 files changed, 77 insertions, 75 deletions
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 } |