[DTrace-devel] [PATCH] test: ensure casting does not affect value

Kris Van Hees kris.van.hees at oracle.com
Wed Jul 31 20:04:46 UTC 2024


On Wed, Jul 31, 2024 at 03:51:52PM -0400, Eugene Loh wrote:
> What is the point of this test?  If we do not know the type of the kernel
> variable, then what does "kernel_read_neg_small_scalar" mean?

We *know* the type.  That is why we use that particular kernel symbol.  The
issue is that on kernel without CTF DTrace cannot know the type, so we need
to tell it that it is an int.

	Kris

> On 7/31/24 15:01, Kris Van Hees wrote:
> > On systems without CTF, we do not know the type of kernel variables.
> > By doing an explicit cast to int64_t a negative int is converted into a
> > large positive integer.  The proper cast is 'int' of course.
> > 
> > Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> > ---
> >   test/unittest/codegen/tst.kernel_read_neg_small_scalar.d | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > index 7c585d1b..cda6649b 100644
> > --- a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > +++ b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > @@ -1,6 +1,6 @@
> >   /*
> >    * Oracle Linux DTrace.
> > - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> > + * Copyright (c) 2022, 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.
> >    */
> > @@ -11,10 +11,10 @@ BEGIN
> >   {
> >   	/*
> >   	 * Unless we are actually crashing, the `crashing_cpu int will be -1.
> > -	 * We cast it to int64_t to ensure that the value read from the kernel
> > +	 * We cast it to int to ensure that the value read from the kernel
> >   	 * is sign-extended.
> >   	 */
> > -	trace((int64_t)`crashing_cpu);
> > +	trace((int)`crashing_cpu);
> >   	exit(0);
> >   }



More information about the DTrace-devel mailing list