Skip to contentSkip to conversation

perf-probe updates - data-structure support improvements, etc.

PATCH Superseded Masami Hiramatsu 2 participants 13 messages Mar 29, 2010

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover perf-probe updates - data-structure support improvements, etc.

Hi Ingo,

Here are several updates of perf-probe. This series improves data structure accessing.

- Set the name of argument which traces a data structure member as the last member of the data structure reference (e.g. f_mode of file->f_mode). This allows us to use perf-trace for tracin data-structure members.

- Add the basic type support. This allows us to fetch the memory with specified bitwidth. Usually, data-structure members are packed on the memory, this means if we want to read a member from memory, we have to access it with type casting. kprobe-tracer now support tracing argument with basic types (u8,u16,u32,u64,s8,s16,s32,s64), and perf-probe decodes the type information of the members.

- Support canonical frame address, which is used for refering frame-base on the kernel built without CONFIG_FRAME_POINTER.

TODOs (possible features):
- Support array element (var[N])
- Support string/dynamic arrays (*var, var[N..M])
- Support tracing static variables (non global)
- Support dynamic array-indexing (var[var2])
- Support force type-casting ((type)var)
- Show what deta-structure member is assigned to each argument.
- Better support for probes on modules
- More debugger like enhancements(%next, --disasm, etc.)

I decided to drop non-root user support (for --add/--del), because this can set probes for getting sensitive data...

Thank you,

---

Masami Hiramatsu (7):
perf probe: Support DW_OP_call_frame_cfa in debuginfo perf probe: Support basic type casting
perf probe: Query basic types from debuginfo trace/kprobes: Support basic types
perf probe: Use the last field name as the argument name perf probe: Support argument name
[BUGFIX] perf probe: Fix to close dwarf when failing to analyze it

 Documentation/trace/kprobetrace.txt     |    4 
 kernel/trace/trace.h                    |   16 -
 kernel/trace/trace_kprobe.c             |  535 +++++++++++++++++++------------
 tools/perf/Documentation/perf-probe.txt |   11 +
 tools/perf/builtin-probe.c              |    4 
 tools/perf/util/probe-event.c           |   70 +++-
 tools/perf/util/probe-event.h           |    3 
 tools/perf/util/probe-finder.c          |  131 ++++++--
 tools/perf/util/probe-finder.h          |    1 
 9 files changed, 516 insertions(+), 259 deletions(-)
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#1 lore raw

PATCH 1/7 perf probe: Fix to close dwarf when failing to analyze it

Fix to close libdw routine when failing to analyze it in find_perf_probe_point().

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/util/probe-finder.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/probe-finder.c +4 -2
index db52ec2..5f6cecc 100644
@@ -812,8 +812,10 @@ int find_perf_probe_point(int fd, unsigned long addr,
 		return -ENOENT;
 
 	/* Find cu die */
-	if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie))
-		return -EINVAL;
+	if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) {
+		ret = -EINVAL;
+		goto end;
+	}
 
 	/* Find a corresponding line */
 	line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr);
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#2 lore raw

PATCH 2/7 perf probe: Support argument name

In reply to Masami Hiramatsu

Set given names to event arguments. The syntax is same as kprobe-tracer, you can add 'NAME=' right before each argument.

e.g.
./perf probe vfs_read foo=file

then, 'foo' is set to the argument name as below.

./perf probe -l
probe:vfs_read (on [email protected]/fs/read_write.c with foo)

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/Documentation/perf-probe.txt |   10 ++++++++-
 tools/perf/builtin-probe.c              |    4 ++--
 tools/perf/util/probe-event.c           |   34 ++++++++++++++++++++++---------
 tools/perf/util/probe-event.h           |    1 +
 tools/perf/util/probe-finder.c          |   27 +++++++++++++++----------
 5 files changed, 52 insertions(+), 24 deletions(-)
tools/perf/Documentation/perf-probe.txt +9 -1
index 0f944b3..0657cf4 100644
@@ -79,7 +79,15 @@ Probe points are defined by following syntax.
 'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition.  In addition, '@SRC' specifies a source file which has that function.
 It is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern.
-'ARG' specifies the arguments of this probe point. You can use the name of local variable, or kprobe-tracer argument format (e.g. $retval, %ax, etc).
+'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT).
+
+PROBE ARGUMENT
+--------------
+Each probe argument follows below syntax.
+
+ [NAME=]LOCALVAR|$retval|%REG|@SYMBOL
+
+'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc).
 
 LINE SYNTAX
 -----------
tools/perf/builtin-probe.c +2 -2
index cf2ffa5..23933c1 100644
@@ -142,9 +142,9 @@ static const struct option options[] = {
 	OPT_CALLBACK('a', "add", NULL,
 #ifdef DWARF_SUPPORT
 		"[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT"
-		" [ARG ...]",
+		" [[NAME=]ARG ...]",
 #else
-		"[EVENT=]FUNC[+OFF|%return] [ARG ...]",
+		"[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]",
 #endif
 		"probe point definition, where\n"
 		"\t\tGROUP:\tGroup name (optional)\n"
tools/perf/util/probe-event.c +24 -10
index 3fc0be7..ab6f53d 100644
@@ -437,22 +437,28 @@ static void parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 /* Parse perf-probe event argument */
 static void parse_perf_probe_arg(const char *str, struct perf_probe_arg *arg)
 {
-	const char *tmp;
+	char *tmp;
 	struct perf_probe_arg_field **fieldp;
 
 	pr_debug("parsing arg: %s into ", str);
 
+	tmp = strchr(str, '=');
+	if (tmp) {
+		arg->name = xstrndup(str, tmp - str);
+		str = tmp + 1;
+	}
+
 	tmp = strpbrk(str, "-.");
 	if (!is_c_varname(str) || !tmp) {
 		/* A variable, register, symbol or special value */
-		arg->name = xstrdup(str);
-		pr_debug("%s\n", arg->name);
+		arg->var = xstrdup(str);
+		pr_debug("%s\n", arg->var);
 		return;
 	}
 
 	/* Structure fields */
-	arg->name = xstrndup(str, tmp - str);
-	pr_debug("%s, ", arg->name);
+	arg->var = xstrndup(str, tmp - str);
+	pr_debug("%s, ", arg->var);
 	fieldp = &arg->field;
 
 	do {
@@ -497,7 +503,7 @@ void parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
 	pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
 	for (i = 0; i < pev->nargs; i++) {
 		parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
-		if (is_c_varname(pev->args[i].name) && pev->point.retprobe)
+		if (is_c_varname(pev->args[i].var) && pev->point.retprobe)
 			semantic_error("You can't specify local variable for"
 				       " kretprobe");
 	}
@@ -514,7 +520,7 @@ bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
 		return true;
 
 	for (i = 0; i < pev->nargs; i++)
-		if (is_c_varname(pev->args[i].name))
+		if (is_c_varname(pev->args[i].var))
 			return true;
 
 	return false;
@@ -575,7 +581,10 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
 	int ret;
 	char *tmp = buf;
 
-	ret = e_snprintf(tmp, len, "%s", pa->name);
+	if (pa->name && pa->var)
+		ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
+	else
+		ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
 	if (ret <= 0)
 		goto error;
 	tmp += ret;
@@ -803,6 +812,8 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
 	for (i = 0; i < pev->nargs; i++) {
 		if (pev->args[i].name)
 			free(pev->args[i].name);
+		if (pev->args[i].var)
+			free(pev->args[i].var);
 		field = pev->args[i].field;
 		while (field) {
 			next = field->next;
@@ -1117,8 +1128,11 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
 	if (tev->nargs) {
 		tev->args = xzalloc(sizeof(struct kprobe_trace_arg)
 				    * tev->nargs);
-		for (i = 0; i < tev->nargs; i++)
-			tev->args[i].value = xstrdup(pev->args[i].name);
+		for (i = 0; i < tev->nargs; i++) {
+			if (pev->args[i].name)
+				tev->args[i].name = xstrdup(pev->args[i].name);
+			tev->args[i].value = xstrdup(pev->args[i].var);
+		}
 	}
 
 	/* Currently just checking function name from symbol map */
tools/perf/util/probe-event.h +1 -0
index cd308b0..a73ede6 100644
@@ -55,6 +55,7 @@ struct perf_probe_arg_field {
 /* Perf probe probing argument */
 struct perf_probe_arg {
 	char				*name;	/* Argument name */
+	char				*var;	/* Variable name */
 	struct perf_probe_arg_field	*field;	/* Structure fields */
 };
 
tools/perf/util/probe-finder.c +16 -11
index 5f6cecc..043140f 100644
@@ -478,35 +478,40 @@ static void convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
 	convert_location(expr, pf);
 
 	if (pf->pvar->field)
-		convert_variable_fields(vr_die, pf->pvar->name,
+		convert_variable_fields(vr_die, pf->pvar->var,
 					pf->pvar->field, &pf->tvar->ref);
 	/* *expr will be cached in libdw. Don't free it. */
 	return ;
 error:
 	/* TODO: Support const_value */
 	die("Failed to find the location of %s at this address.\n"
-	    " Perhaps, it has been optimized out.", pf->pvar->name);
+	    " Perhaps, it has been optimized out.", pf->pvar->var);
 }
 
 /* Find a variable in a subprogram die */
 static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
 {
 	Dwarf_Die vr_die;
-	char buf[128];
+	char buf[32];
 
-	/* TODO: Support struct members and arrays */
-	if (!is_c_varname(pf->pvar->name)) {
+	/* TODO: Support arrays */
+	if (pf->pvar->name)
+		pf->tvar->name = xstrdup(pf->pvar->name);
+	else {
+		synthesize_perf_probe_arg(pf->pvar, buf, 32);
+		pf->tvar->name = xstrdup(buf);
+	}
+
+	if (!is_c_varname(pf->pvar->var)) {
 		/* Copy raw parameters */
-		pf->tvar->value = xstrdup(pf->pvar->name);
+		pf->tvar->value = xstrdup(pf->pvar->var);
 	} else {
-		synthesize_perf_probe_arg(pf->pvar, buf, 128);
-		pf->tvar->name = xstrdup(buf);
 		pr_debug("Searching '%s' variable in context.\n",
-			 pf->pvar->name);
+			 pf->pvar->var);
 		/* Search child die for local variables and parameters. */
-		if (!die_find_variable(sp_die, pf->pvar->name, &vr_die))
+		if (!die_find_variable(sp_die, pf->pvar->var, &vr_die))
 			die("Failed to find '%s' in this function.",
-			    pf->pvar->name);
+			    pf->pvar->var);
 		convert_variable(&vr_die, pf);
 	}
 }
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#3 lore raw

PATCH 3/7 perf probe: Use the last field name as the argument name

In reply to Masami Hiramatsu

Set the last field name to the argument name when the argument is refering a data-structure member.

e.g.
./perf probe --add 'vfs_read file->f_mode'
Add new event:
probe:vfs_read (on vfs_read with f_mode=file->f_mode)

This probe records file->f_mode, but the argument name becomes "f_mode".

This enables perf-trace command to parse trace event format correctly.

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/Documentation/perf-probe.txt |    2 +-
 tools/perf/util/probe-event.c           |    4 ++++
 2 files changed, 5 insertions(+), 1 deletions(-)
tools/perf/Documentation/perf-probe.txt +1 -1
index 0657cf4..d781fc5 100644
@@ -87,7 +87,7 @@ Each probe argument follows below syntax.
 
  [NAME=]LOCALVAR|$retval|%REG|@SYMBOL
 
-'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc).
+'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 
 LINE SYNTAX
 -----------
tools/perf/util/probe-event.c +4 -0
index ab6f53d..19de8b7 100644
@@ -481,6 +481,10 @@ static void parse_perf_probe_arg(const char *str, struct perf_probe_arg *arg)
 	} while (tmp);
 	(*fieldp)->name = xstrdup(str);
 	pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref);
+
+	/* If no name is specified, set the last field name */
+	if (!arg->name)
+		arg->name = xstrdup((*fieldp)->name);
 }
 
 /* Parse perf-probe event command */
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#4 lore raw

PATCH 4/7 trace/kprobes: Support basic types

In reply to Masami Hiramatsu

Support basic types of integer (u8, u16, u32, u64, s8, s16, s32, s64) in kprobe tracer. With this patch, users can specify above basic types on each arguments after ':'. If omitted, the argument type is set as unsigned long (u32 or u64, arch-dependent).

e.g.
echo 'p account_system_time+0 hardirq_offset=%si:s32' > kprobe_events

adds a probe recording hardirq_offset in signed-32bits value on the entry of account_system_time.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 Documentation/trace/kprobetrace.txt |    4 
 kernel/trace/trace.h                |   16 -
 kernel/trace/trace_kprobe.c         |  535 ++++++++++++++++++++++-------------
 3 files changed, 334 insertions(+), 221 deletions(-)
Documentation/trace/kprobetrace.txt +3 -1
index a9100b2..ec94748 100644
@@ -40,7 +40,9 @@ Synopsis of kprobe_events
   $stack	: Fetch stack address.
   $retval	: Fetch return value.(*)
   +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
-  NAME=FETCHARG: Set NAME as the argument name of FETCHARG.
+  NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
+  FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
+		  (u8/u16/u32/u64/s8/s16/s32/s64) are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
kernel/trace/trace.h +2 -14
index bec2c97..3ebdb6b 100644
@@ -102,29 +102,17 @@ struct syscall_trace_exit {
 	long			ret;
 };
 
-struct kprobe_trace_entry {
+struct kprobe_trace_entry_head {
 	struct trace_entry	ent;
 	unsigned long		ip;
-	int			nargs;
-	unsigned long		args[];
 };
 
-#define SIZEOF_KPROBE_TRACE_ENTRY(n)			\
-	(offsetof(struct kprobe_trace_entry, args) +	\
-	(sizeof(unsigned long) * (n)))
-
-struct kretprobe_trace_entry {
+struct kretprobe_trace_entry_head {
 	struct trace_entry	ent;
 	unsigned long		func;
 	unsigned long		ret_ip;
-	int			nargs;
-	unsigned long		args[];
 };
 
-#define SIZEOF_KRETPROBE_TRACE_ENTRY(n)			\
-	(offsetof(struct kretprobe_trace_entry, args) +	\
-	(sizeof(unsigned long) * (n)))
-
 /*
  * trace_flag_type is an enumeration that holds different
  * states when a trace occurs. These are:
kernel/trace/trace_kprobe.c +329 -206

872 lines not on this page · raw message

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#5 lore raw

PATCH 5/7 perf probe: Query basic types from debuginfo

In reply to Masami Hiramatsu

Query the basic type information (byte-size and signed-flag) from debuginfo and pass that to kprobe-tracer. This is especially useful for tracing the members of data structure, because each member has different byte-size on the memory.

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/util/probe-event.c  |    9 +++++
 tools/perf/util/probe-event.h  |    1 +
 tools/perf/util/probe-finder.c |   78 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 80 insertions(+), 8 deletions(-)
tools/perf/util/probe-event.c +9 -0
index 19de8b7..05ca4a9 100644
@@ -740,6 +740,13 @@ static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg,
 		buf += ret;
 		buflen -= ret;
 	}
+	/* Print argument type */
+	if (arg->type) {
+		ret = e_snprintf(buf, buflen, ":%s", arg->type);
+		if (ret <= 0)
+			return ret;
+		buf += ret;
+	}
 
 	return buf - tmp;
 }
@@ -848,6 +855,8 @@ void clear_kprobe_trace_event(struct kprobe_trace_event *tev)
 			free(tev->args[i].name);
 		if (tev->args[i].value)
 			free(tev->args[i].value);
+		if (tev->args[i].type)
+			free(tev->args[i].type);
 		ref = tev->args[i].ref;
 		while (ref) {
 			next = ref->next;
tools/perf/util/probe-event.h +1 -0
index a73ede6..0759db6 100644
@@ -23,6 +23,7 @@ struct kprobe_trace_arg_ref {
 struct kprobe_trace_arg {
 	char				*name;	/* Argument name */
 	char				*value;	/* Base value */
+	char				*type;	/* Type name */
 	struct kprobe_trace_arg_ref	*ref;	/* Referencing offset */
 };
 
tools/perf/util/probe-finder.c +70 -8

130 lines not on this page · raw message

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#6 lore raw

Re: [PATCH -tip 5/7] perf probe: Query basic types from debuginfo

Em Mon, Mar 29, 2010 at 04:38:29PM -0400, Masami Hiramatsu escreveu:

Quoted 16 lines
tools/perf/util/probe-finder.c +16 -0
+static void convert_variable_type(Dwarf_Die *vr_die,
+				  struct kprobe_trace_arg *targ)
+{
+	Dwarf_Die type;
+	char buf[16];
+	int ret;
+
+	if (die_get_real_type(vr_die, &type) == NULL)
+		die("Failed to get a type information of %s.",
+		    dwarf_diename(vr_die));
+
+	ret = die_get_byte_size(&type) * 8;
+	if (ret) {
+		/* Check the bitwidth */
+		if (ret > MAX_BASIC_TYPE_BITS) {
+			pr_warning("  Warning: %s exceeds max-bitwidth."

tools/perf/util/probe-finder.c static void convert_location(Dwarf_Op *op, struct probe_finder *pf) · line 460

Quoted 10 lines
tools/perf/util/probe-finder.c +10 -0
+				   " Cut down to %d bits.\n",
+				   dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
+			ret = MAX_BASIC_TYPE_BITS;
+		}
+
+		ret = snprintf(buf, 16, "%c%d",
+			       die_is_signed_type(&type) ? 's' : 'u', ret);
+		if (ret < 0 || ret >= 16)
+			die("Failed to convert variable type.");
+		targ->type = xstrdup(buf);

Question, should we use the equivalent to panic'ing the kernel in the userspace bits in tools/?

I tend to see all code there as potentially part of a library, i.e. to be callable by some unantecipated new tool or library that would rather receive a return value telling it that the operation can't be performed for some reason so that it can inform the user instead of having the whole tool exit to the command line.

It may well be that some specific operation needs lots of resources but many other don't, panic'c because the one that requires lots of resources can't be performed, bringing down a gui/tui is really nasty.

Perhaps the answer will be the same as for when people added panic calls in the kernel in the past, "you're screwed up anyway if that happens", but it just feels wrong :-\

In the DWARF bits it has even the added twist namespace collapse with DIE 8-)

- Arnaldo

#7 lore raw

Re: [PATCH -tip 5/7] perf probe: Query basic types from debuginfo

Quoted 31 lines · Arnaldo Carvalho de Melo

Em Mon, Mar 29, 2010 at 04:38:29PM -0400, Masami Hiramatsu escreveu:

Quoted 16 lines
tools/perf/util/probe-finder.c +16 -0
+static void convert_variable_type(Dwarf_Die *vr_die,
+				  struct kprobe_trace_arg *targ)
+{
+	Dwarf_Die type;
+	char buf[16];
+	int ret;
+
+	if (die_get_real_type(vr_die, &type) == NULL)
+		die("Failed to get a type information of %s.",
+		    dwarf_diename(vr_die));
+
+	ret = die_get_byte_size(&type) * 8;
+	if (ret) {
+		/* Check the bitwidth */
+		if (ret > MAX_BASIC_TYPE_BITS) {
+			pr_warning("  Warning: %s exceeds max-bitwidth."

tools/perf/util/probe-finder.c static void convert_location(Dwarf_Op *op, struct probe_finder *pf) · line 460

Quoted 10 lines
tools/perf/util/probe-finder.c +10 -0
+				   " Cut down to %d bits.\n",
+				   dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
+			ret = MAX_BASIC_TYPE_BITS;
+		}
+
+		ret = snprintf(buf, 16, "%c%d",
+			       die_is_signed_type(&type) ? 's' : 'u', ret);
+		if (ret < 0 || ret >= 16)
+			die("Failed to convert variable type.");
+		targ->type = xstrdup(buf);

Question, should we use the equivalent to panic'ing the kernel in the userspace bits in tools/?

Quoted 5 lines

I tend to see all code there as potentially part of a library, i.e. to be callable by some unantecipated new tool or library that would rather receive a return value telling it that the operation can't be performed for some reason so that it can inform the user instead of having the whole tool exit to the command line.

OK, so that you want to see

ret = library_func();
if (ret < 0) /* Something wrong happened */

	return ret;

instead of

library_func();
hopefully_executed_next_func();

Quoted 3 lines

It may well be that some specific operation needs lots of resources but many other don't, panic'c because the one that requires lots of resources can't be performed, bringing down a gui/tui is really nasty.

Hmm, agreed. But I'd like to have some API for storing dying^H^H^H^H^Herror message. (maybe can we use setjump/longjump approach - like try/cache - for die()?)

Thank you,

Quoted 14 lines

Perhaps the answer will be the same as for when people added panic calls in the kernel in the past, "you're screwed up anyway if that happens", but it just feels wrong :-\

In the DWARF bits it has even the added twist namespace collapse with DIE 8-)

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#8 lore raw

Re: [PATCH -tip 5/7] perf probe: Query basic types from debuginfo

Em Mon, Mar 29, 2010 at 05:22:00PM -0400, Masami Hiramatsu escreveu:

Quoted 13 lines
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Mon, Mar 29, 2010 at 04:38:29PM -0400, Masami Hiramatsu escreveu:
Question, should we use the equivalent to panic'ing the kernel in the userspace bits in tools/?

I tend to see all code there as potentially part of a library, i.e. to be callable by some unantecipated new tool or library that would rather receive a return value telling it that the operation can't be performed for some reason so that it can inform the user instead of having the whole tool exit to the command line.

OK, so that you want to see

Quoted 8 lines

ret = library_func();
if (ret < 0) /* Something wrong happened */

	return ret;

instead of

library_func();
hopefully_executed_next_func();

Exactly. That was my _suggestion_ :-)

Quoted 6 lines
Quoted 3 lines

It may well be that some specific operation needs lots of resources but many other don't, panic'c because the one that requires lots of resources can't be performed, bringing down a gui/tui is really nasty.

Hmm, agreed. But I'd like to have some API for storing dying^H^H^H^H^Herror message. (maybe can we use setjump/longjump approach - like try/cache - for die()?)

Can't we do just as we do in the kernel and propagate the error back to callers? All the way to userspace, that in this case would be the user instead of an app started by a user? :-)

Wrt api for storing messages, we have pr_{warning,error,debug}, etc, in the TUI mode it is even redirected to the bottom line and I plan to have them get into something browseable if the user wants to see the last pr_ messages.

IOW, just act like you're writing kernel code, that will make it more likely that people that are used to writing code like that will feel at ease while hacking tools/.

- Arnaldo

#9 lore raw

Re: [PATCH -tip 5/7] perf probe: Query basic types from debuginfo

Quoted 32 lines · Arnaldo Carvalho de Melo

Em Mon, Mar 29, 2010 at 05:22:00PM -0400, Masami Hiramatsu escreveu:

Quoted 13 lines
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Mon, Mar 29, 2010 at 04:38:29PM -0400, Masami Hiramatsu escreveu:
Question, should we use the equivalent to panic'ing the kernel in the userspace bits in tools/?

I tend to see all code there as potentially part of a library, i.e. to be callable by some unantecipated new tool or library that would rather receive a return value telling it that the operation can't be performed for some reason so that it can inform the user instead of having the whole tool exit to the command line.

OK, so that you want to see

Quoted 8 lines

ret = library_func();
if (ret < 0) /* Something wrong happened */

	return ret;

instead of

library_func();
hopefully_executed_next_func();

Exactly. That was my _suggestion_ :-)

Quoted 6 lines
Quoted 3 lines

It may well be that some specific operation needs lots of resources but many other don't, panic'c because the one that requires lots of resources can't be performed, bringing down a gui/tui is really nasty.

Hmm, agreed. But I'd like to have some API for storing dying^H^H^H^H^Herror message. (maybe can we use setjump/longjump approach - like try/cache - for die()?)

Quoted 8 lines

Can't we do just as we do in the kernel and propagate the error back to callers? All the way to userspace, that in this case would be the user instead of an app started by a user? :-)

Wrt api for storing messages, we have pr_{warning,error,debug}, etc, in the TUI mode it is even redirected to the bottom line and I plan to have them get into something browseable if the user wants to see the last pr_ messages.

Ah, that's very nice:)
OK, I'll try to use it and remove all 'die()'s.

Thank you!

Quoted 11 lines

IOW, just act like you're writing kernel code, that will make it more likely that people that are used to writing code like that will feel at ease while hacking tools/.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#10 lore raw

Re: [PATCH -tip 5/7] perf probe: Query basic types from debuginfo

Em Mon, Mar 29, 2010 at 06:05:03PM -0400, Masami Hiramatsu escreveu:

Quoted 5 lines
Quoted 4 lines · Arnaldo Carvalho de Melo

Can't we do just as we do in the kernel and propagate the error back to callers? All the way to userspace, that in this case would be the user instead of an app started by a user? :-)

Quoted 7 lines
Quoted 4 lines

Wrt api for storing messages, we have pr_{warning,error,debug}, etc, in the TUI mode it is even redirected to the bottom line and I plan to have them get into something browseable if the user wants to see the last pr_ messages.

Ah, that's very nice:)
OK, I'll try to use it and remove all 'die()'s.

Thanks a lot!

- Arnaldo

#11 lore raw

PATCH 6/7 perf probe: Support basic type casting

In reply to Masami Hiramatsu

Add basic type casting for arguments to perf probe. This allows users to specify the actual type of arguments. Of course, if user sets invalid types, kprobe-tracer rejects that.

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/Documentation/perf-probe.txt |    3 ++-
 tools/perf/util/probe-event.c           |   23 ++++++++++++++++++++++-
 tools/perf/util/probe-event.h           |    1 +
 tools/perf/util/probe-finder.c          |   10 ++++++++--
 4 files changed, 33 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-probe.txt +2 -1
index d781fc5..21820c3 100644
@@ -85,9 +85,10 @@ PROBE ARGUMENT
 --------------
 Each probe argument follows below syntax.
 
- [NAME=]LOCALVAR|$retval|%REG|@SYMBOL
+ [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE]
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo.
 
 LINE SYNTAX
 -----------
tools/perf/util/probe-event.c +22 -1
index 05ca4a9..bef2805 100644
@@ -435,7 +435,7 @@ static void parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 }
 
 /* Parse perf-probe event argument */
-static void parse_perf_probe_arg(const char *str, struct perf_probe_arg *arg)
+static void parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
 {
 	char *tmp;
 	struct perf_probe_arg_field **fieldp;
@@ -445,9 +445,17 @@ static void parse_perf_probe_arg(const char *str, struct perf_probe_arg *arg)
 	tmp = strchr(str, '=');
 	if (tmp) {
 		arg->name = xstrndup(str, tmp - str);
+		pr_debug("name:%s ", arg->name);
 		str = tmp + 1;
 	}
 
+	tmp = strchr(str, ':');
+	if (tmp) {	/* Type setting */
+		*tmp = '\0';
+		arg->type = xstrdup(tmp + 1);
+		pr_debug("type:%s ", arg->type);
+	}
+
 	tmp = strpbrk(str, "-.");
 	if (!is_c_varname(str) || !tmp) {
 		/* A variable, register, symbol or special value */
@@ -603,6 +611,15 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
 		len -= ret;
 		field = field->next;
 	}
+
+	if (pa->type) {
+		ret = e_snprintf(tmp, len, ":%s", pa->type);
+		if (ret <= 0)
+			goto error;
+		tmp += ret;
+		len -= ret;
+	}
+
 	return tmp - buf;
 error:
 	die("Failed to synthesize perf probe argument: %s", strerror(-ret));
@@ -825,6 +842,8 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
 			free(pev->args[i].name);
 		if (pev->args[i].var)
 			free(pev->args[i].var);
+		if (pev->args[i].type)
+			free(pev->args[i].type);
 		field = pev->args[i].field;
 		while (field) {
 			next = field->next;
@@ -1145,6 +1164,8 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
 			if (pev->args[i].name)
 				tev->args[i].name = xstrdup(pev->args[i].name);
 			tev->args[i].value = xstrdup(pev->args[i].var);
+			if (pev->args[i].type)
+				tev->args[i].type = xstrdup(pev->args[i].type);
 		}
 	}
 
tools/perf/util/probe-event.h +1 -0
index 0759db6..5a9837c 100644
@@ -57,6 +57,7 @@ struct perf_probe_arg_field {
 struct perf_probe_arg {
 	char				*name;	/* Argument name */
 	char				*var;	/* Variable name */
+	char				*type;	/* Type name */
 	struct perf_probe_arg_field	*field;	/* Structure fields */
 };
 
tools/perf/util/probe-finder.c +8 -2
index f3c2706..11d6592 100644
@@ -541,7 +541,10 @@ static void convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
 					&die_mem);
 		vr_die = &die_mem;
 	}
-	convert_variable_type(vr_die, pf->tvar);
+	if (pf->pvar->type)
+		pf->tvar->type = xstrdup(pf->pvar->type);
+	else
+		convert_variable_type(vr_die, pf->tvar);
 	/* *expr will be cached in libdw. Don't free it. */
 	return ;
 error:
@@ -554,13 +557,16 @@ error:
 static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
 {
 	Dwarf_Die vr_die;
-	char buf[32];
+	char buf[32], *ptr;
 
 	/* TODO: Support arrays */
 	if (pf->pvar->name)
 		pf->tvar->name = xstrdup(pf->pvar->name);
 	else {
 		synthesize_perf_probe_arg(pf->pvar, buf, 32);
+		ptr = strchr(buf, ':');	/* Change type separator to _ */
+		if (ptr)
+			*ptr = '_';
 		pf->tvar->name = xstrdup(buf);
 	}
 
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#12 lore raw

PATCH 7/7 perf probe: Support DW_OP_call_frame_cfa in debuginfo

In reply to Masami Hiramatsu

When building kernel without CONFIG_FRAME_POINTER, gcc uses CFA (canonical frame address) for frame base. With this patch, perf probe just gets CFI (call frame information) from debuginfo and search corresponding CFA from the CFI. IOW, this allows perf probe works correctly on the kernel without CONFIG_FRAME_POINTER.

<Before>
./perf probe -fn sched_slice:12 lw.weight
Fatal: DW_OP 156 is not supported.

              (^^^ DW_OP_call_frame_cfa)

<After>
./perf probe -fn sched_slice:12 lw.weight
Add new event:
probe:sched_slice (on sched_slice:12 with weight=lw.weight)

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Frederic Weisbecker <[email protected]>

---

 tools/perf/util/probe-finder.c |   14 +++++++++++---
 tools/perf/util/probe-finder.h |    1 +
 2 files changed, 12 insertions(+), 3 deletions(-)
tools/perf/util/probe-finder.c +11 -3
index 11d6592..26f02b9 100644
@@ -396,7 +396,6 @@ static void convert_location(Dwarf_Op *op, struct probe_finder *pf)
 	const char *regs;
 	struct kprobe_trace_arg *tvar = pf->tvar;
 
-	/* TODO: support CFA */
 	/* If this is based on frame buffer, set the offset */
 	if (op->atom == DW_OP_fbreg) {
 		if (pf->fb_ops == NULL)
@@ -623,11 +622,17 @@ static void convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
 	/* Get the frame base attribute/ops */
 	dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
 	ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
-	if (ret <= 0 || nops == 0)
+	if (ret <= 0 || nops == 0) {
 		pf->fb_ops = NULL;
+	} else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
+		   pf->cfi != NULL) {
+		Dwarf_Frame *frame;
+		ret = dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame);
+		DIE_IF(ret != 0);
+		dwarf_frame_cfa(frame, &pf->fb_ops, &nops);
+	}
 
 	/* Find each argument */
-	/* TODO: use dwarf_cfi_addrframe */
 	tev->nargs = pf->pev->nargs;
 	tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
 	for (i = 0; i < pf->pev->nargs; i++) {
@@ -836,6 +841,9 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
 	if (!dbg)
 		return -ENOENT;
 
+	/* Get the call frame information from this dwarf */
+	pf.cfi = dwarf_getcfi(dbg);
+
 	off = 0;
 	line_list__init(&pf.lcache);
 	/* Loop on CUs (Compilation Unit) */
tools/perf/util/probe-finder.h +1 -0
index 3564f22..ddaa2a7 100644
@@ -42,6 +42,7 @@ struct probe_finder {
 	struct list_head	lcache;		/* Line cache for lazy match */
 
 	/* For variable searching */
+	Dwarf_CFI		*cfi;		/* Call Frame Information */
 	Dwarf_Op		*fb_ops;	/* Frame base attribute */
 	struct perf_probe_arg	*pvar;		/* Current target variable */
 	struct kprobe_trace_arg	*tvar;		/* Current result variable */
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]