From owner-freebsd-dtrace@freebsd.org Sat Dec 17 18:48:59 2016 Return-Path: Delivered-To: freebsd-dtrace@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 121A5C8544F for ; Sat, 17 Dec 2016 18:48:59 +0000 (UTC) (envelope-from domagoj.stolfa@gmail.com) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 99C46F06; Sat, 17 Dec 2016 18:48:58 +0000 (UTC) (envelope-from domagoj.stolfa@gmail.com) Received: by mail-wm0-x242.google.com with SMTP id g23so11342848wme.1; Sat, 17 Dec 2016 10:48:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=do4OGJ/RzeMoLZyI93hEmqveXlFKDg2uYPU6dEJZUBo=; b=Jg+m6deHCBabbY/rY/hwyW/XP+gGktRsZ1JvtQwOkC2CwYaIkrE22/Hrc8WJ2nQaRX zuqR6XpIbxW5LilMTqDOk/6JjmiP3FWi3r/QR6Ne4r8UM5qbVuVnAYmvU35/XL6CxaKW OzQQFZkxbRojGGYvBDSnv0Y8CzOKG2rply9jCYKs3FuznG5PeMHQms/z4Yug62qjX+Gl XW6R7H4njfXUixQaIQqlhTBmq7oLq4eRBJ4eXtevqB85tQrkgO65veNA5dNlaXLU35qp VK7rAdA03kCWfc77+Ralv4Kvl/5dTxNhPpkp6tqpiTrg1Ew4y6UHMZuBbWEUfrYySnbk weFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=do4OGJ/RzeMoLZyI93hEmqveXlFKDg2uYPU6dEJZUBo=; b=Ph0TfB9DY6jwltuqCnAkf30LsnAtCmqHz+pThJMHwBWOgG4UA9rFPrBQCwBh9yKh53 5qwHef5518C0WcC4aLruiAXNjHWqCA4O1OB37Ai9H04PwLyKqtC8WDaQs9CsRRKi5p6I w6sURVGNFNFeOZEUJo+N8IdtpEZ+Z+1LsL5aB6S6j4kwCkFTmzhKorVxGJ4qezzsFOLd SiqVLjkSVIOIAXmgu/gKo8bPyM/o/t948u79QCISnmG6X7KrpadMfN8pZjPZ9856Lid/ GKGGi8tavijKUhSE6BS1eLDpV50sa8yxKCAFl7BF/uxDIB3KaKDEaG2xIeWmUAKHW3dD PVtg== X-Gm-Message-State: AIkVDXJLv2f/iHfS/u+Sr0bOFE3SeSsMlTJ0Anqbi9U2o0Drc0syx081/1d+fvmRelaI+g== X-Received: by 10.28.131.72 with SMTP id f69mr7061665wmd.135.1482000536864; Sat, 17 Dec 2016 10:48:56 -0800 (PST) Received: from freebsd-laptop (213-202-70-33.dsl.iskon.hr. [213.202.70.33]) by smtp.gmail.com with ESMTPSA id l2sm12582394wji.7.2016.12.17.10.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Dec 2016 10:48:55 -0800 (PST) Date: Sat, 17 Dec 2016 19:48:53 +0100 From: Domagoj Stolfa To: Hiroki Sato Cc: freebsd-dtrace@freebsd.org Subject: clause-local variable with copyin() Message-ID: <20161217184853.GA11338@freebsd-laptop> References: <20161217.151014.1579687141761225852.hrs@allbsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="oyUTqETQ0mS9luUI" Content-Disposition: inline In-Reply-To: <20161217.151014.1579687141761225852.hrs@allbsd.org> User-Agent: Mutt/1.7.1 (2016-10-04) X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Dec 2016 18:48:59 -0000 --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--