From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 3/3] libtracefs: Implement tracefs_kprobe_clear_probe()
Date: Tue, 29 Jun 2021 16:53:26 -0400 [thread overview]
Message-ID: <20210629205326.117059-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210629205326.117059-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 | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/include/tracefs.h b/include/tracefs.h
index 54c461e85a2b..447821e65ce2 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -213,4 +213,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 48a4f090f041..27d4c2181404 100644
--- a/src/tracefs-kprobes.c
+++ b/src/tracefs-kprobes.c
@@ -204,3 +204,39 @@ int tracefs_kprobe_clear(bool force)
free_instance_list(list);
return ret;
}
+
+int tracefs_kprobe_clear_probe(const char *system, const char *event, bool force)
+{
+ struct instance_list *list = NULL;
+ struct instance_list **plist = &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) {
+ ret = tracefs_instances_walk(build_instances, &plist);
+ if (ret < 0)
+ goto out;
+
+ ret = disable_events(system, event, list);
+ if (ret < 0)
+ goto out;
+ }
+
+ ret = tracefs_instance_file_append(NULL, KPROBE_EVENTS, content);
+ out:
+ free(content);
+ free_instance_list(list);
+
+ return ret < 0 ? -1 : 0;
+}
--
2.30.2
prev parent reply other threads:[~2021-06-29 20:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 20:53 [PATCH 0/3] libtracefs: Facilitate adding and removing kprobes Steven Rostedt
2021-06-29 20:53 ` [PATCH 1/3] libtracefs: Implement tracefs_kprobe_raw() Steven Rostedt
2021-06-29 20:53 ` [PATCH 2/3] libtracefs: Implement tracefs_kprobe_clear() to remove all kprobes Steven Rostedt
2021-06-29 20:53 ` 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=20210629205326.117059-4-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/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).