| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 1 | #if HAVE_CONFIG_H |
| 2 | #include "config.h" |
| 3 | #endif |
| 4 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 5 | #include <string.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> |
| Juan Cespedes | 1b9cfd6 | 1999-08-30 19:34:50 +0200 | [diff] [blame] | 8 | #include <fcntl.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <limits.h> |
| 11 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 12 | #if HAVE_GETOPT_H |
| 13 | #include <getopt.h> |
| 14 | #endif |
| 15 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 16 | #include "ltrace.h" |
| 17 | #include "options.h" |
| 18 | #include "defs.h" |
| 19 | |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 20 | #define MAX_LIBRARY 30 |
| 21 | char *library[MAX_LIBRARY]; |
| 22 | int library_num = 0; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 23 | static char *progname; /* Program name (`ltrace') */ |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 24 | FILE *output; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 25 | int opt_a = DEFAULT_ACOLUMN; /* default alignment column for results */ |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 26 | int opt_c = 0; /* Count time, calls, and report a summary on program exit */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 27 | int opt_d = 0; /* debug */ |
| 28 | int opt_i = 0; /* instruction pointer */ |
| 29 | int opt_s = DEFAULT_STRLEN; /* default maximum # of bytes printed in strings */ |
| 30 | int opt_S = 0; /* display syscalls */ |
| 31 | int opt_L = 1; /* display library calls */ |
| 32 | int opt_f = 0; /* trace child processes as they are created */ |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 33 | char *opt_u = NULL; /* username to run command as */ |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 34 | int opt_r = 0; /* print relative timestamp */ |
| Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 35 | int opt_t = 0; /* print absolute timestamp */ |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 36 | #ifdef USE_DEMANGLE |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 37 | int opt_C = 0; /* Demangle low-level symbol names into user-level names */ |
| 38 | #endif |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 39 | int opt_n = 0; /* indent trace output according to program flow */ |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 40 | int opt_T = 0; /* show the time spent inside each call */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 41 | |
| 42 | /* List of pids given to option -p: */ |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 43 | struct opt_p_t *opt_p = NULL; /* attach to process with a given pid */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 44 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 45 | /* List of function names given to option -e: */ |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 46 | struct opt_e_t *opt_e = NULL; |
| 47 | int opt_e_enable = 1; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 48 | |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 49 | static void usage(void) |
| 50 | { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 51 | #if !(HAVE_GETOPT || HAVE_GETOPT_LONG) |
| 52 | fprintf(stdout, "Usage: %s [command [arg ...]]\n" |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 53 | "Trace library calls of a given program.\n\n", progname); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 54 | #else |
| 55 | fprintf(stdout, "Usage: %s [option ...] [command [arg ...]]\n" |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 56 | "Trace library calls of a given program.\n\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 57 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 58 | " -a, --align=COLUMN align return values in a secific column.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 59 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 60 | " -a COLUMN align return values in a secific column.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 61 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 62 | " -c count time and calls, and report a summary on exit.\n" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 63 | # ifdef USE_DEMANGLE |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 64 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 65 | " -C, --demangle decode low-level symbol names into user-level names.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 66 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 67 | " -C decode low-level symbol names into user-level names.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 68 | # endif |
| 69 | # endif |
| 70 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 71 | " -d, --debug print debugging info.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 72 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 73 | " -d print debugging info.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 74 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 75 | " -e expr modify which events to trace.\n" |
| 76 | " -f follow forks.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 77 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 78 | " -h, --help display this help and exit.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 79 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 80 | " -h display this help and exit.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 81 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 82 | " -i print instruction pointer at time of library call.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 83 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 84 | " -l, --library=FILE print library calls from this library only.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 85 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 86 | " -l FILE print library calls from this library only.\n" |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 87 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 88 | " -L do NOT display library calls.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 89 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 90 | " -n, --indent=NR indent output by NR spaces for each call level nesting.\n" |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 91 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 92 | " -n NR indent output by NR spaces for each call level nesting.\n" |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 93 | # endif |
| 94 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 95 | " -o, --output=FILE write the trace output to that file.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 96 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 97 | " -o FILE write the trace output to that file.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 98 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 99 | " -p PID attach to the process with the process ID pid.\n" |
| 100 | " -r print relative timestamps.\n" |
| 101 | " -s STRLEN specify the maximum string size to print.\n" |
| 102 | " -S display system calls.\n" |
| 103 | " -t, -tt, -ttt print absolute timestamps.\n" |
| 104 | " -T show the time spent inside each call.\n" |
| 105 | " -u USERNAME run command with the userid, groupid of username.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 106 | # if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 107 | " -V, --version output version information and exit.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 108 | # else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 109 | " -V output version information and exit.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 110 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 111 | "\nReport bugs to Juan Cespedes <cespedes@debian.org>\n", |
| 112 | progname); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 113 | #endif |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 116 | static char *search_for_command(char *filename) |
| 117 | { |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 118 | static char pathname[PATH_MAX]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 119 | char *path; |
| 120 | int m, n; |
| 121 | |
| 122 | if (strchr(filename, '/')) { |
| 123 | return filename; |
| 124 | } |
| 125 | for (path = getenv("PATH"); path && *path; path += m) { |
| 126 | if (strchr(path, ':')) { |
| 127 | n = strchr(path, ':') - path; |
| 128 | m = n + 1; |
| 129 | } else { |
| 130 | m = n = strlen(path); |
| 131 | } |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 132 | if (n + strlen(filename) + 1 >= PATH_MAX) { |
| 133 | fprintf(stderr, "Error: filename too long\n"); |
| 134 | exit(1); |
| 135 | } |
| 136 | strncpy(pathname, path, n); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 137 | if (n && pathname[n - 1] != '/') { |
| 138 | pathname[n++] = '/'; |
| 139 | } |
| 140 | strcpy(pathname + n, filename); |
| 141 | if (!access(pathname, X_OK)) { |
| 142 | return pathname; |
| 143 | } |
| 144 | } |
| 145 | return filename; |
| 146 | } |
| 147 | |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 148 | char **process_options(int argc, char **argv) |
| 149 | { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 150 | progname = argv[0]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 151 | output = stderr; |
| 152 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 153 | #if HAVE_GETOPT || HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 154 | while (1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 155 | int c; |
| 156 | #if HAVE_GETOPT_LONG |
| 157 | int option_index = 0; |
| 158 | static struct option long_options[] = { |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 159 | {"align", 1, 0, 'a'}, |
| 160 | {"debug", 0, 0, 'd'}, |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 161 | # ifdef USE_DEMANGLE |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 162 | {"demangle", 0, 0, 'C'}, |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 163 | #endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 164 | {"indent", 1, 0, 'n'}, |
| 165 | {"help", 0, 0, 'h'}, |
| 166 | {"library", 1, 0, 'l'}, |
| 167 | {"output", 1, 0, 'o'}, |
| 168 | {"version", 0, 0, 'V'}, |
| 169 | {0, 0, 0, 0} |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 170 | }; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 171 | c = getopt_long(argc, argv, "+cdfhiLrStTV" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 172 | # ifdef USE_DEMANGLE |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 173 | "C" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 174 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 175 | "a:e:l:n:o:p:s:u:", long_options, |
| 176 | &option_index); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 177 | #else |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 178 | c = getopt(argc, argv, "+cdfhiLrStTV" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 179 | # ifdef USE_DEMANGLE |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 180 | "C" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 181 | # endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 182 | "a:e:l:n:o:p:s:u:"); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 183 | #endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 184 | if (c == -1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 185 | break; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 186 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 187 | switch (c) { |
| 188 | case 'a': |
| 189 | opt_a = atoi(optarg); |
| 190 | break; |
| 191 | case 'c': |
| 192 | opt_c++; |
| 193 | break; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 194 | #ifdef USE_DEMANGLE |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 195 | case 'C': |
| 196 | opt_C++; |
| 197 | break; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 198 | #endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 199 | case 'd': |
| 200 | opt_d++; |
| 201 | break; |
| 202 | case 'e': |
| 203 | { |
| 204 | char *str_e = strdup(optarg); |
| 205 | if (!str_e) { |
| 206 | perror("ltrace: strdup"); |
| 207 | exit(1); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 208 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 209 | if (str_e[0] == '!') { |
| 210 | opt_e_enable = 0; |
| 211 | str_e++; |
| 212 | } |
| 213 | while (*str_e) { |
| 214 | struct opt_e_t *tmp; |
| 215 | char *str2 = strchr(str_e, ','); |
| 216 | if (str2) { |
| 217 | *str2 = '\0'; |
| 218 | } |
| 219 | tmp = malloc(sizeof(struct opt_e_t)); |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 220 | if (!tmp) { |
| 221 | perror("ltrace: malloc"); |
| 222 | exit(1); |
| 223 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 224 | tmp->name = str_e; |
| 225 | tmp->next = opt_e; |
| 226 | opt_e = tmp; |
| 227 | if (str2) { |
| 228 | str_e = str2 + 1; |
| 229 | } else { |
| 230 | break; |
| 231 | } |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 232 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | case 'f': |
| 236 | opt_f = 1; |
| 237 | break; |
| 238 | case 'h': |
| 239 | usage(); |
| 240 | exit(0); |
| 241 | case 'i': |
| 242 | opt_i++; |
| 243 | break; |
| 244 | case 'l': |
| 245 | if (library_num == MAX_LIBRARY) { |
| 246 | fprintf(stderr, |
| 247 | "Too many libraries. Maximum is %i.\n", |
| 248 | MAX_LIBRARY); |
| 249 | exit(1); |
| 250 | } |
| 251 | library[library_num++] = optarg; |
| 252 | break; |
| 253 | case 'L': |
| 254 | opt_L = 0; |
| 255 | break; |
| 256 | case 'n': |
| 257 | opt_n = atoi(optarg); |
| 258 | break; |
| 259 | case 'o': |
| 260 | output = fopen(optarg, "w"); |
| 261 | if (!output) { |
| 262 | fprintf(stderr, |
| 263 | "Can't open %s for output: %s\n", |
| 264 | optarg, strerror(errno)); |
| 265 | exit(1); |
| 266 | } |
| 267 | setvbuf(output, (char *)NULL, _IOLBF, 0); |
| 268 | fcntl(fileno(output), F_SETFD, FD_CLOEXEC); |
| 269 | break; |
| 270 | case 'p': |
| 271 | { |
| 272 | struct opt_p_t *tmp = |
| 273 | malloc(sizeof(struct opt_p_t)); |
| 274 | if (!tmp) { |
| 275 | perror("ltrace: malloc"); |
| 276 | exit(1); |
| 277 | } |
| 278 | tmp->pid = atoi(optarg); |
| 279 | tmp->next = opt_p; |
| 280 | opt_p = tmp; |
| 281 | break; |
| 282 | } |
| 283 | case 'r': |
| 284 | opt_r++; |
| 285 | break; |
| 286 | case 's': |
| 287 | opt_s = atoi(optarg); |
| 288 | break; |
| 289 | case 'S': |
| 290 | opt_S = 1; |
| 291 | break; |
| 292 | case 't': |
| 293 | opt_t++; |
| 294 | break; |
| 295 | case 'T': |
| 296 | opt_T++; |
| 297 | break; |
| 298 | case 'u': |
| 299 | opt_u = optarg; |
| 300 | break; |
| 301 | case 'V': |
| Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame^] | 302 | printf("ltrace version " PACKAGE_VERSION ".\n" |
| 303 | "Copyright (C) 1997-2006 Juan Cespedes <cespedes@debian.org>.\n" |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 304 | "This is free software; see the GNU General Public Licence\n" |
| 305 | "version 2 or later for copying conditions. There is NO warranty.\n"); |
| 306 | exit(0); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 307 | |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 308 | default: |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 309 | #if HAVE_GETOPT_LONG |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 310 | fprintf(stderr, |
| 311 | "Try `%s --help' for more information\n", |
| 312 | progname); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 313 | #else |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 314 | fprintf(stderr, "Try `%s -h' for more information\n", |
| 315 | progname); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 316 | #endif |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 317 | exit(1); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 318 | } |
| 319 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 320 | argc -= optind; |
| 321 | argv += optind; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 322 | #endif |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 323 | |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 324 | if (!opt_p && argc < 1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 325 | fprintf(stderr, "%s: too few arguments\n", progname); |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 326 | usage(); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 327 | exit(1); |
| 328 | } |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 329 | if (opt_r && opt_t) { |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 330 | fprintf(stderr, "%s: Incompatible options -r and -t\n", |
| 331 | progname); |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 332 | exit(1); |
| 333 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 334 | if (argc > 0) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 335 | command = search_for_command(argv[0]); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 336 | } |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 337 | return &argv[0]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 338 | } |