【发布时间】:2021-12-22 13:13:16
【问题描述】:
如果没有 Cgo 代码,我可以在 Visual Studio Code 中设置断点并单步执行 Go 代码而不会出现问题。一旦在 Go 代码中调用了 Cgo 代码,断点基本上就被忽略了,尽管应用程序运行良好。
这里是sn-p:
//hello.c
#include <stdio.h>
void Test() {
printf("C: Hello world");
}
//hello.go
package main
// #cgo LDFLAGS: -Wl,--allow-multiple-definition
// #cgo CFLAGS: -Wall -std=c99 -O1 -g
/*
#include "hello.c"
*/
import "C"
import "fmt"
func main() {
//Call to void function without params
C.Test()
fmt.Printf("Go: Hello world\n")
}
//launch.json
{
// 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 Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "learning"
}
]
}
【问题讨论】:
标签: go debugging visual-studio-code cgo