To turn on tracing in Prolog, execute the "goal"
? trace. true.
When you are finished with tracing, turn it off using the "goal"
? notrace.
Here is an example of trace
in action. First some code,
which computes factorial N  the product of the numbers from 1 to N.
By convention, factorial 0 is 1. Factorial N is often written N!, where
the exclamation mark signifies the "factorial operator". Here is the
code:
factorial(0, 1).

rule 1

factorial(0) = 1 
Prolog dialog/trace output  Commentary 

prolog s factorial.pl blah blah blah … ? trace. true. [trace] ? factorial(3, X). Call: (7) factorial(3, _G284) ? creep* ^ Call: (8) 3>0 ? creep ^ Exit: (8) 3>0 ? creep ^ Call: (8) _L205 is 31 ? creep ^ Exit: (8) 2 is 31 ? creep Call: (8) factorial(2, _L206) ? creep ^ Call: (9) 2>0 ? creep ^ Exit: (9) 2>0 ? creep ^ Call: (9) _L224 is 21 ? creep ^ Exit: (9) 1 is 21 ? creep Call: (9) factorial(1, _L225) ? creep ^ Call: (10) 1>0 ? creep ^ Exit: (10) 1>0 ? creep ^ Call: (10) _L243 is 11 ? creep ^ Exit: (10) 0 is 11 ? creep Call: (10) factorial(0, _L244) ? creep Exit: (10) factorial(0, 1) ? creep ^ Call: (10) _L225 is 1*1 ? creep ^ Exit: (10) 1 is 1*1 ? creep Exit: (9) factorial(1, 1) ? creep ^ Call: (9) _L206 is 1*2 ? creep ^ Exit: (9) 2 is 1*2 ? creep Exit: (8) factorial(2, 2) ? creep ^ Call: (8) _G284 is 2*3 ? creep ^ Exit: (8) 6 is 2*3 ? creep Exit: (7) factorial(3, 6) ? creep X = 6 ; Redo: (10) factorial(0, _L244) ? creep ^ Call: (11) 0>0 ? creep ^ Fail: (11) 0>0 ? creep Fail: (9) factorial(1, _L225) ? creep Fail: (8) factorial(2, _L206) ? creep Fail: (7) factorial(3, _G284) ? creep false. [debug] ? notrace. % turn off tracing true. [debug] ? 

There are further tracing facilities in SWI Prolog. Do
? help(trace).to start to find out about them.
Builtin Prolog functions are not traced  that is,
the internals of calls to things like member
are not
further explained by tracing them.