This file is indexed.

/usr/share/doc/libgnatcoll-doc/html/xref.html is in libgnatcoll-doc 17.0.2017-3.

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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>25. Xref: Cross-referencing source code &#8212; GNATColl 2017 documentation</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2017',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/favicon.ico"/>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="27. Terminal: controlling the console" href="terminals.html" />
    <link rel="prev" title="24. SQL: Database interface" href="sql.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="terminals.html" title="27. Terminal: controlling the console"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="sql.html" title="24. SQL: Database interface"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">GNATColl 2017 documentation</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/adacore_transparent.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">25. <strong>Xref</strong>: Cross-referencing source code</a></li>
<li><a class="reference internal" href="#xref-gnatinspect">26. <strong>Xref</strong>: gnatinspect</a></li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="sql.html"
                        title="previous chapter">24. <strong>SQL</strong>: Database interface</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="terminals.html"
                        title="next chapter">27. <strong>Terminal</strong>: controlling the console</a></p>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="xref-cross-referencing-source-code">
<span id="xref"></span><h1>25. <strong>Xref</strong>: Cross-referencing source code<a class="headerlink" href="#xref-cross-referencing-source-code" title="Permalink to this headline"></a></h1>
<p>When manipulating source code, programmers needs to know where the various
symbols are defined, where they are used, and so on. This is generally
available directly from their IDE and editors. But computing this information
in the first place is tricky, especially for languages that support
overloading of subprograms.</p>
<p>Some compilers like GNAT and gcc can generate this information for Ada
code bases. For instance, GNAT will generate <code class="file docutils literal"><span class="pre">.ali</span></code> files, which
contain the navigation information, when compiling Ada or SPARK code.</p>
<p><code class="file docutils literal"><span class="pre">GNATCOLL.Xref</span></code> can then be used to parse and aggregate all those
files into a single sqlite database, which can be conveniently used to
answer queries such as &#8220;give me the declaration for this entity&#8221;, &#8220;list all
places where this entity is used&#8221;, &#8220;show all subprograms that could be called
in practice at this dispatching call&#8221;, &#8220;what files does this file depend on&#8221;,
&#8220;show me the call graph for this application&#8221;,...</p>
<p>To use this package, some initialization needs to be performed first:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="kn">with</span> <span class="nn">GNATCOLL.Xref</span><span class="p">;</span>     <span class="kn">use</span> <span class="nn">GNATCOLL.Xref</span><span class="p">;</span>
<span class="kn">with</span> <span class="nn">GNATCOLL.SQL.Sqlite</span><span class="p">;</span>
<span class="kn">with</span> <span class="nn">GNATCOLL.Projects</span><span class="p">;</span> <span class="kn">use</span> <span class="nn">GNATCOLL.Projects</span><span class="p">;</span>   <span class="c1">--  1</span>
<span class="kn">with</span> <span class="nn">GNATCOLL.VFS</span><span class="p">;</span>      <span class="kn">use</span> <span class="nn">GNATCOLL.VFS</span><span class="p">;</span>
<span class="kn">with</span> <span class="nn">GNAT.Strings</span><span class="p">;</span>

<span class="kd">procedure</span> <span class="nf">Support</span> <span class="kr">is</span>
   <span class="n">DB</span> <span class="p">:</span> <span class="n">Xref_Database</span><span class="p">;</span>
   <span class="n">Tree</span> <span class="p">:</span> <span class="n">Project_Tree_Access</span> <span class="p">:=</span> <span class="kr">new</span> <span class="n">Project_Tree</span><span class="p">;</span>
   <span class="n">Error</span> <span class="p">:</span> <span class="n">GNAT</span><span class="p">.</span><span class="n">Strings</span><span class="p">.</span><span class="n">String_Access</span><span class="p">;</span>

<span class="kr">begin</span>
   <span class="n">Tree</span><span class="p">.</span><span class="n">Load</span> <span class="p">(</span><span class="n">Create</span> <span class="p">(</span><span class="s">&quot;prj.gpr&quot;</span><span class="p">));</span>  <span class="c1">--  2</span>
   <span class="n">Setup_DB</span>
      <span class="p">(</span><span class="n">DB</span><span class="p">,</span> <span class="n">Tree</span><span class="p">,</span>
       <span class="n">GNATCOLL</span><span class="p">.</span><span class="n">SQL</span><span class="p">.</span><span class="n">Sqlite</span><span class="p">.</span><span class="n">Setup</span> <span class="p">(</span><span class="n">Database</span> <span class="p">=&gt;</span> <span class="s">&quot;testdb.db&quot;</span><span class="p">),</span>
       <span class="n">Error</span><span class="p">);</span>  <span class="c1">-- 3</span>
   <span class="n">Free</span> <span class="p">(</span><span class="n">Error</span><span class="p">);</span>
   <span class="n">Parse_All_LI_Files</span> <span class="p">(</span><span class="n">DB</span><span class="p">,</span> <span class="n">Tree</span><span class="p">.</span><span class="n">Root_Project</span><span class="p">);</span>   <span class="c1">--  4</span>
<span class="kr">end</span> <span class="nf">Support</span><span class="p">;</span>
</pre></div>
</div>
<p>GNATCOLL needs to be able to find the <code class="file docutils literal"><span class="pre">*li</span></code> files. For this, it depends
on project files (as supported by <code class="file docutils literal"><span class="pre">GNATCOLL.Projects</span></code>). So the first
thing to do is to parse the project (step 2).</p>
<p>We then need to tell GNATCOLL where the cross-reference information need to be
aggregated. In this example, it will be stored in a sqlite database on the disk.
By using a name &#8221;:memory:&#8221; instead, we would create a temporary in-memory
database. This is in general faster, but uses more memory and needs to be
recreated every time the program is restarted. We could also decide to store
the information in any other database supported by <code class="file docutils literal"><span class="pre">GNATCOLL.SQL.Exec</span></code>,
for instance PostgreSQL.</p>
<p>Finally, in step 4 we let GNATCOLL parse all the <code class="file docutils literal"><span class="pre">*li</span></code> files that are
relevant for this project. This operation can take a while, depending on the
size of the project. However, if the database already exists on the disk, it
will simply be updated by parsing the files that are not already up-to-date.
When all files are up-to-date, this operation is almost immediate.</p>
<p>At this point, we now have a database that we can start querying. Here are
a few examples, but see the documentation <code class="file docutils literal"><span class="pre">gnatcoll-xref.ads</span></code> for more
types of queries. All these queries have a similar API: they return a
<strong>cursor</strong> which iterates over the result returned by a SQL query. There are
various kinds of cursors, depending on whether they return files, entities,
or references to entities. But they all support the <cite>Has_Element</cite>, <cite>Element</cite>
and <cite>Next</cite> operations, so all loops will look similar:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="kr">pragma</span> <span class="cp">Ada_05</span><span class="p">;</span>   <span class="c1">--  use object-dotted-notation</span>
<span class="kn">with</span> <span class="nn">GNATCOLL.VFS</span><span class="p">;</span>   <span class="kn">use</span> <span class="nn">GNATCOLL.VFS</span><span class="p">;</span>

<span class="kr">declare</span>
    <span class="n">Entity</span> <span class="p">:</span> <span class="n">Entity_Information</span><span class="p">;</span>
    <span class="n">Ref</span>    <span class="p">:</span> <span class="n">Entity_Reference</span><span class="p">;</span>
    <span class="n">File</span>   <span class="p">:</span> <span class="n">Virtual_File</span><span class="p">;</span>
    <span class="n">Refs</span>   <span class="p">:</span> <span class="n">References_Cursor</span><span class="p">;</span>
<span class="kr">begin</span>
    <span class="n">File</span> <span class="p">:=</span> <span class="n">Tree</span><span class="p">.</span><span class="n">Create</span> <span class="p">(</span><span class="s">&quot;source.ads&quot;</span><span class="p">);</span>   <span class="c1">--  5</span>
    <span class="n">Ref</span> <span class="p">:=</span> <span class="n">DB</span><span class="p">.</span><span class="n">Get_Entity</span> <span class="p">(</span><span class="s">&quot;Method&quot;</span><span class="p">,</span> <span class="n">File</span><span class="p">,</span> <span class="n">Line</span> <span class="p">=&gt;</span> <span class="mi">2</span><span class="p">);</span>   <span class="c1">--  6</span>
    <span class="n">Entity</span> <span class="p">:=</span> <span class="n">Ref</span><span class="p">.</span><span class="n">Entity</span><span class="p">;</span>

    <span class="n">DB</span><span class="p">.</span><span class="n">References</span> <span class="p">(</span><span class="n">Entity</span><span class="p">,</span> <span class="n">Refs</span><span class="p">);</span>   <span class="c1">--  7</span>
    <span class="kr">while</span> <span class="n">Refs</span><span class="p">.</span><span class="n">Has_Element</span> <span class="kr">loop</span>
       <span class="n">Ref</span> <span class="p">:=</span> <span class="n">Refs</span><span class="p">.</span><span class="n">Element</span><span class="p">;</span>
       <span class="n">Put_Line</span> <span class="p">(</span><span class="s">&quot; at &quot;</span> <span class="o">&amp;</span> <span class="n">Ref</span><span class="p">.</span><span class="n">File</span><span class="p">.</span><span class="n">Display_Full_Name</span> <span class="o">&amp;</span> <span class="s s-Character">&#39;:&#39;</span>
          <span class="o">&amp;</span> <span class="n">Ref</span><span class="p">.</span><span class="n">Line</span><span class="p">&#39;</span><span class="na">Img</span> <span class="o">&amp;</span> <span class="s s-Character">&#39;:&#39;</span> <span class="o">&amp;</span> <span class="n">Ref</span><span class="p">.</span><span class="n">Column</span><span class="p">&#39;</span><span class="na">Img</span><span class="p">);</span>
       <span class="n">Refs</span><span class="p">.</span><span class="n">Next</span><span class="p">;</span>
    <span class="kr">end</span> <span class="kr">loop</span><span class="p">;</span>
<span class="kr">end</span><span class="p">;</span>
</pre></div>
</div>
<p>This example will print all the references to the entity that is referenced
in file source.ads at line 2 (the column is unspecified).</p>
<p>Step 5 gets a handle on the source file. Here, we depend on the project to
find the precise directory in which the source file is located.
We can of course use an absolute file name instead.</p>
<p>Step 6 gets handle on the entity referenced on line 2 in this file. Such an
entity is the starting point for most queries defined in <cite>GNATCOLL.Xref</cite>.</p>
<p>Finally, on step 7 and the loop below we iterate over all references, and
print their location on the standard output.</p>
<p>Let&#8217;s do a much more complex query: we want to see all references to that
entity, but also places where the entity might be called through a <cite>renames</cite>
statement, or called through a dispatching call via an overriding method
defined on a child tagged type (assuming this is a primitive operation of
a tagged type in the first place). We also want to see all locations
where a method that overrides &#8220;Method&#8221; is called:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="kr">declare</span>
   <span class="n">Refs</span> <span class="p">:</span> <span class="n">Recursive_References_Cursor</span><span class="p">;</span>
<span class="kr">begin</span>
   <span class="n">DB</span><span class="p">.</span><span class="n">Recursive</span> <span class="p">(</span><span class="n">Entity</span><span class="p">,</span> <span class="n">GNATCOLL</span><span class="p">.</span><span class="n">Xref</span><span class="p">.</span><span class="n">References</span><span class="p">&#39;</span><span class="na">Access</span><span class="p">,</span>
                 <span class="n">From_Overriding</span> <span class="p">=&gt;</span> <span class="kc">True</span><span class="p">,</span> <span class="n">From_Overridden</span> <span class="p">=&gt;</span> <span class="kc">True</span><span class="p">,</span>
                 <span class="n">From_Renames</span> <span class="p">=&gt;</span> <span class="kc">True</span><span class="p">);</span>
   <span class="kr">while</span> <span class="n">Refs</span><span class="p">.</span><span class="n">Has_Element</span> <span class="kr">loop</span>
        <span class="p">...</span> <span class="n">same</span> <span class="n">as</span> <span class="n">before</span>
        <span class="n">Refs</span><span class="p">.</span><span class="n">Next</span><span class="p">;</span>
   <span class="kr">end</span> <span class="kr">loop</span><span class="p">;</span>
<span class="kr">end</span><span class="p">;</span>
</pre></div>
</div>
<p>As shown above, the programing pattern is always the same.</p>
<p>GNATCOLL.Xref provides many more subprogram to get information like the list
of fields for a record type (or a C structure), the list of primitive operations
or methods for a tagged object or a class, the call graph for a subprogram,...</p>
<p>It is also able to extract documentation for an entity from the source code, by
looking at the lines of code just before or just after the declaration or the
body of the entity.</p>
</div>
<div class="section" id="xref-gnatinspect">
<h1>26. <strong>Xref</strong>: gnatinspect<a class="headerlink" href="#xref-gnatinspect" title="Permalink to this headline"></a></h1>
<p>As discussed in the previous section, GNATCOLL provides an Ada API to
perform cross-references queries.</p>
<p>There exist a few alternatives when you want to reuse that cross-reference
information from other tools, or command line scripts.</p>
<p>You can of course access the sqlite database directly. Most programming
languages have an interface to sqlite. For instance python does.</p>
<p>But GNATCOLL provides a command line tool dedicated to that purpose, named
<strong>gnatinspect</strong>.</p>
<p>When it is first started on a project, this tool will refresh the xref
database by parsing all the ALI files from the project. This might take
a while (up to several minutes) the first time, unless of course the
xref were already up-to-date because you had loaded the project in GPS
first, or already run gnatinspect.</p>
<p>gnatinspect then displays an interactive prompt that lets you perform
various queries on the database. The full list of queries is available
by typing &#8220;help&#8221; at the prompt, but this documentation will demonstrate
some of them.</p>
<p>Let&#8217;s first look at a number of command line switches that might be
useful:</p>
<ul>
<li><p class="first"><em>&#8211;db=ARG</em>: this switch can be used to specify the name of the database.</p>
<p>By default, gnatinspect checks in the project whether there exists an
attribute IDE&#8217;Xref_Database, which should specify a file name (relative to
the project&#8217;s object_dir) for the database.</p>
<p>If this attribute does not exist, it defaults to &#8220;gnatinspect.db&#8221; in
the project&#8217;s object directory.</p>
<p>If there is no object directory defined in the project, the file is created
in the project&#8217;s directory itself.  You can however specify any name,
including an absolute path, or a path relative to the project&#8217;s object
directory.</p>
<p>An alternative is to specify &#8216;:memory:&#8217;, which creates the database in
memory. This is of course a temporary database which will disappear when
gnatinspect exits, and cannot be shared with other tools.</p>
</li>
<li><p class="first"><em>&#8211;nightlydb=ARG</em>: this switch can help speed up the initial startup
of gnatinspect. The idea is that in a lot of cases, the software on which
a team works is build nightly in a common setup. Running gnatinspect in
that setup will create or update an xref database.
Individual developers can then create their own copy of the database by
starting from the contents of the nightly database (which is pointed to
by the &#8211;nightlydb switch), and then gnatinspect will parse the ALI files
in the user&#8217;s setup that are different from the nightly ones.</p>
</li>
<li><p class="first"><em>&#8211;runtime</em>: by default, gnatinspect will only parse the ALI files from
your project (and of course the ones from imported projects). It will not
however parse the ALI files found in predefined directories, like for
instance the GNAT runtime. This saves time in general. If you click on
a call to one of the runtime subprograms in your own code, gnatinspect
will be able to point you to its declaration. However, you will not have
access to the body, because the link from declaration to body is found in
the ALI files of the runtime.</p>
</li>
<li><p class="first"><em>&#8211;command=ARG</em>: gnatinspect will update the xref database as usual, then
execute a command, display its result, and exit. This can be convenient
when calling gnatinspect from another tool, like Emacs or vi.</p>
</li>
<li><p class="first"><em>&#8211;file=ARG</em>: similar to &#8211;command, but reads the commands to execute from
a file. The file can contain comments (starting with &#8216;&#8211;&#8217;. See also the
&#8211;lead switch.</p>
</li>
<li><p class="first"><em>&#8211;lang=LANG:SPEC:BODY:OBJ</em>: specifies a naming scheme for a language. The
preferred approach is to use a configuration project file (such as those
generated by gprconfig for instance), that would define attributes such as
<cite>Naming&#8217;Spec_Suffix</cite>, <cite>Naming&#8217;Body_Suffix</cite> and
<cite>Compiler&#8217;Object_File_Suffix</cite>. However, this switch provides an alternative
whereby you can specify the same values directly on the command line. For
instance, the equivalent of:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="n">configuration</span> <span class="n">project</span> <span class="n">Autoconf</span> <span class="kr">is</span>
   <span class="kd">package</span> <span class="nc">Naming</span> <span class="kr">is</span>
      <span class="kr">for</span> <span class="n">Spec_Suffix</span> <span class="p">(</span><span class="s">&quot;MyLang&quot;</span><span class="p">)</span> <span class="kn">use</span> <span class="s">&quot;.myl&quot;</span><span class="p">;</span>
   <span class="kr">end</span> <span class="nf">Naming</span><span class="p">;</span>
   <span class="kd">package</span> <span class="nc">Compiler</span> <span class="kr">is</span>
      <span class="kr">for</span> <span class="n">Object_File_Suffix</span> <span class="p">(</span><span class="s">&quot;MyLang&quot;</span><span class="p">)</span> <span class="kn">use</span> <span class="s">&quot;.ali&quot;</span><span class="p">;</span>
   <span class="kr">end</span> <span class="nf">Compiler</span><span class="p">;</span>
<span class="kr">end</span> <span class="nf">Autoconf</span><span class="p">;</span>
</pre></div>
</div>
<p>is to use:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="c1">--lang=MyLang:.myl::.ali</span>
</pre></div>
</div>
<p>A third alternative is to have the same contents as the configuration
project file above, directly in your own project file. This has the same
effect, but needs to be duplicated in each of your project file.</p>
<p>Given one of the above, and assuming your project file includes:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="kr">for</span> <span class="n">Languages</span> <span class="kn">use</span> <span class="p">(</span><span class="s">&quot;Ada&quot;</span><span class="p">,</span> <span class="s">&quot;MyLang&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>then any file with the <code class="file docutils literal"><span class="pre">.myl</span></code> extension will be correctly detected
by the project manager, and any <code class="file docutils literal"><span class="pre">.ali</span></code> file with the same base name
will be parsed by gnatinspect to find cross-reference information.
Remember that the switch <cite>&#8211;config=autoconf.cgpr</cite> must be passed to
gnatinspect if the information is provided via a config project file.</p>
</li>
<li><p class="first"><em>&#8211;lead=ARG</em> should be used in coordination with &#8211;file, and specify lines
to ignore from the file. All lines starting with the given prefix will be
ignored.</p>
</li>
<li><p class="first"><em>&#8211;basenames</em>: controls the display of file names in the output. By default,
gnatinspect outputs full path information.</p>
</li>
<li><p class="first"><em>&#8211;exit</em>: if this switch is specified, gnatinspect updates the xref database
and exits immediately.</p>
</li>
<li><p class="first"><em>&#8211;project=ARG</em> or <em>-P ARG</em> specifes the name of the project to load. This
switch is mandatory.</p>
</li>
<li><p class="first"><em>-X VAR=VALUE</em> is used to specify the value of scenario variables used in
your project. This is similar to the homonym switch in gprbuild.</p>
</li>
<li><p class="first"><em>&#8211;symlinks</em> should be specified if your projet uses symbolic links for
files. This will ensure that the links are fully resolved as stored in the
database, and thus that when a file is visible through different links, the
information is appropriately coalesced in the database for that file.</p>
</li>
<li><p class="first"><em>&#8211;subdirs=ARG</em> is similar to the homonym switch in gprbuild</p>
</li>
<li><p class="first"><em>&#8211;tracefile=ARG</em> is used to point to a file compatible with GNATCOLL.Traces
that controls the debug information generated by gnatinspect. By default,
gnatinspect parses a file called &#8216;.gnatdebug&#8217; in the current directory.</p>
</li>
<li><p class="first"><em>&#8211;encoding=ARG</em> is the character encoding used for source and ALI files.
By default, gnatinspect assumes they are encoded in UTF-8.</p>
</li>
</ul>
<p>Once it has finished parsing the xref information, gnatinspect displays an
interactive prompt, where a number of commands can be used to perform
queries. In a lot of cases, these commands take some file information as
argument (either just the file, or an entity name and the file in which it
is defined).</p>
<p id="index-0">The file names can be given as either a base name, or relative to the current
directory, or even a full name.  But file names are ambiguous (even when a full
path is specified) when aggregate projects are used. It is valid for a given
file to be part of multiple aggregate projects, and depending on the project we
are considering the result of the xref queries might vary).</p>
<p>To remove the ambiguity, it is possible to specify the project to which the
file belongs. The project is specified either as a project name (which itself
could be ambiguous with aggregate projects), or as a full path.</p>
<p>In all commands below, whenever the parameter specifies &#8221;:file&#8221;, you can
use instead &#8221;:<a class="reference external" href="file:project">file:project</a>&#8221; if there are ambiguities. It is also possible
not to specify the file, in which case the entity will be looked for in all
sources of the project.</p>
<p>Here is the full list of commands supported by gnatinspect:</p>
<ul>
<li><p class="first"><em>decl name:file:line:column</em> is probably the most useful command. Given a
reference to an entity, it will indicate where the entity is declared. The
line and column informations are optional:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="n">decl</span> <span class="n">Func</span><span class="p">:</span><span class="n">file</span><span class="p">.</span><span class="n">adb</span><span class="p">:</span><span class="mi">12</span>
<span class="n">Func</span><span class="p">:</span><span class="o">/</span><span class="n">some</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">file2</span><span class="p">.</span><span class="n">adb</span><span class="p">:</span><span class="mi">20</span><span class="p">:</span><span class="mi">9</span>
</pre></div>
</div>
</li>
<li><p class="first"><em>body name:file:line:column</em> is similar to <em>decl</em>, but will return the
location of the body of the entity. When the entity is an Ada private type,
its body is in fact the location of the full declaration for that type.</p>
</li>
<li><p class="first"><em>refs name:file:line:column</em> displays all known references to the entity.</p>
</li>
<li><p class="first"><em>refs_overriding name:file:line:column</em> displays all known references to the
entity or one of its overriding entities</p>
</li>
<li><p class="first"><em>doc name:file:line:column</em> will display documentation for the entity. The
exact format for the entity might change in future versions of gnatinspect,
but will in general include the type of entity, the location of its
declaration, and any comment associated with it in the source code:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="n">doc</span> <span class="n">Func</span><span class="p">:</span><span class="n">file</span><span class="p">.</span><span class="n">adb</span>
<span class="kd">procedure</span> <span class="nf">declared</span> <span class="nf">at</span> <span class="o">/</span><span class="nf">some</span><span class="o">/</span><span class="nf">path</span><span class="o">/</span><span class="nf">file2</span><span class="p">.</span><span class="nf">adb</span><span class="p">:</span><span class="nf">20</span><span class="p">:</span><span class="nf">9</span>

<span class="nf">And</span> <span class="nf">the</span> <span class="nf">comments</span> <span class="nf">written</span> <span class="nf">below</span> <span class="nf">Func</span> <span class="nf">in</span> <span class="nf">file2</span><span class="p">.</span><span class="nf">adb</span>
</pre></div>
</div>
</li>
<li><p class="first"><em>fields name:file:line:column</em> displays the fields of an Ada record type
or a C struct:</p>
<div class="highlight-ada"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;&gt;</span> <span class="n">fields</span> <span class="n">Rec</span><span class="p">:</span><span class="n">file</span><span class="p">.</span><span class="n">ads</span><span class="p">:</span><span class="mi">20</span>
<span class="n">A</span><span class="p">:</span><span class="o">/</span><span class="n">some</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">file</span><span class="p">.</span><span class="n">ads</span><span class="p">:</span><span class="mi">21</span>
<span class="n">B</span><span class="p">:</span><span class="o">/</span><span class="n">some</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">file</span><span class="p">.</span><span class="n">ads</span><span class="p">:</span><span class="mi">22</span>
</pre></div>
</div>
</li>
<li><p class="first"><em>child_types name:file:line:column</em> lists all child types for this entity,
for instance classes that inherit from the entity. This is the opposite of
<em>parent_types</em>.</p>
</li>
<li><p class="first"><em>child_types_recursive name:file:line:column</em> is similar to <em>child_types</em>
but will also list the child types of the children. This query can be used
to find a whole tagged type hierarchy (or class hierarchy in C++).</p>
</li>
<li><p class="first"><em>parent_types name:file:lin:column</em> returns the parent types for the entity,
for instance the classes or interfaces from which it derives. See also
<em>child_types</em>.</p>
</li>
<li><p class="first"><em>methods name:file:line:column</em> returns the list of methods (or primitive
operations) for the entity.</p>
</li>
<li><p class="first"><em>method_of name:file:line:column</em> returns the class or tagged type for
which the entity is a method.</p>
</li>
<li><p class="first"><em>calls name:file:line:column</em> lists all entities called by the entity. This
includes all entities defined within the scope of the entity (so for a
subprogram this will be the list of local variables, but for a package
this includes all subprograms and nested packages defined within that
package).</p>
</li>
<li><p class="first"><em>callers name:file:line:column</em> lists all entities that call the entity. This
information is also available from a call to &#8216;refs&#8217;, but &#8216;callers&#8217; return the
callers directly, instead of references to the original entity.</p>
</li>
<li><p class="first"><em>overrides name:file:line:column</em> returns the entity that is overridden by
the entity (generally a method from a parent class).</p>
</li>
<li><p class="first"><em>overridden name:file:line:column</em> returns the list of entities that override
the parameter (generally methods from children classes).</p>
</li>
<li><p class="first"><em>overridden_recursive name:file:line:column</em> returns the list of entities
that override the parameter (generally methods from children classes). This is
recursive.</p>
</li>
<li><p class="first"><em>type name:file:line:column</em> returns the type of the entity (variable or
constant). For an enumeration literal, this returns the corresponding
enumeration.</p>
</li>
<li><p class="first"><em>component name:file:line:column</em> returns the component type of the entity
(for arrays for instance).</p>
</li>
<li><p class="first"><em>literals name:file:line:column</em> returns the valid literal values for an
enumeration.</p>
</li>
<li><p class="first"><em>pointed name:file:line:column</em> returns the type pointed to by the entity.</p>
</li>
<li><p class="first"><em>qname name:file:line:column</em> returns the fully qualified name for the
entity.</p>
</li>
<li><p class="first"><em>params name:file:line:column</em> returns the list of parameters for the
subprogram.</p>
</li>
</ul>
<p>A number of queries are related to the source files of the project:</p>
<ul class="simple">
<li><em>importing filename</em> lists the files that import the file (via with
statements in Ada or #include in C for instance)</li>
<li><em>imports filename</em> lists the files that the file imports (via with statements
in Ada or #include in C for instance). See also <em>depends_on</em>.</li>
<li><em>depends filename</em> lists the files that the file depends on (recursively
calling <em>imports</em>)</li>
<li><em>entities file</em> lists all entities referenced or declared in the file.</li>
</ul>
<p>Finally, some commands are not related to entities or source files:</p>
<ul class="simple">
<li><em>refresh</em> refreshes the contents of the xref database, by parsing all ALI
files that have been changed.</li>
<li><em>shell</em> Execute a shell command (an alternative is to use &#8216;!&#8217; as the
command).</li>
<li><em>scenario VARIABLE VALUE</em> changes the value of a scenario variable, and
reparse the project.</li>
<li><em>time command arguments</em> executes the command as usual, and report the time
it took to execute it.</li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="terminals.html" title="27. Terminal: controlling the console"
             >next</a> |</li>
        <li class="right" >
          <a href="sql.html" title="24. SQL: Database interface"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">GNATColl 2017 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2007-2017, AdaCore.
    </div>
  </body>
</html>