Skip to content

Commit e520096

Browse files
committed
Merge branch 'pmderodat/edge' into 'master'
Document the support for preprocessing in Ada See merge request eng/das/cov/gnatcoverage!316 For eng/das/cov/gnatcoverage#138
2 parents 42003dd + 39fe372 commit e520096

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

doc/gnatcov/src_traces.rst

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,31 @@ within the same environment, the variable name for a program can actually be
362362
tailored by passing a :cmd-option:`--dump-filename-env-var` switch to |gcvins|,
363363
providing the variable name to use.
364364

365+
Support for preprocessing
366+
-------------------------
367+
368+
|gcvins| automatically detects preprocessor configuration from the compiler
369+
switches present in project files (``-gnatep`` and ``-gnateD`` for Ada sources,
370+
``-D`` and the like for C/C++ sources). It then runs preprocessing on the
371+
source code *before* the instrumentation itself happens. This allows gnatcov
372+
to compute the code coverage only for code that is left "enabled" by
373+
preprocessing directives: disabled code (for instance what follows ``#if Debug
374+
then`` in Ada when the preprocessing symbol ``Debug`` is set to ``False``) is
375+
ignored and thus creates no coverage obligation. Note that consolidation will
376+
not help including code from all "preprocessing branches" in coverage reports,
377+
as gnatcov requires (and checks) that coverage obligations are the same for two
378+
units to consolidate.
379+
380+
Ada pecularities
381+
^^^^^^^^^^^^^^^^
382+
383+
The coverage obligations for code that comes from symbol expansion (for
384+
example, ``$Foo = 42`` expanded into ``My_Variable = 42`` with
385+
``-Dfoo=My_Variable``) designate expanded code. Even though line numbers are
386+
preserved during preprocessing, column numbers may be different between the
387+
original code and the preprocessed code and thus the coverage report.
388+
389+
365390
.. _instr-limitations:
366391

367392
|gcvins| limitations
@@ -413,24 +438,24 @@ state. Should the default limit not be satisfactory, it can be tuned with the
413438
option :cmd-option:`--path-count-limit`.
414439

415440
Other source-traces limitations
416-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
441+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
417442

418443
In Ada, variable or type declarations at the package level can yield elaboration
419444
code. Such code constructs are thus considered to have corresponding coverage
420-
obligations
445+
obligations.
421446

422-
In the case where a `pragma Preelaborate` restriction affects the instrumented
423-
unit, variable and type declarations at the package level are not considered as
424-
coverage obligations, although some elaboration code may still be emitted in
425-
rare instances. Note that declarations within a unit constrained by a
426-
``No_Elaboration_Code`` pragma don't produce coverage obligation either, which
427-
is always correct as no executable code can be emitted by the compiler for them.
447+
In the case where a ``pragma Preelaborate`` restriction affects the
448+
instrumented unit, variable and type declarations at the package level are not
449+
considered as coverage obligations, although some elaboration code may still be
450+
emitted in rare instances. Note that declarations within a unit constrained by
451+
a ``No_Elaboration_Code`` pragma don't produce coverage obligation either,
452+
which is always correct as no executable code can be emitted by the compiler
453+
for them.
428454

429455
There are also a few limitations concerning the source trace workflow as a
430456
whole:
431457

432-
- Separate analysis of generic package instances is not supported,
433-
- Preprocessing directives are ignored by the source instrumenter.
458+
- Separate analysis of generic package instances is not supported.
434459

435460
Toolchain-specific limitations
436461
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -686,7 +711,7 @@ Setting up the coverage runtime
686711
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
687712

688713
As seen in the :ref:`instr-rts` section, we use the ``gnatcov setup`` command to
689-
build and install the :term:`coverage runtime <Coverage Runtime>`::
714+
build and install the :term:`coverage runtime <Coverage Runtime>`.
690715

691716
For our intended target environment, this would be something like::
692717

doc/gnatcov/units_of_interest.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ and then executing::
204204
gnatcov <command> --units=@units.list
205205

206206
Conveying *subprograms* of interest
207-
*********************************
207+
***********************************
208208

209209
|gcv| enables even finer grain control through the use of ``--subprograms``
210210
switch, which restricts coverage analysis to the specified list of subprograms

0 commit comments

Comments
 (0)