aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-06-06 02:55:10 +0000
committerChristopher Faylor <me@cgf.cx>2002-06-06 02:55:10 +0000
commitba692ae9c05667948df8ba8e6af18c9eed80f337 (patch)
treefa0d58343eeaa3f0d522295584ffb5d650054646
parentf7a7cc906744610f140bd40d0246a992fa6d40c3 (diff)
downloadnewlib-ba692ae9c05667948df8ba8e6af18c9eed80f337.zip
newlib-ba692ae9c05667948df8ba8e6af18c9eed80f337.tar.gz
newlib-ba692ae9c05667948df8ba8e6af18c9eed80f337.tar.bz2
* strace.cc (version): New global variable.
(usage): Accomodate stdout output. (print_version): New function.
-rw-r--r--winsup/utils/ChangeLog6
-rw-r--r--winsup/utils/strace.cc63
2 files changed, 49 insertions, 20 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index c5d7839..011fb88 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,9 @@
+2002-06-05 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
+
+ * strace.cc (version): New global variable.
+ (usage): Accomodate stdout output.
+ (print_version): New function.
+
2002-06-03 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
* ssp.c (version): New global variable.
diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
index 210de3d..aa10ba7 100644
--- a/winsup/utils/strace.cc
+++ b/winsup/utils/strace.cc
@@ -35,7 +35,7 @@ int _impure_ptr;
#define alloca __builtin_alloca
// Version string.
-static const char *version_string = "@(#)strace V1.0, Copyright (C) 2001, 2002 Red Hat Inc., " __DATE__ "\n";
+static const char version[] = "$Revision$";
static const char *pgm;
static int forkdebug = 1;
@@ -782,25 +782,27 @@ parse_mask (const char *ms, char **endptr)
}
static void
-usage ()
+usage (FILE *where = stderr)
{
- fprintf (stderr, "\
-Usage: strace [OPTIONS] <command-line>\n\
+ fprintf (where, "\
+Usage: %s [OPTIONS] <command-line>\n\
-b, --buffer-size=SIZE set size of output file buffer\n\
-d, --no-delta don't display the delta-t microsecond timestamp\n\
-f, --trace-children trace child processes (toggle - default true)\n\
- -h, --help display this help info\n\
+ -h, --help output usage information and exit\n\
-m, --mask=MASK set message filter mask\n\
-o, --output=FILENAME set output file to FILENAME\n\
-p, --pid=n attach to executing program with cygwin pid n\n\
-n, --crack-error-numbers output descriptive text instead of error\n\
numbers for Windows errors\n\
-S, --flush-period=PERIOD flush buffered strace output every PERIOD secs\n\
- -t, --timestamp use an absolute hh:mm:ss timestamp insted of the\n\
- default microsecond timestamp. Implies -d\n\
- -v, --version display version info\n\
+ -t, --timestamp use an absolute hh:mm:ss timestamp insted of \n\
+ the default microsecond timestamp. Implies -d\n\
+ -v, --version output version information and exit\n\
-w, --new-window spawn program under test in a new window\n\
-\n\
+\n", pgm);
+ if ( where == stdout)
+ fprintf (stdout, "\
MASK can be any combination of the following mnemonics and/or hex values\n\
(0x is optional). Combine masks with '+' or ',' like so:\n\
\n\
@@ -822,17 +824,14 @@ Usage: strace [OPTIONS] <command-line>\n\
sigp 0x00800 (_STRACE_SIGP) Trace signal and process handling.\n\
minimal 0x01000 (_STRACE_MINIMAL) Very minimal strace output.\n\
exitdump 0x04000 (_STRACE_EXITDUMP) Dump strace cache on exit.\n\
- system 0x08000 (_STRACE_SYSTEM) Serious error which goes to console and log.\n\
+ system 0x08000 (_STRACE_SYSTEM) Serious error; goes to console and log.\n\
nomutex 0x10000 (_STRACE_NOMUTEX) Don't use mutex for synchronization.\n\
malloc 0x20000 (_STRACE_MALLOC) Trace malloc calls.\n\
thread 0x40000 (_STRACE_THREAD) Thread-locking calls.\n\
");
-}
-
-static void
-version ()
-{
- fputs (version_string + 4, stderr);
+ if (where == stderr)
+ fprintf (stderr, "Try '%s --help' for more information.\n", pgm);
+ exit (where == stderr ? 1 : 0 );
}
struct option longopts[] = {
@@ -854,6 +853,28 @@ struct option longopts[] = {
static const char *const opts = "b:dhfm:no:p:S:tuvw";
+static void
+print_version ()
+{
+ const char *v = strchr (version, ':');
+ int len;
+ if (!v)
+ {
+ v = "?";
+ len = 1;
+ }
+ else
+ {
+ v += 2;
+ len = strchr (v, ' ') - v;
+ }
+ printf ("\
+%s (cygwin) %.*s\n\
+System Trace\n\
+Copyright 2000, 2001, 2002 Red Hat, Inc.\n\
+Compiled on %s", pgm, len, v, __DATE__);
+}
+
int
main (int argc, char **argv)
{
@@ -881,8 +902,7 @@ main (int argc, char **argv)
break;
case 'h':
// Print help and exit
- usage ();
- return 1;
+ usage (stdout);
break;
case 'm':
{
@@ -921,14 +941,17 @@ character #%d.\n", optarg, (int) (endptr - optarg), endptr);
break;
case 'v':
// Print version info and exit
- version ();
- return 1;
+ print_version ();
+ return 0;
break;
case 'w':
new_window ^= 1;
break;
}
+ if ( argv[optind] == NULL)
+ usage ();
+
if (!mask)
mask = 1;