Skip to contentSkip to conversation

error: report probe name on failed enabling error

PATCH In review Kris Van Hees 2 participants 3 messages Mar 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 error: report probe name on failed enabling error

---
 libdtrace/dt_bpf.c         | 35 +++++++++++++++++++++++------------
 libdtrace/dt_bpf.h         |  2 ++
 libdtrace/dt_error.c       |  2 ++
 libdtrace/dt_prov_uprobe.c | 15 +++------------
 4 files changed, 30 insertions(+), 24 deletions(-)
libdtrace/dt_bpf.c +23 -12
index 662fd81a..e50bb536 100644
@@ -64,6 +64,25 @@ dt_bpf_error(dtrace_hdl_t *dtp, const char *fmt, ...)
 	return dt_set_errno(dtp, EDT_BPF);
 }
 
+int
+dt_attach_error(dtrace_hdl_t *dtp, int rc, ...)
+{
+	va_list	ap, apc;
+	char	*fmt;
+
+	if (asprintf(&fmt, "Failed to enable %%s:%%s:%%s:%%s: %s",
+		     dtrace_errmsg(dtp, -rc)) > 0) {
+		va_start(ap, rc);
+		va_copy(apc, ap);
+		dt_set_errmsg(dtp, NULL, NULL, NULL, 0, fmt, ap);
+		va_end(ap);
+		dt_debug_printf("bpf", "Failed to enable %s:%s:%s:%s", apc);
+		va_end(apc);
+	}
+
+	return dt_set_errno(dtp, EDT_ENABLING_ERR);
+}
+
 int
 dt_bpf_lockmem_error(dtrace_hdl_t *dtp, const char *msg)
 {
@@ -1335,19 +1354,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 		if (prp->prov->impl->attach)
 			rc = prp->prov->impl->attach(dtp, prp, fd);
 
-		if (rc == -ENOTSUPP) {
-			char	*s;
-
-			close(fd);
-			if (asprintf(&s, "Failed to enable %s:%s:%s:%s",
-				     prp->desc->prv, prp->desc->mod,
-				     prp->desc->fun, prp->desc->prb) == -1)
-				return dt_set_errno(dtp, EDT_ENABLING_ERR);
-			dt_handle_rawerr(dtp, s);
-			free(s);
-		} else if (rc < 0) {
+		if (rc < 0) {
 			close(fd);
-			return dt_set_errno(dtp, EDT_ENABLING_ERR);
+			return dt_attach_error(dtp, rc,
+					       prp->desc->prv, prp->desc->mod,
+					       prp->desc->fun, prp->desc->prb);
 		}
 	}
 
libdtrace/dt_bpf.h +2 -0
index 85934d2d..464f0189 100644
@@ -67,6 +67,8 @@ extern int dt_perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu,
 			      int group_fd, unsigned long flags);
 extern int dt_bpf(enum bpf_cmd cmd, union bpf_attr *attr);
 
+extern int dt_attach_error(struct dtrace_hdl *, int, ...);
+
 extern int dt_bpf_gmap_create(struct dtrace_hdl *);
 extern int dt_bpf_lockmem_error(struct dtrace_hdl *dtp, const char *msg);
 
libdtrace/dt_error.c +2 -0
index 213f0d9e..6721e8e4 100644
@@ -111,6 +111,8 @@ dtrace_errmsg(dtrace_hdl_t *dtp, int error)
 
 	if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0')
 		str = dtp->dt_errmsg;
+	if (error == EDT_ENABLING_ERR && dtp != NULL && dtp->dt_errmsg[0] != '\0')
+		str = dtp->dt_errmsg;
 	else if (error == EDT_BPF && dtp != NULL && dtp->dt_errmsg[0] != '\0')
 		str = dtp->dt_errmsg;
 	else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0)
libdtrace/dt_prov_uprobe.c +3 -12
index 17f2f7ee..96a59aef 100644
@@ -385,19 +385,10 @@ static int add_probe_uprobe(dtrace_hdl_t *dtp, dt_probe_t *prp)
 	if (prp->prov->impl->attach)
 		rc = prp->prov->impl->attach(dtp, prp, fd);
 
-	if (rc == -ENOTSUPP) {
-		char    *s;
-
-		close(fd);
-		if (asprintf(&s, "Failed to enable %s:%s:%s:%s",
-			      prp->desc->prv, prp->desc->mod,
-			      prp->desc->fun, prp->desc->prb) == -1)
-			return dt_set_errno(dtp, EDT_ENABLING_ERR);
-		dt_handle_rawerr(dtp, s);
-		free(s);
-	} else if (rc < 0) {
+	if (rc < 0) {
 		close(fd);
-		return dt_set_errno(dtp, EDT_ENABLING_ERR);
+		return dt_attach_error(dtp, rc, prp->desc->prv, prp->desc->mod,
+						prp->desc->fun, prp->desc->prb);
 	}
 
 	return 0;
Signature · 1 line
2.43.5
Reviewed-by on v1 1/2
#1 lore raw

I don't 100% get our error reporting, but

A few things...

The various files need updated copyright years.

On 2/24/25 13:43, Kris Van Hees wrote:

I don't know if anyone else sees this, but this is the second patch in a few days that has gotten buried in my inbox due to a stale date.  (On Friday, I got one dated 1/24.)  Anyhow, I suppose I now know to look for such emails.

libdtrace/dt_bpf.c dt_bpf_error(dtrace_hdl_t *dtp, const char *fmt, ...) · line 71

Quoted 6 lines
libdtrace/dt_bpf.c +5 -0
+int
+dt_attach_error(dtrace_hdl_t *dtp, int rc, ...)
+{
+	va_list	ap, apc;
+	char	*fmt;

If you asprintf(&fmt), do you want a matching free() to prevent a memory leak?  (Clearly not a big deal, but...) and finally...

libdtrace/dt_error.c dtrace_errmsg(dtrace_hdl_t *dtp, int error) · line 118

Quoted 10 lines
libdtrace/dt_error.c +2 -0
@@ -111,6 +111,8 @@ dtrace_errmsg(dtrace_hdl_t *dtp, int error)
 
  	if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0')
  		str = dtp->dt_errmsg;
+	if (error == EDT_ENABLING_ERR && dtp != NULL && dtp->dt_errmsg[0] != '\0')
+		str = dtp->dt_errmsg;
  	else if (error == EDT_BPF && dtp != NULL && dtp->dt_errmsg[0] != '\0')
  		str = dtp->dt_errmsg;
  	else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0)

Should that be "else if"?  Otherwise, if error==EDT_COMPILER, you trigger both that clause and the later "else" clause.

#2 lore raw
Quoted 6 lines · Eugene Loh

I don't 100% get our error reporting, but

A few things...

The various files need updated copyright years.

Good point.

Quoted 5 lines · Kris Van Hees

I don't know if anyone else sees this, but this is the second patch in a few days that has gotten buried in my inbox due to a stale date.  (On Friday, I got one dated 1/24.)  Anyhow, I suppose I now know to look for such emails.

My fault - due to how I was sending the patches, it took the date stamp on the actual patch and this one was written end of last month, but never sent because I was still working on some other things and it wasn't needed yet.

Will avoid that in the future.

Quoted 10 lines

libdtrace/dt_bpf.c dt_bpf_error(dtrace_hdl_t *dtp, const char *fmt, ...) · line 71

Quoted 6 lines
libdtrace/dt_bpf.c +5 -0
+int
+dt_attach_error(dtrace_hdl_t *dtp, int rc, ...)
+{
+	va_list	ap, apc;
+	char	*fmt;

If you asprintf(&fmt), do you want a matching free() to prevent a memory leak?  (Clearly not a big deal, but...)
and finally...

Good catch - fixed.

Quoted 4 lines
Quoted 4 lines
libdtrace/dt_error.c +0 -0
@@ -111,6 +111,8 @@ dtrace_errmsg(dtrace_hdl_t *dtp, int error)
  	if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0')
  		str = dtp->dt_errmsg;
Quoted 8 lines

libdtrace/dt_error.c dtrace_errmsg(dtrace_hdl_t *dtp, int error) · line 118

Quoted 5 lines
libdtrace/dt_error.c +2 -0
+	if (error == EDT_ENABLING_ERR && dtp != NULL && dtp->dt_errmsg[0] != '\0')
+		str = dtp->dt_errmsg;
  	else if (error == EDT_BPF && dtp != NULL && dtp->dt_errmsg[0] != '\0')
  		str = dtp->dt_errmsg;
  	else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0)

Should that be "else if"?  Otherwise, if error==EDT_COMPILER, you trigger both that clause and the later "else" clause.

Absolutely - fixed.