aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2009-10-16 20:08:01 -0400
committerIngo Molnar <mingo@elte.hu>2009-10-17 03:54:00 -0400
commit074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb (patch)
tree485c1ac28a03ed0558eb443e1212eaf6ceee2c63
parent4c20194c2de151bca14224ae384b47abf7636a95 (diff)
perf: Use die() for error cases in perf-probe
Use die() for exiting perf-probe with errors. This replaces perror_exit(), msg_exit() and fprintf()+exit() with die(), and uses die() in semantic_error(). This also renames 'die' local variables to 'dw_die' for avoiding name confliction. Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20091017000801.16556.46866.stgit@dhcp-100-2-132.bos.redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--tools/perf/builtin-probe.c47
-rw-r--r--tools/perf/util/probe-finder.c55
2 files changed, 34 insertions, 68 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 73c883b715cc..a1467d12547a 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -49,6 +49,7 @@ const char *default_search_path[NR_SEARCH_PATH] = {
49 49
50#define MAX_PATH_LEN 256 50#define MAX_PATH_LEN 256
51#define MAX_PROBES 128 51#define MAX_PROBES 128
52#define MAX_PROBE_ARGS 128
52 53
53/* Session management structure */ 54/* Session management structure */
54static struct { 55static struct {
@@ -60,19 +61,7 @@ static struct {
60 char *events[MAX_PROBES]; 61 char *events[MAX_PROBES];
61} session; 62} session;
62 63
63static void semantic_error(const char *msg) 64#define semantic_error(msg ...) die("Semantic error :" msg)
64{
65 fprintf(stderr, "Semantic error: %s\n", msg);
66 exit(1);
67}
68
69static void perror_exit(const char *msg)
70{
71 perror(msg);
72 exit(1);
73}
74
75#define MAX_PROBE_ARGS 128
76 65
77static int parse_probepoint(const struct option *opt __used, 66static int parse_probepoint(const struct option *opt __used,
78 const char *str, int unset __used) 67 const char *str, int unset __used)
@@ -109,7 +98,7 @@ static int parse_probepoint(const struct option *opt __used,
109 /* Duplicate the argument */ 98 /* Duplicate the argument */
110 argv[argc] = strndup(s, str - s); 99 argv[argc] = strndup(s, str - s);
111 if (argv[argc] == NULL) 100 if (argv[argc] == NULL)
112 perror_exit("strndup"); 101 die("strndup");
113 if (++argc == MAX_PROBE_ARGS) 102 if (++argc == MAX_PROBE_ARGS)
114 semantic_error("Too many arguments"); 103 semantic_error("Too many arguments");
115 debug("argv[%d]=%s\n", argc, argv[argc - 1]); 104 debug("argv[%d]=%s\n", argc, argv[argc - 1]);
@@ -171,7 +160,7 @@ static int parse_probepoint(const struct option *opt __used,
171 if (pp->nr_args > 0) { 160 if (pp->nr_args > 0) {
172 pp->args = (char **)malloc(sizeof(char *) * pp->nr_args); 161 pp->args = (char **)malloc(sizeof(char *) * pp->nr_args);
173 if (!pp->args) 162 if (!pp->args)
174 perror_exit("malloc"); 163 die("malloc");
175 memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args); 164 memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args);
176 } 165 }
177 166
@@ -260,7 +249,7 @@ static int write_new_event(int fd, const char *buf)
260 printf("Adding new event: %s\n", buf); 249 printf("Adding new event: %s\n", buf);
261 ret = write(fd, buf, strlen(buf)); 250 ret = write(fd, buf, strlen(buf));
262 if (ret <= 0) 251 if (ret <= 0)
263 perror("Error: Failed to create event"); 252 die("failed to create event.");
264 253
265 return ret; 254 return ret;
266} 255}
@@ -273,7 +262,7 @@ static int synthesize_probepoint(struct probe_point *pp)
273 int i, len, ret; 262 int i, len, ret;
274 pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char)); 263 pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
275 if (!buf) 264 if (!buf)
276 perror_exit("calloc"); 265 die("calloc");
277 ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); 266 ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
278 if (ret <= 0 || ret >= MAX_CMDLEN) 267 if (ret <= 0 || ret >= MAX_CMDLEN)
279 goto error; 268 goto error;
@@ -322,10 +311,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
322 ret = synthesize_probepoint(&session.probes[j]); 311 ret = synthesize_probepoint(&session.probes[j]);
323 if (ret == -E2BIG) 312 if (ret == -E2BIG)
324 semantic_error("probe point is too long."); 313 semantic_error("probe point is too long.");
325 else if (ret < 0) { 314 else if (ret < 0)
326 perror("snprintf"); 315 die("snprintf");
327 return -1;
328 }
329 } 316 }
330 317
331#ifndef NO_LIBDWARF 318#ifndef NO_LIBDWARF
@@ -336,10 +323,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
336 fd = open(session.vmlinux, O_RDONLY); 323 fd = open(session.vmlinux, O_RDONLY);
337 else 324 else
338 fd = open_default_vmlinux(); 325 fd = open_default_vmlinux();
339 if (fd < 0) { 326 if (fd < 0)
340 perror("vmlinux/module file open"); 327 die("vmlinux/module file open");
341 return -1;
342 }
343 328
344 /* Searching probe points */ 329 /* Searching probe points */
345 for (j = 0; j < session.nr_probe; j++) { 330 for (j = 0; j < session.nr_probe; j++) {
@@ -349,10 +334,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
349 334
350 lseek(fd, SEEK_SET, 0); 335 lseek(fd, SEEK_SET, 0);
351 ret = find_probepoint(fd, pp); 336 ret = find_probepoint(fd, pp);
352 if (ret <= 0) { 337 if (ret <= 0)
353 fprintf(stderr, "Error: No probe point found.\n"); 338 die("No probe point found.\n");
354 return -1;
355 }
356 debug("probe event %s found\n", session.events[j]); 339 debug("probe event %s found\n", session.events[j]);
357 } 340 }
358 close(fd); 341 close(fd);
@@ -363,10 +346,8 @@ setup_probes:
363 /* Settng up probe points */ 346 /* Settng up probe points */
364 snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path); 347 snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path);
365 fd = open(buf, O_WRONLY, O_APPEND); 348 fd = open(buf, O_WRONLY, O_APPEND);
366 if (fd < 0) { 349 if (fd < 0)
367 perror("kprobe_events open"); 350 die("kprobe_events open");
368 return -1;
369 }
370 for (j = 0; j < session.nr_probe; j++) { 351 for (j = 0; j < session.nr_probe; j++) {
371 pp = &session.probes[j]; 352 pp = &session.probes[j];
372 if (pp->found == 1) { 353 if (pp->found == 1) {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index ec6f53f29e00..338fdb9e093d 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -31,6 +31,8 @@
31#include <string.h> 31#include <string.h>
32#include <stdarg.h> 32#include <stdarg.h>
33#include <ctype.h> 33#include <ctype.h>
34
35#include "util.h"
34#include "probe-finder.h" 36#include "probe-finder.h"
35 37
36 38
@@ -43,20 +45,6 @@ struct die_link {
43static Dwarf_Debug __dw_debug; 45static Dwarf_Debug __dw_debug;
44static Dwarf_Error __dw_error; 46static Dwarf_Error __dw_error;
45 47
46static void msg_exit(int ret, const char *fmt, ...)
47{
48 va_list ap;
49
50 va_start(ap, fmt);
51 fprintf(stderr, "Error: ");
52 vfprintf(stderr, fmt, ap);
53 va_end(ap);
54
55 fprintf(stderr, "\n");
56 exit(ret);
57}
58
59
60/* 48/*
61 * Generic dwarf analysis helpers 49 * Generic dwarf analysis helpers
62 */ 50 */
@@ -151,11 +139,11 @@ static Dwarf_Unsigned die_get_fileno(Dwarf_Die cu_die, const char *fname)
151} 139}
152 140
153/* Compare diename and tname */ 141/* Compare diename and tname */
154static int die_compare_name(Dwarf_Die die, const char *tname) 142static int die_compare_name(Dwarf_Die dw_die, const char *tname)
155{ 143{
156 char *name; 144 char *name;
157 int ret; 145 int ret;
158 ret = dwarf_diename(die, &name, &__dw_error); 146 ret = dwarf_diename(dw_die, &name, &__dw_error);
159 ERR_IF(ret == DW_DLV_ERROR); 147 ERR_IF(ret == DW_DLV_ERROR);
160 if (ret == DW_DLV_OK) { 148 if (ret == DW_DLV_OK) {
161 ret = strcmp(tname, name); 149 ret = strcmp(tname, name);
@@ -187,25 +175,25 @@ static int die_within_subprogram(Dwarf_Die sp_die, Dwarf_Addr addr,
187} 175}
188 176
189/* Check the die is inlined function */ 177/* Check the die is inlined function */
190static Dwarf_Bool die_inlined_subprogram(Dwarf_Die die) 178static Dwarf_Bool die_inlined_subprogram(Dwarf_Die dw_die)
191{ 179{
192 /* TODO: check strictly */ 180 /* TODO: check strictly */
193 Dwarf_Bool inl; 181 Dwarf_Bool inl;
194 int ret; 182 int ret;
195 183
196 ret = dwarf_hasattr(die, DW_AT_inline, &inl, &__dw_error); 184 ret = dwarf_hasattr(dw_die, DW_AT_inline, &inl, &__dw_error);
197 ERR_IF(ret == DW_DLV_ERROR); 185 ERR_IF(ret == DW_DLV_ERROR);
198 return inl; 186 return inl;
199} 187}
200 188
201/* Get the offset of abstruct_origin */ 189/* Get the offset of abstruct_origin */
202static Dwarf_Off die_get_abstract_origin(Dwarf_Die die) 190static Dwarf_Off die_get_abstract_origin(Dwarf_Die dw_die)
203{ 191{
204 Dwarf_Attribute attr; 192 Dwarf_Attribute attr;
205 Dwarf_Off cu_offs; 193 Dwarf_Off cu_offs;
206 int ret; 194 int ret;
207 195
208 ret = dwarf_attr(die, DW_AT_abstract_origin, &attr, &__dw_error); 196 ret = dwarf_attr(dw_die, DW_AT_abstract_origin, &attr, &__dw_error);
209 ERR_IF(ret != DW_DLV_OK); 197 ERR_IF(ret != DW_DLV_OK);
210 ret = dwarf_formref(attr, &cu_offs, &__dw_error); 198 ret = dwarf_formref(attr, &cu_offs, &__dw_error);
211 ERR_IF(ret != DW_DLV_OK); 199 ERR_IF(ret != DW_DLV_OK);
@@ -214,7 +202,7 @@ static Dwarf_Off die_get_abstract_origin(Dwarf_Die die)
214} 202}
215 203
216/* Get entry pc(or low pc, 1st entry of ranges) of the die */ 204/* Get entry pc(or low pc, 1st entry of ranges) of the die */
217static Dwarf_Addr die_get_entrypc(Dwarf_Die die) 205static Dwarf_Addr die_get_entrypc(Dwarf_Die dw_die)
218{ 206{
219 Dwarf_Attribute attr; 207 Dwarf_Attribute attr;
220 Dwarf_Addr addr; 208 Dwarf_Addr addr;
@@ -224,7 +212,7 @@ static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
224 int ret; 212 int ret;
225 213
226 /* Try to get entry pc */ 214 /* Try to get entry pc */
227 ret = dwarf_attr(die, DW_AT_entry_pc, &attr, &__dw_error); 215 ret = dwarf_attr(dw_die, DW_AT_entry_pc, &attr, &__dw_error);
228 ERR_IF(ret == DW_DLV_ERROR); 216 ERR_IF(ret == DW_DLV_ERROR);
229 if (ret == DW_DLV_OK) { 217 if (ret == DW_DLV_OK) {
230 ret = dwarf_formaddr(attr, &addr, &__dw_error); 218 ret = dwarf_formaddr(attr, &addr, &__dw_error);
@@ -234,13 +222,13 @@ static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
234 } 222 }
235 223
236 /* Try to get low pc */ 224 /* Try to get low pc */
237 ret = dwarf_lowpc(die, &addr, &__dw_error); 225 ret = dwarf_lowpc(dw_die, &addr, &__dw_error);
238 ERR_IF(ret == DW_DLV_ERROR); 226 ERR_IF(ret == DW_DLV_ERROR);
239 if (ret == DW_DLV_OK) 227 if (ret == DW_DLV_OK)
240 return addr; 228 return addr;
241 229
242 /* Try to get ranges */ 230 /* Try to get ranges */
243 ret = dwarf_attr(die, DW_AT_ranges, &attr, &__dw_error); 231 ret = dwarf_attr(dw_die, DW_AT_ranges, &attr, &__dw_error);
244 ERR_IF(ret != DW_DLV_OK); 232 ERR_IF(ret != DW_DLV_OK);
245 ret = dwarf_formref(attr, &offs, &__dw_error); 233 ret = dwarf_formref(attr, &offs, &__dw_error);
246 ERR_IF(ret != DW_DLV_OK); 234 ERR_IF(ret != DW_DLV_OK);
@@ -382,11 +370,11 @@ static void show_location(Dwarf_Loc *loc, struct probe_finder *pf)
382 } else if (op == DW_OP_regx) { 370 } else if (op == DW_OP_regx) {
383 regn = loc->lr_number; 371 regn = loc->lr_number;
384 } else 372 } else
385 msg_exit(-EINVAL, "Dwarf_OP %d is not supported.\n", op); 373 die("Dwarf_OP %d is not supported.\n", op);
386 374
387 regs = get_arch_regstr(regn); 375 regs = get_arch_regstr(regn);
388 if (!regs) 376 if (!regs)
389 msg_exit(-EINVAL, "%lld exceeds max register number.\n", regn); 377 die("%lld exceeds max register number.\n", regn);
390 378
391 if (deref) 379 if (deref)
392 ret = snprintf(pf->buf, pf->len, 380 ret = snprintf(pf->buf, pf->len,
@@ -417,8 +405,8 @@ static void show_variable(Dwarf_Die vr_die, struct probe_finder *pf)
417 dwarf_dealloc(__dw_debug, attr, DW_DLA_ATTR); 405 dwarf_dealloc(__dw_debug, attr, DW_DLA_ATTR);
418 return ; 406 return ;
419error: 407error:
420 msg_exit(-1, "Failed to find the location of %s at this address.\n" 408 die("Failed to find the location of %s at this address.\n"
421 " Perhaps, it was optimized out.\n", pf->var); 409 " Perhaps, it has been optimized out.\n", pf->var);
422} 410}
423 411
424static int variable_callback(struct die_link *dlink, void *data) 412static int variable_callback(struct die_link *dlink, void *data)
@@ -456,8 +444,7 @@ static void find_variable(Dwarf_Die sp_die, struct probe_finder *pf)
456 /* Search child die for local variables and parameters. */ 444 /* Search child die for local variables and parameters. */
457 ret = search_die_from_children(sp_die, variable_callback, pf); 445 ret = search_die_from_children(sp_die, variable_callback, pf);
458 if (!ret) 446 if (!ret)
459 msg_exit(-1, "Failed to find '%s' in this function.\n", 447 die("Failed to find '%s' in this function.\n", pf->var);
460 pf->var);
461} 448}
462 449
463/* Get a frame base on the address */ 450/* Get a frame base on the address */
@@ -568,8 +555,7 @@ static void find_by_line(Dwarf_Die cu_die, struct probe_finder *pf)
568 /* Search a real subprogram including this line, */ 555 /* Search a real subprogram including this line, */
569 ret = search_die_from_children(cu_die, probeaddr_callback, pf); 556 ret = search_die_from_children(cu_die, probeaddr_callback, pf);
570 if (ret == 0) 557 if (ret == 0)
571 msg_exit(-1, 558 die("Probe point is not found in subprograms.\n");
572 "Probe point is not found in subprograms.\n");
573 /* Continuing, because target line might be inlined. */ 559 /* Continuing, because target line might be inlined. */
574 } 560 }
575 dwarf_srclines_dealloc(__dw_debug, lines, cnt); 561 dwarf_srclines_dealloc(__dw_debug, lines, cnt);
@@ -621,7 +607,7 @@ static int probefunc_callback(struct die_link *dlink, void *data)
621 !die_inlined_subprogram(lk->die)) 607 !die_inlined_subprogram(lk->die))
622 goto found; 608 goto found;
623 } 609 }
624 msg_exit(-1, "Failed to find real subprogram.\n"); 610 die("Failed to find real subprogram.\n");
625found: 611found:
626 /* Get offset from subprogram */ 612 /* Get offset from subprogram */
627 ret = die_within_subprogram(lk->die, pf->addr, &offs); 613 ret = die_within_subprogram(lk->die, pf->addr, &offs);
@@ -649,8 +635,7 @@ int find_probepoint(int fd, struct probe_point *pp)
649 635
650 ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error); 636 ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error);
651 if (ret != DW_DLV_OK) 637 if (ret != DW_DLV_OK)
652 msg_exit(-1, "Failed to call dwarf_init(). " 638 die("Failed to call dwarf_init(). Maybe, not a dwarf file.\n");
653 "Maybe, not a dwarf file?\n");
654 639
655 pp->found = 0; 640 pp->found = 0;
656 while (++cu_number) { 641 while (++cu_number) {