summaryrefslogtreecommitdiff
path: root/usr.sbin/btrace
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2021-11-12 16:57:25 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2021-11-12 16:57:25 +0000
commitf53c0cc9d2f6e71d48358d00fa10e47f9429d01b (patch)
tree8f535e307204ffaf7fbca5b7734dd21fb53314ca /usr.sbin/btrace
parent4c7ded1f6a1805d2a85944a15c14ac5bfc592328 (diff)
Implement the probe variable. Can be used for example with
@map[probe] = count(); OK mpi@
Diffstat (limited to 'usr.sbin/btrace')
-rw-r--r--usr.sbin/btrace/bt.56
-rw-r--r--usr.sbin/btrace/bt_parse.y3
-rw-r--r--usr.sbin/btrace/bt_parser.h3
-rw-r--r--usr.sbin/btrace/btrace.c41
-rw-r--r--usr.sbin/btrace/map.c3
5 files changed, 50 insertions, 6 deletions
diff --git a/usr.sbin/btrace/bt.5 b/usr.sbin/btrace/bt.5
index 3912c231adf..f26355c70aa 100644
--- a/usr.sbin/btrace/bt.5
+++ b/usr.sbin/btrace/bt.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bt.5,v 1.12 2021/10/03 22:01:48 dv Exp $
+.\" $OpenBSD: bt.5,v 1.13 2021/11/12 16:57:24 claudio Exp $
.\"
.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 3 2021 $
+.Dd $Mdocdate: November 12 2021 $
.Dt BT 5
.Os
.Sh NAME
@@ -105,6 +105,8 @@ Kernel stack of the current thread.
Timestamp of the event in nanoseconds.
.It Va pid
Process ID of the current thread.
+.It Va probe
+Full name of the probe.
.It Va retval
Return value of the traced syscall.
.It Va tid
diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y
index f519efd87fd..dd4b0c40456 100644
--- a/usr.sbin/btrace/bt_parse.y
+++ b/usr.sbin/btrace/bt_parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: bt_parse.y,v 1.44 2021/10/03 22:01:48 dv Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.45 2021/11/12 16:57:24 claudio Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
@@ -717,6 +717,7 @@ lookup(char *s)
{ "pid", BUILTIN, B_AT_BI_PID },
{ "print", F_PRINT, B_AC_PRINT },
{ "printf", FUNCN, B_AC_PRINTF },
+ { "probe", BUILTIN, B_AT_BI_PROBE },
{ "retval", BUILTIN, B_AT_BI_RETVAL },
{ "str", STR, B_AT_FN_STR },
{ "sum", MOP1, B_AT_MF_SUM },
diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h
index 6ba180c4379..4c6165df130 100644
--- a/usr.sbin/btrace/bt_parser.h
+++ b/usr.sbin/btrace/bt_parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bt_parser.h,v 1.21 2021/10/03 22:01:48 dv Exp $ */
+/* $OpenBSD: bt_parser.h,v 1.22 2021/11/12 16:57:24 claudio Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
@@ -147,6 +147,7 @@ struct bt_arg {
B_AT_BI_ARG9,
B_AT_BI_ARGS,
B_AT_BI_RETVAL,
+ B_AT_BI_PROBE,
B_AT_FN_STR, /* str($1); str($1, 3); */
diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c
index 899ac24ff22..87fc5c1199c 100644
--- a/usr.sbin/btrace/btrace.c
+++ b/usr.sbin/btrace/btrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btrace.c,v 1.59 2021/10/24 14:18:58 mpi Exp $ */
+/* $OpenBSD: btrace.c,v 1.60 2021/11/12 16:57:24 claudio Exp $ */
/*
* Copyright (c) 2019 - 2021 Martin Pieuchot <mpi@openbsd.org>
@@ -256,6 +256,18 @@ read_btfile(const char *filename, size_t *len)
return fcontent;
}
+static int
+dtpi_cmp(const void *a, const void *b)
+{
+ const struct dtioc_probe_info *ai = a, *bi = b;
+
+ if (ai->dtpi_pbn > bi->dtpi_pbn)
+ return 1;
+ if (ai->dtpi_pbn < bi->dtpi_pbn)
+ return -1;
+ return 0;
+}
+
void
dtpi_cache(int fd)
{
@@ -276,6 +288,8 @@ dtpi_cache(int fd)
dtpr.dtpr_probes = dt_dtpis;
if (ioctl(fd, DTIOCGPLIST, &dtpr))
err(1, "DTIOCGPLIST");
+
+ qsort(dt_dtpis, dt_ndtpi, sizeof(*dt_dtpis), dtpi_cmp);
}
void
@@ -351,6 +365,15 @@ dtpi_get_by_value(const char *prov, const char *func, const char *name)
return NULL;
}
+static struct dtioc_probe_info *
+dtpi_get_by_id(unsigned int pbn)
+{
+ struct dtioc_probe_info d;
+
+ d.dtpi_pbn = pbn;
+ return bsearch(&d, dt_dtpis, dt_ndtpi, sizeof(*dt_dtpis), dtpi_cmp);
+}
+
void
rules_do(int fd)
{
@@ -1263,6 +1286,8 @@ ba_name(struct bt_arg *ba)
return "args";
case B_AT_BI_RETVAL:
return "retval";
+ case B_AT_BI_PROBE:
+ return "probe";
case B_AT_FN_STR:
return "str";
case B_AT_OP_PLUS:
@@ -1372,6 +1397,9 @@ ba2long(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_BI_RETVAL:
val = dtev->dtev_retval[0];
break;
+ case B_AT_BI_PROBE:
+ val = dtev->dtev_pbn;
+ break;
case B_AT_OP_PLUS ... B_AT_OP_LOR:
val = baexpr2long(ba, dtev);
break;
@@ -1390,6 +1418,7 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev)
{
static char buf[STRLEN];
struct bt_var *bv;
+ struct dtioc_probe_info *dtpi;
const char *str;
buf[0] = '\0';
@@ -1436,6 +1465,15 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev)
snprintf(buf, sizeof(buf), "%ld", (long)dtev->dtev_retval[0]);
str = buf;
break;
+ case B_AT_BI_PROBE:
+ dtpi = dtpi_get_by_id(dtev->dtev_pbn);
+ if (dtpi != NULL)
+ snprintf(buf, sizeof(buf), "%s:%s:%s",
+ dtpi->dtpi_prov, dtpi_func(dtpi), dtpi->dtpi_name);
+ else
+ snprintf(buf, sizeof(buf), "%u", dtev->dtev_pbn);
+ str = buf;
+ break;
case B_AT_MAP:
bv = ba->ba_value;
/* Unitialized map */
@@ -1510,6 +1548,7 @@ ba2dtflags(struct bt_arg *ba)
flags |= DTEVT_FUNCARGS;
break;
case B_AT_BI_RETVAL:
+ case B_AT_BI_PROBE:
break;
case B_AT_MF_COUNT:
case B_AT_MF_MAX:
diff --git a/usr.sbin/btrace/map.c b/usr.sbin/btrace/map.c
index 9ec0fa3b7d9..d2afab11aa0 100644
--- a/usr.sbin/btrace/map.c
+++ b/usr.sbin/btrace/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.17 2021/09/09 06:58:39 mpi Exp $ */
+/* $OpenBSD: map.c,v 1.18 2021/11/12 16:57:24 claudio Exp $ */
/*
* Copyright (c) 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -144,6 +144,7 @@ map_insert(struct map *map, const char *key, struct bt_arg *bval,
case B_AT_BI_NSECS:
case B_AT_BI_ARG0 ... B_AT_BI_ARG9:
case B_AT_BI_RETVAL:
+ case B_AT_BI_PROBE:
free(mep->mval);
mep->mval = ba_new(ba2long(bval, dtev), B_AT_LONG);
break;