This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
- From: Nan Xiao <xiaonan830818 at gmail dot com>
- To: systemtap at sourceware dot org
- Date: Thu, 26 Nov 2015 11:47:06 +0800
- Subject: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
- Authentication-results: sourceware.org; auth=none
Hi all,
>From the "foreach" section in SystemTap
doc(https://sourceware.org/systemtap/langref/Statement_types.html#SECTION00076000000000000000),
I can see there is a foreach usage:
foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT
But execute the following script generate errors:
# cat test.stp
#!/usr/bin/stap
global reads
probe vfs.read
{
reads[pid(), execname()]++
}
probe timer.s(3)
{
foreach (var = [pid, name] in reads)
printf("%d\n", reads[var]);
exit()
}
# ./test.stp
semantic error: inconsistent arity (2 vs 1): identifier 'reads' at
./test.stp:13:18
source: printf("%d\n", reads[var]);
^
semantic error: arity 2 first inferred here: identifier 'reads' at :7:2
source: reads[pid(), execname()]++
^
Pass 2: analysis failed. [man error::pass2]
What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in
ARRAY) STMT"? How to use it?
Thanks in advance!
Best Regards
Nan Xiao