libtracefs: Facilitate adding and removing kprobes
cover libtracefs: Facilitate adding and removing kprobes
Add a tracefs_kprobe_raw() to facilitate adding kprobe events. It's denoted as "raw" because it still requires knowing the complex format of a kprobe, but at least it helps with other formats:
p:[[system/]event] addr fmt
The user only needs to know the "fmt" part above, and not worry about what file to open, or how to open it.
Also add a tracefs_kprobe_clear() to clear all kprobes and a tracefs_kprobe_clear_probe() to clear an individual kprobe. Both have a "force" parameter, that if set, will then try to disable the kprobe in all instances (including the top) and then remove the kprobe(s).
(Man pages coming after this).
Steven Rostedt (VMware) (3):
libtracefs: Implement tracefs_kprobe_raw()
libtracefs: Implement tracefs_kprobe_clear() to remove all kprobes
libtracefs: Implement tracefs_kprobe_clear_probe()
include/tracefs.h | 5 + src/Makefile | 1 + src/tracefs-kprobes.c | 242 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 src/tracefs-kprobes.c
Signature · 1 line
2.30.2
PATCH 1/3 libtracefs: Implement tracefs_kprobe_raw()
From: "Steven Rostedt (VMware)" <[email protected]>
Add a function to facilitate creating a kprobe event. It has the "raw" in its name because it still requires knowing the format of the kprobe. But does handle the kprobe naming better and writing to the kprobe_event file.
--- include/tracefs.h | 4 +++ src/Makefile | 1 + src/tracefs-kprobes.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/tracefs-kprobes.c
include/tracefs.h +4 -0
@@ -209,4 +209,8 @@ int tracefs_tracer_clear(struct tracefs_instance *instance);ssize_t tracefs_trace_pipe_stream (int fd,struct tracefs_instance *instance,int flags);ssize_t tracefs_trace_pipe_print (struct tracefs_instance *instance,int flags);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); +#endif /* _TRACE_FS_H */
src/Makefile +1 -0
@@ -8,6 +8,7 @@ OBJS += tracefs-instance.o OBJS += tracefs-events.o OBJS += tracefs-tools.o OBJS += tracefs-marker.o +OBJS += tracefs-kprobes.o OBJS := $(OBJS:%.o=$(bdir)/%.o) DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
src/tracefs-kprobes.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 2/3 libtracefs: Implement tracefs_kprobe_clear() to remove all kprobes
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
A call to tracefs_kprobe_clear() will attempt to disable all kprobes. If any kprobe is set, and the @force parameter is set, it will fail with errno set to EBUSY. If @force is set, then it will attempt to disable all the defined kprobe events and then clear it.
--- include/tracefs.h | 2 +- src/tracefs-kprobes.c | 136 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-)
include/tracefs.h +1 -1
@@ -212,5 +212,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);#endif /* _TRACE_FS_H */
src/tracefs-kprobes.c +136 -0
139 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 3/3 libtracefs: Implement tracefs_kprobe_clear_probe()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
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.
--- include/tracefs.h | 1 + src/tracefs-kprobes.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
include/tracefs.h +1 -0
@@ -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 */
src/tracefs-kprobes.c +36 -0
@@ -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 ; +}
Signature · 1 line
2.30.2