Possible to launch graphical debugger when using foreign language interface

I’m using the foreign language interface (following the example in the pyswip project).
Is it possible to launch the graphical debugger? Pyswip calls PL_initialize with [./, -q,--nosignals], and is able to execute and query and receive results. However query: gtrace, some_pred(X)., I’m not able to launch the debugger. Should it be possible?

I has a quick look at the swipl sources (is this the swipl main?):

Thanks in advance.

In theory it should work. Not sure whether --nosignals may interfere. Signals are used in some inter-thread communication. Simpler things to test: can you load library(pce)? After that, can you open a window by calling e.g. send(new(window), open)?

Ah, also wrong is ./. The first argument should be swipl or you need to pass -F swipl

To some extend a handicapped development environment is the consequence of embedding :frowning:

1 Like

Thank you, Jan.

?- load_files(library(pce),[]).
true.
?- send(new(window), open).
true.

… succeeded in creating windows (when run via the C API). But, neither of
args[0] = /usr/bin/swipl
args[0] = /usr/lib/swi-prolog/bin/x86_64-linux/swipl
seemed to make a difference to gtrace. Choosing -F file as a non prolog directory causes gtrace to be an undefined procedure, so it seems likely that it was able to find the some initialization files (wherever this lives),

The following is printed:

% The graphical front-end will be used for subsequent tracing

however, spy(level0/1). does not cause:

% Spy point on level0/1

to be printed. I also tried exporting:
XPCEHOME = /usr/lib/swi-prolog/, and
XPCEHOME = /usr/lib/swi-prolog/xpce
with no luck.

if gtrace/0 doesn’t say it is undefined and opening an xpce window succeeds I start to wonder what it means the the graphical debugger doesn’t work? Once you started xpce you should have a new thread called pce (run threads/0 to print the active threads). Does that happen?

What does spy(level0/1) do? One of the issue could be deadlocks. While SWI-Prolog is fully multi-threaded, Python view on thread synchronization is quite different.

1 Like

! Yes. PL_query was being provided (PL_Q_NODEBUG | PL_Q_CATCH_EXCEPTION) (pyswip).
Passing PL_Q_NORMAL fixes enables the graphical debugger. Not sure about spy yet, but it matters less if the debugger is available, I’ll dig deeper.

Many thanks.

PS. gtrace blocks the Python thread (in PL_query) until debugging is complete – seems like the right and safe thing (re: threads).