Interrupting a script in a debugger

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Interrupting a script in a debugger

Miles Thornton
I have written a basic debugger for my application which embeds
Spidermonkey 1.8.5.
It works pretty well. I can put in breakpoints, step, next etc,
examine the stack, print variable values etc.
One thing that I can't work out how to do is make it so the script can
be interrupted.
There seems to be a hook JS_SetInterrupt that I thought would do the
trick but I can't see how to make it work.
For example, given the following script (which is just a stupid
example which takes a long time to run) the function I register with
JS_SetInterrupt before running the script never gets called.

for (var j=0; j<100; j++)
{
    var test2 = 0.0;
    var test = 2.0;

    for (var i=0; i<10000000; i++)
    {
        test = test + 0.1;
        test = 1.01*test + 0.1 - 0.015 + test*0.001;
        if (test > 100.0) test = Math.max(test-90.0,2.0);
        test2 = Math.sqrt(test);
        test = test + test2;
    }

Can anyone tell me how to get JS_SetInterrupt to work?
Alternatively, if I'm using this for completely the wrong thing, does
anybody know a way that I can register a function which is called
repeatedly that I can test to see if the script is interrupted?

If I had a script which used my own functions and property getters/
setters then I could write something to do the interrupts but that
would not work in the case above as it is only using core JavaScript.

Thanks

Miles
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: Interrupting a script in a debugger

Colin Fraser-2
"Miles" <[hidden email]> wrote:
> There seems to be a hook JS_SetInterrupt that I thought would do the
> trick but I can't see how to make it work.
> For example, given the following script (which is just a stupid
> example which takes a long time to run) the function I register with
> JS_SetInterrupt before running the script never gets called.

I think you must be on the right track, I'm using the older 1.8 code, so
perhaps something has changed in 1.8.5 but my understanding is that by using
JS_SetInterrupt you get a callback at every execution point which should let
you interrupt execution.

The calls I have used in my simple debugger are:

  JS_SetInterrupt(rt, debugger_TrapHook, arg);
  JS_SetExecuteHook(rt, debugger_InterpreterHook, arg);

I don't actually support an interrupt command, so maybe I'm missing
something but I think it would work.

I know there is a fair bit of work going on to improve the debugging
capabilities badged as jsdbg2 (bug 672829).  It might be worth looking at
that for inspiration, or in case anything has changed in the latest
spidermonkey code.

Colin



_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine