Yield based debugging: allow for a fancy debugger for the browser version! - Reply 01

Sounds interesting !

Here I am… more or less 10 years after I dabbled with prolog_trace_interception/4 and others internal predicates for syntax colouring and interactive debugging (it was part of the code from where we got the swipl-win Qt porting).

But since I never played with swipl wasm before, let me some time to approach the broad argument.

I’d like to peruse your code to open an experimental branch in Qt swipl-win with basic debugging .

I’ve uploaded the tests to GitHub - JanWielemaker/yield-trace: Yield based tracer for SWI-Prolog (proof-of-concept)

You need the very latest git version to run it. After cloning and updating swipl you can do

swipl-ld  -o trace -g trace.c

After which you can run

./trace

and have a Prolog version where ?- trace, goal. works using yield. Most of the tracer is implemented in Prolog, i.e.

  • trace event causes PL_next_solution() to return
  • C calls Prolog to print the goal and get the user response
  • C resumes the yielded query.

That can work in the browser, except that one needs an async version for the second step that allows for waiting for some browser event. Alternatively this may be implemented in a mixture of non-blocking Prolog calls and JavaScript.

Note that the trace.pl is a bit convoluted as I also allows it to work on the prolog_trace_interception/4 hook and make it hookable by test_trace.pl, a rudimentary attempt at a framework to generate and run tests on the debugger.

My plan is to add something really basic to the WASM Prolog shell that will further demonstrate the idea.

Jan, I’ve been able to perform some tests, after downloading and installing the latest daily build.
But I had to use Visual Studio 2022, because swipl-ld didn’t work.

First, the positive results:

Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.20-16-g42d61c053)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit [https://www.swi-prolog.org](https://www.swi-prolog.org)
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- ls.
% [test_trace.pl](http://test_trace.pl) trace.c
% test_trace.vcxproj [trace.pl](http://trace.pl)
% test_trace.vcxproj.filters x64/
% test_trace.vcxproj.user
true.

2 ?- [test_trace].
true.

3 ?- trace.
true.

[trace] 3 ?- ls.
% Tracing by yielding to C
^ Call: (19) catch(tty_size(_7428, _7430), _8112, _7430=80)? s
[skip]
^ Exit: (19) catch(shell:tty_size(_7428, 80), error(not_implemented(procedure, tty_size/2), context(prolog_stack([frame(20, call(system:tty_size/2), tty_size(_19856, _19858)), frame(19, clause(<clause>(0000029effd183f0), 2), catch(shell:tty_size(..., ...), _19884, shell:(... = ...))), frame(18, clause(<clause>(0000029e81ab2500), 26), prolog:message(..., ..., ...)), frame(17, clause(..., ...), translate_message(..., ..., ...)), frame(..., ..., ...)|...]), _19818)), shell:(80=80))? s
[skip]
Call: (19) _21202=_7420? l
[leap]
% [test_trace.pl](http://test_trace.pl) trace.c
% test_trace.vcxproj [trace.pl](http://trace.pl)
% test_trace.vcxproj.filters x64/
% test_trace.vcxproj.user
true.

[debug] 4 ?-

Now, for the swipl-ld problem (that happens also if I try using what worked when I helped Stassa…)

PS C:\Users\cccar\test\prolog\swipl\yield-trace> swipl-ld -o trace -g trace.c
gcc.exe: warning: files/swipl: linker input file unused because linking not done
gcc.exe: error: files/swipl: linker input file not found: No such file or directory
gcc.exe returned code 1
*** C:\Program Files\swipl\bin\swipl-ld.exe exit status 1

Anyway, I feel I can continue.
Thanks, and see you soon.

Good. I’m surprised it runs on Windows at all :slight_smile: Also the latest daily is not really good enough (but the C based tracing works).

You should not need to do that. trace.c already loads trace.pl and that is enough. If it says % Tracing by yielding to C, you are using the new thing.