我正在尝试调试一个依赖于本机绑定的nodejs脚本。该脚本还涉及分支子进程。我正在使用valgrind
通过以下选项调试内存问题:
valgrind --leak-check=summary --show-leak-kinds=all --trace-children=yes --verbose node app.js
仅当我设置--trace-children=no
时才有效,否则总是失败。
我创建了以下示例脚本来测试场景,似乎valgrind
无法调试在节点中运行的子进程。
// main.js
var cp = require('child_process');
var child = cp.fork('./worker');
child.on('message', function(m) {
// Receive results from child process
console.log('received: ' + m);
});
// Send child process some work
child.send('Please up-case this string');
和
worker.js
process.on('message', function(m) {
// Do work (in this case just up-case the string
m = m.toUpperCase();
// Pass results back to parent process
process.send(m.toUpperCase(m));
});
valgrind
总是因以下错误而失败:
==10401== execve(0x1048a3150(/bin/bash), 0x1048a3638, 0x1048a3658) failed, errno 2
==10401== EXEC FAILED: I can't recover from execve() failing, so I'm dying.
==10401== Add more stringent tests in PRE(sys_execve), or work out how to recover.