Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * builtin-probe.c |
| 3 | * |
| 4 | * Builtin probe command: Set up probe events by C expression |
| 5 | * |
| 6 | * Written by Masami Hiramatsu <mhiramat@redhat.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
| 22 | */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 23 | #include <sys/utsname.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <errno.h> |
| 28 | #include <stdio.h> |
| 29 | #include <unistd.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 33 | #include "perf.h" |
| 34 | #include "builtin.h" |
| 35 | #include "util/util.h" |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 36 | #include "util/strlist.h" |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 37 | #include "util/strfilter.h" |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 38 | #include "util/symbol.h" |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 39 | #include "util/debug.h" |
Borislav Petkov | 553873e | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 40 | #include <api/fs/debugfs.h> |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 41 | #include "util/parse-options.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 42 | #include "util/probe-finder.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 43 | #include "util/probe-event.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 44 | |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 45 | #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 46 | #define DEFAULT_FUNC_FILTER "!_*" |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 47 | #define DEFAULT_LIST_FILTER "*:*" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 48 | |
| 49 | /* Session management structure */ |
| 50 | static struct { |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 51 | int command; /* Command short_name */ |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 52 | bool list_events; |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 53 | bool force_add; |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 54 | bool show_ext_vars; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 55 | bool uprobes; |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 56 | bool quiet; |
Masami Hiramatsu | 8cb0aa4 | 2015-04-01 19:25:42 +0900 | [diff] [blame] | 57 | bool target_used; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 58 | int nevents; |
| 59 | struct perf_probe_event events[MAX_PROBES]; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 60 | struct line_range line_range; |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 61 | char *target; |
Masami Hiramatsu | ef4a356 | 2010-04-21 15:56:40 -0400 | [diff] [blame] | 62 | int max_probe_points; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 63 | struct strfilter *filter; |
Masami Hiramatsu | 12a1fad | 2010-03-16 18:05:44 -0400 | [diff] [blame] | 64 | } params; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 65 | |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 66 | /* Parse an event definition. Note that any error must die. */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 67 | static int parse_probe_event(const char *str) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 68 | { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 69 | struct perf_probe_event *pev = ¶ms.events[params.nevents]; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 70 | int ret; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 71 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 72 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); |
Arnaldo Carvalho de Melo | 8a7ddad | 2010-05-18 22:57:27 -0300 | [diff] [blame] | 73 | if (++params.nevents == MAX_PROBES) { |
| 74 | pr_err("Too many probes (> %d) were specified.", MAX_PROBES); |
| 75 | return -1; |
| 76 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 77 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 78 | pev->uprobes = params.uprobes; |
Masami Hiramatsu | 7afb3fa | 2015-04-01 19:25:39 +0900 | [diff] [blame] | 79 | if (params.target) { |
| 80 | pev->target = strdup(params.target); |
| 81 | if (!pev->target) |
| 82 | return -ENOMEM; |
Masami Hiramatsu | 8cb0aa4 | 2015-04-01 19:25:42 +0900 | [diff] [blame] | 83 | params.target_used = true; |
Masami Hiramatsu | 7afb3fa | 2015-04-01 19:25:39 +0900 | [diff] [blame] | 84 | } |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 85 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 86 | /* Parse a perf-probe command into event */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 87 | ret = parse_perf_probe_command(str, pev); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 88 | pr_debug("%d arguments\n", pev->nargs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 89 | |
| 90 | return ret; |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 93 | static int params_add_filter(const char *str) |
| 94 | { |
| 95 | const char *err = NULL; |
| 96 | int ret = 0; |
| 97 | |
| 98 | pr_debug2("Add filter: %s\n", str); |
| 99 | if (!params.filter) { |
| 100 | params.filter = strfilter__new(str, &err); |
| 101 | if (!params.filter) |
| 102 | ret = err ? -EINVAL : -ENOMEM; |
| 103 | } else |
| 104 | ret = strfilter__or(params.filter, str, &err); |
| 105 | |
| 106 | if (ret == -EINVAL) { |
| 107 | pr_err("Filter parse error at %td.\n", err - str + 1); |
| 108 | pr_err("Source: \"%s\"\n", str); |
| 109 | pr_err(" %*c\n", (int)(err - str + 1), '^'); |
| 110 | } |
| 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 115 | static int set_target(const char *ptr) |
| 116 | { |
| 117 | int found = 0; |
| 118 | const char *buf; |
| 119 | |
| 120 | /* |
| 121 | * The first argument after options can be an absolute path |
| 122 | * to an executable / library or kernel module. |
| 123 | * |
| 124 | * TODO: Support relative path, and $PATH, $LD_LIBRARY_PATH, |
| 125 | * short module name. |
| 126 | */ |
| 127 | if (!params.target && ptr && *ptr == '/') { |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 128 | params.target = strdup(ptr); |
| 129 | if (!params.target) |
| 130 | return -ENOMEM; |
Masami Hiramatsu | 8cb0aa4 | 2015-04-01 19:25:42 +0900 | [diff] [blame] | 131 | params.target_used = false; |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 132 | |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 133 | found = 1; |
| 134 | buf = ptr + (strlen(ptr) - 3); |
| 135 | |
| 136 | if (strcmp(buf, ".ko")) |
| 137 | params.uprobes = true; |
| 138 | |
| 139 | } |
| 140 | |
| 141 | return found; |
| 142 | } |
| 143 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 144 | static int parse_probe_event_argv(int argc, const char **argv) |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 145 | { |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 146 | int i, len, ret, found_target; |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 147 | char *buf; |
| 148 | |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 149 | found_target = set_target(argv[0]); |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 150 | if (found_target < 0) |
| 151 | return found_target; |
| 152 | |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 153 | if (found_target && argc == 1) |
| 154 | return 0; |
| 155 | |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 156 | /* Bind up rest arguments */ |
| 157 | len = 0; |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 158 | for (i = 0; i < argc; i++) { |
| 159 | if (i == 0 && found_target) |
| 160 | continue; |
| 161 | |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 162 | len += strlen(argv[i]) + 1; |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 163 | } |
Arnaldo Carvalho de Melo | 8a7ddad | 2010-05-18 22:57:27 -0300 | [diff] [blame] | 164 | buf = zalloc(len + 1); |
| 165 | if (buf == NULL) |
| 166 | return -ENOMEM; |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 167 | len = 0; |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 168 | for (i = 0; i < argc; i++) { |
| 169 | if (i == 0 && found_target) |
| 170 | continue; |
| 171 | |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 172 | len += sprintf(&buf[len], "%s ", argv[i]); |
Srikar Dronamraju | 73eff9f | 2012-04-16 17:39:25 +0530 | [diff] [blame] | 173 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 174 | ret = parse_probe_event(buf); |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 175 | free(buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 176 | return ret; |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 177 | } |
| 178 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 179 | static int opt_set_target(const struct option *opt, const char *str, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 180 | int unset __maybe_unused) |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 181 | { |
| 182 | int ret = -ENOENT; |
Masami Hiramatsu | 8a613d4 | 2013-12-26 05:41:50 +0000 | [diff] [blame] | 183 | char *tmp; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 184 | |
Masami Hiramatsu | 7afb3fa | 2015-04-01 19:25:39 +0900 | [diff] [blame] | 185 | if (str) { |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 186 | if (!strcmp(opt->long_name, "exec")) |
| 187 | params.uprobes = true; |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 188 | #ifdef HAVE_DWARF_SUPPORT |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 189 | else if (!strcmp(opt->long_name, "module")) |
| 190 | params.uprobes = false; |
| 191 | #endif |
| 192 | else |
| 193 | return ret; |
| 194 | |
Masami Hiramatsu | 8a613d4 | 2013-12-26 05:41:50 +0000 | [diff] [blame] | 195 | /* Expand given path to absolute path, except for modulename */ |
| 196 | if (params.uprobes || strchr(str, '/')) { |
| 197 | tmp = realpath(str, NULL); |
| 198 | if (!tmp) { |
| 199 | pr_warning("Failed to get the absolute path of %s: %m\n", str); |
| 200 | return ret; |
| 201 | } |
| 202 | } else { |
| 203 | tmp = strdup(str); |
| 204 | if (!tmp) |
| 205 | return -ENOMEM; |
| 206 | } |
Masami Hiramatsu | 7afb3fa | 2015-04-01 19:25:39 +0900 | [diff] [blame] | 207 | free(params.target); |
Masami Hiramatsu | 8a613d4 | 2013-12-26 05:41:50 +0000 | [diff] [blame] | 208 | params.target = tmp; |
Masami Hiramatsu | 8cb0aa4 | 2015-04-01 19:25:42 +0900 | [diff] [blame] | 209 | params.target_used = false; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 210 | ret = 0; |
| 211 | } |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 216 | /* Command option callbacks */ |
| 217 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 218 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 219 | static int opt_show_lines(const struct option *opt, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 220 | const char *str, int unset __maybe_unused) |
Hitoshi Mitake | 0eda738 | 2010-01-16 21:31:16 +0900 | [diff] [blame] | 221 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 222 | int ret = 0; |
| 223 | |
Masami Hiramatsu | 13e27d7 | 2011-08-11 20:02:53 +0900 | [diff] [blame] | 224 | if (!str) |
| 225 | return 0; |
| 226 | |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 227 | if (params.command == 'L') { |
Masami Hiramatsu | 13e27d7 | 2011-08-11 20:02:53 +0900 | [diff] [blame] | 228 | pr_warning("Warning: more than one --line options are" |
| 229 | " detected. Only the first one is valid.\n"); |
| 230 | return 0; |
| 231 | } |
| 232 | |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 233 | params.command = opt->short_name; |
Masami Hiramatsu | 13e27d7 | 2011-08-11 20:02:53 +0900 | [diff] [blame] | 234 | ret = parse_line_range_desc(str, ¶ms.line_range); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 235 | |
| 236 | return ret; |
Hitoshi Mitake | 0eda738 | 2010-01-16 21:31:16 +0900 | [diff] [blame] | 237 | } |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 238 | |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 239 | static int opt_show_vars(const struct option *opt, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 240 | const char *str, int unset __maybe_unused) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 241 | { |
| 242 | struct perf_probe_event *pev = ¶ms.events[params.nevents]; |
| 243 | int ret; |
| 244 | |
| 245 | if (!str) |
| 246 | return 0; |
| 247 | |
| 248 | ret = parse_probe_event(str); |
| 249 | if (!ret && pev->nargs != 0) { |
| 250 | pr_err(" Error: '--vars' doesn't accept arguments.\n"); |
| 251 | return -EINVAL; |
| 252 | } |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 253 | params.command = opt->short_name; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 254 | |
| 255 | return ret; |
| 256 | } |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 257 | #endif |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 258 | static int opt_add_probe_event(const struct option *opt, |
| 259 | const char *str, int unset __maybe_unused) |
| 260 | { |
| 261 | if (str) { |
| 262 | params.command = opt->short_name; |
| 263 | return parse_probe_event(str); |
| 264 | } |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int opt_set_filter_with_command(const struct option *opt, |
| 270 | const char *str, int unset) |
Masami Hiramatsu | 9f7811d | 2015-05-05 11:29:50 +0900 | [diff] [blame] | 271 | { |
| 272 | if (!unset) |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 273 | params.command = opt->short_name; |
Masami Hiramatsu | 9f7811d | 2015-05-05 11:29:50 +0900 | [diff] [blame] | 274 | |
| 275 | if (str) |
| 276 | return params_add_filter(str); |
| 277 | |
| 278 | return 0; |
| 279 | } |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 280 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 281 | static int opt_set_filter(const struct option *opt __maybe_unused, |
| 282 | const char *str, int unset __maybe_unused) |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 283 | { |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 284 | if (str) |
| 285 | return params_add_filter(str); |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 286 | |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 287 | return 0; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 288 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 289 | |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 290 | static int init_params(void) |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 291 | { |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 292 | return line_range__init(¶ms.line_range); |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void cleanup_params(void) |
| 296 | { |
| 297 | int i; |
| 298 | |
| 299 | for (i = 0; i < params.nevents; i++) |
| 300 | clear_perf_probe_event(params.events + i); |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 301 | line_range__clear(¶ms.line_range); |
| 302 | free(params.target); |
| 303 | if (params.filter) |
| 304 | strfilter__delete(params.filter); |
| 305 | memset(¶ms, 0, sizeof(params)); |
| 306 | } |
| 307 | |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 308 | static void pr_err_with_code(const char *msg, int err) |
| 309 | { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 310 | char sbuf[STRERR_BUFSIZE]; |
| 311 | |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 312 | pr_err("%s", msg); |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 313 | pr_debug(" Reason: %s (Code: %d)", |
| 314 | strerror_r(-err, sbuf, sizeof(sbuf)), err); |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 315 | pr_err("\n"); |
| 316 | } |
| 317 | |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 318 | static int |
| 319 | __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) |
Arnaldo Carvalho de Melo | 11c4e4a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 320 | { |
| 321 | const char * const probe_usage[] = { |
| 322 | "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]", |
| 323 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", |
| 324 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 325 | "perf probe --list [GROUP:]EVENT ...", |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 326 | #ifdef HAVE_DWARF_SUPPORT |
Arnaldo Carvalho de Melo | 11c4e4a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 327 | "perf probe [<options>] --line 'LINEDESC'", |
| 328 | "perf probe [<options>] --vars 'PROBEPOINT'", |
Masami Hiramatsu | f3ab481 | 2010-02-25 08:35:12 -0500 | [diff] [blame] | 329 | #endif |
Masami Hiramatsu | b3ac032 | 2015-04-23 22:46:12 +0900 | [diff] [blame] | 330 | "perf probe [<options>] --funcs", |
Arnaldo Carvalho de Melo | 11c4e4a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 331 | NULL |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 332 | }; |
Namhyung Kim | 13dcbbc | 2014-10-23 00:15:49 +0900 | [diff] [blame] | 333 | struct option options[] = { |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 334 | OPT_INCR('v', "verbose", &verbose, |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 335 | "be more verbose (show parsed arguments, etc)"), |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 336 | OPT_BOOLEAN('q', "quiet", ¶ms.quiet, |
| 337 | "be quiet (do not show any mesages)"), |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 338 | OPT_CALLBACK_DEFAULT('l', "list", NULL, "[GROUP:]EVENT", |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 339 | "list up probe events", |
| 340 | opt_set_filter_with_command, DEFAULT_LIST_FILTER), |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 341 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 342 | opt_set_filter_with_command), |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 343 | OPT_CALLBACK('a', "add", NULL, |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 344 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | 32cb0dd | 2010-03-03 22:38:43 -0500 | [diff] [blame] | 345 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 346 | " [[NAME=]ARG ...]", |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 347 | #else |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 348 | "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]", |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 349 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 350 | "probe point definition, where\n" |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 351 | "\t\tGROUP:\tGroup name (optional)\n" |
| 352 | "\t\tEVENT:\tEvent name\n" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 353 | "\t\tFUNC:\tFunction name\n" |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 354 | "\t\tOFF:\tOffset from function entry (in byte)\n" |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 355 | "\t\t%return:\tPut the probe at function return\n" |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 356 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 357 | "\t\tSRC:\tSource code path\n" |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 358 | "\t\tRL:\tRelative line number from function entry.\n" |
| 359 | "\t\tAL:\tAbsolute line number in file.\n" |
| 360 | "\t\tPT:\tLazy expression of line code.\n" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 361 | "\t\tARG:\tProbe argument (local variable name or\n" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 362 | "\t\t\tkprobe-tracer argument format.)\n", |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 363 | #else |
| 364 | "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n", |
| 365 | #endif |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 366 | opt_add_probe_event), |
Masami Hiramatsu | 12a1fad | 2010-03-16 18:05:44 -0400 | [diff] [blame] | 367 | OPT_BOOLEAN('f', "force", ¶ms.force_add, "forcibly add events" |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 368 | " with existing name"), |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 369 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 370 | OPT_CALLBACK('L', "line", NULL, |
Masami Hiramatsu | 085ea73 | 2010-04-02 12:50:39 -0400 | [diff] [blame] | 371 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 372 | "Show source code lines.", opt_show_lines), |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 373 | OPT_CALLBACK('V', "vars", NULL, |
| 374 | "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT", |
| 375 | "Show accessible variables on PROBEDEF", opt_show_vars), |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 376 | OPT_BOOLEAN('\0', "externs", ¶ms.show_ext_vars, |
| 377 | "Show external variables too (with --vars only)"), |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 378 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 379 | "file", "vmlinux pathname"), |
Chase Douglas | 9ed7e1b | 2010-06-14 15:26:30 -0400 | [diff] [blame] | 380 | OPT_STRING('s', "source", &symbol_conf.source_prefix, |
| 381 | "directory", "path to kernel source"), |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 382 | OPT_CALLBACK('m', "module", NULL, "modname|path", |
| 383 | "target module name (for online) or path (for offline)", |
| 384 | opt_set_target), |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 385 | #endif |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 386 | OPT__DRY_RUN(&probe_event_dry_run), |
Masami Hiramatsu | ef4a356 | 2010-04-21 15:56:40 -0400 | [diff] [blame] | 387 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, |
| 388 | "Set how many probe points can be found for a probe."), |
Masami Hiramatsu | 9f7811d | 2015-05-05 11:29:50 +0900 | [diff] [blame] | 389 | OPT_CALLBACK_DEFAULT('F', "funcs", NULL, "[FILTER]", |
| 390 | "Show potential probe-able functions.", |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 391 | opt_set_filter_with_command, DEFAULT_FUNC_FILTER), |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 392 | OPT_CALLBACK('\0', "filter", NULL, |
| 393 | "[!]FILTER", "Set a filter (with --vars/funcs only)\n" |
| 394 | "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n" |
| 395 | "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)", |
| 396 | opt_set_filter), |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 397 | OPT_CALLBACK('x', "exec", NULL, "executable|path", |
| 398 | "target executable name or path", opt_set_target), |
Azat Khuzhin | 35e17b2 | 2013-10-28 12:04:24 +0400 | [diff] [blame] | 399 | OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, |
Masami Hiramatsu | 4cdcc33 | 2014-10-27 16:31:24 -0400 | [diff] [blame] | 400 | "Enable symbol demangling"), |
Avi Kivity | 763122a | 2014-09-13 07:15:05 +0300 | [diff] [blame] | 401 | OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, |
| 402 | "Enable kernel symbol demangling"), |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 403 | OPT_END() |
Arnaldo Carvalho de Melo | 11c4e4a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 404 | }; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 405 | int ret; |
| 406 | |
Namhyung Kim | 13dcbbc | 2014-10-23 00:15:49 +0900 | [diff] [blame] | 407 | set_option_flag(options, 'a', "add", PARSE_OPT_EXCLUSIVE); |
| 408 | set_option_flag(options, 'd', "del", PARSE_OPT_EXCLUSIVE); |
| 409 | set_option_flag(options, 'l', "list", PARSE_OPT_EXCLUSIVE); |
| 410 | #ifdef HAVE_DWARF_SUPPORT |
| 411 | set_option_flag(options, 'L', "line", PARSE_OPT_EXCLUSIVE); |
| 412 | set_option_flag(options, 'V', "vars", PARSE_OPT_EXCLUSIVE); |
| 413 | #endif |
Masami Hiramatsu | b3ac032 | 2015-04-23 22:46:12 +0900 | [diff] [blame] | 414 | set_option_flag(options, 'F', "funcs", PARSE_OPT_EXCLUSIVE); |
Namhyung Kim | 13dcbbc | 2014-10-23 00:15:49 +0900 | [diff] [blame] | 415 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 416 | argc = parse_options(argc, argv, options, probe_usage, |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 417 | PARSE_OPT_STOP_AT_NON_OPTION); |
Masami Hiramatsu | ce11a60 | 2009-12-15 10:31:28 -0500 | [diff] [blame] | 418 | if (argc > 0) { |
| 419 | if (strcmp(argv[0], "-") == 0) { |
| 420 | pr_warning(" Error: '-' is not supported.\n"); |
| 421 | usage_with_options(probe_usage, options); |
| 422 | } |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 423 | if (params.command && params.command != 'a') { |
| 424 | pr_warning(" Error: another command except --add is set.\n"); |
| 425 | usage_with_options(probe_usage, options); |
| 426 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 427 | ret = parse_probe_event_argv(argc, argv); |
| 428 | if (ret < 0) { |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 429 | pr_err_with_code(" Error: Command Parse Error.", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 430 | return ret; |
| 431 | } |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 432 | params.command = 'a'; |
Masami Hiramatsu | ce11a60 | 2009-12-15 10:31:28 -0500 | [diff] [blame] | 433 | } |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 434 | |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 435 | if (params.quiet) { |
| 436 | if (verbose != 0) { |
| 437 | pr_err(" Error: -v and -q are exclusive.\n"); |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | verbose = -1; |
| 441 | } |
| 442 | |
Masami Hiramatsu | ef4a356 | 2010-04-21 15:56:40 -0400 | [diff] [blame] | 443 | if (params.max_probe_points == 0) |
| 444 | params.max_probe_points = MAX_PROBES; |
| 445 | |
Franck Bui-Huu | fd930ff | 2010-12-10 14:06:03 +0100 | [diff] [blame] | 446 | /* |
| 447 | * Only consider the user's kernel image path if given. |
| 448 | */ |
| 449 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); |
| 450 | |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 451 | switch (params.command) { |
| 452 | case 'l': |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 453 | if (params.uprobes) { |
| 454 | pr_warning(" Error: Don't use --list with --exec.\n"); |
| 455 | usage_with_options(probe_usage, options); |
| 456 | } |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 457 | ret = show_perf_probe_events(params.filter); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 458 | if (ret < 0) |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 459 | pr_err_with_code(" Error: Failed to show event list.", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 460 | return ret; |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 461 | case 'F': |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 462 | ret = show_available_funcs(params.target, params.filter, |
| 463 | params.uprobes); |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 464 | if (ret < 0) |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 465 | pr_err_with_code(" Error: Failed to show functions.", ret); |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 466 | return ret; |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 467 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 468 | case 'L': |
Masami Hiramatsu | 2b394bc | 2014-09-17 08:40:54 +0000 | [diff] [blame] | 469 | ret = show_line_range(¶ms.line_range, params.target, |
| 470 | params.uprobes); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 471 | if (ret < 0) |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 472 | pr_err_with_code(" Error: Failed to show lines.", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 473 | return ret; |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 474 | case 'V': |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 475 | if (!params.filter) |
| 476 | params.filter = strfilter__new(DEFAULT_VAR_FILTER, |
| 477 | NULL); |
| 478 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 479 | ret = show_available_vars(params.events, params.nevents, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 480 | params.max_probe_points, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 481 | params.target, |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 482 | params.filter, |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 483 | params.show_ext_vars); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 484 | if (ret < 0) |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 485 | pr_err_with_code(" Error: Failed to show vars.", ret); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 486 | return ret; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 487 | #endif |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 488 | case 'd': |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 489 | ret = del_perf_probe_events(params.filter); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 490 | if (ret < 0) { |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 491 | pr_err_with_code(" Error: Failed to delete events.", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 492 | return ret; |
| 493 | } |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 494 | break; |
| 495 | case 'a': |
Masami Hiramatsu | 8cb0aa4 | 2015-04-01 19:25:42 +0900 | [diff] [blame] | 496 | /* Ensure the last given target is used */ |
| 497 | if (params.target && !params.target_used) { |
| 498 | pr_warning(" Error: -x/-m must follow the probe definitions.\n"); |
| 499 | usage_with_options(probe_usage, options); |
| 500 | } |
| 501 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 502 | ret = add_perf_probe_events(params.events, params.nevents, |
Masami Hiramatsu | c82ec0a | 2010-10-21 19:13:29 +0900 | [diff] [blame] | 503 | params.max_probe_points, |
| 504 | params.force_add); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 505 | if (ret < 0) { |
Masami Hiramatsu | b4bf113 | 2014-06-06 07:13:52 +0000 | [diff] [blame] | 506 | pr_err_with_code(" Error: Failed to add events.", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 507 | return ret; |
| 508 | } |
Masami Hiramatsu | b1019d5 | 2015-05-06 00:22:57 +0900 | [diff] [blame] | 509 | break; |
| 510 | default: |
| 511 | usage_with_options(probe_usage, options); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 512 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 513 | return 0; |
| 514 | } |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 515 | |
| 516 | int cmd_probe(int argc, const char **argv, const char *prefix) |
| 517 | { |
| 518 | int ret; |
| 519 | |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 520 | ret = init_params(); |
| 521 | if (!ret) { |
| 522 | ret = __cmd_probe(argc, argv, prefix); |
| 523 | cleanup_params(); |
| 524 | } |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 525 | |
Masami Hiramatsu | 9bc9f3b | 2015-05-06 21:46:45 +0900 | [diff] [blame] | 526 | return ret < 0 ? ret : 0; |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 527 | } |