This file is indexed.

/usr/share/gps/plug-ins/gnatcov.py is in gnat-gps-common 5.3dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
""" This plug-in adds support for GNATcoverage.

This plug-in provides the following:
   * A new Build Mode "gnatcov"
   * Several new project attributes which GPS will
     use to drive various tools in the context of
     GNATcoverage
   * Build targets to launch runs and analyses
   * Menus corresponding to these build targets.

The Build Mode "gnatcov" is listed in the Build Mode
combo, in the main toolbar. Objects generated under
this build mode are generated in a subdirectory "gnatcov"
in all object and executable directories specified by
the project hierarchy.

The following Project Properties are added, which are
available in the "GNATcov" section of the Project
Properties editor, and which map to attributes in a
package "IDE_Coverage" in the project files.

  * Gnatcov_Mode_Switches: switches that GPS will pass
    to the command line used to build while the "gnatcov"
    Build Mode is selected

  * Level_Run: the coverage level to pass to the
    "gnatcov run" command

  * Switches_Run: additional switches to pass to
    the "gnatcov run" command

  * Level_Coverage: the coverage level to pass to
    the "gnatcov coverage" command

  * Switches_Coverage: additional switches to pass
    to the "gnatcov coverage" command

This plugin defines two new build targets, to launch
"gnatcov run" and "gnatcov coverage", automatically
generated for every executable defined in the project
hierarchy, along with menus, under the menu
   Tools->GNATcoverage.

In addition, this plugin automatically loads or refreshes
the Coverage Report in GPS after every call to the
"gnatcov coverage" build target.

With this plugin, the steps to follow for a typical
GNATcoverage session would be:
  1 - switch to the "gnatcov" Build Mode in the toolbar
  2 - build the executable using the standard mechanism
  3 - launch a first run using the menu
      Tools->GNATcoverage->Run under gnatcov
  4 - launch a first analysis using the menu
      Tools->GNATcoverage->Coverage with gnatcov
  5 - edit the code or the test driver, then rerun
      steps 2, 3, 4

Note: this plug-in activates only when the command-line tool
"gnatcov" is found on the PATH.
"""


###########################################################################
## No user customization below this line
###########################################################################

import GPS, os.path, os_utils;

#
# Project support
#

project_support_xml = """

  <project_attribute
    name="Gnatcov_Mode_Switches"
    label="Switches in 'gnatcov' mode"
    package="IDE_Coverage"
    editor_page="GNATcov"
    editor_section="Build"
    hide_in="wizard library_wizard"
    description="Extra build switches to pass to the builder when in 'gnatcov' mode.">
    <string />
  </project_attribute>

  <project_attribute
    name="Level_Run"
    label="Coverage Level"
    package="IDE_Coverage"
    editor_page="GNATcov"
    editor_section="Run"
    hide_in="wizard library_wizard"
    description="The coverage level to pass to gnatcov run.">

      <choice>branch</choice>
      <choice>insn</choice>
      <choice default="true">stmt</choice>
      <choice>stmt+decisison</choice>
      <choice>stmt+mcdc</choice>

  </project_attribute>

  <project_attribute
    name="Switches_Run"
    label="Extra switches"
    package="IDE_Coverage"
    editor_page="GNATcov"
    editor_section="Run"
    hide_in="wizard library_wizard"
    description="Extra build switches to pass to gnatcov run">
    <string />
  </project_attribute>

  <project_attribute
    name="Level_Coverage"
    label="Coverage Level"
    package="IDE_Coverage"
    editor_page="GNATcov"
    editor_section="Coverage"
    hide_in="wizard library_wizard"
    description="The coverage level to pass to gnatcov coverage.">

      <choice>branch</choice>
      <choice>insn</choice>
      <choice default="true">stmt</choice>
      <choice>stmt+decisison</choice>
      <choice>stmt+mcdc</choice>

  </project_attribute>

  <project_attribute
    name="Switches_Coverage"
    label="Extra switches"
    package="IDE_Coverage"
    editor_page="GNATcov"
    editor_section="Coverage"
    hide_in="wizard library_wizard"
    description="Extra build switches to pass to gnatcov coverage">
    <string />
  </project_attribute>
"""

#
# Build targets and modes
#

xml = """

  <!--  Program execution under instrumented execution environment  -->

  <target-model name="gnatcov-run" category="">
    <description>Run under GNATcov for code coverage</description>
    <command-line>
      <arg>gnatcov</arg>
      <arg>run</arg>
    </command-line>
    <icon>gps-build-all</icon>
    <switches command="%(tool_name)s" columns="2" lines="2">
    </switches>
  </target-model>

  <target model="gnatcov-run" category="GNATcov run"
      name="Run under GNATcov"
      @MENU@>
    <target-type>executable</target-type>
    <in-toolbar>FALSE</in-toolbar>
    <in-menu>TRUE</in-menu>
    <read-only>TRUE</read-only>
    <icon>gps-build-all</icon>
    <launch-mode>MANUALLY</launch-mode>
    <command-line>
      <arg>gnatcov</arg>
      <arg>run</arg>
      <arg>-P%PP</arg>
      <arg>--recursive</arg>
      <arg>%target</arg>
      <arg>-c</arg>
      <arg>%attr(ide_coverage'level_coverage,stmt)</arg>
      <arg>-o</arg>
      <arg>%TT.trace</arg>
      <arg>%E</arg>
      <arg>%attr(ide_coverage'switches_run)</arg>
    </command-line>
  </target>

  <!--  Coverage report generation  -->

  <target-model name="gnatcov-coverage" category="">
    <description>Code coverage with GNATcov</description>
    <command-line>
      <arg>gnatcov</arg>
      <arg>coverage</arg>
      <arg>-P%PP</arg>
      <arg>--recursive</arg>
      <arg>%target</arg>
      <arg>--annotate=xcov</arg>
    </command-line>
    <icon>gps-build-all</icon>
    <switches command="%(tool_name)s" columns="1" lines="4">
    </switches>
  </target-model>

  <target model="gnatcov-coverage" category="GNATcov coverage"
          name="Generate GNATcov Main Report"
          @MENU@>
    <target-type>executable</target-type>
    <in-toolbar>FALSE</in-toolbar>
    <in-menu>TRUE</in-menu>
    <read-only>TRUE</read-only>
    <icon>gps-build-all</icon>
    <launch-mode>MANUALLY</launch-mode>
    <command-line>
      <arg>gnatcov</arg>
      <arg>coverage</arg>
      <arg>-P%PP</arg>
      <arg>--recursive</arg>
      <arg>%target</arg>
      <arg>-c</arg>
      <arg>%attr(ide_coverage'level_coverage,stmt)</arg>
      <arg>--annotate=xcov+</arg>
      <arg>--output-dir=%O</arg>
      <arg>-T</arg>
      <arg>%TT.trace</arg>
      <arg>%attr(ide_coverage'switches_coverage)</arg>
    </command-line>
  </target>

  <builder-mode name="gnatcov">
   <description>Build with GNATcoverage information</description>
   <subdir>gnatcov</subdir>
   <supported-model>builder</supported-model>
   <supported-model>gnatmake</supported-model>
   <supported-model>gprbuild</supported-model>
   <supported-model filter="--subdirs=">gnatcov-coverage</supported-model>
   <supported-model filter="--subdirs=">gprclean</supported-model>
   <extra-args>
      <arg>%attr(ide_coverage'gnatcov_mode_switches)</arg>
      <arg>--subdirs=%subdir</arg>
      <arg>-cargs</arg>
      <arg>-g</arg>
      <arg>-fdump-scos</arg>
      <arg>-fpreserve-control-flow</arg>
   </extra-args>
  </builder-mode>


"""

def reload_gnatcov_data():
    """ Clean the coverage report and reload it from the files.
    """
    # Switch to gcov mode
    if GPS.Preference("Coverage-Toolchain").get() != 'Gnatcov':
        GPS.Preference("Coverage-Toolchain").set('Gnatcov')

    GPS.execute_action("/Tools/Coverage/Clear coverage from memory")
    GPS.execute_action("/Tools/Coverage/Load data for all projects")

def on_gps_started (hook_name):
    """ Called once, when GPS is starting.
    """
    global gnatcov_menu_separator

    if os_utils.locate_exec_on_path ("gnatcov") != "":
        GPS.Hook("compilation_finished").add(on_compilation_finished)

        menu = "/Tools/GNATcov/"
        ref  = "Coverage"
        gnatcov_menu = GPS.Menu.create(menu + '-', ref=ref, add_before=False)

        GPS.parse_xml(xml.replace("@MENU@", 'menu="%s"' % menu))

def on_compilation_finished(hook, category,
    target_name="", mode_name="", status=""):
    """ Called whenever a compilation ends.
    """

    if status:
        return

    if target_name in ["Generate GNATcov Main Report"]:
        reload_gnatcov_data()

GPS.parse_xml (project_support_xml)

GPS.Hook ("gps_started").add (on_gps_started)