tools lib traceevent: Add pevent_print_func_field() helper function
authorSteven Rostedt <srostedt@redhat.com>
Fri, 1 Nov 2013 21:54:00 +0000 (17:54 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Nov 2013 17:36:49 +0000 (14:36 -0300)
Add the pevent_print_func_field() that will look up a field that is
expected to be a function pointer, and it will print the function name
and offset of the address given by the field.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20131101215501.869542711@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/event-parse.c
tools/lib/traceevent/event-parse.h

index fc6f35f591f688347f72e1d6eeaea163f17089e2..8f450adaa9c27107d6ecc42bed6b5702833babe9 100644 (file)
@@ -5367,6 +5367,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
        return -1;
 }
 
+/**
+ * pevent_print_func_field - print a field and a format for function pointers
+ * @s: The seq to print to
+ * @fmt: The printf format to print the field with.
+ * @event: the event that the field is for
+ * @name: The name of the field
+ * @record: The record with the field name.
+ * @err: print default error if failed.
+ *
+ * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
+ */
+int pevent_print_func_field(struct trace_seq *s, const char *fmt,
+                           struct event_format *event, const char *name,
+                           struct pevent_record *record, int err)
+{
+       struct format_field *field = pevent_find_field(event, name);
+       struct pevent *pevent = event->pevent;
+       unsigned long long val;
+       struct func_map *func;
+       char tmp[128];
+
+       if (!field)
+               goto failed;
+
+       if (pevent_read_number_field(field, record->data, &val))
+               goto failed;
+
+       func = find_func(pevent, val);
+
+       if (func)
+               snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
+       else
+               sprintf(tmp, "0x%08llx", val);
+
+       return trace_seq_printf(s, fmt, tmp);
+
+ failed:
+       if (err)
+               trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
+       return -1;
+}
+
 static void free_func_handle(struct pevent_function_handler *func)
 {
        struct pevent_func_params *params;
index dc8539ee948504ca6c6f5d13cb19d881544671de..8d73d2594f65de39c4a0c9d35c976847e30ab0fe 100644 (file)
@@ -569,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
                           struct event_format *event, const char *name,
                           struct pevent_record *record, int err);
 
+int pevent_print_func_field(struct trace_seq *s, const char *fmt,
+                          struct event_format *event, const char *name,
+                          struct pevent_record *record, int err);
+
 int pevent_register_event_handler(struct pevent *pevent, int id,
                                  const char *sys_name, const char *event_name,
                                  pevent_event_handler_func func, void *context);