github.com/haraldrudell/parl@v0.4.176/pruntime/frame-r.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pruntime
     7  
     8  import (
     9  	"strconv"
    10  )
    11  
    12  // Frame represents an executing code location, ie. a code line in source code
    13  //   - parl.Frame is similar to [runtime.Frame] returned by [runtime.CallersFrames]
    14  //     but has only basic types, ie. can be stored or transferred
    15  //   - [pdebug.Frame] implements [parl.Frame]
    16  //   - Frame is a value container only created by [pdebug.NewStack].
    17  //     Frame extends [pruntime.CodeLocation] with argument values
    18  type FrameR struct {
    19  	CodeLocation
    20  	// function argument values like "(1, 0x14000113040)"
    21  	//	- values of value-types like int are displayed
    22  	//	- most types appear as a pointer value “0x…”
    23  	args string
    24  }
    25  
    26  var _ Frame = &FrameR{}
    27  
    28  // the code location for this frame, never nil
    29  func (f *FrameR) Loc() (location *CodeLocation) { return &f.CodeLocation }
    30  
    31  // function argument values like "(1, 0x14000113040)"
    32  //   - values of basic types like int are displayed
    33  //   - most types appear as a pointer value “0x…”
    34  func (f *FrameR) Args() (args string) { return f.args }
    35  
    36  // prints the Frame suitable to be part of a stack trace
    37  //   - fully qualified package name with function or type and method
    38  //     and argument values
    39  //   - absolute path to source file and line number
    40  //
    41  // output:
    42  //
    43  //	github.com/haraldrudell/parl/pdebug.TestFrame(0x1400014a340)␤
    44  //	␠␠frame_test.go:15
    45  func (f *FrameR) String() (s string) {
    46  	return f.CodeLocation.FuncName + f.args + "\n" +
    47  		"\x20\x20" + f.CodeLocation.File + ":" + strconv.Itoa(f.CodeLocation.Line)
    48  }