linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH v2 4/4] libtracefs: Implement tracefs_kprobe_clear_probe()
Date: Wed, 30 Jun 2021 11:47:29 -0400	[thread overview]
Message-ID: <20210630154729.129873-5-rostedt@goodmis.org> (raw)
In-Reply-To: <20210630154729.129873-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add the function tracefs_kprobe_clear_probe() that will remove a single
kprobe. If the @force parameter is set, it will disable that probe in all
instances (including the top level instance) before removing it.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs.h     |  1 +
 src/tracefs-kprobes.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/tracefs.h b/include/tracefs.h
index 19b9b49d2dae..d7980c773b3d 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -218,4 +218,5 @@ void tracefs_trace_pipe_stop(struct tracefs_instance *instance);
 int tracefs_kprobe_raw(const char *system, const char *event,
 		       const char *addr, const char *format);
 int tracefs_kprobe_clear(bool force);
+int tracefs_kprobe_clear_probe(const char *system, const char *event, bool force);
 #endif /* _TRACE_FS_H */
diff --git a/src/tracefs-kprobes.c b/src/tracefs-kprobes.c
index a6faf69fc010..6f3fbac35d76 100644
--- a/src/tracefs-kprobes.c
+++ b/src/tracefs-kprobes.c
@@ -184,3 +184,32 @@ int tracefs_kprobe_clear(bool force)
 	free(content);
 	return ret;
 }
+
+int tracefs_kprobe_clear_probe(const char *system, const char *event, bool force)
+{
+	char **instance_list;
+	char *content;
+	int ret;
+
+	if (!system)
+		system = "kprobes";
+
+	ret = asprintf(&content, "-:%s/%s", system, event);
+	if (ret < 0)
+		return -1;
+
+	/*
+	 * Since we know we are disabling a specific event, try
+	 * to disable it first before clearing it.
+	 */
+	if (force) {
+		instance_list = tracefs_instances(NULL);
+		disable_events(system, event, instance_list);
+		tracefs_list_free(instance_list);
+	}
+
+	ret = tracefs_instance_file_append(NULL, KPROBE_EVENTS, content);
+	free(content);
+
+	return ret < 0 ? -1 : 0;
+}
-- 
2.30.2


      parent reply	other threads:[~2021-06-30 15:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30 15:47 [PATCH v2 0/4] libtracefs: Facilitate adding and removing kprobes Steven Rostedt
2021-06-30 15:47 ` [PATCH v2 1/4] libtracefs: Implement tracefs_instances() Steven Rostedt
2021-06-30 15:47 ` [PATCH v2 2/4] libtracefs: Implement tracefs_kprobe_raw() Steven Rostedt
2021-06-30 19:46   ` Yordan Karadzhov (VMware)
2021-06-30 19:53     ` Steven Rostedt
2021-06-30 20:05       ` Yordan Karadzhov (VMware)
2021-06-30 15:47 ` [PATCH v2 3/4] libtracefs: Implement tracefs_kprobe_clear() to remove all kprobes Steven Rostedt
2021-06-30 15:47 ` Steven Rostedt [this message]

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=20210630154729.129873-5-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --subject='Re: [PATCH v2 4/4] libtracefs: Implement tracefs_kprobe_clear_probe()' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox