Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: Cannot Debug goyacc file #1674

Closed
acekingke opened this issue Aug 9, 2021 · 9 comments
Closed

debug: Cannot Debug goyacc file #1674

acekingke opened this issue Aug 9, 2021 · 9 comments
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@acekingke
Copy link

For asking questions, see:

Before filing an issue, please review our troubleshooting guides

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go from the VS Code integrated terminal.
    go version go1.16.6 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    ➜ ~ gopls -v version
    Build info

golang.org/x/tools/gopls v0.7.1
golang.org/x/tools/[email protected] h1:Mh3Z8Xcoq3Zy7ksSlwDV/nzQSbjFf06A+L+F8YHq55U=
github.com/BurntSushi/[email protected] h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/google/[email protected] h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/[email protected] h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/[email protected] h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/[email protected] h1:ZC/gVBZl8poJyKzWLxxlsmhayVGosF4mohR35szD5Bg=
golang.org/x/[email protected] h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
honnef.co/go/[email protected] h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
mvdan.cc/[email protected] h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
mvdan.cc/xurls/[email protected] h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    ➜ ~ code -v
    1.59.0
    379476f0e13988d90fab105c5c19e7abc8b1dea8
    x64

  • Check your installed extensions to get the version of the VS Code Go extension
    Go
    v0.26.0

  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    Checking configured tools....
    GOBIN: undefined
    toolsGopath:
    gopath: /root/gopath
    GOROOT: /root/go
    PATH: /root/go/bin:/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/bin:/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/gopath/bin:/usr/local/bin

    gopkgs: gopkgs not installed
    go-outline: /root/gopath/bin/go-outline installed
    gotests: /root/gopath/bin/gotests installed
    gomodifytags: gomodifytags not installed
    impl: impl not installed
    goplay: goplay not installed
    dlv: /root/gopath/bin/dlv installed
    dlv-dap: dlv-dap not installed
    staticcheck: staticcheck not installed
    gopls: /root/gopath/bin/gopls installed

go env
Workspace Folder (radondb-mysql-kubernetes): /root/radondb-mysql-kubernetes
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/gopath"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/root/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/radondb-mysql-kubernetes/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build570529864=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

I add expr.y , and go generate , But it cannot breakpoint for it

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This is an example of a goyacc program.
// To build it:
// goyacc -p "expr" expr.y (produces y.go)
// go build -o expr y.go
// expr
// > <type an expression>

%{

package main

import (
	"bytes"
	"fmt"
	"log"
	"math/big"

	"unicode/utf8"
)

%}

%union {
	num *big.Rat
}

%type	<num>	expr expr1 expr2 expr3

%token '+' '-' '*' '/' '(' ')'

%token	<num>	NUM

%%

top:
	expr
	{
		if $1.IsInt() {
			fmt.Println($1.Num().String())
		} else {
			fmt.Println($1.String())
		}
	}

expr:
	expr1
|	'+' expr
	{
		$$ = $2
	}
|	'-' expr
	{
		$$ = $2.Neg($2)
	}

expr1:
	expr2
|	expr1 '+' expr2
	{
		$$ = $1.Add($1, $3)
	}
|	expr1 '-' expr2
	{
		$$ = $1.Sub($1, $3)
	}

expr2:
	expr3
|	expr2 '*' expr3
	{
		$$ = $1.Mul($1, $3)
	}
|	expr2 '/' expr3
	{
		$$ = $1.Quo($1, $3)
	}

expr3:
	NUM
|	'(' expr ')'
	{
		$$ = $2
	}


%%

// The parser expects the lexer to return 0 on EOF.  Give it a name
// for clarity.
const eof = 0

// The parser uses the type <prefix>Lex as a lexer. It must provide
// the methods Lex(*<prefix>SymType) int and Error(string).
type exprLex struct {
	line []byte
	peek rune
}

// The parser calls this method to get each new token. This
// implementation returns operators and NUM.
func (x *exprLex) Lex(yylval *exprSymType) int {
	for {
		c := x.next()
		switch c {
		case eof:
			return eof
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			return x.num(c, yylval)
		case '+', '-', '*', '/', '(', ')':
			return int(c)

		// Recognize Unicode multiplication and division
		// symbols, returning what the parser expects.
		case '×':
			return '*'
		case '÷':
			return '/'

		case ' ', '\t', '\n', '\r':
		default:
			log.Printf("unrecognized character %q", c)
		}
	}
}

// Lex a number.
func (x *exprLex) num(c rune, yylval *exprSymType) int {
	add := func(b *bytes.Buffer, c rune) {
		if _, err := b.WriteRune(c); err != nil {
			log.Fatalf("WriteRune: %s", err)
		}
	}
	var b bytes.Buffer
	add(&b, c)
	L: for {
		c = x.next()
		switch c {
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'e', 'E':
			add(&b, c)
		default:
			break L
		}
	}
	if c != eof {
		x.peek = c
	}
	yylval.num = &big.Rat{}
	_, ok := yylval.num.SetString(b.String())
	if !ok {
		log.Printf("bad number %q", b.String())
		return eof
	}
	return NUM
}

// Return the next rune for the lexer.
func (x *exprLex) next() rune {
	if x.peek != eof {
		r := x.peek
		x.peek = eof
		return r
	}
	if len(x.line) == 0 {
		return eof
	}
	c, size := utf8.DecodeRune(x.line)
	x.line = x.line[size:]
	if c == utf8.RuneError && size == 1 {
		log.Print("invalid utf8")
		return x.next()
	}
	return c
}

// The parser calls this method on a parse error.
func (x *exprLex) Error(s string) {
	log.Printf("parse error: %s", s)
}

func main() {
	linestring := "12+1"
	exprParse(&exprLex{line:  []byte(linestring)})
}

The debug launch.json as follow:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}/expr.go",
            "env": {},
            "externalConsole": true,
            "args": []
        }
    ]
}

Steps to reproduce the behavior:

  1. configure the lauch.json
  2. breakpiont in expr.go main function
  3. run, It cannot breakpoint

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

@gopherbot gopherbot added this to the Untriaged milestone Aug 9, 2021
@hyangah
Copy link
Contributor

hyangah commented Aug 9, 2021

@acekingke We need more info. Is there any error message shown in the DEBUG CONSOLE pane or popup message?

@hyangah hyangah added Debug Issues related to the debugging functionality of the extension. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 9, 2021
@hyangah hyangah changed the title Cannot Debug goyacc file debug: Cannot Debug goyacc file Aug 9, 2021
@acekingke
Copy link
Author

NO message, just cannot break at breakpoint

@hyangah
Copy link
Contributor

hyangah commented Aug 10, 2021

@acekingke Can you please update the extension to the latest (v0.27.0) and enable verbose logging and share what's printed in DEBUG CONSOLE pane?

To enable verbose logging:

   "logOutput": "dap,debugger",
   "showLog": true

@acekingke
Copy link
Author

It is updated to v0.27.0.
result is :

Starting: /root/gopath/bin/dlv-dap dap --listen=127.0.0.1:33063 --log=true --log-output=debugger,dap --log-dest=3
DAP server listening at: 127.0.0.1:33063
2021-08-11T11:43:21+08:00 debug layer=dap DAP server pid = 292825
2021-08-11T11:43:21+08:00 debug layer=dap [<- from client]{"seq":1,"type":"request","command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"go","locale":"en","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"supportsMemoryReferences":true,"supportsProgressReporting":true,"supportsInvalidatedEvent":true}}
2021-08-11T11:43:21+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":true,"supportsConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsSetVariable":true,"supportsExceptionInfoRequest":true,"supportTerminateDebuggee":true,"supportsDelayedStackTraceLoading":true,"supportsClipboardContext":true}}
2021-08-11T11:43:21+08:00 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"launch","arguments":{"__configurationTarget":5,"__sessionId":"f4c75b6b-94bb-422d-8a9e-ddb3acd3c7e7","apiVersion":2,"args":[],"debugAdapter":"dlv-dap","dlvLoadConfig":{"followPointers":true,"maxArrayValues":64,"maxStringLen":64,"maxStructFields":-1,"maxVariableRecurse":1},"dlvToolPath":"/root/gopath/bin/dlv-dap","env":{"BROWSER":"/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/bin/helpers/browser.sh","GO111MODULE":"on","GOMODCACHE":"/root/gopath/pkg/mod","GOPATH":"/root/gopath","GOPROXY":"https://goproxy.io","GOROOT":"/root/go","HOME":"/root","LESS":"-R","LOGNAME":"root","LSCOLORS":"Gxfxcxdxbxegedabagacad","LS_COLORS":"","MAIL":"/var/mail/root","OLDPWD":"/root","PAGER":"less","PATH":"/root/go/bin:/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/bin:/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/gopath/bin:/usr/local/bin","PWD":"/root","SHELL":"/usr/bin/zsh","SHLVL":"1","SSH_CLIENT":"171.113.248.208 5003 22","SSH_CONNECTION":"171.113.248.208 5003 192.168.0.7 22","USER":"root","VSCODE_AGENT_FOLDER":"/root/.vscode-server","VSCODE_AMD_ENTRYPOINT":"vs/server/remoteExtensionHostProcess","VSCODE_CWD":"/root","VSCODE_EXTHOST_WILL_SEND_SOCKET":"true","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH":"/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/remote/node_modules","VSCODE_IPC_HOOK_CLI":"/tmp/vscode-ipc-a95d610e-5060-4b2f-877e-9747b639d995.sock","VSCODE_LOG_NATIVE":"false","VSCODE_LOG_STACK":"false","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"availableLanguages\":{}}","VSCODE_PIPE_LOGGING":"true","VSCODE_VERBOSE_LOGGING":"true","ZSH":"/root/.oh-my-zsh","_":"/root/.vscode-server/bin/379476f0e13988d90fab105c5c19e7abc8b1dea8/node"},"externalConsole":true,"logOutput":"debugger,dap","mode":"debug","name":"Launch","packagePathToGoModPathMap":{"/root/temp":"/dev"},"program":"/root/temp/expr.go","request":"launch","showGlobalVariables":false,"showLog":true,"substitutePath":[],"type":"go"}}
2021-08-11T11:43:21+08:00 debug layer=dap debug backend is 'default'
2021-08-11T11:43:21+08:00 debug layer=dap building binary '/root/temp/__debug_bin' from '/root/temp/expr.go' with flags ''
2021-08-11T11:43:21+08:00 debug layer=dap running program in /root/temp

2021-08-11T11:43:21+08:00 info layer=debugger launching process with args: [/root/temp/__debug_bin]
2021-08-11T11:43:21+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2021-08-11T11:43:21+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}
2021-08-11T11:43:21+08:00 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"expr.go","path":"/root/temp/expr.go"},"breakpoints":[{"line":144},{"line":553},{"line":599}],"lines":[144,553,599]}}
2021-08-11T11:43:21+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"could not find file /root/temp/expr.go","source":{}},{"verified":false,"message":"could not find file /root/temp/expr.go","source":{}},{"verified":false,"message":"could not find file /root/temp/expr.go","source":{}}]}}
2021-08-11T11:43:22+08:00 debug layer=dap [<- from client]{"seq":4,"type":"request","command":"setFunctionBreakpoints","arguments":{"breakpoints":[]}}
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":4,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
2021-08-11T11:43:22+08:00 debug layer=dap [<- from client]{"seq":5,"type":"request","command":"configurationDone","arguments":{}}
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":5,"success":true,"command":"configurationDone"}
2021-08-11T11:43:22+08:00 debug layer=debugger continuing
13
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}
2021-08-11T11:43:22+08:00 debug layer=dap [<- from client]{"seq":6,"type":"request","command":"threads"}
2021-08-11T11:43:22+08:00 debug layer=dap Process 292868 has exited with status 0
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":6,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"Dummy"}]}}
2021-08-11T11:43:22+08:00 debug layer=dap [<- from client]{"seq":7,"type":"request","command":"disconnect","arguments":{}}
2021-08-11T11:43:22+08:00 debug layer=debugger halting
2021-08-11T11:43:22+08:00 debug layer=dap halt returned state: Process 292868 has exited with status 0
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Process 292868 has exited with status 0\n","source":{}}}
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Detaching\n","source":{}}}
2021-08-11T11:43:22+08:00 debug layer=debugger detaching
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":7,"success":true,"command":"disconnect"}
2021-08-11T11:43:22+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}
2021-08-11T11:43:22+08:00 debug layer=dap DAP server stopping...
2021-08-11T11:43:22+08:00 debug layer=dap DAP server stopped
Process 292868 has exited with status 0
Detaching
dlv dap (292825) exited with code: 0

@hyangah
Copy link
Contributor

hyangah commented Aug 12, 2021

Thanks @aceking

Looks like the breakpoint couldn't be found from the compiled binary. There are visual signals for unverified breakpoints
but since the program exited so fast, it's possible that users wouldn't recognize it.

2021-08-11T11:43:21+08:00 debug layer=dap [-> to client]{
"seq":0,"type":"response","request_seq":3,"success":true,
"command":"setBreakpoints","body":{
   "breakpoints":[{"verified":false,"message":"could not find file /root/temp/expr.go","source":{}}, ...

Not sure why this happened. My current guess is the symlink - @acekingke what is the relationship between /root/temp and /dev?

2021-08-11T11:43:21+08:00 debug layer=dap [<- from  #client]{"seq":2,"type":"request","command":"launch","arguments":{
...
"packagePathToGoModPathMap": {"/root/temp":"/dev"},
"program":"/root/temp/expr.go",
"request":"launch",
...}

@acekingke
Copy link
Author

It's not symlink

@acekingke
Copy link
Author

/root/temp is my code directory ,I don't why /dev occur here

1 similar comment
@acekingke
Copy link
Author

/root/temp is my code directory ,I don't why /dev occur here

@hyangah
Copy link
Contributor

hyangah commented Nov 10, 2021

Sorry I cannot guess your file system set up but the extension and go command's behavior. The /dev is the directory the Go command think the go.mod file exists - the go extension retrieves this info by running go env GOMOD command from the workspace root directory (i.e. /root/temp).

If the problem persists, I think one option is to use the substitutePath attribute to tell dlv to treat all /root/temp file names like /dev.

@hyangah hyangah closed this as completed Nov 12, 2021
@golang golang locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants