[go-nuts] use delve to debug golang with 'next' will skip some step

84 views
Skip to first unread message

林 子鹏

unread,
Jul 27, 2021, 1:57:17 PM7/27/21
to golan...@googlegroups.com
When I use delve to debug this project(dlv debug t.go):
//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:

jake...@gmail.com

unread,
Jul 27, 2021, 6:26:19 PM7/27/21
to golang-nuts
Was the code built with optimizations disabled?

drc...@google.com

unread,
Jul 28, 2021, 9:00:36 AM7/28/21
to golang-nuts
That debugging is (now) in the runtime package, which is (always) compiled with optimizations on.
That will tend to interfere with debugging.  The 1.17 change to use registers for passing parameters
has also caused some regressions in debugging quality (and it would be nice to fix those, but it is tricky).
Reply all
Reply to author
Forward
0 new messages