TraceMethodEntryUsingTracer Aspect
[CodeInstrumentation Group]

This aspect is defined in file: ../../AspectXLib/CodeInstrumentation/Tracer/aspects/TraceMethodEntryUsingTracer.ax

Aspect Description

Sample aspect program that shows how to insert instructions that use dedicated Tracer object for tracing. This example is implemented according to the Trace design pattern

This aspect program shows an example of how the implementation of selected methods in a certain code base can be modified to output a tracing message every time the method is entered. In this example, the tracing message is output using a dedicated object of type DC_TestTracer that encapsulates the code that process the tracing messages. DC_TestTracer class extends the Tracer abstract class, which is a part of the OBS Framework. An instance of class DC_TestTracer is accessed through the TracerSingleton class. Hence the TracerSingleton is used as a component that sends the trace signals to a log file or standard output. See the Trace design pattern for more information.

This aspect defines four advices that describe four separate but related changes. The first advice inserts the tracing code in the target methods. The second advice inserts a new include statement to include the stdio library that is required by the printf method. The third advice modifies the comments of the classes that are affected by the change to include a statement that the class code has been automatically modified by an aspect program. The fourth advice modifies the comment of the methods that are affected by the change to include a description of the type of change that has been woven into the code.

This sample aspect program targets all methods called fTwoParameter.
Author:
A. Pasetti, O. Rohlik
See also:
TraceMethodEntry

Pointcuts

functiontargetMethodImplementation
 Points to the implementations of the methods that must be modified
unittargetImplementationUnit
 Points to all the units that contain implementations of methods that must be modified

Advices

addaddIncludeRootObject
 Add the #include "TracerSingleton
begininsertTrace
 Insert the tracing instruction in the target method

Pointcut Documentation

function targetMethodImplementation (source)
Points to the implementations of the methods that must be modified. The methods that must be modified are those whose name is fTwoParameter.

The implementation of the restriction relies on the fact that in srcML the element name contains two other name subelements where the first of them contains the class name and the second contains name of the method. Therefore to access the name of the method the following expression is used: src:name/src:name[2].

If it were desired to capture more than one target class, this could be done by modifying the XPath expression in the constraint to include names whose class part matches several class names.

This pointcut only points to the method implementation. A second pointcut (targetMethodDeclaration) points to the method declarations.
unit targetImplementationUnit (source)
Points to all the units that contain implementations of methods that must be modified. In srcML, a unit is a source file (a definition file, a declaration file, or an inline file). This pointcut therefore identifies all the source files that contain an implementation of the target method.

Advice Documentation

add addIncludeRootObject (source)

Triplet: unit add include

Add the #include "TracerSingleton.h" preprocessor directive. The inclusion of this header file is necessary because the code that is woven into the target methods uses the static method getInstance() declared in the this file.

Refers to global pointcut: unit targetImplementationUnit

begin insertTrace (source)

Triplet: function begin codeFragment

Insert the tracing instruction in the target method. This advice defines a tracing signal item at the beginning of the target method. Then the item is send to the Tracer object using the sendSynchTrace() method. The Tracer object is encapsulated in the TracerSingleton class. Thus only one Tracer object is available to the whole application.

Refers to global pointcut: function targetMethodImplementation