-/* $OpenBSD: btrace.c,v 1.72 2023/08/13 09:52:47 mpi Exp $ */
+/* $OpenBSD: btrace.c,v 1.73 2023/08/15 20:51:45 dv Exp $ */
/*
* Copyright (c) 2019 - 2021 Martin Pieuchot <mpi@openbsd.org>
struct dtioc_arg_info **dt_args; /* array of probe arguments */
struct dt_evt bt_devt; /* fake event for BEGIN/END */
+#define DTEV_PBN_BEGINEND 0 /* fake probe number for BEGIN/END */
uint64_t bt_filtered; /* # of events filtered out */
struct syms *kelf, *uelf;
err(1, NULL);
}
+ assert(dtpi->dtpi_pbn > 0);
if (dt_args[dtpi->dtpi_pbn - 1] != NULL)
return;
dtpi->dtpi_name);
if (strncmp(dtpi->dtpi_prov, "tracepoint", DTNAMESIZE) == 0) {
dtai_cache(fd, dtpi);
+ assert(dtpi->dtpi_pbn > 0);
dtai = dt_args[dtpi->dtpi_pbn - 1];
printf("(");
for (j = 0; j < dtpi->dtpi_nargs; j++, dtai++) {
kelf = kelf_open(_PATH_KSYMS);
/* Initialize "fake" event for BEGIN/END */
- bt_devt.dtev_pbn = -1;
+ bt_devt.dtev_pbn = DTEV_PBN_BEGINEND;
strlcpy(bt_devt.dtev_comm, getprogname(), sizeof(bt_devt.dtev_comm));
bt_devt.dtev_pid = getpid();
bt_devt.dtev_tid = getthrid();
if (bp->bp_type != B_PT_PROBE ||
bp->bp_pbn != dtev->dtev_pbn)
continue;
-
+ assert(dtev->dtev_pbn > 0);
dtai_cache(fd, &dt_dtpis[dtev->dtev_pbn - 1]);
rule_eval(r, dtev);
}
const char *argtype, *fmt;
long value;
- dtai = dt_args[dtev->dtev_pbn - 1];
argn = dat - B_AT_BI_ARG0;
+
+ if (dtev->dtev_pbn == DTEV_PBN_BEGINEND)
+ errx(1, "arg%d builtin is not valid in BEGIN or END actions",
+ argn);
+ dtai = dt_args[dtev->dtev_pbn - 1];
argtype = dtai[argn].dtai_argtype;
if (strncmp(argtype, "int", DTNAMESIZE) == 0) {
value = dtev->dtev_args[argn];
}
- snprintf(buf, sizeof(buf), fmt, dtev->dtev_args[argn]);
+ snprintf(buf, sizeof(buf), fmt, value);
return buf;
}
str = buf;
break;
case B_AT_BI_PROBE:
+ assert(dtev->dtev_pbn > 0);
dtpi = &dt_dtpis[dtev->dtev_pbn - 1];
if (dtpi != NULL)
snprintf(buf, sizeof(buf), "%s:%s:%s",