我正在使用WebStorm 8来调试一个父进程派生子进程并向其发送消息的场景。
为了使子进程可调试,我将——debug或——debug-brk作为参数。
WebStorm成功地拾取了孩子的端口,但是我无法让调试行为正确。
下面是一个示例代码:
父母:
var proc = require('child_process').fork('./child.js', [], {execArgv: ['--debug']});
proc.send({say: 'hello 1'});
setTimeout(function () {
proc.send({say: 'hello 2'});
}, 3000);
:
console.log('child started');
process.on('message', function (msg) {
console.log("child got message", msg);
});
1)当运行时没有调试模式和分支没有——debug和——debug-brk,代码运行良好,输出如下:
child started
child got message { say: 'hello 1' }
child got message { say: 'hello 2' }
2)当在调试模式下运行和与——debug-brk分叉时,代码的行为不同-第一条消息永远不会到达进程,输出是:
debugger listening on port 62008
debugger listening on port 5858
child started
child got message { say: 'hello 2' }
3)当在调试模式下运行和与——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导致一些断点被跳过。
在不修改流并确保所有断点都停止的情况下,调试父进程和子进程的正确方法是什么?
看起来像一个bug;登录为WEB-12528,请为它投票