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

Debug script

Aug 14, 2015 at 6:18 AM
Hi,

Script loaded dynamically does not hit break point.

I have script ex:
var a=10;
var b=20
var c=a+b;
ScriptLib.LoadScript("sample.js");
var d=a+b+c;
and in LoadScript() function I am reading this file and I am calling
scriptEngine.Evaluate(FileScript)
am also setting break point line no to 0. This hits the break point and I am successfully able to debug step by step till line 4

I have also provided option to load script dynamically similar to shown here
engine.Evaluate(File.ReadAllText(path))
Dynamically loaded script executes successfully but the script in this file does not hit break point. I am trying to debug the dynamically loaded script also.

Please let me know is this a limitation or am I missing something.

Thank you.
Coordinator
Aug 14, 2015 at 2:32 PM
Hello!

A couple of questions:
  • Which script engine are you using?
  • How are you setting a breakpoint in the dynamically loaded script code?
Thanks!
Aug 17, 2015 at 4:24 AM
Hi,

I am using V8ScriptEngine java script engine for execution.
V8ScriptEngine scriptEngine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers | V8ScriptEngineFlags.EnableDebugging, debuggingPort)
Debug point is set through V8 DebuggerProtocol(DebuggerProtocol ). I am not setting any break point to dynamically generated script. breakpoint is set to main script.

main script:-
var a=10;
var b=20
var c=a+b;
ScriptLib.LoadScript("sample.js");
var d=a+b+c;
dynamically loaded script("sample.js") :-
var d=25;
var e=35;
var f=d*e;
ScriptLib is a HostObject added to an engine, executes script on same engine.


Thank you.
Coordinator
Aug 17, 2015 at 2:23 PM
Hi again,

I am not setting any break point to dynamically generated script.

The script debugger cannot step into a .NET method. However, you can force it to stop within the "sample.js" code by adding a debugger statement:
debugger;
var d=25;
var e=35;
var f=d*e;
The debugger statement will cause the script debugger to break in at that location. It does nothing when no script debugger is attached. You can add it to the script file or insert it programmatically at runtime.

Good luck!
Aug 18, 2015 at 4:16 AM
Edited Aug 18, 2015 at 4:17 AM
Hi,

Thank you its working.
 I am writing custom debugger using debugger protocol. How can I get values of variables, i am using lookup request[Look Up](https://code.google.com/p/v8-wiki/wiki/DebuggerProtocol#Request_lookup), but it does not return any values and complex objects are not serialized. Is there any alternative for debugging other than Debugger protocol?
Thank you.
Coordinator
Aug 18, 2015 at 2:37 PM
Hello,

How can I get values of variables

To retrieve the value of a variable, Eclipse seems to use the evaluate request. Here's a sample from Eclipse's debugger console:
> Sent to Chrome:
Content-Length:132

{"seq":25,"type":"request","command":"evaluate","arguments":{"disable_break":true,"expression":"value","inlineRefs":true,"frame":0}}
> end of message

> Received from Chrome:
Content-Length:789

{"seq":31,"request_seq":25,"type":"response","command":"evaluate","success":true,"body":{"handle":5,"type":"object","className":"Object","constructorFunction":{"ref":2,"type":"function","name":"Object","inferredName":"","scriptId":4},"protoObject":{"ref":4,"type":"object","className":"Object"},"prototypeObject":{"ref":3,"type":"undefined"},"properties":[{"name":"foo","value":{"ref":20,"type":"number","value":123}},{"name":"bar","value":{"ref":21,"type":"number","value":456.789}},{"name":"baz","value":{"ref":22,"type":"string","value":"foobar"}}],"text":"#<Object>"},"refs":[{"handle":20,"type":"number","value":123,"text":"123"},{"handle":21,"type":"number","value":456.789,"text":"456.789"},{"handle":22,"type":"string","value":"foobar","length":6,"text":"foobar"}],"running":false}
> end of message
Eclipse sent this request to retrieve a value for display in a tooltip. When the expression evaluates to an object, V8 appears to return information about immediate child properties only (as opposed to full serialization).

Is there any alternative for debugging other than Debugger protocol?

We're not aware of any other way to debug scripts running in V8.

Cheers!