mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Masami Hiramatsu <mhiramat@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, acme@redhat.com,
	hpa@zytor.com, mingo@redhat.com, a.p.zijlstra@chello.nl,
	fweisbec@gmail.com, rostedt@goodmis.org, tglx@linutronix.de,
	mhiramat@redhat.com, mingo@elte.hu
Subject: [tip:perf/probes] perf: Use die() for error cases in perf-probe
Date: Sat, 17 Oct 2009 10:06:11 GMT	[thread overview]
Message-ID: <tip-074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb@git.kernel.org> (raw)
In-Reply-To: <20091017000801.16556.46866.stgit@dhcp-100-2-132.bos.redhat.com>

Commit-ID:  074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb
Gitweb:     http://git.kernel.org/tip/074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Fri, 16 Oct 2009 20:08:01 -0400
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 17 Oct 2009 09:54:00 +0200

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>
---
 tools/perf/builtin-probe.c     |   47 ++++++++++------------------------
 tools/perf/util/probe-finder.c |   55 ++++++++++++++-------------------------
 2 files changed, 34 insertions(+), 68 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 73c883b..a1467d1 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] = {
 
 #define MAX_PATH_LEN 256
 #define MAX_PROBES 128
+#define MAX_PROBE_ARGS 128
 
 /* Session management structure */
 static struct {
@@ -60,19 +61,7 @@ static struct {
 	char *events[MAX_PROBES];
 } session;
 
-static void semantic_error(const char *msg)
-{
-	fprintf(stderr, "Semantic error: %s\n", msg);
-	exit(1);
-}
-
-static void perror_exit(const char *msg)
-{
-	perror(msg);
-	exit(1);
-}
-
-#define MAX_PROBE_ARGS 128
+#define semantic_error(msg ...) die("Semantic error :" msg)
 
 static int parse_probepoint(const struct option *opt __used,
 			    const char *str, int unset __used)
@@ -109,7 +98,7 @@ static int parse_probepoint(const struct option *opt __used,
 			/* Duplicate the argument */
 			argv[argc] = strndup(s, str - s);
 			if (argv[argc] == NULL)
-				perror_exit("strndup");
+				die("strndup");
 			if (++argc == MAX_PROBE_ARGS)
 				semantic_error("Too many arguments");
 			debug("argv[%d]=%s\n", argc, argv[argc - 1]);
@@ -171,7 +160,7 @@ static int parse_probepoint(const struct option *opt __used,
 	if (pp->nr_args > 0) {
 		pp->args = (char **)malloc(sizeof(char *) * pp->nr_args);
 		if (!pp->args)
-			perror_exit("malloc");
+			die("malloc");
 		memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args);
 	}
 
@@ -260,7 +249,7 @@ static int write_new_event(int fd, const char *buf)
 	printf("Adding new event: %s\n", buf);
 	ret = write(fd, buf, strlen(buf));
 	if (ret <= 0)
-		perror("Error: Failed to create event");
+		die("failed to create event.");
 
 	return ret;
 }
@@ -273,7 +262,7 @@ static int synthesize_probepoint(struct probe_point *pp)
 	int i, len, ret;
 	pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
 	if (!buf)
-		perror_exit("calloc");
+		die("calloc");
 	ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
 	if (ret <= 0 || ret >= MAX_CMDLEN)
 		goto error;
@@ -322,10 +311,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 		ret = synthesize_probepoint(&session.probes[j]);
 		if (ret == -E2BIG)
 			semantic_error("probe point is too long.");
-		else if (ret < 0) {
-			perror("snprintf");
-			return -1;
-		}
+		else if (ret < 0)
+			die("snprintf");
 	}
 
 #ifndef NO_LIBDWARF
@@ -336,10 +323,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 		fd = open(session.vmlinux, O_RDONLY);
 	else
 		fd = open_default_vmlinux();
-	if (fd < 0) {
-		perror("vmlinux/module file open");
-		return -1;
-	}
+	if (fd < 0)
+		die("vmlinux/module file open");
 
 	/* Searching probe points */
 	for (j = 0; j < session.nr_probe; j++) {
@@ -349,10 +334,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 
 		lseek(fd, SEEK_SET, 0);
 		ret = find_probepoint(fd, pp);
-		if (ret <= 0) {
-			fprintf(stderr, "Error: No probe point found.\n");
-			return -1;
-		}
+		if (ret <= 0)
+			die("No probe point found.\n");
 		debug("probe event %s found\n", session.events[j]);
 	}
 	close(fd);
@@ -363,10 +346,8 @@ setup_probes:
 	/* Settng up probe points */
 	snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path);
 	fd = open(buf, O_WRONLY, O_APPEND);
-	if (fd < 0) {
-		perror("kprobe_events open");
-		return -1;
-	}
+	if (fd < 0)
+		die("kprobe_events open");
 	for (j = 0; j < session.nr_probe; j++) {
 		pp = &session.probes[j];
 		if (pp->found == 1) {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index ec6f53f..338fdb9 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -31,6 +31,8 @@
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
+
+#include "util.h"
 #include "probe-finder.h"
 
 
@@ -43,20 +45,6 @@ struct die_link {
 static Dwarf_Debug __dw_debug;
 static Dwarf_Error __dw_error;
 
-static void msg_exit(int ret, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	fprintf(stderr, "Error:  ");
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-
-	fprintf(stderr, "\n");
-	exit(ret);
-}
-
-
 /*
  * Generic dwarf analysis helpers
  */
@@ -151,11 +139,11 @@ static Dwarf_Unsigned die_get_fileno(Dwarf_Die cu_die, const char *fname)
 }
 
 /* Compare diename and tname */
-static int die_compare_name(Dwarf_Die die, const char *tname)
+static int die_compare_name(Dwarf_Die dw_die, const char *tname)
 {
 	char *name;
 	int ret;
-	ret = dwarf_diename(die, &name, &__dw_error);
+	ret = dwarf_diename(dw_die, &name, &__dw_error);
 	ERR_IF(ret == DW_DLV_ERROR);
 	if (ret == DW_DLV_OK) {
 		ret = strcmp(tname, name);
@@ -187,25 +175,25 @@ static int die_within_subprogram(Dwarf_Die sp_die, Dwarf_Addr addr,
 }
 
 /* Check the die is inlined function */
-static Dwarf_Bool die_inlined_subprogram(Dwarf_Die die)
+static Dwarf_Bool die_inlined_subprogram(Dwarf_Die dw_die)
 {
 	/* TODO: check strictly */
 	Dwarf_Bool inl;
 	int ret;
 
-	ret = dwarf_hasattr(die, DW_AT_inline, &inl, &__dw_error);
+	ret = dwarf_hasattr(dw_die, DW_AT_inline, &inl, &__dw_error);
 	ERR_IF(ret == DW_DLV_ERROR);
 	return inl;
 }
 
 /* Get the offset of abstruct_origin */
-static Dwarf_Off die_get_abstract_origin(Dwarf_Die die)
+static Dwarf_Off die_get_abstract_origin(Dwarf_Die dw_die)
 {
 	Dwarf_Attribute attr;
 	Dwarf_Off cu_offs;
 	int ret;
 
-	ret = dwarf_attr(die, DW_AT_abstract_origin, &attr, &__dw_error);
+	ret = dwarf_attr(dw_die, DW_AT_abstract_origin, &attr, &__dw_error);
 	ERR_IF(ret != DW_DLV_OK);
 	ret = dwarf_formref(attr, &cu_offs, &__dw_error);
 	ERR_IF(ret != DW_DLV_OK);
@@ -214,7 +202,7 @@ static Dwarf_Off die_get_abstract_origin(Dwarf_Die die)
 }
 
 /* Get entry pc(or low pc, 1st entry of ranges)  of the die */
-static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
+static Dwarf_Addr die_get_entrypc(Dwarf_Die dw_die)
 {
 	Dwarf_Attribute attr;
 	Dwarf_Addr addr;
@@ -224,7 +212,7 @@ static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
 	int ret;
 
 	/* Try to get entry pc */
-	ret = dwarf_attr(die, DW_AT_entry_pc, &attr, &__dw_error);
+	ret = dwarf_attr(dw_die, DW_AT_entry_pc, &attr, &__dw_error);
 	ERR_IF(ret == DW_DLV_ERROR);
 	if (ret == DW_DLV_OK) {
 		ret = dwarf_formaddr(attr, &addr, &__dw_error);
@@ -234,13 +222,13 @@ static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
 	}
 
 	/* Try to get low pc */
-	ret = dwarf_lowpc(die, &addr, &__dw_error);
+	ret = dwarf_lowpc(dw_die, &addr, &__dw_error);
 	ERR_IF(ret == DW_DLV_ERROR);
 	if (ret == DW_DLV_OK)
 		return addr;
 
 	/* Try to get ranges */
-	ret = dwarf_attr(die, DW_AT_ranges, &attr, &__dw_error);
+	ret = dwarf_attr(dw_die, DW_AT_ranges, &attr, &__dw_error);
 	ERR_IF(ret != DW_DLV_OK);
 	ret = dwarf_formref(attr, &offs, &__dw_error);
 	ERR_IF(ret != DW_DLV_OK);
@@ -382,11 +370,11 @@ static void show_location(Dwarf_Loc *loc, struct probe_finder *pf)
 	} else if (op == DW_OP_regx) {
 		regn = loc->lr_number;
 	} else
-		msg_exit(-EINVAL, "Dwarf_OP %d is not supported.\n", op);
+		die("Dwarf_OP %d is not supported.\n", op);
 
 	regs = get_arch_regstr(regn);
 	if (!regs)
-		msg_exit(-EINVAL, "%lld exceeds max register number.\n", regn);
+		die("%lld exceeds max register number.\n", regn);
 
 	if (deref)
 		ret = snprintf(pf->buf, pf->len,
@@ -417,8 +405,8 @@ static void show_variable(Dwarf_Die vr_die, struct probe_finder *pf)
 	dwarf_dealloc(__dw_debug, attr, DW_DLA_ATTR);
 	return ;
 error:
-	msg_exit(-1, "Failed to find the location of %s at this address.\n"
-		 " Perhaps, it was optimized out.\n", pf->var);
+	die("Failed to find the location of %s at this address.\n"
+	    " Perhaps, it has been optimized out.\n", pf->var);
 }
 
 static 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)
 	/* Search child die for local variables and parameters. */
 	ret = search_die_from_children(sp_die, variable_callback, pf);
 	if (!ret)
-		msg_exit(-1, "Failed to find '%s' in this function.\n",
-			 pf->var);
+		die("Failed to find '%s' in this function.\n", pf->var);
 }
 
 /* Get a frame base on the address */
@@ -568,8 +555,7 @@ static void find_by_line(Dwarf_Die cu_die, struct probe_finder *pf)
 		/* Search a real subprogram including this line, */
 		ret = search_die_from_children(cu_die, probeaddr_callback, pf);
 		if (ret == 0)
-			msg_exit(-1,
-				 "Probe point is not found in subprograms.\n");
+			die("Probe point is not found in subprograms.\n");
 		/* Continuing, because target line might be inlined. */
 	}
 	dwarf_srclines_dealloc(__dw_debug, lines, cnt);
@@ -621,7 +607,7 @@ static int probefunc_callback(struct die_link *dlink, void *data)
 				    !die_inlined_subprogram(lk->die))
 					goto found;
 			}
-			msg_exit(-1, "Failed to find real subprogram.\n");
+			die("Failed to find real subprogram.\n");
 found:
 			/* Get offset from subprogram */
 			ret = die_within_subprogram(lk->die, pf->addr, &offs);
@@ -649,8 +635,7 @@ int find_probepoint(int fd, struct probe_point *pp)
 
 	ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error);
 	if (ret != DW_DLV_OK)
-		msg_exit(-1, "Failed to call dwarf_init(). "
-			 "Maybe, not a dwarf file?\n");
+		die("Failed to call dwarf_init(). Maybe, not a dwarf file.\n");
 
 	pp->found = 0;
 	while (++cu_number) {

  reply	other threads:[~2009-10-17 10:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-17  0:07 [PATCH -tip tracing/kprobes 0/9] tracing/kprobes, perf: perf probe and kprobe-tracer bugfixes Masami Hiramatsu
2009-10-17  0:07 ` [PATCH -tip tracing/kprobes 1/9] tracing/kprobes: Update kprobe-tracer selftest against new syntax Masami Hiramatsu
2009-10-17 10:04   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:07 ` [PATCH -tip tracing/kprobes 2/9] tracing/kprobes: Add failure messages for debugging Masami Hiramatsu
2009-10-17 10:05   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:07 ` [PATCH -tip tracing/kprobes 3/9] x86: Add MMX/SSE opcode groups to opcode map Masami Hiramatsu
2009-10-17 10:05   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:07 ` [PATCH -tip tracing/kprobes 4/9] x86: Add AMD prefetch and 3DNow! opcodes " Masami Hiramatsu
2009-10-17 10:05   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:07 ` [PATCH -tip tracing/kprobes 5/9] perf: Check libdwarf APIs for perf probe Masami Hiramatsu
2009-10-17 10:05   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:08 ` [PATCH -tip tracing/kprobes 6/9] perf: Use die() for error cases in perf-probe Masami Hiramatsu
2009-10-17 10:06   ` tip-bot for Masami Hiramatsu [this message]
2009-10-17  0:08 ` [PATCH -tip tracing/kprobes 7/9] perf: Use eprintf() for debug messages " Masami Hiramatsu
2009-10-17 10:06   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:08 ` [PATCH -tip tracing/kprobes 8/9] perf: Add DIE_IF() macro for error checking Masami Hiramatsu
2009-10-17 10:06   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  0:08 ` [PATCH -tip tracing/kprobes 9/9] perf: Add perf-probe document Masami Hiramatsu
2009-10-17 10:06   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-10-17  8:02 ` [PATCH -tip tracing/kprobes 0/9] tracing/kprobes, perf: perf probe and kprobe-tracer bugfixes Ingo Molnar
2009-10-17 10:34   ` Ingo Molnar
2009-10-17 10:37     ` Ingo Molnar
2009-10-18  6:01     ` Masami Hiramatsu
2009-10-19  7:51       ` Ingo Molnar
2009-10-19 11:00         ` Frederic Weisbecker
2009-10-19 11:21           ` Ingo Molnar
2009-10-19 19:32             ` Frederic Weisbecker
2009-10-20  6:43               ` Ingo Molnar
2009-10-20 17:51                 ` Frederic Weisbecker
2009-10-19 19:51             ` Masami Hiramatsu
2009-10-19 22:54               ` Masami Hiramatsu
2009-10-20  6:51                 ` Ingo Molnar
2009-10-21  0:05                   ` Masami Hiramatsu
2009-10-20  6:50               ` Ingo Molnar
2009-10-20 14:38                 ` Masami Hiramatsu
2009-10-19 16:18           ` Arnaldo Carvalho de Melo
2009-10-20 17:45             ` Frederic Weisbecker
2009-10-19 18:56         ` Masami Hiramatsu
2009-10-20  6:54           ` Ingo Molnar
2009-10-20 14:27             ` Masami Hiramatsu
2009-10-19 23:10 ` Ashwin Chaugule
2009-10-20  0:30   ` Masami Hiramatsu
2009-10-20  1:59     ` Ashwin Chaugule
2009-10-20  6:55       ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb@git.kernel.org \
    --to=mhiramat@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome