[DTrace-devel] [PATCH 2/2 v3] Show signed values for signed immediate conditional branches

Eugene Loh eugene.loh at oracle.com
Tue Mar 29 16:44:44 UTC 2022


On 3/29/22 12:41 AM, Kris Van Hees via DTrace-devel wrote:

> The disassembler will now print negative values correctly in signed
> conditional branch instructions with an immediate operand.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>   libdtrace/dt_dis.c                    | 29 +++++++++++++++++++--------
>   test/unittest/disasm/tst.ann-js-neg.r |  2 ++
I'm confused.  Is there a branch that already has a test?  Or was there 
supposed to be a test in this patch that was omitted?  (I'm guessing the 
latter.)
>   2 files changed, 23 insertions(+), 8 deletions(-)
>   create mode 100644 test/unittest/disasm/tst.ann-js-neg.r
>
> diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
> index bfd639c6..b5a1f067 100644
> --- a/libdtrace/dt_dis.c
> +++ b/libdtrace/dt_dis.c
> @@ -286,6 +286,19 @@ dt_dis_branch_imm(const dtrace_difo_t *dp, const char *name, uint_t addr,
>   	return 0;
>   }
>   
> +/*ARGSUSED*/
> +static uint_t
> +dt_dis_sbranch_imm(const dtrace_difo_t *dp, const char *name, uint_t addr,
> +	      const struct bpf_insn *in, const char *rname, FILE *fp)
> +{
> +	int	n;
> +
> +	n = fprintf(fp, "%-4s %s, %d, %d", name, reg(in->dst_reg), in->imm,
> +		    in->off);
> +	fprintf(fp, "%*s! -> %03u\n", DT_DIS_PAD(n), "", addr + 1 + in->off);
> +	return 0;
> +}
> +
>   /*ARGSUSED*/
>   static uint_t
>   dt_dis_load(const dtrace_difo_t *dp, const char *name, uint_t addr,
> @@ -720,10 +733,10 @@ dt_dis_difo(const dtrace_difo_t *dp, FILE *fp, const dt_ident_t *idp,
>   		INSN3(JMP32, JLT, K)	= { "jlt", dt_dis_branch_imm },
>   		INSN3(JMP32, JGE, K)	= { "jge", dt_dis_branch_imm },
>   		INSN3(JMP32, JLE, K)	= { "jle", dt_dis_branch_imm },
> -		INSN3(JMP32, JSGT, K)	= { "jsgt", dt_dis_branch_imm },
> -		INSN3(JMP32, JSLT, K)	= { "jslt", dt_dis_branch_imm },
> -		INSN3(JMP32, JSGE, K)	= { "jsge", dt_dis_branch_imm },
> -		INSN3(JMP32, JSLE, K)	= { "jsle", dt_dis_branch_imm },
> +		INSN3(JMP32, JSGT, K)	= { "jsgt", dt_dis_sbranch_imm },
> +		INSN3(JMP32, JSLT, K)	= { "jslt", dt_dis_sbranch_imm },
> +		INSN3(JMP32, JSGE, K)	= { "jsge", dt_dis_sbranch_imm },
> +		INSN3(JMP32, JSLE, K)	= { "jsle", dt_dis_sbranch_imm },
>   		INSN3(JMP32, JSET, K)	= { "jset", dt_dis_branch_imm },
>   		/* 64-bit jump ops, op(dst, src) */
>   		INSN3(JMP, JEQ, X)	= { "jeq", dt_dis_branch },
> @@ -744,10 +757,10 @@ dt_dis_difo(const dtrace_difo_t *dp, FILE *fp, const dt_ident_t *idp,
>   		INSN3(JMP, JLT, K)	= { "jlt", dt_dis_branch_imm },
>   		INSN3(JMP, JGE, K)	= { "jge", dt_dis_branch_imm },
>   		INSN3(JMP, JLE, K)	= { "jle", dt_dis_branch_imm },
> -		INSN3(JMP, JSGT, K)	= { "jsgt", dt_dis_branch_imm },
> -		INSN3(JMP, JSLT, K)	= { "jslt", dt_dis_branch_imm },
> -		INSN3(JMP, JSGE, K)	= { "jsge", dt_dis_branch_imm },
> -		INSN3(JMP, JSLE, K)	= { "jsle", dt_dis_branch_imm },
> +		INSN3(JMP, JSGT, K)	= { "jsgt", dt_dis_sbranch_imm },
> +		INSN3(JMP, JSLT, K)	= { "jslt", dt_dis_sbranch_imm },
> +		INSN3(JMP, JSGE, K)	= { "jsge", dt_dis_sbranch_imm },
> +		INSN3(JMP, JSLE, K)	= { "jsle", dt_dis_sbranch_imm },
>   		INSN3(JMP, JSET, K)	= { "jset", dt_dis_branch_imm },
>   		INSN2(JMP, JA)		= { "ja", dt_dis_jump },
>   		/* Store instructions, [dst + off] = src */
> diff --git a/test/unittest/disasm/tst.ann-js-neg.r b/test/unittest/disasm/tst.ann-js-neg.r
> new file mode 100644
> index 00000000..d70a02ff
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-js-neg.r
> @@ -0,0 +1,2 @@
> +75 0 0 XXXX 00000000    jsge %r0, 0, 3
> +d5 0 0 XXXX fffff800    jsle %r0, -2048, 2



More information about the DTrace-devel mailing list