awto/effectfuljs

Breakpoints sometimes not work

hcnode opened this issue · 2 comments

Hi,

I have a problem when I use Effectful Javascript Debugger extension in vscode, hope I did not go to the wrong place.

In the codes below, when a breakpoint set on line 'console.log(line);', assume two lines in input.txt, so the breakpoint line should be stopped twice when debug run, but actually only stopped when first line read.

var fs = require('fs'),
    readline = require('readline');

var rd = readline.createInterface({
    input: fs.createReadStream('path/to/input.txt'),
    output: process.stdout,
});

rd.on('line', function(line) {
    console.log(line);
});

The launch config is created by default:

{
	"type": "effectful",
	"request": "launch",
	"name": "Launch Node application",
	"preset": "node",
	"cwd": "${workspaceRoot}",
	"command": "node",
	"args": [
		"${file}"
	],
	"console": "integratedTerminal",
	"env": {}
}

The version of the Effectful Javascript Debugger extension I installed is v1.3.42

awto commented

Yes, unfortunately, the debugger doesn't work well when runtime calls some user functions synchronously. The breakpoint releases the main thread so readline thinks the event handling is done and it can proceed with something else.

I'm going to release the next major update in a couple of weeks. It will work a bit better - at least it will stop on the breakpoints. However, it won't stop the readline, so it will proceed to output the lines to process.stdout even when stopped on a breakpoint.

However, even now breakpoints should work when in time-traveling mode. If you enable time-traveling, execute your program till the end, and after go back and forward everything breakpoints should work. With other advantages, like you don't need to restart the process.

There are a couple of solutions for non-time-traveling modes but in longer-term plans. For example, we can transpile embedded node modules (if they are in JS) this way everything will work immediately. Or we can try to block the main thread instead of releasing(#10) it, etc. But I cannot give any estimates for these features. If you wish to contribute anything I'll be happy to help.

Thank you for so detail explain!

I have not used the time-traveling mode yet, it sounds AWESOME! I will try it!