This project has moved. For the latest updates, please go here.

Header format for V8 debugger

May 10, 2016 at 2:08 PM
Dear ClearScript team,

I've been dabbling latey with node-inspector to see what would be needed to adapt ClearScript to work with it - aside from some global services, it looks like the header format as defined in (https://clearscript.codeplex.com/SourceControl/latest#ClearScript/V8/V8DebugAgent.cs) does not match what is usually coming from Node.

Specifically, the node debugger (as seen in https://github.com/nodejs/node/commit/8d82ec21308812132a71afe45c5bc517b4a43354, line 72) expects a whitespace after the colon, while ClearScript is not sending one. Is this intended?

Just by changing that (plus a couple of mocked services) I am able to connect with node-inspector and inspect global variables as defined in ClearScript, so I'm hopeful about getting it to work.

Thanks!
Coordinator
May 10, 2016 at 9:26 PM
Hello!

We'll be happy to adjust the header as long as it doesn't break the Eclipse debugger. Can you detail the changes you made to enable node-inspector?

Thanks!
May 11, 2016 at 5:46 AM
Hi,

for the moment I haven't changed anything in ClearScript, opting to modify che node debugger instead (that would be, just removing the whitespace in the regular expression here https://github.com/nodejs/node/commit/8d82ec21308812132a71afe45c5bc517b4a43354 at line 72) - I will take time in the next couple of days to play around with the ClearScript source code and see if just modifying the V8DebugAgent.cs gets us all the way.

Regarding the engine itself, all I've done is exposing a mock of the process and global objects with just the bare minimum fields to avoid having an exception in the inspector itself. So far I was able to inspect global variables while the engine is running and perform step-by-step debugging on compiled script(s) - although so far I was not able to have the inspector react to the "debugger symbol reached" event automatically; that is still under investigation.

Since it is of interest for you, I will try and provide an out of the box solution starting from a fork of ClearScript in the next few days. Thanks!
May 16, 2016 at 7:17 AM
Hi guys,

so, I can confirm that it is possible to connect with node-inspector by adding a space after the colons in the header transmission message, and providing (very simple) "process" and "global" objects. From the ClearScript point of view, two lines of code need to change in (https://clearscript.codeplex.com/SourceControl/latest#ClearScript/V8/V8DebugAgent.cs):

(1)
SendStringAsync(tcpClient, "Type:connect\r\nV8-Version:" + version + "\r\nProtocol-Version:1\r\nEmbedding-Host:" + name + "\r\nContent-Length:0\r\n\r\n", OnConnectionMessageSent);
becomes
SendStringAsync(tcpClient, "Type:connect\r\nV8-Version: " + version + "\r\nProtocol-Version: 1\r\nEmbedding-Host: " + name + "\r\nContent-Length: 0\r\n\r\n", OnConnectionMessageSent);
and (2)
var headerBytes = Encoding.UTF8.GetBytes(MiscHelpers.FormatInvariant("Content-Length:{0}\r\n\r\n", contentBytes.Length));
becomes
var headerBytes = Encoding.UTF8.GetBytes(MiscHelpers.FormatInvariant("Content-Length: {0}\r\n\r\n", contentBytes.Length));
Unfortunately I have no easy way to test if such changes break the Eclipse debugger (although I think that's unlikely, as the Eclipse debugger already works with node). Let me know if you need more information!
Coordinator
May 16, 2016 at 7:41 PM
Thank you very much for the details! We'll test these changes with Eclipse, and if all goes well, we'll include them in the next point release. Thanks again!
Jul 26, 2016 at 2:36 PM
Hey,

just a quick note - since you modified the headers for the debugger protocol, it is now also possible to connect to a ClearScript instance by using the base node.js debugger (e.g. node debug localhost:9999) without any additional setup!

Now all it takes is a graphical wrapper for that :-)
Coordinator
Jul 27, 2016 at 12:18 PM
Great! Thanks for confirming the fix!