Code display issue in Delve for Go on Windows 10 - debugging

I've installed Delve on Windows 10 and it seems to work but the display does not show line numbers and does not point out the current line.
According to the Delve "Getting Started" Guide I should see something like
(dlv) continue
> main.main() ./test.go:5 (hits goroutine(1):1 total:1) (PC: 0x49ecf3)
1: package main
2:
3: import "fmt"
4:
=> 5: func main() {
6: fmt.Println("delve test")
7: }
(dlv)
But what I see is more like
(dlv) continue
> main.main() ./test.go:5 (hits goroutine(1):1 total:1) (PC: 0x49ecf3)
package main
import "fmt"
func main() {
fmt.Println("delve test")
}
(dlv)
I can step through the code and display variable values etc, but the lack of a current line pointer => makes it hard to use.
C:> dlv version
Delve Debugger
Version: 1.3.2
Build: $Id: 569ccbd514fc47c8b4c521b142556867ec5e6917 $
C:> go version
go version go1.12.5 windows/amd64
C:>ver
Microsoft Windows [Version 10.0.18362.418]
C:>chcp
Active code page: 850
Perhaps there is a problem due to MS Windows Command-Prompt console capabilities? Is there a workaround or other solution for this?

If you were using PowerShell, maybe you need to change the background color.
Hope it helps.

Related

A nil pointer panic occurs only in debug mode while calling fmt.Sprintf

What version of Go are you using (go version)?
$ go version
go version go1.18 darwin/amd64
What did you do?
I wrote some simple code below that it try to print a struct
import v1 "k8s.io/api/core/v1"
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
func main() {
data := v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
DeletionTimestamp: nil,
},
}
str := fmt.Sprintf("%#v", data)
fmt.Println(str)
}
What did you expect to see?
same behavior with or without debugger
What did you see instead?
I was intended to print a struct called Namespace which is defined in k8s.io/api/core/v1/types.go, when I run it simply in GoLand(GoLand 2021.3.4) without debug, it runs as expected and the structure of the object had been printed in the console, but when i run it also in Goland but with debug, the program had been interrupted by an error: "bad access: nil dereference". the call stack is:
<autogenerated>:2
fmt.(*pp).handleMethods (print.go:603) fmt
fmt.(*pp).printValue (print.go:723) fmt
fmt.(*pp).printValue (print.go:806) fmt
fmt.(*pp).printValue (print.go:806) fmt
fmt.(*pp).printArg (print.go:712) fmt
fmt.(*pp).doPrintf (print.go:1026) fmt
fmt.Sprintf (print.go:219) fmt
main.main (main.go:97) main
runtime.main (proc.go:250) runtime
runtime.goexit (asm_amd64.s:1571) runtime
- Async Stack Trace
<autogenerated>:2
this is a little bit weird: If this(panic) is a intented behavior, then how can it runs correctly without debugger?
I had the same problem. I tried to upgrade the mac os version, but it did not work.
The main reason is debugserver version,mine before version is:
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver --version
debugserver-#(#)PROGRAM:LLDB PROJECT:lldb-1205.0.27
and, later upgrade debugserver by:
sudo rm -rf /Library/Developer/CommandLineTools
and it will remain to intall again, and the latest version is:
debugserver-#(#)PROGRAM:LLDB PROJECT:lldb-1316.0.9.46
then, everything works.

VSCode import problem with windows API call

When importing golang.org/x/sys/windows in VSCode, I can only choose SIGDescribe, nothing else.
Hovering over the import, following errors appear.
error while importing golang.org/x/sys/windows: build constraints exclude all Go files in /home/username/go/pkg/mod/golang.org/x/sys#v0.0.0-20210630005230-0f9fa26af87c/windows
could not import golang.org/x/sys/windows (no required module provides package "golang.org/x/sys/windows")compilerBrokenImport
The manual command go get golang.org/x/sys/windows gives the following error message
Command 'gopls.go_get_package' failed: Error: err: exit status 1: stderr: package golang.org/x/sys/windows: build constraints exclude all Go files in /home/username/go/pkg/mod/golang.org/x/sys#v0.0.0-20210630005230-0f9fa26af87c/windows .
I already re-installed Golang and updated GoTools in VSCode, no changes.
Goal: The following code below should work.
package main
import "golang.org/x/sys/windows"
func main() {
user32DLL := windows.NewLazyDLL("user32.dll")
}
OS: Ubuntu 21.04
GO Version: 1.16.6
Editor: VSCode 1.58.1
Make a folder somewhere something. Then make a file something/main.go:
package main
import "golang.org/x/sys/windows"
func main() {
println(windows.EVENTLOG_ERROR_TYPE == 1)
}
Then build:
go mod init something
go mod tidy
go build

Every "go" command leads to a panic from a certain main.go

I've noticed that every go command has stopped working, due to a panic from a main.go in a particular module:
> go env
panic: required key FOO missing value
goroutine 1 [running]:
github.com/kelseyhightower/envconfig.MustProcess(...)
/Users/kurtpeek/go/pkg/mod/github.com/kelseyhightower/envconfig#v1.4.0/envconfig.go:233
main.main()
/Users/kurtpeek/go/pkg/mod/github.com/myorg/mymodule/go#v0.0.0-20210129234103-92f90e2df5c0/main.go:13 +0x314
where the 'offending' main go is similar to
package main
import (
"github.com/kelseyhightower/envconfig"
"github.pie.apple.com/someorg/somemodule/config"
)
func main() {
cfg := &config.Config{}
envconfig.MustProcess("", cfg)
}
I have no idea why a go env command should fail for this reason?
Your module is called github.com/myorg/mymodule/go, which means that the installed binary is called "go" (after the last path segment). This binary likely shadows the go tool depending on how your PATH is configured.
I suggest you change the module path to avoid this problem.
You might try to reinstall go as it seems that somehow the binary for go env command is replaced by a binary you were potentially trying to compile, possible reason could be you built the program in the directory containing the go tools. I recommend reinstalling go

go run command not providing enough information to debug

when I was trying out scenarios on channels in go, I came across a code to reproduce deadlock as below
package main
import (
"fmt"
)
func main() {
c := make(chan bool)
c <- true
}
when I run it using
go run gorouting.go
I am getting the below output
> main.main()
> E:/GO Samples/gorouting.go:13 +0x57
> exit status 2
but when I did run in https://play.golang.org I got more details about the exception, am I missing something in the command or do i need to do any configuration at the machine level?
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]:
main.main()
/tmp/sandbox592049259/main.go:7 +0x60
I am running with this configuration
go version go1.10.3 windows/amd64
Thanks for the help
When you use go run xxx.go go only compiles/runs that file within the main package...versus running go install && xxx where xxx is the name of your executable. go install builds everything and copies to the bin dir...try that locally.

I can't run Go programs anymore

This is the oddest problem I've ever encountered. I have my Go development environment set up on a Windows 2008 R2 virtual machine. I don't even restart it nor run Windows update.
Today I just realized that I can no longer run Go programs. I can successfully build and run unit tests with 'go test'. However, running any compiled Go program, (even hello world) causes a pop-up window titled 'Unsupported 16-bit application' to appear. The error message is as follows:
The version of this file is not compatible with the version of Windows
you're running. Check your computer's system information to see
whether you need an x86 (32-bit) or x64 (64-bit) version of the
program, and then contact the software publisher.
The result is the same regardless of what version of Go I use (x86/x64). Also note that I'm not using any IDE. I call go.exe to build/test from the command line.
I can't get my head around this since running 'go test' works just fine.
Any thoughts?
EDIT:
Here's the console output when I build and run the program:
build/run output
Interestingly, dumpbin suggests that indeed there's something wrong with the executable
C:\Program Files (x86)\Microsoft Visual Studio 11.0>dumpbin /headers
C:\Projects \GoPlayground\src\playground\playground.exe Microsoft (R)
COFF/PE Dumper Version 11.00.51106.1 Copyright (C) Microsoft
Corporation. All rights reserved.
Dump of file C:\Projects\GoPlayground\src\playground\playground.exe
File Type: LIBRARY
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4003: invali d library format; library ignored
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4048: Invali d format file; ignored
Summary
C:\Program Files (x86)\Microsoft Visual Studio 11.0>
And here's the full source code:
package playground
import "fmt"
import "playground/another"
func main() {
fmt.Println("Hello world!")
fmt.Println(another.Foobar(2))
}
-------------------
package another
func Foobar(i int) int {
return i + 1
}
EDIT2:
I've reinstalled Go twice with no effect.
The Go Programming Language Specification
Program execution
A complete program is created by linking a single, unimported package
called the main package with all the packages it imports,
transitively. The main package must have package name main and declare
a function main that takes no arguments and returns no value.
func main() { … }
Program execution begins by initializing the main package and then
invoking the function main. When that function invocation returns, the
program exits. It does not wait for other (non-main) goroutines to
complete.
Use package main, not package playground. For example,
playground.go:
package main
import (
"fmt"
"playground/another"
)
func main() {
fmt.Println("Hello world!")
fmt.Println(another.Foobar(2))
}
playground/another.go:
package another
func Foobar(i int) int {
return i + 1
}
Output:
Hello world!
3

Resources