Date: Sat, 17 Dec 2016 19:48:53 +0100 From: Domagoj Stolfa <domagoj.stolfa@gmail.com> To: Hiroki Sato <hrs@FreeBSD.org> Cc: freebsd-dtrace@freebsd.org Subject: clause-local variable with copyin() Message-ID: <20161217184853.GA11338@freebsd-laptop> In-Reply-To: <20161217.151014.1579687141761225852.hrs@allbsd.org> References: <20161217.151014.1579687141761225852.hrs@allbsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, > I have trouble with clause-local variable. A minimum working example > is attached. The "sample" program simply displays a string in an > infinite loop with a USDT named as "dump-str", sample_debug.d does > copyin() and printf() the whole buffer assuming it is > nul-terminated: >=20 > | sample$target:::dump-str > | { > | this->st =3D copyin(arg0, 1024); > | > | printf("(1)st =3D %s, %p\n", stringof(this->st), > | (char *)this->st); > | } > | sample$target:::dump-str > | { > | printf("(2)st =3D %s, %p\n", stringof(this->st), > | (char *)this->st); > | printf("(3)st =3D %s\n", stringof(copyin(arg0, 1024))); > | } >=20 > The odd part is that it does not work with splitting the probe into > the two as above but works fine without the split. The result was as > follows: >=20 > | % sudo make test > | dtrace -C -I/var/home/hrs/sample_str -s sample_debug.d -c /var/home/hr= s/sample_str/sample > | dtrace: script 'sample_debug.d' matched 5 probes > | CPU ID FUNCTION:NAME > | 0 61714 main:dump-str (1)st =3D test-uname, ffff= fe0001a19118 > | > | 0 61714 main:dump-str (2)st =3D , fffffe0001a191= 18 > | (3)st =3D test-uname >=20 > this->st became empty at the beginning of the second probe. >=20 > The symptom varied depending on the address of this->st, so I am > guessing that this->st was incorrectly freed at the end of the first > probe. If I use copyinstr(arg0) instead of copyin(), this problem > does not occur. That does seem like what's happening based on the described behaviour and running the examples you've provided. > Do I misunderstand clause-local variable? I noticed this when I use > if-then clause which was recently implemented as a syntax sugar to > split a probe automatically. The following ended up with the same > result: >=20 > | sample$target:::dump-str > | { > | this->st =3D copyin(arg0, 1024); > | > | printf("(1)st =3D %s, %p\n", stringof(this->st), > | (char *)this->st); > | if (0) { > | } > | printf("(2)st =3D %s, %p\n", stringof(this->st), > | (char *)this->st); > | printf("(3)st =3D %s\n", stringof(copyin(arg0, 1024))); > | } No, the clause-local variables should remain intact eventhough the probe is split up into two clauses. See [1] for an example. This is reproducible on FreeBSD 12.0-CURRENT and seems like a bug. [1] http://dtrace.org/guide/chp-variables.html#chp-variables-4 --=20 Best regards, Domagoj Stolfa. --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEHQB+y96lmmv+IXofwxT+ikb0YU4FAlhViJUACgkQwxT+ikb0 YU6iXAf9EtBXQ42BBrV+826ki1qk5tHaq0AYFZucRh3W3RdyrGYVKtW5sTKmt1Ap Z0qDUNbz9qwDr53gLBJAi/T8ngFvILnAkFfs1dzisLwFJM0ntoIqHrYKhgV7QsFG hZM9VK3waE39MKvoUv2SEAKULUZn6vjlvUgJfvU0CKnLGjYO7DChSTv4PoSo/U8i CQvbywPCLgkQpHsRAK3H2Qa+7MujPFxN+MKkrENG08ossUxxGdR724V5krX+MXTb y0Z0tLLUw23Up58weMzCSxWUyd6fT5beoy1fbO9uUwAMqtar0jfPmsBINmz/ZDMZ D+kmvRM7w47xPcDdNIQSOzyMfNSMRA== =iFwy -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20161217184853.GA11338>