Debug mode and trace points

The two places I’ve found that reference “Debug Mode” both state that it stops/traps “Trace Points” (which I understand to mean traces set by trace/1 and trace/2):

  • Here it says: “In debug mode, Prolog stops at spy and trace points…”
  • Here it says: " If debug mode is activated the system traps encountered spy points (see spy/1) and trace points (see trace/1)…"

From what I can tell, Trace Points set by trace/1 and trace/2 don’t care whether you are in debug mode or not (and furthermore that the system never stops at a trace point set by trace/1 and trace/2, it only stops when in trace mode set by trace/0):

foo(bar).
foo(baz).
?- trace(foo/1).
%         foo/1: [all]
true.

?- debugging.
% Debug mode is off
true.

?- tracing.
false.

?- foo(X).
 T Call: foo(_17194)
 T Exit: foo(bar)
X = bar ;
 T Redo: foo(bar)
 T Exit: foo(baz)
X = baz.

Am I missing something or is there just a bug in the docs?

1 Like

You are right. In the old days trace/1,2 was implemented in the VM and only checked in debug mode. These days it is implemented using wrap_predicate/4, which does not rely on the debug mode.

Debug mode does control whether spy and breakpoints are effective. Note that a spy point watches the visible ports of the target predicate. A break point is realized by watching a specific location in the compiled code of a clause.

[fixed the two referenced locations in the docs]

1 Like