DebugInformation for function calls in separate script

Sep 28, 2010 at 8:36 AM

Hi!

I´ve created a visual debugger for Jint that allows to run a bunch of script files, set breakpoints in each as well as do step by step debugging through them all.
I would need to find out in which scriptFile (all running in the same instance/context) the debugger is stepping through (or where a break point lands).

Here is what I´m doing (simplified the code to make it, hopefully, clearer):

// init the engine
JintEngine jEngine = new JintEngine();
...

// Loops over all the script files in the list. Made separate calls here for illustrative purpose
jEngine.Run(scriptFile1);
jEngine.Run(scriptFile2);
...

// At the debug step...
public static void DebugStep(object sender, Jint.Debugger.DebugInformation info)
{

...

int dbgLine=info.CurrentStatement.Source.Start.Line;
string srcCode=info.CurrentStatement.Source.Code;

int scriptFile=info.CurrentStatement.Source.Script;  // something like this would be good... replacing int with some pointer to the instance or so..

...
}

scriptFile1 contains a function:

function square(x)
{
  return x * x;
 }

scriptFile2 calls this function.

var four=square(2); // will call function in scriptFile1

So the problem is that if I´m visually debugging and step through it, I will get into scriptFile2, when it then calls the function square, I do not get information to find out which file to show.
It will just give me information on the line number and source code line, not which of the script files it jumped to.

A possible hack would be to search all script files for the line number and source line and show this one, but that would be slow. Another choice is to pre-parse for all function calls and use the call stack in combination with the first idea. Still, I´m sure both these solutions will cause problems in many other scenarios that I´ve not even thought of yet :)

I guess Jint internally might already have this information easily accessible that could be provided with the "Jint.Debugger.DebugInformation info" parameter on step or breakpoint events.

Is this something that could be quickly added? Or is there some other way of getting this information that I might have missed?


Thanks in advance!

 

 

 

Sep 28, 2010 at 5:20 PM

Not meaning to hijack your post but is there any chance of sharing the debugger with other Jint users?

Sep 29, 2010 at 1:21 PM
nickntg wrote:

Not meaning to hijack your post but is there any chance of sharing the debugger with other Jint users?

If I had the rights I would. The code I´m developing belongs to a customer, so I can´t share it.
Also it´s a mixed script language that mixes Javascript with three other macro languages, so there is a pre-parsing step converting everything to javascript in the background while
visually showing the mixed script language and the debugger is doing a lot of special handling for this.

I do recommend you look at AvalonEdit for using it as the syntax highlighting editor, though you will have to extend it for break point support and stepping markers.

Best regards

Sep 29, 2010 at 2:38 PM
Edited Sep 29, 2010 at 2:42 PM
rcswer wrote:

If I had the rights I would. The code I´m developing belongs to a customer, so I can´t share it.
[...]

I do recommend you look at AvalonEdit for using it as the syntax highlighting editor, though you will have to extend it for break point support and stepping markers.

I'm nearly in the same situation, I used AvalonEdit as editor and I added breakpoint markers support. Now I'm working to a "program tree" panel filled by means of a dedicated jint visitor, but it's only a prototype yet.

If I'll manage to convince my boss I'll be glad to release the entire solution, but I think it will be difficult. If not, I think that there is no problem if I post here the debugger class, but for breakpoints markers there is some code left.

@rcswer: my editor at present works only on a single script at a time, I'm sorry I can't help you.

bye