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" |
Borislav Petkov | 553873e | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 43 | #include <api/fs/debugfs.h> |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 44 | #include <api/fs/tracefs.h> |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 45 | #include "trace-event.h" /* For __maybe_unused */ |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 46 | #include "probe-event.h" |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 47 | #include "probe-finder.h" |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 48 | #include "session.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 49 | |
| 50 | #define MAX_CMDLEN 256 |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 51 | #define PERFPROBE_GROUP "probe" |
| 52 | |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 53 | bool probe_event_dry_run; /* Dry run flag */ |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 54 | struct probe_conf probe_conf; |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 55 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 56 | #define semantic_error(msg ...) pr_err("Semantic error :" msg) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 57 | |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 58 | /* If there is no space to write, returns -E2BIG. */ |
| 59 | static int e_snprintf(char *str, size_t size, const char *format, ...) |
Masami Hiramatsu | 8498845 | 2009-12-07 12:00:53 -0500 | [diff] [blame] | 60 | __attribute__((format(printf, 3, 4))); |
| 61 | |
| 62 | static int e_snprintf(char *str, size_t size, const char *format, ...) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 63 | { |
| 64 | int ret; |
| 65 | va_list ap; |
| 66 | va_start(ap, format); |
| 67 | ret = vsnprintf(str, size, format, ap); |
| 68 | va_end(ap); |
| 69 | if (ret >= (int)size) |
| 70 | ret = -E2BIG; |
| 71 | return ret; |
| 72 | } |
| 73 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 74 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
Masami Hiramatsu | 981d05a | 2014-01-16 09:39:44 +0000 | [diff] [blame] | 75 | static void clear_probe_trace_event(struct probe_trace_event *tev); |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 76 | static struct machine *host_machine; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 77 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 78 | /* Initialize symbol maps and path of vmlinux/modules */ |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 79 | static int init_symbol_maps(bool user_only) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 80 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 81 | int ret; |
| 82 | |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 83 | symbol_conf.sort_by_name = true; |
Namhyung Kim | 680d926 | 2015-03-06 16:31:27 +0900 | [diff] [blame] | 84 | symbol_conf.allow_aliases = true; |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 85 | ret = symbol__init(NULL); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 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 | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 91 | if (host_machine || user_only) /* already initialized */ |
| 92 | return 0; |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 93 | |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 94 | if (symbol_conf.vmlinux_name) |
| 95 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); |
| 96 | |
| 97 | host_machine = machine__new_host(); |
| 98 | if (!host_machine) { |
| 99 | pr_debug("machine__new_host() failed.\n"); |
| 100 | symbol__exit(); |
| 101 | ret = -1; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 102 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 103 | out: |
| 104 | if (ret < 0) |
| 105 | pr_warning("Failed to init vmlinux path.\n"); |
| 106 | return ret; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 109 | static void exit_symbol_maps(void) |
| 110 | { |
| 111 | if (host_machine) { |
| 112 | machine__delete(host_machine); |
| 113 | host_machine = NULL; |
| 114 | } |
| 115 | symbol__exit(); |
| 116 | } |
| 117 | |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 118 | static struct symbol *__find_kernel_function_by_name(const char *name, |
| 119 | struct map **mapp) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 120 | { |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 121 | return machine__find_kernel_function_by_name(host_machine, name, mapp, |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 122 | NULL); |
| 123 | } |
| 124 | |
Masami Hiramatsu | 8f33f7d | 2014-02-06 05:32:20 +0000 | [diff] [blame] | 125 | static struct symbol *__find_kernel_function(u64 addr, struct map **mapp) |
| 126 | { |
| 127 | return machine__find_kernel_function(host_machine, addr, mapp, NULL); |
| 128 | } |
| 129 | |
| 130 | static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) |
| 131 | { |
| 132 | /* kmap->ref_reloc_sym should be set if host_machine is initialized */ |
| 133 | struct kmap *kmap; |
| 134 | |
| 135 | if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0) |
| 136 | return NULL; |
| 137 | |
| 138 | kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]); |
Wang Nan | ba92732 | 2015-04-07 08:22:45 +0000 | [diff] [blame] | 139 | if (!kmap) |
| 140 | return NULL; |
Masami Hiramatsu | 8f33f7d | 2014-02-06 05:32:20 +0000 | [diff] [blame] | 141 | return kmap->ref_reloc_sym; |
| 142 | } |
| 143 | |
| 144 | static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc) |
| 145 | { |
| 146 | struct ref_reloc_sym *reloc_sym; |
| 147 | struct symbol *sym; |
| 148 | struct map *map; |
| 149 | |
| 150 | /* ref_reloc_sym is just a label. Need a special fix*/ |
| 151 | reloc_sym = kernel_get_ref_reloc_sym(); |
| 152 | if (reloc_sym && strcmp(name, reloc_sym->name) == 0) |
| 153 | return (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr; |
| 154 | else { |
| 155 | sym = __find_kernel_function_by_name(name, &map); |
| 156 | if (sym) |
| 157 | return map->unmap_ip(map, sym->start) - |
He Kuang | f56847c | 2015-02-27 18:52:53 +0800 | [diff] [blame] | 158 | ((reloc) ? 0 : map->reloc); |
Masami Hiramatsu | 8f33f7d | 2014-02-06 05:32:20 +0000 | [diff] [blame] | 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 163 | static struct map *kernel_get_module_map(const char *module) |
| 164 | { |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 165 | struct map_groups *grp = &host_machine->kmaps; |
Arnaldo Carvalho de Melo | 1eee78a | 2015-05-22 12:58:53 -0300 | [diff] [blame] | 166 | struct maps *maps = &grp->maps[MAP__FUNCTION]; |
Arnaldo Carvalho de Melo | 4bb7123d | 2015-05-22 11:52:22 -0300 | [diff] [blame] | 167 | struct map *pos; |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 168 | |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 169 | /* A file path -- this is an offline module */ |
| 170 | if (module && strchr(module, '/')) |
Arnaldo Carvalho de Melo | 9f2de31 | 2015-06-01 12:01:02 -0300 | [diff] [blame] | 171 | return machine__findnew_module_map(host_machine, 0, module); |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 172 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 173 | if (!module) |
| 174 | module = "kernel"; |
| 175 | |
Arnaldo Carvalho de Melo | 4bb7123d | 2015-05-22 11:52:22 -0300 | [diff] [blame] | 176 | for (pos = maps__first(maps); pos; pos = map__next(pos)) { |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 177 | if (strncmp(pos->dso->short_name + 1, module, |
| 178 | pos->dso->short_name_len - 2) == 0) { |
| 179 | return pos; |
| 180 | } |
| 181 | } |
| 182 | return NULL; |
| 183 | } |
| 184 | |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 185 | static struct map *get_target_map(const char *target, bool user) |
| 186 | { |
| 187 | /* Init maps of given executable or kernel */ |
| 188 | if (user) |
| 189 | return dso__new_map(target); |
| 190 | else |
| 191 | return kernel_get_module_map(target); |
| 192 | } |
| 193 | |
| 194 | static void put_target_map(struct map *map, bool user) |
| 195 | { |
| 196 | if (map && user) { |
| 197 | /* Only the user map needs to be released */ |
Arnaldo Carvalho de Melo | 84c2caf | 2015-05-25 16:59:56 -0300 | [diff] [blame] | 198 | map__put(map); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
| 202 | |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 203 | static int convert_exec_to_group(const char *exec, char **result) |
| 204 | { |
| 205 | char *ptr1, *ptr2, *exec_copy; |
| 206 | char buf[64]; |
| 207 | int ret; |
| 208 | |
| 209 | exec_copy = strdup(exec); |
| 210 | if (!exec_copy) |
| 211 | return -ENOMEM; |
| 212 | |
| 213 | ptr1 = basename(exec_copy); |
| 214 | if (!ptr1) { |
| 215 | ret = -EINVAL; |
| 216 | goto out; |
| 217 | } |
| 218 | |
| 219 | ptr2 = strpbrk(ptr1, "-._"); |
| 220 | if (ptr2) |
| 221 | *ptr2 = '\0'; |
| 222 | ret = e_snprintf(buf, 64, "%s_%s", PERFPROBE_GROUP, ptr1); |
| 223 | if (ret < 0) |
| 224 | goto out; |
| 225 | |
| 226 | *result = strdup(buf); |
| 227 | ret = *result ? 0 : -ENOMEM; |
| 228 | |
| 229 | out: |
| 230 | free(exec_copy); |
| 231 | return ret; |
| 232 | } |
| 233 | |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 234 | static void clear_perf_probe_point(struct perf_probe_point *pp) |
| 235 | { |
| 236 | free(pp->file); |
| 237 | free(pp->function); |
| 238 | free(pp->lazy_line); |
| 239 | } |
| 240 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 241 | static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) |
| 242 | { |
| 243 | int i; |
| 244 | |
| 245 | for (i = 0; i < ntevs; i++) |
| 246 | clear_probe_trace_event(tevs + i); |
| 247 | } |
| 248 | |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 249 | static bool kprobe_blacklist__listed(unsigned long address); |
| 250 | static bool kprobe_warn_out_range(const char *symbol, unsigned long address) |
| 251 | { |
| 252 | /* Get the address of _etext for checking non-probable text symbol */ |
| 253 | if (kernel_get_symbol_address_by_name("_etext", false) < address) |
| 254 | pr_warning("%s is out of .text, skip it.\n", symbol); |
| 255 | else if (kprobe_blacklist__listed(address)) |
| 256 | pr_warning("%s is blacklisted function, skip it.\n", symbol); |
| 257 | else |
| 258 | return false; |
| 259 | |
| 260 | return true; |
| 261 | } |
| 262 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 263 | #ifdef HAVE_DWARF_SUPPORT |
Wang Nan | 60fb774 | 2015-05-28 02:25:05 +0000 | [diff] [blame] | 264 | |
| 265 | static int kernel_get_module_dso(const char *module, struct dso **pdso) |
| 266 | { |
| 267 | struct dso *dso; |
| 268 | struct map *map; |
| 269 | const char *vmlinux_name; |
| 270 | int ret = 0; |
| 271 | |
| 272 | if (module) { |
Arnaldo Carvalho de Melo | 3d39ac5 | 2015-05-28 13:06:42 -0300 | [diff] [blame] | 273 | list_for_each_entry(dso, &host_machine->dsos.head, node) { |
| 274 | if (!dso->kernel) |
| 275 | continue; |
Wang Nan | 60fb774 | 2015-05-28 02:25:05 +0000 | [diff] [blame] | 276 | if (strncmp(dso->short_name + 1, module, |
| 277 | dso->short_name_len - 2) == 0) |
| 278 | goto found; |
| 279 | } |
| 280 | pr_debug("Failed to find module %s.\n", module); |
| 281 | return -ENOENT; |
| 282 | } |
| 283 | |
| 284 | map = host_machine->vmlinux_maps[MAP__FUNCTION]; |
| 285 | dso = map->dso; |
| 286 | |
| 287 | vmlinux_name = symbol_conf.vmlinux_name; |
| 288 | dso->load_errno = 0; |
| 289 | if (vmlinux_name) |
| 290 | ret = dso__load_vmlinux(dso, map, vmlinux_name, false, NULL); |
| 291 | else |
| 292 | ret = dso__load_vmlinux_path(dso, map, NULL); |
| 293 | found: |
| 294 | *pdso = dso; |
| 295 | return ret; |
| 296 | } |
| 297 | |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 298 | /* |
| 299 | * Some binaries like glibc have special symbols which are on the symbol |
| 300 | * table, but not in the debuginfo. If we can find the address of the |
| 301 | * symbol from map, we can translate the address back to the probe point. |
| 302 | */ |
| 303 | static int find_alternative_probe_point(struct debuginfo *dinfo, |
| 304 | struct perf_probe_point *pp, |
| 305 | struct perf_probe_point *result, |
| 306 | const char *target, bool uprobes) |
| 307 | { |
| 308 | struct map *map = NULL; |
| 309 | struct symbol *sym; |
| 310 | u64 address = 0; |
| 311 | int ret = -ENOENT; |
| 312 | |
| 313 | /* This can work only for function-name based one */ |
| 314 | if (!pp->function || pp->file) |
| 315 | return -ENOTSUP; |
| 316 | |
| 317 | map = get_target_map(target, uprobes); |
| 318 | if (!map) |
| 319 | return -EINVAL; |
| 320 | |
| 321 | /* Find the address of given function */ |
| 322 | map__for_each_symbol_by_name(map, pp->function, sym) { |
Masami Hiramatsu | e6d7c91 | 2015-03-22 20:40:22 +0900 | [diff] [blame] | 323 | if (uprobes) |
| 324 | address = sym->start; |
| 325 | else |
| 326 | address = map->unmap_ip(map, sym->start); |
Namhyung Kim | e578da3 | 2015-03-06 16:31:29 +0900 | [diff] [blame] | 327 | break; |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 328 | } |
| 329 | if (!address) { |
| 330 | ret = -ENOENT; |
| 331 | goto out; |
| 332 | } |
Wang Nan | f6c1562 | 2015-04-08 02:14:34 +0000 | [diff] [blame] | 333 | pr_debug("Symbol %s address found : %" PRIx64 "\n", |
| 334 | pp->function, address); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 335 | |
| 336 | ret = debuginfo__find_probe_point(dinfo, (unsigned long)address, |
| 337 | result); |
| 338 | if (ret <= 0) |
| 339 | ret = (!ret) ? -ENOENT : ret; |
| 340 | else { |
| 341 | result->offset += pp->offset; |
| 342 | result->line += pp->line; |
He Kuang | 9d7b45c | 2015-04-13 19:41:28 +0800 | [diff] [blame] | 343 | result->retprobe = pp->retprobe; |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 344 | ret = 0; |
| 345 | } |
| 346 | |
| 347 | out: |
| 348 | put_target_map(map, uprobes); |
| 349 | return ret; |
| 350 | |
| 351 | } |
| 352 | |
| 353 | static int get_alternative_probe_event(struct debuginfo *dinfo, |
| 354 | struct perf_probe_event *pev, |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 355 | struct perf_probe_point *tmp) |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 356 | { |
| 357 | int ret; |
| 358 | |
| 359 | memcpy(tmp, &pev->point, sizeof(*tmp)); |
| 360 | memset(&pev->point, 0, sizeof(pev->point)); |
| 361 | ret = find_alternative_probe_point(dinfo, tmp, &pev->point, |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 362 | pev->target, pev->uprobes); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 363 | if (ret < 0) |
| 364 | memcpy(&pev->point, tmp, sizeof(*tmp)); |
| 365 | |
| 366 | return ret; |
| 367 | } |
Masami Hiramatsu | a15ad2f | 2014-02-06 05:32:27 +0000 | [diff] [blame] | 368 | |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 369 | static int get_alternative_line_range(struct debuginfo *dinfo, |
| 370 | struct line_range *lr, |
| 371 | const char *target, bool user) |
| 372 | { |
David Ahern | 6d4a489 | 2015-03-11 10:36:20 -0400 | [diff] [blame] | 373 | struct perf_probe_point pp = { .function = lr->function, |
| 374 | .file = lr->file, |
| 375 | .line = lr->start }; |
| 376 | struct perf_probe_point result; |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 377 | int ret, len = 0; |
| 378 | |
David Ahern | 6d4a489 | 2015-03-11 10:36:20 -0400 | [diff] [blame] | 379 | memset(&result, 0, sizeof(result)); |
| 380 | |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 381 | if (lr->end != INT_MAX) |
| 382 | len = lr->end - lr->start; |
| 383 | ret = find_alternative_probe_point(dinfo, &pp, &result, |
| 384 | target, user); |
| 385 | if (!ret) { |
| 386 | lr->function = result.function; |
| 387 | lr->file = result.file; |
| 388 | lr->start = result.line; |
| 389 | if (lr->end != INT_MAX) |
| 390 | lr->end = lr->start + len; |
| 391 | clear_perf_probe_point(&pp); |
| 392 | } |
| 393 | return ret; |
| 394 | } |
| 395 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 396 | /* Open new debuginfo of given module */ |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 397 | static struct debuginfo *open_debuginfo(const char *module, bool silent) |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 398 | { |
Masami Hiramatsu | a15ad2f | 2014-02-06 05:32:27 +0000 | [diff] [blame] | 399 | const char *path = module; |
Masami Hiramatsu | 419e873 | 2015-05-27 17:37:18 +0900 | [diff] [blame] | 400 | char reason[STRERR_BUFSIZE]; |
| 401 | struct debuginfo *ret = NULL; |
| 402 | struct dso *dso = NULL; |
| 403 | int err; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 404 | |
Masami Hiramatsu | a15ad2f | 2014-02-06 05:32:27 +0000 | [diff] [blame] | 405 | if (!module || !strchr(module, '/')) { |
Masami Hiramatsu | 419e873 | 2015-05-27 17:37:18 +0900 | [diff] [blame] | 406 | err = kernel_get_module_dso(module, &dso); |
| 407 | if (err < 0) { |
| 408 | if (!dso || dso->load_errno == 0) { |
| 409 | if (!strerror_r(-err, reason, STRERR_BUFSIZE)) |
| 410 | strcpy(reason, "(unknown)"); |
| 411 | } else |
| 412 | dso__strerror_load(dso, reason, STRERR_BUFSIZE); |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 413 | if (!silent) |
Masami Hiramatsu | 419e873 | 2015-05-27 17:37:18 +0900 | [diff] [blame] | 414 | pr_err("Failed to find the path for %s: %s\n", |
| 415 | module ?: "kernel", reason); |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 416 | return NULL; |
| 417 | } |
Masami Hiramatsu | 419e873 | 2015-05-27 17:37:18 +0900 | [diff] [blame] | 418 | path = dso->long_name; |
Masami Hiramatsu | 469b9b8 | 2010-10-21 19:13:41 +0900 | [diff] [blame] | 419 | } |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 420 | ret = debuginfo__new(path); |
| 421 | if (!ret && !silent) { |
| 422 | pr_warning("The %s file has no debug information.\n", path); |
| 423 | if (!module || !strtailcmp(path, ".ko")) |
| 424 | pr_warning("Rebuild with CONFIG_DEBUG_INFO=y, "); |
| 425 | else |
| 426 | pr_warning("Rebuild with -g, "); |
| 427 | pr_warning("or install an appropriate debuginfo package.\n"); |
| 428 | } |
| 429 | return ret; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 430 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 431 | |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 432 | |
Masami Hiramatsu | 99ca423 | 2014-01-16 09:39:49 +0000 | [diff] [blame] | 433 | static int get_text_start_address(const char *exec, unsigned long *address) |
| 434 | { |
| 435 | Elf *elf; |
| 436 | GElf_Ehdr ehdr; |
| 437 | GElf_Shdr shdr; |
| 438 | int fd, ret = -ENOENT; |
| 439 | |
| 440 | fd = open(exec, O_RDONLY); |
| 441 | if (fd < 0) |
| 442 | return -errno; |
| 443 | |
| 444 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
| 445 | if (elf == NULL) |
| 446 | return -EINVAL; |
| 447 | |
| 448 | if (gelf_getehdr(elf, &ehdr) == NULL) |
| 449 | goto out; |
| 450 | |
| 451 | if (!elf_section_by_name(elf, &ehdr, &shdr, ".text", NULL)) |
| 452 | goto out; |
| 453 | |
| 454 | *address = shdr.sh_addr - shdr.sh_offset; |
| 455 | ret = 0; |
| 456 | out: |
| 457 | elf_end(elf); |
| 458 | return ret; |
| 459 | } |
| 460 | |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 461 | /* |
| 462 | * Convert trace point to probe point with debuginfo |
| 463 | */ |
| 464 | static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp, |
| 465 | struct perf_probe_point *pp, |
| 466 | bool is_kprobe) |
| 467 | { |
| 468 | struct debuginfo *dinfo = NULL; |
| 469 | unsigned long stext = 0; |
| 470 | u64 addr = tp->address; |
| 471 | int ret = -ENOENT; |
| 472 | |
| 473 | /* convert the address to dwarf address */ |
| 474 | if (!is_kprobe) { |
| 475 | if (!addr) { |
| 476 | ret = -EINVAL; |
| 477 | goto error; |
| 478 | } |
| 479 | ret = get_text_start_address(tp->module, &stext); |
| 480 | if (ret < 0) |
| 481 | goto error; |
| 482 | addr += stext; |
| 483 | } else { |
| 484 | addr = kernel_get_symbol_address_by_name(tp->symbol, false); |
| 485 | if (addr == 0) |
| 486 | goto error; |
| 487 | addr += tp->offset; |
| 488 | } |
| 489 | |
| 490 | pr_debug("try to find information at %" PRIx64 " in %s\n", addr, |
| 491 | tp->module ? : "kernel"); |
| 492 | |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 493 | dinfo = open_debuginfo(tp->module, verbose == 0); |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 494 | if (dinfo) { |
| 495 | ret = debuginfo__find_probe_point(dinfo, |
| 496 | (unsigned long)addr, pp); |
| 497 | debuginfo__delete(dinfo); |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 498 | } else |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 499 | ret = -ENOENT; |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 500 | |
| 501 | if (ret > 0) { |
| 502 | pp->retprobe = tp->retprobe; |
| 503 | return 0; |
| 504 | } |
| 505 | error: |
| 506 | pr_debug("Failed to find corresponding probes from debuginfo.\n"); |
| 507 | return ret ? : -ENOENT; |
| 508 | } |
| 509 | |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 510 | static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, |
| 511 | int ntevs, const char *exec) |
| 512 | { |
| 513 | int i, ret = 0; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 514 | unsigned long stext = 0; |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 515 | |
| 516 | if (!exec) |
| 517 | return 0; |
| 518 | |
| 519 | ret = get_text_start_address(exec, &stext); |
| 520 | if (ret < 0) |
| 521 | return ret; |
| 522 | |
| 523 | for (i = 0; i < ntevs && ret >= 0; i++) { |
Masami Hiramatsu | 981a237 | 2014-02-05 05:18:58 +0000 | [diff] [blame] | 524 | /* point.address is the addres of point.symbol + point.offset */ |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 525 | tevs[i].point.address -= stext; |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 526 | tevs[i].point.module = strdup(exec); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 527 | if (!tevs[i].point.module) { |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 528 | ret = -ENOMEM; |
| 529 | break; |
| 530 | } |
| 531 | tevs[i].uprobes = true; |
| 532 | } |
| 533 | |
| 534 | return ret; |
| 535 | } |
| 536 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 537 | static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, |
| 538 | int ntevs, const char *module) |
| 539 | { |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 540 | int i, ret = 0; |
| 541 | char *tmp; |
| 542 | |
| 543 | if (!module) |
| 544 | return 0; |
| 545 | |
| 546 | tmp = strrchr(module, '/'); |
| 547 | if (tmp) { |
| 548 | /* This is a module path -- get the module name */ |
| 549 | module = strdup(tmp + 1); |
| 550 | if (!module) |
| 551 | return -ENOMEM; |
| 552 | tmp = strchr(module, '.'); |
| 553 | if (tmp) |
| 554 | *tmp = '\0'; |
| 555 | tmp = (char *)module; /* For free() */ |
| 556 | } |
| 557 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 558 | for (i = 0; i < ntevs; i++) { |
| 559 | tevs[i].point.module = strdup(module); |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 560 | if (!tevs[i].point.module) { |
| 561 | ret = -ENOMEM; |
| 562 | break; |
| 563 | } |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 564 | } |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 565 | |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 566 | free(tmp); |
Masami Hiramatsu | 14a8fd7 | 2011-06-27 16:27:51 +0900 | [diff] [blame] | 567 | return ret; |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 568 | } |
| 569 | |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 570 | /* Post processing the probe events */ |
| 571 | static int post_process_probe_trace_events(struct probe_trace_event *tevs, |
| 572 | int ntevs, const char *module, |
| 573 | bool uprobe) |
| 574 | { |
| 575 | struct ref_reloc_sym *reloc_sym; |
| 576 | char *tmp; |
Masami Hiramatsu | 5a51fcd | 2015-05-06 21:46:49 +0900 | [diff] [blame] | 577 | int i, skipped = 0; |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 578 | |
| 579 | if (uprobe) |
| 580 | return add_exec_to_probe_trace_events(tevs, ntevs, module); |
| 581 | |
| 582 | /* Note that currently ref_reloc_sym based probe is not for drivers */ |
| 583 | if (module) |
| 584 | return add_module_to_probe_trace_events(tevs, ntevs, module); |
| 585 | |
Masami Hiramatsu | 8f33f7d | 2014-02-06 05:32:20 +0000 | [diff] [blame] | 586 | reloc_sym = kernel_get_ref_reloc_sym(); |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 587 | if (!reloc_sym) { |
| 588 | pr_warning("Relocated base symbol is not found!\n"); |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | |
| 592 | for (i = 0; i < ntevs; i++) { |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 593 | if (!tevs[i].point.address || tevs[i].point.retprobe) |
| 594 | continue; |
| 595 | /* If we found a wrong one, mark it by NULL symbol */ |
| 596 | if (kprobe_warn_out_range(tevs[i].point.symbol, |
| 597 | tevs[i].point.address)) { |
| 598 | tmp = NULL; |
| 599 | skipped++; |
| 600 | } else { |
| 601 | tmp = strdup(reloc_sym->name); |
| 602 | if (!tmp) |
| 603 | return -ENOMEM; |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 604 | } |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 605 | /* If we have no realname, use symbol for it */ |
| 606 | if (!tevs[i].point.realname) |
| 607 | tevs[i].point.realname = tevs[i].point.symbol; |
| 608 | else |
| 609 | free(tevs[i].point.symbol); |
| 610 | tevs[i].point.symbol = tmp; |
| 611 | tevs[i].point.offset = tevs[i].point.address - |
| 612 | reloc_sym->unrelocated_addr; |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 613 | } |
Masami Hiramatsu | 5a51fcd | 2015-05-06 21:46:49 +0900 | [diff] [blame] | 614 | return skipped; |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 617 | /* Try to find perf_probe_event with debuginfo */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 618 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 619 | struct probe_trace_event **tevs) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 620 | { |
| 621 | bool need_dwarf = perf_probe_event_need_dwarf(pev); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 622 | struct perf_probe_point tmp; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 623 | struct debuginfo *dinfo; |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 624 | int ntevs, ret = 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 625 | |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 626 | dinfo = open_debuginfo(pev->target, !need_dwarf); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 627 | if (!dinfo) { |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 628 | if (need_dwarf) |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 629 | return -ENOENT; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 630 | pr_debug("Could not open debuginfo. Try to use symbols.\n"); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 634 | pr_debug("Try to find probe point from debuginfo.\n"); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 635 | /* Searching trace events corresponding to a probe event */ |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 636 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 637 | |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 638 | if (ntevs == 0) { /* Not found, retry with an alternative */ |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 639 | ret = get_alternative_probe_event(dinfo, pev, &tmp); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 640 | if (!ret) { |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 641 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 642 | /* |
| 643 | * Write back to the original probe_event for |
| 644 | * setting appropriate (user given) event name |
| 645 | */ |
| 646 | clear_perf_probe_point(&pev->point); |
| 647 | memcpy(&pev->point, &tmp, sizeof(tmp)); |
| 648 | } |
| 649 | } |
| 650 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 651 | debuginfo__delete(dinfo); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 652 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 653 | if (ntevs > 0) { /* Succeeded to find trace events */ |
Masami Hiramatsu | dfef99c | 2014-02-06 05:32:16 +0000 | [diff] [blame] | 654 | pr_debug("Found %d probe_trace_events.\n", ntevs); |
| 655 | ret = post_process_probe_trace_events(*tevs, ntevs, |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 656 | pev->target, pev->uprobes); |
Masami Hiramatsu | 5a51fcd | 2015-05-06 21:46:49 +0900 | [diff] [blame] | 657 | if (ret < 0 || ret == ntevs) { |
Masami Hiramatsu | 981d05a | 2014-01-16 09:39:44 +0000 | [diff] [blame] | 658 | clear_probe_trace_events(*tevs, ntevs); |
| 659 | zfree(tevs); |
| 660 | } |
Masami Hiramatsu | 5a51fcd | 2015-05-06 21:46:49 +0900 | [diff] [blame] | 661 | if (ret != ntevs) |
| 662 | return ret < 0 ? ret : ntevs; |
| 663 | ntevs = 0; |
| 664 | /* Fall through */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 665 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 666 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 667 | if (ntevs == 0) { /* No error but failed to find probe point. */ |
Masami Hiramatsu | 0687eba | 2015-03-06 16:31:25 +0900 | [diff] [blame] | 668 | pr_warning("Probe point '%s' not found.\n", |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 669 | synthesize_perf_probe_point(&pev->point)); |
Masami Hiramatsu | 0687eba | 2015-03-06 16:31:25 +0900 | [diff] [blame] | 670 | return -ENOENT; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 671 | } |
| 672 | /* Error path : ntevs < 0 */ |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 673 | pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs); |
| 674 | if (ntevs == -EBADF) { |
| 675 | pr_warning("Warning: No dwarf info found in the vmlinux - " |
| 676 | "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n"); |
| 677 | if (!need_dwarf) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 678 | pr_debug("Trying to use symbols.\n"); |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 679 | return 0; |
| 680 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 681 | } |
Masami Hiramatsu | 15eca30 | 2010-04-21 15:56:24 -0400 | [diff] [blame] | 682 | return ntevs; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | #define LINEBUF_SIZE 256 |
| 686 | #define NR_ADDITIONAL_LINES 2 |
| 687 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 688 | 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] | 689 | { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 690 | char buf[LINEBUF_SIZE], sbuf[STRERR_BUFSIZE]; |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 691 | const char *color = show_num ? "" : PERF_COLOR_BLUE; |
| 692 | const char *prefix = NULL; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 693 | |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 694 | do { |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 695 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) |
| 696 | goto error; |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 697 | if (skip) |
| 698 | continue; |
| 699 | if (!prefix) { |
| 700 | prefix = show_num ? "%7d " : " "; |
| 701 | color_fprintf(stdout, color, prefix, l); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 702 | } |
Franck Bui-Huu | befe341 | 2010-12-20 15:18:01 +0100 | [diff] [blame] | 703 | color_fprintf(stdout, color, "%s", buf); |
| 704 | |
| 705 | } while (strchr(buf, '\n') == NULL); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 706 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 707 | return 1; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 708 | error: |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 709 | if (ferror(fp)) { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 710 | pr_warning("File read error: %s\n", |
| 711 | strerror_r(errno, sbuf, sizeof(sbuf))); |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 712 | return -1; |
| 713 | } |
| 714 | return 0; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 715 | } |
| 716 | |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 717 | static int _show_one_line(FILE *fp, int l, bool skip, bool show_num) |
| 718 | { |
| 719 | int rv = __show_one_line(fp, l, skip, show_num); |
| 720 | if (rv == 0) { |
| 721 | pr_warning("Source file is shorter than expected.\n"); |
| 722 | rv = -1; |
| 723 | } |
| 724 | return rv; |
| 725 | } |
| 726 | |
| 727 | #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true) |
| 728 | #define show_one_line(f,l) _show_one_line(f,l,false,false) |
| 729 | #define skip_one_line(f,l) _show_one_line(f,l,true,false) |
| 730 | #define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false) |
| 731 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 732 | /* |
| 733 | * Show line-range always requires debuginfo to find source file and |
| 734 | * line number. |
| 735 | */ |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 736 | static int __show_line_range(struct line_range *lr, const char *module, |
| 737 | bool user) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 738 | { |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 739 | int l = 1; |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 740 | struct int_node *ln; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 741 | struct debuginfo *dinfo; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 742 | FILE *fp; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 743 | int ret; |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 744 | char *tmp; |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 745 | char sbuf[STRERR_BUFSIZE]; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 746 | |
| 747 | /* Search a line range */ |
Masami Hiramatsu | 92561cb | 2014-08-15 01:44:32 +0000 | [diff] [blame] | 748 | dinfo = open_debuginfo(module, false); |
| 749 | if (!dinfo) |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 750 | return -ENOENT; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 751 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 752 | ret = debuginfo__find_line_range(dinfo, lr); |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 753 | if (!ret) { /* Not found, retry with an alternative */ |
| 754 | ret = get_alternative_line_range(dinfo, lr, module, user); |
| 755 | if (!ret) |
| 756 | ret = debuginfo__find_line_range(dinfo, lr); |
| 757 | } |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 758 | debuginfo__delete(dinfo); |
Masami Hiramatsu | 5ee05b8 | 2014-06-06 07:14:06 +0000 | [diff] [blame] | 759 | if (ret == 0 || ret == -ENOENT) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 760 | pr_warning("Specified source line is not found.\n"); |
| 761 | return -ENOENT; |
| 762 | } else if (ret < 0) { |
Masami Hiramatsu | 5ee05b8 | 2014-06-06 07:14:06 +0000 | [diff] [blame] | 763 | pr_warning("Debuginfo analysis failed.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 764 | return ret; |
| 765 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 766 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 767 | /* Convert source file path */ |
| 768 | tmp = lr->path; |
Masami Hiramatsu | 6a330a3 | 2010-07-09 18:29:11 +0900 | [diff] [blame] | 769 | ret = get_real_path(tmp, lr->comp_dir, &lr->path); |
He Kuang | a78604d | 2015-03-04 18:01:42 +0800 | [diff] [blame] | 770 | |
| 771 | /* Free old path when new path is assigned */ |
| 772 | if (tmp != lr->path) |
| 773 | free(tmp); |
| 774 | |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 775 | if (ret < 0) { |
Masami Hiramatsu | 5ee05b8 | 2014-06-06 07:14:06 +0000 | [diff] [blame] | 776 | pr_warning("Failed to find source file path.\n"); |
Masami Hiramatsu | 7cf0b79 | 2010-07-09 18:28:59 +0900 | [diff] [blame] | 777 | return ret; |
| 778 | } |
| 779 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 780 | setup_pager(); |
| 781 | |
| 782 | if (lr->function) |
Masami Hiramatsu | 8737ebd | 2011-02-10 18:08:16 +0900 | [diff] [blame] | 783 | fprintf(stdout, "<%s@%s:%d>\n", lr->function, lr->path, |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 784 | lr->start - lr->offset); |
| 785 | else |
Franck Bui-Huu | 62c15fc | 2010-12-20 15:18:00 +0100 | [diff] [blame] | 786 | fprintf(stdout, "<%s:%d>\n", lr->path, lr->start); |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 787 | |
| 788 | fp = fopen(lr->path, "r"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 789 | if (fp == NULL) { |
| 790 | pr_warning("Failed to open %s: %s\n", lr->path, |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 791 | strerror_r(errno, sbuf, sizeof(sbuf))); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 792 | return -errno; |
| 793 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 794 | /* Skip to starting line number */ |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 795 | while (l < lr->start) { |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 796 | ret = skip_one_line(fp, l++); |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 797 | if (ret < 0) |
| 798 | goto end; |
| 799 | } |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 800 | |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 801 | intlist__for_each(ln, lr->line_list) { |
| 802 | for (; ln->i > l; l++) { |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 803 | ret = show_one_line(fp, l - lr->offset); |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 804 | if (ret < 0) |
| 805 | goto end; |
| 806 | } |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 807 | ret = show_one_line_with_num(fp, l++ - lr->offset); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 808 | if (ret < 0) |
| 809 | goto end; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | if (lr->end == INT_MAX) |
| 813 | lr->end = l + NR_ADDITIONAL_LINES; |
Franck Bui-Huu | fde52db | 2010-12-20 15:18:04 +0100 | [diff] [blame] | 814 | while (l <= lr->end) { |
| 815 | ret = show_one_line_or_eof(fp, l++ - lr->offset); |
| 816 | if (ret <= 0) |
Franck Bui-Huu | 44b81e9 | 2010-12-20 15:18:02 +0100 | [diff] [blame] | 817 | break; |
| 818 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 819 | end: |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 820 | fclose(fp); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 821 | return ret; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 822 | } |
| 823 | |
Masami Hiramatsu | 2b394bc | 2014-09-17 08:40:54 +0000 | [diff] [blame] | 824 | int show_line_range(struct line_range *lr, const char *module, bool user) |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 825 | { |
| 826 | int ret; |
| 827 | |
Masami Hiramatsu | 2b394bc | 2014-09-17 08:40:54 +0000 | [diff] [blame] | 828 | ret = init_symbol_maps(user); |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 829 | if (ret < 0) |
| 830 | return ret; |
Masami Hiramatsu | 811dd2a | 2015-03-06 16:31:22 +0900 | [diff] [blame] | 831 | ret = __show_line_range(lr, module, user); |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 832 | exit_symbol_maps(); |
| 833 | |
| 834 | return ret; |
| 835 | } |
| 836 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 837 | static int show_available_vars_at(struct debuginfo *dinfo, |
| 838 | struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 839 | struct strfilter *_filter) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 840 | { |
| 841 | char *buf; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 842 | int ret, i, nvars; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 843 | struct str_node *node; |
| 844 | struct variable_list *vls = NULL, *vl; |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 845 | struct perf_probe_point tmp; |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 846 | const char *var; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 847 | |
| 848 | buf = synthesize_perf_probe_point(&pev->point); |
| 849 | if (!buf) |
| 850 | return -EINVAL; |
| 851 | pr_debug("Searching variables at %s\n", buf); |
| 852 | |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 853 | ret = debuginfo__find_available_vars_at(dinfo, pev, &vls); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 854 | if (!ret) { /* Not found, retry with an alternative */ |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 855 | ret = get_alternative_probe_event(dinfo, pev, &tmp); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 856 | if (!ret) { |
| 857 | ret = debuginfo__find_available_vars_at(dinfo, pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 858 | &vls); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 859 | /* Release the old probe_point */ |
| 860 | clear_perf_probe_point(&tmp); |
| 861 | } |
| 862 | } |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 863 | if (ret <= 0) { |
Masami Hiramatsu | 69e96ea | 2014-06-06 07:13:59 +0000 | [diff] [blame] | 864 | if (ret == 0 || ret == -ENOENT) { |
| 865 | pr_err("Failed to find the address of %s\n", buf); |
| 866 | ret = -ENOENT; |
| 867 | } else |
| 868 | pr_warning("Debuginfo analysis failed.\n"); |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 869 | goto end; |
| 870 | } |
Masami Hiramatsu | 69e96ea | 2014-06-06 07:13:59 +0000 | [diff] [blame] | 871 | |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 872 | /* Some variables are found */ |
| 873 | fprintf(stdout, "Available variables at %s\n", buf); |
| 874 | for (i = 0; i < ret; i++) { |
| 875 | vl = &vls[i]; |
| 876 | /* |
| 877 | * A probe point might be converted to |
| 878 | * several trace points. |
| 879 | */ |
| 880 | fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol, |
| 881 | vl->point.offset); |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 882 | zfree(&vl->point.symbol); |
Masami Hiramatsu | bd09d7b | 2011-01-20 23:15:39 +0900 | [diff] [blame] | 883 | nvars = 0; |
| 884 | if (vl->vars) { |
| 885 | strlist__for_each(node, vl->vars) { |
| 886 | var = strchr(node->s, '\t') + 1; |
| 887 | if (strfilter__compare(_filter, var)) { |
| 888 | fprintf(stdout, "\t\t%s\n", node->s); |
| 889 | nvars++; |
| 890 | } |
| 891 | } |
| 892 | strlist__delete(vl->vars); |
| 893 | } |
| 894 | if (nvars == 0) |
| 895 | fprintf(stdout, "\t\t(No matched variables)\n"); |
| 896 | } |
| 897 | free(vls); |
| 898 | end: |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 899 | free(buf); |
| 900 | return ret; |
| 901 | } |
| 902 | |
| 903 | /* Show available variables on given probe point */ |
| 904 | int show_available_vars(struct perf_probe_event *pevs, int npevs, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 905 | struct strfilter *_filter) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 906 | { |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 907 | int i, ret = 0; |
| 908 | struct debuginfo *dinfo; |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 909 | |
Masami Hiramatsu | 2b394bc | 2014-09-17 08:40:54 +0000 | [diff] [blame] | 910 | ret = init_symbol_maps(pevs->uprobes); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 911 | if (ret < 0) |
| 912 | return ret; |
| 913 | |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 914 | dinfo = open_debuginfo(pevs->target, false); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 915 | if (!dinfo) { |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 916 | ret = -ENOENT; |
| 917 | goto out; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 918 | } |
| 919 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 920 | setup_pager(); |
| 921 | |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 922 | for (i = 0; i < npevs && ret >= 0; i++) |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 923 | ret = show_available_vars_at(dinfo, &pevs[i], _filter); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 924 | |
| 925 | debuginfo__delete(dinfo); |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 926 | out: |
| 927 | exit_symbol_maps(); |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 928 | return ret; |
| 929 | } |
| 930 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 931 | #else /* !HAVE_DWARF_SUPPORT */ |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 932 | |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 933 | static int |
| 934 | find_perf_probe_point_from_dwarf(struct probe_trace_point *tp __maybe_unused, |
| 935 | struct perf_probe_point *pp __maybe_unused, |
| 936 | bool is_kprobe __maybe_unused) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 937 | { |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 938 | return -ENOSYS; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 939 | } |
| 940 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 941 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 942 | struct probe_trace_event **tevs __maybe_unused) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 943 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 944 | if (perf_probe_event_need_dwarf(pev)) { |
| 945 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 946 | return -ENOSYS; |
| 947 | } |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 948 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 949 | return 0; |
| 950 | } |
| 951 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 952 | int show_line_range(struct line_range *lr __maybe_unused, |
Masami Hiramatsu | 2b394bc | 2014-09-17 08:40:54 +0000 | [diff] [blame] | 953 | const char *module __maybe_unused, |
| 954 | bool user __maybe_unused) |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 955 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 956 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 957 | return -ENOSYS; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 958 | } |
| 959 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 960 | int show_available_vars(struct perf_probe_event *pevs __maybe_unused, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 961 | int npevs __maybe_unused, |
| 962 | struct strfilter *filter __maybe_unused) |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 963 | { |
| 964 | pr_warning("Debuginfo-analysis is not supported.\n"); |
| 965 | return -ENOSYS; |
| 966 | } |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 967 | #endif |
| 968 | |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 969 | void line_range__clear(struct line_range *lr) |
| 970 | { |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 971 | free(lr->function); |
| 972 | free(lr->file); |
| 973 | free(lr->path); |
| 974 | free(lr->comp_dir); |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 975 | intlist__delete(lr->line_list); |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 976 | memset(lr, 0, sizeof(*lr)); |
| 977 | } |
| 978 | |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 979 | int line_range__init(struct line_range *lr) |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 980 | { |
| 981 | memset(lr, 0, sizeof(*lr)); |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 982 | lr->line_list = intlist__new(NULL); |
| 983 | if (!lr->line_list) |
| 984 | return -ENOMEM; |
| 985 | else |
| 986 | return 0; |
Masami Hiramatsu | e53b00d | 2014-01-16 09:39:47 +0000 | [diff] [blame] | 987 | } |
| 988 | |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 989 | static int parse_line_num(char **ptr, int *val, const char *what) |
| 990 | { |
| 991 | const char *start = *ptr; |
| 992 | |
| 993 | errno = 0; |
| 994 | *val = strtol(*ptr, ptr, 0); |
| 995 | if (errno || *ptr == start) { |
| 996 | semantic_error("'%s' is not a valid number.\n", what); |
| 997 | return -EINVAL; |
| 998 | } |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Masami Hiramatsu | 573709f | 2015-05-06 21:46:47 +0900 | [diff] [blame] | 1002 | /* Check the name is good for event, group or function */ |
| 1003 | static bool is_c_func_name(const char *name) |
| 1004 | { |
| 1005 | if (!isalpha(*name) && *name != '_') |
| 1006 | return false; |
| 1007 | while (*++name != '\0') { |
| 1008 | if (!isalpha(*name) && !isdigit(*name) && *name != '_') |
| 1009 | return false; |
| 1010 | } |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 1014 | /* |
| 1015 | * Stuff 'lr' according to the line range described by 'arg'. |
| 1016 | * The line range syntax is described by: |
| 1017 | * |
| 1018 | * SRC[:SLN[+NUM|-ELN]] |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 1019 | * FNC[@SRC][:SLN[+NUM|-ELN]] |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 1020 | */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1021 | int parse_line_range_desc(const char *arg, struct line_range *lr) |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1022 | { |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 1023 | char *range, *file, *name = strdup(arg); |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1024 | int err; |
Franck Bui-Huu | 9d95b58 | 2010-12-20 15:18:03 +0100 | [diff] [blame] | 1025 | |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1026 | if (!name) |
| 1027 | return -ENOMEM; |
| 1028 | |
| 1029 | lr->start = 0; |
| 1030 | lr->end = INT_MAX; |
| 1031 | |
| 1032 | range = strchr(name, ':'); |
| 1033 | if (range) { |
| 1034 | *range++ = '\0'; |
| 1035 | |
| 1036 | err = parse_line_num(&range, &lr->start, "start line"); |
| 1037 | if (err) |
| 1038 | goto err; |
| 1039 | |
| 1040 | if (*range == '+' || *range == '-') { |
| 1041 | const char c = *range++; |
| 1042 | |
| 1043 | err = parse_line_num(&range, &lr->end, "end line"); |
| 1044 | if (err) |
| 1045 | goto err; |
| 1046 | |
| 1047 | if (c == '+') { |
| 1048 | lr->end += lr->start; |
| 1049 | /* |
| 1050 | * Adjust the number of lines here. |
| 1051 | * If the number of lines == 1, the |
| 1052 | * the end of line should be equal to |
| 1053 | * the start of line. |
| 1054 | */ |
| 1055 | lr->end--; |
| 1056 | } |
| 1057 | } |
| 1058 | |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1059 | 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] | 1060 | |
| 1061 | err = -EINVAL; |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1062 | if (lr->start > lr->end) { |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1063 | semantic_error("Start line must be smaller" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1064 | " than end line.\n"); |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1065 | goto err; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1066 | } |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1067 | if (*range != '\0') { |
| 1068 | semantic_error("Tailing with invalid str '%s'.\n", range); |
| 1069 | goto err; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1070 | } |
Masami Hiramatsu | d3b63d7 | 2010-04-14 18:39:42 -0400 | [diff] [blame] | 1071 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1072 | |
Masami Hiramatsu | e116dfa | 2011-02-10 18:08:10 +0900 | [diff] [blame] | 1073 | file = strchr(name, '@'); |
| 1074 | if (file) { |
| 1075 | *file = '\0'; |
| 1076 | lr->file = strdup(++file); |
| 1077 | if (lr->file == NULL) { |
| 1078 | err = -ENOMEM; |
| 1079 | goto err; |
| 1080 | } |
| 1081 | lr->function = name; |
Masami Hiramatsu | 573709f | 2015-05-06 21:46:47 +0900 | [diff] [blame] | 1082 | } else if (strchr(name, '/') || strchr(name, '.')) |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1083 | lr->file = name; |
Masami Hiramatsu | 573709f | 2015-05-06 21:46:47 +0900 | [diff] [blame] | 1084 | else if (is_c_func_name(name))/* We reuse it for checking funcname */ |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1085 | lr->function = name; |
Masami Hiramatsu | 573709f | 2015-05-06 21:46:47 +0900 | [diff] [blame] | 1086 | else { /* Invalid name */ |
| 1087 | semantic_error("'%s' is not a valid function name.\n", name); |
| 1088 | err = -EINVAL; |
| 1089 | goto err; |
| 1090 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1091 | |
| 1092 | return 0; |
Franck Bui-Huu | 21dd9ae | 2010-12-20 15:18:05 +0100 | [diff] [blame] | 1093 | err: |
| 1094 | free(name); |
| 1095 | return err; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 1096 | } |
| 1097 | |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1098 | /* Parse probepoint definition. */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1099 | 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] | 1100 | { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1101 | struct perf_probe_point *pp = &pev->point; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1102 | char *ptr, *tmp; |
| 1103 | char c, nc = 0; |
Naveen N. Rao | 3099c02 | 2015-04-28 17:35:34 +0530 | [diff] [blame] | 1104 | bool file_spec = false; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1105 | /* |
| 1106 | * <Syntax> |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1107 | * perf probe [EVENT=]SRC[:LN|;PTN] |
| 1108 | * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT] |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 1109 | * |
| 1110 | * TODO:Group name support |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1111 | */ |
Wang Nan | e59d29e | 2015-04-28 08:46:09 +0000 | [diff] [blame] | 1112 | if (!arg) |
| 1113 | return -EINVAL; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1114 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1115 | ptr = strpbrk(arg, ";=@+%"); |
| 1116 | if (ptr && *ptr == '=') { /* Event name */ |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 1117 | *ptr = '\0'; |
| 1118 | tmp = ptr + 1; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1119 | if (strchr(arg, ':')) { |
| 1120 | semantic_error("Group name is not supported yet.\n"); |
| 1121 | return -ENOTSUP; |
| 1122 | } |
Masami Hiramatsu | 573709f | 2015-05-06 21:46:47 +0900 | [diff] [blame] | 1123 | if (!is_c_func_name(arg)) { |
Masami Hiramatsu | b7702a2 | 2009-12-16 17:24:15 -0500 | [diff] [blame] | 1124 | semantic_error("%s is bad for event name -it must " |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1125 | "follow C symbol-naming rule.\n", arg); |
| 1126 | return -EINVAL; |
| 1127 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1128 | pev->event = strdup(arg); |
| 1129 | if (pev->event == NULL) |
| 1130 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1131 | pev->group = NULL; |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 1132 | arg = tmp; |
| 1133 | } |
| 1134 | |
Naveen N. Rao | 3099c02 | 2015-04-28 17:35:34 +0530 | [diff] [blame] | 1135 | /* |
| 1136 | * Check arg is function or file name and copy it. |
| 1137 | * |
| 1138 | * We consider arg to be a file spec if and only if it satisfies |
| 1139 | * all of the below criteria:: |
| 1140 | * - it does not include any of "+@%", |
| 1141 | * - it includes one of ":;", and |
| 1142 | * - it has a period '.' in the name. |
| 1143 | * |
| 1144 | * Otherwise, we consider arg to be a function specification. |
| 1145 | */ |
| 1146 | if (!strpbrk(arg, "+@%") && (ptr = strpbrk(arg, ";:")) != NULL) { |
| 1147 | /* This is a file spec if it includes a '.' before ; or : */ |
| 1148 | if (memchr(arg, '.', ptr - arg)) |
| 1149 | file_spec = true; |
| 1150 | } |
| 1151 | |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1152 | ptr = strpbrk(arg, ";:+@%"); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1153 | if (ptr) { |
| 1154 | nc = *ptr; |
| 1155 | *ptr++ = '\0'; |
| 1156 | } |
| 1157 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1158 | tmp = strdup(arg); |
| 1159 | if (tmp == NULL) |
| 1160 | return -ENOMEM; |
| 1161 | |
Naveen N. Rao | 3099c02 | 2015-04-28 17:35:34 +0530 | [diff] [blame] | 1162 | if (file_spec) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1163 | pp->file = tmp; |
Naveen N. Rao | 3099c02 | 2015-04-28 17:35:34 +0530 | [diff] [blame] | 1164 | else |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1165 | pp->function = tmp; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1166 | |
| 1167 | /* Parse other options */ |
| 1168 | while (ptr) { |
| 1169 | arg = ptr; |
| 1170 | c = nc; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1171 | if (c == ';') { /* Lazy pattern must be the last part */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1172 | pp->lazy_line = strdup(arg); |
| 1173 | if (pp->lazy_line == NULL) |
| 1174 | return -ENOMEM; |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1175 | break; |
| 1176 | } |
| 1177 | ptr = strpbrk(arg, ";:+@%"); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1178 | if (ptr) { |
| 1179 | nc = *ptr; |
| 1180 | *ptr++ = '\0'; |
| 1181 | } |
| 1182 | switch (c) { |
| 1183 | case ':': /* Line number */ |
| 1184 | pp->line = strtoul(arg, &tmp, 0); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1185 | if (*tmp != '\0') { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1186 | semantic_error("There is non-digit char" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1187 | " in line number.\n"); |
| 1188 | return -EINVAL; |
| 1189 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1190 | break; |
| 1191 | case '+': /* Byte offset from a symbol */ |
| 1192 | pp->offset = strtoul(arg, &tmp, 0); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1193 | if (*tmp != '\0') { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1194 | semantic_error("There is non-digit character" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1195 | " in offset.\n"); |
| 1196 | return -EINVAL; |
| 1197 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1198 | break; |
| 1199 | case '@': /* File name */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1200 | if (pp->file) { |
| 1201 | semantic_error("SRC@SRC is not allowed.\n"); |
| 1202 | return -EINVAL; |
| 1203 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1204 | pp->file = strdup(arg); |
| 1205 | if (pp->file == NULL) |
| 1206 | return -ENOMEM; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1207 | break; |
| 1208 | case '%': /* Probe places */ |
| 1209 | if (strcmp(arg, "return") == 0) { |
| 1210 | pp->retprobe = 1; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1211 | } else { /* Others not supported yet */ |
| 1212 | semantic_error("%%%s is not supported.\n", arg); |
| 1213 | return -ENOTSUP; |
| 1214 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1215 | break; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1216 | default: /* Buggy case */ |
| 1217 | pr_err("This program has a bug at %s:%d.\n", |
| 1218 | __FILE__, __LINE__); |
| 1219 | return -ENOTSUP; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1220 | break; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | /* Exclusion check */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1225 | if (pp->lazy_line && pp->line) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1226 | semantic_error("Lazy pattern can't be used with" |
| 1227 | " line number.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1228 | return -EINVAL; |
| 1229 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1230 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1231 | if (pp->lazy_line && pp->offset) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1232 | semantic_error("Lazy pattern can't be used with offset.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1233 | return -EINVAL; |
| 1234 | } |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1235 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1236 | if (pp->line && pp->offset) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1237 | semantic_error("Offset can't be used with line number.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1238 | return -EINVAL; |
| 1239 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1240 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1241 | if (!pp->line && !pp->lazy_line && pp->file && !pp->function) { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1242 | semantic_error("File always requires line number or " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1243 | "lazy pattern.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1244 | return -EINVAL; |
| 1245 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1246 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1247 | if (pp->offset && !pp->function) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1248 | semantic_error("Offset requires an entry function.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1249 | return -EINVAL; |
| 1250 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1251 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1252 | if (pp->retprobe && !pp->function) { |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1253 | semantic_error("Return probe requires an entry function.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1254 | return -EINVAL; |
| 1255 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1256 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1257 | if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) { |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 1258 | semantic_error("Offset/Line/Lazy pattern can't be used with " |
Masami Hiramatsu | 0e43e5d | 2010-12-17 22:12:11 +0900 | [diff] [blame] | 1259 | "return probe.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1260 | return -EINVAL; |
| 1261 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1262 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1263 | 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] | 1264 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, |
| 1265 | pp->lazy_line); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1266 | return 0; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1269 | /* Parse perf-probe event argument */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1270 | 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] | 1271 | { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1272 | char *tmp, *goodname; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1273 | struct perf_probe_arg_field **fieldp; |
| 1274 | |
| 1275 | pr_debug("parsing arg: %s into ", str); |
| 1276 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1277 | tmp = strchr(str, '='); |
| 1278 | if (tmp) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1279 | arg->name = strndup(str, tmp - str); |
| 1280 | if (arg->name == NULL) |
| 1281 | return -ENOMEM; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1282 | pr_debug("name:%s ", arg->name); |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1283 | str = tmp + 1; |
| 1284 | } |
| 1285 | |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1286 | tmp = strchr(str, ':'); |
| 1287 | if (tmp) { /* Type setting */ |
| 1288 | *tmp = '\0'; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1289 | arg->type = strdup(tmp + 1); |
| 1290 | if (arg->type == NULL) |
| 1291 | return -ENOMEM; |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1292 | pr_debug("type:%s ", arg->type); |
| 1293 | } |
| 1294 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1295 | tmp = strpbrk(str, "-.["); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1296 | if (!is_c_varname(str) || !tmp) { |
| 1297 | /* A variable, register, symbol or special value */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1298 | arg->var = strdup(str); |
| 1299 | if (arg->var == NULL) |
| 1300 | return -ENOMEM; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1301 | pr_debug("%s\n", arg->var); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1302 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1303 | } |
| 1304 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1305 | /* Structure fields or array element */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1306 | arg->var = strndup(str, tmp - str); |
| 1307 | if (arg->var == NULL) |
| 1308 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1309 | goodname = arg->var; |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1310 | pr_debug("%s, ", arg->var); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1311 | fieldp = &arg->field; |
| 1312 | |
| 1313 | do { |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1314 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); |
| 1315 | if (*fieldp == NULL) |
| 1316 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1317 | if (*tmp == '[') { /* Array */ |
| 1318 | str = tmp; |
| 1319 | (*fieldp)->index = strtol(str + 1, &tmp, 0); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1320 | (*fieldp)->ref = true; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1321 | if (*tmp != ']' || tmp == str + 1) { |
| 1322 | semantic_error("Array index must be a" |
| 1323 | " number.\n"); |
| 1324 | return -EINVAL; |
| 1325 | } |
| 1326 | tmp++; |
| 1327 | if (*tmp == '\0') |
| 1328 | tmp = NULL; |
| 1329 | } else { /* Structure */ |
| 1330 | if (*tmp == '.') { |
| 1331 | str = tmp + 1; |
| 1332 | (*fieldp)->ref = false; |
| 1333 | } else if (tmp[1] == '>') { |
| 1334 | str = tmp + 2; |
| 1335 | (*fieldp)->ref = true; |
| 1336 | } else { |
| 1337 | semantic_error("Argument parse error: %s\n", |
| 1338 | str); |
| 1339 | return -EINVAL; |
| 1340 | } |
| 1341 | tmp = strpbrk(str, "-.["); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1342 | } |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1343 | if (tmp) { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1344 | (*fieldp)->name = strndup(str, tmp - str); |
| 1345 | if ((*fieldp)->name == NULL) |
| 1346 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1347 | if (*str != '[') |
| 1348 | goodname = (*fieldp)->name; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1349 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); |
| 1350 | fieldp = &(*fieldp)->next; |
| 1351 | } |
| 1352 | } while (tmp); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1353 | (*fieldp)->name = strdup(str); |
| 1354 | if ((*fieldp)->name == NULL) |
| 1355 | return -ENOMEM; |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1356 | if (*str != '[') |
| 1357 | goodname = (*fieldp)->name; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1358 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); |
Masami Hiramatsu | df0faf4 | 2010-04-12 13:17:00 -0400 | [diff] [blame] | 1359 | |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1360 | /* 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] | 1361 | if (!arg->name) { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1362 | arg->name = strdup(goodname); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1363 | if (arg->name == NULL) |
| 1364 | return -ENOMEM; |
| 1365 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1366 | return 0; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1369 | /* Parse perf-probe event command */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1370 | 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] | 1371 | { |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1372 | char **argv; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1373 | int argc, i, ret = 0; |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 1374 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1375 | argv = argv_split(cmd, &argc); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1376 | if (!argv) { |
| 1377 | pr_debug("Failed to split arguments.\n"); |
| 1378 | return -ENOMEM; |
| 1379 | } |
| 1380 | if (argc - 1 > MAX_PROBE_ARGS) { |
| 1381 | semantic_error("Too many probe arguments (%d).\n", argc - 1); |
| 1382 | ret = -ERANGE; |
| 1383 | goto out; |
| 1384 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1385 | /* Parse probe point */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1386 | ret = parse_perf_probe_point(argv[0], pev); |
| 1387 | if (ret < 0) |
| 1388 | goto out; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1389 | |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1390 | /* Copy arguments and ensure return probe has no C argument */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1391 | pev->nargs = argc - 1; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1392 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
| 1393 | if (pev->args == NULL) { |
| 1394 | ret = -ENOMEM; |
| 1395 | goto out; |
| 1396 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1397 | for (i = 0; i < pev->nargs && ret >= 0; i++) { |
| 1398 | ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]); |
| 1399 | if (ret >= 0 && |
| 1400 | is_c_varname(pev->args[i].var) && pev->point.retprobe) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1401 | semantic_error("You can't specify local variable for" |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1402 | " kretprobe.\n"); |
| 1403 | ret = -EINVAL; |
| 1404 | } |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1405 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1406 | out: |
Masami Hiramatsu | e1c01d6 | 2009-11-30 19:20:05 -0500 | [diff] [blame] | 1407 | argv_free(argv); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1408 | |
| 1409 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1412 | /* Return true if this perf_probe_event requires debuginfo */ |
| 1413 | bool perf_probe_event_need_dwarf(struct perf_probe_event *pev) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1414 | { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1415 | int i; |
| 1416 | |
| 1417 | if (pev->point.file || pev->point.line || pev->point.lazy_line) |
| 1418 | return true; |
| 1419 | |
| 1420 | for (i = 0; i < pev->nargs; i++) |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1421 | if (is_c_varname(pev->args[i].var)) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1422 | return true; |
| 1423 | |
| 1424 | return false; |
| 1425 | } |
| 1426 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1427 | /* Parse probe_events event into struct probe_point */ |
| 1428 | static int parse_probe_trace_command(const char *cmd, |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1429 | struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1430 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1431 | struct probe_trace_point *tp = &tev->point; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1432 | char pr; |
| 1433 | char *p; |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1434 | char *argv0_str = NULL, *fmt, *fmt1_str, *fmt2_str, *fmt3_str; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1435 | int ret, i, argc; |
| 1436 | char **argv; |
| 1437 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1438 | pr_debug("Parsing probe_events: %s\n", cmd); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1439 | argv = argv_split(cmd, &argc); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1440 | if (!argv) { |
| 1441 | pr_debug("Failed to split arguments.\n"); |
| 1442 | return -ENOMEM; |
| 1443 | } |
| 1444 | if (argc < 2) { |
| 1445 | semantic_error("Too few probe arguments.\n"); |
| 1446 | ret = -ERANGE; |
| 1447 | goto out; |
| 1448 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1449 | |
| 1450 | /* Scan event and group name. */ |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1451 | argv0_str = strdup(argv[0]); |
| 1452 | if (argv0_str == NULL) { |
| 1453 | ret = -ENOMEM; |
| 1454 | goto out; |
| 1455 | } |
| 1456 | fmt1_str = strtok_r(argv0_str, ":", &fmt); |
| 1457 | fmt2_str = strtok_r(NULL, "/", &fmt); |
| 1458 | fmt3_str = strtok_r(NULL, " \t", &fmt); |
| 1459 | if (fmt1_str == NULL || strlen(fmt1_str) != 1 || fmt2_str == NULL |
| 1460 | || fmt3_str == NULL) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1461 | semantic_error("Failed to parse event name: %s\n", argv[0]); |
| 1462 | ret = -EINVAL; |
| 1463 | goto out; |
| 1464 | } |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1465 | pr = fmt1_str[0]; |
| 1466 | tev->group = strdup(fmt2_str); |
| 1467 | tev->event = strdup(fmt3_str); |
| 1468 | if (tev->group == NULL || tev->event == NULL) { |
| 1469 | ret = -ENOMEM; |
| 1470 | goto out; |
| 1471 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1472 | 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] | 1473 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1474 | tp->retprobe = (pr == 'r'); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1475 | |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 1476 | /* Scan module name(if there), function name and offset */ |
| 1477 | p = strchr(argv[1], ':'); |
| 1478 | if (p) { |
| 1479 | tp->module = strndup(argv[1], p - argv[1]); |
| 1480 | p++; |
| 1481 | } else |
| 1482 | p = argv[1]; |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1483 | fmt1_str = strtok_r(p, "+", &fmt); |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 1484 | if (fmt1_str[0] == '0') /* only the address started with 0x */ |
| 1485 | tp->address = strtoul(fmt1_str, NULL, 0); |
| 1486 | else { |
| 1487 | /* Only the symbol-based probe has offset */ |
| 1488 | tp->symbol = strdup(fmt1_str); |
| 1489 | if (tp->symbol == NULL) { |
| 1490 | ret = -ENOMEM; |
| 1491 | goto out; |
| 1492 | } |
| 1493 | fmt2_str = strtok_r(NULL, "", &fmt); |
| 1494 | if (fmt2_str == NULL) |
| 1495 | tp->offset = 0; |
| 1496 | else |
| 1497 | tp->offset = strtoul(fmt2_str, NULL, 10); |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1498 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1499 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1500 | tev->nargs = argc - 2; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1501 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1502 | if (tev->args == NULL) { |
| 1503 | ret = -ENOMEM; |
| 1504 | goto out; |
| 1505 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1506 | for (i = 0; i < tev->nargs; i++) { |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1507 | p = strchr(argv[i + 2], '='); |
| 1508 | if (p) /* We don't need which register is assigned. */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1509 | *p++ = '\0'; |
| 1510 | else |
| 1511 | p = argv[i + 2]; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1512 | tev->args[i].name = strdup(argv[i + 2]); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1513 | /* TODO: parse regs and offset */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1514 | tev->args[i].value = strdup(p); |
| 1515 | if (tev->args[i].name == NULL || tev->args[i].value == NULL) { |
| 1516 | ret = -ENOMEM; |
| 1517 | goto out; |
| 1518 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1519 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1520 | ret = 0; |
| 1521 | out: |
Irina Tirdea | bcbd004 | 2012-09-20 23:37:50 +0300 | [diff] [blame] | 1522 | free(argv0_str); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1523 | argv_free(argv); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1524 | return ret; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1525 | } |
| 1526 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1527 | /* Compose only probe arg */ |
| 1528 | int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) |
| 1529 | { |
| 1530 | struct perf_probe_arg_field *field = pa->field; |
| 1531 | int ret; |
| 1532 | char *tmp = buf; |
| 1533 | |
Masami Hiramatsu | 4848193 | 2010-04-12 13:16:53 -0400 | [diff] [blame] | 1534 | if (pa->name && pa->var) |
| 1535 | ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var); |
| 1536 | else |
| 1537 | ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1538 | if (ret <= 0) |
| 1539 | goto error; |
| 1540 | tmp += ret; |
| 1541 | len -= ret; |
| 1542 | |
| 1543 | while (field) { |
Masami Hiramatsu | b2a3c12 | 2010-05-19 15:57:42 -0400 | [diff] [blame] | 1544 | if (field->name[0] == '[') |
| 1545 | ret = e_snprintf(tmp, len, "%s", field->name); |
| 1546 | else |
| 1547 | ret = e_snprintf(tmp, len, "%s%s", |
| 1548 | field->ref ? "->" : ".", field->name); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1549 | if (ret <= 0) |
| 1550 | goto error; |
| 1551 | tmp += ret; |
| 1552 | len -= ret; |
| 1553 | field = field->next; |
| 1554 | } |
Masami Hiramatsu | 11a1ca3 | 2010-04-12 13:17:22 -0400 | [diff] [blame] | 1555 | |
| 1556 | if (pa->type) { |
| 1557 | ret = e_snprintf(tmp, len, ":%s", pa->type); |
| 1558 | if (ret <= 0) |
| 1559 | goto error; |
| 1560 | tmp += ret; |
| 1561 | len -= ret; |
| 1562 | } |
| 1563 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1564 | return tmp - buf; |
| 1565 | error: |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 1566 | pr_debug("Failed to synthesize perf probe argument: %d\n", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1567 | return ret; |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1568 | } |
| 1569 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1570 | /* Compose only probe point (not argument) */ |
| 1571 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1572 | { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1573 | char *buf, *tmp; |
| 1574 | char offs[32] = "", line[32] = "", file[32] = ""; |
| 1575 | int ret, len; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 1576 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1577 | buf = zalloc(MAX_CMDLEN); |
| 1578 | if (buf == NULL) { |
| 1579 | ret = -ENOMEM; |
| 1580 | goto error; |
| 1581 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1582 | if (pp->offset) { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1583 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1584 | if (ret <= 0) |
| 1585 | goto error; |
| 1586 | } |
| 1587 | if (pp->line) { |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1588 | ret = e_snprintf(line, 32, ":%d", pp->line); |
| 1589 | if (ret <= 0) |
| 1590 | goto error; |
| 1591 | } |
| 1592 | if (pp->file) { |
Franck Bui-Huu | 32ae2ad | 2010-12-23 16:04:23 +0100 | [diff] [blame] | 1593 | tmp = pp->file; |
| 1594 | len = strlen(tmp); |
| 1595 | if (len > 30) { |
| 1596 | tmp = strchr(pp->file + len - 30, '/'); |
| 1597 | tmp = tmp ? tmp + 1 : pp->file + len - 30; |
| 1598 | } |
| 1599 | ret = e_snprintf(file, 32, "@%s", tmp); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1600 | if (ret <= 0) |
| 1601 | goto error; |
| 1602 | } |
| 1603 | |
| 1604 | if (pp->function) |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1605 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function, |
| 1606 | offs, pp->retprobe ? "%return" : "", line, |
| 1607 | file); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1608 | else |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1609 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1610 | if (ret <= 0) |
| 1611 | goto error; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1612 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1613 | return buf; |
| 1614 | error: |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 1615 | pr_debug("Failed to synthesize perf probe point: %d\n", ret); |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1616 | free(buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1617 | return NULL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | #if 0 |
| 1621 | char *synthesize_perf_probe_command(struct perf_probe_event *pev) |
| 1622 | { |
| 1623 | char *buf; |
| 1624 | int i, len, ret; |
| 1625 | |
| 1626 | buf = synthesize_perf_probe_point(&pev->point); |
| 1627 | if (!buf) |
| 1628 | return NULL; |
| 1629 | |
| 1630 | len = strlen(buf); |
| 1631 | for (i = 0; i < pev->nargs; i++) { |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1632 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1633 | pev->args[i].name); |
| 1634 | if (ret <= 0) { |
| 1635 | free(buf); |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | len += ret; |
| 1639 | } |
| 1640 | |
| 1641 | return buf; |
| 1642 | } |
| 1643 | #endif |
| 1644 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1645 | 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] | 1646 | char **buf, size_t *buflen, |
| 1647 | int depth) |
| 1648 | { |
| 1649 | int ret; |
| 1650 | if (ref->next) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1651 | depth = __synthesize_probe_trace_arg_ref(ref->next, buf, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1652 | buflen, depth + 1); |
| 1653 | if (depth < 0) |
| 1654 | goto out; |
| 1655 | } |
| 1656 | |
| 1657 | ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset); |
| 1658 | if (ret < 0) |
| 1659 | depth = ret; |
| 1660 | else { |
| 1661 | *buf += ret; |
| 1662 | *buflen -= ret; |
| 1663 | } |
| 1664 | out: |
| 1665 | return depth; |
| 1666 | |
| 1667 | } |
| 1668 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1669 | static int synthesize_probe_trace_arg(struct probe_trace_arg *arg, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1670 | char *buf, size_t buflen) |
| 1671 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1672 | struct probe_trace_arg_ref *ref = arg->ref; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1673 | int ret, depth = 0; |
| 1674 | char *tmp = buf; |
| 1675 | |
| 1676 | /* Argument name or separator */ |
| 1677 | if (arg->name) |
| 1678 | ret = e_snprintf(buf, buflen, " %s=", arg->name); |
| 1679 | else |
| 1680 | ret = e_snprintf(buf, buflen, " "); |
| 1681 | if (ret < 0) |
| 1682 | return ret; |
| 1683 | buf += ret; |
| 1684 | buflen -= ret; |
| 1685 | |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1686 | /* Special case: @XXX */ |
| 1687 | if (arg->value[0] == '@' && arg->ref) |
| 1688 | ref = ref->next; |
| 1689 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1690 | /* Dereferencing arguments */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1691 | if (ref) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1692 | depth = __synthesize_probe_trace_arg_ref(ref, &buf, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1693 | &buflen, 1); |
| 1694 | if (depth < 0) |
| 1695 | return depth; |
| 1696 | } |
| 1697 | |
| 1698 | /* Print argument value */ |
Masami Hiramatsu | b7dcb85 | 2010-05-19 15:57:49 -0400 | [diff] [blame] | 1699 | if (arg->value[0] == '@' && arg->ref) |
| 1700 | ret = e_snprintf(buf, buflen, "%s%+ld", arg->value, |
| 1701 | arg->ref->offset); |
| 1702 | else |
| 1703 | ret = e_snprintf(buf, buflen, "%s", arg->value); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1704 | if (ret < 0) |
| 1705 | return ret; |
| 1706 | buf += ret; |
| 1707 | buflen -= ret; |
| 1708 | |
| 1709 | /* Closing */ |
| 1710 | while (depth--) { |
| 1711 | ret = e_snprintf(buf, buflen, ")"); |
| 1712 | if (ret < 0) |
| 1713 | return ret; |
| 1714 | buf += ret; |
| 1715 | buflen -= ret; |
| 1716 | } |
Masami Hiramatsu | 4984912 | 2010-04-12 13:17:15 -0400 | [diff] [blame] | 1717 | /* Print argument type */ |
| 1718 | if (arg->type) { |
| 1719 | ret = e_snprintf(buf, buflen, ":%s", arg->type); |
| 1720 | if (ret <= 0) |
| 1721 | return ret; |
| 1722 | buf += ret; |
| 1723 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1724 | |
| 1725 | return buf - tmp; |
| 1726 | } |
| 1727 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1728 | char *synthesize_probe_trace_command(struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1729 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1730 | struct probe_trace_point *tp = &tev->point; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1731 | char *buf; |
| 1732 | int i, len, ret; |
| 1733 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1734 | buf = zalloc(MAX_CMDLEN); |
| 1735 | if (buf == NULL) |
| 1736 | return NULL; |
| 1737 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 1738 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p', |
| 1739 | tev->group, tev->event); |
| 1740 | if (len <= 0) |
| 1741 | goto error; |
| 1742 | |
| 1743 | /* Uprobes must have tp->address and tp->module */ |
| 1744 | if (tev->uprobes && (!tp->address || !tp->module)) |
| 1745 | goto error; |
| 1746 | |
| 1747 | /* Use the tp->address for uprobes */ |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1748 | if (tev->uprobes) |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 1749 | ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx", |
| 1750 | tp->module, tp->address); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1751 | else |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 1752 | ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu", |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1753 | tp->module ?: "", tp->module ? ":" : "", |
| 1754 | tp->symbol, tp->offset); |
| 1755 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 1756 | if (ret <= 0) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1757 | goto error; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 1758 | len += ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1759 | |
| 1760 | for (i = 0; i < tev->nargs; i++) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1761 | ret = synthesize_probe_trace_arg(&tev->args[i], buf + len, |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1762 | MAX_CMDLEN - len); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1763 | if (ret <= 0) |
| 1764 | goto error; |
| 1765 | len += ret; |
| 1766 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1767 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1768 | return buf; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1769 | error: |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1770 | free(buf); |
| 1771 | return NULL; |
| 1772 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1773 | |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 1774 | static int find_perf_probe_point_from_map(struct probe_trace_point *tp, |
| 1775 | struct perf_probe_point *pp, |
| 1776 | bool is_kprobe) |
| 1777 | { |
| 1778 | struct symbol *sym = NULL; |
| 1779 | struct map *map; |
| 1780 | u64 addr; |
| 1781 | int ret = -ENOENT; |
| 1782 | |
| 1783 | if (!is_kprobe) { |
| 1784 | map = dso__new_map(tp->module); |
| 1785 | if (!map) |
| 1786 | goto out; |
| 1787 | addr = tp->address; |
| 1788 | sym = map__find_symbol(map, addr, NULL); |
| 1789 | } else { |
| 1790 | addr = kernel_get_symbol_address_by_name(tp->symbol, true); |
| 1791 | if (addr) { |
| 1792 | addr += tp->offset; |
| 1793 | sym = __find_kernel_function(addr, &map); |
| 1794 | } |
| 1795 | } |
| 1796 | if (!sym) |
| 1797 | goto out; |
| 1798 | |
| 1799 | pp->retprobe = tp->retprobe; |
| 1800 | pp->offset = addr - map->unmap_ip(map, sym->start); |
| 1801 | pp->function = strdup(sym->name); |
| 1802 | ret = pp->function ? 0 : -ENOMEM; |
| 1803 | |
| 1804 | out: |
| 1805 | if (map && !is_kprobe) { |
Arnaldo Carvalho de Melo | 84c2caf | 2015-05-25 16:59:56 -0300 | [diff] [blame] | 1806 | map__put(map); |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | return ret; |
| 1810 | } |
| 1811 | |
| 1812 | static int convert_to_perf_probe_point(struct probe_trace_point *tp, |
| 1813 | struct perf_probe_point *pp, |
| 1814 | bool is_kprobe) |
| 1815 | { |
| 1816 | char buf[128]; |
| 1817 | int ret; |
| 1818 | |
| 1819 | ret = find_perf_probe_point_from_dwarf(tp, pp, is_kprobe); |
| 1820 | if (!ret) |
| 1821 | return 0; |
| 1822 | ret = find_perf_probe_point_from_map(tp, pp, is_kprobe); |
| 1823 | if (!ret) |
| 1824 | return 0; |
| 1825 | |
| 1826 | pr_debug("Failed to find probe point from both of dwarf and map.\n"); |
| 1827 | |
| 1828 | if (tp->symbol) { |
| 1829 | pp->function = strdup(tp->symbol); |
| 1830 | pp->offset = tp->offset; |
| 1831 | } else if (!tp->module && !is_kprobe) { |
| 1832 | ret = e_snprintf(buf, 128, "0x%" PRIx64, (u64)tp->address); |
| 1833 | if (ret < 0) |
| 1834 | return ret; |
| 1835 | pp->function = strdup(buf); |
| 1836 | pp->offset = 0; |
| 1837 | } |
| 1838 | if (pp->function == NULL) |
| 1839 | return -ENOMEM; |
| 1840 | |
| 1841 | pp->retprobe = tp->retprobe; |
| 1842 | |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1846 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1847 | struct perf_probe_event *pev, bool is_kprobe) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1848 | { |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1849 | char buf[64] = ""; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1850 | int i, ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1851 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1852 | /* Convert event/group name */ |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1853 | pev->event = strdup(tev->event); |
| 1854 | pev->group = strdup(tev->group); |
| 1855 | if (pev->event == NULL || pev->group == NULL) |
| 1856 | return -ENOMEM; |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 1857 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1858 | /* Convert trace_point to probe_point */ |
Masami Hiramatsu | 5a6f631 | 2014-02-06 05:32:23 +0000 | [diff] [blame] | 1859 | ret = convert_to_perf_probe_point(&tev->point, &pev->point, is_kprobe); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1860 | if (ret < 0) |
| 1861 | return ret; |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 1862 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1863 | /* Convert trace_arg to probe_arg */ |
| 1864 | pev->nargs = tev->nargs; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 1865 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
| 1866 | if (pev->args == NULL) |
| 1867 | return -ENOMEM; |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1868 | for (i = 0; i < tev->nargs && ret >= 0; i++) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1869 | if (tev->args[i].name) |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1870 | pev->args[i].name = strdup(tev->args[i].name); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1871 | else { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1872 | ret = synthesize_probe_trace_arg(&tev->args[i], |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1873 | buf, 64); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1874 | pev->args[i].name = strdup(buf); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1875 | } |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 1876 | if (pev->args[i].name == NULL && ret >= 0) |
| 1877 | ret = -ENOMEM; |
| 1878 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1879 | |
| 1880 | if (ret < 0) |
| 1881 | clear_perf_probe_event(pev); |
| 1882 | |
| 1883 | return ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | void clear_perf_probe_event(struct perf_probe_event *pev) |
| 1887 | { |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1888 | struct perf_probe_arg_field *field, *next; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1889 | int i; |
| 1890 | |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1891 | free(pev->event); |
| 1892 | free(pev->group); |
Masami Hiramatsu | 7afb3fa | 2015-04-01 19:25:39 +0900 | [diff] [blame] | 1893 | free(pev->target); |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 1894 | clear_perf_probe_point(&pev->point); |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1895 | |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1896 | for (i = 0; i < pev->nargs; i++) { |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1897 | free(pev->args[i].name); |
| 1898 | free(pev->args[i].var); |
| 1899 | free(pev->args[i].type); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1900 | field = pev->args[i].field; |
| 1901 | while (field) { |
| 1902 | next = field->next; |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 1903 | zfree(&field->name); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 1904 | free(field); |
| 1905 | field = next; |
| 1906 | } |
| 1907 | } |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1908 | free(pev->args); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1909 | memset(pev, 0, sizeof(*pev)); |
| 1910 | } |
| 1911 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1912 | static void clear_probe_trace_event(struct probe_trace_event *tev) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1913 | { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 1914 | struct probe_trace_arg_ref *ref, *next; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1915 | int i; |
| 1916 | |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1917 | free(tev->event); |
| 1918 | free(tev->group); |
| 1919 | free(tev->point.symbol); |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 1920 | free(tev->point.realname); |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1921 | free(tev->point.module); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1922 | for (i = 0; i < tev->nargs; i++) { |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1923 | free(tev->args[i].name); |
| 1924 | free(tev->args[i].value); |
| 1925 | free(tev->args[i].type); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1926 | ref = tev->args[i].ref; |
| 1927 | while (ref) { |
| 1928 | next = ref->next; |
| 1929 | free(ref); |
| 1930 | ref = next; |
| 1931 | } |
| 1932 | } |
Arnaldo Carvalho de Melo | f538565 | 2013-12-26 15:54:57 -0300 | [diff] [blame] | 1933 | free(tev->args); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 1934 | memset(tev, 0, sizeof(*tev)); |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1935 | } |
| 1936 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 1937 | static void print_open_warning(int err, bool is_kprobe) |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1938 | { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 1939 | char sbuf[STRERR_BUFSIZE]; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1940 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 1941 | if (err == -ENOENT) { |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1942 | const char *config; |
| 1943 | |
| 1944 | if (!is_kprobe) |
| 1945 | config = "CONFIG_UPROBE_EVENTS"; |
| 1946 | else |
| 1947 | config = "CONFIG_KPROBE_EVENTS"; |
| 1948 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 1949 | pr_warning("%cprobe_events file does not exist" |
| 1950 | " - please rebuild kernel with %s.\n", |
| 1951 | is_kprobe ? 'k' : 'u', config); |
| 1952 | } else if (err == -ENOTSUP) |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 1953 | pr_warning("Tracefs or debugfs is not mounted.\n"); |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 1954 | else |
| 1955 | pr_warning("Failed to open %cprobe_events: %s\n", |
| 1956 | is_kprobe ? 'k' : 'u', |
| 1957 | strerror_r(-err, sbuf, sizeof(sbuf))); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 1958 | } |
| 1959 | |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 1960 | static void print_both_open_warning(int kerr, int uerr) |
| 1961 | { |
| 1962 | /* Both kprobes and uprobes are disabled, warn it. */ |
| 1963 | if (kerr == -ENOTSUP && uerr == -ENOTSUP) |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 1964 | pr_warning("Tracefs or debugfs is not mounted.\n"); |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 1965 | else if (kerr == -ENOENT && uerr == -ENOENT) |
| 1966 | pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " |
| 1967 | "or/and CONFIG_UPROBE_EVENTS.\n"); |
| 1968 | else { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 1969 | char sbuf[STRERR_BUFSIZE]; |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 1970 | pr_warning("Failed to open kprobe events: %s.\n", |
| 1971 | strerror_r(-kerr, sbuf, sizeof(sbuf))); |
| 1972 | pr_warning("Failed to open uprobe events: %s.\n", |
| 1973 | strerror_r(-uerr, sbuf, sizeof(sbuf))); |
| 1974 | } |
| 1975 | } |
| 1976 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 1977 | static int open_probe_events(const char *trace_file, bool readwrite) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1978 | { |
| 1979 | char buf[PATH_MAX]; |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1980 | const char *__debugfs; |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 1981 | const char *tracing_dir = ""; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 1982 | int ret; |
| 1983 | |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 1984 | __debugfs = tracefs_find_mountpoint(); |
| 1985 | if (__debugfs == NULL) { |
| 1986 | tracing_dir = "tracing/"; |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1987 | |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 1988 | __debugfs = debugfs_find_mountpoint(); |
| 1989 | if (__debugfs == NULL) |
| 1990 | return -ENOTSUP; |
| 1991 | } |
| 1992 | |
| 1993 | ret = e_snprintf(buf, PATH_MAX, "%s/%s%s", |
| 1994 | __debugfs, tracing_dir, trace_file); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1995 | if (ret >= 0) { |
Masami Hiramatsu | 7ca5989 | 2010-04-14 18:39:28 -0400 | [diff] [blame] | 1996 | pr_debug("Opening %s write=%d\n", buf, readwrite); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1997 | if (readwrite && !probe_event_dry_run) |
Masami Hiramatsu | b8dc3984 | 2015-05-06 21:46:42 +0900 | [diff] [blame] | 1998 | ret = open(buf, O_RDWR | O_APPEND, 0); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 1999 | else |
| 2000 | ret = open(buf, O_RDONLY, 0); |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 2001 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2002 | if (ret < 0) |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2003 | ret = -errno; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2004 | } |
| 2005 | return ret; |
| 2006 | } |
| 2007 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2008 | static int open_kprobe_events(bool readwrite) |
| 2009 | { |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 2010 | return open_probe_events("kprobe_events", readwrite); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | static int open_uprobe_events(bool readwrite) |
| 2014 | { |
Steven Rostedt (Red Hat) | 23773ca | 2015-02-02 14:35:07 -0500 | [diff] [blame] | 2015 | return open_probe_events("uprobe_events", readwrite); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | /* Get raw string list of current kprobe_events or uprobe_events */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2019 | static struct strlist *get_probe_trace_command_rawlist(int fd) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2020 | { |
| 2021 | int ret, idx; |
| 2022 | FILE *fp; |
| 2023 | char buf[MAX_CMDLEN]; |
| 2024 | char *p; |
| 2025 | struct strlist *sl; |
| 2026 | |
| 2027 | sl = strlist__new(true, NULL); |
| 2028 | |
| 2029 | fp = fdopen(dup(fd), "r"); |
| 2030 | while (!feof(fp)) { |
| 2031 | p = fgets(buf, MAX_CMDLEN, fp); |
| 2032 | if (!p) |
| 2033 | break; |
| 2034 | |
| 2035 | idx = strlen(p) - 1; |
| 2036 | if (p[idx] == '\n') |
| 2037 | p[idx] = '\0'; |
| 2038 | ret = strlist__add(sl, buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2039 | if (ret < 0) { |
Masami Hiramatsu | 6eb0866 | 2014-08-14 02:22:30 +0000 | [diff] [blame] | 2040 | pr_debug("strlist__add failed (%d)\n", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2041 | strlist__delete(sl); |
| 2042 | return NULL; |
| 2043 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2044 | } |
| 2045 | fclose(fp); |
| 2046 | |
| 2047 | return sl; |
| 2048 | } |
| 2049 | |
Masami Hiramatsu | 9aaf5a5 | 2015-02-19 23:31:13 +0900 | [diff] [blame] | 2050 | struct kprobe_blacklist_node { |
| 2051 | struct list_head list; |
| 2052 | unsigned long start; |
| 2053 | unsigned long end; |
| 2054 | char *symbol; |
| 2055 | }; |
| 2056 | |
| 2057 | static void kprobe_blacklist__delete(struct list_head *blacklist) |
| 2058 | { |
| 2059 | struct kprobe_blacklist_node *node; |
| 2060 | |
| 2061 | while (!list_empty(blacklist)) { |
| 2062 | node = list_first_entry(blacklist, |
| 2063 | struct kprobe_blacklist_node, list); |
| 2064 | list_del(&node->list); |
| 2065 | free(node->symbol); |
| 2066 | free(node); |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | static int kprobe_blacklist__load(struct list_head *blacklist) |
| 2071 | { |
| 2072 | struct kprobe_blacklist_node *node; |
| 2073 | const char *__debugfs = debugfs_find_mountpoint(); |
| 2074 | char buf[PATH_MAX], *p; |
| 2075 | FILE *fp; |
| 2076 | int ret; |
| 2077 | |
| 2078 | if (__debugfs == NULL) |
| 2079 | return -ENOTSUP; |
| 2080 | |
| 2081 | ret = e_snprintf(buf, PATH_MAX, "%s/kprobes/blacklist", __debugfs); |
| 2082 | if (ret < 0) |
| 2083 | return ret; |
| 2084 | |
| 2085 | fp = fopen(buf, "r"); |
| 2086 | if (!fp) |
| 2087 | return -errno; |
| 2088 | |
| 2089 | ret = 0; |
| 2090 | while (fgets(buf, PATH_MAX, fp)) { |
| 2091 | node = zalloc(sizeof(*node)); |
| 2092 | if (!node) { |
| 2093 | ret = -ENOMEM; |
| 2094 | break; |
| 2095 | } |
| 2096 | INIT_LIST_HEAD(&node->list); |
| 2097 | list_add_tail(&node->list, blacklist); |
| 2098 | if (sscanf(buf, "0x%lx-0x%lx", &node->start, &node->end) != 2) { |
| 2099 | ret = -EINVAL; |
| 2100 | break; |
| 2101 | } |
| 2102 | p = strchr(buf, '\t'); |
| 2103 | if (p) { |
| 2104 | p++; |
| 2105 | if (p[strlen(p) - 1] == '\n') |
| 2106 | p[strlen(p) - 1] = '\0'; |
| 2107 | } else |
| 2108 | p = (char *)"unknown"; |
| 2109 | node->symbol = strdup(p); |
| 2110 | if (!node->symbol) { |
| 2111 | ret = -ENOMEM; |
| 2112 | break; |
| 2113 | } |
| 2114 | pr_debug2("Blacklist: 0x%lx-0x%lx, %s\n", |
| 2115 | node->start, node->end, node->symbol); |
| 2116 | ret++; |
| 2117 | } |
| 2118 | if (ret < 0) |
| 2119 | kprobe_blacklist__delete(blacklist); |
| 2120 | fclose(fp); |
| 2121 | |
| 2122 | return ret; |
| 2123 | } |
| 2124 | |
| 2125 | static struct kprobe_blacklist_node * |
| 2126 | kprobe_blacklist__find_by_address(struct list_head *blacklist, |
| 2127 | unsigned long address) |
| 2128 | { |
| 2129 | struct kprobe_blacklist_node *node; |
| 2130 | |
| 2131 | list_for_each_entry(node, blacklist, list) { |
| 2132 | if (node->start <= address && address <= node->end) |
| 2133 | return node; |
| 2134 | } |
| 2135 | |
| 2136 | return NULL; |
| 2137 | } |
| 2138 | |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2139 | static LIST_HEAD(kprobe_blacklist); |
| 2140 | |
| 2141 | static void kprobe_blacklist__init(void) |
| 2142 | { |
| 2143 | if (!list_empty(&kprobe_blacklist)) |
| 2144 | return; |
| 2145 | |
| 2146 | if (kprobe_blacklist__load(&kprobe_blacklist) < 0) |
| 2147 | pr_debug("No kprobe blacklist support, ignored\n"); |
| 2148 | } |
| 2149 | |
| 2150 | static void kprobe_blacklist__release(void) |
| 2151 | { |
| 2152 | kprobe_blacklist__delete(&kprobe_blacklist); |
| 2153 | } |
| 2154 | |
| 2155 | static bool kprobe_blacklist__listed(unsigned long address) |
| 2156 | { |
| 2157 | return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address); |
| 2158 | } |
| 2159 | |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2160 | static int perf_probe_event__sprintf(struct perf_probe_event *pev, |
| 2161 | const char *module, |
| 2162 | struct strbuf *result) |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2163 | { |
Masami Hiramatsu | 7e990a5 | 2009-12-15 10:31:21 -0500 | [diff] [blame] | 2164 | int i, ret; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2165 | char buf[128]; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2166 | char *place; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2167 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2168 | /* Synthesize only event probe point */ |
| 2169 | place = synthesize_perf_probe_point(&pev->point); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2170 | if (!place) |
| 2171 | return -EINVAL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2172 | |
| 2173 | ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event); |
Masami Hiramatsu | 7e990a5 | 2009-12-15 10:31:21 -0500 | [diff] [blame] | 2174 | if (ret < 0) |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2175 | goto out; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2176 | |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2177 | strbuf_addf(result, " %-20s (on %s", buf, place); |
Masami Hiramatsu | fb226cc | 2014-02-06 05:32:13 +0000 | [diff] [blame] | 2178 | if (module) |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2179 | strbuf_addf(result, " in %s", module); |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2180 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2181 | if (pev->nargs > 0) { |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2182 | strbuf_addstr(result, " with"); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 2183 | for (i = 0; i < pev->nargs; i++) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2184 | ret = synthesize_perf_probe_arg(&pev->args[i], |
| 2185 | buf, 128); |
| 2186 | if (ret < 0) |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2187 | goto out; |
| 2188 | strbuf_addf(result, " %s", buf); |
Masami Hiramatsu | 7df2f32 | 2010-03-16 18:06:26 -0400 | [diff] [blame] | 2189 | } |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2190 | } |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2191 | strbuf_addch(result, ')'); |
| 2192 | out: |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2193 | free(place); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2194 | return ret; |
Masami Hiramatsu | 278498d | 2009-12-08 17:02:40 -0500 | [diff] [blame] | 2195 | } |
| 2196 | |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2197 | /* Show an event */ |
| 2198 | static int show_perf_probe_event(struct perf_probe_event *pev, |
| 2199 | const char *module, bool use_stdout) |
| 2200 | { |
| 2201 | struct strbuf buf = STRBUF_INIT; |
| 2202 | int ret; |
| 2203 | |
| 2204 | ret = perf_probe_event__sprintf(pev, module, &buf); |
| 2205 | if (ret >= 0) { |
| 2206 | if (use_stdout) |
| 2207 | printf("%s\n", buf.buf); |
| 2208 | else |
| 2209 | pr_info("%s\n", buf.buf); |
| 2210 | } |
| 2211 | strbuf_release(&buf); |
| 2212 | |
| 2213 | return ret; |
| 2214 | } |
| 2215 | |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2216 | static bool filter_probe_trace_event(struct probe_trace_event *tev, |
| 2217 | struct strfilter *filter) |
| 2218 | { |
| 2219 | char tmp[128]; |
| 2220 | |
| 2221 | /* At first, check the event name itself */ |
| 2222 | if (strfilter__compare(filter, tev->event)) |
| 2223 | return true; |
| 2224 | |
| 2225 | /* Next, check the combination of name and group */ |
| 2226 | if (e_snprintf(tmp, 128, "%s:%s", tev->group, tev->event) < 0) |
| 2227 | return false; |
| 2228 | return strfilter__compare(filter, tmp); |
| 2229 | } |
| 2230 | |
| 2231 | static int __show_perf_probe_events(int fd, bool is_kprobe, |
| 2232 | struct strfilter *filter) |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2233 | { |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2234 | int ret = 0; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2235 | struct probe_trace_event tev; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2236 | struct perf_probe_event pev; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2237 | struct strlist *rawlist; |
| 2238 | struct str_node *ent; |
| 2239 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2240 | memset(&tev, 0, sizeof(tev)); |
| 2241 | memset(&pev, 0, sizeof(pev)); |
Masami Hiramatsu | 7204133 | 2010-01-05 17:47:10 -0500 | [diff] [blame] | 2242 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2243 | rawlist = get_probe_trace_command_rawlist(fd); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2244 | if (!rawlist) |
Masami Hiramatsu | 6eb0866 | 2014-08-14 02:22:30 +0000 | [diff] [blame] | 2245 | return -ENOMEM; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2246 | |
Masami Hiramatsu | adf365f | 2009-12-15 10:32:03 -0500 | [diff] [blame] | 2247 | strlist__for_each(ent, rawlist) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2248 | ret = parse_probe_trace_command(ent->s, &tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2249 | if (ret >= 0) { |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2250 | if (!filter_probe_trace_event(&tev, filter)) |
| 2251 | goto next; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2252 | ret = convert_to_perf_probe_event(&tev, &pev, |
| 2253 | is_kprobe); |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2254 | if (ret < 0) |
| 2255 | goto next; |
| 2256 | ret = show_perf_probe_event(&pev, tev.point.module, |
| 2257 | true); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2258 | } |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2259 | next: |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2260 | clear_perf_probe_event(&pev); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2261 | clear_probe_trace_event(&tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2262 | if (ret < 0) |
| 2263 | break; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2264 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2265 | strlist__delete(rawlist); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2266 | |
| 2267 | return ret; |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 2268 | } |
| 2269 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2270 | /* List up current perf-probe events */ |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2271 | int show_perf_probe_events(struct strfilter *filter) |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2272 | { |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2273 | int kp_fd, up_fd, ret; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2274 | |
| 2275 | setup_pager(); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2276 | |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 2277 | ret = init_symbol_maps(false); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2278 | if (ret < 0) |
| 2279 | return ret; |
| 2280 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2281 | kp_fd = open_kprobe_events(false); |
| 2282 | if (kp_fd >= 0) { |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2283 | ret = __show_perf_probe_events(kp_fd, true, filter); |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2284 | close(kp_fd); |
| 2285 | if (ret < 0) |
| 2286 | goto out; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2287 | } |
| 2288 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2289 | up_fd = open_uprobe_events(false); |
| 2290 | if (kp_fd < 0 && up_fd < 0) { |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 2291 | print_both_open_warning(kp_fd, up_fd); |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2292 | ret = kp_fd; |
| 2293 | goto out; |
| 2294 | } |
| 2295 | |
| 2296 | if (up_fd >= 0) { |
Masami Hiramatsu | b6a8964 | 2015-04-24 18:47:50 +0900 | [diff] [blame] | 2297 | ret = __show_perf_probe_events(up_fd, false, filter); |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2298 | close(up_fd); |
| 2299 | } |
| 2300 | out: |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 2301 | exit_symbol_maps(); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2302 | return ret; |
| 2303 | } |
| 2304 | |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2305 | /* Get current perf-probe event names */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2306 | 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] | 2307 | { |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2308 | char buf[128]; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2309 | struct strlist *sl, *rawlist; |
| 2310 | struct str_node *ent; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2311 | struct probe_trace_event tev; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2312 | int ret = 0; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2313 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2314 | memset(&tev, 0, sizeof(tev)); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2315 | rawlist = get_probe_trace_command_rawlist(fd); |
Masami Hiramatsu | 6eb0866 | 2014-08-14 02:22:30 +0000 | [diff] [blame] | 2316 | if (!rawlist) |
| 2317 | return NULL; |
Masami Hiramatsu | e1d2017 | 2009-12-07 12:00:46 -0500 | [diff] [blame] | 2318 | sl = strlist__new(true, NULL); |
Masami Hiramatsu | adf365f | 2009-12-15 10:32:03 -0500 | [diff] [blame] | 2319 | strlist__for_each(ent, rawlist) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2320 | ret = parse_probe_trace_command(ent->s, &tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2321 | if (ret < 0) |
| 2322 | break; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2323 | if (include_group) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2324 | ret = e_snprintf(buf, 128, "%s:%s", tev.group, |
| 2325 | tev.event); |
| 2326 | if (ret >= 0) |
| 2327 | ret = strlist__add(sl, buf); |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2328 | } else |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2329 | ret = strlist__add(sl, tev.event); |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2330 | clear_probe_trace_event(&tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2331 | if (ret < 0) |
| 2332 | break; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2333 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2334 | strlist__delete(rawlist); |
| 2335 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2336 | if (ret < 0) { |
| 2337 | strlist__delete(sl); |
| 2338 | return NULL; |
| 2339 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2340 | return sl; |
| 2341 | } |
| 2342 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2343 | 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] | 2344 | { |
Frederic Weisbecker | 6eca8cc | 2010-04-21 02:01:05 +0200 | [diff] [blame] | 2345 | int ret = 0; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2346 | char *buf = synthesize_probe_trace_command(tev); |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 2347 | char sbuf[STRERR_BUFSIZE]; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2348 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2349 | if (!buf) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2350 | pr_debug("Failed to synthesize probe trace event.\n"); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2351 | return -EINVAL; |
| 2352 | } |
| 2353 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2354 | pr_debug("Writing event: %s\n", buf); |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 2355 | if (!probe_event_dry_run) { |
| 2356 | ret = write(fd, buf, strlen(buf)); |
Namhyung Kim | 7949ba1 | 2015-01-10 19:33:48 +0900 | [diff] [blame] | 2357 | if (ret <= 0) { |
| 2358 | ret = -errno; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2359 | pr_warning("Failed to write event: %s\n", |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 2360 | strerror_r(errno, sbuf, sizeof(sbuf))); |
Namhyung Kim | 7949ba1 | 2015-01-10 19:33:48 +0900 | [diff] [blame] | 2361 | } |
Masami Hiramatsu | f4d7da4 | 2010-03-16 18:06:05 -0400 | [diff] [blame] | 2362 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2363 | free(buf); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2364 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2365 | } |
| 2366 | |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2367 | static int get_new_event_name(char *buf, size_t len, const char *base, |
| 2368 | struct strlist *namelist, bool allow_suffix) |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2369 | { |
| 2370 | int i, ret; |
Masami Hiramatsu | 35a23ff9 | 2015-06-12 14:08:20 +0900 | [diff] [blame] | 2371 | char *p; |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 2372 | |
Naveen N. Rao | 3099c02 | 2015-04-28 17:35:34 +0530 | [diff] [blame] | 2373 | if (*base == '.') |
| 2374 | base++; |
| 2375 | |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 2376 | /* Try no suffix */ |
| 2377 | ret = e_snprintf(buf, len, "%s", base); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2378 | if (ret < 0) { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 2379 | pr_debug("snprintf() failed: %d\n", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2380 | return ret; |
| 2381 | } |
Masami Hiramatsu | 35a23ff9 | 2015-06-12 14:08:20 +0900 | [diff] [blame] | 2382 | /* Cut off the postfixes (e.g. .const, .isra)*/ |
| 2383 | p = strchr(buf, '.'); |
| 2384 | if (p && p != buf) |
| 2385 | *p = '\0'; |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 2386 | if (!strlist__has_entry(namelist, buf)) |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2387 | return 0; |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 2388 | |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 2389 | if (!allow_suffix) { |
| 2390 | pr_warning("Error: event \"%s\" already exists. " |
| 2391 | "(Use -f to force duplicates.)\n", base); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2392 | return -EEXIST; |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 2393 | } |
| 2394 | |
Masami Hiramatsu | 17f88fc | 2009-12-08 17:03:02 -0500 | [diff] [blame] | 2395 | /* Try to add suffix */ |
| 2396 | for (i = 1; i < MAX_EVENT_INDEX; i++) { |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2397 | ret = e_snprintf(buf, len, "%s_%d", base, i); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2398 | if (ret < 0) { |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 2399 | pr_debug("snprintf() failed: %d\n", ret); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2400 | return ret; |
| 2401 | } |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2402 | if (!strlist__has_entry(namelist, buf)) |
| 2403 | break; |
| 2404 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2405 | if (i == MAX_EVENT_INDEX) { |
| 2406 | pr_warning("Too many events are on the same function.\n"); |
| 2407 | ret = -ERANGE; |
| 2408 | } |
| 2409 | |
| 2410 | return ret; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2411 | } |
| 2412 | |
Masami Hiramatsu | 79702f6 | 2015-02-28 11:53:29 +0900 | [diff] [blame] | 2413 | /* Warn if the current kernel's uprobe implementation is old */ |
| 2414 | static void warn_uprobe_event_compat(struct probe_trace_event *tev) |
| 2415 | { |
| 2416 | int i; |
| 2417 | char *buf = synthesize_probe_trace_command(tev); |
| 2418 | |
| 2419 | /* Old uprobe event doesn't support memory dereference */ |
| 2420 | if (!tev->uprobes || tev->nargs == 0 || !buf) |
| 2421 | goto out; |
| 2422 | |
| 2423 | for (i = 0; i < tev->nargs; i++) |
| 2424 | if (strglobmatch(tev->args[i].value, "[$@+-]*")) { |
| 2425 | pr_warning("Please upgrade your kernel to at least " |
| 2426 | "3.14 to have access to feature %s\n", |
| 2427 | tev->args[i].value); |
| 2428 | break; |
| 2429 | } |
| 2430 | out: |
| 2431 | free(buf); |
| 2432 | } |
| 2433 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2434 | static int __add_probe_trace_events(struct perf_probe_event *pev, |
| 2435 | struct probe_trace_event *tevs, |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2436 | int ntevs, bool allow_suffix) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2437 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2438 | int i, fd, ret; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2439 | struct probe_trace_event *tev = NULL; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2440 | char buf[64]; |
| 2441 | const char *event, *group; |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2442 | struct strlist *namelist; |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2443 | bool safename; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2444 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2445 | if (pev->uprobes) |
| 2446 | fd = open_uprobe_events(true); |
| 2447 | else |
| 2448 | fd = open_kprobe_events(true); |
| 2449 | |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2450 | if (fd < 0) { |
| 2451 | print_open_warning(fd, !pev->uprobes); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2452 | return fd; |
Masami Hiramatsu | 5e45187 | 2014-08-13 16:12:48 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
Masami Hiramatsu | b498ce1 | 2009-11-30 19:20:25 -0500 | [diff] [blame] | 2455 | /* Get current event names */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2456 | namelist = get_probe_trace_event_names(fd, false); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2457 | if (!namelist) { |
| 2458 | pr_debug("Failed to get current event list.\n"); |
Masami Hiramatsu | ae2cb1a | 2015-05-06 21:46:40 +0900 | [diff] [blame] | 2459 | ret = -ENOMEM; |
| 2460 | goto close_out; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2461 | } |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2462 | |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2463 | safename = (pev->point.function && !strisglob(pev->point.function)); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2464 | ret = 0; |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 2465 | pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":"); |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 2466 | for (i = 0; i < ntevs; i++) { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2467 | tev = &tevs[i]; |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2468 | /* Skip if the symbol is out of .text or blacklisted */ |
Masami Hiramatsu | 5a51fcd | 2015-05-06 21:46:49 +0900 | [diff] [blame] | 2469 | if (!tev->point.symbol) |
| 2470 | continue; |
Masami Hiramatsu | 9aaf5a5 | 2015-02-19 23:31:13 +0900 | [diff] [blame] | 2471 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2472 | if (pev->event) |
| 2473 | event = pev->event; |
| 2474 | else |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2475 | if (safename) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2476 | event = pev->point.function; |
| 2477 | else |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2478 | event = tev->point.realname; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2479 | if (pev->group) |
| 2480 | group = pev->group; |
| 2481 | else |
| 2482 | group = PERFPROBE_GROUP; |
| 2483 | |
| 2484 | /* Get an unused new event name */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2485 | ret = get_new_event_name(buf, 64, event, |
| 2486 | namelist, allow_suffix); |
| 2487 | if (ret < 0) |
| 2488 | break; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2489 | event = buf; |
| 2490 | |
Masami Hiramatsu | 02b95da | 2010-04-12 13:17:56 -0400 | [diff] [blame] | 2491 | tev->event = strdup(event); |
| 2492 | tev->group = strdup(group); |
| 2493 | if (tev->event == NULL || tev->group == NULL) { |
| 2494 | ret = -ENOMEM; |
| 2495 | break; |
| 2496 | } |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2497 | ret = write_probe_trace_event(fd, tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2498 | if (ret < 0) |
| 2499 | break; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2500 | /* Add added event name to namelist */ |
| 2501 | strlist__add(namelist, event); |
| 2502 | |
| 2503 | /* Trick here - save current event/group */ |
| 2504 | event = pev->event; |
| 2505 | group = pev->group; |
| 2506 | pev->event = tev->event; |
| 2507 | pev->group = tev->group; |
Masami Hiramatsu | ba7ecb0 | 2015-06-13 10:31:16 +0900 | [diff] [blame] | 2508 | show_perf_probe_event(pev, tev->point.module, false); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2509 | /* Trick here - restore current event/group */ |
| 2510 | pev->event = (char *)event; |
| 2511 | pev->group = (char *)group; |
| 2512 | |
| 2513 | /* |
| 2514 | * Probes after the first probe which comes from same |
| 2515 | * user input are always allowed to add suffix, because |
| 2516 | * there might be several addresses corresponding to |
| 2517 | * one code line. |
| 2518 | */ |
| 2519 | allow_suffix = true; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2520 | } |
Masami Hiramatsu | 79702f6 | 2015-02-28 11:53:29 +0900 | [diff] [blame] | 2521 | if (ret == -EINVAL && pev->uprobes) |
| 2522 | warn_uprobe_event_compat(tev); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2523 | |
Masami Hiramatsu | 9aaf5a5 | 2015-02-19 23:31:13 +0900 | [diff] [blame] | 2524 | /* Note that it is possible to skip all events because of blacklist */ |
| 2525 | if (ret >= 0 && tev->event) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2526 | /* Show how to use the event. */ |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 2527 | pr_info("\nYou can now use it in all perf tools, such as:\n\n"); |
| 2528 | pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group, |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2529 | tev->event); |
| 2530 | } |
Masami Hiramatsu | a9b495b | 2009-12-08 17:02:47 -0500 | [diff] [blame] | 2531 | |
Masami Hiramatsu | e1d2017 | 2009-12-07 12:00:46 -0500 | [diff] [blame] | 2532 | strlist__delete(namelist); |
Masami Hiramatsu | ae2cb1a | 2015-05-06 21:46:40 +0900 | [diff] [blame] | 2533 | close_out: |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2534 | close(fd); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2535 | return ret; |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 2536 | } |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2537 | |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2538 | static int find_probe_functions(struct map *map, char *name, |
| 2539 | struct symbol **syms) |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2540 | { |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2541 | int found = 0; |
Arnaldo Carvalho de Melo | 0a3873a | 2015-01-16 16:40:25 -0300 | [diff] [blame] | 2542 | struct symbol *sym; |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2543 | struct rb_node *tmp; |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2544 | |
Wang Nan | 75e4a2a | 2015-05-15 12:14:44 +0000 | [diff] [blame] | 2545 | if (map__load(map, NULL) < 0) |
| 2546 | return 0; |
| 2547 | |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2548 | map__for_each_symbol(map, sym, tmp) { |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2549 | if (strglobmatch(sym->name, name)) { |
Masami Hiramatsu | 4c85935 | 2015-05-08 10:03:35 +0900 | [diff] [blame] | 2550 | found++; |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2551 | if (syms && found < probe_conf.max_probes) |
| 2552 | syms[found - 1] = sym; |
| 2553 | } |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2554 | } |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2555 | |
| 2556 | return found; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | #define strdup_or_goto(str, label) \ |
| 2560 | ({ char *__p = strdup(str); if (!__p) goto label; __p; }) |
| 2561 | |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 2562 | void __weak arch__fix_tev_from_maps(struct perf_probe_event *pev __maybe_unused, |
| 2563 | struct probe_trace_event *tev __maybe_unused, |
| 2564 | struct map *map __maybe_unused) { } |
| 2565 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | * Find probe function addresses from map. |
| 2568 | * Return an error or the number of found probe_trace_event |
| 2569 | */ |
| 2570 | static int find_probe_trace_events_from_map(struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2571 | struct probe_trace_event **tevs) |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2572 | { |
| 2573 | struct map *map = NULL; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2574 | struct ref_reloc_sym *reloc_sym = NULL; |
| 2575 | struct symbol *sym; |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2576 | struct symbol **syms = NULL; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2577 | struct probe_trace_event *tev; |
| 2578 | struct perf_probe_point *pp = &pev->point; |
| 2579 | struct probe_trace_point *tp; |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2580 | int num_matched_functions; |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2581 | int ret, i, j, skipped = 0; |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2582 | |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 2583 | map = get_target_map(pev->target, pev->uprobes); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2584 | if (!map) { |
| 2585 | ret = -EINVAL; |
| 2586 | goto out; |
| 2587 | } |
| 2588 | |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2589 | syms = malloc(sizeof(struct symbol *) * probe_conf.max_probes); |
| 2590 | if (!syms) { |
| 2591 | ret = -ENOMEM; |
| 2592 | goto out; |
| 2593 | } |
| 2594 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2595 | /* |
| 2596 | * Load matched symbols: Since the different local symbols may have |
| 2597 | * same name but different addresses, this lists all the symbols. |
| 2598 | */ |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2599 | num_matched_functions = find_probe_functions(map, pp->function, syms); |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2600 | if (num_matched_functions == 0) { |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2601 | pr_err("Failed to find symbol %s in %s\n", pp->function, |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 2602 | pev->target ? : "kernel"); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2603 | ret = -ENOENT; |
| 2604 | goto out; |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2605 | } else if (num_matched_functions > probe_conf.max_probes) { |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2606 | pr_err("Too many functions matched in %s\n", |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 2607 | pev->target ? : "kernel"); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2608 | ret = -E2BIG; |
| 2609 | goto out; |
| 2610 | } |
| 2611 | |
Namhyung Kim | 25dd917 | 2015-01-14 20:18:08 +0900 | [diff] [blame] | 2612 | if (!pev->uprobes && !pp->retprobe) { |
He Kuang | 0560a0c | 2015-03-20 09:56:56 +0800 | [diff] [blame] | 2613 | reloc_sym = kernel_get_ref_reloc_sym(); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2614 | if (!reloc_sym) { |
| 2615 | pr_warning("Relocated base symbol is not found!\n"); |
| 2616 | ret = -EINVAL; |
| 2617 | goto out; |
| 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | /* Setup result trace-probe-events */ |
| 2622 | *tevs = zalloc(sizeof(*tev) * num_matched_functions); |
| 2623 | if (!*tevs) { |
| 2624 | ret = -ENOMEM; |
| 2625 | goto out; |
| 2626 | } |
| 2627 | |
| 2628 | ret = 0; |
Namhyung Kim | 564c62a | 2015-01-14 20:18:07 +0900 | [diff] [blame] | 2629 | |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2630 | for (j = 0; j < num_matched_functions; j++) { |
| 2631 | sym = syms[j]; |
| 2632 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2633 | tev = (*tevs) + ret; |
| 2634 | tp = &tev->point; |
| 2635 | if (ret == num_matched_functions) { |
| 2636 | pr_warning("Too many symbols are listed. Skip it.\n"); |
| 2637 | break; |
| 2638 | } |
| 2639 | ret++; |
| 2640 | |
| 2641 | if (pp->offset > sym->end - sym->start) { |
| 2642 | pr_warning("Offset %ld is bigger than the size of %s\n", |
| 2643 | pp->offset, sym->name); |
| 2644 | ret = -ENOENT; |
| 2645 | goto err_out; |
| 2646 | } |
| 2647 | /* Add one probe point */ |
| 2648 | tp->address = map->unmap_ip(map, sym->start) + pp->offset; |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2649 | /* If we found a wrong one, mark it by NULL symbol */ |
| 2650 | if (!pev->uprobes && |
| 2651 | kprobe_warn_out_range(sym->name, tp->address)) { |
| 2652 | tp->symbol = NULL; /* Skip it */ |
| 2653 | skipped++; |
| 2654 | } else if (reloc_sym) { |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2655 | tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out); |
| 2656 | tp->offset = tp->address - reloc_sym->addr; |
| 2657 | } else { |
| 2658 | tp->symbol = strdup_or_goto(sym->name, nomem_out); |
| 2659 | tp->offset = pp->offset; |
| 2660 | } |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2661 | tp->realname = strdup_or_goto(sym->name, nomem_out); |
| 2662 | |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2663 | tp->retprobe = pp->retprobe; |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 2664 | if (pev->target) |
| 2665 | tev->point.module = strdup_or_goto(pev->target, |
| 2666 | nomem_out); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2667 | tev->uprobes = pev->uprobes; |
| 2668 | tev->nargs = pev->nargs; |
| 2669 | if (tev->nargs) { |
| 2670 | tev->args = zalloc(sizeof(struct probe_trace_arg) * |
| 2671 | tev->nargs); |
| 2672 | if (tev->args == NULL) |
| 2673 | goto nomem_out; |
| 2674 | } |
| 2675 | for (i = 0; i < tev->nargs; i++) { |
| 2676 | if (pev->args[i].name) |
| 2677 | tev->args[i].name = |
| 2678 | strdup_or_goto(pev->args[i].name, |
| 2679 | nomem_out); |
| 2680 | |
| 2681 | tev->args[i].value = strdup_or_goto(pev->args[i].var, |
| 2682 | nomem_out); |
| 2683 | if (pev->args[i].type) |
| 2684 | tev->args[i].type = |
| 2685 | strdup_or_goto(pev->args[i].type, |
| 2686 | nomem_out); |
| 2687 | } |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 2688 | arch__fix_tev_from_maps(pev, tev, map); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2689 | } |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2690 | if (ret == skipped) { |
| 2691 | ret = -ENOENT; |
| 2692 | goto err_out; |
| 2693 | } |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2694 | |
| 2695 | out: |
Masami Hiramatsu | 9b118ac | 2015-03-06 16:31:20 +0900 | [diff] [blame] | 2696 | put_target_map(map, pev->uprobes); |
Wang Nan | 6bb536c | 2015-05-29 09:45:47 +0000 | [diff] [blame] | 2697 | free(syms); |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2698 | return ret; |
| 2699 | |
| 2700 | nomem_out: |
| 2701 | ret = -ENOMEM; |
| 2702 | err_out: |
| 2703 | clear_probe_trace_events(*tevs, num_matched_functions); |
| 2704 | zfree(tevs); |
| 2705 | goto out; |
| 2706 | } |
| 2707 | |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 2708 | bool __weak arch__prefers_symtab(void) { return false; } |
| 2709 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2710 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2711 | struct probe_trace_event **tevs) |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 2712 | { |
Masami Hiramatsu | eb948e5 | 2014-02-06 05:32:25 +0000 | [diff] [blame] | 2713 | int ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2714 | |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 2715 | if (pev->uprobes && !pev->group) { |
| 2716 | /* Replace group name if not given */ |
Masami Hiramatsu | 4422552 | 2015-05-08 10:03:28 +0900 | [diff] [blame] | 2717 | ret = convert_exec_to_group(pev->target, &pev->group); |
Masami Hiramatsu | fb7345b | 2013-12-26 05:41:53 +0000 | [diff] [blame] | 2718 | if (ret != 0) { |
| 2719 | pr_warning("Failed to make a group name.\n"); |
| 2720 | return ret; |
| 2721 | } |
| 2722 | } |
| 2723 | |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 2724 | if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) { |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2725 | ret = find_probe_trace_events_from_map(pev, tevs); |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 2726 | if (ret > 0) |
| 2727 | return ret; /* Found in symbol table */ |
| 2728 | } |
| 2729 | |
Masami Hiramatsu | 4b4da7f | 2010-03-22 13:10:26 -0300 | [diff] [blame] | 2730 | /* Convert perf_probe_event with debuginfo */ |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2731 | ret = try_to_find_probe_trace_events(pev, tevs); |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 2732 | if (ret != 0) |
Masami Hiramatsu | 190b57f | 2011-06-27 16:27:45 +0900 | [diff] [blame] | 2733 | return ret; /* Found in debuginfo or got an error */ |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 2734 | |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2735 | return find_probe_trace_events_from_map(pev, tevs); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | struct __event_package { |
| 2739 | struct perf_probe_event *pev; |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2740 | struct probe_trace_event *tevs; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2741 | int ntevs; |
| 2742 | }; |
| 2743 | |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2744 | int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2745 | { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2746 | int i, j, ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2747 | struct __event_package *pkgs; |
| 2748 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2749 | ret = 0; |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 2750 | pkgs = zalloc(sizeof(struct __event_package) * npevs); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2751 | |
Masami Hiramatsu | e334016f1 | 2010-04-12 13:17:49 -0400 | [diff] [blame] | 2752 | if (pkgs == NULL) |
| 2753 | return -ENOMEM; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2754 | |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 2755 | ret = init_symbol_maps(pevs->uprobes); |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 2756 | if (ret < 0) { |
| 2757 | free(pkgs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2758 | return ret; |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 2759 | } |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2760 | |
| 2761 | /* Loop 1: convert all events */ |
| 2762 | for (i = 0; i < npevs; i++) { |
| 2763 | pkgs[i].pev = &pevs[i]; |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2764 | /* Init kprobe blacklist if needed */ |
| 2765 | if (!pkgs[i].pev->uprobes) |
| 2766 | kprobe_blacklist__init(); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2767 | /* Convert with or without debuginfo */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2768 | ret = convert_to_probe_trace_events(pkgs[i].pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2769 | &pkgs[i].tevs); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2770 | if (ret < 0) |
| 2771 | goto end; |
| 2772 | pkgs[i].ntevs = ret; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2773 | } |
Masami Hiramatsu | b031220 | 2015-06-16 20:50:55 +0900 | [diff] [blame^] | 2774 | /* This just release blacklist only if allocated */ |
| 2775 | kprobe_blacklist__release(); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2776 | |
| 2777 | /* Loop 2: add all events */ |
Arnaldo Carvalho de Melo | 8635bf6 | 2011-02-22 06:56:18 -0300 | [diff] [blame] | 2778 | for (i = 0; i < npevs; i++) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2779 | ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 2780 | pkgs[i].ntevs, |
| 2781 | probe_conf.force_add); |
Arnaldo Carvalho de Melo | fbee632 | 2011-02-21 13:23:57 -0300 | [diff] [blame] | 2782 | if (ret < 0) |
| 2783 | break; |
| 2784 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2785 | end: |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 2786 | /* Loop 3: cleanup and free trace events */ |
| 2787 | for (i = 0; i < npevs; i++) { |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2788 | for (j = 0; j < pkgs[i].ntevs; j++) |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2789 | clear_probe_trace_event(&pkgs[i].tevs[j]); |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 2790 | zfree(&pkgs[i].tevs); |
Masami Hiramatsu | 449e5b2 | 2010-08-03 11:11:40 +0900 | [diff] [blame] | 2791 | } |
| 2792 | free(pkgs); |
Masami Hiramatsu | ee45b6c | 2014-02-06 05:32:04 +0000 | [diff] [blame] | 2793 | exit_symbol_maps(); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2794 | |
| 2795 | return ret; |
Masami Hiramatsu | e0faa8d | 2010-03-16 18:05:37 -0400 | [diff] [blame] | 2796 | } |
| 2797 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2798 | static int __del_trace_probe_event(int fd, struct str_node *ent) |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2799 | { |
| 2800 | char *p; |
| 2801 | char buf[128]; |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2802 | int ret; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2803 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2804 | /* Convert from perf-probe event to trace-probe event */ |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2805 | ret = e_snprintf(buf, 128, "-:%s", ent->s); |
| 2806 | if (ret < 0) |
| 2807 | goto error; |
| 2808 | |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2809 | p = strchr(buf + 2, ':'); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2810 | if (!p) { |
| 2811 | pr_debug("Internal error: %s should have ':' but not.\n", |
| 2812 | ent->s); |
| 2813 | ret = -ENOTSUP; |
| 2814 | goto error; |
| 2815 | } |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2816 | *p = '/'; |
| 2817 | |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 2818 | pr_debug("Writing event: %s\n", buf); |
| 2819 | ret = write(fd, buf, strlen(buf)); |
Masami Hiramatsu | 44a5604 | 2011-10-04 19:45:04 +0900 | [diff] [blame] | 2820 | if (ret < 0) { |
| 2821 | ret = -errno; |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2822 | goto error; |
Masami Hiramatsu | 44a5604 | 2011-10-04 19:45:04 +0900 | [diff] [blame] | 2823 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2824 | |
Masami Hiramatsu | 5e17b28 | 2014-10-27 16:31:31 -0400 | [diff] [blame] | 2825 | pr_info("Removed event: %s\n", ent->s); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2826 | return 0; |
| 2827 | error: |
Masami Hiramatsu | 5f03cba | 2014-08-14 02:22:34 +0000 | [diff] [blame] | 2828 | pr_warning("Failed to delete event: %s\n", |
| 2829 | strerror_r(-ret, buf, sizeof(buf))); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2830 | return ret; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2831 | } |
| 2832 | |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2833 | static int del_trace_probe_events(int fd, struct strfilter *filter, |
| 2834 | struct strlist *namelist) |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2835 | { |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2836 | struct str_node *ent; |
| 2837 | const char *p; |
Masami Hiramatsu | 6dbe31f | 2015-04-23 22:46:14 +0900 | [diff] [blame] | 2838 | int ret = -ENOENT; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2839 | |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2840 | if (!namelist) |
| 2841 | return -ENOENT; |
| 2842 | |
| 2843 | strlist__for_each(ent, namelist) { |
| 2844 | p = strchr(ent->s, ':'); |
| 2845 | if ((p && strfilter__compare(filter, p + 1)) || |
| 2846 | strfilter__compare(filter, ent->s)) { |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 2847 | ret = __del_trace_probe_event(fd, ent); |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2848 | if (ret < 0) |
| 2849 | break; |
Masami Hiramatsu | bbbb521 | 2009-12-15 10:32:10 -0500 | [diff] [blame] | 2850 | } |
| 2851 | } |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2852 | |
| 2853 | return ret; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2854 | } |
| 2855 | |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2856 | int del_perf_probe_events(struct strfilter *filter) |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2857 | { |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2858 | int ret, ret2, ufd = -1, kfd = -1; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2859 | struct strlist *namelist = NULL, *unamelist = NULL; |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2860 | char *str = strfilter__string(filter); |
| 2861 | |
| 2862 | if (!str) |
| 2863 | return -EINVAL; |
| 2864 | |
| 2865 | pr_debug("Delete filter: \'%s\'\n", str); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2866 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2867 | /* Get current event names */ |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2868 | kfd = open_kprobe_events(true); |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 2869 | if (kfd >= 0) |
| 2870 | namelist = get_probe_trace_event_names(kfd, true); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2871 | |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2872 | ufd = open_uprobe_events(true); |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 2873 | if (ufd >= 0) |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2874 | unamelist = get_probe_trace_event_names(ufd, true); |
| 2875 | |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 2876 | if (kfd < 0 && ufd < 0) { |
| 2877 | print_both_open_warning(kfd, ufd); |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2878 | ret = kfd; |
Masami Hiramatsu | 467ec08 | 2014-08-13 16:12:50 +0000 | [diff] [blame] | 2879 | goto error; |
| 2880 | } |
| 2881 | |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2882 | ret = del_trace_probe_events(kfd, filter, namelist); |
| 2883 | if (ret < 0 && ret != -ENOENT) |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2884 | goto error; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2885 | |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2886 | ret2 = del_trace_probe_events(ufd, filter, unamelist); |
Masami Hiramatsu | dddc7ee | 2015-05-27 17:37:25 +0900 | [diff] [blame] | 2887 | if (ret2 < 0 && ret2 != -ENOENT) { |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2888 | ret = ret2; |
Masami Hiramatsu | dddc7ee | 2015-05-27 17:37:25 +0900 | [diff] [blame] | 2889 | goto error; |
| 2890 | } |
| 2891 | if (ret == -ENOENT && ret2 == -ENOENT) |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2892 | pr_debug("\"%s\" does not hit any event.\n", str); |
| 2893 | /* Note that this is silently ignored */ |
Masami Hiramatsu | dddc7ee | 2015-05-27 17:37:25 +0900 | [diff] [blame] | 2894 | ret = 0; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2895 | |
| 2896 | error: |
| 2897 | if (kfd >= 0) { |
Srikar Dronamraju | a23c4dc | 2012-05-31 17:16:43 +0530 | [diff] [blame] | 2898 | strlist__delete(namelist); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2899 | close(kfd); |
| 2900 | } |
| 2901 | |
| 2902 | if (ufd >= 0) { |
Srikar Dronamraju | a23c4dc | 2012-05-31 17:16:43 +0530 | [diff] [blame] | 2903 | strlist__delete(unamelist); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2904 | close(ufd); |
| 2905 | } |
Masami Hiramatsu | 307a464 | 2015-05-05 11:29:48 +0900 | [diff] [blame] | 2906 | free(str); |
Masami Hiramatsu | 146a143 | 2010-04-12 13:17:42 -0400 | [diff] [blame] | 2907 | |
| 2908 | return ret; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2909 | } |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2910 | |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2911 | /* TODO: don't use a global variable for filter ... */ |
| 2912 | static struct strfilter *available_func_filter; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 2913 | |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2914 | /* |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2915 | * If a symbol corresponds to a function with global binding and |
| 2916 | * matches filter return 0. For all others return 1. |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2917 | */ |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2918 | static int filter_available_functions(struct map *map __maybe_unused, |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2919 | struct symbol *sym) |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2920 | { |
Namhyung Kim | e578da3 | 2015-03-06 16:31:29 +0900 | [diff] [blame] | 2921 | if (strfilter__compare(available_func_filter, sym->name)) |
Masami Hiramatsu | 3c42258 | 2011-01-20 23:15:45 +0900 | [diff] [blame] | 2922 | return 0; |
| 2923 | return 1; |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2924 | } |
| 2925 | |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2926 | int show_available_funcs(const char *target, struct strfilter *_filter, |
| 2927 | bool user) |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2928 | { |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2929 | struct map *map; |
| 2930 | int ret; |
| 2931 | |
| 2932 | ret = init_symbol_maps(user); |
| 2933 | if (ret < 0) |
| 2934 | return ret; |
| 2935 | |
| 2936 | /* Get a symbol map */ |
| 2937 | if (user) |
| 2938 | map = dso__new_map(target); |
| 2939 | else |
| 2940 | map = kernel_get_module_map(target); |
| 2941 | if (!map) { |
| 2942 | pr_err("Failed to get a map for %s\n", (target) ? : "kernel"); |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2943 | return -EINVAL; |
| 2944 | } |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2945 | |
| 2946 | /* Load symbols with given filter */ |
| 2947 | available_func_filter = _filter; |
| 2948 | if (map__load(map, filter_available_functions)) { |
| 2949 | pr_err("Failed to load symbols in %s\n", (target) ? : "kernel"); |
| 2950 | goto end; |
| 2951 | } |
Masami Hiramatsu | e80711c | 2011-01-13 21:46:11 +0900 | [diff] [blame] | 2952 | if (!dso__sorted_by_name(map->dso, map->type)) |
| 2953 | dso__sort_by_name(map->dso, map->type); |
| 2954 | |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2955 | /* Show all (filtered) symbols */ |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2956 | setup_pager(); |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2957 | dso__fprintf_symbols_by_name(map->dso, map->type, stdout); |
| 2958 | end: |
| 2959 | if (user) { |
Arnaldo Carvalho de Melo | 84c2caf | 2015-05-25 16:59:56 -0300 | [diff] [blame] | 2960 | map__put(map); |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2961 | } |
| 2962 | exit_symbol_maps(); |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2963 | |
Masami Hiramatsu | 2df5863 | 2014-02-06 05:32:11 +0000 | [diff] [blame] | 2964 | return ret; |
Srikar Dronamraju | 225466f | 2012-04-16 17:39:09 +0530 | [diff] [blame] | 2965 | } |
| 2966 | |