From owner-freebsd-dtrace@freebsd.org Sat Dec 17 18:38:25 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 9CEB9C8522D for ; Sat, 17 Dec 2016 18:38:25 +0000 (UTC) (envelope-from matthew.ahrens@delphix.com) Received: from mail-it0-x22c.google.com (mail-it0-x22c.google.com [IPv6:2607:f8b0:4001:c0b::22c]) (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 5DC55A89 for ; Sat, 17 Dec 2016 18:38:25 +0000 (UTC) (envelope-from matthew.ahrens@delphix.com) Received: by mail-it0-x22c.google.com with SMTP id b132so18910640iti.1 for ; Sat, 17 Dec 2016 10:38:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphix.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8b+ARpGUkb7P5Kjr6ZRaTJ4wXaAba19P4WVMsISeyco=; b=Awz3z1zzcy9Wim7GtgXvstQcZeZAvcpWu3BGalJk91ixwrDb4/bziyRAPiFBLOCpoI V/6XqFHprOm6nDDwVIV/tmrGJ8cR2fapevXD7rrDf0R/IlAllFXBO2YPqD2OKmWKKpoU 0WEJ5+myMS/0nT5gEZOYB8vgdcfMSZ4NN8Gvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8b+ARpGUkb7P5Kjr6ZRaTJ4wXaAba19P4WVMsISeyco=; b=cKkmksYt5HNuAlZLESqjDbgiToDwWfqsC7KCMCwWcSV3X21ZODP/LbWPgWpHmVwXS4 vAKoycWV6cPpapWglIlKaSwWFWJBsfkmo4ixMMCEuNH/zkliQs7iTNqN22VtZZOkQQyS nvPLHgK1r3dbyfqjwVv3iTHNNKZvoOV2Q1ys7VdFqT4MIjo6sS13qsiChLiHScFfnS/z XxQyo2ndEecp8NP2Y6pdEgajFA2nH7559VSgcQP2DQQbFkmcOELI3qs5kPaGgf1koJmj mgIkYS/fUHNUyqb58Egj5Fqvbj40yV4r7vWZ+Un8TgFnS9sGV+HNRHHCYJcC8XvsaZk1 BF3Q== X-Gm-Message-State: AKaTC02+R77LX7Z/e59xDgYGnO9JHV07TqUbktw6T7XsQPOL2JtXVB0TP6BNbEYxTygG9q4qnwHZkxFEST7LhV2Z X-Received: by 10.36.184.194 with SMTP id m185mr8721624ite.3.1481999903585; Sat, 17 Dec 2016 10:38:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.36.224.132 with HTTP; Sat, 17 Dec 2016 10:38:23 -0800 (PST) In-Reply-To: <20161217.151014.1579687141761225852.hrs@allbsd.org> References: <20161217.151014.1579687141761225852.hrs@allbsd.org> From: Matthew Ahrens Date: Sat, 17 Dec 2016 10:38:23 -0800 Message-ID: Subject: Re: clause-local variable with copyin() To: Hiroki Sato Cc: freebsd-dtrace@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:38:25 -0000 On Fri, Dec 16, 2016 at 10:10 PM, Hiroki Sato wrote: > 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. > Perhaps this is a bug (or at least, unexpected behavior) with copyin(). I assume that it works fine with simple data types (e.g. numbers). > > Do I misunderstand clause-local variable? No, it should work as you are doing. So-called "clause-local" variables are actually implemented as "enabled-probe-local" variables I tried to test out your script on illumos but I got as far as this before running out of time: dtrace -h -s sample_probes.d gcc -c sample.c dtrace -G -s sample_probes.d sample.o gcc -o sample sample.o dtrace -s sample_debug.d -c ./sample dtrace: failed to compile script sample_debug.d: line 1: 'dump-str' is an invalid probe name --matt > 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 >