【问题标题】:How to debug Go with Cgo in Visual Studio Code如何在 Visual Studio Code 中使用 Cgo 调试 Go
【发布时间】: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


    【解决方案1】:

    这是目前已知的bug。这可能会在 go 1.18 中得到修复。在 Linux 上可以正常调试。

    【讨论】:

      猜你喜欢
      • 2017-09-20
      • 1970-01-01
      • 2016-12-27
      • 2020-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多