From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964799AbbGWVw7 (ORCPT ); Thu, 23 Jul 2015 17:52:59 -0400 Received: from mail.kernel.org ([198.145.29.136]:42733 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753850AbbGWVwx (ORCPT ); Thu, 23 Jul 2015 17:52:53 -0400 Date: Thu, 23 Jul 2015 18:52:46 -0300 From: Arnaldo Carvalho de Melo To: Steven Rostedt Cc: David Ahern , Adrian Hunter , Borislav Petkov , Frederic Weisbecker , Jiri Olsa , Namhyung Kim , Stephane Eranian , Ingo Molnar , Linux Kernel Mailing List Subject: Re: [RFC PATCH] tools lib traceevent: Allow setting an alternative symbol resolver Message-ID: <20150723215246.GF3154@kernel.org> References: <20150723150433.GA3154@kernel.org> <20150723122130.716df9fe@gandalf.local.home> <20150723172554.GC3154@kernel.org> <20150723141039.1bd48bf2@gandalf.local.home> <20150723141133.4065321e@gandalf.local.home> <20150723212536.GE3154@kernel.org> <20150723173524.057a5969@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150723173524.057a5969@gandalf.local.home> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Jul 23, 2015 at 05:35:24PM -0400, Steven Rostedt escreveu: > On Thu, 23 Jul 2015 18:25:36 -0300 > Arnaldo Carvalho de Melo wrote: > > > Like this? > > Yep, but some comments. > > > +int pevent_set_function_resolver(struct pevent *pevent, > > + pevent_func_resolver_t *func, void *priv) > > +{ > > + struct func_resolver *resolver = malloc(sizeof(*resolver)); > > + > > + if (resolver == NULL) { > > + errno = ENOMEM; > > Why set errno, wont a failed malloc set it for us? Humm, I thought about that, I've read malloc's man page and it doesn't mention that... in the return section, but later, in NOTES, it says UNIX98 requires that and glibc does it, so I'm ditching this... > > + return -1; > > + } > > + > > + resolver->func = func; > > + resolver->priv = priv; > > + > > + free(pevent->func_resolver); > > + pevent->func_resolver = resolver; > > Also I wonder if we should add a way to clear the resolver. That is, > you want to use the default resolver? I am adding a reset_function_resolver(pevent); > Not really a necessity, as I don't see any current programs using it, > but it would complete the interface. > > -- Steve > > > + > > + return 0; > > +} > > + > > +static struct func_map * > > +find_func(struct pevent *pevent, unsigned long long addr) > > +{ > > + struct func_map *map; > > + > > + if (!pevent->func_resolver) > > + return __find_func(pevent, addr); > > + > > + map = &pevent->func_resolver->map; > > + map->mod = NULL; > > + map->addr = addr; > > + map->func = pevent->func_resolver->func(pevent->func_resolver->priv, > > + &map->addr, &map->mod); > > + if (map->func == NULL) > > + return NULL; > > + > > + return map; > > +} > > + > > /** > > * pevent_find_function - find a function by a given address > > * @pevent: handle for the pevent > > @@ -6564,6 +6618,7 @@ void pevent_free(struct pevent *pevent) > > free(pevent->trace_clock); > > free(pevent->events); > > free(pevent->sort_events); > > + free(pevent->func_resolver); > > > > free(pevent); > > } > > diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h > > index 063b1971eb35..416e1bd9fe33 100644 > > --- a/tools/lib/traceevent/event-parse.h > > +++ b/tools/lib/traceevent/event-parse.h > > @@ -453,6 +453,10 @@ struct cmdline_list; > > struct func_map; > > struct func_list; > > struct event_handler; > > +struct func_resolver; > > + > > +typedef char *(pevent_func_resolver_t)(void *priv, > > + unsigned long long *addrp, char **modp); > > > > struct pevent { > > int ref_count; > > @@ -481,6 +485,7 @@ struct pevent { > > int cmdline_count; > > > > struct func_map *func_map; > > + struct func_resolver *func_resolver; > > struct func_list *funclist; > > unsigned int func_count; > > > > @@ -611,6 +616,8 @@ enum trace_flag_type { > > TRACE_FLAG_SOFTIRQ = 0x10, > > }; > > > > +int pevent_set_function_resolver(struct pevent *pevent, > > + pevent_func_resolver_t *func, void *priv); > > int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); > > int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock); > > int pevent_register_function(struct pevent *pevent, char *name,