From owner-freebsd-dtrace@freebsd.org Sat Dec 17 06:13:30 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 3205DC84D41 for ; Sat, 17 Dec 2016 06:13:30 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (gatekeeper.allbsd.org [IPv6:2001:2f0:104:e001::32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.allbsd.org", Issuer "RapidSSL SHA256 CA - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 96D821CCD for ; Sat, 17 Dec 2016 06:13:28 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail-d.allbsd.org (p2027-ipbf1605funabasi.chiba.ocn.ne.jp [123.225.191.27]) (authenticated bits=56) by mail.allbsd.org (8.15.2/8.15.2) with ESMTPSA id uBH6D28g045696 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) (Client CN "/OU=GT07882699/OU=See+20www.rapidssl.com/resources/cps+20+28c+2915/OU=Domain+20Control+20Validated+20-+20RapidSSL+28R+29/CN=*.allbsd.org", Issuer "/C=US/O=GeoTrust+20Inc./CN=RapidSSL+20SHA256+20CA+20-+20G3") for ; Sat, 17 Dec 2016 15:13:22 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from alph.allbsd.org (alph.allbsd.org [192.168.0.10]) by mail-d.allbsd.org (8.15.2/8.15.2) with ESMTPS id uBH6BlBO060177 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Sat, 17 Dec 2016 15:11:47 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (localhost [IPv6:::1]) (authenticated bits=0) by alph.allbsd.org (8.15.2/8.15.2) with ESMTPA id uBH6BiSd060171 for ; Sat, 17 Dec 2016 15:11:46 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Sat, 17 Dec 2016 15:10:14 +0900 (JST) Message-Id: <20161217.151014.1579687141761225852.hrs@allbsd.org> To: freebsd-dtrace@freebsd.org Subject: clause-local variable with copyin() From: Hiroki Sato X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.7 on Emacs 25.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Sat_Dec_17_15_10_14_2016_904)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.99 at gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender DNS name whitelisted, not delayed by milter-greylist-4.4.3 (mail.allbsd.org [133.31.130.32]); Sat, 17 Dec 2016 15:13:23 +0900 (JST) X-Spam-Status: No, score=-99.9 required=13.0 tests=CONTENT_TYPE_PRESENT, QENCPTR1,USER_IN_WHITELIST autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on gatekeeper.allbsd.org 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 06:13:30 -0000 ----Security_Multipart0(Sat_Dec_17_15_10_14_2016_904)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Dec_17_15_10_14_2016_434)--" Content-Transfer-Encoding: 7bit ----Next_Part(Sat_Dec_17_15_10_14_2016_434)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, 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: | sample$target:::dump-str | { | this->st = copyin(arg0, 1024); | | printf("(1)st = %s, %p\n", stringof(this->st), | (char *)this->st); | } | sample$target:::dump-str | { | printf("(2)st = %s, %p\n", stringof(this->st), | (char *)this->st); | printf("(3)st = %s\n", stringof(copyin(arg0, 1024))); | } 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: | % sudo make test | dtrace -C -I/var/home/hrs/sample_str -s sample_debug.d -c /var/home/hrs/sample_str/sample | dtrace: script 'sample_debug.d' matched 5 probes | CPU ID FUNCTION:NAME | 0 61714 main:dump-str (1)st = test-uname, fffffe0001a19118 | | 0 61714 main:dump-str (2)st = , fffffe0001a19118 | (3)st = test-uname this->st became empty at the beginning of the second probe. 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. 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: | sample$target:::dump-str | { | this->st = copyin(arg0, 1024); | | printf("(1)st = %s, %p\n", stringof(this->st), | (char *)this->st); | if (0) { | } | printf("(2)st = %s, %p\n", stringof(this->st), | (char *)this->st); | printf("(3)st = %s\n", stringof(copyin(arg0, 1024))); | } -- Hiroki ----Next_Part(Sat_Dec_17_15_10_14_2016_434)-- Content-Type: Application/Octet-Stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="sample_str.tar.gz" H4sIAF3RVFgAA+1XbW/aMBDma/wrTqxVk4mkTkiIBKNS105Tp7EiWD+1FQqJgagQotip1FX97zvT hJexlg+jTKh5hJTofLmzfff4MdybxGPW4yI5Lr0VKKWu60CJ2i61zaXnAmBWqeWYDrUdF6hp1dxq CZw3m9ESUi68BKcySvirfpvGs3XMn3sCvqh/y7tjg3DMtp4D96NWs1+uv2Vl9cefi3tHTbtqOiWg W5/JX/DO69/uXH5tKs9dQFqnP5oK6XbOurnJ8CHrkDiZ9hk3AkIE46JOlEAkns9APwP94uDROLvq nF90nkDn+RcB66dDIwDdBxy//PxNjh9nqYgRRv44DRh86vPAwOhDY3J3Qv73frw3LPE/r/jWc2zi v2OaOf+tquXO+E/dgv+7wIc5DfkDP469xJsYoxOyZBbBOOyv2cLpn6YkjIartjQK0VPaFsby6nEy KhMSRoJMvDBS76dhoJFHovgjLwEurk1q2bcNQhSMHvnxg8pFBcry/NHTyJuwcgV4+ItNBzigaQ3p d70wgA7mLTTh6IYe4dhgmoDaaGiACZTuaav9/Uvv/KrV7nV/dlR1lvKjhp+hqxLjYsRALR/ym0gm ebbyMWOxasr3J5xUwkSaRKBSNDzt68G1xv/5Qb+9HJv4T/HOl/PfqpnIfwf9C/7vAljt+zBgSSba khyzBoAgncQ92Rc5NbDJG/va5QVewjr/s2vbFnNs4r9tW/P/f9Wa1H/HrhX6vxM8F/0A92DIRL1e l7TXsRukDItRyPUTLlBD/Wn8gAqNXrQCUpY1Kcu5TKImzrwOeQUO40wy5X0AhTgPolWIAoj8OJnb pXi+Not5EuufkiziVPM4qzHWl6jts7AXKFCgwAb8Bpa19lwAFgAA ----Next_Part(Sat_Dec_17_15_10_14_2016_434)---- ----Security_Multipart0(Sat_Dec_17_15_10_14_2016_904)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEABECAAYFAlhU1sYACgkQTyzT2CeTzy31swCdFKup6gWMlbd1JO9eO2QV1g5k ju4AoNFUotWuD5DthI1AtegovL6dFUHL =gBnV -----END PGP SIGNATURE----- ----Security_Multipart0(Sat_Dec_17_15_10_14_2016_904)----