Re: Debug Interface for the mozjs, how to start/stop/pause/continue the js engine
lemmel <[email protected]> Mon, 06 Apr 2020 21:20:08 +0200
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <1818019.zmCWQ9F2oI@sakura> |
Thanks for your input ! So if I read you correctly for the following simple scenario : - A) user gives me code = - B) the code is executed in mozjs - C) while executing, the user press pause - D) the code is paused in mozjs - E) the user =AB step over =BB B) several steps: = - I should initialize the engine, register all my utility functions (e.g. t= hose managing events) and set the debugger (with code like the one in https= ://developer.mozilla.org/en-US/docs/Tools/Debugger-API/Tutorial-Breakpoint)= through a call to JS::Evaluate - then I give the user code to the engine through a call to JS::Evaluate - immediately a "onNewScript" event is triggered (in ./Debugger.md) C) normally my =AB callback =BB on onStep (through a onEnterFrame like in = js/src/jit-test/tests/debug/Frame-onStep-01.js) ignore the "steps" D) but after the user order, I block the mozjs library by not returning fro= m my callback ? Is it the trick ? In js/src/doc/Debugger/Debugger-API.md, it is said that "Both the debugg= ee and the code using `Debugger` to observe it must run in the same thread"= (the code "using the Debugger" is mine I suppose), so no risks of corrupti= on. E) and so on Did I understand correctly ? Le lundi 6 avril 2020, 16:19:47 CEST Nicolas B. Pierron a =E9crit : > Hi, > = > SpiderMonkey does have a Debugger interface. This interface is available = from JavaScript code to inspect other code which is running in the same eng= ine. > = > 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 Debugg= er. 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] b= ut they would contains extra code which is specific to Firefox. > = > The Debugger API works using callbacks. Thus if you want to stop at a giv= en 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/de= bug > [3] https://developer.mozilla.org/en-US/docs/Tools/Debugger-API/Tutorial-= Breakpoint > _______________________________________________ > dev-tech-js-engine mailing list > [email protected] > https://lists.mozilla.org/listinfo/dev-tech-js-engine > =