Standard library / runtime

runtime.StackRecord.Stack()

Expose the nonzero prefix of the fixed-size stack buffer. Use CallersFrames for actual return PCs, not the synthetic numbers here. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (r *StackRecord) Stack() []uintptr

Return Value

[]uintptr

Prefix of the stack buffer before the first zero PC.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() { r := runtime.StackRecord{Stack0: [32]uintptr{1, 2, 0, 9}}; fmt.Println(len(r.Stack())) }
Go Reference