Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * builtin-probe.c |
| 3 | * |
| 4 | * Builtin probe command: Set up probe events by C expression |
| 5 | * |
| 6 | * Written by Masami Hiramatsu <mhiramat@redhat.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
| 22 | */ |
| 23 | #define _GNU_SOURCE |
| 24 | #include <sys/utsname.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <errno.h> |
| 29 | #include <stdio.h> |
| 30 | #include <unistd.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | #undef _GNU_SOURCE |
| 35 | #include "perf.h" |
| 36 | #include "builtin.h" |
| 37 | #include "util/util.h" |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 38 | #include "util/strlist.h" |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 39 | #include "util/event.h" |
| 40 | #include "util/debug.h" |
Masami Hiramatsu | 96c9661 | 2009-12-16 17:24:00 -0500 | [diff] [blame] | 41 | #include "util/debugfs.h" |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 42 | #include "util/symbol.h" |
| 43 | #include "util/thread.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 44 | #include "util/parse-options.h" |
| 45 | #include "util/parse-events.h" /* For debugfs_path */ |
| 46 | #include "util/probe-finder.h" |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 47 | #include "util/probe-event.h" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 48 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 49 | #define MAX_PATH_LEN 256 |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 50 | |
| 51 | /* Session management structure */ |
| 52 | static struct { |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 53 | bool need_dwarf; |
| 54 | bool list_events; |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 55 | bool force_add; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 56 | bool show_lines; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 57 | int nr_probe; |
| 58 | struct probe_point probes[MAX_PROBES]; |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 59 | struct strlist *dellist; |
Arnaldo Carvalho de Melo | 8ad94c6 | 2010-02-03 16:52:03 -0200 | [diff] [blame] | 60 | struct map_groups kmap_groups; |
| 61 | struct map *kmaps[MAP__NR_TYPES]; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 62 | struct line_range line_range; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 63 | } session; |
| 64 | |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 65 | |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 66 | /* Parse an event definition. Note that any error must die. */ |
| 67 | static void parse_probe_event(const char *str) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 68 | { |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 69 | struct probe_point *pp = &session.probes[session.nr_probe]; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 70 | |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 71 | pr_debug("probe-definition(%d): %s\n", session.nr_probe, str); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 72 | if (++session.nr_probe == MAX_PROBES) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 73 | die("Too many probes (> %d) are specified.", MAX_PROBES); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 74 | |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 75 | /* Parse perf-probe event into probe_point */ |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 76 | parse_perf_probe_event(str, pp, &session.need_dwarf); |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 77 | |
Arnaldo Carvalho de Melo | b7cb10e | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 78 | pr_debug("%d arguments\n", pp->nr_args); |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 81 | static void parse_probe_event_argv(int argc, const char **argv) |
| 82 | { |
| 83 | int i, len; |
| 84 | char *buf; |
| 85 | |
| 86 | /* Bind up rest arguments */ |
| 87 | len = 0; |
| 88 | for (i = 0; i < argc; i++) |
| 89 | len += strlen(argv[i]) + 1; |
| 90 | buf = zalloc(len + 1); |
| 91 | if (!buf) |
| 92 | die("Failed to allocate memory for binding arguments."); |
| 93 | len = 0; |
| 94 | for (i = 0; i < argc; i++) |
| 95 | len += sprintf(&buf[len], "%s ", argv[i]); |
| 96 | parse_probe_event(buf); |
| 97 | free(buf); |
| 98 | } |
| 99 | |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 100 | static int opt_add_probe_event(const struct option *opt __used, |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 101 | const char *str, int unset __used) |
| 102 | { |
| 103 | if (str) |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 104 | parse_probe_event(str); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 108 | static int opt_del_probe_event(const struct option *opt __used, |
| 109 | const char *str, int unset __used) |
| 110 | { |
| 111 | if (str) { |
| 112 | if (!session.dellist) |
| 113 | session.dellist = strlist__new(true, NULL); |
| 114 | strlist__add(session.dellist, str); |
| 115 | } |
| 116 | return 0; |
| 117 | } |
| 118 | |
Masami Hiramatsu | 62bdc1b | 2009-12-15 10:32:40 -0500 | [diff] [blame] | 119 | /* Currently just checking function name from symbol map */ |
| 120 | static void evaluate_probe_point(struct probe_point *pp) |
| 121 | { |
| 122 | struct symbol *sym; |
Arnaldo Carvalho de Melo | 8ad94c6 | 2010-02-03 16:52:03 -0200 | [diff] [blame] | 123 | sym = map__find_symbol_by_name(session.kmaps[MAP__FUNCTION], |
| 124 | pp->function, NULL); |
Masami Hiramatsu | 62bdc1b | 2009-12-15 10:32:40 -0500 | [diff] [blame] | 125 | if (!sym) |
| 126 | die("Kernel symbol \'%s\' not found - probe not added.", |
| 127 | pp->function); |
| 128 | } |
| 129 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 130 | #ifndef NO_DWARF_SUPPORT |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 131 | static int open_vmlinux(void) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 132 | { |
Arnaldo Carvalho de Melo | 8ad94c6 | 2010-02-03 16:52:03 -0200 | [diff] [blame] | 133 | if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) { |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 134 | pr_debug("Failed to load kernel map.\n"); |
| 135 | return -EINVAL; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 136 | } |
Arnaldo Carvalho de Melo | 8ad94c6 | 2010-02-03 16:52:03 -0200 | [diff] [blame] | 137 | pr_debug("Try to open %s\n", |
| 138 | session.kmaps[MAP__FUNCTION]->dso->long_name); |
| 139 | return open(session.kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 140 | } |
Hitoshi Mitake | 0eda738 | 2010-01-16 21:31:16 +0900 | [diff] [blame] | 141 | |
| 142 | static int opt_show_lines(const struct option *opt __used, |
| 143 | const char *str, int unset __used) |
| 144 | { |
| 145 | if (str) |
| 146 | parse_line_range_desc(str, &session.line_range); |
| 147 | INIT_LIST_HEAD(&session.line_range.line_list); |
| 148 | session.show_lines = true; |
| 149 | return 0; |
| 150 | } |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 151 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 152 | |
| 153 | static const char * const probe_usage[] = { |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 154 | "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]", |
| 155 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 156 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 157 | "perf probe --list", |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 158 | #ifndef NO_DWARF_SUPPORT |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 159 | "perf probe --line 'LINEDESC'", |
Masami Hiramatsu | f3ab481 | 2010-02-25 08:35:12 -0500 | [diff] [blame] | 160 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 161 | NULL |
| 162 | }; |
| 163 | |
| 164 | static const struct option options[] = { |
Masami Hiramatsu | 89c69c0 | 2009-10-16 20:08:10 -0400 | [diff] [blame] | 165 | OPT_BOOLEAN('v', "verbose", &verbose, |
| 166 | "be more verbose (show parsed arguments, etc)"), |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 167 | #ifndef NO_DWARF_SUPPORT |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 168 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 169 | "file", "vmlinux pathname"), |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 170 | #endif |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 171 | OPT_BOOLEAN('l', "list", &session.list_events, |
| 172 | "list up current probe events"), |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 173 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", |
| 174 | opt_del_probe_event), |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 175 | OPT_CALLBACK('a', "add", NULL, |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 176 | #ifdef NO_DWARF_SUPPORT |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 177 | "[EVENT=]FUNC[+OFF|%return] [ARG ...]", |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 178 | #else |
Masami Hiramatsu | 32cb0dd | 2010-03-03 22:38:43 -0500 | [diff] [blame] | 179 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 180 | " [ARG ...]", |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 181 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 182 | "probe point definition, where\n" |
Masami Hiramatsu | af663d7 | 2009-12-15 10:32:18 -0500 | [diff] [blame] | 183 | "\t\tGROUP:\tGroup name (optional)\n" |
| 184 | "\t\tEVENT:\tEvent name\n" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 185 | "\t\tFUNC:\tFunction name\n" |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 186 | "\t\tOFF:\tOffset from function entry (in byte)\n" |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 187 | "\t\t%return:\tPut the probe at function return\n" |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 188 | #ifdef NO_DWARF_SUPPORT |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 189 | "\t\tARG:\tProbe argument (only \n" |
| 190 | #else |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 191 | "\t\tSRC:\tSource code path\n" |
Masami Hiramatsu | 2a9c8c3 | 2010-02-25 08:36:12 -0500 | [diff] [blame] | 192 | "\t\tRL:\tRelative line number from function entry.\n" |
| 193 | "\t\tAL:\tAbsolute line number in file.\n" |
| 194 | "\t\tPT:\tLazy expression of line code.\n" |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 195 | "\t\tARG:\tProbe argument (local variable name or\n" |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 196 | #endif |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 197 | "\t\t\tkprobe-tracer argument format.)\n", |
Masami Hiramatsu | 253977b | 2009-10-27 16:43:10 -0400 | [diff] [blame] | 198 | opt_add_probe_event), |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 199 | OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events" |
| 200 | " with existing name"), |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 201 | #ifndef NO_DWARF_SUPPORT |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 202 | OPT_CALLBACK('L', "line", NULL, |
| 203 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", |
| 204 | "Show source code lines.", opt_show_lines), |
| 205 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 206 | OPT_END() |
| 207 | }; |
| 208 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 209 | /* Initialize symbol maps for vmlinux */ |
| 210 | static void init_vmlinux(void) |
| 211 | { |
| 212 | symbol_conf.sort_by_name = true; |
| 213 | if (symbol_conf.vmlinux_name == NULL) |
| 214 | symbol_conf.try_vmlinux_path = true; |
| 215 | else |
| 216 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); |
| 217 | if (symbol__init() < 0) |
| 218 | die("Failed to init symbol map."); |
Arnaldo Carvalho de Melo | 8ad94c6 | 2010-02-03 16:52:03 -0200 | [diff] [blame] | 219 | |
| 220 | map_groups__init(&session.kmap_groups); |
| 221 | if (map_groups__create_kernel_maps(&session.kmap_groups, |
| 222 | session.kmaps) < 0) |
| 223 | die("Failed to create kernel maps."); |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 226 | int cmd_probe(int argc, const char **argv, const char *prefix __used) |
| 227 | { |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 228 | int i, ret; |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 229 | #ifndef NO_DWARF_SUPPORT |
Xiao Guangrong | bdad0db | 2009-12-02 16:08:41 +0800 | [diff] [blame] | 230 | int fd; |
| 231 | #endif |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 232 | struct probe_point *pp; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 233 | |
| 234 | argc = parse_options(argc, argv, options, probe_usage, |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 235 | PARSE_OPT_STOP_AT_NON_OPTION); |
Masami Hiramatsu | ce11a60 | 2009-12-15 10:31:28 -0500 | [diff] [blame] | 236 | if (argc > 0) { |
| 237 | if (strcmp(argv[0], "-") == 0) { |
| 238 | pr_warning(" Error: '-' is not supported.\n"); |
| 239 | usage_with_options(probe_usage, options); |
| 240 | } |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 241 | parse_probe_event_argv(argc, argv); |
Masami Hiramatsu | ce11a60 | 2009-12-15 10:31:28 -0500 | [diff] [blame] | 242 | } |
Masami Hiramatsu | 46ab492 | 2009-10-27 16:43:02 -0400 | [diff] [blame] | 243 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 244 | if ((!session.nr_probe && !session.dellist && !session.list_events && |
| 245 | !session.show_lines)) |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 246 | usage_with_options(probe_usage, options); |
| 247 | |
Masami Hiramatsu | 96c9661 | 2009-12-16 17:24:00 -0500 | [diff] [blame] | 248 | if (debugfs_valid_mountpoint(debugfs_path) < 0) |
| 249 | die("Failed to find debugfs path."); |
| 250 | |
Masami Hiramatsu | fac13fd | 2009-12-15 10:31:14 -0500 | [diff] [blame] | 251 | if (session.list_events) { |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 252 | if (session.nr_probe != 0 || session.dellist) { |
| 253 | pr_warning(" Error: Don't use --list with" |
| 254 | " --add/--del.\n"); |
| 255 | usage_with_options(probe_usage, options); |
| 256 | } |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 257 | if (session.show_lines) { |
| 258 | pr_warning(" Error: Don't use --list with --line.\n"); |
| 259 | usage_with_options(probe_usage, options); |
| 260 | } |
Masami Hiramatsu | 4de189f | 2009-11-30 19:20:17 -0500 | [diff] [blame] | 261 | show_perf_probe_events(); |
| 262 | return 0; |
| 263 | } |
| 264 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 265 | #ifndef NO_DWARF_SUPPORT |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 266 | if (session.show_lines) { |
| 267 | if (session.nr_probe != 0 || session.dellist) { |
| 268 | pr_warning(" Error: Don't use --line with" |
| 269 | " --add/--del.\n"); |
| 270 | usage_with_options(probe_usage, options); |
| 271 | } |
| 272 | init_vmlinux(); |
| 273 | fd = open_vmlinux(); |
| 274 | if (fd < 0) |
| 275 | die("Could not open debuginfo file."); |
| 276 | ret = find_line_range(fd, &session.line_range); |
| 277 | if (ret <= 0) |
| 278 | die("Source line is not found.\n"); |
| 279 | close(fd); |
| 280 | show_line_range(&session.line_range); |
| 281 | return 0; |
| 282 | } |
| 283 | #endif |
| 284 | |
Masami Hiramatsu | fa28244 | 2009-12-08 17:03:23 -0500 | [diff] [blame] | 285 | if (session.dellist) { |
| 286 | del_trace_kprobe_events(session.dellist); |
| 287 | strlist__delete(session.dellist); |
| 288 | if (session.nr_probe == 0) |
| 289 | return 0; |
| 290 | } |
| 291 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 292 | /* Add probes */ |
| 293 | init_vmlinux(); |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 294 | |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 295 | if (session.need_dwarf) |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 296 | #ifdef NO_DWARF_SUPPORT |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 297 | die("Debuginfo-analysis is not supported"); |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 298 | #else /* !NO_DWARF_SUPPORT */ |
Masami Hiramatsu | f41b1e4 | 2009-11-30 19:19:27 -0500 | [diff] [blame] | 299 | pr_debug("Some probes require debuginfo.\n"); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 300 | |
Masami Hiramatsu | a128168 | 2009-12-15 10:32:33 -0500 | [diff] [blame] | 301 | fd = open_vmlinux(); |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 302 | if (fd < 0) { |
| 303 | if (session.need_dwarf) |
Masami Hiramatsu | f984f03 | 2009-12-08 17:03:09 -0500 | [diff] [blame] | 304 | die("Could not open debuginfo file."); |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 305 | |
Masami Hiramatsu | d3a2dbf | 2009-12-07 12:00:59 -0500 | [diff] [blame] | 306 | pr_debug("Could not open vmlinux/module file." |
| 307 | " Try to use symbols.\n"); |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 308 | goto end_dwarf; |
| 309 | } |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 310 | |
| 311 | /* Searching probe points */ |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 312 | for (i = 0; i < session.nr_probe; i++) { |
| 313 | pp = &session.probes[i]; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 314 | if (pp->found) |
| 315 | continue; |
| 316 | |
| 317 | lseek(fd, SEEK_SET, 0); |
Masami Hiramatsu | 81cb8aa | 2010-02-25 08:35:34 -0500 | [diff] [blame] | 318 | ret = find_probe_point(fd, pp); |
Masami Hiramatsu | 411edfe | 2009-12-15 10:31:35 -0500 | [diff] [blame] | 319 | if (ret > 0) |
| 320 | continue; |
Masami Hiramatsu | 7ef17aa | 2009-12-15 10:32:47 -0500 | [diff] [blame] | 321 | if (ret == 0) { /* No error but failed to find probe point. */ |
| 322 | synthesize_perf_probe_point(pp); |
| 323 | die("Probe point '%s' not found. - probe not added.", |
| 324 | pp->probes[0]); |
| 325 | } |
Masami Hiramatsu | 411edfe | 2009-12-15 10:31:35 -0500 | [diff] [blame] | 326 | /* Error path */ |
| 327 | if (session.need_dwarf) { |
| 328 | if (ret == -ENOENT) |
| 329 | pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
| 330 | die("Could not analyze debuginfo."); |
| 331 | } |
| 332 | pr_debug("An error occurred in debuginfo analysis." |
| 333 | " Try to use symbols.\n"); |
| 334 | break; |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 335 | } |
| 336 | close(fd); |
| 337 | |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 338 | end_dwarf: |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 339 | #endif /* !NO_DWARF_SUPPORT */ |
Masami Hiramatsu | 23e8ec0 | 2009-10-07 18:28:30 -0400 | [diff] [blame] | 340 | |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 341 | /* Synthesize probes without dwarf */ |
Masami Hiramatsu | d1bde3f | 2009-12-08 17:02:54 -0500 | [diff] [blame] | 342 | for (i = 0; i < session.nr_probe; i++) { |
| 343 | pp = &session.probes[i]; |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 344 | if (pp->found) /* This probe is already found. */ |
| 345 | continue; |
| 346 | |
Masami Hiramatsu | 62bdc1b | 2009-12-15 10:32:40 -0500 | [diff] [blame] | 347 | evaluate_probe_point(pp); |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 348 | ret = synthesize_trace_kprobe_event(pp); |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 349 | if (ret == -E2BIG) |
Masami Hiramatsu | 50656ee | 2009-11-30 19:19:58 -0500 | [diff] [blame] | 350 | die("probe point definition becomes too long."); |
Masami Hiramatsu | a225a1d | 2009-11-03 19:12:30 -0500 | [diff] [blame] | 351 | else if (ret < 0) |
| 352 | die("Failed to synthesize a probe point."); |
| 353 | } |
| 354 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 355 | /* Settng up probe points */ |
Masami Hiramatsu | d761b08 | 2009-12-15 10:32:25 -0500 | [diff] [blame] | 356 | add_trace_kprobe_events(session.probes, session.nr_probe, |
| 357 | session.force_add); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |