linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: y.karadz@gmail.com, linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v3 05/11] libtracefs: Change tracefs_kprobe_info API
Date: Wed, 3 Nov 2021 23:06:25 -0400	[thread overview]
Message-ID: <20211103230625.284fb344@rorschach.local.home> (raw)
In-Reply-To: <20211103154417.246999-6-tz.stoyanov@gmail.com>

On Wed,  3 Nov 2021 17:44:11 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> -enum tracefs_kprobe_type tracefs_kprobe_info(const char *group, const char *event,
> -					     char **type, char **addr, char **format)
> +enum tracefs_dynevent_type tracefs_kprobe_info(struct tracefs_dynevent *kprobe,
> +					       char **system, char **event,
> +					       char **prefix, char **addr, char **format)
>  {
> -	enum tracefs_kprobe_type rtype = TRACEFS_ALL_KPROBES;
> -	char *saveptr;
> -	char *content;
> -	char *system;
> -	char *probe;
> -	char *ktype;
> -	char *kaddr;
> -	char *kfmt;
> -	int ret;
> -
> -	if (!group)
> -		group = KPROBE_DEFAULT_GROUP;
> -
> -	if (type)
> -		*type = NULL;
> +	if (system)
> +		*system = NULL;
> +	if (event)
> +		*event = NULL;
> +	if (prefix)
> +		*prefix = NULL;
>  	if (addr)
>  		*addr = NULL;
>  	if (format)
>  		*format = NULL;
>  
> -	content = tracefs_instance_file_read(NULL, KPROBE_EVENTS, NULL);
> -	if (!content)
> -		return rtype;
> -
> -	ret = parse_kprobe(content, &saveptr, &ktype, &system, &probe,
> -			   &kaddr, &kfmt);
> -
> -	while (!ret) {
> -
> -		if (!strcmp(system, group) && !strcmp(probe, event)) {
> -			if (type)
> -				*type = strdup(ktype);
> -			if (addr)
> -				*addr = strdup(kaddr);
> -			if (format)
> -				*format = strdup(kfmt);
> +	if (!kprobe)
> +		return TRACEFS_DYNEVENT_MAX;
>  
> -			switch (*ktype) {
> -			case 'p': rtype = TRACEFS_KPROBE; break;
> -			case 'r': rtype = TRACEFS_KRETPROBE; break;
> -			}
> -			break;
> +	if (system) {
> +		if (kprobe->system) {
> +			*system = strdup(kprobe->system);
> +			if (!(*system))
> +				goto error;
>  		}
> -		ret = parse_kprobe(NULL, &saveptr, &ktype, &system, &probe,
> -				   &kaddr, &kfmt);
>  	}
> -	free(content);
> -	return rtype;
> +	if (event) {
> +		*event = strdup(kprobe->event);
> +		if (!(*event))
> +			goto error;
> +	}
> +	if (prefix) {
> +		*prefix = strdup(kprobe->prefix);
> +		if (!(*prefix))
> +			goto error;
> +	}
> +	if (addr && kprobe->address) {
> +		*addr = strdup(kprobe->address);
> +		if (!(*addr))
> +			goto error;
> +	}
> +	if (format && kprobe->format) {
> +		*format = strdup(kprobe->format);
> +		if (!(*format))
> +			goto error;
> +	}
> +
> +	return kprobe->type;
> +
> +error:
> +	if (system)
> +		free(*system);
> +	if (event)
> +		free(*event);
> +	if (prefix)
> +		free(*prefix);
> +	if (addr)
> +		free(*addr);
> +	if (format)
> +		free(*format);
> +	return TRACEFS_DYNEVENT_MAX;
>  }



The above can be shorten to just:

enum tracefs_dynevent_type tracefs_kprobe_info(struct tracefs_dynevent *kprobe,
					       char **system, char **event,
					       char **prefix, char **addr, char **format)
{
	char **lvalues[] = { system, event, prefix, addr, format };
	char **rvalues[] = { &kprobe->system, &kprobe->event, &kprobe->prefix,
		&kprobe->address, &kprobe->format };
	int i;

	if (!kprobe)
		return TRACEFS_DYNEVENT_MAX;

	for (i = 0; i < 5; i++) {
		if (lvalues[i]) {
			if (*rvalues[i]) {
				*lvalues[i] = strdup(*rvalues[i]);
				if (!*lvalues[i])
					goto error;
			} else {
				*lvalues[i] = NULL;
			}
		}
	}

	return kprobe->type;

error:
	for (i--; i >= 0; i--) {
		if (lvalues[i])
			free(*lvalues[i]);
	}

	return TRACEFS_DYNEVENT_MAX;
}


 ;-)

-- Steve

  reply	other threads:[~2021-11-04  3:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 15:44 [PATCH v3 00/11] libtracefs dynamic events support Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 01/11] libtracefs: Add new public macros for bits manipulations Tzvetomir Stoyanov (VMware)
2021-11-03 16:24   ` Steven Rostedt
2021-11-03 16:34     ` Tzvetomir Stoyanov
2021-11-03 16:47       ` Steven Rostedt
2021-11-03 15:44 ` [PATCH v3 02/11] libtracefs: New APIs for dynamic events Tzvetomir Stoyanov (VMware)
2021-11-03 17:03   ` Steven Rostedt
2021-11-03 22:17     ` Steven Rostedt
2021-11-04  0:56       ` Steven Rostedt
2021-11-04  1:17     ` Steven Rostedt
2021-11-04  1:26     ` Steven Rostedt
2021-11-03 22:18   ` Steven Rostedt
2021-11-04  2:27   ` Steven Rostedt
2021-11-03 15:44 ` [PATCH v3 03/11] libtracefs: New APIs for kprobe allocation Tzvetomir Stoyanov (VMware)
2021-11-04  2:40   ` Steven Rostedt
2021-11-03 15:44 ` [PATCH v3 04/11] libtracefs: Remove redundant kprobes APIs Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 05/11] libtracefs: Change tracefs_kprobe_info API Tzvetomir Stoyanov (VMware)
2021-11-04  3:06   ` Steven Rostedt [this message]
2021-11-03 15:44 ` [PATCH v3 06/11] libtracefs: Reimplement kprobe raw APIs Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 07/11] libtracefs: Extend kprobes unit test Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 08/11] libtracefs: Rename tracefs_synth_init API Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 09/11] libtracefs: Use the internal dynamic events API when creating synthetic events Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 10/11] libtracefs: Update kprobes man pages Tzvetomir Stoyanov (VMware)
2021-11-03 15:44 ` [PATCH v3 11/11] libtracefs: Document dynamic events APIs Tzvetomir Stoyanov (VMware)

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=20211103230625.284fb344@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    --cc=y.karadz@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).