From 9751739cb303784348f0a47212eb2fd7146d55f6 Mon Sep 17 00:00:00 2001 From: mpi Date: Sat, 24 Feb 2024 19:42:54 +0000 Subject: [PATCH] Check for builtins used inside tuple to ask the kernel to copyout specific data. Allow to save stacktrace and process name in tuples. --- usr.sbin/btrace/btrace.c | 108 ++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index 5e5f23f2f2a..4450e98b83a 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btrace.c,v 1.87 2024/02/24 17:05:59 mpi Exp $ */ +/* $OpenBSD: btrace.c,v 1.88 2024/02/24 19:42:54 mpi Exp $ */ /* * Copyright (c) 2019 - 2023 Martin Pieuchot @@ -1814,6 +1814,58 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev) return str; } +int +ba2flags(struct bt_arg *ba) +{ + int flags = 0; + + assert(ba->ba_type != B_AT_MAP); + assert(ba->ba_type != B_AT_TUPLE); + + switch (ba->ba_type) { + case B_AT_STR: + case B_AT_LONG: + case B_AT_TMEMBER: + case B_AT_VAR: + case B_AT_HIST: + case B_AT_NIL: + break; + case B_AT_BI_KSTACK: + flags |= DTEVT_KSTACK; + break; + case B_AT_BI_USTACK: + flags |= DTEVT_USTACK; + break; + case B_AT_BI_COMM: + flags |= DTEVT_EXECNAME; + break; + case B_AT_BI_CPU: + case B_AT_BI_PID: + case B_AT_BI_TID: + case B_AT_BI_NSECS: + break; + case B_AT_BI_ARG0 ... B_AT_BI_ARG9: + 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: + case B_AT_MF_MIN: + case B_AT_MF_SUM: + case B_AT_FN_STR: + break; + case B_AT_OP_PLUS ... B_AT_OP_LOR: + flags |= ba2dtflags(ba->ba_value); + break; + default: + xabort("invalid argument type %d", ba->ba_type); + } + + return flags; +} + /* * Return dt(4) flags indicating which data should be recorded by the * kernel, if any, for a given `ba'. @@ -1830,51 +1882,15 @@ ba2dtflags(struct bt_arg *ba) do { if (ba->ba_type == B_AT_MAP) - bval = ba->ba_key; - else - bval = ba; - - switch (bval->ba_type) { - case B_AT_STR: - case B_AT_LONG: - case B_AT_TUPLE: - case B_AT_TMEMBER: - case B_AT_VAR: - case B_AT_HIST: - case B_AT_NIL: - break; - case B_AT_BI_KSTACK: - flags |= DTEVT_KSTACK; - break; - case B_AT_BI_USTACK: - flags |= DTEVT_USTACK; - break; - case B_AT_BI_COMM: - flags |= DTEVT_EXECNAME; - break; - case B_AT_BI_CPU: - case B_AT_BI_PID: - case B_AT_BI_TID: - case B_AT_BI_NSECS: - break; - case B_AT_BI_ARG0 ... B_AT_BI_ARG9: - 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: - case B_AT_MF_MIN: - case B_AT_MF_SUM: - case B_AT_FN_STR: - break; - case B_AT_OP_PLUS ... B_AT_OP_LOR: - flags |= ba2dtflags(bval->ba_value); - break; - default: - xabort("invalid argument type %d", bval->ba_type); - } + flags |= ba2flags(ba->ba_key); + else if (ba->ba_type == B_AT_TUPLE) { + bval = ba->ba_value; + do { + flags |= ba2flags(bval); + } while ((bval = SLIST_NEXT(bval, ba_next)) != NULL); + } else + flags |= ba2flags(ba); + } while ((ba = SLIST_NEXT(ba, ba_next)) != NULL); --recursions; -- 2.20.1