This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: container_of in systemtap scripts
- From: Josh Stone <jistone at redhat dot com>
- To: "Frank Ch. Eigler" <fche at redhat dot com>
- Cc: Andi Kleen <andi at firstfloor dot org>, systemtap at sources dot redhat dot com
- Date: Mon, 18 Jan 2010 11:55:38 -0800
- Subject: Re: container_of in systemtap scripts
- References: <20100118131557.GA4127@basil.fritz.box> <y0miqazihef.fsf@fche.csb>
On 01/18/2010 07:04 AM, Frank Ch. Eigler wrote:
> Andi Kleen <andi@firstfloor.org> writes:
>
>> systemtap 1.1 works nicely.
>
> Thanks for trying it.
>
>> [...] @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),
> "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. Currently it
can be written:
@cast(ptr, "type")
@cast(ptr, "type", "module")
@cast(ptr, "type", "<header>")
I propose adding a qualifier on the type field, something like
"type->field" or "type:field". The former is consistent with how fields
are specified elsewhere, but it may imply more flexibility than a
"container_of" can support. (e.g. "mystruct->foo->bar" could only work
if there are no pointers in that chain.) The latter with a colon looks
nice to me, but it introduces a new syntax.
Josh