[Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf

glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=24953

            Bug ID: 24953
           Summary: foreach statement not retrieving correct array values
                    in stapbpf
           Product: systemtap
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: bpf
          Assignee: systemtap at sourceware dot org
          Reporter: sapatel at redhat dot com
  Target Milestone: ---

When using foreach statements with arrays on stapbpf, the incorrect values are
retrieved. For example, the following script demonstrates this:

global arr

probe begin { arr[1] = 1; arr[2] = 2; exit() }

probe end { foreach ( v = v1 in arr) { printf("%d ", v) } }'

'1 2 ' should be printed, but rather '0 0 ' is printed.

--
You are receiving this mail because:
You are the assignee for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug bpf/24953] foreach statement not retrieving correct array values in stapbpf

glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=24953

William Cohen <wcohen at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wcohen at redhat dot com

--- Comment #1 from William Cohen <wcohen at redhat dot com> ---
Without the assignment in the foreach gets the values:

[wcohen@localhost testsuite]$ more ~/foreach2.stp
global arr

probe begin { arr[1] = 1; arr[2] = 2; exit()}

probe end { foreach ( v in arr) { printf("%d ", v) } }
[wcohen@localhost testsuite]$ sudo stap --bpf ~/foreach2.stp
2 1

Trying to do things like the testsuite systemtap.base/array_slicing.exp or
systemtap.base/foreach_value.stp?

--
You are receiving this mail because:
You are the assignee for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug bpf/24953] foreach statement not retrieving correct array values in stapbpf

glaubitz at physik dot fu-berlin.de
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=24953

--- Comment #2 from Sagar Patel <sapatel at redhat dot com> ---
(In reply to William Cohen from comment #1)

> Without the assignment in the foreach gets the values:
>
> [wcohen@localhost testsuite]$ more ~/foreach2.stp
> global arr
>
> probe begin { arr[1] = 1; arr[2] = 2; exit()}
>
> probe end { foreach ( v in arr) { printf("%d ", v) } }
> [wcohen@localhost testsuite]$ sudo stap --bpf ~/foreach2.stp
> 2 1
>
> Trying to do things like the testsuite systemtap.base/array_slicing.exp or
> systemtap.base/foreach_value.stp?

Sorry, I should've used a clearer example. In the script above, it seems to
"work" because the indices and the actual values in the array are the same.

In the following script, you can observe that without the assignment, 'v' is
referring to the indices and it will print "a b ":

global arr

probe begin { arr["a"] = 1; arr["b"] = 2; exit() }

probe end {foreach ( v in arr) { printf("%s ", v) } }

One possible alternative is to index into the array using 'v' and that works.

I'm trying to do things like systemtap.base/foreach_value.stp and more
specifically, things like tapset/prometheus.stpm where the indices and array
values are both used in the foreach statement.

--
You are receiving this mail because:
You are the assignee for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly in stapbpf

glaubitz at physik dot fu-berlin.de
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=24953

Serhei Makarov <me at serhei dot io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |me at serhei dot io
            Summary|foreach statement not       |foreach (v = v1,v2) syntax
                   |retrieving correct array    |not behaving correctly in
                   |values in stapbpf           |stapbpf

--- Comment #3 from Serhei Makarov <me at serhei dot io> ---
Returning the keys (not the values) is expected behaviour for a simple foreach
statement.

https://sourceware.org/systemtap/langref/6_Statement_types.html#SECTION00076000000000000000
> The foreach statement loops over each element of a named global array, assigning the current key to VAR.

So that doesn't need to be changed.

The current foreach (v = v1, v2 in arr) behaviour in stapbpf is not correct,
however.

If you look at foreach_loop in staptree.h
https://sourceware.org/git/gitweb.cgi?p=systemtap.git;a=blob;f=staptree.h;h=27358085596b8e2bf2c6aa41785ffb067327a9c4;hb=HEAD#l758
there should be fields which specify where to store the value, and which are
ignored in bpf-translate.cxx.

--
You are receiving this mail because:
You are the assignee for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly in stapbpf

glaubitz at physik dot fu-berlin.de
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=24953

Sagar Patel <sapatel at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|systemtap at sourceware dot org    |sapatel at redhat dot com

--
You are receiving this mail because:
You are the assignee for the bug.