Ethan Trithon
Ethan Trithon

Reputation: 73

Debugging issue with fmt.Scanln

I would like to debug a very simple go program (just to see if/how things work with VSCode)

This is my src so far:

package main

import (
    "fmt"
)

func main() {
    fmt.Printf("Please enter your name\n>>")
    name := "" //«breakpoint on this line»
    fmt.Scanln(&name)
    fmt.Println("Welcome to my awesome program, " + name + "!")
}

When I start debugging, all is well until I hit the "step over" button on the next line (fmt.Scanln(&name)).

My local variables disappear from the list, I can no longer hit the "Step" buttons (only pause, which does nothing, restart and stop), and if I try and enter something into the debug console, nothing happens. Then when I stop debugging, it tells me

«whatever I entered»
*not available*

Do you know what my mistake could be? Any help would be greatly appreciated.

Upvotes: 2

Views: 1989

Answers (2)

arainchi
arainchi

Reputation: 1492

On my Macbook I had to add this to launch.json

"console": "integratedTerminal"

Without this "console" option VScode would hang at fmt.Scanln()

See https://github.com/golang/vscode-go/blob/master/docs/debugging.md for details

Upvotes: 4

jcm
jcm

Reputation: 33

Looks like this is a limitation of VSCode's implementation using the delve debugger. Maybe allowed soon, and if you run delve externally it can work right now. See discussion here: https://github.com/Microsoft/vscode-go/issues/219

Upvotes: 0

Related Questions