next up previous
Next: 12 Compiling to C Up: BinProlog 5.75 User Previous: 10 Source-level stateless modules

11 Editing, apropos/1, trace/1, spy/1, nospy/1

To edit a file and then compile it use:

   ?- edit(<editor>,<file>).

To edit and recompile the currently compiled file using the emacs editor, attached to environment variables EDITOR or VISUAL type:

   ?- ed.

To edit and recompile the currently compiled file using the edit editor (under DOS) type:

   ?- edit.

To simply recompile the last file type:

  ?- co.

The debugger/tracer uses R.A. O'Keefe's public domain meta-interpreter. You can modify it in the file "extra.pl". DCG-expansion is supported by the public domain file dcg.pl.

To debug a file type:

?- reconsult(FileName).

and then

?- trace(Goal).

For interactivity, both the toplevel and the debugger depend on

?-interactive(yes).

or

?-interactive(no).

My personal preference is using interactive(no) within a scrollable window. However, as traditionally all Prologs hassle the user after each answer BinProlog 5.75 will do the same by default.

If you forget the name of some builtin, apropos/1 (or help/1) will give you some (flexible up to one misspelled or missing letter) matches with their arities.

BinProlog 5.75 allows debugging of dynamically recompiled code. Load your file with reconsult or one of its variants (dconsult, oconsult). You can benefit from efficient execution of code you do not want to look into which gets compiled on the fly during the debugging session, while being able to use trace/1 and listing/1 to see your predicates.

BinProlog 5.75 also features some new tracing options, i.e:

ENTER ==> call without tracing
l ==> listing
q,a ==> abort
p ==> toplevel Prolog query
t ==> succeed, but do not call this goal
f ==> fail, and do not call this goal
k ==> keep goal for further inspection
s ==> show saved goals instances
h ==> help
; ==> continue (default)

The following terminal session shows an example of debugging session:

?-reconsult(allperms).
consulting(../progs/allperms.pl)
consulted(../progs/allperms.pl)
time(consulting = 50,quick_compiling = 0,static_space = 0)
yes
?- interactive(no).
yes
?- trace(g0(3)).
Call: g0(3)
 !!! clause: g0/1
 Call: nats(1,3,_x2770)
  !!! clause: nats/3
  Call: 1 < 3
   !!! compiled((<)/2)
  Exit: 1 < 3
  Call: _x3157 is 1+1
   !!! compiled((is)/2)
  Exit: 2 is 1+1
  Call: nats(2,3,_x3159)
   !!! clause: nats/3
   Call: 2 < 3
    !!! compiled((<)/2)
   Exit: 2 < 3
   Call: _x4115 is 2+1
    !!! compiled((is)/2)
   Exit: 3 is 2+1
   Call: nats(3,3,_x4117)
    !!! clause: nats/3
    CUT
   Exit: nats(3,3,[3])
  Exit: nats(2,3,[2,3])
 Exit: nats(1,3,[1,2,3])
 Call: perm([1,2,3],_x2773)
  !!! clause: perm/2
  Call: perm([2,3],_x5527)
   !!! clause: perm/2
   Call: perm([3],_x5905)
    !!! clause: perm/2
    Call: perm([],_x6283)
     !!! clause: perm/2
    Exit: perm([],[])
    Call: insert(3,[],_x5905)
     !!! clause: insert/3
    Exit: insert(3,[],[3])
   Exit: perm([3],[3])
   Call: insert(2,[3],_x5527)
    !!! clause: insert/3
   Exit: insert(2,[3],[2,3])
  Exit: perm([2,3],[2,3])
  Call: insert(1,[2,3],_x2773)
   !!! clause: insert/3
  Exit: insert(1,[2,3],[1,2,3])
 Exit: perm([1,2,3],[1,2,3])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[1,2,3])
  Redo: insert(1,[2,3],[1,2,3])
   Call: insert(1,[3],_x7793)
    !!! clause: insert/3
   Exit: insert(1,[3],[1,3])
  Exit: insert(1,[2,3],[2,1,3])
 Exit: perm([1,2,3],[2,1,3])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[2,1,3])
  Redo: insert(1,[2,3],[2,1,3])
   Redo: insert(1,[3],[1,3])
    Call: insert(1,[],_x8180)
     !!! clause: insert/3
    Exit: insert(1,[],[1])
   Exit: insert(1,[3],[3,1])
  Exit: insert(1,[2,3],[2,3,1])
 Exit: perm([1,2,3],[2,3,1])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[2,3,1])
  Redo: insert(1,[2,3],[2,3,1])
   Redo: insert(1,[3],[3,1])
    Redo: insert(1,[],[1])
    Fail: insert(1,[],_x8180)
   Fail: insert(1,[3],_x7793)
  Fail: insert(1,[2,3],_x2773)
  Redo: perm([2,3],[2,3])
   Redo: insert(2,[3],[2,3])
    Call: insert(2,[],_x7404)
     !!! clause: insert/3
    Exit: insert(2,[],[2])
   Exit: insert(2,[3],[3,2])
  Exit: perm([2,3],[3,2])
  Call: insert(1,[3,2],_x2773)
   !!! clause: insert/3
  Exit: insert(1,[3,2],[1,3,2])
 Exit: perm([1,2,3],[1,3,2])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[1,3,2])
  Redo: insert(1,[3,2],[1,3,2])
   Call: insert(1,[2],_x8155)
    !!! clause: insert/3
   Exit: insert(1,[2],[1,2])
  Exit: insert(1,[3,2],[3,1,2])
 Exit: perm([1,2,3],[3,1,2])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[3,1,2])
  Redo: insert(1,[3,2],[3,1,2])
   Redo: insert(1,[2],[1,2])
    Call: insert(1,[],_x8542)
     !!! clause: insert/3
    Exit: insert(1,[],[1])
   Exit: insert(1,[2],[2,1])
  Exit: insert(1,[3,2],[3,2,1])
 Exit: perm([1,2,3],[3,2,1])
 Call: fail
  !!! compiled(fail/0)
 Fail: fail
 Redo: perm([1,2,3],[3,2,1])
  Redo: insert(1,[3,2],[3,2,1])
   Redo: insert(1,[2],[2,1])
    Redo: insert(1,[],[1])
    Fail: insert(1,[],_x8542)
   Fail: insert(1,[2],_x8155)
  Fail: insert(1,[3,2],_x2773)
  Redo: perm([2,3],[3,2])
   Redo: insert(2,[3],[3,2])
    Redo: insert(2,[],[2])
    Fail: insert(2,[],_x7404)
   Fail: insert(2,[3],_x5527)
   Redo: perm([3],[3])
    Redo: insert(3,[],[3])
    Fail: insert(3,[],_x5905)
    Redo: perm([],[])
    Fail: perm([],_x6283)
   Fail: perm([3],_x5905)
  Fail: perm([2,3],_x5527)
 Fail: perm([1,2,3],_x2773)
 Redo: nats(1,3,[1,2,3])
  Redo: nats(2,3,[2,3])
   Redo: nats(3,3,[3])
   Fail: nats(3,3,_x4117)
   Redo: 3 is 2+1
   Fail: _x4115 is 2+1
   Redo: 2 < 3
   Fail: 2 < 3
  Fail: nats(2,3,_x3159)
  Redo: 2 is 1+1
  Fail: _x3157 is 1+1
  Redo: 1 < 3
  Fail: 1 < 3
 Fail: nats(1,3,_x2770)
Exit: g0(3)

?-  interactive(yes).

?-  trace(insert(1,[2,3],Res)).
Call: insert(1,[2,3],_x2407) <ENTER=call, ;=trace, h=help>: l

% dynamic: insert/3:
insert(A,B,[A|B]).
insert(B,[A|C],[A|D]) :- 
        insert(B,C,D).

!!! clause: insert/3
Exit: insert(1,[2,3],[1,2,3])
Res=[1,2,3];

Redo: insert(1,[2,3],[1,2,3])
Call: insert(1,[3],_x3149) <ENTER=call, ;=trace, h=help>: ;
 !!! clause: insert/3
Exit: insert(1,[3],[1,3])
Exit: insert(1,[2,3],[2,1,3])
Res=[2,1,3]q

?-

Starting with version 3.08 spy/1 and nospy/1 allow to watch entry and exit from compiled predicates. Note that they should be in the file to be compiled, before any use of the predicate to be spied on as in:

% FILE: jbond.pl
:-spy a/1.
:-spy c/1.

b(X):-a(X),c(X).

a(1).
a(2).

c(2).
c(3).

This gives the following interaction:

?-[jbond].
......
?- b(X).

Call: a(_2158) <enter=call, other=trace>: ;
 !!! compiled(a/1)
Exit: a(1)
Call: c(1) <enter=call, other=trace>: ;
 !!! compiled(c/1)
Fail: c(1)
Redo: a(1)
Exit: a(2)
Call: c(2) <enter=call, other=trace>: ;
 !!! compiled(c/1)
Exit: c(2)
X=2;

Redo: c(2)
Fail: c(2)
Redo: a(2)
Fail: a(_2158)
no

Although these are very basic debugging facilities you can enhance them at your will and with some discipline in programming they may be all you really need. Anyway, future of debugging is definitely not by tracing. One thing is to have stronger static checking. In dynamic debugging the way go is to have a database of trace-events and then query it with high level tools. We plan to add some non-tracing database-oriented debugging facilities in the future.

You can generate a kind of intermediate WAM-assembler by

  ?- compile(asm,[file1,file2,...],'huge_file.asm').

A convenient way to see interactively the sequence of program transformations BinProlog is based on is:

?- asm.
a-->b,c,d.
^D

DEFINITE:
a(A,B) :- 
        b(A,C),
        c(C,D),
        d(D,B).

BINARY:
a(A,B,C) :- 
        b(A,D,c(D,E,d(E,B,C))).

WAM-ASSEMBLER:
clause_? a,3
firstarg_? _/0,6
put_structure d/3,var(4-4/11,1/2)
write_variable put,var(5-5/10,1/2)
write_value put,var(2-2/6,2/2)
write_value put,var(3-3/7,2/2)
put_structure c/3,var(3-8/14,1/2)
write_variable put,var(2-9/13,1/2)
write_value put,var(5-5/10,2/2)
write_value put,var(4-4/11,2/2)
execute_? b,3



next up previous
Next: 12 Compiling to C Up: BinProlog 5.75 User Previous: 10 Source-level stateless modules



Paul Tarau
Thu Apr 3 10:26:39 AST 1997