//t.go
package main
import (
"fmt"
"os"
"reflect"
"unsafe"
)
func main() {
s1 := make([]uint8, 0)
aboutSlice(&s1, "s1")
s2 := make([]uint8, 8)
aboutSlice(&s2, "s2")
new_s1 := append(s1, 10)
new_s2 := append(s2, 20)
aboutSlice(&new_s1, "new_s1")
aboutSlice(&new_s2, "new_s2")
os.Exit(0)
}
func aboutSlice(s *[]uint8, n string) {
fmt.Printf("%s:\tmem_addr:%p\tsize:%v\taddr:%#x\tlen:%v\tcap:%v\n", n, s, unsafe.Sizeof(*s), (*reflect.SliceHeader)(unsafe.Pointer(s)).Data, len(*s), cap(*s))
}
I want to analyze the behavior of function growslice(in runtime/slice.go),and then set breakpoints on func growslice,I use
n and
s to analyze it, but it will skip some step, like the picture below:
