public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf
@ 2019-08-30 15:59 sapatel at redhat dot com
  2019-08-30 18:41 ` [Bug bpf/24953] " wcohen at redhat dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sapatel at redhat dot com @ 2019-08-30 15:59 UTC (permalink / raw)
  To: systemtap

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug bpf/24953] foreach statement not retrieving correct array values in stapbpf
  2019-08-30 15:59 [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf sapatel at redhat dot com
@ 2019-08-30 18:41 ` wcohen at redhat dot com
  2019-08-30 18:52 ` sapatel at redhat dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: wcohen at redhat dot com @ 2019-08-30 18:41 UTC (permalink / raw)
  To: systemtap

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug bpf/24953] foreach statement not retrieving correct array values in stapbpf
  2019-08-30 15:59 [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf sapatel at redhat dot com
  2019-08-30 18:41 ` [Bug bpf/24953] " wcohen at redhat dot com
@ 2019-08-30 18:52 ` sapatel at redhat dot com
  2019-09-03 14:06 ` [Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly " me at serhei dot io
  2019-09-26 19:55 ` sapatel at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: sapatel at redhat dot com @ 2019-08-30 18:52 UTC (permalink / raw)
  To: systemtap

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly in stapbpf
  2019-08-30 15:59 [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf sapatel at redhat dot com
  2019-08-30 18:41 ` [Bug bpf/24953] " wcohen at redhat dot com
  2019-08-30 18:52 ` sapatel at redhat dot com
@ 2019-09-03 14:06 ` me at serhei dot io
  2019-09-26 19:55 ` sapatel at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: me at serhei dot io @ 2019-09-03 14:06 UTC (permalink / raw)
  To: systemtap

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly in stapbpf
  2019-08-30 15:59 [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf sapatel at redhat dot com
                   ` (2 preceding siblings ...)
  2019-09-03 14:06 ` [Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly " me at serhei dot io
@ 2019-09-26 19:55 ` sapatel at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: sapatel at redhat dot com @ 2019-09-26 19:55 UTC (permalink / raw)
  To: systemtap

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-09-26 19:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30 15:59 [Bug bpf/24953] New: foreach statement not retrieving correct array values in stapbpf sapatel at redhat dot com
2019-08-30 18:41 ` [Bug bpf/24953] " wcohen at redhat dot com
2019-08-30 18:52 ` sapatel at redhat dot com
2019-09-03 14:06 ` [Bug bpf/24953] foreach (v = v1,v2) syntax not behaving correctly " me at serhei dot io
2019-09-26 19:55 ` sapatel at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).