vscode利用lauch.json和docker中的delve调试本地crdb(远程调试go程序)

----在这里插入图片描述

在这里插入图片描述


参考链接:

https://github.com/cockroachdb/cockroach/blob/master/docs/design.md

如果不记录就会变成大沙比

所用镜像:kdp-system/crdb-compiler

编译为release模式的镜像:cockroachdb/builder(该镜像为cockroachdb自带


root@e69d78bbd052:/home/inspur/src/github.com/cockroach
db/cockroach# make help            
Running make with -j16
GOPATH set to /home/inspur
Detected change in build system. Rebooting make.
Running make with -j16
GOPATH set to /home/inspur
Usage:
  make [target...] [VAR=foo VAR2=bar...]

Useful commands:
  acceptance                     Run acceptance tests.
  archive                        Build a source tarball from this repository.
  bench                          Run benchmarks.
  build                          Build the CockroachDB binary.
  buildoss                       Build the CockroachDB binary without any CCL-licensed code.
  buildshort                     Build the CockroachDB binary without the admin UI.
  check-libroach                 Run libroach tests.
  clean                          Remove build artifacts.
  compose                        Run compose tests.
  fuzz                           Run fuzz tests.
  generate                       Regenerate generated code.
  help                           Print help for targets with comments.
  install                        Install the CockroachDB binary.
  lint                           Run all style checkers and linters.
  lintshort                      Run a fast subset of the style checkers and linters.
  maintainer-clean               Like clean, but also remove some auto-generated source code.
  pre-push                       Run generate, lint, and test.
  protobuf                       Regenerate generated code for protobuf definitions.
  stress                         Run tests under stress.
  stressrace                     Run tests under stress with the race detector enabled.
  test                           Run tests.
  testbaselogic                  Run SQL Logic Tests.
  testccllogic                   Run SQL CCL Logic Tests.
  testoptlogic                   Run SQL Logic Tests from opt package.
  testrace                       Run tests with the Go race detector enabled.
  ui-clean                       Remove build artifacts.
  ui-maintainer-clean            Like clean, but also remove installed dependencies
  unsafe-clean                   Like maintainer-clean, but also remove ALL untracked/ignored files.

Useful variables:
  ACCEPTANCETIMEOUT              Test timeout to use for acceptance tests.
  BENCHES                        Benchmarks to run for use with `make bench`.
  BENCHTIMEOUT                   Test timeout to use for benchmarks.
  BUILDINFO_TAG                  Override for .buildinfo/tag
  CLUSTER                        Cluster to use for `make roachprod-stress`
  DESTDIR                        Indicate the base root directory where to install
  FILES                          Space delimited list of logic test files to run, for make testlogic/testccllogic/testoptlogic.
  GOTESTFLAGS                    selectively.  There's likely a better solution.
  LINTTIMEOUT                    Test timeout to use for the linter.
  PKG                            Which package to run tests against, e.g. "./pkg/foo".
  RACETIMEOUT                    Test timeout to use for race tests.
  STRESSFLAGS                    Extra flags to pass to `stress` during `make stress`.
  TESTFLAGS                      Extra flags to pass to the go test runner, e.g. "-v --vmodule=raft=1"
  TESTS                          Tests to run for use with `make test` or `make check-libroach`.
  TESTTIMEOUT                    Test timeout to use for regular tests.
  VERBOSE                        Verbose allows turning on verbose output from the cmake builds.

Typical usage:
  make test
    Run all unit tests.

  make test PKG=./pkg/sql
    Run all unit tests in the ./pkg/sql package

  make test PKG=./pkg/sql/parser TESTS=TestParse
    Run the TestParse test in the ./pkg/sql/parser package.

  make bench PKG=./pkg/sql/parser BENCHES=BenchmarkParse
    Run the BenchmarkParse benchmark in the ./pkg/sql/parser package.

  make testlogic
    Run all OSS SQL logic tests.

  make testccllogic
    Run all CCL SQL logic tests.

  make testoptlogic
    Run all opt exec builder SQL logic tests.

  make testbaselogic
    Run all the baseSQL SQL logic tests.

  make testlogic FILES='prepare|fk'
    Run the logic tests in the files named prepare and fk (the full path is not required).

  make testlogic FILES=fk SUBTESTS='20042|20045'
    Run the logic tests within subtests 20042 and 20045 in the file named fk.

  make testlogic TESTCONFIG=local
    Run the logic tests for the cluster configuration 'local'.

  make fuzz
    Run all fuzz tests for 12m each (or whatever the default TESTTIMEOUT is).

  make fuzz PKG=./pkg/sql/... TESTTIMEOUT=1m
    Run all fuzz tests under the sql directory for 1m each.

  make fuzz PKG=./pkg/sql/sem/tree TESTS=Decimal TESTTIMEOUT=1m
    Run the Decimal fuzz tests in the tree directory for 1m.

  make check-libroach TESTS=ccl
    Run the libroach tests matching .*ccl.*


make clean
#编译crdb,在docker中
make build(开发者模式)
make install(部署模式)

https://github.com/cockroachdb/cockroach/blob/release-20.1/build/README.md

vscode利用delve调试crdb


  • 创建了一个delve容器用于debug crdb
  • delve:

Delve是一个用于Go编程语言的调试器。它提供了一组命令和功能,可以帮助开发人员在调试过程中检查变量、设置断点、单步执行代码等操作。Delve可以与Go程序一起使用,以便在运行时检查和调试代码。它是一个强大的工具,可以帮助开发人员快速定位和解决问题。

你可以使用Delve来调试CockroachDB,它是一个基于Go语言开发的分布式数据库系统。通过在CockroachDB代码中设置断点,你可以使用Delve来跟踪代码的执行,检查变量的值,并在需要时进行单步调试。

  • 配置vscode的lauch.json文件

    • 安装go扩展

      首先确保已在vscode中安装go扩展,并且可以使用delve进行调试

    • 创建launch.json文件

      选择debug中的创建launch.json,选择go,connect to server
      在这里插入图片描述

    • 配置lauch.json

      {
      // 使用 IntelliSense 了解相关属性。 
      // 悬停以查看现有属性的描述。
      // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
      "version": "0.2.0",
      "configurations": [
          {
              "name": "Connect to docker delve",
              "type": "go",
              "debugAdapter": "dlv-dap",
              "request": "attach",
              "mode": "remote",
              //"remotePath": "${workspaceFolder}/cockroach/cockroach",///home/inspur/src/github.com/cockroachdb/cockroach
              "port": 16013, //del_port
              "host": "172.18.0.8",//node_ip
              //"program":"${workspaceFolder}/cockroach",
              //"cwd":"/nvme/go/src/github.com/cockroachdb/cockroach", 
              "cwd":"${workspaceFolder}",
              "substitutePath": [
                  {"from":"/nvme/go/src/github.com/cockroachdb/cockroach","to":"/home/inspur/src/github.com/cockroachdb/cockroach"}
              ],
              //"env":{"gopath":"/home/inspur/go"},
              "showLog": true,//启动调试日志
              //"miDebuggerPath": "/home/inspur/bin/dlv",
              //"sudo": true
          }
      ]
      
      
    • 启动调试

      保存lauch.json后,点击左侧的运行并点击播放按钮(这个时候禁用所有断点,等到执行sql语句之前再启动所有断点)

      出现以下错误:
      在这里插入图片描述

      因为俺这个沙比的容器中执行DLV的脚本不小心挂了。。。。重启就好了。。。
      在这里插入图片描述
      参考链接:https://github.com/golang/vscode-go/blob/master/docs/debugging.md

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值