英文:
Vscode debug breakpoint passed over
问题
我正在运行最新的VScode 1.74.2,Golang 1.19.4和最新的Go工具,操作系统是macOS Ventura 13.1。
我有一个简单的“Hello World”程序,其中包含2个断点。每次都会跳过第一个断点。
这似乎与下面的特定golang子句有关。无论我把它放在哪里并在If语句处设置断点,调试器都会直接跳过它,到达下一个断点并停在那里。非常令人困惑。
if runtime.GOOS != `darwin` {
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
完整程序:
package main
import (
"fmt"
"os"
"runtime"
)
func main() {
if runtime.GOOS != `darwin` {
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
fmt.Println(`Hello World!`)
}
是一个bug吗?
我打开了详细跟踪,添加了一个fmt.Println语句在if语句之前,然后在第一个fmt.Println语句(第19行),if语句(第21行)和if语句子句后的fmt.Println语句(第26行)上设置了断点。然后开始调试。调试器在第19行停下来,并禁用了第21行的断点!
请参见附加的截图。
在跟踪中我看到了这个:
“[19:33:38.490 UTC] Error on CreateBreakpoint: could not find statement at /Users/gforghetti/Projects/Golang/Golang-gforghetti/Test_Programs/HelloWorld/HelloWorld.go:21, please use a line with a statement”
英文:
I'm running the latest VScode 1.74.2, Golang 1.19.4, and the latest Go Tools on macOs Ventura 13.1.
Got a simple "Hello World" program with 2 breakpoints. The 1st breakpoint is bypassed everytime.
It seems to be related to this specific golang clause below. No matter where I put it and set the breakpoint at the If statement, the debugger shoots right past it to the next breakpoint and stops there. Very confusing.
if runtime.GOOS != `darwin` {
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
Complete program:
package main
import (
"fmt"
"os"
"runtime"
)
func main() {
if runtime.GOOS != `darwin` {
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
fmt.Println(`Hello World!`)
}
A bug?
I was expecting the debugger to stop at the 1st breakpoint at the if statement.
I turned on Verbose tracing, added a fmt.Println statement before the if statement and then set breakpoints on the 1st fmt.Println statement (line 19), the if statement (line 21) and the fmt.Println statement (line 26) following the if statement clause. Then started debugging. The devolve debugger stopped on line 19 and disabled the breakpoint on line 21!
See attached screens.
Looking in the trace I see this:
"[19:33:38.490 UTC] Error on CreateBreakpoint: could not find statement at /Users/gforghetti/Projects/Golang/Golang-gforghetti/Test_Programs/HelloWorld/HelloWorld.go:21, please use a line with a statement"
答案1
得分: 1
Delve(vscode go的调试后端)找不到与第一个断点对应的语句,并且只使用第二个断点开始调试会话。如果您查看“断点”面板,您会发现第一个断点变灰了。
这在调试会话期间启用详细跟踪时更加明显。(在launch.json启动配置中设置"trace": "verbose"
,并检查“Go Debug”输出通道)
[Trace - 09:55:31.99] client -> {
"command":"setBreakpoints",
"arguments":{
"source": {"name":"main.go","path":"/project/demo/main.go"},
"lines":[10,14],"breakpoints":[{"line":10},{"line":14}],
"sourceModified":false},
"type":"request","seq":3}
...
[Trace - 09:55:31.101] client <- {
"seq":0,
"type":"response",
"request_seq":3,
"success":true,
"command":"setBreakpoints",
"body":{
"breakpoints":
[
{"verified":false,
"message":"could not find statement at /project/demo/main.go:10, please use a line with a statement",
"source":{}},
{"id":2,"verified":true,
"source": {"name":"main.go","path":"/project/demo/main.go"},"line":14}]}}
如果您更改代码以添加语句,您将能够在第一个断点处停止。
...
func main() {
if x := runtime.GOOS; x != `darwin` { // <-- 现在第一个断点有效。
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
fmt.Println(`Hello World!`)
}
提示:您可以通过选择上下文菜单(鼠标右键单击)中的“打开反汇编视图”来查看汇编代码,并查看Go编译器生成的代码。
英文:
Delve (vscode go's debugging backend) couldn't find a statement corresponding to the first breakpoint and started the debugging session with only the second breakpoint. If you look at the "Breakpoints" panel, you will see the first breakpoint was greyed out.
This is more visible when you enable the verbose tracing during the debugging session. (Set "trace": "verbose"
in launch.json launch configuration and check "Go Debug" OUTPUT channel)
[Trace - 09:55:31.99] client -> {
"command":"setBreakpoints",
"arguments":{
"source": {"name":"main.go","path":"/project/demo/main.go"},
"lines":[10,14],"breakpoints":[{"line":10},{"line":14}],
"sourceModified":false},
"type":"request","seq":3}
...
[Trace - 09:55:31.101] client <- {
"seq":0,
"type":"response",
"request_seq":3,
"success":true,
"command":"setBreakpoints",
"body":{
"breakpoints":
[
{"verified":false,
"message":"could not find statement at /project/demo/main.go:10, please use a line with a statement",
"source":{}},
{"id":2,"verified":true,
"source": {"name":"main.go","path":"/project/demo/main.go"},"line":14}]}}
If you change the code to add a statement, you will be able to stop at the first breakpoint.
...
func main() {
if x := runtime.GOOS; x != `darwin` { // <-- first breakpoint now valid.
fmt.Fprintln(os.Stderr, `only runs on macOS`)
os.Exit(1)
}
fmt.Println(`Hello World!`)
}
Tip: You can check the assembly code by selecting "Open Disassembly View" from the context menu (mouse right click) and see what code the Go compiler produces.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论