The following configuration script demonstrates how the application might
control the Log statements embedded in the Mod module at configuration
time. In this case, the configuration script arranges for the Log
statements within the Mod module (shown above) to always generate events.
Without these configuration statements, no Log events would be generated
by this module.
Example 2: The following XDC configuration statements turn on enter
and exit logging at configuration time for a module. Without any other
changes in the runtime code, every time a module Mod's function is
being called or exits, an event will be logged.
const Log.NUMARGS |
|
Maximum number of arguments supported in Log events
XDCscript usage |
meta-domain |
#define Log_NUMARGS (Int)8
const Log.PRINTFID |
|
The EventId for Log_print() events
XDCscript usage |
meta-domain |
typedef Log.Event |
|
Log event type
typedef opaque Log_Event;
DETAILS
An
Event is represented on the target as a 32-bit value that can
be decoded offline to recover the
Event information defined in
a corresponding metaonly
EventDesc. In addition,
Events may be
decoded at runtime via methods provided in this module; see
getMask and
getEventId.
When an event is "raised" a
Types_Event is
created which has the same event ID as the
Log_Event but also
encodes the module ID of the caller. This new event is passed to
the underlying
ILogger module along with any arguments
associated with the event.
SEE
typedef Log.EventId |
|
Unique ID embedded in each Event
DETAILS
This ID must be used to compare two Events for equality. Event
ids are not guaranteed to remain constant between different
configurations of an application. For example, adding a module
may cause the event ids of another module to change.
However, event ids declared by a module are guaranteed to be
consecutive values starting from the first declared
Log_Event and increasing to the last declared
event. As a result, clients of a module can efficiently test ranges
of events and modules can add new events, such as internal trace
events, without breaking clients; simply be careful to add new events
after any existing events in you module's
.xdc specification.
SEE
metaonly struct Log.EventDesc |
|
Log event descriptor
XDCscript usage |
meta-domain |
var obj = new Log.EventDesc;
obj.mask = Bits16 ...
// event enable mask
obj.msg = String ...
// event "printf" message format string
DETAILS
Each Log event is defined by a Log event descriptor.
The
mask defines which bits in the module's diagnostics mask
enable this
Log event. Events "posted" via
Log_write are only
written to the underlying logger if one of the mask's bits matches
the caller's module diagnostics settings (see
xdc.runtime.Types.common$).
The
msg defines a printf style format string that defines how to
render the arguments passed along the event in a
Log_write call.
For a description of the allowable format strings see
print6.
SEE
struct Log.EventRec |
|
The target representation of a recorded event
XDCscript usage |
meta-domain |
var obj = new Log.EventRec;
// time event was written
obj.serial = Bits32 ...
// serial number of event
obj.evt = Bits32 ...
// target encoding of an Event
// arguments passed via Log_write/print
typedef struct Log_EventRec {
// time event was written
Bits32 serial;
// serial number of event
// target encoding of an Event
// arguments passed via Log_write/print
} Log_EventRec;
DETAILS
This structure defines how events are recorded on the target.
config Log.L_construct // module-wide |
|
Lifecycle event posted when an instance is constructed
XDCscript usage |
meta-domain |
msg: "<-- construct: %p('%s')"
};
config Log.L_create // module-wide |
|
Lifecycle event posted when an instance is created
XDCscript usage |
meta-domain |
msg: "<-- create: %p('%s')"
};
config Log.L_delete // module-wide |
|
Lifecycle event posted when an instance is deleted
XDCscript usage |
meta-domain |
msg: "--> delete: (%p)"
};
config Log.L_destruct // module-wide |
|
Lifecycle event posted when an instance is destructed
XDCscript usage |
meta-domain |
msg: "--> destruct: (%p)"
};
metaonly config Log.common$ // module-wide |
|
Common module configuration parameters
XDCscript usage |
meta-domain |
DETAILS
All modules have this configuration parameter. Its name
contains the '$' character to ensure it does not conflict with
configuration parameters declared by the module. This allows
new configuration parameters to be added in the future without
any chance of breaking existing modules.
Log.doPrint( ) // module-wide |
|
Render an event as text via System_printf
ARGUMENTS
evRec
a nonNULL pointer to an initialized Log_EventRec
structure to be formated via
System_printf.
DETAILS
This method is not gated and may make more than one call to
System_printf. This utility method is typically used within the
implementation of a logger which initializes
Log_EventRec structures based on
Log events
produced by the application.
Log.getEventId( ) // module-wide |
|
Get event ID of the specified (encoded) event
ARGUMENTS
evt
the Log event encoding a mask and event ID
DETAILS
This method is used to compare "known"
Log events with
"raised"
Types_Event.
RETURNS
event ID of the specified event
SEE
Log.getMask( ) // module-wide |
|
Get the Diags mask for the specified (encoded) event
ARGUMENTS
evt
the Log event encoding a mask and event ID
RETURNS
Diags mask for the specified event
Log.print0( ) // module-wide |
|
Generate a Log "print event" with 0 arguments
macro Void Log_print0(
Diags_Mask mask,
String fmt );
SEE
Log.print1( ) // module-wide |
|
Generate a Log "print event" with 1 argument
macro Void Log_print1(
Diags_Mask mask,
String fmt,
IArg a1 );
SEE
Log.print2( ) // module-wide |
|
Generate a Log "print event" with 2 arguments
macro Void Log_print2(
Diags_Mask mask,
String fmt,
IArg a1,
IArg a2 );
SEE
Log.print3( ) // module-wide |
|
Generate a Log "print event" with 3 arguments
macro Void Log_print3(
Diags_Mask mask,
String fmt,
IArg a1,
IArg a2,
IArg a3 );
SEE
Log.print4( ) // module-wide |
|
Generate a Log "print event" with 4 arguments
macro Void Log_print4(
Diags_Mask mask,
String fmt,
IArg a1,
IArg a2,
IArg a3,
IArg a4 );
SEE
Log.print5( ) // module-wide |
|
Generate a Log "print event" with 5 arguments
macro Void Log_print5(
Diags_Mask mask,
String fmt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5 );
SEE
Log.print6( ) // module-wide |
|
Generate a Log "print event" with 6 arguments
macro Void Log_print6(
Diags_Mask mask,
String fmt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5,
IArg a6 );
ARGUMENTS
mask
enable bits for this Log event
fmt
a printf style format string
a1
value for first format conversion character
a2
value for second format conversion character
a3
value for third format conversion character
a4
value for fourth format conversion character
a5
value for fifth format conversion character
a6
value for sixth format conversion character
DETAILS
As a convenience to C (as well as assembly language) programmers,
the Log module provides a variation of the ever-popular printf
function.
The print[0-6] functions generate a Log "print event" and route
it to the current module's logger.
The arguments passed to
print[0-6] may be characters, integers,
strings, or pointers. However, because the declared type of the
arguments is
IArg, all pointer arguments must be cast
to an
IArg type.
IArg is an integral type large enough to hold
any pointer or an
int. So, casting a pointer to an
IArg does
not cause any loss of information and C's normal integer conversions
make the cast unnecessary for integral arguments.
The format string can use the following conversion characters.
However, it is important to recall that all arguments referenced by
these conversion characters have been converted to an IArg
prior to conversion; so, the use of "length modifiers" should be
avoided.
Conversion Character Description
------------------------------------------------
%c Character
%d Signed integer
%u Unsigned integer
%x Unsigned hexadecimal integer
%o Unsigned octal integer
%s Character string
%p Pointer
%f Single precision floating point (float)
Format strings, while very convenient, are a well known source of
portability problems: each format specification must precisely match
the types of the arguments passed. Underlying "printf" functions use
the format string to determine how far to advance through their
argument list. For targets where pointer types and integers are the
same size there are no problems. However, suppose a target's pointer
type is larger than its integer type. In this case, because integer
arguments are widened to be of type IArg, a format specification of
"%d" causes an underlying printf() implementation to read the
extended part of the integer argument as part of the next argument(!).
To get around this problem and still allow the use of "natural"
format specifications (e.g.,
%d and
%x with optional width
specifications),
System.aprintf() is used which assumes
that all arguments have been widened to be of type
IArg.
See
System.printf for complete details.
The %f format specifier is used to print a single precision float
value. Note that %f assumes that sizeof(Float) <= sizeof(IArg).
Most clients that interpret float values except that they are
represented in IEEE 754 floating point format. Therefore, it is
recommended that the float values are converted into that format prior
to supplying the values to Log functions in cases where targets do
not generate the float values in IEEE 754 floating point format by
default.
EXAMPLES
The following example demonstrates a typical usage.
String list[];
UInt i;
Log_print2(Diags_USER2, "list[%u] = %s\n", i, (IArg)list[i]);
Note that the IArg cast above is only necessary for pointer
arguments; C's normal parameter conversions implicitly convert
integral arguments.
Log.put4( ) // module-wide |
|
Unconditionally put the specified Types event
macro Void Log_put4(
Types_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4 );
ARGUMENTS
evt
the Types event to put into the log
a1
value for first format conversion character
a2
value for second format conversion character
a3
value for third format conversion character
a4
value for fourth format conversion character
DETAILS
This method unconditionally puts the specified
Types.Event
evt into the log. This type of event is created either implicitly
(and passed to an
ILogger implementation) or explicitly
via
Types.makeEvent().
SEE
Log.put8( ) // module-wide |
|
Unconditionally put the specified Types event
macro Void Log_put8(
Types_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5,
IArg a6,
IArg a7,
IArg a8 );
DETAILS
This method is identical to
put4 except that it allows
up to eight arguments to be passed.
SEE
Log.write0( ) // module-wide |
|
Generate a Log event with 0 arguments
SEE
Log.write1( ) // module-wide |
|
Generate a Log event with 1 argument
macro Void Log_write1(
Log_Event evt,
IArg a1 );
SEE
Log.write2( ) // module-wide |
|
Generate a Log event with 2 arguments
macro Void Log_write2(
Log_Event evt,
IArg a1,
IArg a2 );
SEE
Log.write3( ) // module-wide |
|
Generate a Log event with 3 arguments
macro Void Log_write3(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3 );
SEE
Log.write4( ) // module-wide |
|
Generate a Log event with 4 arguments
macro Void Log_write4(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4 );
SEE
Log.write5( ) // module-wide |
|
Generate a Log event with 5 arguments
macro Void Log_write5(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5 );
SEE
Log.write6( ) // module-wide |
|
Generate a Log event with 6 arguments
macro Void Log_write6(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5,
IArg a6 );
SEE
Log.write7( ) // module-wide |
|
Generate a Log event with 7 arguments
macro Void Log_write7(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5,
IArg a6,
IArg a7 );
SEE
Log.write8( ) // module-wide |
|
Generate a Log event with 8 arguments
macro Void Log_write8(
Log_Event evt,
IArg a1,
IArg a2,
IArg a3,
IArg a4,
IArg a5,
IArg a6,
IArg a7,
IArg a8 );
ARGUMENTS
evt
the Log event to write
a1
value for first format conversion character
a2
value for second format conversion character
a3
value for third format conversion character
a4
value for fourth format conversion character
a5
value for fifth format conversion character
a6
value for sixth format conversion character
a7
value for seventh format conversion character
a8
value for eighth format conversion character
DETAILS
If the mask in the specified Log event has any bit set which is
also set in the current module's diagnostics mask, then this call to
write will "raise" the given Log event.
module-wide built-ins |
|
// Get this module's unique id
Bool Log_Module_startupDone( );
// Test if this module has completed startup
// The heap from which this module allocates memory
Bool Log_Module_hasMask( );
// Test whether this module has a diagnostics mask
Bits16 Log_Module_getMask( );
// Returns the diagnostics mask for this module
Void Log_Module_setMask( Bits16 mask );
// Set the diagnostics mask for this module