☰

Tracing/monitoring of PLAI analyses

Author(s): Isabel Garcia-Contreras, Marco Ciccalè (minor improvements).

The following tools are provided for both interactive and non-interactive tracing/monitoring of the solver and the abstract domain operations.

Tracing the fixpoint operations

During analysis, the solver can emit messages to the top level reporting on the operations in the analysis graph as they are being performed. This is particularly useful in combination with the raw output, since node ids in the graph match those in the raw true assertions and the true annotations.

For enabling this feature, comment out the

:- use_package(ciaopp(plai/notrace)).

directive in the src/plai/fixpoint_options.pl file, and recompile CiaoPP:

$ ciao build --bin ciaopp

In some cases cleaning may be necessary before recompilation, because of possible undetected dependencies during incremental compilation due to included files:

$ ciao clean ciaopp
$ ciao build --bin ciaopp

Then, set preprocess flag trace_fixp to trace, which, if you are using the CiaoPP top level, can be done by:

ciaopp ?- set_pp_flag(trace_fixp, trace).
or, if you are using the CiaoPP command line interface, it can be done by:
$ ciaopp -A <file> -ftrace_fixp=trace

Additionally, and only from the CiaoPP top level, if the preprocess flag timestamp_trace is set to on, a timestamp is printed when tracing. This can be helpful for diagnosing performance issues.

The interactive abstract debugger

In addition to the raw tracing above, an abstract debugging tool is provided on top of it that is analogous to the standard source-level debugger (see The interactive debugger), but for the abstract execution of a program. As in the standard debugger, the interactive abstract debugger can highlight the point in the source code that corresponds to the current step being performed by the analysis. The actual highlighting of the source lines is handled by the editor/IDE (Emacs, VS Code, Playground, etc.).

The abstract debugger extends Byrd's Procedure Box model of debugging execution, which provides a simple way of visualizing control flow at the predicate level.

Abstract procedure box model

In the standard Byrd model, each predicate call is represented as a box with four ports: Call, Exit, Redo, and Fail. The abstract debugger reuses this same structure, but the transitions between ports now reflect the abstract execution of the program rather than its concrete execution. That is, instead of displaying (inlined) unifications (e.g., p(a)), the abstract debugger displays abstract substitutions belonging to the abstract domain being used (e.g., p(X): [ground([X])] for the groundness domain).

Consider the following diagrams:

Literal (also entry, i.e., initial call)

    Call    ┌─────────────┐    Succ
───────────►│  Procedure  │───────────►
            └─────────────┘
Procedure
 WidenCall  FixpStart ┌───────────┐ WidenSucc  FixpEnd
─ ─ ─ ─ ─ ─►─────────►│  Clauses  │─ ─ ─ ─ ─ ─►───────►
                      └───────────┘
                          ▲   │
                          └───┘
                         FixpIter
Clauses
VisitClause ┌────────────┐ ExitClause   Comb
───────────►│   Clause   │────────────►──────►
            └────────────┘     │
                   ▲           │
                   └───────────┘
                     ExitClause
Clause
Proj Entry ┌────────────┐ Exit Prime
────►─────►│  Literals  │─────►─────►
           └────────────┘
There are labeled arrows (representing ports) indicating the control flow in and out of the procedure boxes. The abstract substitution at each port is displayed at every step. The meaning of each labeled arrow (port) in the abstract setting is as follows:

  • Call: fires at the Literal box carrying the call abstraction, i.e., the abstract substitution just before an invocation to the procedure (say, p/n) from a literal in the body of another procedure (say main/0). It represents that the analyzer is about to start analyzing procedure p/n for that particular calling context. Control passes to the Procedure box, where the fixpoint computation begins.

  • FixpStart: the analyzer is about to start a fixpoint computation for the invocation to procedure p/n.

  • FixpIter: marks each iteration of the fixpoint computation.

  • FixpEnd: marks the end of the fixpoint computation (once stabilized).

  • WidenCall: may fire to widen the call abstraction.

  • WidenSucc: may fire to widen the success abstraction.

  • Succ: fires once the fixpoint has stabilized, carrying the resulting success abstraction.

  • VisitClause: fires for each clause (all clauses analyzed unconditionally); control passes to the Clause box.

  • Proj: projects the call abstraction onto the goal variables.

  • Entry: projects the call abstraction onto the clause variables.

  • Exit: fires once all body literals have been processed.

  • Prime: projects the exit abstraction back into the calling context.

  • Comb: combines all clauses' prime abstractions into the procedure's overall success abstraction.

  • Built-ins are handled via the abstract transfer function.

  • Predicate calls are handled by recursively re-entering the Program box.

Format of the abstract debugging messages

The format of the abstract debugging messages mimics that of regular debugging, so the reader is referred to the interactive debugger's manual for details. However, here we discuss some slight differences:

Instead of (in-lined) unifications, abstract debugging messages show first the subgoal under analysis, then the abstract substitution, and, when changing variable context, the variable binding equations.

For example, the following abstract debugging messages:

  1  1  Call: integers(Low_1,High_1,Is_1): [int(Low_1),int(High_1),term(Is_1)] ?
  2  1  Entry: integers(Low_2,High_2,[Low_2|Is_2]): [int(Low_2),int(High_2),term(Is_2)]
    ➔ with [Low_2=Low_1,High_2=High_1,[Low_2|Is_2]=Is_1] ?

produced when analyzing the following program:

:- pred integers(Low, High, Is) : (int(Low), int(High)) => int(Is).
integers(Low, High, [Low | Rest]) :-
    Low =< High, !,
    M is Low + 1,
    integers(M, High, Rest).
integers(_,_,[]).

Show:

  1. The analyzer is about to start the analysis of the integers(Low_1,High_1,Is_1) procedure with the (calling) abstract state [int(Low_1),int(High_1),term(Is_1)] (taken from its pred assertion).

  2. The analyzer has changed the variable context to that of one of the clauses of integers/3 (the first one).

Manipulating ports

Ports can be "unleashed." This means that the debugger will stop and display the corresponding message while not allowing the user to interact with it. Obviously, the ? prompt will not be shown in such messages, since the user has specified that no interaction is desired at this point.

Also, ports can be "hidden." This means that the debugger will not stop nor display the corresponding message.

Usage

Abstract debugging is enabled via PLAI's tracing facilities, as in Tracing the fixpoint operations. However, the trace_fixp flag needs to be set to debug. I.e., the steps to follow are:

  1. Make sure CiaoPP has been recompiled with tracing activated (see Tracing the fixpoint operations).

  2. Load CiaoPP in the top level: ?- use_module(ciaopp(ciaopp)).

  3. Enable debug mode: ?- set_pp_flag(trace_fixp, debug).

  4. Start an analysis, e.g.:

    ?- module(example).
    ...
    
    ?- analyze(shfr).
    @{Analyzing (shfr): [/private/tmp/p.pl]
    @{init for the plai fixpoint in 0.196 msec.@}
    @{preprocessed for the plai fixpoint in 0.395 msec.@}
       1  1  Call: p(_3706): [sharing([[_3706]])] ? ;
       2  1  Entry: p(_3928): [sharing([[_3928]])] with [_3928=_3706] ? ;
       3  1  Call: q(_3928): [sharing([[_3928]])] ? ;
       4  2  Call: q(_3928): [sharing([[_3928]])] ? ;
       5  2  Entry: q(_4694): [sharing([[_4694]])] with [_4694=_3928] ? 
    ...

If this is done within one of the supported IDEs (Emacs, VS Code, Playground, etc.) the corresponding element in the source program will be highlighted, as in the standard source debugger.

Currently, this functionality is available only if CiaoPP is being run in the ciao top level, i.e., the source lines will not be highlighted if analyzing from the ciaopp or lpdoc top levels.

Visualization of the analysis graph

Note that the daVinci executable has to be accessible in the path for Ciao.

?- trace_fixp(view).     % This will open a uDraw(Graph) window

yes
?- module(PathToModule). % load the module to analyze (located in PathToModule)

yes
?- analyze(AbsInt).      % Analyze for abstract domain AbsInt
% The process will appear in the uDraw(Graph) window.

yes
?- trace_fixp(no).       % Stop the tracing

The implementation may not support all features of CiaoPP. For example, in the actions: ?- analyze(AbsInt), analyze(AbsInt). the second analysis will fail (only if the tracing is on).

uDraw(Graph) extended features

A menu is generated in uDraw(Graph) (Edit) that allows to execute the analysis in a synchronous and asynchronous way (see Edit->Mode) to switch options.

If the synchronous option is on, once the analysis has started, the visualization (and the fixpoint) will do one operation each step. The next step will be performed only if command Edit->'One step ahead' is executed.

Activate run-time checks

Go to any module, add :- use_package(rtchecks). and recompile by

$ ciao build --bin ciaopp

Modules recommended:

  • Generic domain interface src/plai/domains.pl.
  • Any specific domain of src/domains/* (check that it has assertions!).
  • Fixpoints: src/plai/fixpoint_options.pl.
  • Generic fixpoint operations: src/plai/fixpo_ops.pl.
  • Modular analysis: src/plai/intermod_options.pl.
  • Incremental analysis: src/plai/incanal/incanal_options.pl.
  • Assertions during fixpoint: src/plai/apply_assertions.pl/src/plai/apply_assertions_old.pl.

In domains.pl the assertions were written by looking only at some domains, not all of them. It could happen that they are too restrictive. If you find that an assertion does not hold in run-time, please open an issue.