Spectrum 链开发--IDE 断点调试介绍

栏目: 编程工具 · 发布时间: 7年前

Spectrum 链开发--IDE 断点调试介绍

作者:GirpZhang

实验环境

  • Windows10

  • go1.9.2.windows-amd64

  • Visual Studio Code

  • Git 2.18.0

需要完成 Visual Studio Code + GoLang 开发环境配置

  • 安装 go 1.9.2.windows-amd64

  • 安装 Git

  • 安装 GoLang,配置 GOPATH

    本例中使用的 "GOPATH":"E:/GoPath";"GOROOT":"E:/Go"

  • 安装 Visual Studio Code,安装 Go 插件,介绍中是 Rich Go language support for Visual Studio Code

  • 调试配置:

    VSCode->查看->调试->添加调试目标,在"没有调试"的下拉框中点击"添加配置.." 添加目标调试配置:

{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Launch",

            "type": "go",

            "request": "launch",

            "mode": "debug",

            "remotePath": "",

            "port": 2345,

            "host": "127.0.0.1",

            "program": "${fileDirname}",

            "env": {

                "GOPATH":"E:/GoPath",

                "GOROOT":"E:/Go"

            },

            "args": [],

            "showLog": true

        }

    ]

}

下载 Spectrum 代码

git clone git@github.com:SmartMeshFoundation/Spectrum.git

调试准备

  • 在 E:/GoPath/src 下新建多级目录:\github.com\SmartMeshFoundation\Spectrum

  • 将下载下来的 Spectrum.git 中的代码复制到 E:/GoPath/src/github.com/SmartMeshFoundation/Spectrum 下

  • 打开 VSCode,选择 文件->打开文件夹->打开 Spectrum 文件夹

  • 打开 cmd->smc->main.go 文件

  • F5 调试,会提示如下错误:

Failded to continue:"Cannot find Delve debugger. Install from https://github.com/derekparker/delve & ensure it is in your "GOPATH/bin" or "PATH"
  • 然后我们使用 Go 命令行编译调试器、将 dlv 调试器放在 GOPATH 的 bin 目录下

    • 使用 cmd 命令行,进入目录 E:\GoPath\bin

    • 执行命令安装 dlv

    go get github.com/derekparker/delve/cmd/dlv
  • 然后就可以正常调试了,在需要的地方打上断点进行单步调试:

Spectrum 链开发--IDE 断点调试介绍

image


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Programming Collective Intelligence

Programming Collective Intelligence

Toby Segaran / O'Reilly Media / 2007-8-26 / USD 39.99

Want to tap the power behind search rankings, product recommendations, social bookmarking, and online matchmaking? This fascinating book demonstrates how you can build Web 2.0 applications to mine the......一起来看看 《Programming Collective Intelligence》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具