JS Debugger for embedders?

Hi, folks –

Is there any currently-relevant information on the JS debugger API? I have jsapi embedded into Python, and wrote a node-like JS repl in Python for it. Now I need to write a debugger and am hoping to find some information about.

I hacked on jsdb back in the day, but this was poorly supported in the shell even by version 1.8. Jim Blandy told me about 10 years ago that he was planning to rip all that stuff out and replace it with a real debugger API. I’ve found some stuff from the SM22 era on m.o. but it was marked as no longer supported.

Anybody know what’s what? Is there some example code I can look at somewhere?

I was looking for this myself a few months ago. The best things I found were https://firefox-source-docs.mozilla.org/js/Debugger/index.html and JS_DefineDebuggerObject.

I’m planning to implement proper debugger support with IDE integration in my embedding, so I’ve done some research on this topic:

  • There is a standard debugger API interface that should be implemented called Debugger Adapter Protocol (DAP). DAP allows to integrate debugger easily in most of modern IDEs. There are several frameworks that simplify it’s implementation, e.g. https://github.com/google/cppdap for C++.
  • To implement this interface in JS you have to use Debugger API. It’s implemented mostly in JS code, while native code is just an adapter for external API (e.g. DAP), which looks something like this:
void Step(/*...*/) {
  ExecuteScript("/* script that executes step with Debugger API */");
}

jsdb is a good example on how to use Debugger API and remains pretty much relevant, aside from non-DAP debugger interface and outdated embedded SM.

Thanks!

If either of you start a debugger project - follow up here? I’ll do the same if we do. I’m thinking that even though we have different embeddings, we may be able to share effort on debugger support if/when the time comes.

@ TheQwertiest I’m suprised to see you mention jsdb? Can you point to where it’s gone in current m-c? It was badly rotted ten years ago, and appears to have been removed from the repo by now.

BTW - have you seen https://github.com/swojtasiak/jsrdbg ?

suprised to see you mention jsdb

Ah, sorry, I’ve misremembered the repo name - I meant jsrdbg that you’ve linked :slight_smile:

follow up here?

To be honest, it’ll be quite a while before I can start working on that, since I have a mountain of things I want to/have to implement before tackling the debugger.

But there is a project ticket that can be followed, in case anyone interested in my implementation (once I actually start working on it)

Don’t forget jorendb! I use it semi-regularly when working on the GC rooting hazard analysis, since that runs on the JS shell.

It’s a bit clunky and I’ve never bothered adding support for filename:lineno breakpoints (the APIs for enumerating available scripts were very much in flux way back when I was actively working on jorendb itself). I use debugger statements and c <lineno> (continue to a line number within the current script) as a workaround.

I’ve been tempted to do a rewrite using async/await for control flow (jorendb predates Promises). But given that I am the only one who uses jorendb as far as I know, it hasn’t exactly been a high priority.

1 Like

Steve - thank you! Bless Jason. :slight_smile:

This sounds perfectly usable to me, and I’ll check it out shortly. I have a similar project on the go for node, and hilariously, it also doesn’t use promises nor do breakpoints. But it’s usable enough for me. The debugger keyword is a really great feature for interpreted/jitted languages.

I managed to create a basic debugger in our embedding using the information in https://firefox-source-docs.mozilla.org/js/Debugger/index.html. I wrote the basic debugger code in JS and then compiled/evaluated it from my C/C++ code. I passed information back to C/C++ by some functions I defined with JS_DefineFunctions.
It all seems to work OK. :smiley:

In GNOME, we have a souped-up version of jorendb for use at the command line: https://gitlab.gnome.org/GNOME/gjs/-/blob/a691005f24b165b86ccbcfd586610206851460f1/modules/script/_bootstrap/debugger.js

It’s on the horizon, but with no concrete plans, to also implement a debugger server in order to be able to attach browser devtools to a running GNOME desktop process.