Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: Frames.Next is confusing #18788

Closed
mlsteele opened this issue Jan 25, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@mlsteele
Copy link

commented Jan 25, 2017

What version of Go are you using (go version)?

play.golang.org

What operating system and processor architecture are you using (go env)?

play.golang.org

What did you do?

Sample program:
https://play.golang.org/p/5ckof3s_kJ

What did you expect to see?

The documentation for Frames.Next says "Next returns frame information for the next caller. If more is false, there are no more callers (the Frame value is valid)."

Reading that I would expect that more return this sort of thing

-> valid_frame, true
-> valid_frame, true
-> valid_frame, false
-> invalid_frame, false
-> etc.

Where invalid_frame is the default-valued frame.

What did you see instead?

-> valid_frame, true
-> valid_frame, true
-> valid_frame, true
-> invalid_frame, true
-> etc.
-> invalid_frame, false
-> etc.

So what?

This behavior of returning more=true and spitting out invalid Frames seems pretty weird. But I assume that changing the behavior of Next is out of the question. So I propose the documentation be updated by someone who knows how this thing works. The docs could read "Next returns frame information for the next caller. If more is false, no further calls to Next should be made. If frame is nil-valued, no further frames will be non-nil valued." And an example in the docs of how to go from a Frames to a complete []Frame would be great!

@ALTree ALTree changed the title runtime.Frames.Next is confusing runtime: Frames.Next is confusing Jan 25, 2017

@ALTree ALTree added this to the Go1.9Maybe milestone Jan 25, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 26, 2017

There isn't anything wrong with Frames.Next. You've misunderstood how to use runtime.Callers. runtime.CallersFrames assumes that all the frames you pass in are valid. You need to look at the value that runtime.Callers returns, and use that to limit the number of meaningful entries.

For example: https://play.golang.org/p/g8TrgyehBO .

This may seem kind of pointless with the current gc toolchain, but for 1.9 it is likely we will introduce inlining of non-leaf functions, and at that point it will be useful. gccgo already uses it in that way.

@josharian

This comment has been minimized.

Copy link
Contributor

commented Jan 28, 2017

@ianlancetaylor I think that converting your example here into a godoc example would be valuable. Re-opening this issue to that end.

@josharian josharian reopened this Jan 28, 2017

@josharian

This comment has been minimized.

Copy link
Contributor

commented Jan 28, 2017

Also, in the example code, need to check whether n == 0, and if so, never enter the loop in the first place.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 11, 2017

CL https://golang.org/cl/36892 mentions this issue.

@gopherbot gopherbot closed this in 8da91a6 Feb 13, 2017

@golang golang locked and limited conversation to collaborators Feb 13, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.