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