doushang7209 2018-08-30 15:46
浏览 143
已采纳

Golang调试器未运行

I am trying to set up VS Code with Go, and I am getting an error when attaching the debugger. Since I am brand new to VS Code, I have no leads as to why.

I have installed delve debugger:

go get -u github.com/derekparker/delve/cmd/dlv
delv -v 
delv 9.11.3-1ubuntu1.1-Ubuntu

I get this error when I try to attach the debugger to a very simple golang file:

API server listening at: 127.0.0.1:2345
time="2018-08-30T09:39:57-06:00" level=info msg="launching process with args: [/home/craig/Documents/GoLang/src/github.com/mornindew/sharedPackages/email/debug]" layer=debugger
Can not debug non-main package
Process exiting with code: 1

Code:

package email

import "fmt"

// SendEmail - Sends The email
func SendEmail() {

}

func main() {
    fmt.Println("Hello World!")
    i := 101
    fmt.Println(i)
}

This is all very helpful, thank you very much.

It makes me think that I have a problem in my project organization. I have a project that has a bunch of reusable packages. I didn't want to create a github repo for each individual package. Essentially:

package1
-- package1.go
-- package1_test.go
package2
-- package2.go
-- package2_test.go
...
package10
-- package10.go
-- package10_test.go

Is this structured incorrectly? Is there a recommended way to accomplish this?

  • 写回答

2条回答 默认 最新

  • donglu8549 2018-08-30 15:49
    关注

    The error is because you are trying to debug non main package. Debug the file from main package if you have settings to debug the file with main function. Else you can create setting for debugging the whole package. But for your problem just change the package name as

    package main
    
    import "fmt"
    
    // SendEmail - Sends The email
    func SendEmail() {
    
    }
    
    func main() {
        fmt.Println("Hello World!")
        i := 101
        fmt.Println(i)
    }
    

    or Run debugger from the main package with main function. To debug the whole workspace change the settings in launch.json as:

    {
        "name": "Remote",
        "type": "go",
        "request": "launch",
        "mode": "remote",
        "remotePath": "${workspaceRoot}",
        "port": 2345,
        "host": "127.0.0.1",
        "program": "${workspaceRoot}",
        "env": {}
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)