我正在使用WebStorm 8来调试父进程分叉子进程的场景,并向其发送消息 .
为了使子进程可调试,我将 --debug 或 --debug-brk 作为参数传递 .
WebStorm成功地接收了孩子的端口,但是我无法正确调试行为 .
这是一个示例代码:
Parent :
var proc = require('child_process').fork('./child.js', [], {execArgv: ['--debug']});
proc.send({say: 'hello 1'});
setTimeout(function () {
proc.send({say: 'hello 2'});
}, 3000);
Child :
console.log('child started');
process.on('message', function (msg) {
console.log("child got message", msg);
});
1)当 running without debug mode 和 forking 没有--debug而没有--debug-brk时,代码运行良好,输出如下:
child started
child got message { say: 'hello 1' }
child got message { say: 'hello 2' }
2)当 running in debug mode 和 forking with --debug-brk 代码行为不同时 - 第一条消息永远不会到达进程,输出为:
debugger listening on port 62008
debugger listening on port 5858
child started
child got message { say: 'hello 2' }
3)当 running in debug mode 和 forking with --debug 两个消息到达时,子消息处理程序内的断点仅针对第二个消息(hello 2)触发 . 输出是:
debugger listening on port 62022
debugger listening on port 5858
child started
child got message { say: 'hello 1' }
child got message { say: 'hello 2' }
基本上,这里似乎有两个问题:--debug-brk导致代码运行方式不同,而--debug导致跳过一些断点 .
在不修改流程并确保所有断点都停止的情况下,调试父级和子级的正确方法是什么?
1 回答
看起来像一个bug;记录为WEB-12528,请投票支持