@@ -148,38 +148,28 @@ void tracefs_kprobe_free(struct tracefs_dynevent *kprobe)
dynevent_free(kprobe);
}
-
-static int insert_kprobe(const char *type, const char *system,
- const char *event, const char *addr,
- const char *format)
+static int kprobe_raw(enum trace_dynevent_type type, const char *system,
+ const char *event, const char *addr, const char *format)
{
- char *str;
+ static struct tracefs_dynevent *kp;
int ret;
- if (!tracefs_file_exists(NULL, KPROBE_EVENTS))
- return -1;
-
- errno = EBADMSG;
- if (!addr || !format)
+ kp = kprobe_alloc(type, system, event, addr, format);
+ if (!kp)
return -1;
- if (!event)
- event = addr;
-
- if (system)
- ret = asprintf(&str, "%s:%s/%s %s %s\n",
- type, system, event, addr, format);
- else
- ret = asprintf(&str, "%s:%s %s %s\n",
- type, event, addr, format);
-
- if (ret < 0)
- return -1;
+ if (type == TRACE_DYNEVENT_KRETPROBE) {
+ free(kp->prefix);
+ kp->prefix = NULL;
+ ret = asprintf(&kp->prefix, "r:");
+ if (ret < 0)
+ return ret;
+ }
- ret = tracefs_instance_file_append(NULL, KPROBE_EVENTS, str);
- free(str);
+ ret = dynevent_create(kp);
+ dynevent_free(kp);
- return ret < 0 ? ret : 0;
+ return ret;
}
/**
@@ -205,7 +195,7 @@ static int insert_kprobe(const char *type, const char *system,
int tracefs_kprobe_raw(const char *system, const char *event,
const char *addr, const char *format)
{
- return insert_kprobe("p", system, event, addr, format);
+ return kprobe_raw(TRACE_DYNEVENT_KPROBE, system, event, addr, format);
}
/**
@@ -231,7 +221,7 @@ int tracefs_kprobe_raw(const char *system, const char *event,
int tracefs_kretprobe_raw(const char *system, const char *event,
const char *addr, const char *format)
{
- return insert_kprobe("r", system, event, addr, format);
+ return kprobe_raw(TRACE_DYNEVENT_KRETPROBE, system, event, addr, format);
}
/**
In order to unify the code and use the new dynamic event helpers, these kprobe APIs are rewritten: kracefs_kprobe_raw() kracefs_kretprobe_raw() The definition and logic of the APIs remain the same. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- src/tracefs-kprobes.c | 44 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 27 deletions(-)