Date: Sat, 17 Dec 2016 15:10:14 +0900 (JST) From: Hiroki Sato <hrs@FreeBSD.org> To: freebsd-dtrace@freebsd.org Subject: clause-local variable with copyin() Message-ID: <20161217.151014.1579687141761225852.hrs@allbsd.org>
next in thread | raw e-mail | index | archive | help
----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)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20161217.151014.1579687141761225852.hrs>