| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 1 | #include "config.h" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 2 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 3 | #include <sys/ioctl.h> |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 4 | #include <assert.h> |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | #include <error.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <getopt.h> |
| 9 | #include <limits.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <unistd.h> |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 13 | |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 14 | #include "common.h" |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 15 | #include "filter.h" |
| 16 | #include "glob.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 17 | |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 18 | #ifndef SYSCONFDIR |
| 19 | #define SYSCONFDIR "/etc" |
| 20 | #endif |
| 21 | |
| Olaf Hering | e948e58 | 2006-10-12 23:53:44 +0200 | [diff] [blame] | 22 | #define SYSTEM_CONFIG_FILE SYSCONFDIR "/ltrace.conf" |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 23 | #define USER_CONFIG_FILE "~/.ltrace.conf" |
| 24 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 25 | struct options_t options = { |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 26 | .align = DEFAULT_ALIGN, /* alignment column for results */ |
| 27 | .user = NULL, /* username to run command as */ |
| 28 | .syscalls = 0, /* display syscalls */ |
| 29 | .libcalls = 1, /* display library calls */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 30 | #ifdef USE_DEMANGLE |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 31 | .demangle = 0, /* Demangle low-level symbol names */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 32 | #endif |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 33 | .indent = 0, /* indent output according to program flow */ |
| 34 | .output = NULL, /* output to a specific file */ |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 35 | .summary = 0, /* Report a summary on program exit */ |
| 36 | .debug = 0, /* debug */ |
| 37 | .arraylen = DEFAULT_ARRAYLEN, /* maximum # array elements to print */ |
| 38 | .strlen = DEFAULT_STRLEN, /* maximum # of bytes printed in strings */ |
| 39 | .follow = 0, /* trace child processes */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 42 | static char *progname; /* Program name (`ltrace') */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 43 | int opt_i = 0; /* instruction pointer */ |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 44 | int opt_r = 0; /* print relative timestamp */ |
| Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 45 | int opt_t = 0; /* print absolute timestamp */ |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 46 | int opt_T = 0; /* show the time spent inside each call */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 47 | |
| 48 | /* List of pids given to option -p: */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 49 | 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] | 50 | |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 51 | /* List of global function names given to -x: */ |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 52 | struct opt_x_t *opt_x = NULL; |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 53 | unsigned int opt_x_cnt = 0; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 54 | |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 55 | /* List of filenames give to option -F: */ |
| 56 | struct opt_F_t *opt_F = NULL; /* alternate configuration file(s) */ |
| 57 | |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 58 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 59 | /* Set a break on the routine named here in order to re-initialize breakpoints |
| 60 | after all the PLTs have been initialzed */ |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 61 | char *PLTs_initialized_by_here = PLT_REINITALISATION_BP; |
| 62 | #endif |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 63 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 64 | static void |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 65 | err_usage(void) { |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 66 | fprintf(stderr, "Try `%s --help' for more information\n", progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 67 | exit(1); |
| 68 | } |
| 69 | |
| 70 | static void |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 71 | usage(void) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 72 | fprintf(stdout, "Usage: %s [option ...] [command [arg ...]]\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 73 | "Trace library calls of a given program.\n\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 74 | " -a, --align=COLUMN align return values in a secific column.\n" |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 75 | " -A ARRAYLEN maximum number of array elements to print.\n" |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 76 | " -b, --no-signals don't print signals.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 77 | " -c count time and calls, and report a summary on exit.\n" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 78 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 79 | " -C, --demangle decode low-level symbol names into user-level names.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 80 | # endif |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 81 | " -D, --debug=LEVEL enable debugging (see -Dh or --debug=help).\n" |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 82 | " -Dh, --debug=help show help on debugging.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 83 | " -e expr modify which events to trace.\n" |
| Juan Cespedes | c4e53a9 | 2009-05-06 20:36:42 +0200 | [diff] [blame] | 84 | " -f trace children (fork() and clone()).\n" |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 85 | " -F, --config=FILE load alternate configuration file (may be repeated).\n" |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 86 | " -g, --no-plt disable breakpoints on PLT entries.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 87 | " -h, --help display this help and exit.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 88 | " -i print instruction pointer at time of library call.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 89 | " -l, --library=FILE print library calls from this library only.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 90 | " -L do NOT display library calls.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 91 | " -n, --indent=NR indent output by NR spaces for each call level nesting.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 92 | " -o, --output=FILE write the trace output to that file.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 93 | " -p PID attach to the process with the process ID pid.\n" |
| 94 | " -r print relative timestamps.\n" |
| 95 | " -s STRLEN specify the maximum string size to print.\n" |
| 96 | " -S display system calls.\n" |
| 97 | " -t, -tt, -ttt print absolute timestamps.\n" |
| 98 | " -T show the time spent inside each call.\n" |
| 99 | " -u USERNAME run command with the userid, groupid of username.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 100 | " -V, --version output version information and exit.\n" |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 101 | #if defined(HAVE_LIBUNWIND) |
| 102 | " -w=NR, --where=NR print backtrace showing NR stack frames at most.\n" |
| 103 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 104 | " -x NAME treat the global NAME like a library subroutine.\n" |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 105 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 106 | " -X NAME same as -x; and PLT's will be initialized by here.\n" |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 107 | #endif |
| 108 | "\nReport bugs to ltrace-devel@lists.alioth.debian.org\n", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 109 | progname); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 112 | static void |
| 113 | usage_debug(void) { |
| 114 | fprintf(stdout, "%s debugging option, --debug=<octal> or -D<octal>:\n", progname); |
| 115 | fprintf(stdout, |
| 116 | "\n" |
| 117 | " number ref. in source description\n" |
| 118 | " 1 general Generally helpful progress information\n" |
| 119 | " 10 event Shows every event received by a traced process\n" |
| 120 | " 20 process Shows actions carried upon a traced processes\n" |
| 121 | " 40 function Shows every entry to internal functions\n" |
| 122 | "\n" |
| 123 | "Debugging options are mixed using bitwise-or.\n" |
| 124 | "Note that the meanings and values are subject to change.\n" |
| 125 | ); |
| 126 | } |
| 127 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 128 | static char * |
| 129 | search_for_command(char *filename) { |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 130 | static char pathname[PATH_MAX]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 131 | char *path; |
| 132 | int m, n; |
| 133 | |
| 134 | if (strchr(filename, '/')) { |
| 135 | return filename; |
| 136 | } |
| 137 | for (path = getenv("PATH"); path && *path; path += m) { |
| 138 | if (strchr(path, ':')) { |
| 139 | n = strchr(path, ':') - path; |
| 140 | m = n + 1; |
| 141 | } else { |
| 142 | m = n = strlen(path); |
| 143 | } |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 144 | if (n + strlen(filename) + 1 >= PATH_MAX) { |
| 145 | fprintf(stderr, "Error: filename too long\n"); |
| 146 | exit(1); |
| 147 | } |
| 148 | strncpy(pathname, path, n); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 149 | if (n && pathname[n - 1] != '/') { |
| 150 | pathname[n++] = '/'; |
| 151 | } |
| 152 | strcpy(pathname + n, filename); |
| 153 | if (!access(pathname, X_OK)) { |
| 154 | return pathname; |
| 155 | } |
| 156 | } |
| 157 | return filename; |
| 158 | } |
| 159 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 160 | static void |
| 161 | guess_cols(void) { |
| 162 | struct winsize ws; |
| 163 | char *c; |
| 164 | |
| 165 | options.align = DEFAULT_ALIGN; |
| 166 | c = getenv("COLUMNS"); |
| 167 | if (c && *c) { |
| 168 | char *endptr; |
| 169 | int cols; |
| 170 | cols = strtol(c, &endptr, 0); |
| 171 | if (cols > 0 && !*endptr) { |
| 172 | options.align = cols * 5 / 8; |
| 173 | } |
| 174 | } else if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col > 0) { |
| 175 | options.align = ws.ws_col * 5 / 8; |
| Juan Cespedes | 43739a6 | 2009-04-07 13:10:08 +0200 | [diff] [blame] | 176 | } else if (ioctl(2, TIOCGWINSZ, &ws) != -1 && ws.ws_col > 0) { |
| 177 | options.align = ws.ws_col * 5 / 8; |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 181 | static void |
| 182 | add_filter_rule(struct filter *filt, const char *expr, |
| 183 | enum filter_rule_type type, |
| 184 | const char *sym, int sym_re_p, |
| 185 | const char *lib, int lib_re_p) |
| 186 | { |
| 187 | fprintf(stderr, "add_filter_rule, type = %d\n", type); |
| 188 | fprintf(stderr, "+ symname = %s (re=%d)\n", sym, sym_re_p); |
| 189 | fprintf(stderr, "+ libname = %s (re=%d)\n", lib, lib_re_p); |
| 190 | struct filter_rule *rule = malloc(sizeof(*rule)); |
| 191 | struct filter_lib_matcher *matcher = malloc(sizeof(*matcher)); |
| 192 | |
| 193 | if (rule == NULL || matcher == NULL) { |
| 194 | error(0, errno, "rule near '%s' will be ignored", expr); |
| 195 | fail: |
| 196 | free(rule); |
| 197 | free(matcher); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | regex_t symbol_re; |
| 202 | int status = (sym_re_p ? regcomp : globcomp)(&symbol_re, sym, 0); |
| 203 | if (status != 0) { |
| 204 | char buf[100]; |
| 205 | regerror(status, &symbol_re, buf, sizeof buf); |
| 206 | error(0, 0, "rule near '%s' will be ignored: %s", expr, buf); |
| 207 | goto fail; |
| 208 | } |
| 209 | |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 210 | if (strcmp(lib, "MAIN") == 0) { |
| 211 | filter_lib_matcher_main_init(matcher); |
| 212 | } else { |
| 213 | enum filter_lib_matcher_type type |
| 214 | = lib[0] == '/' ? FLM_PATHNAME : FLM_SONAME; |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 215 | |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 216 | regex_t lib_re; |
| 217 | status = (lib_re_p ? regcomp : globcomp)(&lib_re, lib, 0); |
| 218 | if (status != 0) { |
| 219 | char buf[100]; |
| 220 | regerror(status, &lib_re, buf, sizeof buf); |
| 221 | error(0, 0, "rule near '%s' will be ignored: %s", |
| 222 | expr, buf); |
| 223 | |
| 224 | regfree(&symbol_re); |
| 225 | goto fail; |
| 226 | } |
| 227 | filter_lib_matcher_name_init(matcher, type, lib_re); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 230 | filter_rule_init(rule, type, matcher, symbol_re); |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame] | 231 | filter_add_rule(filt, rule); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static int |
| 235 | parse_filter(struct filter *filt, char *expr) |
| 236 | { |
| 237 | fprintf(stderr, "filter '%s'\n", expr); |
| 238 | |
| 239 | /* Filter is a chain of sym@lib rules separated by '-'. If |
| 240 | * the filter expression starts with '-', the missing initial |
| 241 | * rule is implicitly *@*. */ |
| 242 | |
| 243 | enum filter_rule_type type = FR_ADD; |
| 244 | |
| 245 | while (*expr != 0) { |
| 246 | size_t s = strcspn(expr, "@-"); |
| 247 | char *symname = expr; |
| 248 | char *libname; |
| 249 | char *next = expr + s + 1; |
| 250 | enum filter_rule_type this_type = type; |
| 251 | |
| 252 | if (expr[s] == 0) { |
| 253 | libname = "*"; |
| 254 | expr = next - 1; |
| 255 | |
| 256 | } else if (expr[s] == '-') { |
| 257 | libname = "*"; |
| 258 | expr = next; |
| 259 | type = FR_SUBTRACT; |
| 260 | |
| 261 | } else { |
| 262 | assert(expr[s] == '@'); |
| 263 | expr[s] = 0; |
| 264 | s = strcspn(next, "-"); |
| 265 | if (s == 0) { |
| 266 | libname = "*"; |
| 267 | expr = next; |
| 268 | } else if (next[s] == 0) { |
| 269 | expr = next + s; |
| 270 | libname = next; |
| 271 | |
| 272 | } else { |
| 273 | assert(next[s] == '-'); |
| 274 | type = FR_SUBTRACT; |
| 275 | next[s] = 0; |
| 276 | expr = next + s + 1; |
| 277 | libname = next; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | assert(*libname != 0); |
| 282 | char *symend = symname + strlen(symname) - 1; |
| 283 | char *libend = libname + strlen(libname) - 1; |
| 284 | int sym_is_re = 0; |
| 285 | int lib_is_re = 0; |
| 286 | |
| 287 | /* |
| 288 | * /xxx/@... and ...@/xxx/ means that xxx are regular |
| 289 | * expressions. They are globs otherwise. |
| 290 | * |
| 291 | * /xxx@yyy/ is the same as /xxx/@/yyy/ |
| 292 | * |
| 293 | * @/xxx matches library path name |
| 294 | * @.xxx matches library relative path name |
| 295 | */ |
| 296 | if (symname[0] == '/') { |
| 297 | if (symname != symend && symend[0] == '/') { |
| 298 | ++symname; |
| 299 | *symend-- = 0; |
| 300 | sym_is_re = 1; |
| 301 | |
| 302 | } else { |
| 303 | sym_is_re = 1; |
| 304 | lib_is_re = 1; |
| 305 | ++symname; |
| 306 | |
| 307 | /* /XXX@YYY/ is the same as |
| 308 | * /XXX/@/YYY/. */ |
| 309 | if (libend[0] != '/') |
| 310 | error(0, 0, "unmatched '/'" |
| 311 | " in symbol name"); |
| 312 | else |
| 313 | *libend-- = 0; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /* If libname ends in '/', then we expect '/' in the |
| 318 | * beginning too. Otherwise the initial '/' is part |
| 319 | * of absolute file name. */ |
| 320 | if (!lib_is_re && libend[0] == '/') { |
| 321 | lib_is_re = 1; |
| 322 | *libend-- = 0; |
| 323 | if (libname != libend && libname[0] == '/') |
| 324 | ++libname; |
| 325 | else |
| 326 | error(0, 0, "unmatched '/' in library name"); |
| 327 | } |
| 328 | |
| 329 | if (*symname == 0) /* /@AA/ */ |
| 330 | symname = "*"; |
| 331 | if (*libname == 0) /* /aa@/ */ |
| 332 | libname = "*"; |
| 333 | |
| 334 | add_filter_rule(filt, expr, this_type, |
| 335 | symname, sym_is_re, |
| 336 | libname, lib_is_re); |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static struct filter * |
| 343 | recursive_parse_chain(char *expr) |
| 344 | { |
| 345 | /* Event expression grammar: |
| 346 | * |
| 347 | * Chain ::= Filter FilterList |
| 348 | * FilterList ::= eps | ',' Filter FilterList |
| 349 | * Filter ::= Rule RuleList |
| 350 | * RuleList ::= eps | '-' Rule RuleList |
| 351 | * Rule ::= eps | Glob Soname |
| 352 | * Soname ::= eps | '@' Glob | '@' '/' Filename |
| 353 | * Glob ::= '/' Regex '/' |
| 354 | */ |
| 355 | |
| 356 | struct filter *filt = malloc(sizeof(*filt)); |
| 357 | if (filt == NULL) { |
| 358 | error(0, errno, "(part of) filter will be ignored: '%s'", expr); |
| 359 | return NULL; |
| 360 | } |
| 361 | |
| Petr Machata | 35c8814 | 2012-04-04 00:54:43 +0200 | [diff] [blame] | 362 | filter_init(filt); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 363 | struct filter *next = NULL; |
| 364 | char *it; |
| 365 | int escape = 0; |
| 366 | for (it = expr; ; ++it) { |
| 367 | if (*it == 0) |
| 368 | goto done; |
| 369 | |
| 370 | if (escape) { |
| 371 | escape = 0; |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | if (*it == '\\') { |
| 376 | escape = 1; |
| 377 | |
| 378 | } else if (*it == ',') { |
| 379 | *it = 0; |
| 380 | next = recursive_parse_chain(it + 1); |
| 381 | done: |
| 382 | filt->next = next; |
| 383 | if (parse_filter(filt, expr) < 0) { |
| 384 | fprintf(stderr, |
| 385 | "Filter '%s' will be ignored.\n", expr); |
| 386 | free(filt); |
| 387 | filt = next; |
| 388 | } |
| 389 | return filt; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | static void |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame^] | 395 | parse_filter_chain(const char *expr, struct filter **retp) |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 396 | { |
| 397 | char *str = strdup(expr); |
| 398 | if (str == NULL) { |
| 399 | error(0, errno, "filter '%s' will be ignored", expr); |
| 400 | return; |
| 401 | } |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame^] | 402 | *retp = recursive_parse_chain(str); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 405 | char ** |
| 406 | process_options(int argc, char **argv) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 407 | progname = argv[0]; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 408 | options.output = stderr; |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 409 | options.no_plt = 0; |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 410 | options.no_signals = 0; |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 411 | #if defined(HAVE_LIBUNWIND) |
| 412 | options.bt_depth = -1; |
| 413 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 414 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 415 | guess_cols(); |
| 416 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 417 | while (1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 418 | int c; |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 419 | char *p; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 420 | int option_index = 0; |
| 421 | static struct option long_options[] = { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 422 | {"align", 1, 0, 'a'}, |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 423 | {"config", 1, 0, 'F'}, |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 424 | {"debug", 1, 0, 'D'}, |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 425 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 426 | {"demangle", 0, 0, 'C'}, |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 427 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 428 | {"indent", 1, 0, 'n'}, |
| 429 | {"help", 0, 0, 'h'}, |
| 430 | {"library", 1, 0, 'l'}, |
| 431 | {"output", 1, 0, 'o'}, |
| 432 | {"version", 0, 0, 'V'}, |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 433 | {"no-plt", 0, 0, 'g'}, |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 434 | {"no-signals", 0, 0, 'b'}, |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 435 | #if defined(HAVE_LIBUNWIND) |
| 436 | {"where", 1, 0, 'w'}, |
| 437 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 438 | {0, 0, 0, 0} |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 439 | }; |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 440 | c = getopt_long(argc, argv, "+cfhiLrStTVgb" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 441 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 442 | "C" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 443 | # endif |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 444 | #if defined(HAVE_LIBUNWIND) |
| 445 | "a:A:D:e:F:l:n:o:p:s:u:x:X:w:", long_options, |
| 446 | #else /* !defined(HAVE_LIBUNWIND) */ |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 447 | "a:A:D:e:F:l:n:o:p:s:u:x:X:", long_options, |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 448 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 449 | &option_index); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 450 | if (c == -1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 451 | break; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 452 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 453 | switch (c) { |
| 454 | case 'a': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 455 | options.align = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 456 | break; |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 457 | case 'A': |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 458 | options.arraylen = atoi(optarg); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 459 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 460 | case 'b': |
| 461 | options.no_signals = 1; |
| 462 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 463 | case 'c': |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 464 | options.summary++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 465 | break; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 466 | #ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 467 | case 'C': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 468 | options.demangle++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 469 | break; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 470 | #endif |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 471 | case 'D': |
| 472 | if (optarg[0]=='h') { |
| 473 | usage_debug(); |
| 474 | exit(0); |
| 475 | } |
| 476 | options.debug = strtoul(optarg,&p,8); |
| 477 | if (*p) { |
| 478 | fprintf(stderr, "%s: --debug requires an octal argument\n", progname); |
| 479 | err_usage(); |
| 480 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 481 | break; |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 482 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 483 | case 'e': |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame^] | 484 | parse_filter_chain(optarg, &options.plt_filter); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 485 | break; |
| 486 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 487 | case 'f': |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 488 | options.follow = 1; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 489 | break; |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 490 | case 'F': |
| 491 | { |
| 492 | struct opt_F_t *tmp = malloc(sizeof(struct opt_F_t)); |
| 493 | if (!tmp) { |
| 494 | perror("ltrace: malloc"); |
| 495 | exit(1); |
| 496 | } |
| 497 | tmp->filename = strdup(optarg); |
| 498 | tmp->next = opt_F; |
| 499 | opt_F = tmp; |
| 500 | break; |
| 501 | } |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 502 | case 'g': |
| 503 | options.no_plt = 1; |
| 504 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 505 | case 'h': |
| 506 | usage(); |
| 507 | exit(0); |
| 508 | case 'i': |
| 509 | opt_i++; |
| 510 | break; |
| 511 | case 'l': |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 512 | assert(!"-l support not yet implemented"); |
| 513 | abort(); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 514 | break; |
| 515 | case 'L': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 516 | options.libcalls = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 517 | break; |
| 518 | case 'n': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 519 | options.indent = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 520 | break; |
| 521 | case 'o': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 522 | options.output = fopen(optarg, "w"); |
| 523 | if (!options.output) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 524 | fprintf(stderr, |
| 525 | "Can't open %s for output: %s\n", |
| 526 | optarg, strerror(errno)); |
| 527 | exit(1); |
| 528 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 529 | setvbuf(options.output, (char *)NULL, _IOLBF, 0); |
| 530 | fcntl(fileno(options.output), F_SETFD, FD_CLOEXEC); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 531 | break; |
| 532 | case 'p': |
| 533 | { |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 534 | struct opt_p_t *tmp = malloc(sizeof(struct opt_p_t)); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 535 | if (!tmp) { |
| 536 | perror("ltrace: malloc"); |
| 537 | exit(1); |
| 538 | } |
| 539 | tmp->pid = atoi(optarg); |
| 540 | tmp->next = opt_p; |
| 541 | opt_p = tmp; |
| 542 | break; |
| 543 | } |
| 544 | case 'r': |
| 545 | opt_r++; |
| 546 | break; |
| 547 | case 's': |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 548 | options.strlen = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 549 | break; |
| 550 | case 'S': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 551 | options.syscalls = 1; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 552 | break; |
| 553 | case 't': |
| 554 | opt_t++; |
| 555 | break; |
| 556 | case 'T': |
| 557 | opt_T++; |
| 558 | break; |
| 559 | case 'u': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 560 | options.user = optarg; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 561 | break; |
| 562 | case 'V': |
| 563 | printf("ltrace version " PACKAGE_VERSION ".\n" |
| Juan Cespedes | 1423f08 | 2009-04-07 00:45:33 +0200 | [diff] [blame] | 564 | "Copyright (C) 1997-2009 Juan Cespedes <cespedes@debian.org>.\n" |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 565 | "This is free software; see the GNU General Public Licence\n" |
| 566 | "version 2 or later for copying conditions. There is NO warranty.\n"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 567 | exit(0); |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 568 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 569 | #if defined(HAVE_LIBUNWIND) |
| 570 | case 'w': |
| 571 | options.bt_depth = atoi(optarg); |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 572 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 573 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 574 | case 'X': |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 575 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 576 | PLTs_initialized_by_here = optarg; |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 577 | #else |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 578 | fprintf(stderr, "WARNING: \"-X\" not used for this " |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 579 | "architecture: assuming you meant \"-x\"\n"); |
| 580 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 581 | /* Fall Thru */ |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 582 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 583 | case 'x': |
| 584 | { |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 585 | struct opt_x_t *p = opt_x; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 586 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 587 | /* First, check for duplicate. */ |
| 588 | while (p && strcmp(p->name, optarg)) { |
| 589 | p = p->next; |
| 590 | } |
| 591 | if (p) { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 592 | break; |
| 593 | } |
| 594 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 595 | /* If not duplicate, add to list. */ |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 596 | p = malloc(sizeof(struct opt_x_t)); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 597 | if (!p) { |
| 598 | perror("ltrace: malloc"); |
| 599 | exit(1); |
| 600 | } |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 601 | opt_x_cnt++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 602 | p->name = optarg; |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 603 | p->found = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 604 | p->next = opt_x; |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 605 | p->hash = ~(0UL); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 606 | opt_x = p; |
| 607 | break; |
| 608 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 609 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 610 | default: |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 611 | err_usage(); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 612 | } |
| 613 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 614 | argc -= optind; |
| 615 | argv += optind; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 616 | |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 617 | if (!opt_F) { |
| 618 | opt_F = malloc(sizeof(struct opt_F_t)); |
| 619 | opt_F->next = malloc(sizeof(struct opt_F_t)); |
| 620 | opt_F->next->next = NULL; |
| 621 | opt_F->filename = USER_CONFIG_FILE; |
| 622 | opt_F->next->filename = SYSTEM_CONFIG_FILE; |
| 623 | } |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 624 | /* Reverse the config file list since it was built by |
| 625 | * prepending, and it would make more sense to process the |
| 626 | * files in the order they were given. Probably it would make |
| 627 | * more sense to keep a tail pointer instead? */ |
| 628 | { |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 629 | struct opt_F_t *egg = NULL; |
| 630 | struct opt_F_t *chicken; |
| 631 | while (opt_F) { |
| 632 | chicken = opt_F->next; |
| 633 | opt_F->next = egg; |
| 634 | egg = opt_F; |
| 635 | opt_F = chicken; |
| 636 | } |
| 637 | opt_F = egg; |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 638 | } |
| 639 | |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 640 | /* Set default filter. Use @MAIN for now, as that's what |
| 641 | * ltrace used to have in the past. XXX Maybe we should make |
| 642 | * this "*" instead. */ |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame^] | 643 | if (options.plt_filter == NULL) { |
| 644 | parse_filter_chain("@MAIN", &options.plt_filter); |
| Petr Machata | 0367389 | 2012-04-03 13:51:09 +0200 | [diff] [blame] | 645 | options.hide_caller = 1; |
| 646 | } |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame] | 647 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 648 | if (!opt_p && argc < 1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 649 | fprintf(stderr, "%s: too few arguments\n", progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 650 | err_usage(); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 651 | } |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 652 | if (opt_r && opt_t) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 653 | fprintf(stderr, "%s: Incompatible options -r and -t\n", |
| 654 | progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 655 | err_usage(); |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 656 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 657 | if (argc > 0) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 658 | command = search_for_command(argv[0]); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 659 | } |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 660 | return &argv[0]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 661 | } |