From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29272 invoked by alias); 13 Feb 2006 19:28:42 -0000 Received: (qmail 29263 invoked by uid 22791); 13 Feb 2006 19:28:42 -0000 X-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 13 Feb 2006 19:28:41 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id k1DJSdjr026263 for ; Mon, 13 Feb 2006 14:28:39 -0500 Received: from pobox.toronto.redhat.com (pobox.toronto.redhat.com [172.16.14.4]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id k1DJSc123590; Mon, 13 Feb 2006 14:28:39 -0500 Received: from touchme.toronto.redhat.com (IDENT:postfix@touchme.toronto.redhat.com [172.16.14.9]) by pobox.toronto.redhat.com (8.12.8/8.12.8) with ESMTP id k1DJSc93008847; Mon, 13 Feb 2006 14:28:38 -0500 Received: from ton.toronto.redhat.com (ton.toronto.redhat.com [172.16.14.15]) by touchme.toronto.redhat.com (Postfix) with ESMTP id 96A078000E9; Mon, 13 Feb 2006 14:28:38 -0500 (EST) Received: from ton.toronto.redhat.com (localhost.localdomain [127.0.0.1]) by ton.toronto.redhat.com (8.13.1/8.13.1) with ESMTP id k1DJSc4D007839; Mon, 13 Feb 2006 14:28:38 -0500 Received: (from fche@localhost) by ton.toronto.redhat.com (8.13.1/8.13.1/Submit) id k1DJScbL007836; Mon, 13 Feb 2006 14:28:38 -0500 X-Authentication-Warning: ton.toronto.redhat.com: fche set sender to fche@redhat.com using -f To: Mark McLoughlin Cc: systemtap@sourceware.org Subject: Re: Global constants References: <1139852331.11054.17.camel@localhost.localdomain> From: fche@redhat.com (Frank Ch. Eigler) Date: Mon, 13 Feb 2006 19:28:00 -0000 In-Reply-To: <1139852331.11054.17.camel@localhost.localdomain> Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2006-q1/txt/msg00489.txt.bz2 Hi, Mark - markmc wrote: > [...] > const O_CREAT = 64 > probe kernel.function ("sys_open") { > if ($flags & O_CREAT) { > printf ("foo\n"); > } > } > --- > Attached is a patch which implements this. [...] Wow, I commend that you went all the way with your idea to an implementation. A few observations though: The code doesn't need the { } around the printf, and the printf doesn't need a semicolon. Perhaps probes consisting of a single statement shouldn't require the outer braces either: probe kernel.function ("sys_open") if ($flags & O_CREAT) printf ("foo\n") The standard syscalls tapset should define such constants, so end-user scripts do not have to. If the main purpose of this syntax is to compress initialization of globals into a single line, one can do it with less effort. The parser could rewrite global var = expr to global var; probe begin { var = expr } There need be no performance concerns here, partly because the optimizer will get rid of any such globals that are not read. It could similarly get rid of or merge initialization "begin" probes. Even with this sort of rewriting, if the right hand side of such assignments can be an expression, not just a literal, analysis & runtime considerations could become complicated. Consider dependency ordering, context setup, error checking, if for example expr is a function call dealing with other globals. If read-only-ness of these globals is important, then a new "const" keyword would indeed come in handy. (I'd promptly reuse it as a qualifier for embedded-C functions that are declared to have no side-effects.) I would implement this angle by a new flag on vardecl, enforced non-lvalueness during elaboration or translation, rather than whole new staptree.h classes. - FChE