kg_sYy
kg_sYy

Reputation: 1215

scanner.Scan() hangs in GoLand debugger

Using Go v1.11.1 on OSX Mojava with GoLand 2018.3. When I run the following program in normal mode (not via debugger), it works fine. When I run it with the debugger, it hangs in the scanner.Scan() call.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    fmt.Println("Hello")
    fmt.Print("> ")

    for scanner.Scan() {
        input := scanner.Text()
        fmt.Println(input)
        fmt.Print("> ")
    }

}

Stepping through with the debugger, scanner.Scan() seems to hang on reading the input. I got to this line in file called "zsyscall_darwin_amd64.go":

r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p)))

It never returns, regardless of what I type in the command prompt. In the non-debugger configuration it works fine and prints back anything I type (after pressing enter).

Upvotes: 4

Views: 687

Answers (1)

kg_sYy
kg_sYy

Reputation: 1215

Thanks for the comments. After reporting the issue I was made aware this is a known issue in GoLand and has been over a year now:

https://youtrack.jetbrains.com/issue/GO-4264

There seems to be some issue with the delve debugger backend on OSX. A potential workaround in the comments relates to compiling your own backend in native mode, but this potentially causes other issues.

Hope it gets fixed soon. Quite difficult to debug without a debugger :).

Upvotes: 2

Related Questions