atian25 / blog

天猪部落阁 http://atian25.github.io
1.59k stars 107 forks source link

使用 vscode@1.6 断点调试 egg cluster #15

Closed atian25 closed 6 years ago

atian25 commented 8 years ago

前言

上一次的折腾参见: https://github.com/atian25/blog/issues/14

配置

在刚发布的 vscode 1.6 release note 中, 可以解决该问题, 具体步骤:

  "runtimeArgs": [
     "--nolazy", "--debug"
  ],
  "port": 5859,

image

atian25 commented 8 years ago

好像有问题, 重启后端口占用, 之前的进程没退出. 估计是 egg cluster 守护了, vscode 干不掉, 再研究下

研究结果:

update:

atian25 commented 7 years ago

1.8 里面可以这么用, 虽然调试体验还是一般.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "start egg",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/index.js",
      "cwd": "${workspaceRoot}",
      "runtimeArgs": [
        "--debug"
      ],
      "port": 5859
    },
    {
      "name": "attach worker",
      "type": "node",
      "request": "attach",
      "port": 5858
    },
    {
      "name": "attach agent",
      "type": "node",
      "request": "attach",
      "port": 5856
    }
  ],
  "compounds": [
    {
      "name": "egg debug",
      "configurations": ["start egg", "attach worker", "attach agent"]
    }
  ]
}
Rwing commented 7 years ago

假如我想debug断点EggCore的构造函数,好像用这个方法不行....

atian25 commented 7 years ago

嗯, 因为 attach 的太晚了, 这个可以再研究下.

我目前是放弃用 vscode 来 debug, 直接用 webstorm

Rwing commented 7 years ago

webstorm可以?可以说说怎么配置吗,我用webstorm也不行啊

atian25 commented 7 years ago

如图, 无需什么特别配置 webstorm-debug

atian25 commented 7 years ago

https://code.visualstudio.com/updates/v1_9#_debugging

1.9 版做了些优化,Nodemon Setup'restart' option,有兴趣的同学可以研究下,如何主动 attach 新的 worker debug port

atian25 commented 7 years ago

更新下,可以直接用 webstorm debug npm scripts 了,无需写入口文件。

修改 npm scripts 为:

{
  "dev": "egg-bin dev -- $NODE_DEBUG_OPTION",
}

然后在 webstorm 里面配置一个 npm 的 configuration 即可

image

用 webstorm debug 启动后,环境变量 $NODE_DEBUG_OPTION 被赋值为类似 --debug-brk=53243 --expose_debug_as=v8debug,从而被 egg-bin 传递进去。

atian25 commented 7 years ago

egg-bin 已经重构,支持传参,最新的 3.0,要去掉 --,即:

并且 debug 指令改为继承 dev, 故建议用 egg-bin debug

{
   "scripts": {
      "dev": "egg-bin debug $NODE_DEBUG_OPTION",
  }
}

https://github.com/eggjs/egg-bin#command

atian25 commented 7 years ago

我擦,vscode 的 debug,支持 The Restart Frame action allows you to re-enter the current function after you have changed variables with the Set Value action

新文档不错 https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_restart-frame-node

boizz commented 7 years ago

webstorm启动一些大型例如node_modules里面的文件夹层级太多的项目很容易崩

atian25 commented 7 years ago

@BoizZ 用我们写的 https://github.com/coolme200/webstorm-disable-index

boizz commented 7 years ago

@atian25 666

atian25 commented 7 years ago

现在通过 @okoala 写的 egg-development-proxyworker 可以完美实现 vscode debug egg 了。详见:https://eggjs.org/zh-cn/core/development.html#使用-vscode-进行调试

j4dream commented 7 years ago

well done

huboshu0819 commented 7 years ago

完全按照文档来的,vscode里面打断点还是无效0.0

atian25 commented 7 years ago

@huboshu0819 @okoala 来接客啦~

okoala commented 7 years ago

@atian25 你看看那个 PR 有啥问题,没问题就合并掉了吧~

huboshu0819 commented 7 years ago

真是秒速啊!!

okoala commented 7 years ago

@huboshu0819 要不你到官网提 issue, 然后把 vscode 相关打印信息贴出来看看~

huboshu0819 commented 7 years ago

@okoala 好哇 我等下去提。 这个是打印信息,您可以先看下 image

okoala commented 7 years ago

@huboshu0819 目测是你没有 attach worker 啊 ~

atian25 commented 7 years ago

没啥问题吧,你在那边 ping 下其他人。好像 ci 挂了。

发自我的 iPhone

在 2017年6月13日,18:01,仙森 notifications@github.com 写道:

@atian25 你看看那个 PR 有啥问题,没问题就合并掉了吧~

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

okoala commented 7 years ago

那个覆盖率问题,我稍后完善,不影响使用~

huboshu0819 commented 7 years ago

@okoala 刚去官网提了issue,我看配置文件里面我有设置启动 attach worker额。 image

okoala commented 7 years ago

@huboshu0819 直接在官网交流吧~

okoala commented 7 years ago

eggjs/egg#1048

atian25 commented 7 years ago

终于可以宣布该问题完美解决了~

ChaofengYan commented 7 years ago

image

之前还好使的,现在一直报错

atian25 commented 7 years ago

@ChaofengYan npm update 了没? 删除依赖重新安装下,不要 lock。

ChaofengYan commented 7 years ago

@atian25 使用egg-init 新建的一个type=simple项目,使用npm i安装依赖,没有lock,依然报同样的错误

atian25 commented 7 years ago

我试了本地无法复现。

atian25 commented 6 years ago

终于,今天 VSCode@1.12.0 正式支持了 Automatically attach debugger to Node.js subprocesses

我们这个问题可以完美解决了,详细描述参见:https://github.com/atian25/blog/issues/25

boizz commented 6 years ago

天猪威武