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 golang project, breakpoint is invalid #3447

Closed
Jerry-yz opened this issue Jul 10, 2024 · 7 comments
Closed

debug golang project, breakpoint is invalid #3447

Jerry-yz opened this issue Jul 10, 2024 · 7 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Jerry-yz
Copy link

Jerry-yz commented Jul 10, 2024

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

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • <go1.22>
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • <v1.91>
  • Check your installed extensions to get the version of the VS Code Go extension
    • <v0.41.4>
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • <{
      "debug.allowBreakpointsEverywhere": true,
      "go.alternateTools": {}
      }>

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

A clear and concise description of what the bug.
A clear and concise description of what you expected to happen.

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. See error
    Steps to Reproduce:
    breakpoint main.go line fmt.Println(i), it invalid
    func main() {
    for i := 0; i < 10; i++ {
    fmt.Println(i)
    }
    }
    2.terminal immediate output

Screenshots or recordings

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

@gopherbot gopherbot added this to the Untriaged milestone Jul 10, 2024
@hyangah
Copy link
Contributor

hyangah commented Jul 10, 2024

@Jerry-yz thanks for reaching out. I cannot reproduce it myself.

Can you capture the log and share it with us? Here is the instruction:
https://github.com/golang/vscode-go/wiki/debugging#collect-logs

And, please let us know how exactly you launched the debug session - pressing F5? or clicking "Run and Debug" button in the debug view, or having launch.json?

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 10, 2024
@Jerry-yz
Copy link
Author

Jerry-yz commented Jul 11, 2024

> @Jerry-yz thanks for reaching out. I cannot reproduce it myself.

Can you capture the log and share it with us? Here is the instruction: https://github.com/golang/vscode-go/wiki/debugging#collect-logs

And, please let us know how exactly you launched the debug session - pressing F5? or clicking "Run and Debug" button in the debug view, or having launch.json?

this is my launch.json:
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${fileDirname}" }, ] }
and terminal is output:
Starting: /home/yz/work/go/bin/dlv dap --listen=127.0.0.1:60749 --log-dest=3 from /home/yz/learn/test
DAP server listening at: 127.0.0.1:60749
Type 'dlv help' for list of commands.
3
Process 1632 has exited with status 0
Detaching
dlv dap (1456) exited with code: 0

@Jerry-yz
Copy link
Author

i edit launch.json:
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"logOutput": "dap",
"showLog": true,
"stopOnEntry": true
}
then, terminal log:
2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/home/yz/learn/test/mysql/main.go"},"breakpoints":[{"line":14}],"lines":[14]}}
2024-07-11T21:52:56+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 /home/yz/learn/test/mysql/main.go"}]}}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":4,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/home/yz/learn/test/main.go"},"breakpoints":[{"line":25}],"lines":[25]}}
2024-07-11T21:52:56+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":4,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"could not find statement at /home/yz/learn/test/main.go:25, please use a line with a statement"}]}}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":5,"type":"request","command":"setFunctionBreakpoints","arguments":{"breakpoints":[]}}
2024-07-11T21:52:56+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":5,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":6,"type":"request","command":"setInstructionBreakpoints","arguments":{"breakpoints":[]}}
2024-07-11T21:52:56+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":6,"success":true,"command":"setInstructionBreakpoints","body":{"breakpoints":[]}}

@hyangah
Copy link
Contributor

hyangah commented Jul 15, 2024

Thanks. It's a bit confusing that there are two different breakpoints involving main.go and neither worked.

Let's try what path the binary is built with.

  1. Since you already have "stopOnEntry": true, the debugging should stop at the beginning, right?
  2. When the debugging stops, open "DEBUG CONSOLE", enter "dlv sources main.go"
    Screenshot 2024-07-15 at 10 36 05 AM

What source code path does it show?

@Jerry-yz
Copy link
Author

Thanks. It's a bit confusing that there are two different breakpoints involving main.go and neither worked.

Let's try what path the binary is built with.

  1. Since you already have "stopOnEntry": true, the debugging should stop at the beginning, right?
  2. When the debugging stops, open "DEBUG CONSOLE", enter "dlv sources main.go"
    Screenshot 2024-07-15 at 10 36 05 AM

What source code path does it show?

the log output source code path
/home/yz/learn/test/mysql/main.go

@hyangah
Copy link
Contributor

hyangah commented Jul 16, 2024

That is strange. Then, if line 14 is indeed fmt.Println(i), that should work.

2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/home/yz/learn/test/mysql/main.go"},"breakpoints":[{"line":14}],"lines":[14]}}
2024-07-11T21:52:56+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 /home/yz/learn/test/mysql/main.go"}]}}

The launch request arguments and the following build messages were redacted, so I don't know exactly how you built the binary. Do you use any non-default build flags added in the launch arg or environment variables? (go env)

I am running out of ideas and cannot reproduce.

Can you try if dlv command line tool works?

$ cd /home/yz/learn/test/mysql
$ dlv debug
Type 'help' for list of commands.
(dlv) b /home/yz/learn/test/mysql/main.go:14
Breakpoint 1 set at 0x10ae6ca for main.main() ./main.go:14
(dlv) c
> [Breakpoint 1] main.main() ./main.go:14 (hits goroutine(1):1 total:1) (PC: 0x10ae6ca)
     9: )
    10:
    11: // main
    12: func main() {
    13:         for i := 0; i < 10; i++ {
=>  14:                 fmt.Println(i)
    15:         }
    16: }

Does it work for you?

@Jerry-yz
Copy link
Author

That is strange. Then, if line 14 is indeed fmt.Println(i), that should work.

2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2024-07-11T21:52:55+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}
2024-07-11T21:52:56+08:00 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/home/yz/learn/test/mysql/main.go"},"breakpoints":[{"line":14}],"lines":[14]}}
2024-07-11T21:52:56+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 /home/yz/learn/test/mysql/main.go"}]}}

The launch request arguments and the following build messages were redacted, so I don't know exactly how you built the binary. Do you use any non-default build flags added in the launch arg or environment variables? (go env)

I am running out of ideas and cannot reproduce.

Can you try if dlv command line tool works?

$ cd /home/yz/learn/test/mysql
$ dlv debug
Type 'help' for list of commands.
(dlv) b /home/yz/learn/test/mysql/main.go:14
Breakpoint 1 set at 0x10ae6ca for main.main() ./main.go:14
(dlv) c
> [Breakpoint 1] main.main() ./main.go:14 (hits goroutine(1):1 total:1) (PC: 0x10ae6ca)
     9: )
    10:
    11: // main
    12: func main() {
    13:         for i := 0; i < 10; i++ {
=>  14:                 fmt.Println(i)
    15:         }
    16: }

Does it work for you?

it not workl:
dlv debug
Type 'help' for list of commands.
(dlv) b /home/yz/learn/test/mysql/main.go:14
Command failed: could not find statement at /home/yz/learn/test/mysql/main.go:14, please use a line with a statement
(dlv)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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