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
Closed

runtime: Frames.Next is confusing #18788

mlsteele opened this issue Jan 25, 2017 · 4 comments
Labels
Documentation FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@mlsteele
Copy link

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 Documentation NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Jan 25, 2017
@ALTree ALTree added this to the Go1.9Maybe milestone Jan 25, 2017
@ianlancetaylor
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

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

@gopherbot
Copy link

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

@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.
Labels
Documentation FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants