consider the small snippet below:
package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
for i := 1; i < 100; i++ {
fmt.Println("A:", i)
}
}()
go func() {
defer wg.Done()
for i := 1; i < 100; i++ {
fmt.Println("B:", i)
}
}()
wg.Wait()
}
in delve, we can easily switch between goroutines using the commands like
goroutine
goroutine <id>
goroutine <id> <command>
and if i want run step by step in goroutine 1, just use the command
goroutine 1 next
In vscode, it seems the only way to deal with goroutines is the call stack, however, it seems that this is the internal threads in go runtime, not the goroutines, so how can i focus the running process in the specified goroutine?
so how can i focus the running process in the specified goroutine?
vscode-go issue 1797 should bring a possible solution:
For example, when debugging a simple hello world program, 5 different goroutines appear in the callstack:
This proposal is to (by default) only show the user goroutines in the call stack. When using this new default, the call stack for hello world will only show a single goroutine, as would be expected from a simple program with no concurrency:
It just (Oct. 2021) has been submitted in CL 359402 (CL = Change List: a set of commits/patches)
package.json: add config to hide system goroutines in debug
This change includes the configuration for hiding the system goroutines in a debug session
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With