Skip to content

Revert change to errors.Frame's type #188

Closed

Description

@davecheney

In #183 the definition of errors.Frame was altered to type Frame runtime.Frame. This was necessary because of the changes to mid stack inlining in Go 1.12 and the deprecation of runtime.FuncForPC.

https://go-review.googlesource.com/c/go/+/156364 suggests that it may be possible to continue to use runtime.FuncForPC. If this CL lands #183 should be mostly reverted for the 1.0 release.

A future v2 release would probably drop the use of runtime.FuncForPC and redeclare errors.Frame as an opaque struct.

Activity

  1. added this to the 0.9 milestone on Jan 6, 2019
  2. arcana261 commented on Jan 6, 2019

    @arcana261

    I agree.. Since we can obtain runtime.Frame from PC's we could have just let good ol' Frame stay there. But I don't know whether it's too late to revert this breaking change or not. Other libraries might have adopted this change :(

  3. davecheney commented on Jan 6, 2019

    @davecheney
    MemberAuthor

    .. Since we can obtain runtime.Frame

    How would you do that?

    As to breaking change on master, I tagged v0.8.1 before I made this change.

  4. arcana261 commented on Jan 6, 2019

    @arcana261

    using runtime.CallersFrames? maybe?

    Thank you for tagging.. much appreciated ^_^

  5. arcana261 commented on Jan 6, 2019

    @arcana261

    we could alter implementation of format like this:

    // format allows stack trace printing calls to be made with a bytes.Buffer.
    func (ptrFrame Frame) format(w io.Writer, s fmt.State, verb rune) {
    	frames := runtime.CallersFrames([]uintptr{uintptr(ptrFrame)})
    	if frames == nil {
    		return
    	}
    	f, _ := frames.Next()
    
    ....
  6. davecheney commented on Jan 6, 2019

    @davecheney
    MemberAuthor
  7. arcana261 commented on Jan 6, 2019

    @arcana261

    I understand. I was merely pointing out that we could obtain an instance of runtime.Frame this way instead of #183 . And we could use runtime.Frame.Function, runtime.Frame.Line.. etc. And I've confirmed that we can accurately convert a single PC to runtime.Frame.

    Complete listing is as follows:
    Basically it's #183 without changing type of errors.Frame. Instead a we convert a single PC to runtime.Frame and the rest is still #183

    // format allows stack trace printing calls to be made with a bytes.Buffer.
    func (ptrFrame Frame) format(w io.Writer, s fmt.State, verb rune) {
    	frames := runtime.CallersFrames([]uintptr{uintptr(ptrFrame)})
    	if frames == nil {
    		return
    	}
    	f, _ := frames.Next()
    
    	switch verb {
    	case 's':
    		switch {
    		case s.Flag('+'):
    			fn := runtime.Frame(f).Func
    			if fn == nil {
    				io.WriteString(w, "unknown")
    			} else {
    				file := runtime.Frame(f).File
    				io.WriteString(w, fn.Name())
    				io.WriteString(w, "\n\t")
    				io.WriteString(w, file)
    			}
    		default:
    			file := runtime.Frame(f).File
    			if file == "" {
    				file = "unknown"
    			}
    			io.WriteString(w, path.Base(file))
    		}
    	case 'd':
    		io.WriteString(w, strconv.Itoa(runtime.Frame(f).Line))
    	case 'n':
    		name := runtime.Frame(f).Function
    		io.WriteString(s, funcname(name))
    	case 'v':
    		ptrFrame.format(w, s, 's')
    		io.WriteString(w, ":")
    		ptrFrame.format(w, s, 'd')
    	}
    }
  8. davecheney commented on Jan 6, 2019

    @davecheney
    MemberAuthor
  9. uberbo commented on Jan 7, 2019

    @uberbo

    Is there any reason for using runtime.Frame(f).Func.Name() instead of runtime.Frame(f).Function?

  10. dcu commented on Jan 8, 2019

    @dcu

    aws/aws-xray-sdk-go#77 is related to this

  11. davecheney commented on Jan 8, 2019

    @davecheney
    MemberAuthor
  12. davecheney commented on Jan 9, 2019

    @davecheney
    MemberAuthor

    Closed in #193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions