Re: Debug Interface for the mozjs, how to start/stop/pause/continue the js engine

"Nicolas B. Pierron" <[email protected]> Mon, 6 Apr 2020 07:19:47 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
Hi,

SpiderMonkey does have a Debugger interface. This interface is available from JavaScript code to inspect other code which is running in the same engine.

I am no expert in the Debugger, but I would reading the documentation[1] to find which function seems interesting and checking the test suite[2] to find example of usage.

Firefox uses SpiderMonkey and uses this interface to implement its Debugger. However it adds extra complexity to it, in order to handle Debug from a different process. You can find some examples using the Debugger API [3] but they would contains extra code which is specific to Firefox.

The Debugger API works using callbacks. Thus if you want to stop at a given location, you register a callback using `Debugger.Script.setBreakpoint`, which would gives you a `Debugger.Frame` as argument of the `hit` function. Then you can register the `onStep` callback there and continue this way.  I am sure some improvement could be made to make this API more async-await friendly. However, Generators and Promises did not exists at the time.

[1] https://developer.mozilla.org/en-US/docs/Tools/Debugger-API
[2] https://searchfox.org/mozilla-central/source/js/src/jit-test/tests/debug
[3] https://developer.mozilla.org/en-US/docs/Tools/Debugger-API/Tutorial-Breakpoint