Download the Plugin Development Guide - Frama-C

Transcript
4.7. PLUG-IN GENERAL SERVICES
4.7 Plug-in General Services
Module
Plugin
provides an access to some general services available for all plug-ins.
goal of this module is twofold.
The
First, it helps developpers to use general Frama-C services.
Second, it provides to the end-user a set of features common to all plug-ins.
these services, you have to apply the functor
To access to
Plugin.Register.
Each plug-in must apply this functor exactly once.
Example 4.9
Here is how the plug-in
From
applies the functor
Plugin.Register
for its own
use.
i n c l u d e Plugin . Register
( struct
l e t name = " from analysis "
l e t shortname = " from "
l e t h e l p = " functional dependencies "
end )
Applying this functor mainly provides two dierent services. First it gives access to functions
for printing messages in a Frama-C-compliant way (see Section 4.8). Second it allows to dene
plug-in specic parameters available as options on the Frama-C command line to the end-user
(see Section 4.13).
4.8 Logging Services
Displaying results of plug-in computations to users, warning them of the hypothesis taken by
the static analyzers, reporting incorrect inputs, all these tasks are easy to think about, but
turn to be dicult to handle in a readable way. As soon as your plug-in is registered (see
Section 4.7 above), though, you automatically benet from many logging facilities provided
by the kernel. What is more, when logging through these services, messages from your plug-in
combine with other messages from other plug-ins, in a consistent and user-friendly way.
As a general rule, you should never write to standard output and error channels through
OCaml standard libraries.
Pervasives.stderr
For instance, you should never use
channels, nor
Format.printf-like
Pervasives.stdout
Format.fprintf to implement pretty-printers for your own complex
printf-like routines of Log.Messages to display messages to the user. All
Instead, you should use
data, and only the
these routines are immediately available from your plug-in general services.
Example 4.10
and
routines.
A minimal example of a plug-in using the logging services:
module S e l f = P l u g i n . R e g i s t e r
( struct
l e t name = " foo plugin "
l e t shortname = " foo "
l e t h e l p = " illustration of logging services "
end )
l e t pp_dg out n =
Format. f p r i n t f out
" you have at least debug % d" n
l e t run () =
53