@@ -219,4 +219,5 @@ int tracefs_kprobe_raw(const char *system, const char *event,
const char *addr, const char *format);
int tracefs_kretprobe_raw(const char *system, const char *event,
const char *addr, const char *format);
+char **tracefs_get_kprobes(void);
#endif /* _TRACE_FS_H */
@@ -103,3 +103,69 @@ int tracefs_kretprobe_raw(const char *system, const char *event,
{
return insert_kprobe("r", system, event, addr, format);
}
+
+/**
+ * tracefs_get_kprobes - return a list kprobes (by group/event name)
+ *
+ * Returns a list of strings that contain the kprobes that exist
+ * in the kprobe_events files. The strings returned are in the
+ * "group/event" format.
+ * The list must be freed with tracefs_list_free().
+ * If there are no kprobes, a list is still returned, but it contains
+ * only a NULL pointer.
+ * On error, NULL is returned.
+ */
+char **tracefs_get_kprobes(void)
+{
+ char **list = NULL;
+ char *content;
+ char *saveptr;
+ char *event;
+ char *p;
+ int cnt = 0;
+
+ content = tracefs_instance_file_read(NULL, KPROBE_EVENTS, NULL);
+ if (!content)
+ return NULL;
+
+ p = strtok_r(content, ":", &saveptr);
+
+ while (p) {
+ char **tmp;
+
+ /* Failed parsing always return a failure */
+ p = strtok_r(NULL, " ", &saveptr);
+ if (!p)
+ break;
+
+ event = strdup(p);
+ if (!event)
+ goto fail;
+
+ tmp = realloc(list, sizeof(*list) * (cnt + 2));
+ if (!tmp)
+ goto fail;
+
+ list = tmp;
+ list[cnt++] = event;
+ list[cnt] = NULL;
+
+ p = strtok_r(NULL, "\n", &saveptr);
+ /* Could be end of content */
+ if (!p)
+ break;
+
+ /* p is NULL on end of content */
+ p = strtok_r(NULL, ":", &saveptr);
+ }
+
+ if (!list)
+ list = calloc(1, sizeof(*list));
+ out:
+ free(content);
+ return list;
+ fail:
+ free(list);
+ list = NULL;
+ goto out;
+}