Debugging gf3 / sandbox module

I am doing my baby steps in node.js and I am trying to understand the mechanism of the sandbox.

I am currently using node v4.0.0 and the node inspector v0.12.3.

I installed the gf3 / sandbox module and ran it with this simple code:

var s = new Sandbox(); s.run('1 + 1 + " apples"',function(output) { console.log(output.result); }); 

To easily debug, I also commented on the timeout function in the sandbox.js file:

 // timer = setTimeout(function() { // self.child.stdout.removeListener('output', output); // stdout = JSON.stringify({ result: 'TimeoutError', console: [] }); // self.child.kill('SIGKILL'); // }, self.options.timeout); 

The problem is that debugging CANNOT break ANY shovel.js line shovel.js , and I'm 100% sure that the module uses its code.

Why? And what can I do to debug shovel.js ?

+7
javascript sandbox node-inspector
source share
1 answer

sandbox.js spawns shovel.js as a child process without debugging enabled (for example, the --debug option). That way, the child process runs fine, and your breakpoints are simply ignored. You also need to start the child process in debug mode.

If you want to debug both sandbox.js and shovel.js at the same time, use different debug ports. I'm not sure about node-inspector, but here is an example of how you can do this with the debugger module. I'm sure you can tweak it a bit to work with node-inspector.

  • Comment out the timeout code as you already did
  • Send debug option at child birth to sandbox.js . Note that port 5859 :

     self.child = spawn(this.options.node, ['--debug-brk=5859',this.options.shovel], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }); 
  • run example.js in debug mode. By default, it starts at port 5858 :

     node --debug-brk example.js 
  • Now debug sandbox.js , connecting to 5858 :

     node debug localhost:5858 
  • After starting the child process, you can start a separate terminal and start debugging shovel.js on port 5859 :

      node debug localhost:5859 

For the node inspector, I think you need to use the node-debug command instead of this.options.node for the child process. There are also options to explicitly set the debug port.


Above, these may be steps for the node-inspector . Note. I have not tested it:

  • Same as above
  • Open the sandbox.js file and change this line , as shown below, to pass the debugging option when spawning the child process. Note that port 5859 :

     self.child = spawn('node-debug', ['--debug-port=5859',this.options.shovel], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }); 
  • run example.js in debug mode. By default, it starts at port 5858 :

     node-debug example.js 
  • Now go to the browser to debug the parent process:

    http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858

  • After starting the child process, open another browser window to debug shovel.js :

    http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5859

+3
source share

All Articles