| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.103.0/coding/ai/skills/logtalk-debugging/SKILL.md |
name: logtalk-debugging description: Debug Logtalk code with the debugger tool, debug mode, breakpoints, tracing, and related techniques. Use when diagnosing failures, unexpected solutions, exceptions, or non-determinism in Logtalk entities. license: Apache-2.0 metadata: copyright: "2026 Paulo Moura <pmoura@logtalk.org>" ---
Use Logtalkâs official debugger and debugging API. Entities must be compiled in debug mode to be traceable. Do not invent a parallel debugging workflow.
Read and follow:
Do not duplicate those pages. Prefer linking to specific sections when more detail is needed.
| ?- logtalk_load(debugger(loader)).
Optionally load it from a settings file at startup.
set_logtalk_flag(debug, on) (also turns off optimize).logtalk_load(Files, [debug(on)]).logtalk_make(debug) (or {+d} with many backends).clean flag on when turning debug on at runtime so previously compiled files are regenerated.set_logtalk_flag(debug, on) directive inside the entity or at the start of the file.| ?- debugger::debugging(Entity).
/ debugger::debug` â select the debugger as the active debug handler.ports_profiler would be deactivated).logtalk_make(normal), logtalk_make(optimal), or {+n} / {+o}) for performance.
Ports: call, exit, redo, fail, exception, plus Logtalkâs fact and rule (head unification with a fact or rule).
Control which ports pause for interaction:
| ?- debugger::leash([call, exit, fail]). | ?- debugger::leash(loose). % or half, tight, full, none
Default is to pause at every port. Unleashed ports are printed but do not stop.
| Type | Typical API | Pauses when |
|---|---|---|
| Predicate / non-terminal | spy(Name/Arity), spy(Name//Arity), optionally `Object::Name/Arity` | All ports for that predicate |
| Clause | spy(Entity-Line) | Unification at that clause head |
| Conditional | spy(Entity, Line, Condition) | Unification and condition holds (lambda or hit-count expression) |
| Hit count | Condition is e.g. =<(N), =:=(N), mod(M), >(N) | Unification count matches expression |
| Triggered | Condition is another Entity-Line breakpoint | That other breakpoint was hit earlier |
| Context | spy(Sender, This, Self, Goal) | Current execution context and goal are subsumed by the templates |
Remove with the matching nospy/... predicates (including nospy(_) to clear matching predicate/clause breakpoints). Setting a clause breakpoint clears conflicting conditional/triggered/log points on the same clause.
Conditional lambdas run in user, must be side-effect free, and may use forms like [Goal]>>Cond or [Count, N, Goal]>>Cond.
testing skill: compile with debug(on), re-run a single test (`tests::run(TestId)`), and spy the relevant predicates.redo ports or missing determinism when deterministic/1 tests fail.exception (e.g. tight or full) and spy the predicate that should throw or catch.-> and ; before changing the algorithm.{Goal} for native calls inside Logtalk source.debug(on) and heavy leashing on for routine work (slow, noisy)ports_profiler or other handlers are loadedtrace/debug as appropriate)debug, optimize, cleanports_profiler, settings files for loading the debugger at startup