From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13915 invoked by alias); 18 Jan 2010 20:39:44 -0000 Received: (qmail 13901 invoked by uid 22791); 18 Jan 2010 20:39:43 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40 X-Spam-Check-By: sourceware.org Received: from mail-pw0-f51.google.com (HELO mail-pw0-f51.google.com) (209.85.160.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Jan 2010 20:39:39 +0000 Received: by pwj15 with SMTP id 15so1983141pwj.10 for ; Mon, 18 Jan 2010 12:39:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.114.187.16 with SMTP id k16mr3839801waf.112.1263847177499; Mon, 18 Jan 2010 12:39:37 -0800 (PST) In-Reply-To: <4B54BCBA.6090002@redhat.com> References: <20100118131557.GA4127@basil.fritz.box> <4B54BCBA.6090002@redhat.com> Date: Mon, 18 Jan 2010 20:39:00 -0000 Message-ID: <40e92d5b1001181239y4168b059l355ca07323f0c00c@mail.gmail.com> Subject: Re: container_of in systemtap scripts From: =?UTF-8?Q?Przemys=C5=82aw_Pawe=C5=82czyk?= To: Josh Stone Cc: "Frank Ch. Eigler" , Andi Kleen , systemtap@sources.redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2010-q1/txt/msg00177.txt.bz2 On Mon, Jan 18, 2010 at 20:55, Josh Stone wrote: > On 01/18/2010 07:04 AM, Frank Ch. Eigler wrote: >> Andi Kleen writes: >>> [...] =C2=A0@cast doesn't support that. Are there any other clean ways = to >>> write container_of() natively >> >> Actually it this sort of thing should work, since we have "&" operators: >> >> @cast($subfieldptr - (& @cast(0, "struct container")->subfield), >> =C2=A0 =C2=A0 =C2=A0 "struct container") >> >>> or are there plans to extend cast to include an offset? >> >> Sure, we can do something like that if needed. > > The hardest part of such things is deciding on the syntax. =C2=A0Currentl= y it > can be written: > > =C2=A0@cast(ptr, "type") > =C2=A0@cast(ptr, "type", "module") > =C2=A0@cast(ptr, "type", "
") > > I propose adding a qualifier on the type field, something like > "type->field" or "type:field". =C2=A0The former is consistent with how fi= elds > are specified elsewhere, but it may imply more flexibility than a > "container_of" can support. =C2=A0(e.g. "mystruct->foo->bar" could only w= ork > if there are no pointers in that chain.) =C2=A0The latter with a colon lo= oks > nice to me, but it introduces a new syntax. My syntax proposal for container_of equivalent in stap is following one: @cast(ptr, "type<-field"[, "module"]) Looks rather clear and also supports imaginable chaining. After all, syntax is a secondary thing here. Regards. --=20 Przemys=C5=82aw Pawe=C5=82czyk