-/* $OpenBSD: bt_parse.y,v 1.29 2021/04/21 10:53:17 mpi Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.30 2021/04/22 09:36:39 mpi Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
struct bt_rule *br_new(struct bt_probe *, struct bt_filter *, struct bt_stmt *,
enum bt_rtype);
-struct bt_filter *bf_new(enum bt_argtype, enum bt_filtervar, int);
struct bt_probe *bp_new(const char *, const char *, const char *, int32_t);
struct bt_arg *ba_append(struct bt_arg *, struct bt_arg *);
struct bt_arg *ba_op(enum bt_argtype, struct bt_arg *, struct bt_arg *);
%type <v.string> gvar lvar
%type <v.number> staticval
-%type <v.i> fval testop binop builtin
+%type <v.i> testop binop builtin
%type <v.i> BUILTIN F_DELETE F_PRINT FUNC0 FUNC1 FUNCN OP1 OP4
%type <v.i> MOP0 MOP1
%type <v.probe> probe probename
| STRING ':' HZ ':' NUMBER { $$ = bp_new($1, "hz", NULL, $5); }
;
-
-fval : PID { $$ = B_FV_PID; }
- | TID { $$ = B_FV_TID; }
- ;
-
testop : OP_EQ { $$ = B_AT_OP_EQ; }
| OP_NE { $$ = B_AT_OP_NE; }
| OP_LE { $$ = B_AT_OP_LE; }
return br;
}
-/* Create a new event filter */
-struct bt_filter *
-bf_new(enum bt_argtype op, enum bt_filtervar var, int val)
-{
- struct bt_filter *bf;
-
- if (val < 0 || val > INT_MAX)
- errx(1, "invalid pid '%d'", val);
-
- bf = calloc(1, sizeof(*bf));
- if (bf == NULL)
- err(1, "bt_filter: calloc");
- bf->bf_evtfilter.bf_op = op;
- bf->bf_evtfilter.bf_var = var;
- bf->bf_evtfilter.bf_val = val;
-
- return bf;
-}
-
/* Create a new condition */
struct bt_filter *
bc_new(struct bt_arg *term, enum bt_argtype op, struct bt_arg *ba)
-/* $OpenBSD: bt_parser.h,v 1.15 2021/04/21 10:28:54 mpi Exp $ */
+/* $OpenBSD: bt_parser.h,v 1.16 2021/04/22 09:36:39 mpi Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
* Filters, also known as predicates, describe under which set of
* conditions a rule is executed.
*
- * Depending on their type they are performed in-kernel or when a rule
- * is evaluated. In the first case they might prevent the recording of
- * events, in the second case events might be discarded at runtime.
+ * They are performed when a rule is evaluated and events might be
+ * discarded at runtime.
*/
struct bt_filter {
- struct bt_evtfilter bf_evtfilter; /* in-kernel event filter */
struct bt_stmt *bf_condition; /* per event condition */
};
-/* $OpenBSD: btrace.c,v 1.34 2021/04/21 13:23:56 jmc Exp $ */
+/* $OpenBSD: btrace.c,v 1.35 2021/04/22 09:36:39 mpi Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
}
}
-static inline enum dt_operand
-dop2dt(enum bt_argtype op)
-{
- switch (op) {
- case B_AT_OP_EQ: return DT_OP_EQ;
- case B_AT_OP_NE: return DT_OP_NE;
- default: break;
- }
- xabort("unknown operand %d", op);
-}
-
-
-static inline enum dt_filtervar
-dvar2dt(enum bt_filtervar var)
-{
- switch (var) {
- case B_FV_PID: return DT_FV_PID;
- case B_FV_TID: return DT_FV_TID;
- case B_FV_NONE: return DT_FV_NONE;
- default: break;
- }
- xabort("unknown filter %d", var);
-}
-
-
void
rules_setup(int fd)
{
r->br_pbn = dtpi->dtpi_pbn;
dtrq->dtrq_pbn = dtpi->dtpi_pbn;
- if (r->br_filter != NULL &&
- r->br_filter->bf_condition == NULL) {
- struct bt_evtfilter *df = &r->br_filter->bf_evtfilter;
-
- dtrq->dtrq_filter.dtf_operand = dop2dt(df->bf_op);
- dtrq->dtrq_filter.dtf_variable = dvar2dt(df->bf_var);
- dtrq->dtrq_filter.dtf_value = df->bf_val;
- }
dtrq->dtrq_rate = r->br_probe->bp_rate;
SLIST_FOREACH(bs, &r->br_action, bs_next) {
va_end(ap);
}
-static inline const char *
-debug_getfiltervar(struct bt_evtfilter *df)
-{
- switch (df->bf_var) {
- case B_FV_PID: return "pid";
- case B_FV_TID: return "tid";
- case B_FV_NONE: return "";
- default:
- xabort("invalid filtervar %d", df->bf_var);
- }
-}
-
-static inline const char *
-debug_getfilterop(struct bt_evtfilter *df)
-{
- switch (df->bf_op) {
- case B_AT_OP_EQ: return "==";
- case B_AT_OP_NE: return "!=";
- default:
- xabort("invalid operand %d", df->bf_op);
- }
-}
-
void
debug_dump_filter(struct bt_rule *r)
{
if (r->br_filter != NULL) {
struct bt_stmt *bs = r->br_filter->bf_condition;
+ struct bt_arg *bop = SLIST_FIRST(&bs->bs_args);
+ struct bt_arg *a, *b;
- if (bs == NULL) {
- struct bt_evtfilter *df = &r->br_filter->bf_evtfilter;
+ a = bop->ba_value;
+ b = SLIST_NEXT(a, ba_next);
- debugx(" / %s %s %u /", debug_getfiltervar(df),
- debug_getfilterop(df), df->bf_val);
- } else {
- struct bt_arg *bop = SLIST_FIRST(&bs->bs_args);
- struct bt_arg *a, *b;
-
- a = bop->ba_value;
- b = SLIST_NEXT(a, ba_next);
-
- debugx(" / %s %s %s /", ba_name(a), ba_name(bop),
- (b != NULL) ? ba_name(b) : "NULL");
- }
+ debugx(" / %s %s %s /", ba_name(a), ba_name(bop),
+ (b != NULL) ? ba_name(b) : "NULL");
}
debugx("\n");
}