Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1 | /* |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2 | * probe-event.c : perf-probe definition to probe_events format converter |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 3 | * |
| 4 | * Written by Masami Hiramatsu <mhiramat@redhat.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 22 | #include <sys/utsname.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <errno.h> |
| 27 | #include <stdio.h> |
| 28 | #include <unistd.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 31 | #include <stdarg.h> |
| 32 | #include <limits.h> |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 33 | #include <elf.h> |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 34 | |
Masami Hiramatsu | 31facc5 | 2010-03-16 18:05:30 -0400 | [diff] [blame] | 35 | #include "util.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 36 | #include "event.h" |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 37 | #include "strlist.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 38 | #include "debug.h" |
Masami Hiramatsu | 7204133 | 2010-01-05 17:47:10 -0500 | [diff] [blame] | 39 | #include "cache.h" |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 40 | #include "color.h" |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 41 | #include "symbol.h" |
| 42 | #include "thread.h" |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 43 | #include "debugfs.h" |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 44 | #include "trace-event.h" /* For __unused */ |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 45 | #include "probe-event.h" |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 46 | #include "probe-finder.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 47 | |
| 48 | #define MAX_CMDLEN 256 |
| 49 | #define MAX_PROBE_ARGS 128 |
| 50 | #define PERFPROBE_GROUP "probe" |
| 51 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 52 | bool probe_event_dry_run; /* Dry run flag */ |
| 53 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 54 | #define semantic_error(msg ...) pr_err("Semantic error :" msg) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 55 | |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 56 | /* If there is no space to write, returns -E2BIG. */ |
| 57 | static int e_snprintf(char *str, size_t size, const char *format, ...) |
Masami Hiramatsu | 8498845 | 2009-12-07 12:00:53 -0500 | [diff] [blame] | 58 | __attribute__((format(printf, 3, 4))); |
| 59 | |
| 60 | static int e_snprintf(char *str, size_t size, const char *format, ...) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 61 | { |
| 62 | int ret; |
| 63 | va_list ap; |
| 64 | va_start(ap, format); |
| 65 | ret = vsnprintf(str, size, format, ap); |
| 66 | va_end(ap); |
| 67 | if (ret >= (int)size) |
| 68 | ret = -E2BIG; |
| 69 | return ret; |
| 70 | } |
| 71 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 73 | static struct machine machine; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 74 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 75 | /* Initialize symbol maps and path of vmlinux/modules */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 76 | static int init_vmlinux(void) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 77 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 78 | int ret; |
| 79 | |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 80 | symbol_conf.sort_by_name = true; |
| 81 | if (symbol_conf.vmlinux_name == NULL) |
| 82 | symbol_conf.try_vmlinux_path = true; |
| 83 | else |
| 84 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 85 | ret = symbol__init(); |
| 86 | if (ret < 0) { |
| 87 | pr_debug("Failed to init symbol map.\n"); |
| 88 | goto out; |
| 89 | } |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 90 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 91 | ret = machine__init(&machine, "", HOST_KERNEL_ID); |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 92 | if (ret < 0) |
| 93 | goto out; |
| 94 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 95 | if (machine__create_kernel_maps(&machine) < 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 96 | pr_debug("machine__create_kernel_maps() failed.\n"); |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 97 | goto out; |
| 98 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 99 | out: |
| 100 | if (ret < 0) |
| 101 | pr_warning("Failed to init vmlinux path.\n"); |
| 102 | return ret; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 105 | static struct symbol *__find_kernel_function_by_name(const char *name, |
| 106 | struct map **mapp) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 107 | { |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 108 | return machine__find_kernel_function_by_name(&machine, name, mapp, |
| 109 | NULL); |
| 110 | } |
| 111 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 112 | static struct map *kernel_get_module_map(const char *module) |
| 113 | { |
| 114 | struct rb_node *nd; |
| 115 | struct map_groups *grp = &machine.kmaps; |
| 116 | |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 117 | /* A file path -- this is an offline module */ |
| 118 | if (module && strchr(module, '/')) |
| 119 | return machine__new_module(&machine, 0, module); |
| 120 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 121 | if (!module) |
| 122 | module = "kernel"; |
| 123 | |
| 124 | for (nd = rb_first(&grp->maps[MAP__FUNCTION]); nd; nd = rb_next(nd)) { |
| 125 | struct map *pos = rb_entry(nd, struct map, rb_node); |
| 126 | if (strncmp(pos->dso->short_name + 1, module, |
| 127 | pos->dso->short_name_len - 2) == 0) { |
| 128 | return pos; |
| 129 | } |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
| 133 | |
| 134 | static struct dso *kernel_get_module_dso(const char *module) |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 135 | { |
| 136 | struct dso *dso; |
Franck Bui-Huu | fd930ff | 2010-12-10 14:06:03 +0100 | [diff] [blame] | 137 | struct map *map; |
| 138 | const char *vmlinux_name; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 139 | |
| 140 | if (module) { |
| 141 | list_for_each_entry(dso, &machine.kernel_dsos, node) { |
| 142 | if (strncmp(dso->short_name + 1, module, |
| 143 | dso->short_name_len - 2) == 0) |
| 144 | goto found; |
| 145 | } |
| 146 | pr_debug("Failed to find module %s.\n", module); |
| 147 | return NULL; |
Franck Bui-Huu | fd930ff | 2010-12-10 14:06:03 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | map = machine.vmlinux_maps[MAP__FUNCTION]; |
| 151 | dso = map->dso; |
| 152 | |
| 153 | vmlinux_name = symbol_conf.vmlinux_name; |
| 154 | if (vmlinux_name) { |
| 155 | if (dso__load_vmlinux(dso, map, vmlinux_name, NULL) <= 0) |
| 156 | return NULL; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 157 | } else { |
Franck Bui-Huu | c3a34e0 | 2010-12-10 14:07:14 +0100 | [diff] [blame] | 158 | if (dso__load_vmlinux_path(dso, map, NULL) <= 0) { |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 159 | pr_debug("Failed to load kernel map.\n"); |
| 160 | return NULL; |
| 161 | } |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 162 | } |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 163 | found: |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 164 | return dso; |
| 165 | } |
| 166 | |
| 167 | const char *kernel_get_module_path(const char *module) |
| 168 | { |
| 169 | struct dso *dso = kernel_get_module_dso(module); |
| 170 | return (dso) ? dso->long_name : NULL; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #ifdef DWARF_SUPPORT |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 174 | /* Open new debuginfo of given module */ |
| 175 | static struct debuginfo *open_debuginfo(const char *module) |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 176 | { |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 177 | const char *path; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 178 | |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 179 | /* A file path -- this is an offline module */ |
| 180 | if (module && strchr(module, '/')) |
| 181 | path = module; |
| 182 | else { |
| 183 | path = kernel_get_module_path(module); |
| 184 | |
| 185 | if (!path) { |
| 186 | pr_err("Failed to find path of %s module.\n", |
| 187 | module ?: "kernel"); |
| 188 | return NULL; |
| 189 | } |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 190 | } |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 191 | return debuginfo__new(path); |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 192 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 193 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 194 | /* |
| 195 | * Convert trace point to probe point with debuginfo |
| 196 | * Currently only handles kprobes. |
| 197 | */ |
| 198 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 199 | struct perf_probe_point *pp) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 200 | { |
| 201 | struct symbol *sym; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 202 | struct map *map; |
| 203 | u64 addr; |
| 204 | int ret = -ENOENT; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 205 | struct debuginfo *dinfo; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 206 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 207 | sym = __find_kernel_function_by_name(tp->symbol, &map); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 208 | if (sym) { |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 209 | addr = map->unmap_ip(map, sym->start + tp->offset); |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 210 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 211 | tp->offset, addr); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 212 | |
| 213 | dinfo = debuginfo__new_online_kernel(addr); |
| 214 | if (dinfo) { |
| 215 | ret = debuginfo__find_probe_point(dinfo, |
| 216 | (unsigned long)addr, pp); |
| 217 | debuginfo__delete(dinfo); |
| 218 | } else { |
| 219 | pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n", |
| 220 | addr); |
| 221 | ret = -ENOENT; |
| 222 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 223 | } |
| 224 | if (ret <= 0) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 225 | pr_debug("Failed to find corresponding probes from " |
| 226 | "debuginfo. Use kprobe event information.\n"); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 227 | pp->function = strdup(tp->symbol); |
| 228 | if (pp->function == NULL) |
| 229 | return -ENOMEM; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 230 | pp->offset = tp->offset; |
| 231 | } |
| 232 | pp->retprobe = tp->retprobe; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 233 | |
| 234 | return 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 235 | } |
| 236 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 237 | static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, |
| 238 | int ntevs, const char *module) |
| 239 | { |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 240 | int i, ret = 0; |
| 241 | char *tmp; |
| 242 | |
| 243 | if (!module) |
| 244 | return 0; |
| 245 | |
| 246 | tmp = strrchr(module, '/'); |
| 247 | if (tmp) { |
| 248 | /* This is a module path -- get the module name */ |
| 249 | module = strdup(tmp + 1); |
| 250 | if (!module) |
| 251 | return -ENOMEM; |
| 252 | tmp = strchr(module, '.'); |
| 253 | if (tmp) |
| 254 | *tmp = '\0'; |
| 255 | tmp = (char *)module; /* For free() */ |
| 256 | } |
| 257 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 258 | for (i = 0; i < ntevs; i++) { |
| 259 | tevs[i].point.module = strdup(module); |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 260 | if (!tevs[i].point.module) { |
| 261 | ret = -ENOMEM; |
| 262 | break; |
| 263 | } |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 264 | } |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 265 | |
| 266 | if (tmp) |
| 267 | free(tmp); |
| 268 | |
| 269 | return ret; |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 270 | } |
| 271 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 272 | /* Try to find perf_probe_event with debuginfo */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 273 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 274 | struct probe_trace_event **tevs, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 275 | int max_tevs, const char *target) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 276 | { |
| 277 | bool need_dwarf = perf_probe_event_need_dwarf(pev); |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 278 | struct debuginfo *dinfo = open_debuginfo(target); |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 279 | int ntevs, ret = 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 280 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 281 | if (!dinfo) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 282 | if (need_dwarf) { |
| 283 | pr_warning("Failed to open debuginfo file.\n"); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 284 | return -ENOENT; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 285 | } |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 286 | pr_debug("Could not open debuginfo. Try to use symbols.\n"); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 290 | /* Searching trace events corresponding to a probe event */ |
| 291 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs); |
| 292 | |
| 293 | debuginfo__delete(dinfo); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 294 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 295 | if (ntevs > 0) { /* Succeeded to find trace events */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 296 | pr_debug("find %d probe_trace_events.\n", ntevs); |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 297 | if (target) |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 298 | ret = add_module_to_probe_trace_events(*tevs, ntevs, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 299 | target); |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 300 | return ret < 0 ? ret : ntevs; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 301 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 302 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 303 | if (ntevs == 0) { /* No error but failed to find probe point. */ |
| 304 | pr_warning("Probe point '%s' not found.\n", |
| 305 | synthesize_perf_probe_point(&pev->point)); |
| 306 | return -ENOENT; |
| 307 | } |
| 308 | /* Error path : ntevs < 0 */ |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 309 | pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs); |
| 310 | if (ntevs == -EBADF) { |
| 311 | pr_warning("Warning: No dwarf info found in the vmlinux - " |
| 312 | "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n"); |
| 313 | if (!need_dwarf) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 314 | pr_debug("Trying to use symbols.\n"); |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 315 | return 0; |
| 316 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 317 | } |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 318 | return ntevs; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 319 | } |
| 320 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 321 | /* |
| 322 | * Find a src file from a DWARF tag path. Prepend optional source path prefix |
| 323 | * and chop off leading directories that do not exist. Result is passed back as |
| 324 | * a newly allocated path on success. |
| 325 | * Return 0 if file was found and readable, -errno otherwise. |
| 326 | */ |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 327 | static int get_real_path(const char *raw_path, const char *comp_dir, |
| 328 | char **new_path) |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 329 | { |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 330 | const char *prefix = symbol_conf.source_prefix; |
| 331 | |
| 332 | if (!prefix) { |
| 333 | if (raw_path[0] != '/' && comp_dir) |
| 334 | /* If not an absolute path, try to use comp_dir */ |
| 335 | prefix = comp_dir; |
| 336 | else { |
| 337 | if (access(raw_path, R_OK) == 0) { |
| 338 | *new_path = strdup(raw_path); |
| 339 | return 0; |
| 340 | } else |
| 341 | return -errno; |
| 342 | } |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 343 | } |
| 344 | |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 345 | *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2)); |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 346 | if (!*new_path) |
| 347 | return -ENOMEM; |
| 348 | |
| 349 | for (;;) { |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 350 | sprintf(*new_path, "%s/%s", prefix, raw_path); |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 351 | |
| 352 | if (access(*new_path, R_OK) == 0) |
| 353 | return 0; |
| 354 | |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 355 | if (!symbol_conf.source_prefix) |
| 356 | /* In case of searching comp_dir, don't retry */ |
| 357 | return -errno; |
| 358 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 359 | switch (errno) { |
| 360 | case ENAMETOOLONG: |
| 361 | case ENOENT: |
| 362 | case EROFS: |
| 363 | case EFAULT: |
| 364 | raw_path = strchr(++raw_path, '/'); |
| 365 | if (!raw_path) { |
| 366 | free(*new_path); |
| 367 | *new_path = NULL; |
| 368 | return -ENOENT; |
| 369 | } |
| 370 | continue; |
| 371 | |
| 372 | default: |
| 373 | free(*new_path); |
| 374 | *new_path = NULL; |
| 375 | return -errno; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 380 | #define LINEBUF_SIZE 256 |
| 381 | #define NR_ADDITIONAL_LINES 2 |
| 382 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 383 | static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 384 | { |
| 385 | char buf[LINEBUF_SIZE]; |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 386 | const char *color = show_num ? "" : PERF_COLOR_BLUE; |
| 387 | const char *prefix = NULL; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 388 | |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 389 | do { |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 390 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) |
| 391 | goto error; |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 392 | if (skip) |
| 393 | continue; |
| 394 | if (!prefix) { |
| 395 | prefix = show_num ? "%7d " : " "; |
| 396 | color_fprintf(stdout, color, prefix, l); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 397 | } |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 398 | color_fprintf(stdout, color, "%s", buf); |
| 399 | |
| 400 | } while (strchr(buf, '\n') == NULL); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 401 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 402 | return 1; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 403 | error: |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 404 | if (ferror(fp)) { |
Franck Bui-Huu | 32b2b6e | 2010-12-22 17:37:13 +0100 | [diff] [blame] | 405 | pr_warning("File read error: %s\n", strerror(errno)); |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 406 | return -1; |
| 407 | } |
| 408 | return 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 409 | } |
| 410 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 411 | static int _show_one_line(FILE *fp, int l, bool skip, bool show_num) |
| 412 | { |
| 413 | int rv = __show_one_line(fp, l, skip, show_num); |
| 414 | if (rv == 0) { |
| 415 | pr_warning("Source file is shorter than expected.\n"); |
| 416 | rv = -1; |
| 417 | } |
| 418 | return rv; |
| 419 | } |
| 420 | |
| 421 | #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true) |
| 422 | #define show_one_line(f,l) _show_one_line(f,l,false,false) |
| 423 | #define skip_one_line(f,l) _show_one_line(f,l,true,false) |
| 424 | #define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false) |
| 425 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 426 | /* |
| 427 | * Show line-range always requires debuginfo to find source file and |
| 428 | * line number. |
| 429 | */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 430 | int show_line_range(struct line_range *lr, const char *module) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 431 | { |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 432 | int l = 1; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 433 | struct line_node *ln; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 434 | struct debuginfo *dinfo; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 435 | FILE *fp; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 436 | int ret; |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 437 | char *tmp; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 438 | |
| 439 | /* Search a line range */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 440 | ret = init_vmlinux(); |
| 441 | if (ret < 0) |
| 442 | return ret; |
| 443 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 444 | dinfo = open_debuginfo(module); |
| 445 | if (!dinfo) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 446 | pr_warning("Failed to open debuginfo file.\n"); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 447 | return -ENOENT; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 450 | ret = debuginfo__find_line_range(dinfo, lr); |
| 451 | debuginfo__delete(dinfo); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 452 | if (ret == 0) { |
| 453 | pr_warning("Specified source line is not found.\n"); |
| 454 | return -ENOENT; |
| 455 | } else if (ret < 0) { |
| 456 | pr_warning("Debuginfo analysis failed. (%d)\n", ret); |
| 457 | return ret; |
| 458 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 459 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 460 | /* Convert source file path */ |
| 461 | tmp = lr->path; |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 462 | ret = get_real_path(tmp, lr->comp_dir, &lr->path); |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 463 | free(tmp); /* Free old path */ |
| 464 | if (ret < 0) { |
| 465 | pr_warning("Failed to find source file. (%d)\n", ret); |
| 466 | return ret; |
| 467 | } |
| 468 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 469 | setup_pager(); |
| 470 | |
| 471 | if (lr->function) |
Masami Hiramatsu | 8737ebd | 2011-02-10 18:08:16 +0900 | [diff] [blame] | 472 | fprintf(stdout, "<%s@%s:%d>\n", lr->function, lr->path, |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 473 | lr->start - lr->offset); |
| 474 | else |
Franck Bui-Huu | 62c15fc | 2010-12-20 15:18:00 +0100 | [diff] [blame] | 475 | fprintf(stdout, "<%s:%d>\n", lr->path, lr->start); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 476 | |
| 477 | fp = fopen(lr->path, "r"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 478 | if (fp == NULL) { |
| 479 | pr_warning("Failed to open %s: %s\n", lr->path, |
| 480 | strerror(errno)); |
| 481 | return -errno; |
| 482 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 483 | /* Skip to starting line number */ |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 484 | while (l < lr->start) { |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 485 | ret = skip_one_line(fp, l++); |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 486 | if (ret < 0) |
| 487 | goto end; |
| 488 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 489 | |
| 490 | list_for_each_entry(ln, &lr->line_list, list) { |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 491 | for (; ln->line > l; l++) { |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 492 | ret = show_one_line(fp, l - lr->offset); |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 493 | if (ret < 0) |
| 494 | goto end; |
| 495 | } |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 496 | ret = show_one_line_with_num(fp, l++ - lr->offset); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 497 | if (ret < 0) |
| 498 | goto end; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if (lr->end == INT_MAX) |
| 502 | lr->end = l + NR_ADDITIONAL_LINES; |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 503 | while (l <= lr->end) { |
| 504 | ret = show_one_line_or_eof(fp, l++ - lr->offset); |
| 505 | if (ret <= 0) |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 506 | break; |
| 507 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 508 | end: |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 509 | fclose(fp); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 510 | return ret; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 511 | } |
| 512 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 513 | static int show_available_vars_at(struct debuginfo *dinfo, |
| 514 | struct perf_probe_event *pev, |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 515 | int max_vls, struct strfilter *_filter, |
| 516 | bool externs) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 517 | { |
| 518 | char *buf; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 519 | int ret, i, nvars; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 520 | struct str_node *node; |
| 521 | struct variable_list *vls = NULL, *vl; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 522 | const char *var; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 523 | |
| 524 | buf = synthesize_perf_probe_point(&pev->point); |
| 525 | if (!buf) |
| 526 | return -EINVAL; |
| 527 | pr_debug("Searching variables at %s\n", buf); |
| 528 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 529 | ret = debuginfo__find_available_vars_at(dinfo, pev, &vls, |
| 530 | max_vls, externs); |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 531 | if (ret <= 0) { |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 532 | pr_err("Failed to find variables at %s (%d)\n", buf, ret); |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 533 | goto end; |
| 534 | } |
| 535 | /* Some variables are found */ |
| 536 | fprintf(stdout, "Available variables at %s\n", buf); |
| 537 | for (i = 0; i < ret; i++) { |
| 538 | vl = &vls[i]; |
| 539 | /* |
| 540 | * A probe point might be converted to |
| 541 | * several trace points. |
| 542 | */ |
| 543 | fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol, |
| 544 | vl->point.offset); |
| 545 | free(vl->point.symbol); |
| 546 | nvars = 0; |
| 547 | if (vl->vars) { |
| 548 | strlist__for_each(node, vl->vars) { |
| 549 | var = strchr(node->s, '\t') + 1; |
| 550 | if (strfilter__compare(_filter, var)) { |
| 551 | fprintf(stdout, "\t\t%s\n", node->s); |
| 552 | nvars++; |
| 553 | } |
| 554 | } |
| 555 | strlist__delete(vl->vars); |
| 556 | } |
| 557 | if (nvars == 0) |
| 558 | fprintf(stdout, "\t\t(No matched variables)\n"); |
| 559 | } |
| 560 | free(vls); |
| 561 | end: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 562 | free(buf); |
| 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | /* Show available variables on given probe point */ |
| 567 | int show_available_vars(struct perf_probe_event *pevs, int npevs, |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 568 | int max_vls, const char *module, |
| 569 | struct strfilter *_filter, bool externs) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 570 | { |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 571 | int i, ret = 0; |
| 572 | struct debuginfo *dinfo; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 573 | |
| 574 | ret = init_vmlinux(); |
| 575 | if (ret < 0) |
| 576 | return ret; |
| 577 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 578 | dinfo = open_debuginfo(module); |
| 579 | if (!dinfo) { |
| 580 | pr_warning("Failed to open debuginfo file.\n"); |
| 581 | return -ENOENT; |
| 582 | } |
| 583 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 584 | setup_pager(); |
| 585 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 586 | for (i = 0; i < npevs && ret >= 0; i++) |
| 587 | ret = show_available_vars_at(dinfo, &pevs[i], max_vls, _filter, |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 588 | externs); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 589 | |
| 590 | debuginfo__delete(dinfo); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 591 | return ret; |
| 592 | } |
| 593 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 594 | #else /* !DWARF_SUPPORT */ |
| 595 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 596 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 597 | struct perf_probe_point *pp) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 598 | { |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 599 | struct symbol *sym; |
| 600 | |
| 601 | sym = __find_kernel_function_by_name(tp->symbol, NULL); |
| 602 | if (!sym) { |
| 603 | pr_err("Failed to find symbol %s in kernel.\n", tp->symbol); |
| 604 | return -ENOENT; |
| 605 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 606 | pp->function = strdup(tp->symbol); |
| 607 | if (pp->function == NULL) |
| 608 | return -ENOMEM; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 609 | pp->offset = tp->offset; |
| 610 | pp->retprobe = tp->retprobe; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 611 | |
| 612 | return 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 613 | } |
| 614 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 615 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
| 616 | struct probe_trace_event **tevs __unused, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 617 | int max_tevs __unused, const char *mod __unused) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 618 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 619 | if (perf_probe_event_need_dwarf(pev)) { |
| 620 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 621 | return -ENOSYS; |
| 622 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 626 | int show_line_range(struct line_range *lr __unused, const char *module __unused) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 627 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 628 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 629 | return -ENOSYS; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 630 | } |
| 631 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 632 | int show_available_vars(struct perf_probe_event *pevs __unused, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 633 | int npevs __unused, int max_vls __unused, |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 634 | const char *module __unused, |
| 635 | struct strfilter *filter __unused, |
| 636 | bool externs __unused) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 637 | { |
| 638 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 639 | return -ENOSYS; |
| 640 | } |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 641 | #endif |
| 642 | |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 643 | static int parse_line_num(char **ptr, int *val, const char *what) |
| 644 | { |
| 645 | const char *start = *ptr; |
| 646 | |
| 647 | errno = 0; |
| 648 | *val = strtol(*ptr, ptr, 0); |
| 649 | if (errno || *ptr == start) { |
| 650 | semantic_error("'%s' is not a valid number.\n", what); |
| 651 | return -EINVAL; |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 656 | /* |
| 657 | * Stuff 'lr' according to the line range described by 'arg'. |
| 658 | * The line range syntax is described by: |
| 659 | * |
| 660 | * SRC[:SLN[+NUM|-ELN]] |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 661 | * FNC[@SRC][:SLN[+NUM|-ELN]] |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 662 | */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 663 | int parse_line_range_desc(const char *arg, struct line_range *lr) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 664 | { |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 665 | char *range, *file, *name = strdup(arg); |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 666 | int err; |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 667 | |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 668 | if (!name) |
| 669 | return -ENOMEM; |
| 670 | |
| 671 | lr->start = 0; |
| 672 | lr->end = INT_MAX; |
| 673 | |
| 674 | range = strchr(name, ':'); |
| 675 | if (range) { |
| 676 | *range++ = '\0'; |
| 677 | |
| 678 | err = parse_line_num(&range, &lr->start, "start line"); |
| 679 | if (err) |
| 680 | goto err; |
| 681 | |
| 682 | if (*range == '+' || *range == '-') { |
| 683 | const char c = *range++; |
| 684 | |
| 685 | err = parse_line_num(&range, &lr->end, "end line"); |
| 686 | if (err) |
| 687 | goto err; |
| 688 | |
| 689 | if (c == '+') { |
| 690 | lr->end += lr->start; |
| 691 | /* |
| 692 | * Adjust the number of lines here. |
| 693 | * If the number of lines == 1, the |
| 694 | * the end of line should be equal to |
| 695 | * the start of line. |
| 696 | */ |
| 697 | lr->end--; |
| 698 | } |
| 699 | } |
| 700 | |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 701 | pr_debug("Line range is %d to %d\n", lr->start, lr->end); |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 702 | |
| 703 | err = -EINVAL; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 704 | if (lr->start > lr->end) { |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 705 | semantic_error("Start line must be smaller" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 706 | " than end line.\n"); |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 707 | goto err; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 708 | } |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 709 | if (*range != '\0') { |
| 710 | semantic_error("Tailing with invalid str '%s'.\n", range); |
| 711 | goto err; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 712 | } |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 713 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 714 | |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 715 | file = strchr(name, '@'); |
| 716 | if (file) { |
| 717 | *file = '\0'; |
| 718 | lr->file = strdup(++file); |
| 719 | if (lr->file == NULL) { |
| 720 | err = -ENOMEM; |
| 721 | goto err; |
| 722 | } |
| 723 | lr->function = name; |
| 724 | } else if (strchr(name, '.')) |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 725 | lr->file = name; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 726 | else |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 727 | lr->function = name; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 728 | |
| 729 | return 0; |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 730 | err: |
| 731 | free(name); |
| 732 | return err; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 733 | } |
| 734 | |
Masami Hiramatsu | b7702a2 | 2009-12-16 17:24:15 -0500 | [diff] [blame] | 735 | /* Check the name is good for event/group */ |
| 736 | static bool check_event_name(const char *name) |
| 737 | { |
| 738 | if (!isalpha(*name) && *name != '_') |
| 739 | return false; |
| 740 | while (*++name != '\0') { |
| 741 | if (!isalpha(*name) && !isdigit(*name) && *name != '_') |
| 742 | return false; |
| 743 | } |
| 744 | return true; |
| 745 | } |
| 746 | |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 747 | /* Parse probepoint definition. */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 748 | static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 749 | { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 750 | struct perf_probe_point *pp = &pev->point; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 751 | char *ptr, *tmp; |
| 752 | char c, nc = 0; |
| 753 | /* |
| 754 | * <Syntax> |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 755 | * perf probe [EVENT=]SRC[:LN|;PTN] |
| 756 | * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT] |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 757 | * |
| 758 | * TODO:Group name support |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 759 | */ |
| 760 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 761 | ptr = strpbrk(arg, ";=@+%"); |
| 762 | if (ptr && *ptr == '=') { /* Event name */ |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 763 | *ptr = '\0'; |
| 764 | tmp = ptr + 1; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 765 | if (strchr(arg, ':')) { |
| 766 | semantic_error("Group name is not supported yet.\n"); |
| 767 | return -ENOTSUP; |
| 768 | } |
| 769 | if (!check_event_name(arg)) { |
Masami Hiramatsu | b7702a2 | 2009-12-16 17:24:15 -0500 | [diff] [blame] | 770 | semantic_error("%s is bad for event name -it must " |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 771 | "follow C symbol-naming rule.\n", arg); |
| 772 | return -EINVAL; |
| 773 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 774 | pev->event = strdup(arg); |
| 775 | if (pev->event == NULL) |
| 776 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 777 | pev->group = NULL; |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 778 | arg = tmp; |
| 779 | } |
| 780 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 781 | ptr = strpbrk(arg, ";:+@%"); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 782 | if (ptr) { |
| 783 | nc = *ptr; |
| 784 | *ptr++ = '\0'; |
| 785 | } |
| 786 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 787 | tmp = strdup(arg); |
| 788 | if (tmp == NULL) |
| 789 | return -ENOMEM; |
| 790 | |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 791 | /* Check arg is function or file and copy it */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 792 | if (strchr(tmp, '.')) /* File */ |
| 793 | pp->file = tmp; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 794 | else /* Function */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 795 | pp->function = tmp; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 796 | |
| 797 | /* Parse other options */ |
| 798 | while (ptr) { |
| 799 | arg = ptr; |
| 800 | c = nc; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 801 | if (c == ';') { /* Lazy pattern must be the last part */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 802 | pp->lazy_line = strdup(arg); |
| 803 | if (pp->lazy_line == NULL) |
| 804 | return -ENOMEM; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 805 | break; |
| 806 | } |
| 807 | ptr = strpbrk(arg, ";:+@%"); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 808 | if (ptr) { |
| 809 | nc = *ptr; |
| 810 | *ptr++ = '\0'; |
| 811 | } |
| 812 | switch (c) { |
| 813 | case ':': /* Line number */ |
| 814 | pp->line = strtoul(arg, &tmp, 0); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 815 | if (*tmp != '\0') { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 816 | semantic_error("There is non-digit char" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 817 | " in line number.\n"); |
| 818 | return -EINVAL; |
| 819 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 820 | break; |
| 821 | case '+': /* Byte offset from a symbol */ |
| 822 | pp->offset = strtoul(arg, &tmp, 0); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 823 | if (*tmp != '\0') { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 824 | semantic_error("There is non-digit character" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 825 | " in offset.\n"); |
| 826 | return -EINVAL; |
| 827 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 828 | break; |
| 829 | case '@': /* File name */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 830 | if (pp->file) { |
| 831 | semantic_error("SRC@SRC is not allowed.\n"); |
| 832 | return -EINVAL; |
| 833 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 834 | pp->file = strdup(arg); |
| 835 | if (pp->file == NULL) |
| 836 | return -ENOMEM; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 837 | break; |
| 838 | case '%': /* Probe places */ |
| 839 | if (strcmp(arg, "return") == 0) { |
| 840 | pp->retprobe = 1; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 841 | } else { /* Others not supported yet */ |
| 842 | semantic_error("%%%s is not supported.\n", arg); |
| 843 | return -ENOTSUP; |
| 844 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 845 | break; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 846 | default: /* Buggy case */ |
| 847 | pr_err("This program has a bug at %s:%d.\n", |
| 848 | __FILE__, __LINE__); |
| 849 | return -ENOTSUP; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | /* Exclusion check */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 855 | if (pp->lazy_line && pp->line) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 856 | semantic_error("Lazy pattern can't be used with" |
| 857 | " line number.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 858 | return -EINVAL; |
| 859 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 860 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 861 | if (pp->lazy_line && pp->offset) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 862 | semantic_error("Lazy pattern can't be used with offset.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 863 | return -EINVAL; |
| 864 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 865 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 866 | if (pp->line && pp->offset) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 867 | semantic_error("Offset can't be used with line number.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 870 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 871 | if (!pp->line && !pp->lazy_line && pp->file && !pp->function) { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 872 | semantic_error("File always requires line number or " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 873 | "lazy pattern.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 874 | return -EINVAL; |
| 875 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 876 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 877 | if (pp->offset && !pp->function) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 878 | semantic_error("Offset requires an entry function.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 879 | return -EINVAL; |
| 880 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 881 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 882 | if (pp->retprobe && !pp->function) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 883 | semantic_error("Return probe requires an entry function.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 884 | return -EINVAL; |
| 885 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 886 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 887 | if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 888 | semantic_error("Offset/Line/Lazy pattern can't be used with " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 889 | "return probe.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 890 | return -EINVAL; |
| 891 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 892 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 893 | pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n", |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 894 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, |
| 895 | pp->lazy_line); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 896 | return 0; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 897 | } |
| 898 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 899 | /* Parse perf-probe event argument */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 900 | static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 901 | { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 902 | char *tmp, *goodname; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 903 | struct perf_probe_arg_field **fieldp; |
| 904 | |
| 905 | pr_debug("parsing arg: %s into ", str); |
| 906 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 907 | tmp = strchr(str, '='); |
| 908 | if (tmp) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 909 | arg->name = strndup(str, tmp - str); |
| 910 | if (arg->name == NULL) |
| 911 | return -ENOMEM; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 912 | pr_debug("name:%s ", arg->name); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 913 | str = tmp + 1; |
| 914 | } |
| 915 | |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 916 | tmp = strchr(str, ':'); |
| 917 | if (tmp) { /* Type setting */ |
| 918 | *tmp = '\0'; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 919 | arg->type = strdup(tmp + 1); |
| 920 | if (arg->type == NULL) |
| 921 | return -ENOMEM; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 922 | pr_debug("type:%s ", arg->type); |
| 923 | } |
| 924 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 925 | tmp = strpbrk(str, "-.["); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 926 | if (!is_c_varname(str) || !tmp) { |
| 927 | /* A variable, register, symbol or special value */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 928 | arg->var = strdup(str); |
| 929 | if (arg->var == NULL) |
| 930 | return -ENOMEM; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 931 | pr_debug("%s\n", arg->var); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 932 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 935 | /* Structure fields or array element */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 936 | arg->var = strndup(str, tmp - str); |
| 937 | if (arg->var == NULL) |
| 938 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 939 | goodname = arg->var; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 940 | pr_debug("%s, ", arg->var); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 941 | fieldp = &arg->field; |
| 942 | |
| 943 | do { |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 944 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); |
| 945 | if (*fieldp == NULL) |
| 946 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 947 | if (*tmp == '[') { /* Array */ |
| 948 | str = tmp; |
| 949 | (*fieldp)->index = strtol(str + 1, &tmp, 0); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 950 | (*fieldp)->ref = true; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 951 | if (*tmp != ']' || tmp == str + 1) { |
| 952 | semantic_error("Array index must be a" |
| 953 | " number.\n"); |
| 954 | return -EINVAL; |
| 955 | } |
| 956 | tmp++; |
| 957 | if (*tmp == '\0') |
| 958 | tmp = NULL; |
| 959 | } else { /* Structure */ |
| 960 | if (*tmp == '.') { |
| 961 | str = tmp + 1; |
| 962 | (*fieldp)->ref = false; |
| 963 | } else if (tmp[1] == '>') { |
| 964 | str = tmp + 2; |
| 965 | (*fieldp)->ref = true; |
| 966 | } else { |
| 967 | semantic_error("Argument parse error: %s\n", |
| 968 | str); |
| 969 | return -EINVAL; |
| 970 | } |
| 971 | tmp = strpbrk(str, "-.["); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 972 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 973 | if (tmp) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 974 | (*fieldp)->name = strndup(str, tmp - str); |
| 975 | if ((*fieldp)->name == NULL) |
| 976 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 977 | if (*str != '[') |
| 978 | goodname = (*fieldp)->name; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 979 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); |
| 980 | fieldp = &(*fieldp)->next; |
| 981 | } |
| 982 | } while (tmp); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 983 | (*fieldp)->name = strdup(str); |
| 984 | if ((*fieldp)->name == NULL) |
| 985 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 986 | if (*str != '[') |
| 987 | goodname = (*fieldp)->name; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 988 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); |
Masami Hiramatsu | df0faf4 | 2010-04-12 13:17:00 -0400 | [diff] [blame] | 989 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 990 | /* If no name is specified, set the last field name (not array index)*/ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 991 | if (!arg->name) { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 992 | arg->name = strdup(goodname); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 993 | if (arg->name == NULL) |
| 994 | return -ENOMEM; |
| 995 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 996 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 997 | } |
| 998 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 999 | /* Parse perf-probe event command */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1000 | int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1001 | { |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1002 | char **argv; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1003 | int argc, i, ret = 0; |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 1004 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1005 | argv = argv_split(cmd, &argc); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1006 | if (!argv) { |
| 1007 | pr_debug("Failed to split arguments.\n"); |
| 1008 | return -ENOMEM; |
| 1009 | } |
| 1010 | if (argc - 1 > MAX_PROBE_ARGS) { |
| 1011 | semantic_error("Too many probe arguments (%d).\n", argc - 1); |
| 1012 | ret = -ERANGE; |
| 1013 | goto out; |
| 1014 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1015 | /* Parse probe point */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1016 | ret = parse_perf_probe_point(argv[0], pev); |
| 1017 | if (ret < 0) |
| 1018 | goto out; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1019 | |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1020 | /* Copy arguments and ensure return probe has no C argument */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1021 | pev->nargs = argc - 1; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1022 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
| 1023 | if (pev->args == NULL) { |
| 1024 | ret = -ENOMEM; |
| 1025 | goto out; |
| 1026 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1027 | for (i = 0; i < pev->nargs && ret >= 0; i++) { |
| 1028 | ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]); |
| 1029 | if (ret >= 0 && |
| 1030 | is_c_varname(pev->args[i].var) && pev->point.retprobe) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1031 | semantic_error("You can't specify local variable for" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1032 | " kretprobe.\n"); |
| 1033 | ret = -EINVAL; |
| 1034 | } |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1035 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1036 | out: |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1037 | argv_free(argv); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1038 | |
| 1039 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1040 | } |
| 1041 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1042 | /* Return true if this perf_probe_event requires debuginfo */ |
| 1043 | bool perf_probe_event_need_dwarf(struct perf_probe_event *pev) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1044 | { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1045 | int i; |
| 1046 | |
| 1047 | if (pev->point.file || pev->point.line || pev->point.lazy_line) |
| 1048 | return true; |
| 1049 | |
| 1050 | for (i = 0; i < pev->nargs; i++) |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1051 | if (is_c_varname(pev->args[i].var)) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1052 | return true; |
| 1053 | |
| 1054 | return false; |
| 1055 | } |
| 1056 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1057 | /* Parse probe_events event into struct probe_point */ |
| 1058 | static int parse_probe_trace_command(const char *cmd, |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1059 | struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1060 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1061 | struct probe_trace_point *tp = &tev->point; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1062 | char pr; |
| 1063 | char *p; |
| 1064 | int ret, i, argc; |
| 1065 | char **argv; |
| 1066 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1067 | pr_debug("Parsing probe_events: %s\n", cmd); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1068 | argv = argv_split(cmd, &argc); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1069 | if (!argv) { |
| 1070 | pr_debug("Failed to split arguments.\n"); |
| 1071 | return -ENOMEM; |
| 1072 | } |
| 1073 | if (argc < 2) { |
| 1074 | semantic_error("Too few probe arguments.\n"); |
| 1075 | ret = -ERANGE; |
| 1076 | goto out; |
| 1077 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1078 | |
| 1079 | /* Scan event and group name. */ |
Liming Wang | 93aaa45 | 2009-12-02 16:42:54 +0800 | [diff] [blame] | 1080 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1081 | &pr, (float *)(void *)&tev->group, |
| 1082 | (float *)(void *)&tev->event); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1083 | if (ret != 3) { |
| 1084 | semantic_error("Failed to parse event name: %s\n", argv[0]); |
| 1085 | ret = -EINVAL; |
| 1086 | goto out; |
| 1087 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1088 | pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1089 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1090 | tp->retprobe = (pr == 'r'); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1091 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1092 | /* Scan module name(if there), function name and offset */ |
| 1093 | p = strchr(argv[1], ':'); |
| 1094 | if (p) { |
| 1095 | tp->module = strndup(argv[1], p - argv[1]); |
| 1096 | p++; |
| 1097 | } else |
| 1098 | p = argv[1]; |
| 1099 | ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1100 | &tp->offset); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1101 | if (ret == 1) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1102 | tp->offset = 0; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1103 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1104 | tev->nargs = argc - 2; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1105 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1106 | if (tev->args == NULL) { |
| 1107 | ret = -ENOMEM; |
| 1108 | goto out; |
| 1109 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1110 | for (i = 0; i < tev->nargs; i++) { |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1111 | p = strchr(argv[i + 2], '='); |
| 1112 | if (p) /* We don't need which register is assigned. */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1113 | *p++ = '\0'; |
| 1114 | else |
| 1115 | p = argv[i + 2]; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1116 | tev->args[i].name = strdup(argv[i + 2]); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1117 | /* TODO: parse regs and offset */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1118 | tev->args[i].value = strdup(p); |
| 1119 | if (tev->args[i].name == NULL || tev->args[i].value == NULL) { |
| 1120 | ret = -ENOMEM; |
| 1121 | goto out; |
| 1122 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1123 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1124 | ret = 0; |
| 1125 | out: |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1126 | argv_free(argv); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1127 | return ret; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1128 | } |
| 1129 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1130 | /* Compose only probe arg */ |
| 1131 | int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) |
| 1132 | { |
| 1133 | struct perf_probe_arg_field *field = pa->field; |
| 1134 | int ret; |
| 1135 | char *tmp = buf; |
| 1136 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1137 | if (pa->name && pa->var) |
| 1138 | ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var); |
| 1139 | else |
| 1140 | ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1141 | if (ret <= 0) |
| 1142 | goto error; |
| 1143 | tmp += ret; |
| 1144 | len -= ret; |
| 1145 | |
| 1146 | while (field) { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1147 | if (field->name[0] == '[') |
| 1148 | ret = e_snprintf(tmp, len, "%s", field->name); |
| 1149 | else |
| 1150 | ret = e_snprintf(tmp, len, "%s%s", |
| 1151 | field->ref ? "->" : ".", field->name); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1152 | if (ret <= 0) |
| 1153 | goto error; |
| 1154 | tmp += ret; |
| 1155 | len -= ret; |
| 1156 | field = field->next; |
| 1157 | } |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1158 | |
| 1159 | if (pa->type) { |
| 1160 | ret = e_snprintf(tmp, len, ":%s", pa->type); |
| 1161 | if (ret <= 0) |
| 1162 | goto error; |
| 1163 | tmp += ret; |
| 1164 | len -= ret; |
| 1165 | } |
| 1166 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1167 | return tmp - buf; |
| 1168 | error: |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1169 | pr_debug("Failed to synthesize perf probe argument: %s\n", |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1170 | strerror(-ret)); |
| 1171 | return ret; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1174 | /* Compose only probe point (not argument) */ |
| 1175 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1176 | { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1177 | char *buf, *tmp; |
| 1178 | char offs[32] = "", line[32] = "", file[32] = ""; |
| 1179 | int ret, len; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1180 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1181 | buf = zalloc(MAX_CMDLEN); |
| 1182 | if (buf == NULL) { |
| 1183 | ret = -ENOMEM; |
| 1184 | goto error; |
| 1185 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1186 | if (pp->offset) { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1187 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1188 | if (ret <= 0) |
| 1189 | goto error; |
| 1190 | } |
| 1191 | if (pp->line) { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1192 | ret = e_snprintf(line, 32, ":%d", pp->line); |
| 1193 | if (ret <= 0) |
| 1194 | goto error; |
| 1195 | } |
| 1196 | if (pp->file) { |
Franck Bui-Huu | 32ae2ad | 2010-12-23 16:04:23 +0100 | [diff] [blame] | 1197 | tmp = pp->file; |
| 1198 | len = strlen(tmp); |
| 1199 | if (len > 30) { |
| 1200 | tmp = strchr(pp->file + len - 30, '/'); |
| 1201 | tmp = tmp ? tmp + 1 : pp->file + len - 30; |
| 1202 | } |
| 1203 | ret = e_snprintf(file, 32, "@%s", tmp); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1204 | if (ret <= 0) |
| 1205 | goto error; |
| 1206 | } |
| 1207 | |
| 1208 | if (pp->function) |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1209 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function, |
| 1210 | offs, pp->retprobe ? "%return" : "", line, |
| 1211 | file); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1212 | else |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1213 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1214 | if (ret <= 0) |
| 1215 | goto error; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1216 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1217 | return buf; |
| 1218 | error: |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1219 | pr_debug("Failed to synthesize perf probe point: %s\n", |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1220 | strerror(-ret)); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1221 | if (buf) |
| 1222 | free(buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1223 | return NULL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | #if 0 |
| 1227 | char *synthesize_perf_probe_command(struct perf_probe_event *pev) |
| 1228 | { |
| 1229 | char *buf; |
| 1230 | int i, len, ret; |
| 1231 | |
| 1232 | buf = synthesize_perf_probe_point(&pev->point); |
| 1233 | if (!buf) |
| 1234 | return NULL; |
| 1235 | |
| 1236 | len = strlen(buf); |
| 1237 | for (i = 0; i < pev->nargs; i++) { |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1238 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1239 | pev->args[i].name); |
| 1240 | if (ret <= 0) { |
| 1241 | free(buf); |
| 1242 | return NULL; |
| 1243 | } |
| 1244 | len += ret; |
| 1245 | } |
| 1246 | |
| 1247 | return buf; |
| 1248 | } |
| 1249 | #endif |
| 1250 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1251 | static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1252 | char **buf, size_t *buflen, |
| 1253 | int depth) |
| 1254 | { |
| 1255 | int ret; |
| 1256 | if (ref->next) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1257 | depth = __synthesize_probe_trace_arg_ref(ref->next, buf, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1258 | buflen, depth + 1); |
| 1259 | if (depth < 0) |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset); |
| 1264 | if (ret < 0) |
| 1265 | depth = ret; |
| 1266 | else { |
| 1267 | *buf += ret; |
| 1268 | *buflen -= ret; |
| 1269 | } |
| 1270 | out: |
| 1271 | return depth; |
| 1272 | |
| 1273 | } |
| 1274 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1275 | static int synthesize_probe_trace_arg(struct probe_trace_arg *arg, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1276 | char *buf, size_t buflen) |
| 1277 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1278 | struct probe_trace_arg_ref *ref = arg->ref; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1279 | int ret, depth = 0; |
| 1280 | char *tmp = buf; |
| 1281 | |
| 1282 | /* Argument name or separator */ |
| 1283 | if (arg->name) |
| 1284 | ret = e_snprintf(buf, buflen, " %s=", arg->name); |
| 1285 | else |
| 1286 | ret = e_snprintf(buf, buflen, " "); |
| 1287 | if (ret < 0) |
| 1288 | return ret; |
| 1289 | buf += ret; |
| 1290 | buflen -= ret; |
| 1291 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1292 | /* Special case: @XXX */ |
| 1293 | if (arg->value[0] == '@' && arg->ref) |
| 1294 | ref = ref->next; |
| 1295 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1296 | /* Dereferencing arguments */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1297 | if (ref) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1298 | depth = __synthesize_probe_trace_arg_ref(ref, &buf, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1299 | &buflen, 1); |
| 1300 | if (depth < 0) |
| 1301 | return depth; |
| 1302 | } |
| 1303 | |
| 1304 | /* Print argument value */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1305 | if (arg->value[0] == '@' && arg->ref) |
| 1306 | ret = e_snprintf(buf, buflen, "%s%+ld", arg->value, |
| 1307 | arg->ref->offset); |
| 1308 | else |
| 1309 | ret = e_snprintf(buf, buflen, "%s", arg->value); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1310 | if (ret < 0) |
| 1311 | return ret; |
| 1312 | buf += ret; |
| 1313 | buflen -= ret; |
| 1314 | |
| 1315 | /* Closing */ |
| 1316 | while (depth--) { |
| 1317 | ret = e_snprintf(buf, buflen, ")"); |
| 1318 | if (ret < 0) |
| 1319 | return ret; |
| 1320 | buf += ret; |
| 1321 | buflen -= ret; |
| 1322 | } |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 1323 | /* Print argument type */ |
| 1324 | if (arg->type) { |
| 1325 | ret = e_snprintf(buf, buflen, ":%s", arg->type); |
| 1326 | if (ret <= 0) |
| 1327 | return ret; |
| 1328 | buf += ret; |
| 1329 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1330 | |
| 1331 | return buf - tmp; |
| 1332 | } |
| 1333 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1334 | char *synthesize_probe_trace_command(struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1335 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1336 | struct probe_trace_point *tp = &tev->point; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1337 | char *buf; |
| 1338 | int i, len, ret; |
| 1339 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1340 | buf = zalloc(MAX_CMDLEN); |
| 1341 | if (buf == NULL) |
| 1342 | return NULL; |
| 1343 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1344 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu", |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1345 | tp->retprobe ? 'r' : 'p', |
| 1346 | tev->group, tev->event, |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1347 | tp->module ?: "", tp->module ? ":" : "", |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1348 | tp->symbol, tp->offset); |
| 1349 | if (len <= 0) |
| 1350 | goto error; |
| 1351 | |
| 1352 | for (i = 0; i < tev->nargs; i++) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1353 | ret = synthesize_probe_trace_arg(&tev->args[i], buf + len, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1354 | MAX_CMDLEN - len); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1355 | if (ret <= 0) |
| 1356 | goto error; |
| 1357 | len += ret; |
| 1358 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1359 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1360 | return buf; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1361 | error: |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1362 | free(buf); |
| 1363 | return NULL; |
| 1364 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1365 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1366 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1367 | struct perf_probe_event *pev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1368 | { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1369 | char buf[64] = ""; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1370 | int i, ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1371 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1372 | /* Convert event/group name */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1373 | pev->event = strdup(tev->event); |
| 1374 | pev->group = strdup(tev->group); |
| 1375 | if (pev->event == NULL || pev->group == NULL) |
| 1376 | return -ENOMEM; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1377 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1378 | /* Convert trace_point to probe_point */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1379 | ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1380 | if (ret < 0) |
| 1381 | return ret; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1382 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1383 | /* Convert trace_arg to probe_arg */ |
| 1384 | pev->nargs = tev->nargs; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1385 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
| 1386 | if (pev->args == NULL) |
| 1387 | return -ENOMEM; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1388 | for (i = 0; i < tev->nargs && ret >= 0; i++) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1389 | if (tev->args[i].name) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1390 | pev->args[i].name = strdup(tev->args[i].name); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1391 | else { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1392 | ret = synthesize_probe_trace_arg(&tev->args[i], |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1393 | buf, 64); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1394 | pev->args[i].name = strdup(buf); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1395 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1396 | if (pev->args[i].name == NULL && ret >= 0) |
| 1397 | ret = -ENOMEM; |
| 1398 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1399 | |
| 1400 | if (ret < 0) |
| 1401 | clear_perf_probe_event(pev); |
| 1402 | |
| 1403 | return ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | void clear_perf_probe_event(struct perf_probe_event *pev) |
| 1407 | { |
| 1408 | struct perf_probe_point *pp = &pev->point; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1409 | struct perf_probe_arg_field *field, *next; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1410 | int i; |
| 1411 | |
| 1412 | if (pev->event) |
| 1413 | free(pev->event); |
| 1414 | if (pev->group) |
| 1415 | free(pev->group); |
| 1416 | if (pp->file) |
| 1417 | free(pp->file); |
| 1418 | if (pp->function) |
| 1419 | free(pp->function); |
| 1420 | if (pp->lazy_line) |
| 1421 | free(pp->lazy_line); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1422 | for (i = 0; i < pev->nargs; i++) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1423 | if (pev->args[i].name) |
| 1424 | free(pev->args[i].name); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1425 | if (pev->args[i].var) |
| 1426 | free(pev->args[i].var); |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1427 | if (pev->args[i].type) |
| 1428 | free(pev->args[i].type); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1429 | field = pev->args[i].field; |
| 1430 | while (field) { |
| 1431 | next = field->next; |
| 1432 | if (field->name) |
| 1433 | free(field->name); |
| 1434 | free(field); |
| 1435 | field = next; |
| 1436 | } |
| 1437 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1438 | if (pev->args) |
| 1439 | free(pev->args); |
| 1440 | memset(pev, 0, sizeof(*pev)); |
| 1441 | } |
| 1442 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1443 | static void clear_probe_trace_event(struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1444 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1445 | struct probe_trace_arg_ref *ref, *next; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1446 | int i; |
| 1447 | |
| 1448 | if (tev->event) |
| 1449 | free(tev->event); |
| 1450 | if (tev->group) |
| 1451 | free(tev->group); |
| 1452 | if (tev->point.symbol) |
| 1453 | free(tev->point.symbol); |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1454 | if (tev->point.module) |
| 1455 | free(tev->point.module); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1456 | for (i = 0; i < tev->nargs; i++) { |
| 1457 | if (tev->args[i].name) |
| 1458 | free(tev->args[i].name); |
| 1459 | if (tev->args[i].value) |
| 1460 | free(tev->args[i].value); |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 1461 | if (tev->args[i].type) |
| 1462 | free(tev->args[i].type); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1463 | ref = tev->args[i].ref; |
| 1464 | while (ref) { |
| 1465 | next = ref->next; |
| 1466 | free(ref); |
| 1467 | ref = next; |
| 1468 | } |
| 1469 | } |
| 1470 | if (tev->args) |
| 1471 | free(tev->args); |
| 1472 | memset(tev, 0, sizeof(*tev)); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1473 | } |
| 1474 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1475 | static int open_kprobe_events(bool readwrite) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1476 | { |
| 1477 | char buf[PATH_MAX]; |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1478 | const char *__debugfs; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1479 | int ret; |
| 1480 | |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1481 | __debugfs = debugfs_find_mountpoint(); |
| 1482 | if (__debugfs == NULL) { |
| 1483 | pr_warning("Debugfs is not mounted.\n"); |
| 1484 | return -ENOENT; |
| 1485 | } |
| 1486 | |
| 1487 | ret = e_snprintf(buf, PATH_MAX, "%stracing/kprobe_events", __debugfs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1488 | if (ret >= 0) { |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1489 | pr_debug("Opening %s write=%d\n", buf, readwrite); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1490 | if (readwrite && !probe_event_dry_run) |
| 1491 | ret = open(buf, O_RDWR, O_APPEND); |
| 1492 | else |
| 1493 | ret = open(buf, O_RDONLY, 0); |
| 1494 | } |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1495 | |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1496 | if (ret < 0) { |
| 1497 | if (errno == ENOENT) |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1498 | pr_warning("kprobe_events file does not exist - please" |
| 1499 | " rebuild kernel with CONFIG_KPROBE_EVENT.\n"); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1500 | else |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1501 | pr_warning("Failed to open kprobe_events file: %s\n", |
| 1502 | strerror(errno)); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1503 | } |
| 1504 | return ret; |
| 1505 | } |
| 1506 | |
| 1507 | /* Get raw string list of current kprobe_events */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1508 | static struct strlist *get_probe_trace_command_rawlist(int fd) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1509 | { |
| 1510 | int ret, idx; |
| 1511 | FILE *fp; |
| 1512 | char buf[MAX_CMDLEN]; |
| 1513 | char *p; |
| 1514 | struct strlist *sl; |
| 1515 | |
| 1516 | sl = strlist__new(true, NULL); |
| 1517 | |
| 1518 | fp = fdopen(dup(fd), "r"); |
| 1519 | while (!feof(fp)) { |
| 1520 | p = fgets(buf, MAX_CMDLEN, fp); |
| 1521 | if (!p) |
| 1522 | break; |
| 1523 | |
| 1524 | idx = strlen(p) - 1; |
| 1525 | if (p[idx] == '\n') |
| 1526 | p[idx] = '\0'; |
| 1527 | ret = strlist__add(sl, buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1528 | if (ret < 0) { |
| 1529 | pr_debug("strlist__add failed: %s\n", strerror(-ret)); |
| 1530 | strlist__delete(sl); |
| 1531 | return NULL; |
| 1532 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1533 | } |
| 1534 | fclose(fp); |
| 1535 | |
| 1536 | return sl; |
| 1537 | } |
| 1538 | |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1539 | /* Show an event */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1540 | static int show_perf_probe_event(struct perf_probe_event *pev) |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1541 | { |
Masami Hiramatsu | 7e990a5 | 2009-12-15 10:31:21 -0500 | [diff] [blame] | 1542 | int i, ret; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1543 | char buf[128]; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1544 | char *place; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1545 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1546 | /* Synthesize only event probe point */ |
| 1547 | place = synthesize_perf_probe_point(&pev->point); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1548 | if (!place) |
| 1549 | return -EINVAL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1550 | |
| 1551 | ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event); |
Masami Hiramatsu | 7e990a5 | 2009-12-15 10:31:21 -0500 | [diff] [blame] | 1552 | if (ret < 0) |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1553 | return ret; |
| 1554 | |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1555 | printf(" %-20s (on %s", buf, place); |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1556 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1557 | if (pev->nargs > 0) { |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1558 | printf(" with"); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1559 | for (i = 0; i < pev->nargs; i++) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1560 | ret = synthesize_perf_probe_arg(&pev->args[i], |
| 1561 | buf, 128); |
| 1562 | if (ret < 0) |
| 1563 | break; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1564 | printf(" %s", buf); |
| 1565 | } |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1566 | } |
| 1567 | printf(")\n"); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1568 | free(place); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1569 | return ret; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 1570 | } |
| 1571 | |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1572 | /* List up current perf-probe events */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1573 | int show_perf_probe_events(void) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1574 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1575 | int fd, ret; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1576 | struct probe_trace_event tev; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1577 | struct perf_probe_event pev; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1578 | struct strlist *rawlist; |
| 1579 | struct str_node *ent; |
| 1580 | |
Masami Hiramatsu | 7204133 | 2010-01-05 17:47:10 -0500 | [diff] [blame] | 1581 | setup_pager(); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1582 | ret = init_vmlinux(); |
| 1583 | if (ret < 0) |
| 1584 | return ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1585 | |
| 1586 | memset(&tev, 0, sizeof(tev)); |
| 1587 | memset(&pev, 0, sizeof(pev)); |
Masami Hiramatsu | 7204133 | 2010-01-05 17:47:10 -0500 | [diff] [blame] | 1588 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1589 | fd = open_kprobe_events(false); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1590 | if (fd < 0) |
| 1591 | return fd; |
| 1592 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1593 | rawlist = get_probe_trace_command_rawlist(fd); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1594 | close(fd); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1595 | if (!rawlist) |
| 1596 | return -ENOENT; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1597 | |
Masami Hiramatsu | adf365f | 2009-12-15 10:32:03 -0500 | [diff] [blame] | 1598 | strlist__for_each(ent, rawlist) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1599 | ret = parse_probe_trace_command(ent->s, &tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1600 | if (ret >= 0) { |
| 1601 | ret = convert_to_perf_probe_event(&tev, &pev); |
| 1602 | if (ret >= 0) |
| 1603 | ret = show_perf_probe_event(&pev); |
| 1604 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1605 | clear_perf_probe_event(&pev); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1606 | clear_probe_trace_event(&tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1607 | if (ret < 0) |
| 1608 | break; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1609 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1610 | strlist__delete(rawlist); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1611 | |
| 1612 | return ret; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1613 | } |
| 1614 | |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1615 | /* Get current perf-probe event names */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1616 | static struct strlist *get_probe_trace_event_names(int fd, bool include_group) |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1617 | { |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1618 | char buf[128]; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1619 | struct strlist *sl, *rawlist; |
| 1620 | struct str_node *ent; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1621 | struct probe_trace_event tev; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1622 | int ret = 0; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1623 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1624 | memset(&tev, 0, sizeof(tev)); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1625 | rawlist = get_probe_trace_command_rawlist(fd); |
Masami Hiramatsu | e1d2017 | 2009-12-07 12:00:46 -0500 | [diff] [blame] | 1626 | sl = strlist__new(true, NULL); |
Masami Hiramatsu | adf365f | 2009-12-15 10:32:03 -0500 | [diff] [blame] | 1627 | strlist__for_each(ent, rawlist) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1628 | ret = parse_probe_trace_command(ent->s, &tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1629 | if (ret < 0) |
| 1630 | break; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1631 | if (include_group) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1632 | ret = e_snprintf(buf, 128, "%s:%s", tev.group, |
| 1633 | tev.event); |
| 1634 | if (ret >= 0) |
| 1635 | ret = strlist__add(sl, buf); |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1636 | } else |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1637 | ret = strlist__add(sl, tev.event); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1638 | clear_probe_trace_event(&tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1639 | if (ret < 0) |
| 1640 | break; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1641 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1642 | strlist__delete(rawlist); |
| 1643 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1644 | if (ret < 0) { |
| 1645 | strlist__delete(sl); |
| 1646 | return NULL; |
| 1647 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1648 | return sl; |
| 1649 | } |
| 1650 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1651 | static int write_probe_trace_event(int fd, struct probe_trace_event *tev) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1652 | { |
Frederic Weisbecker | 6eca8cc | 2010-04-21 02:01:05 +0200 | [diff] [blame] | 1653 | int ret = 0; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1654 | char *buf = synthesize_probe_trace_command(tev); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1655 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1656 | if (!buf) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1657 | pr_debug("Failed to synthesize probe trace event.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1658 | return -EINVAL; |
| 1659 | } |
| 1660 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1661 | pr_debug("Writing event: %s\n", buf); |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1662 | if (!probe_event_dry_run) { |
| 1663 | ret = write(fd, buf, strlen(buf)); |
| 1664 | if (ret <= 0) |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1665 | pr_warning("Failed to write event: %s\n", |
| 1666 | strerror(errno)); |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1667 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1668 | free(buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1669 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1670 | } |
| 1671 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1672 | static int get_new_event_name(char *buf, size_t len, const char *base, |
| 1673 | struct strlist *namelist, bool allow_suffix) |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1674 | { |
| 1675 | int i, ret; |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 1676 | |
| 1677 | /* Try no suffix */ |
| 1678 | ret = e_snprintf(buf, len, "%s", base); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1679 | if (ret < 0) { |
| 1680 | pr_debug("snprintf() failed: %s\n", strerror(-ret)); |
| 1681 | return ret; |
| 1682 | } |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 1683 | if (!strlist__has_entry(namelist, buf)) |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1684 | return 0; |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 1685 | |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 1686 | if (!allow_suffix) { |
| 1687 | pr_warning("Error: event \"%s\" already exists. " |
| 1688 | "(Use -f to force duplicates.)\n", base); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1689 | return -EEXIST; |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 1690 | } |
| 1691 | |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 1692 | /* Try to add suffix */ |
| 1693 | for (i = 1; i < MAX_EVENT_INDEX; i++) { |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1694 | ret = e_snprintf(buf, len, "%s_%d", base, i); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1695 | if (ret < 0) { |
| 1696 | pr_debug("snprintf() failed: %s\n", strerror(-ret)); |
| 1697 | return ret; |
| 1698 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1699 | if (!strlist__has_entry(namelist, buf)) |
| 1700 | break; |
| 1701 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1702 | if (i == MAX_EVENT_INDEX) { |
| 1703 | pr_warning("Too many events are on the same function.\n"); |
| 1704 | ret = -ERANGE; |
| 1705 | } |
| 1706 | |
| 1707 | return ret; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1708 | } |
| 1709 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1710 | static int __add_probe_trace_events(struct perf_probe_event *pev, |
| 1711 | struct probe_trace_event *tevs, |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1712 | int ntevs, bool allow_suffix) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1713 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1714 | int i, fd, ret; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1715 | struct probe_trace_event *tev = NULL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1716 | char buf[64]; |
| 1717 | const char *event, *group; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1718 | struct strlist *namelist; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1719 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 1720 | fd = open_kprobe_events(true); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1721 | if (fd < 0) |
| 1722 | return fd; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 1723 | /* Get current event names */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1724 | namelist = get_probe_trace_event_names(fd, false); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1725 | if (!namelist) { |
| 1726 | pr_debug("Failed to get current event list.\n"); |
| 1727 | return -EIO; |
| 1728 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1729 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1730 | ret = 0; |
Srikar Dronamraju | a844d1e | 2012-01-20 17:43:54 +0530 | [diff] [blame] | 1731 | printf("Added new event%s\n", (ntevs > 1) ? "s:" : ":"); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1732 | for (i = 0; i < ntevs; i++) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1733 | tev = &tevs[i]; |
| 1734 | if (pev->event) |
| 1735 | event = pev->event; |
| 1736 | else |
| 1737 | if (pev->point.function) |
| 1738 | event = pev->point.function; |
| 1739 | else |
| 1740 | event = tev->point.symbol; |
| 1741 | if (pev->group) |
| 1742 | group = pev->group; |
| 1743 | else |
| 1744 | group = PERFPROBE_GROUP; |
| 1745 | |
| 1746 | /* Get an unused new event name */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1747 | ret = get_new_event_name(buf, 64, event, |
| 1748 | namelist, allow_suffix); |
| 1749 | if (ret < 0) |
| 1750 | break; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1751 | event = buf; |
| 1752 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1753 | tev->event = strdup(event); |
| 1754 | tev->group = strdup(group); |
| 1755 | if (tev->event == NULL || tev->group == NULL) { |
| 1756 | ret = -ENOMEM; |
| 1757 | break; |
| 1758 | } |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1759 | ret = write_probe_trace_event(fd, tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1760 | if (ret < 0) |
| 1761 | break; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1762 | /* Add added event name to namelist */ |
| 1763 | strlist__add(namelist, event); |
| 1764 | |
| 1765 | /* Trick here - save current event/group */ |
| 1766 | event = pev->event; |
| 1767 | group = pev->group; |
| 1768 | pev->event = tev->event; |
| 1769 | pev->group = tev->group; |
| 1770 | show_perf_probe_event(pev); |
| 1771 | /* Trick here - restore current event/group */ |
| 1772 | pev->event = (char *)event; |
| 1773 | pev->group = (char *)group; |
| 1774 | |
| 1775 | /* |
| 1776 | * Probes after the first probe which comes from same |
| 1777 | * user input are always allowed to add suffix, because |
| 1778 | * there might be several addresses corresponding to |
| 1779 | * one code line. |
| 1780 | */ |
| 1781 | allow_suffix = true; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1782 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1783 | |
| 1784 | if (ret >= 0) { |
| 1785 | /* Show how to use the event. */ |
Srikar Dronamraju | a844d1e | 2012-01-20 17:43:54 +0530 | [diff] [blame] | 1786 | printf("\nYou can now use it in all perf tools, such as:\n\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1787 | printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group, |
| 1788 | tev->event); |
| 1789 | } |
Masami Hiramatsu | a9b495b | 2009-12-08 17:02:47 -0500 | [diff] [blame] | 1790 | |
Masami Hiramatsu | e1d2017 | 2009-12-07 12:00:46 -0500 | [diff] [blame] | 1791 | strlist__delete(namelist); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1792 | close(fd); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1793 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1794 | } |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1795 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1796 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, |
| 1797 | struct probe_trace_event **tevs, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 1798 | int max_tevs, const char *target) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 1799 | { |
| 1800 | struct symbol *sym; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1801 | int ret = 0, i; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1802 | struct probe_trace_event *tev; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1803 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1804 | /* Convert perf_probe_event with debuginfo */ |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 1805 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1806 | if (ret != 0) |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1807 | return ret; /* Found in debuginfo or got an error */ |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 1808 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1809 | /* Allocate trace event buffer */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1810 | tev = *tevs = zalloc(sizeof(struct probe_trace_event)); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1811 | if (tev == NULL) |
| 1812 | return -ENOMEM; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 1813 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1814 | /* Copy parameters */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1815 | tev->point.symbol = strdup(pev->point.function); |
| 1816 | if (tev->point.symbol == NULL) { |
| 1817 | ret = -ENOMEM; |
| 1818 | goto error; |
| 1819 | } |
Jovi Zhang | ce27a44 | 2011-07-25 22:08:08 +0800 | [diff] [blame] | 1820 | |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 1821 | if (target) { |
| 1822 | tev->point.module = strdup(target); |
Jovi Zhang | ce27a44 | 2011-07-25 22:08:08 +0800 | [diff] [blame] | 1823 | if (tev->point.module == NULL) { |
| 1824 | ret = -ENOMEM; |
| 1825 | goto error; |
| 1826 | } |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1827 | } |
Jovi Zhang | ce27a44 | 2011-07-25 22:08:08 +0800 | [diff] [blame] | 1828 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1829 | tev->point.offset = pev->point.offset; |
Masami Hiramatsu | 04ddd04 | 2010-08-27 20:38:53 +0900 | [diff] [blame] | 1830 | tev->point.retprobe = pev->point.retprobe; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1831 | tev->nargs = pev->nargs; |
| 1832 | if (tev->nargs) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1833 | tev->args = zalloc(sizeof(struct probe_trace_arg) |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1834 | * tev->nargs); |
| 1835 | if (tev->args == NULL) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1836 | ret = -ENOMEM; |
| 1837 | goto error; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1838 | } |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1839 | for (i = 0; i < tev->nargs; i++) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1840 | if (pev->args[i].name) { |
| 1841 | tev->args[i].name = strdup(pev->args[i].name); |
| 1842 | if (tev->args[i].name == NULL) { |
| 1843 | ret = -ENOMEM; |
| 1844 | goto error; |
| 1845 | } |
| 1846 | } |
| 1847 | tev->args[i].value = strdup(pev->args[i].var); |
| 1848 | if (tev->args[i].value == NULL) { |
| 1849 | ret = -ENOMEM; |
| 1850 | goto error; |
| 1851 | } |
| 1852 | if (pev->args[i].type) { |
| 1853 | tev->args[i].type = strdup(pev->args[i].type); |
| 1854 | if (tev->args[i].type == NULL) { |
| 1855 | ret = -ENOMEM; |
| 1856 | goto error; |
| 1857 | } |
| 1858 | } |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1859 | } |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 1860 | } |
| 1861 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1862 | /* Currently just checking function name from symbol map */ |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1863 | sym = __find_kernel_function_by_name(tev->point.symbol, NULL); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1864 | if (!sym) { |
| 1865 | pr_warning("Kernel symbol \'%s\' not found.\n", |
| 1866 | tev->point.symbol); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1867 | ret = -ENOENT; |
| 1868 | goto error; |
Prashanth Nageshappa | 1c1bc92 | 2012-02-28 09:43:01 +0530 | [diff] [blame] | 1869 | } else if (tev->point.offset > sym->end - sym->start) { |
| 1870 | pr_warning("Offset specified is greater than size of %s\n", |
| 1871 | tev->point.symbol); |
| 1872 | ret = -ENOENT; |
| 1873 | goto error; |
| 1874 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1875 | } |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1876 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1877 | return 1; |
| 1878 | error: |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1879 | clear_probe_trace_event(tev); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1880 | free(tev); |
| 1881 | *tevs = NULL; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1882 | return ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | struct __event_package { |
| 1886 | struct perf_probe_event *pev; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1887 | struct probe_trace_event *tevs; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1888 | int ntevs; |
| 1889 | }; |
| 1890 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1891 | int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 1892 | int max_tevs, const char *target, bool force_add) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1893 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1894 | int i, j, ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1895 | struct __event_package *pkgs; |
| 1896 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1897 | pkgs = zalloc(sizeof(struct __event_package) * npevs); |
| 1898 | if (pkgs == NULL) |
| 1899 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1900 | |
| 1901 | /* Init vmlinux path */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1902 | ret = init_vmlinux(); |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 1903 | if (ret < 0) { |
| 1904 | free(pkgs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1905 | return ret; |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 1906 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1907 | |
| 1908 | /* Loop 1: convert all events */ |
| 1909 | for (i = 0; i < npevs; i++) { |
| 1910 | pkgs[i].pev = &pevs[i]; |
| 1911 | /* Convert with or without debuginfo */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1912 | ret = convert_to_probe_trace_events(pkgs[i].pev, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 1913 | &pkgs[i].tevs, |
| 1914 | max_tevs, |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 1915 | target); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1916 | if (ret < 0) |
| 1917 | goto end; |
| 1918 | pkgs[i].ntevs = ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /* Loop 2: add all events */ |
Arnaldo Carvalho de Melo | 8635bf6 | 2011-02-22 06:56:18 -0300 | [diff] [blame] | 1922 | for (i = 0; i < npevs; i++) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1923 | ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs, |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1924 | pkgs[i].ntevs, force_add); |
Arnaldo Carvalho de Melo | fbee632 | 2011-02-21 13:23:57 -0300 | [diff] [blame] | 1925 | if (ret < 0) |
| 1926 | break; |
| 1927 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1928 | end: |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 1929 | /* Loop 3: cleanup and free trace events */ |
| 1930 | for (i = 0; i < npevs; i++) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1931 | for (j = 0; j < pkgs[i].ntevs; j++) |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1932 | clear_probe_trace_event(&pkgs[i].tevs[j]); |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 1933 | free(pkgs[i].tevs); |
| 1934 | } |
| 1935 | free(pkgs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1936 | |
| 1937 | return ret; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 1938 | } |
| 1939 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1940 | static int __del_trace_probe_event(int fd, struct str_node *ent) |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1941 | { |
| 1942 | char *p; |
| 1943 | char buf[128]; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1944 | int ret; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1945 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1946 | /* Convert from perf-probe event to trace-probe event */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1947 | ret = e_snprintf(buf, 128, "-:%s", ent->s); |
| 1948 | if (ret < 0) |
| 1949 | goto error; |
| 1950 | |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1951 | p = strchr(buf + 2, ':'); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1952 | if (!p) { |
| 1953 | pr_debug("Internal error: %s should have ':' but not.\n", |
| 1954 | ent->s); |
| 1955 | ret = -ENOTSUP; |
| 1956 | goto error; |
| 1957 | } |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1958 | *p = '/'; |
| 1959 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1960 | pr_debug("Writing event: %s\n", buf); |
| 1961 | ret = write(fd, buf, strlen(buf)); |
Masami Hiramatsu | 44a5604 | 2011-10-04 19:45:04 +0900 | [diff] [blame] | 1962 | if (ret < 0) { |
| 1963 | ret = -errno; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1964 | goto error; |
Masami Hiramatsu | 44a5604 | 2011-10-04 19:45:04 +0900 | [diff] [blame] | 1965 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1966 | |
Srikar Dronamraju | a844d1e | 2012-01-20 17:43:54 +0530 | [diff] [blame] | 1967 | printf("Removed event: %s\n", ent->s); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1968 | return 0; |
| 1969 | error: |
| 1970 | pr_warning("Failed to delete event: %s\n", strerror(-ret)); |
| 1971 | return ret; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1972 | } |
| 1973 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1974 | static int del_trace_probe_event(int fd, const char *group, |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1975 | const char *event, struct strlist *namelist) |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1976 | { |
| 1977 | char buf[128]; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1978 | struct str_node *ent, *n; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1979 | int found = 0, ret = 0; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1980 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1981 | ret = e_snprintf(buf, 128, "%s:%s", group, event); |
| 1982 | if (ret < 0) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1983 | pr_err("Failed to copy event.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1984 | return ret; |
| 1985 | } |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 1986 | |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1987 | if (strpbrk(buf, "*?")) { /* Glob-exp */ |
| 1988 | strlist__for_each_safe(ent, n, namelist) |
| 1989 | if (strglobmatch(ent->s, buf)) { |
| 1990 | found++; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1991 | ret = __del_trace_probe_event(fd, ent); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1992 | if (ret < 0) |
| 1993 | break; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 1994 | strlist__remove(namelist, ent); |
| 1995 | } |
| 1996 | } else { |
| 1997 | ent = strlist__find(namelist, buf); |
| 1998 | if (ent) { |
| 1999 | found++; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2000 | ret = __del_trace_probe_event(fd, ent); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2001 | if (ret >= 0) |
| 2002 | strlist__remove(namelist, ent); |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2003 | } |
| 2004 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2005 | if (found == 0 && ret >= 0) |
| 2006 | pr_info("Info: Event \"%s\" does not exist.\n", buf); |
| 2007 | |
| 2008 | return ret; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2009 | } |
| 2010 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2011 | int del_perf_probe_events(struct strlist *dellist) |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2012 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2013 | int fd, ret = 0; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2014 | const char *group, *event; |
| 2015 | char *p, *str; |
| 2016 | struct str_node *ent; |
| 2017 | struct strlist *namelist; |
| 2018 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 2019 | fd = open_kprobe_events(true); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2020 | if (fd < 0) |
| 2021 | return fd; |
| 2022 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2023 | /* Get current event names */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2024 | namelist = get_probe_trace_event_names(fd, true); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2025 | if (namelist == NULL) |
| 2026 | return -EINVAL; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2027 | |
Masami Hiramatsu | adf365f | 2009-12-15 10:32:03 -0500 | [diff] [blame] | 2028 | strlist__for_each(ent, dellist) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 2029 | str = strdup(ent->s); |
| 2030 | if (str == NULL) { |
| 2031 | ret = -ENOMEM; |
| 2032 | break; |
| 2033 | } |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2034 | pr_debug("Parsing: %s\n", str); |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2035 | p = strchr(str, ':'); |
| 2036 | if (p) { |
| 2037 | group = str; |
| 2038 | *p = '\0'; |
| 2039 | event = p + 1; |
| 2040 | } else { |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2041 | group = "*"; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2042 | event = str; |
| 2043 | } |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2044 | pr_debug("Group: %s, Event: %s\n", group, event); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2045 | ret = del_trace_probe_event(fd, group, event, namelist); |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2046 | free(str); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2047 | if (ret < 0) |
| 2048 | break; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2049 | } |
| 2050 | strlist__delete(namelist); |
| 2051 | close(fd); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2052 | |
| 2053 | return ret; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2054 | } |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2055 | /* TODO: don't use a global variable for filter ... */ |
| 2056 | static struct strfilter *available_func_filter; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2057 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2058 | /* |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2059 | * If a symbol corresponds to a function with global binding and |
| 2060 | * matches filter return 0. For all others return 1. |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2061 | */ |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2062 | static int filter_available_functions(struct map *map __unused, |
| 2063 | struct symbol *sym) |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2064 | { |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2065 | if (sym->binding == STB_GLOBAL && |
| 2066 | strfilter__compare(available_func_filter, sym->name)) |
| 2067 | return 0; |
| 2068 | return 1; |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2069 | } |
| 2070 | |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 2071 | int show_available_funcs(const char *target, struct strfilter *_filter) |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2072 | { |
| 2073 | struct map *map; |
| 2074 | int ret; |
| 2075 | |
| 2076 | setup_pager(); |
| 2077 | |
| 2078 | ret = init_vmlinux(); |
| 2079 | if (ret < 0) |
| 2080 | return ret; |
| 2081 | |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 2082 | map = kernel_get_module_map(target); |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2083 | if (!map) { |
Srikar Dronamraju | 4eced23 | 2012-02-02 19:50:40 +0530 | [diff] [blame] | 2084 | pr_err("Failed to find %s map.\n", (target) ? : "kernel"); |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2085 | return -EINVAL; |
| 2086 | } |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2087 | available_func_filter = _filter; |
| 2088 | if (map__load(map, filter_available_functions)) { |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2089 | pr_err("Failed to load map.\n"); |
| 2090 | return -EINVAL; |
| 2091 | } |
| 2092 | if (!dso__sorted_by_name(map->dso, map->type)) |
| 2093 | dso__sort_by_name(map->dso, map->type); |
| 2094 | |
| 2095 | dso__fprintf_symbols_by_name(map->dso, map->type, stdout); |
| 2096 | return 0; |
| 2097 | } |