使用子进程对nodejs进行Valgrind内存调试

时间:2018-04-19 14:51:35

标签: node.js debugging memory-leaks valgrind

我正在尝试调试一个依赖于本机绑定的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.

0 个答案:

没有答案