4
votes

Is there a way to hide individual predicates from the trace? In a rule like this:

p(<Stuff>) :-
    q(),
    p(<ModifiedStuff>);
    s(),
    p(<ModifiedStuff>);
    p(<ModifiedStuff>).

I would for example like to hide q() and s() from the trace, because I only am interested in the calls to p(). q() and s() might call a lot of other predicates, which totally cloggs up the trace and makes it hard to find the relevant calls in it.

edit 1

I have now tried executing from the command line rather than from inside the interpreter and piping the trace to grep for grepping lines containing p... but to my disappointment I had to realize when running from the command line, it still opens a prolog shell, so piping the output does not work at all. Only print will actually send to the shell running the prolog process.

edit 2 (output when using trace(p, all))

?- trace(shift_reduce, all).
%         shift_reduce/2: [call,redo,exit,fail]
true.

[debug]  ?- shift_reduce([λ,x,x], T).
 T Call: (8) shift_reduce([λ, x, x], _7344)
 T Exit: (8) shift_reduce([λ, x, x], [e, [λ], [v, [x]], [e, [v, [...]]]])
T = [e, [λ], [v, [x]], [e, [v, [x]]]] ;
 T Exit: (8) shift_reduce([λ, x, x], [e, [λ], [v, [x]], [e, [v, [...]]]])
T = [e, [λ], [v, [x]], [e, [v, [x]]]] ;
 T Fail: (8) shift_reduce([λ, x, x], _7344)
false.

[debug]  ?-
2
If you want to run from the command line and output to a file, did you try using tee? (That is, of course, assuming you're using Linux, but you haven't said... I think Windows has an equivalent command) - lurker
You can use trace/2 to trace intresting for you predicates only. Something like trace(q, +call)., trace(p, +call).. - Stanislav Ivanov
You can also debug using spy points instead of trace. - Paulo Moura

2 Answers

3
votes

In SWI-Prolog you can use trace/2 like:

trace(p, all) and this will enable information related to p and also this will activate debug mode.

while you're on debug mode you can call:

p(<Stuff>).

and this will now show information only for p.

1
votes

When you press return in the debugger, the debugger usually creaps. The classical apprach is to set spy points what you want to see. And then leap from spy point to spy point. Many debuggers provide a leap command.

Here is an example code:

p :- q, s, p.
q.
s.

When you trace and creap you get the following trace:

?- trace.
true.

[trace]  ?- p.
   Call: (8) p ? creep
   Call: (9) q ? creep
   Exit: (9) q ? creep
   Call: (9) s ? creep
   Exit: (9) s ? creep
   Call: (9) p ? creep
   Call: (10) q ? 

When you debug, use a spy point on p/0 and leap you get the following trace:

?- debug.
true.

[debug]  ?- spy(p/0).
% Spy point on p/0
true.

[debug]  ?- p.
 * Call: (8) p ? leap
 * Call: (9) p ? leap
 * Call: (10) p ? leap
 * Call: (11) p ? 

You can combine the above with the leash/1 directive, so that the debugger doesn't prompt.