[DTrace-devel] [PATCH v2 05/22] Set the ERROR PRID in BPF code
Kris Van Hees
kris.van.hees at oracle.com
Fri Sep 13 19:50:09 UTC 2024
On Fri, Sep 13, 2024 at 01:15:35PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> There are multiple options for how to set this value. One is to
> hardwire it to 3, its expected value. Another is to set the value
> during relocation. Here, we choose a middle ground: we define
> the value symbolically (to 3) and also check that value.
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> bpf/probe_error.c | 3 ++
> libdtrace/dt_dctx.h | 7 ++++
> libdtrace/dt_prov_dtrace.c | 3 ++
> test/unittest/builtinvar/tst.id_ERROR.r | 1 +
> test/unittest/builtinvar/tst.id_ERROR.sh | 52 ++++++++++++++++++++++++
> 5 files changed, 66 insertions(+)
> create mode 100644 test/unittest/builtinvar/tst.id_ERROR.r
> create mode 100755 test/unittest/builtinvar/tst.id_ERROR.sh
>
> diff --git a/bpf/probe_error.c b/bpf/probe_error.c
> index cad161fd7..1081ee71d 100644
> --- a/bpf/probe_error.c
> +++ b/bpf/probe_error.c
> @@ -26,6 +26,7 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
> uint64_t illval)
> {
> dt_mstate_t *mst = dctx->mst;
> + int oldprid = mst->prid;
>
> __builtin_memcpy(mst->saved_argv, mst->argv, sizeof(mst->saved_argv));
> mst->argv[0] = 0;
> @@ -35,7 +36,9 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
> mst->argv[4] = fault;
> mst->argv[5] = illval;
>
> + mst->prid = DTRACE_ERROR_ID;
> dt_error(dctx);
> + mst->prid = oldprid;
>
> __builtin_memcpy(mst->argv, mst->saved_argv, sizeof(mst->saved_argv));
> mst->fault = fault;
> diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
> index 633c529f3..d8232868d 100644
> --- a/libdtrace/dt_dctx.h
> +++ b/libdtrace/dt_dctx.h
> @@ -14,6 +14,13 @@
> #include <dt_pt_regs.h>
> #include <dt_state.h>
>
> +/*
> + * Static probe IDs for the dtrace provider.
> + */
> +#define DTRACE_BEGIN_ID 1
> +#define DTRACE_END_ID 2
> +#define DTRACE_ERROR_ID 3
> +
> /*
> * The DTrace machine state.
> */
> diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
> index bf87cb054..9f0d72b78 100644
> --- a/libdtrace/dt_prov_dtrace.c
> +++ b/libdtrace/dt_prov_dtrace.c
> @@ -45,18 +45,21 @@ static int populate(dtrace_hdl_t *dtp)
>
> prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "BEGIN");
> if (prp) {
> + assert(prp->desc->id == DTRACE_BEGIN_ID);
> n++;
> dt_probe_enable(dtp, prp);
> }
>
> prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "END");
> if (prp) {
> + assert(prp->desc->id == DTRACE_END_ID);
> n++;
> dt_probe_enable(dtp, prp);
> }
>
> prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "ERROR");
> if (prp) {
> + assert(prp->desc->id == DTRACE_ERROR_ID);
> n++;
> dt_probe_enable(dtp, prp);
> dtp->dt_error = prp;
> diff --git a/test/unittest/builtinvar/tst.id_ERROR.r b/test/unittest/builtinvar/tst.id_ERROR.r
> new file mode 100644
> index 000000000..2e9ba477f
> --- /dev/null
> +++ b/test/unittest/builtinvar/tst.id_ERROR.r
> @@ -0,0 +1 @@
> +success
> diff --git a/test/unittest/builtinvar/tst.id_ERROR.sh b/test/unittest/builtinvar/tst.id_ERROR.sh
> new file mode 100755
> index 000000000..082ebd0c4
> --- /dev/null
> +++ b/test/unittest/builtinvar/tst.id_ERROR.sh
> @@ -0,0 +1,52 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +dtrace=$1
> +
> +DIRNAME="$tmpdir/builtinvar-id_ERROR.$$.$RANDOM"
> +mkdir -p $DIRNAME
> +cd $DIRNAME
> +
> +# Have a D script report the probe ID within an ERROR probe.
> +
> +$dtrace $dt_flags -qn '
> +BEGIN { *((int*)0) }
> +BEGIN { exit(1) }
> +ERROR { printf("ERROR probe id is %d\n", id); exit(0); }
> +' -o D.out 2> D.err
> +if [ $? -ne 0 ]; then
> + echo DTrace failed
> + echo ==== D.out
> + cat D.out
> + echo ==== D.err
> + cat D.err
> + exit 1
> +fi
> +
> +# Get the ERROR probe ID from "dtrace -l" output.
> +
> +id=`$dtrace $dt_flags -ln dtrace:::ERROR |& awk '/^ *[0-9]* *dtrace *ERROR *$/ { print $1 }'`
> +
> +# Construct expected output.
> +
> +echo "ERROR probe id is $id" > D.out.chk
> +echo >> D.out.chk
> +
> +# Check output.
> +
> +if ! diff -q D.out D.out.chk; then
> + echo output mismatches
> + echo ==== D.out
> + cat D.out
> + echo ==== D.out.chk
> + cat D.out.chk
> + exit 1
> +fi
> +
> +echo success
> +exit 0
> --
> 2.43.5
>
More information about the DTrace-devel
mailing list