[DTrace-devel] [PATCH v2 14/14] Fix string disasm due to new code path
Eugene Loh
eugene.loh at oracle.com
Wed May 3 06:28:10 UTC 2023
The difference between this v2 patch and the earlier one is minor. The
gvar/lvar tests are loosened a little to accommodate changes in the code
generator. That is, we still annotate the assembly line where a gvar or
lvar is accessed. We also used to dump the following line as an extra
check, but that's not "guaranteed" to be predictable.
On 5/3/23 02:24, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> Reviewed-by: Nick Alcock <nick.alcock at oracle.com>
> ---
> libdtrace/dt_dis.c | 15 ++++++++-----
> test/unittest/disasm/tst.ann-str_assoc.r | 2 ++
> test/unittest/disasm/tst.ann-str_assoc.sh | 19 ++++++++++++++++
> test/unittest/disasm/tst.ann-str_gvar.r | 2 ++
> test/unittest/disasm/tst.ann-str_gvar.sh | 27 +++++++++++++++++++++++
> test/unittest/disasm/tst.ann-str_lvar.r | 2 ++
> test/unittest/disasm/tst.ann-str_lvar.sh | 27 +++++++++++++++++++++++
> test/unittest/disasm/tst.ann-str_tvar.r | 2 ++
> test/unittest/disasm/tst.ann-str_tvar.sh | 19 ++++++++++++++++
> 9 files changed, 110 insertions(+), 5 deletions(-)
> create mode 100644 test/unittest/disasm/tst.ann-str_assoc.r
> create mode 100755 test/unittest/disasm/tst.ann-str_assoc.sh
> create mode 100644 test/unittest/disasm/tst.ann-str_gvar.r
> create mode 100755 test/unittest/disasm/tst.ann-str_gvar.sh
> create mode 100644 test/unittest/disasm/tst.ann-str_lvar.r
> create mode 100755 test/unittest/disasm/tst.ann-str_lvar.sh
> create mode 100644 test/unittest/disasm/tst.ann-str_tvar.r
> create mode 100755 test/unittest/disasm/tst.ann-str_tvar.sh
>
> diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
> index 1cfcaf5d..bb2260e3 100644
> --- a/libdtrace/dt_dis.c
> +++ b/libdtrace/dt_dis.c
> @@ -92,7 +92,7 @@ dt_dis_varname_off(const dtrace_difo_t *dp, uint_t off, uint_t scope, uint_t add
> * insn code dst src offset imm
> * -2: ld dst %fp DT_STK_DCTX 00000000
> * -1: ld dst dst DCTX_*VARS 00000000
> - * 0: ld dst dst var_offset 00000000
> + * 0: ld xxx dst var_offset 00000000
> * 0: st dst src var_offset 00000000
> * 0: add dst 0 0 var_offset
> * where instruction 0 is the current instruction, which may be one
> @@ -151,10 +151,11 @@ dt_dis_refname(const dtrace_difo_t *dp, const struct bpf_insn *in, uint_t addr,
> goto out;
>
> /* check the current instruction and read var_offset */
> - if (in->dst_reg != dst)
> - goto out;
> if (in[-1].off == DCTX_STRTAB) {
> - if (in->code == addcode && in->src_reg == 0 && in->off == 0) {
> + if (in->dst_reg == dst &&
> + in->code == addcode &&
> + in->src_reg == 0 &&
> + in->off == 0) {
> str = dt_difo_getstr(dp, in->imm);
> if (str != NULL)
> fprintf(fp, "%*s! \"%s\"", DT_DIS_PAD(n), "",
> @@ -168,9 +169,13 @@ dt_dis_refname(const dtrace_difo_t *dp, const struct bpf_insn *in, uint_t addr,
> var_offset = in->off;
> else if (BPF_CLASS(in->code) == BPF_STX &&
> BPF_MODE(in->code) == BPF_MEM &&
> + in->dst_reg == dst &&
> in->src_reg != dst && in->imm == 0)
> var_offset = in->off;
> - else if (in->code == addcode && in->src_reg == 0 && in->off == 0)
> + else if (in->code == addcode &&
> + in->dst_reg == dst &&
> + in->src_reg == 0 &&
> + in->off == 0)
> var_offset = in->imm;
> else
> goto out;
> diff --git a/test/unittest/disasm/tst.ann-str_assoc.r b/test/unittest/disasm/tst.ann-str_assoc.r
> new file mode 100644
> index 00000000..aa9c1ef7
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_assoc.r
> @@ -0,0 +1,2 @@
> +85 0 1 0000 ffffffff call dt_get_assoc ! CheckVariable[]
> +85 0 1 0000 ffffffff call dt_get_assoc ! CheckVariable[]
> diff --git a/test/unittest/disasm/tst.ann-str_assoc.sh b/test/unittest/disasm/tst.ann-str_assoc.sh
> new file mode 100755
> index 00000000..05d42705
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_assoc.sh
> @@ -0,0 +1,19 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 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
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> + CheckVariable[1234] = "abc";
> + trace(CheckVariable[1234]);
> +}
> +' 2>&1 | awk '/ call dt_get_assoc/ { sub(/^[^:]+: /, ""); print; }'
> +
> +exit $?
> diff --git a/test/unittest/disasm/tst.ann-str_gvar.r b/test/unittest/disasm/tst.ann-str_gvar.r
> new file mode 100644
> index 00000000..c99b4c6c
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_gvar.r
> @@ -0,0 +1,2 @@
> +07 N N 0000 00000000 add %rX, 0 ! CheckVariable
> +69 N N 0000 00000000 ldh %rX, [%rX+0] ! CheckVariable
> diff --git a/test/unittest/disasm/tst.ann-str_gvar.sh b/test/unittest/disasm/tst.ann-str_gvar.sh
> new file mode 100755
> index 00000000..6b2d4d52
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_gvar.sh
> @@ -0,0 +1,27 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 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
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> + CheckVariable = "abc";
> + trace(CheckVariable);
> +}
> +' 2>&1 | awk '/ CheckV/ {
> + sub(/^[^:]+: /, ""); # strip line number
> +
> + gsub(/%r[0-9]/, "%rX"); # hide reg numbers
> + $2 = "N";
> + $3 = "N";
> +
> + print; # print
> + }'
> +
> +exit $?
> diff --git a/test/unittest/disasm/tst.ann-str_lvar.r b/test/unittest/disasm/tst.ann-str_lvar.r
> new file mode 100644
> index 00000000..bf410596
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_lvar.r
> @@ -0,0 +1,2 @@
> +07 N N 0000 00000000 add %rX, 0 ! this->CheckVariable
> +69 N N 0000 00000000 ldh %rX, [%rX+0] ! this->CheckVariable
> diff --git a/test/unittest/disasm/tst.ann-str_lvar.sh b/test/unittest/disasm/tst.ann-str_lvar.sh
> new file mode 100755
> index 00000000..2708dab3
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_lvar.sh
> @@ -0,0 +1,27 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 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
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> + this->CheckVariable = "abc";
> + trace(this->CheckVariable);
> +}
> +' 2>&1 | awk '/this->CheckV/ {
> + sub(/^[^:]+: /, ""); # strip line number
> +
> + gsub(/%r[0-9]/, "%rX"); # hide reg numbers
> + $2 = "N";
> + $3 = "N";
> +
> + print; # print
> + }'
> +
> +exit $?
> diff --git a/test/unittest/disasm/tst.ann-str_tvar.r b/test/unittest/disasm/tst.ann-str_tvar.r
> new file mode 100644
> index 00000000..63b7b77c
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_tvar.r
> @@ -0,0 +1,2 @@
> +85 0 1 0000 ffffffff call dt_get_tvar ! self->CheckVariable
> +85 0 1 0000 ffffffff call dt_get_tvar ! self->CheckVariable
> diff --git a/test/unittest/disasm/tst.ann-str_tvar.sh b/test/unittest/disasm/tst.ann-str_tvar.sh
> new file mode 100755
> index 00000000..ebbdf8be
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-str_tvar.sh
> @@ -0,0 +1,19 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 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
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> + self->CheckVariable = "abc";
> + trace(self->CheckVariable);
> +}
> +' 2>&1 | awk '/ call dt_get_tvar/ { sub(/^[^:]+: /, ""); print; }'
> +
> +exit $?
More information about the DTrace-devel
mailing list