This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
- From: Nan Xiao <xiaonan830818 at gmail dot com>
- To: "Frank Ch. Eigler" <fche at redhat dot com>
- Cc: systemtap at sourceware dot org
- Date: Fri, 27 Nov 2015 10:29:54 +0800
- Subject: Re: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
- Authentication-results: sourceware.org; auth=none
- References: <CA+MhoaNFvx+uvxcXsvt2GtHCaa_-tU=9CLYr8ME3jdG8_Zjq-g at mail dot gmail dot com> <y0moaego7pf dot fsf at fche dot csb> <CA+MhoaOGckAyXYzCCfWNBGotQrR+dizYF52Cd2WhNQD5Yo_+3Q at mail dot gmail dot com>
Hi Frank,
BTW, I think in this
page(https://sourceware.org/systemtap/langref/Statement_types.html#SECTION00076000000000000000),
use
foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT (man stap)
is better and more understandable than
foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT
Thanks!
Best Regards
Nan Xiao
On Fri, Nov 27, 2015 at 10:23 AM, Nan Xiao <xiaonan830818@gmail.com> wrote:
> Hi Frank,
>
> Yeah, it works! Thanks very much for your help!
> Best Regards
> Nan Xiao
>
>
> On Fri, Nov 27, 2015 at 3:56 AM, Frank Ch. Eigler <fche@redhat.com> wrote:
>>
>> xiaonan830818 wrote:
>>
>>> [...]
>>> I can see there is a foreach usage:
>>> foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT
>>
>> See [man stap]. This syntax is for automatically fetching
>> the ARRAY[VAR1,VAR2,...] value into a VALUE variable, so:
>>
>>> But execute the following script generate errors:
>>> [...]
>>> probe timer.s(3)
>>> {
>>> foreach (var = [pid, name] in reads)
>>> printf("%d\n", reads[var]);
>>
>> ... would be correctly written as
>>
>>> printf("%d\n", var)
>>
>>
>> - FChE