next up previous contents index
Next: Getting started with Morphine Up: Morphine - User Manual Previous: Introduction

Subsections

Understanding the Mercury trace

   
Introduction

Mercury programs are heavily transformed before any code is generated. Procedures are put into superhomogeneous form, high order predicates are transformed into first order predicates, some procedures can be inlined; under the commutative semantics, conjunctions and disjunctions can be evaluated in any order. Hence, it is sometimes difficult to relate Mercury source code with its corresponding trace, even if the program is compiled using the strict sequential semantics with all the optimizations switched off. In order to relate the trace with the initial program, it might sometimes be helpful to have a look at the HLDS code (see the Mercury User and Language Reference Manuals [6,5]).

Morphine is connected to the traditional tracer of Mercury. We describe in sub-sections 2.2 to 2.4 the information contained in the trace and we specify in what order each type of events occurs. These descriptions give another point of view of the ``Tracing Mercury Programs'' section of the Mercury user manual3.

   
Trace event representation

We call execution events particular points of the program execution where information concerning the current state of the execution can be retrieved. Mercury events contain several kinds of information: information describing the control flow of the execution, information about the variable instantiations (data information), and information that refers to source code (source connection information).

A trace is therefore a sequence of events, where each event can be seen as a tuple of a relational database. This trace model is the basis of the trace query mechanism.

The different event attributes are as follows. The identifiers in teletype font are the names used in Morphine  to denote event attributes.

Control flow information

Data information

Source connection information

An example of Mercury event


  
Figure 1: An example of Mercury event
\begin{figure}\begin{center}
\begin{tabular}{\vert l\vert c\vert}
\hline
\verb*+...
...
\verb*+ 10: 6 [5] then partition([1, 2], 3, -, -) [s1, c2, t]+
\par\end{figure}

The event structure is illustrated by Figure 1. The displayed structure is related to an event of the execution of the qsort program which sorts the list of integers [3, 1, 2] using a quick sort algorithm. The full code of qsort.m is given in Appendix A. The information contained in that structure indicates that procedure qsort:partition/4-0 is currently invoked, it is the 10th trace events being generated, the 6th goal being invoked, and it has 4thancestors (depth is 5). At this point, only the first two arguments of partition/4 are instantiated: the first one is bounded to the list of integer [1, 2] and the second one to the integer 3 ; third and fourth variable are not live which is indicated by the `-'. The two live local variables are H, bound to the integer 1, and T bound to the list of integer [2]. This event occurred in the then branch of the second conjunction of the first switch of the code of partition/4.

   
The sequence of events

We call trace of a program execution a sequence of events of the same format; in a sense, a trace is a discretisation of the execution. The Mercury trace can be seen as an extended version of the Byrd box model [1] that binds execution events to goals. In this sub-section, we give a specification of the Mercury trace from the point of view of a given goal in extended BNF notation. Depending on the determinism of the procedure, different sequences of events will be generated.

An example of Mercury trace

Figure 2 shows an exhaustive trace of the execution of the qsort program (see Appendix A) on the list [3, 1,2]. In this trace, we only print the following event attributes: Chrono :Call [Depth] Port Proc/Arity ArgList GoalPath. We also filtered out all the procedures that were defined in the module printlist.m which are not of interest here.

Note that input argument of main procedure is not available at exit ports (event 65) since it is destructively updated. Note also the hole between events 48 and 65 that corresponds to events occurring in printlist.m module.


  
Figure 2: Execution trace of qsort([2, 1, 3])
\begin{figure}\small
\begin{tex2html_preform}\begin{verbatim}[Morphine]: fget([m...
... main(-, state('<<c_pointer>>'))\end{verbatim}\end{tex2html_preform}\end{figure}


next up previous contents index
Next: Getting started with Morphine Up: Morphine - User Manual Previous: Introduction
jahier@irisa.fr