home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-docs.zip / gnat_ug_unx.INF (.txt) < prev   
OS/2 Help File  |  2001-09-16  |  284KB  |  9,420 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. -Preface- ΓòÉΓòÉΓòÉ
  3.  
  4.  
  5. ΓòÉΓòÉΓòÉ 2. GNAT User's Guide ΓòÉΓòÉΓòÉ
  6.  
  7.  GNAT User's Guide 
  8.  
  9.  GNAT, The GNU Ada 95 Compiler 
  10.  
  11.  GNAT Version 3.13p 
  12.  
  13.  Date: 2000/05/16 02:37:19 
  14.  
  15.  Ada Core Technologies, Inc. 
  16.  
  17.  (C) Copyright 1995-2000, Ada Core Technologies, Inc. 
  18.  
  19.  Permission is granted to make and distribute verbatim copies of this manual 
  20.  provided the copyright notice and this permission notice are preserved on all 
  21.  copies. 
  22.  
  23.  Silicon Graphics and IRIS are registered trademarks and IRIX is a trademark of 
  24.  Silicon Graphics, Inc. 
  25.  
  26.  IBM PC is a trademark of International Business Machines Corporation. 
  27.  
  28.  UNIX is a registered trademark of AT&T Bell Laboratories. 
  29.  
  30.  The following are trademarks of Compaq Computers: DEC, DEC Ada, DECthreads, 
  31.  DIGITAL, DECset, OpenVMS, and VAX. 
  32.  
  33.  The following are trademarks of Microsoft Corporation: Windows NT, Windows 95, 
  34.  Windows 98. 
  35.  
  36.  The following are trademarks of Wind River Systems: VxWorks, Tornado. 
  37.  
  38.  About This Guide              About This Guide 
  39.  Getting Started With GNAT     Getting Started With GNAT 
  40.  The GNAT Compilation Model    The GNAT Compilation Model 
  41.  Compiling Using gcc           Compiling Using gcc 
  42.  Binding Using gnatbind        Binding Using gnatbind 
  43.  Linking Using gnatlink        Linking Using gnatlink 
  44.  The GNAT Make Program gnatmakeThe GNAT Make Program gnatmake 
  45.  Renaming Files Using gnatchop Renaming Files Using gnatchop 
  46.  Configuration Pragmas         Configuration Pragmas 
  47.  Elaboration Order Handling in GNATElaboration Order Handling in GNAT 
  48.  The cross-referencing tools gnatxref and gnatfindThe cross-referencing tools 
  49.                                gnatxref and gnatfind 
  50.  File Name Krunching Using gnatkrFile Name Krunching Using gnatkr 
  51.  Preprocessing Using gnatprep  Preprocessing Using gnatprep 
  52.  The GNAT library browser gnatlsThe GNAT library browser gnatls 
  53.  GNAT and libraries            GNAT and libraries 
  54.  Using the GNU make utility    Using the GNU make utility 
  55.  Finding memory problems with gnatmemFinding memory problems with gnatmem 
  56.  Finding memory problems with GNAT Debug PoolFinding memory problems with GNAT 
  57.                                Debug Pool 
  58.  Creating Sample Bodies Using gnatstubCreating Sample Bodies Using gnatstub 
  59.  Reducing the Size of Ada Executables with gnatelimReducing the Size of Ada 
  60.                                Executables with gnatelim 
  61.  Other Utility Programs        Other Utility Programs 
  62.  Running and Debugging Ada ProgramsRunning and Debugging Ada Programs 
  63.  Performance Considerations    Performance Considerations 
  64.  Index                         Index  About This Guide 
  65.  What This Guide Contains      What This Guide Contains 
  66.  What You Should Know Before Reading This GuideWhat You Should Know Before 
  67.                                Reading This Guide 
  68.  Related Information           Related Information 
  69.  Conventions                   Conventions  Getting Started With GNAT 
  70.  Running GNAT                  Running GNAT 
  71.  Running a Simple Ada Program  Running a Simple Ada Program 
  72.  Running a Program With Multiple UnitsRunning a Program With Multiple Units 
  73.  Using the gnatmake Utility    Using the gnatmake Utility The GNAT Compilation 
  74.                                Model 
  75.  Source Representation         Source Representation 
  76.  Foreign Language RepresentationForeign Language Representation 
  77.  File Naming Rules             File Naming Rules 
  78.  Using Other File Names        Using Other File Names 
  79.  Generating Object Files       Generating Object Files 
  80.  Source Dependencies           Source Dependencies 
  81.  The Ada Library Information FilesThe Ada Library Information Files 
  82.  Representation of Time Stamps Representation of Time Stamps 
  83.  Binding an Ada Program        Binding an Ada Program 
  84.  Mixed Language Programming    Mixed Language Programming 
  85.  Building mixed Ada & C++ programsBuilding mixed Ada & C++ programs 
  86.  Comparison between GNAT and C/C++ Compilation ModelsComparison between GNAT 
  87.                                and C/C++ Compilation Models 
  88.  Comparison between GNAT and Conventional Ada Library ModelsComparison between 
  89.                                GNAT and Conventional Ada Library Models Foreign 
  90.                                Language Representation 
  91.  Latin-1                       Latin-1 
  92.  Other 8-Bit Codes             Other 8-Bit Codes 
  93.  Wide Character Encodings      Wide Character Encodings Compiling Ada Programs 
  94.                                With gcc 
  95.  Compiling Programs            Compiling Programs 
  96.  Switches for gcc              Switches for gcc 
  97.  Search Paths and the Run-Time Library (RTL)Search Paths and the Run-Time 
  98.                                Library (RTL) 
  99.  Order of Compilation Issues   Order of Compilation Issues 
  100.  Examples                      Examples Switches for gcc 
  101.  Output and Error Message ControlOutput and Error Message Control 
  102.  Debugging and Assertion ControlDebugging and Assertion Control 
  103.  Run-time Checks               Run-time Checks 
  104.  Stack Overflow Checking       Stack Overflow Checking 
  105.  Run-time Control              Run-time Control 
  106.  Style Checking                Style Checking 
  107.  Using gcc for Syntax Checking Using gcc for Syntax Checking 
  108.  Using gcc for Semantic CheckingUsing gcc for Semantic Checking 
  109.  Compiling Ada 83 Programs     Compiling Ada 83 Programs 
  110.  Reference Manual Style CheckingReference Manual Style Checking 
  111.  Character Set Control         Character Set Control 
  112.  File Naming Control           File Naming Control 
  113.  Subprogram Inlining Control   Subprogram Inlining Control 
  114.  Auxiliary Output Control      Auxiliary Output Control 
  115.  Debugging Control             Debugging Control Binding Ada Programs With 
  116.                                gnatbind 
  117.  Running gnatbind              Running gnatbind 
  118.  Generating The Binder Program in CGenerating The Binder Program in C 
  119.  Consistency-Checking Modes    Consistency-Checking Modes 
  120.  Binder Error Message Control  Binder Error Message Control 
  121.  Elaboration Control           Elaboration Control 
  122.  Output Control                Output Control 
  123.  Binding with Non-Ada Main ProgramsBinding with Non-Ada Main Programs 
  124.  Binding Programs with no Main SubprogramBinding Programs with no Main 
  125.                                Subprogram 
  126.  Summary of Binder Switches    Summary of Binder Switches 
  127.  Command-Line Access           Command-Line Access 
  128.  Search Paths for gnatbind     Search Paths for gnatbind 
  129.  Examples of gnatbind Usage    Examples of gnatbind Usage Linking Using 
  130.                                gnatlink 
  131.  Running gnatlink              Running gnatlink 
  132.  Switches for gnatlink         Switches for gnatlink The GNAT Make Program 
  133.                                gnatmake 
  134.  Running gnatmake              Running gnatmake 
  135.  Switches for gnatmake         Switches for gnatmake 
  136.  Mode switches for gnatmake    Mode switches for gnatmake 
  137.  Notes on the Command Line     Notes on the Command Line 
  138.  How gnatmake Works            How gnatmake Works 
  139.  Examples of gnatmake Usage    Examples of gnatmake Usage Renaming Files Using 
  140.                                gnatchop 
  141.  Handling Files with Multiple UnitsHandling Files with Multiple Units 
  142.  Operating gnatchop in Compilation ModeOperating gnatchop in Compilation Mode 
  143.  Command Line for gnatchop     Command Line for gnatchop 
  144.  Switches for gnatchop         Switches for gnatchop 
  145.  Examples of gnatchop Usage    Examples of gnatchop Usage Configuration Pragmas 
  146.  Handling of Configuration PragmasHandling of Configuration Pragmas 
  147.  The Configuration Pragmas fileThe Configuration Pragmas file Elaboration Order 
  148.                                Handling in GNAT 
  149.  Elaboration Code in Ada 95    Elaboration Code in Ada 95 
  150.  Checking the Elaboration Order in Ada 95Checking the Elaboration Order in Ada 
  151.                                95 
  152.  Controlling the Elaboration Order in Ada 95Controlling the Elaboration Order 
  153.                                in Ada 95 
  154.  Controlling Elaboration in GNAT - Internal CallsControlling Elaboration in 
  155.                                GNAT - Internal Calls 
  156.  Controlling Elaboration in GNAT - External CallsControlling Elaboration in 
  157.                                GNAT - External Calls 
  158.  Default Behavior in GNAT - Ensuring SafetyDefault Behavior in GNAT - Ensuring 
  159.                                Safety 
  160.  What to do if the Default Elaboration Behavior FailsWhat to do if the Default 
  161.                                Elaboration Behavior Fails 
  162.  Elaboration for Access-to-Subprogram ValuesElaboration for 
  163.                                Access-to-Subprogram Values 
  164.  Summary of Procedures for Elaboration ControlSummary of Procedures for 
  165.                                Elaboration Control The cross-referencing tools 
  166.                                gnatxref and gnatfind 
  167.  Gnatxref switches             Gnatxref switches 
  168.  Gnatfind switches             Gnatfind switches 
  169.  Project files                 Project files 
  170.  Regular expressions in gnatfind and gnatxrefRegular expressions in gnatfind 
  171.                                and gnatxref 
  172.  Examples of gnatxref usage    Examples of gnatxref usage 
  173.  Examples of gnatfind usage    Examples of gnatfind usage File Name Krunching 
  174.                                Using gnatkr 
  175.  About gnatkr                  About gnatkr 
  176.  Using gnatkr                  Using gnatkr 
  177.  Krunching Method              Krunching Method 
  178.  Examples of gnatkr Usage      Examples of gnatkr Usage Preprocessing Using 
  179.                                gnatprep 
  180.  Using gnatprep                Using gnatprep 
  181.  Switches for gnatprep         Switches for gnatprep 
  182.  Form of definitions file      Form of definitions file 
  183.  Form of input text for gnatprepForm of input text for gnatprep  The GNAT 
  184.                                library browser gnatls 
  185.  Running gnatls                Running gnatls 
  186.  Switches for gnatls           Switches for gnatls 
  187.  Examples of gnatls Usage      Examples of gnatls Usage  GNAT and libraries 
  188.  Creating an Ada library       Creating an Ada library 
  189.  Installing an Ada library     Installing an Ada library 
  190.  Using an Ada library          Using an Ada library 
  191.  Rebuilding the GNAT runtime libraryRebuilding the GNAT runtime library Using 
  192.                                the GNU make utility 
  193.  Using gnatmake in a Makefile  Using gnatmake in a Makefile 
  194.  Automatically creating a list of directoriesAutomatically creating a list of 
  195.                                directories 
  196.  Generating the command line switchesGenerating the command line switches 
  197.  Overcoming command line length limitsOvercoming command line length limits 
  198.                                Finding memory problems with gnatmem 
  199.  Running gnatmem               Running gnatmem 
  200.  Switches for gnatmem          Switches for gnatmem 
  201.  Examples of gnatmem Usage     Examples of gnatmem Usage 
  202.  Implementation note           Implementation note Finding memory problems with 
  203.                                GNAT Debug Pool Creating Sample Bodies Using 
  204.                                gnatstub 
  205.  Running gnatstub              Running gnatstub 
  206.  Switches for gnatstub         Switches for gnatstub Reducing the Size of Ada 
  207.                                Executables with gnatelim 
  208.  About gnatelim                About gnatelim 
  209.  Eliminate pragma              Eliminate pragma 
  210.  Tree Files                    Tree Files 
  211.  Preparing Tree and Bind Files for gnatelimPreparing Tree and Bind Files for 
  212.                                gnatelim 
  213.  Running gnatelim              Running gnatelim 
  214.  Correcting the List of Eliminate PragmasCorrecting the List of Eliminate 
  215.                                Pragmas 
  216.  Making your Executables smallerMaking your Executables smaller 
  217.  Summary of the gnatelim Usage CycleSummary of the gnatelim Usage Cycle Other 
  218.                                Utility Programs 
  219.  Using Other Utility Programs With GNATUsing Other Utility Programs With GNAT 
  220.  The gnatpsys Utility Program  The gnatpsys Utility Program 
  221.  The gnatpsta Utility Program  The gnatpsta Utility Program 
  222.  The External Symbol Naming Scheme of GNATThe External Symbol Naming Scheme of 
  223.                                GNAT 
  224.  Ada Mode for emacs            Ada Mode for emacs 
  225.  Converting Ada files to html using gnathtmlConverting Ada files to html using 
  226.                                gnathtml  Running and Debugging Ada Programs 
  227.  The GNAT Debugger GDB         The GNAT Debugger GDB 
  228.  Running GDB                   Running GDB 
  229.  Introduction to GDB Commands  Introduction to GDB Commands 
  230.  Using Ada Expressions         Using Ada Expressions 
  231.  Calling User-Defined SubprogramsCalling User-Defined Subprograms 
  232.  Ada Exceptions                Ada Exceptions 
  233.  Ada Tasks                     Ada Tasks 
  234.  Debugging Generic Units       Debugging Generic Units 
  235.  GNAT Abnormal Termination     GNAT Abnormal Termination 
  236.  Naming Conventions for GNAT Source FilesNaming Conventions for GNAT Source 
  237.                                Files 
  238.  Getting Internal Debugging InformationGetting Internal Debugging Information 
  239.                                Performance Considerations 
  240.  Controlling Run-time Checks   Controlling Run-time Checks 
  241.  Optimization Levels           Optimization Levels 
  242.  Inlining of Subprograms       Inlining of Subprograms 
  243.  Index                         Index 
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ 3. About This Guide ΓòÉΓòÉΓòÉ
  247.  
  248.  
  249.  This guide describes the use of GNAT, a compiler and software development 
  250.  toolset for the full Ada 95 programming language. It describes the features of 
  251.  the compiler and tools, and details how to use them to build Ada 95 
  252.  applications. 
  253.  
  254.  What This Guide Contains      What This Guide Contains 
  255.  What You Should Know Before Reading This GuideWhat You Should Know Before 
  256.                                Reading This Guide 
  257.  Related Information           Related Information 
  258.  Conventions                   Conventions 
  259.  
  260.  
  261. ΓòÉΓòÉΓòÉ 3.1. What This Guide Contains ΓòÉΓòÉΓòÉ
  262.  
  263.  
  264.  This guide contains the following chapters: 
  265.  
  266.      Getting Started With GNAT, describes how to get started compiling and 
  267.       running Ada programs with the GNAT Ada programming environment. 
  268.  
  269.      The GNAT Compilation Model, describes the compilation model used by GNAT. 
  270.  
  271.      Compiling Using gcc, describes how to compile Ada programs with gcc, the 
  272.       Ada compiler. 
  273.  
  274.      Binding Using gnatbind, describes how to perform binding of Ada programs 
  275.       with gnatbind, the GNAT binding utility. 
  276.  
  277.      Linking Using gnatlink, describes gnatlink, a program that provides for 
  278.       linking using the GNAT run-time library to construct a program. gnatlink 
  279.       can also incorporate foreign language object units into the executable. 
  280.  
  281.      The GNAT Make Program gnatmake, describes gnatmake, a utility that 
  282.       automatically determines the set of sources needed by an Ada compilation 
  283.       unit, and executes the necessary compilations binding and link. 
  284.  
  285.      Renaming Files Using gnatchop, describes gnatchop, a utility that allows 
  286.       you to preprocess a file that contains Ada source code, and split it into 
  287.       one or more new files, one for each compilation unit. 
  288.  
  289.      The cross-referencing tools gnatxref and gnatfind, discusses gnatxref and 
  290.       gnatfind, two tools that provide an easy way to navigate through sources. 
  291.  
  292.      File Name Krunching Using gnatkr, describes the gnatkr file name 
  293.       krunching utility, used to handle shortened file names on operating 
  294.       systems with a limit on the length of names. 
  295.  
  296.      Preprocessing Using gnatprep, describes gnatprep, a preprocessor utility 
  297.       that allows a single source file to be used to generate multiple or 
  298.       parameterized source files, by means of macro substitution. 
  299.  
  300.      The GNAT library browser gnatls, describes gnatls, a utility that 
  301.       displays information about compiled units, including dependences on the 
  302.       corresponding sources files, and consistency of compilations. 
  303.  
  304.      GNAT and libraries, describes the process of creating and using Libraries 
  305.       with GNAT. It also describes how to recompile the GNAT runtime library. 
  306.  
  307.      Using the GNU make utility, describes some techniques for using the GNAT 
  308.       toolset in Makefiles. 
  309.  
  310.      Finding memory problems with gnatmem, describes gnatmem, a utility that 
  311.       monitors dynamic allocation and deallocation activity in a program, and 
  312.       displays information about incorrect deallocations and sources of 
  313.       possible memory leaks. 
  314.  
  315.      Finding memory problems with GNAT Debug Pool, describes how to use the 
  316.       GNAT-specific Debug Pool in order to detect as early as possible the use 
  317.       of incorrect memory references. 
  318.  
  319.      Creating Sample Bodies Using gnatstub, discusses gnatstub, a utility that 
  320.       generates empty but compilable bodies for library units. 
  321.  
  322.      Reducing the Size of Ada Executables with gnatelim, describes gnatelim, a 
  323.       tool which detects unused subprograms and helps the compiler to create a 
  324.       smaller executable for the program. 
  325.  
  326.      Other Utility Programs, discusses several other GNAT utilities, including 
  327.       gnatpsta and gnatpsys. 
  328.  
  329.      Running and Debugging Ada Programs, describes how to run and debug Ada 
  330.       programs. 
  331.  
  332.      Building mixed Ada & C++ programs, gives hints on how to interface with 
  333.       c++. 
  334.  
  335.      Performance Considerations, reviews the trade offs between using defaults 
  336.       or options in program development. 
  337.  
  338.  
  339. ΓòÉΓòÉΓòÉ 3.2. What You Should Know Before Reading This Guide ΓòÉΓòÉΓòÉ
  340.  
  341.  
  342.  This user's guide assumes that you are familiar with Ada 95 language, as 
  343.  described in the International Standard ANSI/ISO/IEC-8652:1995, Jan 1995. 
  344.  
  345.  
  346. ΓòÉΓòÉΓòÉ 3.3. Related Information ΓòÉΓòÉΓòÉ
  347.  
  348.  
  349.  For further information about related tools, refer to the following documents: 
  350.  
  351.      GNAT Reference Manual, which contains all reference material for the GNAT 
  352.       implementation of Ada 95. 
  353.  
  354.      Ada 95 Language Reference Manual, which contains all reference material 
  355.       for the Ada 95 programming language. 
  356.  
  357.      Debugging with GDB contains all details on the use of the GNU 
  358.       source-level debugger. 
  359.  
  360.      GNU Emacs Manual contains full information on the extensible editor and 
  361.       programming environment Emacs. 
  362.  
  363.  
  364. ΓòÉΓòÉΓòÉ 3.4. Conventions ΓòÉΓòÉΓòÉ
  365.  
  366.  
  367.  Following are examples of the typographical and graphic conventions used in 
  368.  this guide: 
  369.  
  370.      Functions, utility program names, standard names, and classes. 
  371.  
  372.      'Option flags' 
  373.  
  374.      'File Names', 'button names', and 'field names'. 
  375.  
  376.      Variables. 
  377.  
  378.      Emphasis. 
  379.  
  380.      [optional information or parameters] 
  381.  
  382.      Examples are described by text 
  383.  
  384.                       and then shown this way.
  385.  
  386.  
  387.  Commands that are entered by the user are preceded in this manual by the 
  388.  characters "$ " (dollar sign followed by space). If your system uses this 
  389.  sequence as a prompt, then the commands will appear exactly as you see them in 
  390.  the manual. If your system uses some other prompt, then the command will 
  391.  appear with the $ replaced by whatever prompt character you are using. 
  392.  
  393.  
  394. ΓòÉΓòÉΓòÉ 4. Getting Started With GNAT ΓòÉΓòÉΓòÉ
  395.  
  396.  
  397.  This chapter describes the simplest ways of using GNAT to compile Ada 
  398.  programs. 
  399.  
  400.  Running GNAT                  Running GNAT 
  401.  Running a Simple Ada Program  Running a Simple Ada Program 
  402.  Running a Program With Multiple UnitsRunning a Program With Multiple Units 
  403.  Using the gnatmake Utility    Using the gnatmake Utility 
  404.  
  405.  
  406. ΓòÉΓòÉΓòÉ 4.1. Running GNAT ΓòÉΓòÉΓòÉ
  407.  
  408.  
  409.  Three steps are needed to create an executable file from an Ada source file: 
  410.  
  411.    1. The source file(s) must be compiled. 
  412.  
  413.    2. The file(s) must be bound using the GNAT binder. 
  414.  
  415.    3. All appropriate object files must be linked to produce an executable. 
  416.  
  417.  All three steps are most commonly handled by using the gnatmake utility 
  418.  program that, given the name of the main program, automatically performs the 
  419.  necessary compilation, binding and linking steps. 
  420.  
  421.  
  422. ΓòÉΓòÉΓòÉ 4.2. Running a Simple Ada Program ΓòÉΓòÉΓòÉ
  423.  
  424.  
  425.  Any editor may be used to prepare an Ada program. If emacs is used, the 
  426.  optional Ada mode may be helpful in laying out the program. The program text 
  427.  is a normal text file. We will suppose in our initial example that you have 
  428.  used your editor to prepare the following standard format text file: 
  429.  
  430.                       with Text_IO; use Text_IO;
  431.                       procedure Hello is
  432.                       begin
  433.                         Put_Line ("Hello WORLD!");
  434.                       end Hello;
  435.  
  436.  This file should be named 'hello.adb'. Using the normal default file naming 
  437.  conventions, By default, GNAT requires that each file contain a single 
  438.  compilation unit whose file name corresponds to the unit name with periods 
  439.  replaced by hyphens, and whose extension is '.ads' for a spec and '.adb' for a 
  440.  body. This default file naming convention can be overridden by use of the 
  441.  special pragma Source_File_Name see Using Other File Names. Alternatively, if 
  442.  you want to rename your files according to this default convention, which is 
  443.  probably more convenient if you will be using GNAT for all your compilation 
  444.  requirements, then the gnatchop utility can be used to perform this renaming 
  445.  operation (see Renaming Files Using gnatchop). 
  446.  
  447.  You can compile the program using the following command: 
  448.  
  449.                       $ gcc -c hello.adb
  450.  
  451.  gcc is the command used to run the compiler. This compiler is capable of 
  452.  compiling programs in several languages including Ada 95 and C. It determines 
  453.  you have given it an Ada program by the extension ('.ads' or '.adb'), and will 
  454.  call the GNAT compiler to compile the specified file. 
  455.  
  456.  The -c switch is required. It tells gcc to only do a compilation. (For C 
  457.  programs, gcc can also do linking, but this capability is not used directly 
  458.  for Ada programs, so the -c switch must always be present.) 
  459.  
  460.  This compile command generates a file 'hello.o' which is the object file 
  461.  corresponding to your Ada program. It also generates a file 'hello.ali' which 
  462.  contains additional information used to check that an Ada program is 
  463.  consistent. To get an executable file, we then use gnatbind to bind the 
  464.  program and gnatlink to link it to produce the executable. The argument to 
  465.  both gnatbind and gnatlink is the name of the 'ali' file, but the default 
  466.  extension of '.ali' can be omitted. This means that in the most common case, 
  467.  the argument is simply the name of the main program: 
  468.  
  469.                       $ gnatbind hello
  470.                       $ gnatlink hello
  471.  
  472.  A simpler method of carrying out these steps is to use gnatmake, which is a 
  473.  master program which invokes all of the required compilation, binding and 
  474.  linking tools in the correct order. In particular, gnatmake automatically 
  475.  recompiles any sources that have been modified since they were last compiled, 
  476.  or sources that depend on such modified sources, so that a consistent 
  477.  compilation is ensured. 
  478.  
  479.                       $ gnatmake hello.adb
  480.  
  481.  The result is an executable program called 'hello', which can be run by 
  482.  entering: 
  483.  
  484.                       $ ./hello
  485.  
  486.  and, if all has gone well, you will see 
  487.  
  488.                       Hello WORLD!
  489.  
  490.  appear in response to this command. 
  491.  
  492.  
  493. ΓòÉΓòÉΓòÉ 4.3. Running a Program With Multiple Units ΓòÉΓòÉΓòÉ
  494.  
  495.  
  496.  Consider a slightly more complicated example that has three files: a main 
  497.  program, and the spec and body of a package: 
  498.  
  499.                       package Greetings is
  500.                         procedure Hello;
  501.                         procedure Goodbye;
  502.                       end Greetings;
  503.                       with Text_IO; use Text_IO;
  504.                       package body Greetings is
  505.                         procedure Hello is
  506.                         begin
  507.                          Put_Line ("Hello WORLD!");
  508.                         end Hello;
  509.                         procedure Goodbye is
  510.                         begin
  511.                          Put_Line ("Goodbye WORLD!");
  512.                         end Goodbye;
  513.                       end Greetings;
  514.                       with Greetings;
  515.                       procedure Gmain is
  516.                       begin
  517.                         Greetings.Hello;
  518.                         Greetings.Goodbye;
  519.                       end Gmain;
  520.  
  521.  Following the one-unit-per-file rule, place this program in the following 
  522.  three separate files: 
  523.  
  524.  greetings.ads 
  525.            spec of package Greetings 
  526.  
  527.  greetings.adb 
  528.            body of package Greetings 
  529.  
  530.  gmain.adb 
  531.            body of main program 
  532.  
  533.  To build an executable version of this program, we could use four separate 
  534.  steps to compile, bind, and link the program, as follows: 
  535.  
  536.                       $ gcc -c gmain.adb
  537.                       $ gcc -c greetings.adb
  538.                       $ gnatbind gmain
  539.                       $ gnatlink gmain
  540.  
  541.  Note that there is no required order of compilation when using GNAT. In 
  542.  particular it is perfectly fine to compile the main program first. Also, it is 
  543.  not necessary to compile package specs in the case where there is a separate 
  544.  body, only the body need be compiled. If you want to submit these programs to 
  545.  the compiler for semantic checking purposes, then you use the -gnatc switch: 
  546.  
  547.                         $ gcc -c greetings.ads -gnatc
  548.  
  549.  Although the compilation can be done in separate steps as in the above 
  550.  example, in practice it is almost always more convenient to use the gnatmake 
  551.  capability. All you need to know in this case is the name of the main program 
  552.  source file. The effect of the above four commands can be achieved with a 
  553.  single one: 
  554.  
  555.                       $ gnatmake gmain.adb
  556.  
  557.  In the next section we discuss the advantages of using gnatmake in more 
  558.  detail. 
  559.  
  560.  
  561. ΓòÉΓòÉΓòÉ 4.4. Using the gnatmake Utility ΓòÉΓòÉΓòÉ
  562.  
  563.  
  564.  If you work on a program by compiling single components at a time using gcc, 
  565.  you typically keep track of the units you modify. In order to build a 
  566.  consistent system, you compile not only these units, but also any units that 
  567.  depend on the units you have modified. For example, in the preceding case, if 
  568.  you edit 'gmain.adb', you only need to recompile that file. But if you edit 
  569.  'greetings.ads', you must recompile both 'greetings.adb' and 'gmain.adb', 
  570.  because both files contain units that depend on 'greetings.ads'. 
  571.  
  572.  gnatbind will warn you if you forget one of these compilation steps, so that 
  573.  it is impossible to generate an inconsistent program as a result of forgetting 
  574.  to do a compilation. Nevertheless it is tedious and error-prone to keep track 
  575.  of dependencies among units. One approach to handle the dependency-bookkeeping 
  576.  is to use a makefile. However, makefiles present maintenance problems of their 
  577.  own: if the dependencies change as you change the program, you must make sure 
  578.  that the makefile is kept up-to-date manually, which is also an error-prone 
  579.  process. 
  580.  
  581.  The gnatmake utility takes care of these details automatically. Invoke it 
  582.  using either one of the following forms: 
  583.  
  584.                       $ gnatmake gmain.adb
  585.                       $ gnatmake gmain
  586.  
  587.  The argument is the name of the file containing the main program from which 
  588.  you may omit the extension. gnatmake examines the environment, automatically 
  589.  recompiles any files that need recompiling, and binds and links the resulting 
  590.  set of object files, generating the executable file, 'gmain'. In a large 
  591.  program, it can be extremely helpful to use gnatmake, because working out by 
  592.  hand what needs to be recompiled can be difficult. 
  593.  
  594.  Note that gnatmake takes into account all the intricate Ada 95 rules that 
  595.  establish dependencies among units. These include dependencies that result 
  596.  from inlining subprogram bodies, and from generic instantiation. Unlike some 
  597.  other Ada make tools, gnatmake does not rely on the dependencies that were 
  598.  found by the compiler on a previous compilation, which may possibly be wrong 
  599.  when sources change. gnatmake determines the exact set of dependencies from 
  600.  scratch each time it is run. 
  601.  
  602.  
  603. ΓòÉΓòÉΓòÉ 5. The GNAT Compilation Model ΓòÉΓòÉΓòÉ
  604.  
  605.  Source Representation         Source Representation 
  606.  Foreign Language RepresentationForeign Language Representation 
  607.  File Naming Rules             File Naming Rules 
  608.  Using Other File Names        Using Other File Names 
  609.  Generating Object Files       Generating Object Files 
  610.  Source Dependencies           Source Dependencies 
  611.  The Ada Library Information FilesThe Ada Library Information Files 
  612.  Representation of Time Stamps Representation of Time Stamps 
  613.  Binding an Ada Program        Binding an Ada Program 
  614.  Mixed Language Programming    Mixed Language Programming 
  615.  Building mixed Ada & C++ programsBuilding mixed Ada & C++ programs 
  616.  Comparison between GNAT and C/C++ Compilation ModelsComparison between GNAT 
  617.                                and C/C++ Compilation Models 
  618.  Comparison between GNAT and Conventional Ada Library ModelsComparison between 
  619.                                GNAT and Conventional Ada Library Models 
  620.  
  621.  This chapter describes the compilation model used by GNAT. Although similar to 
  622.  that used by other languages, such as C and C++, this model is substantially 
  623.  different from the traditional Ada compilation models, which are based on a 
  624.  library. The model is initially described without reference to the 
  625.  library-based model. If you have not previously used an Ada compiler, you need 
  626.  only read the first part of this chapter. The last section describes and 
  627.  discusses the differences between the GNAT model and the traditional Ada 
  628.  compiler models. If you have used other Ada compilers, this section will help 
  629.  you to understand those differences, and the advantages of the GNAT model. 
  630.  
  631.  
  632. ΓòÉΓòÉΓòÉ 5.1. Source Representation ΓòÉΓòÉΓòÉ
  633.  
  634.  
  635.  Ada source programs are represented in standard text files, using Latin-1 
  636.  coding. Latin-1 is an 8-bit code that includes the familiar 7-bit ASCII set, 
  637.  plus additional characters used for representing foreign languages (see 
  638.  Foreign Language Representation for support of non-USA character sets). The 
  639.  format effector characters are represented using their standard ASCII 
  640.  encodings, as follows: 
  641.  
  642.  VT 
  643.            Vertical tab, 16#0B# 
  644.  
  645.  HT 
  646.            Horizontal tab, 16#09# 
  647.  
  648.  CR 
  649.            Carriage return, 16#0D# 
  650.  
  651.  LF 
  652.            Line feed, 16#0A# 
  653.  
  654.  FF 
  655.            Form feed, 16#0C# 
  656.  
  657.  Source files are in standard text file format. In addition, GNAT will 
  658.  recognize a wide variety of stream formats, in which the end of physical 
  659.  physical lines is marked by any of the following sequences: LF, CR, CR-LF, or 
  660.  LF-CR. This is useful in accommodating files that are imported from other 
  661.  operating systems. 
  662.  
  663.  The end of a source file is normally represented by the physical end of file. 
  664.  However, the control character 16#1A# (SUB) is also recognized as signalling 
  665.  the end of the source file. Again, this is provided for compatibility with 
  666.  other operating systems where this code is used to represent the end of file. 
  667.  
  668.  Each file contains a single Ada compilation unit, including any pragmas 
  669.  associated with the unit. For example, this means you must place a package 
  670.  declaration (a package spec) and the corresponding body in separate files. An 
  671.  Ada compilation (which is a sequence of compilation units) is represented 
  672.  using a sequence of files. Similarly, you will place each subunit or child 
  673.  unit in a separate file. 
  674.  
  675.  
  676. ΓòÉΓòÉΓòÉ 5.2. Foreign Language Representation ΓòÉΓòÉΓòÉ
  677.  
  678.  
  679.  GNAT supports the standard character sets defined in Ada 95 as well as several 
  680.  other non-standard character sets for use in localized versions of the 
  681.  compiler (see Character Set Control). 
  682.  
  683.  Latin-1                       Latin-1 
  684.  Other 8-Bit Codes             Other 8-Bit Codes 
  685.  Wide Character Encodings      Wide Character Encodings 
  686.  
  687.  
  688. ΓòÉΓòÉΓòÉ 5.2.1. Latin-1 ΓòÉΓòÉΓòÉ
  689.  
  690.  
  691.  The basic character set is Latin-1. This character set is defined by ISO 
  692.  standard 8859, part 1. The lower half (character codes 16#00# ┬╖┬╖┬╖ 16#7F#) is 
  693.  identical to standard ASCII coding, but the upper half is used to represent 
  694.  additional characters. These include extended letters used by European 
  695.  languages, such as French accents, the vowels with umlauts used in German, and 
  696.  the extra letter A-ring used in Swedish. 
  697.  
  698.  For a complete list of Latin-1 codes and their encodings, see the source file 
  699.  of library unit Ada.Characters.Latin_1 in file 'a-chlat1.ads'. You may use any 
  700.  of these extended characters freely in character or string literals. In 
  701.  addition, the extended characters that represent letters can be used in 
  702.  identifiers. 
  703.  
  704.  
  705. ΓòÉΓòÉΓòÉ 5.2.2. Other 8-Bit Codes ΓòÉΓòÉΓòÉ
  706.  
  707.  
  708.  GNAT also supports several other 8-bit coding schemes: 
  709.  
  710.  Latin-2 
  711.            Latin-2 letters allowed in identifiers, with uppercase and lowercase 
  712.            equivalence. 
  713.  
  714.  Latin-3 
  715.            Latin-3 letters allowed in identifiers, with uppercase and lowercase 
  716.            equivalence. 
  717.  
  718.  Latin-4 
  719.            Latin-4 letters allowed in identifiers, with uppercase and lowercase 
  720.            equivalence. 
  721.  
  722.  IBM PC (code page 437) 
  723.            This code page is the normal default for PCs in the U.S. It 
  724.            corresponds to the original IBM PC character set. This set has some, 
  725.            but not all, of the extended Latin-1 letters, but these letters do 
  726.            not have the same encoding as Latin-1. In this mode, these letters 
  727.            are allowed in identifiers with uppercase and lowercase equivalence. 
  728.  
  729.  IBM PC (code page 850) 
  730.            This code page is a modification of 437 extended to include all the 
  731.            Latin-1 letters, but still not with the usual Latin-1 encoding. In 
  732.            this mode, all these letters are allowed in identifiers with 
  733.            uppercase and lowercase equivalence. 
  734.  
  735.  Full Upper 8-bit 
  736.            Any character in the range 80-FF allowed in identifiers, and all are 
  737.            considered distinct. In other words, there are no uppercase and 
  738.            lowercase equivalences in this range. This is useful in conjunction 
  739.            with certain encoding schemes used for some foreign character sets 
  740.            (e.g. the typical method of representing Chinese characters on the 
  741.            PC). 
  742.  
  743.  No Upper-Half 
  744.            No upper-half characters in the range 80-FF are allowed in 
  745.            identifiers. This gives Ada 83 compatibility for identifier names. 
  746.  
  747.  For precise data on the encodings permitted, and the uppercase and lowercase 
  748.  equivalences that are recognized, see the file 'csets.adb' in the GNAT 
  749.  compiler sources. You will need to obtain a full source release of GNAT to 
  750.  obtain this file. 
  751.  
  752.  
  753. ΓòÉΓòÉΓòÉ 5.2.3. Wide Character Encodings ΓòÉΓòÉΓòÉ
  754.  
  755.  
  756.  GNAT allows wide character codes to appear in character and string literals, 
  757.  and also optionally in identifiers, by means of the following possible 
  758.  encoding schemes: 
  759.  
  760.  Hex Coding 
  761.            In this encoding, a wide character is represented by the following 
  762.            five character sequence: 
  763.  
  764.                       ESC a b c d
  765.  
  766.  Where a, b, c, d are the four hexadecimal characters (using uppercase letters) 
  767.  of the wide character code. For example, ESC A345 is used to represent the 
  768.  wide character with code 16#A345#. This scheme is compatible with use of the 
  769.  full Wide_Character set. 
  770.  
  771.  Upper-Half Coding 
  772.            The wide character with encoding 16#abcd# where the upper bit is on 
  773.            (in other words, "a" is in the range 8-F) is represented as two 
  774.            bytes, 16#ab# and 16#cd#. The second byte cannot be a format control 
  775.            character, but is not required to be in the upper half. This method 
  776.            can be also used for shift-JIS or EUC, where the internal coding 
  777.            matches the external coding. 
  778.  
  779.  Shift JIS Coding 
  780.            A wide character is represented by a two-character sequence, 16#ab# 
  781.            and 16#cd#, with the restrictions described for upper-half encoding 
  782.            as described above. The internal character code is the corresponding 
  783.            JIS character according to the standard algorithm for Shift-JIS 
  784.            conversion. Only characters defined in the JIS code set table can be 
  785.            used with this encoding method. 
  786.  
  787.  EUC Coding 
  788.            A wide character is represented by a two-character sequence 16#ab# 
  789.            and 16#cd#, with both characters being in the upper half. The 
  790.            internal character code is the corresponding JIS character according 
  791.            to the EUC encoding algorithm. Only characters defined in the JIS 
  792.            code set table can be used with this encoding method. 
  793.  
  794.  UTF-8 Coding 
  795.            A wide character is represented using UCS Transformation Format 8 
  796.            (UTF-8) as defined in Annex R of ISO 10646-1/Am.2. Depending on the 
  797.            character value, the representation is a one, two, or three byte 
  798.            sequence: 
  799.  
  800.                       16#0000#-16#007f#: 2#0xxxxxxx#
  801.                       16#0080#-16#07ff#: 2#110xxxxx# 2#10xxxxxx#
  802.                       16#0800#-16#ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
  803.  
  804.  where the xxx bits correspond to the left-padded bits of the 16-bit character 
  805.  value. Note that all lower half ASCII characters are represented as ASCII 
  806.  bytes and all upper half characters and other wide characters are represented 
  807.  as sequences of upper-half (The full UTF-8 scheme allows for encoding 31-bit 
  808.  characters as 6-byte sequences, but in this implementation, all UTF-8 
  809.  sequences of four or more bytes length will be treated as illegal). 
  810.  
  811.  Brackets Coding 
  812.            In this encoding, a wide character is represented by the following 
  813.            eight character sequence: 
  814.  
  815.                       [ " a b c d " ]
  816.  
  817.  Where a, b, c, d are the four hexadecimal characters (using uppercase letters) 
  818.  of the wide character code. For example, ["A345"] is used to represent the 
  819.  wide character with code 16#A345#. It is also possible (though not required) 
  820.  to use the Brackets coding for upper half characters. For example, the code 
  821.  16#A3# can be represented as ["A3"]. 
  822.  
  823.  This scheme is compatible with use of the full Wide_Character set, and is also 
  824.  the method used for wide character encoding in the standard ACVC (Ada Compiler 
  825.  Validation Capability) test suite distributions. 
  826.  
  827.  Note: Some of these coding schemes do not permit the full use of the Ada 95 
  828.  character set. For example, neither Shift JIS, nor EUC allow the use of the 
  829.  upper half of the Latin-1 set. 
  830.  
  831.  
  832. ΓòÉΓòÉΓòÉ 5.3. File Naming Rules ΓòÉΓòÉΓòÉ
  833.  
  834.  
  835.  The default file name is determined by the name of the unit that the file 
  836.  contains. The name is formed by taking the full expanded name of the unit and 
  837.  replacing the separating dots with hyphens and using lowercase for all 
  838.  letters. 
  839.  
  840.  An exception arises if the file name generated by the above rules starts with 
  841.  one of the characters a,g,i, or s, and the second character is a minus. In 
  842.  this case, the character tilde is used in place of the minus. The reason for 
  843.  this special rule is to avoid clashes with the standard names for child units 
  844.  of the packages System, Ada, Interfaces, and GNAT, which use the prefixes s- 
  845.  a- i- and g- respectively. 
  846.  
  847.  The file extension is '.ads' for a spec and '.adb' for a body. The following 
  848.  list shows some examples of these rules. 
  849.  
  850.  main.ads 
  851.            Main (spec) 
  852.  
  853.  main.adb 
  854.            Main (body) 
  855.  
  856.  arith_functions.ads 
  857.            Arith_Functions (package spec) 
  858.  
  859.  arith_functions.adb 
  860.            Arith_Functions (package body) 
  861.  
  862.  func-spec.ads 
  863.            Func.Spec (child package spec) 
  864.  
  865.  func-spec.adb 
  866.            Func.Spec (child package body) 
  867.  
  868.  main-sub.adb 
  869.            Sub (subunit of Main) 
  870.  
  871.  a~bad.adb 
  872.            A.Bad (child package body) 
  873.  
  874.  Following these rules can result in excessively long file names if 
  875.  corresponding unit names are long (for example, if child units or subunits are 
  876.  heavily nested). An option is available to shorten such long file names 
  877.  (called file name "krunching"). This may be particularly useful when programs 
  878.  being developed with GNAT are to be used on operating systems with limited 
  879.  file name lengths. See Using gnatkr. 
  880.  
  881.  Of course, no file shortening algorithm can guarantee uniqueness over all 
  882.  possible unit names; if file name krunching is used, it is your responsibility 
  883.  to ensure no name clashes occur. Alternatively you can specify the exact file 
  884.  names that you want used, as described in the next section. Finally, if your 
  885.  Ada programs are migrating from a compiler with a different naming convention, 
  886.  you can use the gnatchop utility to produce source files that follow the GNAT 
  887.  naming conventions. (For details see Renaming Files Using gnatchop.) 
  888.  
  889.  
  890. ΓòÉΓòÉΓòÉ 5.4. Using Other File Names ΓòÉΓòÉΓòÉ
  891.  
  892.  
  893.  In the previous section, we have described the default rules used by GNAT to 
  894.  determine the file name in which a given unit resides. It is often convenient 
  895.  to follow these default rules, and if you follow them, the compiler knows 
  896.  without being explicitly told where to find all the files it needs. 
  897.  
  898.  However, in some cases, particularly when a program is imported from another 
  899.  Ada compiler environment, it may be more convenient for the programmer to 
  900.  specify which file names contain which units. GNAT allows arbitrary file names 
  901.  to be used by means of the Source_File_Name pragma. The form of this pragma is 
  902.  as shown in the following examples: 
  903.  
  904.                       pragma Source_File_Name (My_Utilities.Stacks,
  905.                        Spec_File_Name => "myutilst_a.ada");
  906.                       pragma Source_File_name (My_Utilities.Stacks,
  907.                        Body_File_Name => "myutilst.ada");
  908.  
  909.  As shown in this example, the first argument for the pragma is the unit name 
  910.  (in this example a child unit). The second argument has the form of a named 
  911.  association. The identifier indicates whether the file name is for a spec or a 
  912.  body; the file name itself is given by a string literal. 
  913.  
  914.  The source file name pragma is a configuration pragma, which means that 
  915.  normally it will be placed in the 'gnat.adc' file used to hold configuration 
  916.  pragmas that apply to a complete compilation environment. For more details on 
  917.  how the 'gnat.adc' file is created and used see Handling of Configuration 
  918.  Pragmas GNAT allows completely arbitrary file names to be specified using the 
  919.  source file name pragma. However, if the file name specified has an extension 
  920.  other than '.ads' or '.adb' it is necessary to use a special syntax when 
  921.  compiling the file. The name in this case must be preceded by the special 
  922.  sequence -x followed by a space and the name of the language, here ada, as in: 
  923.  
  924.                       $ gcc -c -x ada peculiar_file_name.sim
  925.  
  926.  gnatmake handles non-standard file names in the usual manner (the non-standard 
  927.  file name for the main program is simply used as the argument to gnatmake). 
  928.  Note that if the extension is also non-standard, then it must be included in 
  929.  the gnatmake command, it may not be omitted. 
  930.  
  931.  
  932. ΓòÉΓòÉΓòÉ 5.5. Generating Object Files ΓòÉΓòÉΓòÉ
  933.  
  934.  
  935.  An Ada program consists of a set of source files, and the first step in 
  936.  compiling the program is to generate the corresponding object files. These are 
  937.  generated by compiling a subset of these source files. The files you need to 
  938.  compile are the following: 
  939.  
  940.      If a package spec has no body, compile the package spec to produce the 
  941.       object file for the package. 
  942.  
  943.      If a package has both a spec and a body, compile the body to produce the 
  944.       object file for the package. The source file for the package spec need 
  945.       not be compiled in this case because there is only one object file, which 
  946.       contains the code for both the spec and body of the package. 
  947.  
  948.      For a subprogram, compile the subprogram body to produce the object file 
  949.       for the subprogram. The spec, if one is present, is as usual in a 
  950.       separate file, and need not be compiled. 
  951.  
  952.      In the case of subunits, only compile the parent unit. A single object 
  953.       file is generated for the entire subunit tree, which includes all the 
  954.       subunits. 
  955.  
  956.      Compile child units independently of their parent units (though, of 
  957.       course, the spec of all the ancestor unit must be present in order to 
  958.       compile a child unit). 
  959.  
  960.      Compile generic units in the same manner as any other units. The object 
  961.       files in this case are small dummy files that contain at most the flag 
  962.       used for elaboration checking. This is because GNAT always handles 
  963.       generic instantiation by means of macro expansion. However, it is still 
  964.       necessary to compile generic units, for dependency checking and 
  965.       elaboration purposes. 
  966.  
  967.  The preceding rules describe the set of files that must be compiled to 
  968.  generate the object files for a program. Each object file has the same name as 
  969.  the corresponding source file, except that the extension is '.o' as usual. 
  970.  
  971.  You may wish to compile other files for the purpose of checking their 
  972.  syntactic and semantic correctness. For example, in the case where a package 
  973.  has a separate spec and body, you would not normally compile the spec. 
  974.  However, it is convenient in practice to compile the spec to make sure it is 
  975.  error-free before compiling clients of this spec, because such compilations 
  976.  will fail if there is an error in the spec. 
  977.  
  978.  GNAT provides an option for compiling such files purely for the purposes of 
  979.  checking correctness; such compilations are not required as part of the 
  980.  process of building a program. To compile a file in this checking mode, use 
  981.  the -gnatc switch. 
  982.  
  983.  
  984. ΓòÉΓòÉΓòÉ 5.6. Source Dependencies ΓòÉΓòÉΓòÉ
  985.  
  986.  
  987.  A given object file clearly depends on the source file which is compiled to 
  988.  produce it. Here we are using depends in the sense of a typical make utility; 
  989.  in other words, an object file depends on a source file if changes to the 
  990.  source file require the object file to be recompiled. In addition to this 
  991.  basic dependency, a given object may depend on additional source files as 
  992.  follows: 
  993.  
  994.      If a file being compiled with's a unit X, the object file depends on the 
  995.       file containing the spec of unit X. This includes files that are with'ed 
  996.       implicitly either because they are parents of with'ed child units or they 
  997.       are run-time units required by the language constructs used in a 
  998.       particular unit. 
  999.  
  1000.      If a file being compiled instantiates a library level generic unit, the 
  1001.       object file depends on both the spec and body files for this generic 
  1002.       unit. 
  1003.  
  1004.      If a file being compiled instantiates a generic unit defined within a 
  1005.       package, the object file depends on the body file for the package as well 
  1006.       as the spec file. 
  1007.  
  1008.      If a file being compiled contains a call to a subprogram for which pragma 
  1009.       Inline applies and inlining is activated with the -gnatn switch, the 
  1010.       object file depends on the file containing the body of this subprogram as 
  1011.       well as on the file containing the spec. 
  1012.  
  1013.      If an object file O  depends on the proper body of a subunit through 
  1014.       inlining or instantiation, it depends on the parent unit of the subunit. 
  1015.       This means that any modification of the parent unit or one of its 
  1016.       subunits affects the compilation of O. 
  1017.  
  1018.      The object file for a parent unit depends on all its subunit body files. 
  1019.  
  1020.      The previous two rules meant that for purposes of computing dependencies 
  1021.       and recompilation, a body and all its subunits are treated as an 
  1022.       indivisible whole. 
  1023.       These rules are applied transitively: if unit A with's unit B, whose 
  1024.       elaboration calls an inlined procedure in package C, the object file for 
  1025.       unit A will depend on the body of C, in file 'c.adb'. 
  1026.  
  1027.       The set of dependent files described by these rules includes all the 
  1028.       files on which the unit is semantically dependent, as described in the 
  1029.       Ada 95 Language Reference Manual. However, it is a superset of what the 
  1030.       ARM describes, because it includes generic, inline, and subunit 
  1031.       dependencies. 
  1032.  
  1033.       An object file must be recreated by recompiling the corresponding source 
  1034.       file if any of the source files on which it depends are modified. For 
  1035.       example, if the make utility is used to control compilation, the rule for 
  1036.       an Ada object file must mention all the source files on which the object 
  1037.       file depends, according to the above definition. The determination of the 
  1038.       necessary recompilations is done automatically when one uses gnatmake. 
  1039.  
  1040.  
  1041. ΓòÉΓòÉΓòÉ 5.7. The Ada Library Information Files ΓòÉΓòÉΓòÉ
  1042.  
  1043.  
  1044.  Each compilation actually generates two output files. The first of these is 
  1045.  the normal object file that has a '.o' extension. The second is a text file 
  1046.  containing full dependency information. It has the same name as the source 
  1047.  file, but an '.ali' extension. This file is known as the Ada Library 
  1048.  Information (ALI) file. 
  1049.  
  1050.  Normally you need not be concerned with the contents of this file. This 
  1051.  section is included in case you want to understand how these files are being 
  1052.  used by the binder and other GNAT utilities. Each ALI file consists of a 
  1053.  series of lines of the form: 
  1054.  
  1055.                       Key_Character parameter parameter ┬╖┬╖┬╖
  1056.  
  1057.  The first two lines in the file identify the library output version and 
  1058.  Standard version. These are required to be consistent across the entire set of 
  1059.  compilation units in your program. 
  1060.  
  1061.                       V "xxxxxxxxxxxxxxxx"
  1062.  
  1063.  This line indicates the library output version, as defined in 'gnatvsn.ads'. 
  1064.  It ensures that separate object modules of a program are consistent. The 
  1065.  library output version must be changed if anything in the compiler changes 
  1066.  that would affect successful binding of modules compiled separately. Examples 
  1067.  of such changes are modifications in the format of the library information 
  1068.  described in this package, modifications to calling sequences, or to the way 
  1069.  data is represented. 
  1070.  
  1071.                       S "xxxxxxxxxxxxxxxx"
  1072.  
  1073.  This line contains information regarding types declared in packages Standard 
  1074.  as stored in Gnatvsn.Standard_Version. The purpose of this information is to 
  1075.  ensure that all units in a program are compiled with a consistent set of 
  1076.  options. This is critical on systems where, for example, the size of Integer 
  1077.  can be set by command line switches. 
  1078.  
  1079.                       M type [priority]
  1080.  
  1081.  This line is present only for a unit that can be a main program. type is 
  1082.  either P for a parameterless procedure or F for a function returning a value 
  1083.  of integral type. The latter is for writing a main program that returns an 
  1084.  exit status. priority is present only if there was a valid pragma Priority in 
  1085.  the corresponding unit to set the main task priority. It is an unsigned 
  1086.  decimal integer. 
  1087.  
  1088.                       F x
  1089.  
  1090.  This line is present if a pragma Float_Representation or Long_Float is used to 
  1091.  specify other than the default floating-point format. This option applies only 
  1092.  to implementations of GNAT for the Digital Alpha Systems. The character x is 
  1093.  'I' for IEEE_Float, 'G' for VAX_Float with Long_Float using G_Float, and 'D' 
  1094.  for VAX_Float for Long_Float with D_Float. 
  1095.  
  1096.                       P L=x Q=x T=x
  1097.  
  1098.  This line is present if the unit uses tasking directly or indirectly, and has 
  1099.  one or more valid xxx_Policy pragmas that apply to the unit. The arguments are 
  1100.  as follows 
  1101.  
  1102.                       L=x (locking policy)
  1103.  
  1104.  This is present if a valid Locking_Policy pragma applies to the unit. The 
  1105.  single character indicates the policy in effect (e.g. 'C' for 
  1106.  Ceiling_Locking). 
  1107.  
  1108.                       Q=x (queuing policy)
  1109.  
  1110.  This is present if a valid Queuing_Policy pragma applies to the unit. The 
  1111.  single character indicates the policy in effect (e.g. 'P' for 
  1112.  Priority_Queuing). 
  1113.  
  1114.                       T=x (task_dispatching policy)
  1115.  
  1116.  This is present if a valid Task_Dispatching_Policy pragma applies to the unit. 
  1117.  The single character indicates the policy in effect (e.g. 'F' for 
  1118.  FIFO_Within_Priorities). 
  1119.  Following these header lines is a set of information lines, one per 
  1120.  compilation unit. Each line lists a unit in the object file corresponding to 
  1121.  this ALI file. In particular, when a package body or subprogram body is 
  1122.  compiled there will be two such lines, one for the spec and one for the body, 
  1123.  with the entry for the body appearing first. This is the only case in which a 
  1124.  single ALI file contains more than one unit. Note that subunits do not count 
  1125.  as compilation units for this purpose, and generate no library information, 
  1126.  because they are inlined. The lines for each compilation unit have the 
  1127.  following form: 
  1128.  
  1129.                       U unit-name source-name version [attributes]
  1130.  
  1131.  This line identifies the unit to which this section of the library information 
  1132.  file applies. unit-name is the unit name in internal format, as described in 
  1133.  package Uname, and source-name is the name of the source file containing the 
  1134.  unit. 
  1135.  
  1136.  version is the version, given by eight hexadecimal characters with lowercase 
  1137.  letters. This value is a hash code that includes contributions from the time 
  1138.  stamps of this unit and all the units on which it semantically depends. 
  1139.  
  1140.  The optional attributes are a series of two-letter codes indicating 
  1141.  information about the unit. They indicate the nature of the unit and they 
  1142.  summarize information provided by categorization pragmas. 
  1143.  
  1144.  EB 
  1145.            Unit has pragma Elaborate_Body. 
  1146.  
  1147.  NE 
  1148.            Unit has no elaboration routine. All subprogram specs are in this 
  1149.            category, as are subprogram bodies if access-before-elaboration 
  1150.            checks are being generated. Package bodies and specs may or may not 
  1151.            have NE set, depending on whether or not elaboration code is 
  1152.            required. 
  1153.  
  1154.  PK 
  1155.            Unit is a package. 
  1156.  
  1157.  PU 
  1158.            Unit has pragma Pure. 
  1159.  
  1160.  PR 
  1161.            Unit has pragma Preelaborate. 
  1162.  
  1163.  RC 
  1164.            Unit has pragma Remote_Call_Interface. 
  1165.  
  1166.  RT 
  1167.            Unit has pragma Remote_Types. 
  1168.  
  1169.  SP 
  1170.            Unit has pragma Shared_Passive. 
  1171.  
  1172.  SU 
  1173.            Unit is a subprogram. 
  1174.  
  1175.  The attributes may appear in any order, separated by spaces. The next set of 
  1176.  lines in the ALI file have the following form: 
  1177.  
  1178.                       W unit-name [source-name lib-name [E] [EA] [ED]]
  1179.  
  1180.  One of these lines is present for each unit mentioned in an explicit with 
  1181.  clause in the current unit. unit-name is the unit name in internal format. 
  1182.  source-name is the file name of the file that must be compiled to compile that 
  1183.  unit (usually the file for the body, except for packages that have no body). 
  1184.  lib-name is the file name of the library information file that contains the 
  1185.  results of compiling the unit. The E and EA parameters are present if pragma 
  1186.  Elaborate or pragma Elaborate_All, respectively, apply to this unit. ED is 
  1187.  used to indicate that the compiler has determined that a pragma Elaborate_All 
  1188.  for this unit would be desirable. For details on the use of the ED parameter 
  1189.  see See Elaboration Order Handling in GNAT. 
  1190.  Following the unit information is an optional series of lines that indicate 
  1191.  the usage of pragma Linker_Options. For each appearance of pragma 
  1192.  Linker_Options in any of the units for which unit lines are present, a line of 
  1193.  the form 
  1194.  
  1195.                       L string
  1196.  
  1197.  appears. string is the string from the pragma enclosed in quotes. Within the 
  1198.  quotes, the following can occur: 
  1199.  
  1200.      7-bit graphic characters other than " or { 
  1201.  
  1202.      "" (indicating a single " character) 
  1203.  
  1204.      {hh} indicating a character whose code is hex hh 
  1205.  
  1206.  For further details, see Stringt.Write_String_Table_Entry in the file 
  1207.  'stringt.ads'. Note that wide characters of the form {hhhh} cannot be 
  1208.  produced, because pragma Linker_Option accepts only String, not Wide_String. 
  1209.  
  1210.  Finally, the rest of the ALI file contains a series of lines that indicate the 
  1211.  source files on which the compiled units depend. This is used by the binder 
  1212.  for consistency checking and looks like: 
  1213.  
  1214.                       D source-name time-stamp [comments]
  1215.  
  1216.  where comments, if present, must be separated from the time stamp by at least 
  1217.  one blank. Currently this field is unused. 
  1218.  
  1219.  Blank lines are ignored when the library information is read, and separate 
  1220.  sections of the file are separated by blank lines to help readability. Extra 
  1221.  blanks between fields are also ignored. 
  1222.  
  1223.  
  1224. ΓòÉΓòÉΓòÉ 5.8. Representation of Time Stamps ΓòÉΓòÉΓòÉ
  1225.  
  1226.  
  1227.  All compiled units are marked with a time stamp, which is derived from the 
  1228.  source file. The binder uses these time stamps to ensure consistency of the 
  1229.  set of units that constitutes a single program. Time stamps are 
  1230.  fourteen-character strings of the form YYYYMMDDHHMMSS. The fields have the 
  1231.  following meaning: 
  1232.  
  1233.  YYYY 
  1234.            year (4 digits) 
  1235.  
  1236.  MM 
  1237.            month (2 digits 01-12) 
  1238.  
  1239.  DD 
  1240.            day (2 digits 01-31) 
  1241.  
  1242.  HH 
  1243.            hour (2 digits 00-23) 
  1244.  
  1245.  MM 
  1246.            minutes (2 digits 00-59) 
  1247.  
  1248.  SS 
  1249.            seconds (2 digits 00-59) 
  1250.  
  1251.  Time stamps may be compared lexicographically (in other words, the order of 
  1252.  Ada comparison operations on strings) to determine which is later or earlier. 
  1253.  However, in normal mode, only equality comparisons have any effect on the 
  1254.  semantics of the library. Later/earlier comparisons are used only for 
  1255.  determining the most informative error messages to be issued by the binder. 
  1256.  
  1257.  The time stamp is the actual stamp stored with the file without any adjustment 
  1258.  resulting from time zone comparisons. This avoids problems in using libraries 
  1259.  across networks with clients spread across multiple time zones, but it means 
  1260.  that the time stamp might differ from that displayed in a directory listing. 
  1261.  For example, in UNIX systems, file time stamps are stored in Greenwich Mean 
  1262.  Time (GMT), but the ls command displays local times. 
  1263.  
  1264.  
  1265. ΓòÉΓòÉΓòÉ 5.9. Binding an Ada Program ΓòÉΓòÉΓòÉ
  1266.  
  1267.  
  1268.  When using languages such as C and C++, once the source files have been 
  1269.  compiled the only remaining step in building an executable program is linking 
  1270.  the object modules together. This means that it is possible to link an 
  1271.  inconsistent version of a program, in which two units have included different 
  1272.  versions of the same header. 
  1273.  
  1274.  The rules of Ada do not permit such an inconsistent program to be built. For 
  1275.  example, if two clients have different versions of the same package, it is 
  1276.  illegal to build a program containing these two clients. These rules are 
  1277.  enforced by the GNAT binder, which also determines an elaboration order 
  1278.  consistent with the Ada rules. 
  1279.  
  1280.  The GNAT binder is run after all the object files for a program have been 
  1281.  created. It is given the name of the main program unit, and from this it 
  1282.  determines the set of units required by the program, by reading the 
  1283.  corresponding ALI files. It generates error messages if the program is 
  1284.  inconsistent or if no valid order of elaboration exists. 
  1285.  
  1286.  If no errors are detected, the binder produces a main program, in Ada by 
  1287.  default, that contains calls to the elaboration procedures of those 
  1288.  compilation unit that require them, followed by a call to the main program. 
  1289.  This Ada program is compiled to generate the object file for the main program. 
  1290.  The name of the Ada file is b~xxx.adb (with the corresponding spec b~xxx.ads) 
  1291.  where xxx is the name of the main program unit. 
  1292.  
  1293.  Finally, the linker is used to build the resulting executable program, using 
  1294.  the object from the main program from the bind step as well as the object 
  1295.  files for the Ada units of the program. 
  1296.  
  1297.  
  1298. ΓòÉΓòÉΓòÉ 5.10. Mixed Language Programming ΓòÉΓòÉΓòÉ
  1299.  
  1300.  Interfacing to C              Interfacing to C 
  1301.  Calling Conventions           Calling Conventions 
  1302.  
  1303.  
  1304. ΓòÉΓòÉΓòÉ 5.10.1. Interfacing to C ΓòÉΓòÉΓòÉ
  1305.  
  1306.  
  1307.  There are two ways to build a program that contains some Ada files and some 
  1308.  other language files depending on whether the main program is in Ada or not. 
  1309.  If the main program is in Ada, you should proceed as follows: 
  1310.  
  1311.    1. Compile the other language files to generate object files. For instance: 
  1312.  
  1313.                       gcc -c file1.c
  1314.                       gcc -c file2.c
  1315.  
  1316.    2. Compile the Ada units to produce a set of object files and ALI files. For 
  1317.       instance: 
  1318.  
  1319.                       gnatmake -c my_main.adb
  1320.  
  1321.    3. Run the Ada binder on the Ada main program. For instance: 
  1322.  
  1323.                       gnatbind my_main.ali
  1324.  
  1325.    4. Link the Ada main program, the Ada objects and the other language 
  1326.       objects. For instance: 
  1327.  
  1328.                       gnatlink my_main.ali file1.o file2.o
  1329.  
  1330.  The three last steps can be grouped in a single command: 
  1331.  
  1332.                       gnatmake my_main.adb -largs file1.o file2.o
  1333.  
  1334.  If the main program is in some language other than Ada, Then you may have more 
  1335.  than one entry point in the Ada subsystem. You must use a special option of 
  1336.  the binder to generate callable routines to initialize and finalize the Ada 
  1337.  units (see Binding with Non-Ada Main Programs). Calls to the initialization 
  1338.  and finalization routines must be inserted in the main program, or some other 
  1339.  appropriate point in the code. The call to initialize the Ada units must occur 
  1340.  before the first Ada subprogram is called, and the call to finalize the Ada 
  1341.  units must occur after the last Ada subprogram returns. You use the same 
  1342.  procedure for building the program as described previously. In this case, 
  1343.  however, the binder only places the initialization and finalization 
  1344.  subprograms into file 'b~xxx.adb' instead of the main program. So, if the main 
  1345.  program is not in Ada, you should proceed as follows: 
  1346.  
  1347.    1. Compile the other language files to generate object files. For instance: 
  1348.  
  1349.                       gcc -c file1.c
  1350.                       gcc -c file2.c
  1351.  
  1352.    2. Compile the Ada units to produce a set of object files and ALI files. For 
  1353.       instance: 
  1354.  
  1355.                       gnatmake -c entry_point1.adb
  1356.                       gnatmake -c entry_point2.adb
  1357.  
  1358.    3. Run the Ada binder on the Ada main program. For instance: 
  1359.  
  1360.                       gnatbind -n entry_point1.ali entry_point2.ali
  1361.  
  1362.    4. Link the Ada main program, the Ada objects and the other language 
  1363.       objects. You only need to give the last entry point here. For instance: 
  1364.  
  1365.                       gnatlink entry_point2.ali file1.o file2.o
  1366.  
  1367.  
  1368. ΓòÉΓòÉΓòÉ 5.10.2. Calling Conventions ΓòÉΓòÉΓòÉ
  1369.  
  1370.  GNAT follows standard calling sequence conventions and will thus interface to 
  1371.  any other language that also follows these conventions. The following 
  1372.  Convention identifiers are recognized by GNAT: 
  1373.  
  1374.      Ada. This indicates that the standard Ada calling sequence will be used 
  1375.       and all Ada data items may be passed without any limitations in the case 
  1376.       where GNAT is used to generate both the caller and callee. It is also 
  1377.       possible to mix GNAT generated code and code generated by another Ada 
  1378.       compiler. In this case, the data types should be restricted to simple 
  1379.       cases, including primitive types. Whether complex data types can be 
  1380.       passed depends on the situation. Probably it is safe to pass simple 
  1381.       arrays, such as arrays of integers or floats. Records may or may not 
  1382.       work, depending on whether both compilers lay them out identically. 
  1383.       Complex structures involving variant records, access parameters, tasks, 
  1384.       or protected types, are unlikely to be able to be passed. 
  1385.  
  1386.       Note that in the case of GNAT running on a platform that supports DEC Ada 
  1387.       83, a higher degree of compatibility can be guaranteed, and in particular 
  1388.       records are layed out in an identical manner in the two compilers. Note 
  1389.       also that if output from two different compilers is mixed, the program is 
  1390.       responsible for dealing with elaboration issues. Probably the safest 
  1391.       approach is to write the main program in the version of Ada other than 
  1392.       GNAT, so that it takes care of its own elaboration requirements, and then 
  1393.       call the GNAT-generated adainit procedure to ensure elaboration of the 
  1394.       GNAT components. Consult the documentation of the other Ada compiler for 
  1395.       further details on elaboration. 
  1396.  
  1397.       However, it is not possible to mix the tasking runtime of GNAT and DEC 
  1398.       Ada 83, All the tasking operations must either be entirely within GNAT 
  1399.       compiled sections of the program, or entirely within DEC Ada 83 compiled 
  1400.       sections of the program. 
  1401.  
  1402.      Asm. Equivalent to Ada. 
  1403.  
  1404.      Assembler. Equivalent to Ada. 
  1405.  
  1406.      COBOL. Data will be passed according to the conventions described in 
  1407.       section B.4 of the Ada 95 Reference Manual. 
  1408.  
  1409.      C. Data will be passed according to the conventions described in section 
  1410.       B.3 of the Ada 95 Reference Manual. 
  1411.  
  1412.      CPP. This stands for C++. For most purposes this is identical to C. See 
  1413.       the separate description of the specialized GNAT pragmas relating to C++ 
  1414.       interfacing for further details. 
  1415.  
  1416.      Fortran. Data will be passed according to the conventions described in 
  1417.       section B.5 of the Ada 95 Reference Manual. 
  1418.  
  1419.      Intrinsic. This applies to an intrinsic operation, as defined in the Ada 
  1420.       95 Reference Manual. If a a pragma Import (Intrinsic) applies to a 
  1421.       subprogram, this means that the body of the subprogram is provided by the 
  1422.       compiler itself, usually by means of an efficient code sequence, and that 
  1423.       the user does not supply an explicit body for it. In an application 
  1424.       program, the pragma can only be applied to the following two sets of 
  1425.       names, which the GNAT compiler recognizes. 
  1426.  
  1427.         -  Rotate_Left, Rotate_Right, Shift_Left, Shift_Right, Shift_Right_- 
  1428.            Arithmetic.  The corresponding subprogram declaration must have two 
  1429.            formal parameters. The first one must be a signed integer type or a 
  1430.            modular type with a binary modulus, and the second parameter must be 
  1431.            of type Natural. The return type must be the same as the type of the 
  1432.            first argument. The size of this type can only be 8, 16, 32, or 64. 
  1433.  
  1434.         -  binary arithmetic operators: "+", "-", "*", "/" 
  1435.            The corresponding operator declaration must have parameters and 
  1436.            result type that have the same root numeric type (for example, all 
  1437.            three are long_float types). This simplifies the definition of 
  1438.            operations that use type checking to perform dimensional checks: 
  1439.  
  1440.                       type Distance is new Long_Float;
  1441.                       type Time   is new Long_Float;
  1442.                       type Velocity is new Long_Float;
  1443.                       function "/" (D : Distance; T : Time)
  1444.                        return Velocity;
  1445.                       pragma Import (Intrinsic, "/");
  1446.  
  1447.  This common idiom is often programmed with a generic definition and an 
  1448.  explicit body. The pragma makes it simpler to introduce such declarations. It 
  1449.  incurs no overhead in compilation time or code size, because it is implemented 
  1450.  as a single machine instruction. 
  1451.  
  1452.      Stdcall. This is relevant only to NT/Win95 implementations of GNAT, and 
  1453.       specifies that the Stdcall calling sequence will be used, as defined by 
  1454.       the NT API. 
  1455.  
  1456.      Stubbed. This is a special convention that indicates that the compiler 
  1457.       should provide a stub body that raises Program_Error. 
  1458.  
  1459.  
  1460. ΓòÉΓòÉΓòÉ 5.11. Building mixed Ada & C++ programs ΓòÉΓòÉΓòÉ
  1461.  
  1462.  
  1463.  Building a mixed application containing both Ada and C++ code may be a 
  1464.  challenge for the unaware programmer. As a matter of fact, this interfacing 
  1465.  has not been standardized in the Ada 95 reference manual due to the immaturity 
  1466.  and lack of standard of C++ at the time. This section gives a few hints that 
  1467.  should make this task easier. In particular the first section addresses the 
  1468.  differences with interfacing with C. The second section looks into the 
  1469.  delicate problem of linking the complete application from its Ada and C++ 
  1470.  parts. The last section give some hints on how the GNAT runtime can be adapted 
  1471.  in order to allow inter-language dispatching with a new C++ compiler. 
  1472.  
  1473.  Interfacing to C++            Interfacing to C++ 
  1474.  Linking a mixed C++ & Ada programLinking a mixed C++ & Ada program 
  1475.  A simple example              A simple example 
  1476.  Adapting the runtime to a new C++ compilerAdapting the runtime to a new C++ 
  1477.                                compiler 
  1478.  
  1479.  
  1480. ΓòÉΓòÉΓòÉ 5.11.1. Interfacing to C++ ΓòÉΓòÉΓòÉ
  1481.  
  1482.  
  1483.  GNAT supports interfacing with C++ compilers generating code that is 
  1484.  compatible with the standard Application Binary Interface of the given 
  1485.  platform. 
  1486.  Interfacing can be done at 3 levels: simple data, subprograms and classes. In 
  1487.  the first 2 cases, GNAT offer a specific Convention CPP that behaves exactly 
  1488.  like Convention C. Usually C++ mangle names of subprograms and currently GNAT 
  1489.  does not provide any help to solve the demangling problem. This problem can be 
  1490.  addressed in 2 ways: 
  1491.  
  1492.      by modifying the C++ code in order to force a C convention using the 
  1493.       extern "C" syntax. 
  1494.  
  1495.      by figuring out the mangled name and use it as the Link_Name argument of 
  1496.       the pragma import. 
  1497.  
  1498.  Interfacing at the class level can be achieved by using the GNAT specific 
  1499.  pragmas such as CPP_Class and  CPP_Virtual. See the GNAT Reference Manual for 
  1500.  additional information. 
  1501.  
  1502.  
  1503. ΓòÉΓòÉΓòÉ 5.11.2. Linking a mixed C++ & Ada program ΓòÉΓòÉΓòÉ
  1504.  
  1505.  
  1506.  Usually the linker of the C++ development system must be used to link mixed 
  1507.  applications because most C++ systems will resolve elaboration issues (such as 
  1508.  calling constructors on global class instances) transparently during the link 
  1509.  phase. GNAT has been adapted to ease the use of a foreign linker for the last 
  1510.  phase. Three cases can be considered: 
  1511.  
  1512.    1. Using GNAT and G++ (GNU C++ compiler) from the same GCC installation. The 
  1513.       c++ linker can simply be called by using the c++ specific driver called 
  1514.       c++. Note that this setup is not very common because it may request 
  1515.       recompiling the whole GCC tree from sources and it does not allow to 
  1516.       upgrade easily to a new version of one compiler for one of the two 
  1517.       languages without taking the risk of destabilizing the other. 
  1518.  
  1519.                       $ c++ -c file1.C
  1520.                       $ c++ -c file2.C
  1521.                       $ gnatmake ada_unit -largs file1.o file2.o --LINK=c++
  1522.  
  1523.    2. Using GNAT and G++ from 2 different GCC installations. If both compilers 
  1524.       are on the PATH, the same method can be used. It is important to be aware 
  1525.       that environment variables such as C_INCLUDE_PATH, GCC_EXEC_PREFIX, 
  1526.       BINUTILS_ROOT or GCC_ROOT will affect both compilers at the same time and 
  1527.       thus may make one of the 2 compilers operate improperly if they are set 
  1528.       for the other. In particular it is important that the link command has 
  1529.       access to the proper gcc library 'libgcc.a', that is to say the one that 
  1530.       is part of the C++ compiler installation. The implicit link command as 
  1531.       suggested in the gnatmake command from the former example can be replaced 
  1532.       by an explicit link command with full verbosity in order to verify which 
  1533.       library is used: 
  1534.  
  1535.                       $ gnatbind ada_unit
  1536.                       $ gnatlink -v -v ada_unit file1.o file2.o --LINK=c++
  1537.  If there is a problem due to interfering environment variables, it can be 
  1538.  workaround by using an intermediate script. The following example shows the 
  1539.  proper script to use when GNAT has not been installed at its default location 
  1540.  and g++ has been installed at its default location: 
  1541.  
  1542.                       $ gnatlink -v -v ada_unit file1.o file2.o --LINK=./my_script
  1543.                       $ cat ./my_script
  1544.                       #!/bin/sh
  1545.                       unset BINUTILS_ROOT
  1546.                       unset GCC_ROOT
  1547.                       c++ $*
  1548.  
  1549.    3. Using a non GNU C++ compiler. The same set of command as previously 
  1550.       described can be used to insure that the c++ linker is used. Nonetheless, 
  1551.       the Ada code may implicitly depend on the gcc library. The latter can be 
  1552.       located thanks to gnatls: it is to be found on the last directory of the 
  1553.       object path. It must then be explicitly mentioned in the link command : 
  1554.  
  1555.                       $ gnatls -v
  1556.                       $ Gdir=<the last directory on the object path>
  1557.                       $ gnatlink ada_unit file1.o file2.o -L$Gdir -lgcc \
  1558.                         --LINK=<cpp_linker>
  1559.  
  1560.  
  1561. ΓòÉΓòÉΓòÉ 5.11.3. A simple example ΓòÉΓòÉΓòÉ
  1562.  
  1563.  
  1564.  The following example, provided as part of the GNAT examples, show how to 
  1565.  achieve procedural interfacing between Ada and C++ in both directions. The C++ 
  1566.  class A has 2 methods. The first method is exported to Ada by the means of an 
  1567.  extern C wrapper function. THe second method calls an Ada subprogram. On the 
  1568.  Ada side, The C++ calss is modelized by a limited record with a layout 
  1569.  comparable to the C++ class. The Ada subprogram, in turn, calls the c++ 
  1570.  method. So from the C++ main program the code goes back and forth between the 
  1571.  2 languages. 
  1572.  Here are the compilation commands for native configurations: 
  1573.  
  1574.                       $ gnatmake -c simple_cpp_interface
  1575.                       $ c++ -c cpp_main.C
  1576.                       $ c++ -c ex7.C
  1577.                       $ gnatbind -n simple_cpp_interface
  1578.                       $ gnatlink simple_cpp_interface -o cpp_main --LINK=$(CPLUSPLUS) \
  1579.                         -lstdc++ ex7.o cpp_main.o
  1580.  
  1581.  Here are the corresponding sources: 
  1582.  
  1583.                       //cpp_main.C
  1584.                       #include "ex7.h"
  1585.                       extern "C" {
  1586.                        void adainit (void);
  1587.                        void adafinal (void);
  1588.                        void method1 (A *t);
  1589.                       }
  1590.                       void method1 (A *t)
  1591.                       {
  1592.                        t->method1 ();
  1593.                       }
  1594.                       int main ()
  1595.                       {
  1596.                        A obj;
  1597.                        adainit ();
  1598.                        obj.method2 (3030);
  1599.                        adafinal ();
  1600.                       }
  1601.                       //ex7.h
  1602.                       class Origin {
  1603.                        public:
  1604.                        int o_value;
  1605.                       };
  1606.                       class A : public Origin {
  1607.                        public:
  1608.                        void method1 (void);
  1609.                        virtual void method2 (int v);
  1610.                        A();
  1611.                        int  a_value;
  1612.                       };
  1613.                       //ex7.C
  1614.                       #include "ex7.h"
  1615.                       #include <stdio.h>
  1616.                       extern "C" { void ada_method2 (A *t, int v);}
  1617.                       void A::method1 (void)
  1618.                       {
  1619.                        a_value = 2020;
  1620.                        printf ("in A::method1, a_value = %d \n",a_value);
  1621.                       }
  1622.                       void A::method2 (int v)
  1623.                       {
  1624.                         ada_method2 (this, v);
  1625.                         printf ("in A::method2, a_value = %d \n",a_value);
  1626.                       }
  1627.                       A::A(void)
  1628.                       {
  1629.                         a_value = 1010;
  1630.                        printf ("in A::A, a_value = %d \n",a_value);
  1631.                       }
  1632.                       -- Ada sources
  1633.                       package body Simple_Cpp_Interface is
  1634.                         procedure Ada_Method2 (This : in out A; V : Integer) is
  1635.                         begin
  1636.                          Method1 (This);
  1637.                          This.A_Value := V;
  1638.                         end Ada_Method2;
  1639.                       end Simple_Cpp_Interface;
  1640.                       package Simple_Cpp_Interface is
  1641.                         type A is limited
  1642.                          record
  1643.                            O_Value : Integer;
  1644.                            A_Value : Integer;
  1645.                          end record;
  1646.                         pragma Convention (C, A);
  1647.                         procedure Method1 (This : in out A);
  1648.                         pragma Import (C, Method1);
  1649.                         procedure Ada_Method2 (This : in out A; V : Integer);
  1650.                         pragma Export (C, Ada_Method2);
  1651.                       end Simple_Cpp_Interface;
  1652.  
  1653.  
  1654. ΓòÉΓòÉΓòÉ 5.11.4. Adapting the runtime to a new C++ compiler ΓòÉΓòÉΓòÉ
  1655.  
  1656.  
  1657.  GNAT offers the capability to derive Ada 95 tagged types directly from 
  1658.  preexisting C++ classes and . See "Interfacing with C++" in the GNAT reference 
  1659.  manual. The mechanism used by GNAT for achieving such a goal has been made 
  1660.  user configurable through a GNAT library unit Interfaces.CPP. The default 
  1661.  version of this file is adapted to the GNU c++ compiler. Internal knowledge of 
  1662.  the virtual table layout used by the new C++ compiler is needed to configure 
  1663.  properly this unit. The Interface of this unit is known by the compiler and 
  1664.  cannot be changed except for the value of the constants defining the 
  1665.  characteristics of the virtual table: CPP_DT_Prologue_Size, CPP_DT_Entry_Size, 
  1666.  CPP_TSD_Prologue_Size, CPP_TSD_Entry_Size. Read comments in the source of this 
  1667.  unit for more details. 
  1668.  
  1669.  
  1670. ΓòÉΓòÉΓòÉ 5.12. Comparison between GNAT and C/C++ Compilation Models ΓòÉΓòÉΓòÉ
  1671.  
  1672.  
  1673.  The GNAT model of compilation is close to the C and C++ models. You can think 
  1674.  of Ada specs as corresponding to header files in C. As in C, you don't need to 
  1675.  compile specs; they are compiled when they are used. The Ada with is similar 
  1676.  in effect to the #include of a C header. 
  1677.  
  1678.  One notable difference is that, in Ada, you may compile specs separately to 
  1679.  check them for semantic and syntactic accuracy. This is not always possible 
  1680.  with C headers because they are fragments of programs that have less specific 
  1681.  syntactic or semantic rules. 
  1682.  
  1683.  The other major difference is the requirement for running the binder, which 
  1684.  performs two important functions. First, it checks for consistency. In C or 
  1685.  C++, the only defense against assembling inconsistent programs lies outside 
  1686.  the compiler, in a makefile, for example. The binder satisfies the Ada 
  1687.  requirement that it be impossible to construct an inconsistent program when 
  1688.  the compiler is used in normal mode. 
  1689.  
  1690.  The other important function of the binder is to deal with elaboration issues. 
  1691.  There are also elaboration issues in C++ that are handled automatically. This 
  1692.  automatic handling has the advantage of being simpler to use, but the C++ 
  1693.  programmer has no control over elaboration. Where gnatbind might complain 
  1694.  there was no valid order of elaboration, a C++ compiler would simply construct 
  1695.  a program that malfunctioned at run time. 
  1696.  
  1697.  
  1698. ΓòÉΓòÉΓòÉ 5.13. Comparison between GNAT and Conventional Ada Library Models ΓòÉΓòÉΓòÉ
  1699.  
  1700.  
  1701.  This section is intended to be useful to Ada programmers who have previously 
  1702.  used an Ada compiler implementing the traditional Ada library model, as 
  1703.  described in the Ada 95 Language Reference Manual. If you have not used such a 
  1704.  system, please go on to the next section. 
  1705.  
  1706.  In GNAT, there is no library in the normal sense. Instead, the set of source 
  1707.  files themselves acts as the library. Compiling Ada programs does not generate 
  1708.  any centralized information, but rather an object file and a ALI file, which 
  1709.  are of interest only to the binder and linker. In a traditional system, the 
  1710.  compiler reads information not only from the source file being compiled, but 
  1711.  also from the centralized library. This means that the effect of a compilation 
  1712.  depends on what has been previously compiled. In particular: 
  1713.  
  1714.      When a unit is with'ed, the unit seen by the compiler corresponds to the 
  1715.       version of the unit most recently compiled into the library. 
  1716.  
  1717.      Inlining is effective only if the necessary body has already been 
  1718.       compiled into the library. 
  1719.  
  1720.      Compiling a unit may obsolete other units in the library. 
  1721.  
  1722.  In GNAT, compiling one unit never affects the compilation of any other units 
  1723.  because the compiler reads only source files. Only changes to source files can 
  1724.  affect the results of a compilation. In particular: 
  1725.  
  1726.      When a unit is with'ed, the unit seen by the compiler corresponds to the 
  1727.       source version of the unit that is currently accessible to the compiler. 
  1728.  
  1729.      Inlining requires the appropriate source files for the package or 
  1730.       subprogram bodies to be available to the compiler. Inlining is always 
  1731.       effective, independent of the order in which units are complied. 
  1732.  
  1733.      Compiling a unit never affects any other compilations. The editing of 
  1734.       sources may cause previous compilations to be out of date if they 
  1735.       depended on the source file being modified. 
  1736.  
  1737.  The most important result of these differences is that order of compilation is 
  1738.  never significant in GNAT. There is no situation in which one is required to 
  1739.  do one compilation before another. What shows up as order of compilation 
  1740.  requirements in the traditional Ada library becomes, in GNAT, simple source 
  1741.  dependencies; in other words, there is only a set of rules saying what source 
  1742.  files must be present when a file is compiled. 
  1743.  
  1744.  
  1745. ΓòÉΓòÉΓòÉ 6. Compiling Using gcc ΓòÉΓòÉΓòÉ
  1746.  
  1747.  
  1748.  This chapter discusses how to compile Ada programs using the gcc command. It 
  1749.  also describes the set of switches that can be used to control the behavior of 
  1750.  the compiler. 
  1751.  
  1752.  Compiling Programs            Compiling Programs 
  1753.  Switches for gcc              Switches for gcc 
  1754.  Search Paths and the Run-Time Library (RTL)Search Paths and the Run-Time 
  1755.                                Library (RTL) 
  1756.  Order of Compilation Issues   Order of Compilation Issues 
  1757.  Examples                      Examples 
  1758.  
  1759.  
  1760. ΓòÉΓòÉΓòÉ 6.1. Compiling Programs ΓòÉΓòÉΓòÉ
  1761.  
  1762.  
  1763.  The first step in creating an executable program is to compile the units of 
  1764.  the program using the gcc command. You must compile the following files: 
  1765.  
  1766.      the body file ('.adb') for a library level subprogram or generic 
  1767.       subprogram 
  1768.  
  1769.      the spec file ('.ads') for a library level package or generic package 
  1770.       that has no body 
  1771.  
  1772.      the body file ('.adb') for a library level package or generic package 
  1773.       that has a body 
  1774.  
  1775.  You need not compile the following files 
  1776.  
  1777.      the spec of a library unit which has a body 
  1778.  
  1779.      subunits 
  1780.  
  1781.  because they are compiled as part of compiling related units. GNAT package 
  1782.  specs when the corresponding body is compiled, and subunits when the parent is 
  1783.  compiled. If you attempt to compile any of these files, you will get one of 
  1784.  the following error messages (where fff is the name of the file you compiled): 
  1785.  
  1786.                       No code generated for file fff (package spec)
  1787.                       No code generated for file fff (subunit)
  1788.  
  1789.  The basic command for compiling a file containing an Ada unit is 
  1790.  
  1791.                       $ gcc -c [switches] 'file name'
  1792.  
  1793.  where file name is the name of the Ada file (usually having an extension 
  1794.  '.ads' for a spec or '.adb' for a body). You specify the -c switch to tell gcc 
  1795.  to compile, but not link, the file. The result of a successful compilation is 
  1796.  an object file, which has the same name as the source file but an extension of 
  1797.  '.o' and an Ada Library Information (ALI) file, which also has the same name 
  1798.  as the source file, but with '.ali' as the extension. GNAT creates these two 
  1799.  output files in the current directory, but you may specify a source file in 
  1800.  any directory using an absolute or relative path specification containing the 
  1801.  directory information. 
  1802.  
  1803.  gcc is actually a driver program that looks at the extensions of the file 
  1804.  arguments and loads the appropriate compiler. For example, the GNU C compiler 
  1805.  is 'cc1', and the Ada compiler is 'gnat1'. These programs are in directories 
  1806.  known to the driver program (in some configurations via environment variables 
  1807.  you set), but need not be in your path. The gcc driver also calls the 
  1808.  assembler and any other utilities needed to complete the generation of the 
  1809.  required object files. 
  1810.  
  1811.  It is possible to supply several file names on the same gcc command. This 
  1812.  causes gcc to call the appropriate compiler for each file. For example, the 
  1813.  following command lists three separate files to be compiled: 
  1814.  
  1815.                       $ gcc -c x.adb y.adb z.c
  1816.  
  1817.  calls gnat1 (the Ada compiler) twice to compile 'x.adb' and 'y.adb', and cc1 
  1818.  (the C compiler) once to compile 'z.c'. The compiler generates three object 
  1819.  files 'x.o', 'y.o' and 'z.o' and the two ALI files 'x.ali' and 'y.ali' from 
  1820.  the Ada compilations. Any switches apply to all the files listed, except for 
  1821.  -gnatx switches, which apply only to Ada compilations. 
  1822.  
  1823.  
  1824. ΓòÉΓòÉΓòÉ 6.2. Switches for gcc ΓòÉΓòÉΓòÉ
  1825.  
  1826.  
  1827.  The gcc command accepts numerous switches to control the compilation process. 
  1828.  These switches are fully described in this section. 
  1829.  
  1830.  Output and Error Message ControlOutput and Error Message Control 
  1831.  Debugging and Assertion ControlDebugging and Assertion Control 
  1832.  Run-time Checks               Run-time Checks 
  1833.  Stack Overflow Checking       Stack Overflow Checking 
  1834.  Run-time Control              Run-time Control 
  1835.  Style Checking                Style Checking 
  1836.  Using gcc for Syntax Checking Using gcc for Syntax Checking 
  1837.  Using gcc for Semantic CheckingUsing gcc for Semantic Checking 
  1838.  Compiling Ada 83 Programs     Compiling Ada 83 Programs 
  1839.  Reference Manual Style CheckingReference Manual Style Checking 
  1840.  Character Set Control         Character Set Control 
  1841.  File Naming Control           File Naming Control 
  1842.  Subprogram Inlining Control   Subprogram Inlining Control 
  1843.  Auxiliary Output Control      Auxiliary Output Control 
  1844.  Debugging Control             Debugging Control 
  1845.  
  1846.  -b target 
  1847.            Compile your program to run on target, which is the name of a system 
  1848.            configuration. You must have a GNAT cross-compiler built if target 
  1849.            is not the same as your host system. 
  1850.  
  1851.  -Bdir 
  1852.            Load compiler executables (for example, gnat1, the Ada compiler) 
  1853.            from dir instead of the default location. Only use this switch when 
  1854.            multiple versions of the GNAT compiler are available. See the gcc 
  1855.            manual page for further details. You would normally use the -b or -V 
  1856.            switch instead. 
  1857.  
  1858.  -c 
  1859.            Compile. Always use this switch when compiling Ada programs. 
  1860.  
  1861.            Note that you may not use gcc without a -c switch to compile and 
  1862.            link in one step. This is because the binder must be run, and 
  1863.            currently gcc cannot be used to run the GNAT binder. 
  1864.  
  1865.  -g 
  1866.            Generate debugging information. This information is stored in the 
  1867.            object file and copied from there to the final executable file by 
  1868.            the linker, where it can be read by the debugger. You must use the 
  1869.            -g switch if you plan on using the debugger. 
  1870.  
  1871.  -Idir 
  1872.            Direct GNAT to search the dir directory for source files needed by 
  1873.            the current compilation (see Search Paths and the Run-Time Library 
  1874.            (RTL)). 
  1875.  
  1876.  -I- 
  1877.            Do not look for source files in the directory containing the source 
  1878.            file named in the command line (see Search Paths and the Run-Time 
  1879.            Library (RTL)). 
  1880.  
  1881.  -o file 
  1882.            This switch is used in gcc to redirect the generated object file and 
  1883.            its associated ALI file. Beware of this switch with GNAT, because it 
  1884.            may cause the object file and ALI file to have different names which 
  1885.            in turn may confuse the binder and the linker. 
  1886.  
  1887.  -O[n] 
  1888.            n controls the optimization level. 
  1889.  
  1890.              n = 0 
  1891.                          No optimization, the default setting if no -O appears 
  1892.  
  1893.              n = 1 
  1894.                          Normal optimization, the default if you specify -O 
  1895.                          without an operand. 
  1896.  
  1897.              n = 2 
  1898.                          Extensive optimization 
  1899.  
  1900.              n = 3 
  1901.                          Extensive optimization with automatic inlining. This 
  1902.                          applies only to inlining within a unit. For details on 
  1903.                          control of inter-unit inlining see See Subprogram 
  1904.                          Inlining Control. 
  1905.  
  1906.  -S 
  1907.            Used in place of -c to cause the assembler source file to be 
  1908.            generated, using '.s' as the extension, instead of the object file. 
  1909.            This may be useful if you need to examine the generated assembly 
  1910.            code. 
  1911.  
  1912.  -v 
  1913.            Show commands generated by the gcc driver. Normally used only for 
  1914.            debugging purposes or if you need to be sure what version of the 
  1915.            compiler you are executing. 
  1916.  
  1917.  -V ver 
  1918.            Execute ver version of the compiler. This is the gcc version, not 
  1919.            the GNAT version. 
  1920.  
  1921.  -funwind-tables 
  1922.            This switch causes the object files to be generated with unwind 
  1923.            table information. This is required for use of zero cost exception 
  1924.            handling, of for use of the trace capabilities in the GNAT library. 
  1925.  
  1926.  -gnata 
  1927.            Assertions enabled. Pragma Assert and pragma Debug to be activated. 
  1928.  
  1929.  -gnatb 
  1930.            Generate brief messages to stderr even if verbose mode set. 
  1931.  
  1932.  -gnatc 
  1933.            Check syntax and semantics only (no code generation attempted). 
  1934.  
  1935.  -gnatD 
  1936.            Output expanded source files for source level debugging. This switch 
  1937.            also suppress generation of cross-reference information (see 
  1938.            -gnatx). 
  1939.  
  1940.  -gnate 
  1941.            Force error message generation (for use when compiler crashes). 
  1942.  
  1943.  -gnatE 
  1944.            Full dynamic elaboration checks. 
  1945.  
  1946.  -gnatf 
  1947.            Full errors. Multiple errors per line, all undefined references. 
  1948.  
  1949.  -gnatF 
  1950.            Externals names are folded to all uppercase. 
  1951.  
  1952.  -gnatg 
  1953.            GNAT style checks enabled. 
  1954.  
  1955.  -gnatG 
  1956.            List generated expanded code in source form. 
  1957.  
  1958.  -gnatic 
  1959.            Identifier character set (c=1/2/3/4/8/p/f/n/w). 
  1960.  
  1961.  -gnath 
  1962.            Output usage information. The output is written to stdout. 
  1963.  
  1964.  -gnatkn 
  1965.            Limit file names to n (1-999) characters (k = krunch). 
  1966.  
  1967.  -gnatl 
  1968.            Output full source listing with embedded error messages. 
  1969.  
  1970.  -gnatmn 
  1971.            Limit number of detected errors to n (1-999). 
  1972.  
  1973.  -gnatn 
  1974.            Activate inlining across unit boundaries for subprograms for which 
  1975.            pragma inline is specified. 
  1976.  
  1977.  -fno-inline 
  1978.            Suppresses all inlining, even if other optimization or inlining 
  1979.            switches are set. 
  1980.  
  1981.  -fstack-check 
  1982.            Activates stack checking. See separate section on stack checking for 
  1983.            details of the use of this option. 
  1984.  
  1985.  -gnato 
  1986.            Enable other checks, not normally enabled by default, including 
  1987.            numeric overflow checking, and access before elaboration checks. 
  1988.  
  1989.  -gnatp 
  1990.            Suppress all checks. 
  1991.  
  1992.  -gnatq 
  1993.            Don't quit; try semantics, even if parse errors. 
  1994.  
  1995.  -gnatP 
  1996.            Enable polling. This is required on some systems (notably Windows 
  1997.            NT) to obtain asynchronous abort and asynchronous transfer of 
  1998.            control capability. See the description of pragma Polling in the 
  1999.            GNAT Reference Manual for full details. 
  2000.  
  2001.  -gnatR 
  2002.            Output representation information for declared array and record 
  2003.            types. 
  2004.  
  2005.  -gnats 
  2006.            Syntax check only. 
  2007.  
  2008.  -gnatt 
  2009.            Tree output file to be generated. 
  2010.  
  2011.  -gnatT nnn 
  2012.            Set time slice to specified number of microseconds 
  2013.  
  2014.  -gnatu 
  2015.            List units for this compilation. 
  2016.  
  2017.  -gnatU 
  2018.            Tag all error messages with the unique string "error:" 
  2019.  
  2020.  -gnatv 
  2021.            Verbose mode. Full error output with source lines to stdout. 
  2022.  
  2023.  -gnatwm 
  2024.            Warning mode (m=s,e,l for suppress, treat as error, elaboration 
  2025.            warnings). 
  2026.  
  2027.  -gnatWe 
  2028.            Wide character encoding method (e=n/h/u/s/e/8). 
  2029.  
  2030.  -gnatx 
  2031.            Suppress generation of cross-reference information. 
  2032.  
  2033.  -gnatwm 
  2034.            Warning mode 
  2035.  
  2036.  -gnaty 
  2037.            Enable built-in style checks. See separate section describing this 
  2038.            feature. 
  2039.  
  2040.  -gnatzm 
  2041.            Distribution stub generation and compilation (m=r/c for 
  2042.            receiver/caller stubs). 
  2043.  
  2044.  -gnat83 
  2045.            Enforce Ada 83 restrictions. 
  2046.  
  2047.  -gnat95 
  2048.            Standard Ada 95 mode 
  2049.  
  2050.  You may combine a sequence of GNAT switches into a single switch. For example, 
  2051.  the combined switch 
  2052.  
  2053.                       -gnatcfi3
  2054.  
  2055.  is equivalent to specifying the following sequence of switches: 
  2056.  
  2057.                       -gnatc -gnatf -gnati3
  2058.  
  2059.  
  2060. ΓòÉΓòÉΓòÉ 6.2.1. Output and Error Message Control ΓòÉΓòÉΓòÉ
  2061.  
  2062.  
  2063.  The standard default format for error messages is called "brief format." Brief 
  2064.  format messages are written to stderr (the standard error file) and have the 
  2065.  following form: 
  2066.  
  2067.                       e.adb:3:04: Incorrect spelling of keyword "function"
  2068.                       e.adb:4:20: ";" should be "is"
  2069.  
  2070.  The first integer after the file name is the line number in the file, and the 
  2071.  second integer is the column number within the line. emacs can parse the error 
  2072.  messages and point to the referenced character. The following switches provide 
  2073.  control over the error message format: 
  2074.  
  2075.  -gnatv 
  2076.            The v stands for verbose. The effect of this setting is to write 
  2077.            long-format error messages to stdout (the standard output file. The 
  2078.            same program compiled with the -gnatv switch would generate: 
  2079.  
  2080.                       3. funcion X (Q : Integer)
  2081.                         |
  2082.                       >>> Incorrect spelling of keyword "function"
  2083.                       4. return Integer;
  2084.                                |
  2085.                       >>> ";" should be "is"
  2086.  
  2087.  The vertical bar indicates the location of the error, and the '>>>' prefix can 
  2088.  be used to search for error messages. When this switch is used the only source 
  2089.  lines output are those with errors. 
  2090.  
  2091.  -gnatl 
  2092.            The l stands for list. This switch causes a full listing of the file 
  2093.            to be generated. The output might look as follows: 
  2094.  
  2095.                        1. procedure E is
  2096.                        2.   V : Integer;
  2097.                        3.   funcion X (Q : Integer)
  2098.                           |
  2099.                         >>> Incorrect spelling of keyword "function"
  2100.                        4.   return Integer;
  2101.                                  |
  2102.                         >>> ";" should be "is"
  2103.                        5.   begin
  2104.                        6.    return Q + Q;
  2105.                        7.   end;
  2106.                        8. begin
  2107.                        9.   V := X + X;
  2108.                       10.end E;
  2109.  
  2110.  When you specify the -gnatv or -gnatl switches and standard output is 
  2111.  redirected, a brief summary is written to stderr (standard error) giving the 
  2112.  number of error messages and warning messages generated. 
  2113.  
  2114.  -gnatU 
  2115.            This switch forces all error messages to be preceded by the unique 
  2116.            string "error:". This means that error messages take a few more 
  2117.            characters in space, but allows easy searching for and 
  2118.            identification of error messages. 
  2119.  
  2120.  -gnatb 
  2121.            The b stands for brief. This switch causes GNAT to generate the 
  2122.            brief format error messages to stderr (the standard error file) as 
  2123.            well as the verbose format message or full listing (which as usual 
  2124.            is written to stdout (the standard output file). 
  2125.  
  2126.  -gnatmn 
  2127.            The m stands for maximum. n is a decimal integer in the range of 1 
  2128.            to 999 and limits the number of error messages to be generated. For 
  2129.            example, using -gnatm2 might yield 
  2130.  
  2131.                       e.adb:3:04: Incorrect spelling of keyword "function"
  2132.                       e.adb:5:35: missing "┬╖┬╖"
  2133.                       fatal error: maximum errors reached
  2134.                       compilation abandoned
  2135.  
  2136.  -gnatf 
  2137.            The f stands for full. Normally, the compiler suppresses error 
  2138.            messages that are likely to be redundant. This switch causes all 
  2139.            error messages to be generated. In particular, in the case of 
  2140.            references to undefined variables. If a given variable is referenced 
  2141.            several times, the normal format of messages is 
  2142.  
  2143.                       e.adb:7:07: "V" is undefined (more references follow)
  2144.  
  2145.  where the parenthetical comment warns that there are additional references to 
  2146.  the variable V. Compiling the same program with the -gnatf switch yields 
  2147.  
  2148.                       e.adb:7:07: "V" is undefined
  2149.                       e.adb:8:07: "V" is undefined
  2150.                       e.adb:8:12: "V" is undefined
  2151.                       e.adb:8:16: "V" is undefined
  2152.                       e.adb:9:07: "V" is undefined
  2153.                       e.adb:9:12: "V" is undefined
  2154.  
  2155.  -gnatq 
  2156.            The q stands for quit (really "don't quit"). In normal operation 
  2157.            mode, the compiler first parses the program and determines if there 
  2158.            are any syntax errors. If there are, appropriate error messages are 
  2159.            generated and compilation is immediately terminated. This switch 
  2160.            tells GNAT to continue with semantic analysis even if syntax errors 
  2161.            have been found. This may enable the detection of more errors in a 
  2162.            single run. On the other hand, the semantic analyzer is more likely 
  2163.            to encounter some internal fatal error when given a syntactically 
  2164.            invalid tree. 
  2165.  
  2166.  -gnate 
  2167.            Normally, the compiler saves up error messages and generates them at 
  2168.            the end of compilation in proper sequence. This switch  (the 'e' 
  2169.            stands for error) causes error messages to be generated as soon as 
  2170.            they are detected. The use of -gnate may cause error messages to be 
  2171.            generated out of sequence and also disconnects a number of useful 
  2172.            error message processing circuits. This switch should be used only 
  2173.            in error situations where the compiler terminates with no output at 
  2174.            all, or goes into an infinite loop. In such cases, the -gnate switch 
  2175.            may be used to see if any error situations were detected before the 
  2176.            compiler crash (see GNAT Abnormal Termination). 
  2177.  
  2178.  In addition to error messages, which correspond to illegalities as defined in 
  2179.  the Ada 95 Reference Manual, the compiler detects two kinds of warning 
  2180.  situations. 
  2181.  
  2182.  First, the compiler considers some constructs suspicious and generates a 
  2183.  warning message to alert you to a possible error. Second, if the compiler 
  2184.  detects a situation that is sure to raise an exception at run time, it 
  2185.  generates a warning message. The following shows an example of warning 
  2186.  messages: 
  2187.  
  2188.                       e.adb:4:24: warning: creation of object may raise Storage_Error
  2189.                       e.adb:10:17: warning: static value out of range
  2190.                       e.adb:10:17: warning: "Constraint_Error" will be raised at run time
  2191.  
  2192.  GNAT considers a large number of situations as appropriate for the generation 
  2193.  of warning messages. As always, warnings are not definite indications of 
  2194.  errors. For example, if you do an out-of-range assignment with the deliberate 
  2195.  intention of raising a Constraint_Error exception, then the warning that may 
  2196.  be issued does not indicate an error. Some of the situations for which GNAT 
  2197.  issues warnings (at least some of the time) are: 
  2198.  
  2199.      Possible infinitely recursive calls 
  2200.  
  2201.      Out-of-range values being assigned 
  2202.  
  2203.      Possible order of elaboration problems 
  2204.  
  2205.      Unreachable code 
  2206.  
  2207.      Variables that are never assigned a value 
  2208.  
  2209.      Variables that are referenced before being initialized 
  2210.  
  2211.      Task entries with no corresponding Accept statement 
  2212.  
  2213.      Duplicate Accepts for the same task entry in a select 
  2214.  
  2215.      Objects that take too much storage 
  2216.  
  2217.      Unchecked conversion between types of differing sizes 
  2218.  
  2219.      Missing return statements along some execution paths in a function 
  2220.  
  2221.      Incorrect pragmas 
  2222.  
  2223.      Incorrect external names 
  2224.  
  2225.      Allocation from empty storage pool 
  2226.  
  2227.      Potentially blocking operations in protected types 
  2228.  
  2229.      Suspicious parenthesization of expressions 
  2230.  
  2231.      Mismatching bounds in an aggregate 
  2232.  
  2233.      Attempt to return local value by reference 
  2234.  
  2235.      Unrecognized pragmas 
  2236.  
  2237.      Premature instantiation of a generic body 
  2238.  
  2239.      Attempt to pack aliased components 
  2240.  
  2241.      Out of bounds array subscripts 
  2242.  
  2243.      Wrong length on string assignment 
  2244.  
  2245.  The following switches are available to control the handling of warning 
  2246.  messages: 
  2247.  
  2248.  -gnatwa (activate all optional errors) 
  2249.            This swich activates all optional warning messages, see remaining 
  2250.            list in this section for details on optional warning messages that 
  2251.            can be individually controlled. 
  2252.  
  2253.  -gnatwA (suppress all optional errors) 
  2254.            This swich suppresses all optional warning messages, see remaining 
  2255.            list in this section for details on optional warning messages that 
  2256.            can be individually controlled. 
  2257.  
  2258.  -gnatwc (activate warnings on conditionals) 
  2259.            This switch activates warnings for conditional expressions used in 
  2260.            tests that are known to be True or False at compile time. The 
  2261.            default is that such warnings are not generated. 
  2262.  
  2263.  -gnatwC (suppress warnings on conditionals) 
  2264.            This switch suppresses warnings for conditional expressions used in 
  2265.            tests that are known to be True or False at compile time. 
  2266.  
  2267.  -gnatwe (treat warnings as errors) 
  2268.            This switch causes warning messages to be treated as errors. The 
  2269.            warning string still appears, but the warning messages are counted 
  2270.            as errors, and prevent the generation of an object file. 
  2271.  
  2272.  -gnatwl (activate warnings on elaboration pragmas) 
  2273.            This swich activates warnings on missing pragma Elaborate_All 
  2274.            statements. See the section in this guide on elaboration checking 
  2275.            for details on when such pragma should be used. The default is that 
  2276.            such warnings are not generated. 
  2277.  
  2278.  -gnatwL (suppress warnings on elaboration pragmas) 
  2279.            This swich suppresses warnings on missing pragma Elaborate_All 
  2280.            statements. See the section in this guide on elaboration checking 
  2281.            for details on when such pragma should be used. 
  2282.  
  2283.  -gnatws (suppress all warnings) 
  2284.            This switch completely suppresses the output of all warning 
  2285.            messages. 
  2286.  
  2287.  -gnatwu (activate warnings on unused entities) 
  2288.            This switch activates warnings to be generated for entities that are 
  2289.            defined but not referenced, and for units that are with'ed and not 
  2290.            referenced. In the case of packages, a warning is also generated if 
  2291.            no entities in the package are referenced. This means that if the 
  2292.            package is referenced but the only references are in use clauses or 
  2293.            renames declarations, a warning is still generated. A warning is 
  2294.            also generated for a generic package that is with'ed but never 
  2295.            instantiated. In the case where a package or subprogram body is 
  2296.            compiled, and there is a with on the corresponding spec that is only 
  2297.            referenced in the body, a warning is also generated, noting that the 
  2298.            with can be moved to the body. The default is that such warnings are 
  2299.            not generated. 
  2300.  
  2301.  -gnatwU (suppress warnings on unused entities) 
  2302.            This switch suppresses warnings for unused entities and packages. 
  2303.            A string of warning parameters can be used in the same parameter. 
  2304.            For example: 
  2305.  
  2306.                       -gnatwaLe
  2307.  
  2308.  Would turn on all optional warnings except for elaboration pragma warnings, 
  2309.  and also specify that warnings should be treated as errors. 
  2310.  
  2311.  -gnatR 
  2312.            Use of the switch -gnatR causes the compiler to output a listing 
  2313.            showing representation information for declared array and record 
  2314.            types, including record representation clauses. 
  2315.  
  2316.  -gnatx 
  2317.            Normally the compiler generates full cross-referencing information 
  2318.            in the 'ALI' file. This information is used by a number of tools, 
  2319.            including gnatfind and gnatxref. The -gnatx switch suppresses this 
  2320.            information. This saves some space and may slightly speed up 
  2321.            compilation, but means that these tools cannot be used. 
  2322.  
  2323.  
  2324. ΓòÉΓòÉΓòÉ 6.2.2. Debugging and Assertion Control ΓòÉΓòÉΓòÉ
  2325.  
  2326.  -gnata 
  2327.  
  2328.            The pragmas Assert and Debug normally have no effect and are 
  2329.            ignored. This switch, where 'a' stands for assert, causes Assert and 
  2330.            Debug pragmas to be activated. 
  2331.  
  2332.            The pragmas have the form: 
  2333.  
  2334.                         pragma Assert (Boolean-expression [,
  2335.                                  static-string-expression])
  2336.                         pragma Debug (procedure call)
  2337.  
  2338.  The Assert pragma causes Boolean-expression to be tested. If the result is 
  2339.  True, the pragma has no effect (other than possible side effects from 
  2340.  evaluating the expression). If the result is False, the exception Assert_Error 
  2341.  declared in the package System.Assertions is raised (passing 
  2342.  static-string-expression, if present, as the message associated with the 
  2343.  exception). If no string expression is given the default is a string giving 
  2344.  the file name and line number of the pragma. 
  2345.  
  2346.  The Debug pragma causes procedure to be called. Note that pragma Debug may 
  2347.  appear within a declaration sequence, allowing debugging procedures to be 
  2348.  called between declarations. 
  2349.  
  2350.  
  2351. ΓòÉΓòÉΓòÉ 6.2.3. Style Checking ΓòÉΓòÉΓòÉ
  2352.  
  2353.  
  2354.  The -gnatyx switch causes the compiler to enforce specified style rules. A 
  2355.  limited set of style rules has been used in writing the GNAT sources 
  2356.  themselves. This switch allows user programs to activate all or some of these 
  2357.  checks. If the source program fails a specified style check, an appropriate 
  2358.  error message is given, preceded by the character sequence "(style)", and the 
  2359.  program is considered illegal. The string x is a sequence of letters or digits 
  2360.  indicating the particular style checks to be performed. The following checks 
  2361.  are defined: 
  2362.  
  2363.  1-9 (specify indentation level) 
  2364.            If a digit from 1-9 appears in the string after -gnaty then proper 
  2365.            indentation is checked, with the digit indicating the indentation 
  2366.            level required. The general style of required indentation is as 
  2367.            specified by the examples in the Ada Reference Manual. Full line 
  2368.            comments must be aligned with the -- starting on a column that is a 
  2369.            multiple of the alignment level. 
  2370.  
  2371.  a (check attribute casing) 
  2372.            If the letter a appears in the string after -gnaty then attribute 
  2373.            names, including the case of keywords such as digits used as 
  2374.            attributes names, must be written in mixed case, that is, the 
  2375.            initial letter and any letter following an underscore must be 
  2376.            uppercase. All other letters must be lowercase. 
  2377.  
  2378.  b (blanks not allowed at statement end) 
  2379.            If the letter b appears in the string after -gnaty then trailing 
  2380.            blanks are not allowed at the end of statements. The purpose of this 
  2381.            rule, together with h (no horizontal tabs), is to enforce a 
  2382.            canonical format for the use of blanks to separate source tokens. 
  2383.  
  2384.  c (check comments) 
  2385.            If the letter c appears in the string after -gnaty then comments 
  2386.            must meet the following set of rules: 
  2387.  
  2388.                1. The "--" that starts the column must either start in column 
  2389.                   one, or else at least one blank must precede this sequence. 
  2390.  
  2391.                2. Comments that follow other tokens on a line must have at 
  2392.                   least one blank following the "--" at the start of the 
  2393.                   comment. 
  2394.  
  2395.                3. Full line comments must have two blanks following the "--" 
  2396.                   that starts the comment, with the following exceptions. 
  2397.  
  2398.                4. A line consisting only of the "--" characters, possibly 
  2399.                   preceded by blanks is permitted. 
  2400.  
  2401.                5. A comment starting with "--!" is permitted. This allows 
  2402.                   proper processing of the output generated by the gnatprep 
  2403.                   tool. 
  2404.  
  2405.                6. A line consisting entirely of minus signs, possibly preceded 
  2406.                   by blanks, is permitted. This allows the construction of box 
  2407.                   comments where lines of minus signs are used to form the top 
  2408.                   and bottom of the box. 
  2409.  
  2410.                7. If a comment starts and ends with "--" is permitted as long 
  2411.                   as at least one blank follows the initial "--". Together with 
  2412.                   the preceding rule, this allows the construction of box 
  2413.                   comments, as shown in the following example: 
  2414.  
  2415.                                                         ---------------------------
  2416.                                                         -- This is a box comment --
  2417.                                                         -- with two text lines.  --
  2418.                                                         ---------------------------
  2419.  
  2420.  e (check end labels) 
  2421.            If the letter e appears in the string after -gnaty then optional 
  2422.            labels on end statements ending subprograms are required to be 
  2423.            present. 
  2424.  
  2425.  f (no form feeds or vertical tabs) 
  2426.            If the letter f appears in the string after -gnaty then neither form 
  2427.            feeds nor vertical tab characters are not permitted in the source 
  2428.            text. 
  2429.  
  2430.  h (no horizontal tabs) 
  2431.            If the letter h appears in the string after -gnaty then horizontal 
  2432.            tab characters are not permitted in the source text. Together with 
  2433.            the b (no blanks at end of line) check, this enforces a canonical 
  2434.            form for the use of blanks to separate source tokens. 
  2435.  
  2436.  i (check if-then layout) 
  2437.            If the letter i appears in the string after -gnaty, then the keyword 
  2438.            then must appear either on the same line as corresponding if, or on 
  2439.            a line on its own, lined up under the if with at least one non-blank 
  2440.            line in between containing all or part of the condition to be 
  2441.            tested. 
  2442.  
  2443.  k (check keyword casing) 
  2444.            If the letter k appears in the string after -gnaty then all keywords 
  2445.            must be in lower case (with the exception of keywords such as digits 
  2446.            used as attribute names to which this check does not apply). 
  2447.  
  2448.  l (check layout) 
  2449.            If the letter l appears in the string after -gnaty then layout of 
  2450.            statement and declaration constructs must follow the recommendations 
  2451.            in the Ada Reference Manual, as indicated by the form of the syntax 
  2452.            rules. For example an else keyword must be lined up with the 
  2453.            corresponding if keyword. 
  2454.  
  2455.            There are two respects in which the style rule enforced by this 
  2456.            check option are more liberal than those in the Ada Reference 
  2457.            Manual. First in the case of record declarations, it is permissible 
  2458.            to put the record keyword on the same line as the type keyword, and 
  2459.            then the end in end record must line up under type. For example, 
  2460.            either of the following two layouts is acceptable: 
  2461.  
  2462.                                               type q is record
  2463.                                                 a : integer;
  2464.                                                 b : integer;
  2465.                                               end record;
  2466.                                               type q is
  2467.                                                 record
  2468.                                                  a : integer;
  2469.                                                  b : integer;
  2470.                                                 end record;
  2471.  
  2472.              Second, in the case of a block statement, a permitted alternative 
  2473.              is to put the block label on the same line as the declare or begin 
  2474.              keyword, and then line the end keyword up under the block label. 
  2475.              For example both the following are permitted: 
  2476.  
  2477.                                               Block : declare
  2478.                                                 A : Integer := 3;
  2479.                                               begin
  2480.                                                 Proc (A, A);
  2481.                                               end Block;
  2482.                                               Block :
  2483.                                                 declare
  2484.                                                  A : Integer := 3;
  2485.                                                 begin
  2486.                                                  Proc (A, A);
  2487.                                                 end Block;
  2488.  
  2489.              The same alternative format is allowed for loops. For example, 
  2490.              both of the following are permitted: 
  2491.  
  2492.                                               Clear : while J < 10 loop
  2493.                                                 A (J) := 0;
  2494.                                               end loop Clear;
  2495.                                               Clear :
  2496.                                                 while J < 10 loop
  2497.                                                  A (J) := 0;
  2498.                                                 end loop Clear;
  2499.  
  2500.  m (check maximum line length) 
  2501.            If the letter m appears in the string after -gnaty then the length 
  2502.            of source lines must not exceed 79 characters, including any 
  2503.            trailing blanks. The value of 79 allows convenient display on an 80 
  2504.            character wide device or window, allowing for possible special 
  2505.            treatment of 80 character lines. 
  2506.  
  2507.  Mnnn (set maximum line length) 
  2508.            If the sequence Mnnn, where nnn is a decimal number, appears in the 
  2509.            string after -gnaty then the length of lines must not exceed the 
  2510.            given value. 
  2511.  
  2512.  n (check casing of entities in Standard) 
  2513.            If the letter n appears in the string after -gnaty then any 
  2514.            identifier from Standard must be cased to match the presentation in 
  2515.            the Ada Reference Manual (for example, Integer and ASCII.NUL). 
  2516.  
  2517.  p (check pragma casing) 
  2518.            If the letter p appears in the string after -gnaty then pragma names 
  2519.            must be written in mixed case, that is, the initial letter and any 
  2520.            letter following an underscore must be uppercase. All other letters 
  2521.            must be lowercase. 
  2522.  
  2523.  r (check references) 
  2524.            If the letter r appears in the string after -gnaty then all 
  2525.            identifier references must be cased in the same way as the 
  2526.            corresponding declaration. No specific casing style is imposed on 
  2527.            identifiers. The only requirement is for consistency of references 
  2528.            with declarations. 
  2529.  
  2530.  s (check separate specs) 
  2531.            If the letter s appears in the string after -gnaty then separate 
  2532.            declarations ("specs") are required for subprograms (a body is not 
  2533.            allowed to serve as its own declaration). The only exception is that 
  2534.            parameterless library level procedures are not required to have a 
  2535.            separate declaration. This exception covers the most frequent form 
  2536.            of main program procedures. 
  2537.  
  2538.  t (check token spacing) 
  2539.            If the letter t appears in the string after -gnaty then the 
  2540.            following token spacing rules are enforced: 
  2541.  
  2542.                1. The keywords abs and not must be followed by a space. 
  2543.  
  2544.                2. The token => must be surrounded by spaces. 
  2545.  
  2546.                3. The token <> must be preceded by a space or a left 
  2547.                   parenthesis. 
  2548.  
  2549.                4. Binary operators other than ** must be surrounded by spaces. 
  2550.                   There is no restriction on the layout of the ** binary 
  2551.                   operator. 
  2552.  
  2553.                5. Colon must be surrounded by spaces. 
  2554.  
  2555.                6. Colon-equal (assignment) must be surrounded by spaces. 
  2556.  
  2557.                7. Comma must be the first non-blank character on the line, or 
  2558.                   be immediately preceded by a non-blank character, and must be 
  2559.                   followed by a space. 
  2560.  
  2561.                8. Left parenthesis must be preceded by a space, and must not be 
  2562.                   followed by a space (it can be at the end of a line). 
  2563.  
  2564.                9. A right parenthesis must either be the first non-blank 
  2565.                   character on a line, or it must be preceded by a non-blank 
  2566.                   character. 
  2567.  
  2568.                10.A semicolon must not be preceded by a space, and must not be 
  2569.                   followed by a non-blank character. 
  2570.  
  2571.                11.A unary plus or minus may not be followed by a space. 
  2572.  
  2573.                12.A vertical bar must be surrounded by spaces. 
  2574.  
  2575.  
  2576.              In the above rules, appearing in column one is always permitted, 
  2577.              that is, counts as meeting either a requirement for a required 
  2578.              preceding space, or as meeting a requirement for no preceding 
  2579.              space. 
  2580.  
  2581.              Appearing at the end of a line is also always permitted, that is, 
  2582.              counts as meeting either a requirement for a following space, or 
  2583.              as meeting a requirement for no following space. 
  2584.  
  2585.  The switch -gnaty on its own (that is not followed by any letters or digits), 
  2586.  is equivalent to gnaty3abcefhiklmprst, that is all checking options are 
  2587.  enabled, with an indentation level of 3. This is the standard checking option 
  2588.  that is used for the GNAT sources. 
  2589.  
  2590.  
  2591. ΓòÉΓòÉΓòÉ 6.2.4. Run-time Checks ΓòÉΓòÉΓòÉ
  2592.  
  2593.  
  2594.  If you compile with the default options, GNAT will insert many run-time checks 
  2595.  into the compiled code, including code that performs range checking against 
  2596.  constraints, but not arithmetic overflow checking for integer operations 
  2597.  (including division by zero) or checks for access before elaboration on 
  2598.  subprogram calls. All other run-time checks, as required by the Ada 95 
  2599.  Reference Manual, are generated by default. The following gcc switches refine 
  2600.  this default behavior: 
  2601.  
  2602.  -gnatp 
  2603.            Suppress all run-time checks as though pragma Suppress (all_checks) 
  2604.            had been present in the source. Use this switch to improve the 
  2605.            performance of the code at the expense of safety in the presence of 
  2606.            invalid data or program bugs. 
  2607.  
  2608.  -gnato 
  2609.            Enables overflow checking for integer operations. This causes GNAT 
  2610.            to generate slower and larger executable programs by adding code to 
  2611.            check for both overflow and division by zero (resulting in raising 
  2612.            Constraint_Error as required by Ada semantics). Note that the -gnato 
  2613.            switch does not affect the code generated for any floating-point 
  2614.            operations; it applies only to integer operations. For 
  2615.            floating-point, GNAT has the Machine_Overflows attribute set to 
  2616.            False and the normal mode of operation is to generate IEEE NaN and 
  2617.            infinite values on overflow or invalid operations (such as dividing 
  2618.            0.0 by 0.0). 
  2619.  
  2620.  -gnatE 
  2621.            Enables dynamic checks for access-before-elaboration on subprogram 
  2622.            calls and generic instantiations. For full details of the effect and 
  2623.            use of this switch, See Compiling Using gcc. 
  2624.  
  2625.  The setting of these switches only controls the default setting of the checks. 
  2626.  You may modify them using either Suppress (to remove checks) or Unsuppress (to 
  2627.  add back suppressed checks) pragmas in the program source. 
  2628.  
  2629.  
  2630. ΓòÉΓòÉΓòÉ 6.2.5. Stack Overflow Checking ΓòÉΓòÉΓòÉ
  2631.  
  2632.  
  2633.  For most operating systems, gcc does not perform stack overflow checking by 
  2634.  default. This means that if the main environment task or some other task 
  2635.  exceeds the available stack space, then unpredictable behavior will occur. 
  2636.  
  2637.  To activate stack checking, compile all units with the gcc option 
  2638.  -fstack-check. For example: 
  2639.  
  2640.                       gcc -c -fstack-check package1.adb
  2641.  
  2642.  Units compiled with this option will generate extra instructions to check that 
  2643.  any use of the stack (for procedure calls or for declaring local variables in 
  2644.  declare blocks) do not exceed the available stack space. If the space is 
  2645.  exceeded, then a Storage_Error exception is raised. 
  2646.  
  2647.  For declared tasks, the stack size is always controlled by the size given in 
  2648.  an applicable Storage_Size pragma (or is set to the default size if no pragma 
  2649.  is used. 
  2650.  
  2651.  For the environment task, the stack size depends on system defaults and is 
  2652.  unknown to the compiler. The stack may even dynamically grow on some systems, 
  2653.  precluding the normal Ada semantics for stack overflow. In the worst case, 
  2654.  unbounded stack usage, causes unbounded stack expansion resulting in the 
  2655.  system running out of virtual memory. 
  2656.  
  2657.  The stack checking may still work correctly if a fixed size stack is 
  2658.  allocated, but this cannot be guaranteed. To ensure that a clean exception is 
  2659.  signalled for stack overflow, set the environment variable GNAT_STACK_LIMIT to 
  2660.  indicate the maximum stack area that can be used, as in: 
  2661.  
  2662.                       SET GNAT_STACK_LIMIT 1600
  2663.  
  2664.  The limit is given in kilobytes, so the above declaration would set the stack 
  2665.  limit of the environment task to 1.6 megabytes. 
  2666.  
  2667.  
  2668. ΓòÉΓòÉΓòÉ 6.2.6. Run-time Control ΓòÉΓòÉΓòÉ
  2669.  
  2670.  -gnatT nnn 
  2671.  
  2672.            The gnatT switch can be used to specify the time-slicing value to be 
  2673.            used for task switching between equal priority tasks. The value nnn 
  2674.            is given in microseconds as a decimal integer. 
  2675.  
  2676.            Setting the time-slicing value is only effective if the underlying 
  2677.            thread control system can accomodate time slicing. Check the 
  2678.            documentation of your operating system for details. Note that the 
  2679.            time-slicing value can also be set by use of pragma Time_Slice or by 
  2680.            use of the t switch in the gnatbind step. The pragma overrides a 
  2681.            command line argument if both are present, and the t switch for 
  2682.            gnatbind overrides both the pragma and the gcc command line switch. 
  2683.  
  2684.  
  2685. ΓòÉΓòÉΓòÉ 6.2.7. Using gcc for Syntax Checking ΓòÉΓòÉΓòÉ
  2686.  
  2687.  -gnats 
  2688.  
  2689.            The s stands for syntax. 
  2690.  
  2691.            Run GNAT in syntax checking only mode. For example, the command 
  2692.  
  2693.                       $ gcc -c -gnats x.adb
  2694.  
  2695.  compiles file 'x.adb' in syntax-check-only mode. You can check a series of 
  2696.  files in a single command , and can use wild cards to specify such a group of 
  2697.  files. Note that you must specify the -c (compile only) flag in addition to 
  2698.  the -gnats flag. ┬╖ 
  2699.  
  2700.  You may use other switches in conjunction with -gnats. In particular, -gnatl 
  2701.  and -gnatv are useful to control the format of any generated error messages. 
  2702.  
  2703.  The output is simply the error messages, if any. No object file or ALI file is 
  2704.  generated by a syntax-only compilation. Also, no units other than the one 
  2705.  specified are accessed. For example, if a unit X with's a unit Y, compiling 
  2706.  unit X in syntax check only mode does not access the source file containing 
  2707.  unit Y. 
  2708.  
  2709.  Normally, GNAT allows only a single unit in a source file. However, this 
  2710.  restriction does not apply in syntax-check-only mode, and it is possible to 
  2711.  check a file containing multiple compilation units concatenated together. This 
  2712.  is primarily used by the gnatchop utility (see Renaming Files Using gnatchop). 
  2713.  
  2714.  
  2715. ΓòÉΓòÉΓòÉ 6.2.8. Using gcc for Semantic Checking ΓòÉΓòÉΓòÉ
  2716.  
  2717.  -gnatc 
  2718.  
  2719.            The c stands for check. Causes the compiler to operate in semantic 
  2720.            check mode, with full checking for all illegalities specified in the 
  2721.            Ada 95 Reference Manual, but without generation of any source code 
  2722.            (no object or ALI file generated). 
  2723.  
  2724.            Because dependent files must be accessed, you must follow the GNAT 
  2725.            semantic restrictions on file structuring to operate in this mode: 
  2726.  
  2727.                1. The needed source files must be accessible (see Search Paths 
  2728.                   and the Run-Time Library (RTL)). 
  2729.  
  2730.                2. Each file must contain only one compilation unit. 
  2731.  
  2732.                3. The file name and unit name must match (see File Naming 
  2733.                   Rules). 
  2734.  
  2735.              The output consists of error messages as appropriate. No object 
  2736.              file or ALI file is generated. The checking corresponds exactly to 
  2737.              the notion of legality in the Ada 95 Reference Manual. 
  2738.  
  2739.              Any unit can be compiled in semantics-checking-only mode, 
  2740.              including units that would not normally be compiled (subunits, and 
  2741.              specifications where a separate body is present). 
  2742.  
  2743.  
  2744. ΓòÉΓòÉΓòÉ 6.2.9. Compiling Ada 83 Programs ΓòÉΓòÉΓòÉ
  2745.  
  2746.  -gnat83 
  2747.  
  2748.            Although GNAT is primarily an Ada 95 compiler, it accepts this 
  2749.            switch to specify that an Ada 83 program is to be compiled in Ada83 
  2750.            mode. If you specify this switch, GNAT rejects most Ada 95 
  2751.            extensions and applies Ada 83 semantics where this can be done 
  2752.            easily. It is not possible to guarantee this switch does a perfect 
  2753.            job; for example, some subtle tests, such as are found in earlier 
  2754.            ACVC tests (that have been removed from the ACVC suite for Ada 95), 
  2755.            may not compile correctly. However, for most purposes, using this 
  2756.            switch should help to ensure that programs that compile correctly 
  2757.            under the -gnat83 switch can be ported easily to an Ada 83 compiler. 
  2758.            This is the main use of the switch. 
  2759.  
  2760.            With few exceptions (most notably the need to use <> on 
  2761.            unconstrained generic formal parameters, the use of the new Ada 95 
  2762.            keywords, and the use of packages with optional bodies), it is not 
  2763.            necessary to use the -gnat83 switch when compiling Ada 83 programs, 
  2764.            because, with rare exceptions, Ada 95 is upwardly compatible with 
  2765.            Ada 83. This means that a correct Ada 83 program is usually also a 
  2766.            correct Ada 95 program. 
  2767.  
  2768.  -gnat95 
  2769.            This switch specifies normal Ada 95 mode, and cancels the effect of 
  2770.            any previously given -gnat83 switch. 
  2771.  
  2772.  
  2773. ΓòÉΓòÉΓòÉ 6.2.10. Reference Manual Style Checking ΓòÉΓòÉΓòÉ
  2774.  
  2775.  -gnatr 
  2776.  
  2777.            Normally, GNAT permits any source layout consistent with the Ada 95 
  2778.            reference manual requirements. This switch ('r' is for "reference 
  2779.            manual") enforces the layout conventions suggested by the examples 
  2780.            and syntax rules of the Ada 95 Language Reference Manual. For 
  2781.            example, an else must line up with an if and code in the then and 
  2782.            else parts must be indented. The compiler treats violations of the 
  2783.            layout rules as syntax errors if you specify this switch. 
  2784.  
  2785.  -gnatg 
  2786.            Enforces a set of style conventions that correspond to the style 
  2787.            used in the GNAT source code. All compiler units are always compiled 
  2788.            with the -gnatg switch specified. 
  2789.  
  2790.            You can find the full documentation for the style conventions 
  2791.            imposed by -gnatg in the body of the package Style in the compiler 
  2792.            sources (in the file 'style.adb'). 
  2793.  
  2794.            You should not normally use the -gnatg switch. However, you must use 
  2795.            -gnatg for compiling any language-defined unit, or for adding 
  2796.            children to any language-defined unit other than Standard. 
  2797.  
  2798.  
  2799. ΓòÉΓòÉΓòÉ 6.2.11. Character Set Control ΓòÉΓòÉΓòÉ
  2800.  
  2801.  -gnatic 
  2802.  
  2803.            Normally GNAT recognizes the Latin-1 character set in source program 
  2804.            identifiers, as described in the Ada 95 Reference Manual. This 
  2805.            switch causes GNAT to recognize alternate character sets in 
  2806.            identifiers. c is a single character  indicating the character set, 
  2807.            as follows: 
  2808.  
  2809.              1 
  2810.                          Latin-1 identifiers 
  2811.  
  2812.              2 
  2813.                          Latin-2 letters allowed in identifiers 
  2814.  
  2815.              3 
  2816.                          Latin-3 letters allowed in identifiers 
  2817.  
  2818.              4 
  2819.                          Latin-4 letters allowed in identifiers 
  2820.  
  2821.              p 
  2822.                          IBM PC letters (code page 437) allowed in identifiers 
  2823.  
  2824.              8 
  2825.                          IBM PC letters (code page 850) allowed in identifiers 
  2826.  
  2827.              f 
  2828.                          Full upper-half codes allowed in identifiers 
  2829.  
  2830.              n 
  2831.                          No upper-half codes allowed in identifiers 
  2832.  
  2833.              w 
  2834.                          Wide-character codes allowed in identifiers 
  2835.  
  2836.              See Foreign Language Representation, for full details on the 
  2837.              implementation of these character sets. 
  2838.  
  2839.  -gnatWe 
  2840.            Specify the method of encoding for wide characters. e is one of the 
  2841.            following: 
  2842.  
  2843.              h 
  2844.                          Hex encoding (brackets coding also recognized) 
  2845.  
  2846.              u 
  2847.                          Upper half encoding (brackets encoding also 
  2848.                          recognized) 
  2849.  
  2850.              s 
  2851.                          Shift/JIS encoding (brackets encoding also recognized) 
  2852.  
  2853.              e 
  2854.                          EUC encoding (brackets encoding also recognized) 
  2855.  
  2856.              8 
  2857.                          UTF-8 encoding (brackets encoding also recognized) 
  2858.  
  2859.              b 
  2860.                          Brackets encoding only (default value) 
  2861.  
  2862.              For full details on the these encoding methods see See Wide 
  2863.              Character Encodings. Note that brackets coding is always accepted, 
  2864.              even if one of the other options is specified, so for example 
  2865.              -gnatW8 specifies that both brackets and UTF-8 encodings will be 
  2866.              recognized. The units that are with'ed directly or indirectly will 
  2867.              be scanned using the specified representation scheme, and so if 
  2868.              one of the non-brackets scheme is used, it must be used 
  2869.              consistently throughout the program. However, since brackets 
  2870.              encoding is always recognized, it may be conveniently used in 
  2871.              standard libraries, allowing these libraries to be used with any 
  2872.              of the available coding schemes. scheme. If no -gnatW? parameter 
  2873.              is present, then the default representation is Brackets encoding 
  2874.              only. 
  2875.  
  2876.              Note that the wide character representation that is specified 
  2877.              (explicitly or by default) for the main program also acts as the 
  2878.              default encoding used for Wide_Text_IO files if not specifically 
  2879.              overridden by a WCEM form parameter. 
  2880.  
  2881.  
  2882. ΓòÉΓòÉΓòÉ 6.2.12. File Naming Control ΓòÉΓòÉΓòÉ
  2883.  
  2884.  -gnatkn 
  2885.            Activates file name "krunching". n, a decimal integer in the range 
  2886.            1-999, indicates the maximum allowable length of a file name (not 
  2887.            including the '.ads' or '.adb' extension). The default is not to 
  2888.            enable file name krunching. 
  2889.  
  2890.            For the source file naming rules, See File Naming Rules. 
  2891.  
  2892.  
  2893. ΓòÉΓòÉΓòÉ 6.2.13. Subprogram Inlining Control ΓòÉΓòÉΓòÉ
  2894.  
  2895.  -gnatn 
  2896.            The n here is intended to suggest the first syllable of the word 
  2897.            "inline". GNAT recognizes and processes Inline pragmas. However, for 
  2898.            the inlining to actually occur, optimization must be enabled. To 
  2899.            enable inlining across unit boundaries, this is, inlining a call in 
  2900.            one unit of a subprogram declared in a with'ed unit, you must also 
  2901.            specify this switch. In the absence of this switch, GNAT does not 
  2902.            attempt inlining across units and does not need to access the bodies 
  2903.            of subprograms for which pragma Inline is specified if they are not 
  2904.            in the current unit. 
  2905.  
  2906.            If you specify this switch the compiler will access these bodies, 
  2907.            creating an extra source dependency for the resulting object file, 
  2908.            and where possible, the call will be inlined. For further details on 
  2909.            when inlining is possible see See Inlining of Subprograms. 
  2910.  
  2911.  
  2912. ΓòÉΓòÉΓòÉ 6.2.14. Auxiliary Output Control ΓòÉΓòÉΓòÉ
  2913.  
  2914.  -gnatt 
  2915.            Cause GNAT to write the internal tree for a unit to a file (with the 
  2916.            extension '.atd'. This not normally required, but is used by 
  2917.            separate analysis tools. Typically these tools do the necessary 
  2918.            compilations automatically, so you should never have to specify this 
  2919.            switch in normal operation. 
  2920.  
  2921.  -gnatu 
  2922.            Print a list of units required by this compilation on stdout. The 
  2923.            listing includes all units on which the unit being compiled depends 
  2924.            either directly or indirectly. 
  2925.  
  2926.  
  2927. ΓòÉΓòÉΓòÉ 6.2.15. Debugging Control ΓòÉΓòÉΓòÉ
  2928.  
  2929.  -gnatdx 
  2930.            Activate internal debugging switches. x is a letter or digit, or 
  2931.            string of letters or digits, which specifies the type of debugging 
  2932.            outputs desired. Normally these are used only for internal 
  2933.            development or system debugging purposes. You can find full 
  2934.            documentation for these switches in the body of the Debug unit in 
  2935.            the compiler source file 'debug.adb'. 
  2936.  
  2937.  -gnatG 
  2938.            This switch causes the compiler to generate auxiliary output 
  2939.            containing a pseudo-source listing of the generated expanded code. 
  2940.            Like most Ada compilers, GNAT works by first transforming the high 
  2941.            level Ada code into lower level constructs. For example, tasking 
  2942.            operations are transformed into calls to the tasking run-time 
  2943.            routines. A unique capability of GNAT is to list this expanded code 
  2944.            in a form very close to normal Ada source. This is very useful in 
  2945.            understanding the implications of various Ada usage on the 
  2946.            efficiency of the generated code. There are many cases in Ada (e.g. 
  2947.            the use of controlled types), where simple Ada statements can 
  2948.            generate a lot of run-time code. By using -gnatG you can identify 
  2949.            these cases, and consider whether it may be desirable to modify the 
  2950.            coding approach to improve efficiency. 
  2951.  
  2952.            The format of the output is very similar to standard Ada source, and 
  2953.            is easily understood by an Ada programmer. The following special 
  2954.            syntactic additions correspond to low level features used in the 
  2955.            generated code that do not have any exact analogies in pure Ada 
  2956.            source form: 
  2957.  
  2958.  -gnatD 
  2959.            This switch is used in conjunction with -gnatG to cause the expanded 
  2960.            source, as described above to be written to files with names 
  2961.            'xxx.dg', where 'xxx' is the normal file name, for example, if the 
  2962.            source file name is 'hello.adb', then a file 'hello.adb.dg' will be 
  2963.            written. The debugging information generated by the gcc -g switch 
  2964.            will refer to the generated 'xxx.dg' file. This allows you to do 
  2965.            source level debugging using the generated code which is sometimes 
  2966.            useful for complex code, for example to find out exactly which part 
  2967.            of a complex construction raised an exception. This switch also 
  2968.            suppress generation of cross-reference information (see -gnatx). 
  2969.  
  2970.  new xxx [storage_pool = yyy] 
  2971.            Shows the storage pool being used for an allocator. 
  2972.  
  2973.  at end procedure-name; 
  2974.            Shows the finalization (cleanup) procedure for a scope. 
  2975.  
  2976.  (if expr then expr else expr) 
  2977.            Conditional expression equivalent to the x?y:z construction in C. 
  2978.  
  2979.  target^(source) 
  2980.            A conversion with floating-point truncation instead of rounding. 
  2981.  
  2982.  target?(source) 
  2983.            A conversion that bypasses normal Ada semantic checking. In 
  2984.            particular enumeration types and fixed-point types are treated 
  2985.            simply as integers. 
  2986.  
  2987.  target?^(source) 
  2988.            Combines the above two cases. 
  2989.  
  2990.  x #/ y 
  2991.  
  2992.  x #mod y 
  2993.  
  2994.  x #* y 
  2995.  
  2996.  x #rem y 
  2997.            A division or multiplication of fixed-point values which are treated 
  2998.            as integers without any kind of scaling. 
  2999.  
  3000.  free expr [storage_pool = xxx] 
  3001.            Shows the storage pool associated with a free statement. 
  3002.  
  3003.  freeze typename [actions] 
  3004.            Shows the point at which typename is frozen, with possible 
  3005.            associated actions to be performed at the freeze point. 
  3006.  
  3007.  reference itype 
  3008.            Reference (and hence definition) to internal type itype. 
  3009.  
  3010.  function-name! (arg, arg, arg) 
  3011.            Intrinsic function call. 
  3012.  
  3013.  labelname : label 
  3014.            Declaration of label labelname. 
  3015.  
  3016.  expr && expr && expr ┬╖┬╖┬╖ && expr 
  3017.            A multiple concatenation (same effect as expr & expr & expr, but 
  3018.            handled more efficiently). 
  3019.  
  3020.  [constraint_error] 
  3021.            Raise the Constraint_Error exception. 
  3022.  
  3023.  expression'reference 
  3024.            A pointer to the result of evaluating expression. 
  3025.  
  3026.  target-type!(source-expression) 
  3027.            An unchecked conversion of source-expression to target-type. 
  3028.  
  3029.  [numerator/denominator] 
  3030.            Used to represent internal real literals (that) have no exact 
  3031.            representation in base 2-16 (for example, the result of compile time 
  3032.            evaluation of the expression 1.0/27.0). 
  3033.  
  3034.  
  3035. ΓòÉΓòÉΓòÉ 6.3. Search Paths and the Run-Time Library (RTL) ΓòÉΓòÉΓòÉ
  3036.  
  3037.  
  3038.  With the GNAT source-based library system, the compiler must be able to find 
  3039.  source files for units that are needed by the unit being compiled. Search 
  3040.  paths are used to guide this process. 
  3041.  
  3042.  The compiler compiles one source file whose name must be given explicitly on 
  3043.  the command line. In other words, no searching is done for this file. To find 
  3044.  all other source files that are needed (the most common being the specs of 
  3045.  units), the compiler examines the following directories, in the following 
  3046.  order: 
  3047.  
  3048.    1. The directory containing the source file of the main unit being compiled 
  3049.       (the file name on the command line). 
  3050.  
  3051.    2. Each directory named by an -I switch given on the gcc command line, in 
  3052.       the order given. 
  3053.  
  3054.    3. Each of the directories listed in the value of the ADA_INCLUDE_PATH 
  3055.       environment variable. Construct this value exactly as the PATH 
  3056.       environment variable: a list of directory names separated by colons. 
  3057.  
  3058.    4. The content of the "ada_source_path" file which is part of the GNAT 
  3059.       installation tree and is used to store standard libraries such as the 
  3060.       GNAT Run Time Library (RTL) source files. Installing an Ada library 
  3061.  
  3062.  Specifying the switch -I- inhibits the use of the directory containing the 
  3063.  source file named in the command line. You can still have this directory on 
  3064.  your search path, but in this case it must be explicitly requested with a -I 
  3065.  switch. 
  3066.  
  3067.  Specifying the switch -nostdinc inhibits the search of the default location 
  3068.  for the GNAT Run Time Library (RTL) source files. 
  3069.  
  3070.  The compiler outputs its object files and ALI files in the current working 
  3071.  directory. Caution: The object file can be redirected with the -o switch; 
  3072.  however, gcc and gnat1 have not been coordinated on this so the ALI file will 
  3073.  not go to the right place. Therefore, you should avoid using the -o switch. 
  3074.  
  3075.  The packages Ada, System, and Interfaces and their children make up the GNAT 
  3076.  RTL, together with the simple System.IO package used in the "Hello World" 
  3077.  example. The sources for these units are needed by the compiler and are kept 
  3078.  together in one directory. Not all of the bodies are needed, but all of the 
  3079.  sources are kept together anyway. In a normal installation, you need not 
  3080.  specify these directory names when compiling or binding. Either the 
  3081.  environment variables or the built-in defaults cause these files to be found. 
  3082.  
  3083.  In addition to the language-defined hierarchies (System, Ada and Interfaces), 
  3084.  the GNAT distribution provides a fourth hierarchy, consisting of child units 
  3085.  of GNAT. This is a collection of generally useful routines. See the GNAT 
  3086.  Reference Manual for further details. 
  3087.  
  3088.  Besides simplifying access to the RTL, a major use of search paths is in 
  3089.  compiling sources from multiple directories. This can make development 
  3090.  environments much more flexible. 
  3091.  
  3092.  
  3093. ΓòÉΓòÉΓòÉ 6.4. Order of Compilation Issues ΓòÉΓòÉΓòÉ
  3094.  
  3095.  
  3096.  If, in our earlier example, there was a spec for the hello procedure, it would 
  3097.  be contained in the file 'hello.ads'; yet this file would not have to be 
  3098.  explicitly compiled. This is the result of the model we chose to implement 
  3099.  library management. Some of the consequences of this model are as follows: 
  3100.  
  3101.      There is no point in compiling specs (except for package specs with no 
  3102.       bodies) because these are compiled as needed by clients. If you attempt a 
  3103.       useless compilation, you will receive an error message. It is also 
  3104.       useless to compile subunits because they are compiled as needed by the 
  3105.       parent. 
  3106.  
  3107.      There are no order of compilation requirements: performing a compilation 
  3108.       never obsoletes anything. The only way you can obsolete something and 
  3109.       require recompilations is to modify one of the source files on which it 
  3110.       depends. 
  3111.  
  3112.      There is no library as such, apart from the ALI files (see The Ada 
  3113.       Library Information Files, for information on the format of these files). 
  3114.       For now we find it convenient to create separate ALI files, but 
  3115.       eventually the information therein may be incorporated into the object 
  3116.       file directly. 
  3117.  
  3118.      When you compile a unit, the source files for the specs of all units that 
  3119.       it with's, all its subunits, and the bodies of any generics it 
  3120.       instantiates must be available (reachable by the search-paths mechanism 
  3121.       described above), or you will receive a fatal error message. 
  3122.  
  3123.  
  3124. ΓòÉΓòÉΓòÉ 6.5. Examples ΓòÉΓòÉΓòÉ
  3125.  
  3126.  
  3127.  The following are some typical Ada compilation command line examples: 
  3128.  
  3129.  $ gcc -c xyz.adb 
  3130.            Compile body in file 'xyz.adb' with all default options. 
  3131.  
  3132.  $ gcc -c -O2 -gnata xyz-def.adb 
  3133.            Compile the child unit package in file 'xyz-def.adb' with extensive 
  3134.            optimizations, and pragma Assert/Debug statements enabled. 
  3135.  
  3136.  $ gcc -c -gnatc abc-def.adb 
  3137.            Compile the subunit in file 'abc-def.adb' in semantic-checking-only 
  3138.            mode. 
  3139.  
  3140.  
  3141. ΓòÉΓòÉΓòÉ 7. Binding Using gnatbind ΓòÉΓòÉΓòÉ
  3142.  
  3143.  Running gnatbind              Running gnatbind 
  3144.  Generating The Binder Program in CGenerating The Binder Program in C 
  3145.  Consistency-Checking Modes    Consistency-Checking Modes 
  3146.  Binder Error Message Control  Binder Error Message Control 
  3147.  Elaboration Control           Elaboration Control 
  3148.  Output Control                Output Control 
  3149.  Binding with Non-Ada Main ProgramsBinding with Non-Ada Main Programs 
  3150.  Binding Programs with no Main SubprogramBinding Programs with no Main 
  3151.                                Subprogram 
  3152.  Summary of Binder Switches    Summary of Binder Switches 
  3153.  Command-Line Access           Command-Line Access 
  3154.  Search Paths for gnatbind     Search Paths for gnatbind 
  3155.  Examples of gnatbind Usage    Examples of gnatbind Usage 
  3156.  
  3157.  This chapter describes the GNAT binder, gnatbind, which is used to bind 
  3158.  compiled GNAT objects. The gnatbind program performs four separate functions: 
  3159.  
  3160.    1. Checks that a program is consistent, in accordance with the rules in 
  3161.       Chapter 10 of the Ada 95 Reference Manual. In particular, error messages 
  3162.       are generated if a program uses inconsistent versions of a given unit. 
  3163.  
  3164.    2. Checks that an acceptable order of elaboration exists for the program and 
  3165.       issues an error message if it cannot find an order of elaboration that 
  3166.       satisfies the rules in Chapter 10 of the Ada 95 Language Manual. 
  3167.  
  3168.    3. Generates a main program incorporating the given elaboration order. This 
  3169.       program is a small Ada package (body and spec) that must be subsequently 
  3170.       compiled using the GNAT compiler. The necessary compilation step is 
  3171.       usually performed automatically by gnatlink. The two most important 
  3172.       functions of this program are to call the elaboration routines of units 
  3173.       in an appropriate order and to call the main program. 
  3174.  
  3175.    4. Determines the set of object files required by the given main program. 
  3176.       This information is output in the forms of comments in the generated C 
  3177.       program, to be read by the gnatlink utility used to link the Ada 
  3178.       application. 
  3179.  
  3180.  
  3181. ΓòÉΓòÉΓòÉ 7.1. Running gnatbind ΓòÉΓòÉΓòÉ
  3182.  
  3183.  
  3184.  The form of the gnatbind command is 
  3185.  
  3186.                       $ gnatbind [switches] mainprog[.ali] [switches]
  3187.  
  3188.  where mainprog.adb is the Ada file containing the main program unit body. If 
  3189.  no switches are specified, gnatbind constructs an Ada package in two files 
  3190.  whose names are 'b~ada_main.ads', and 'b~ada_main.adb'. For example, if given 
  3191.  the parameter 'hello.ali', for a main program contained in file 'hello.adb', 
  3192.  the binder output files would be 'b~hello.ads' and 'b~hello.adb'. 
  3193.  
  3194.  When doing consistency checking, the binder takes any source files it can 
  3195.  locate into consideration. For example, if the binder determines that the 
  3196.  given main program requires the package Pack, whose '.ali' file is 'pack.ali' 
  3197.  and whose corresponding source spec file is 'pack.ads', it attempts to locate 
  3198.  the source file 'pack.ads' (using the same search path conventions as 
  3199.  previously described for the gcc command). If it can locate this source file, 
  3200.  it checks that the time stamps or source checksums of the source and its 
  3201.  references to in 'ali' files match. In other words, any 'ali' files that 
  3202.  mentions this spec must have resulted from compiling this version of the 
  3203.  source file (or in the case where the source checksums match, a version close 
  3204.  enough that the difference does not matter). 
  3205.  
  3206.  The effect of this consistency checking, which includes source files, is that 
  3207.  the binder ensures that the program is consistent with the latest version of 
  3208.  the source files that can be located at bind time. Editing a source file 
  3209.  without compiling files that depend on the source file cause error messages to 
  3210.  be generated by the binder. 
  3211.  
  3212.  For example, suppose you have a main program 'hello.adb' and a package P, from 
  3213.  file 'p.ads' and you perform the following steps: 
  3214.  
  3215.    1. Enter gcc -c hello.adb to compile the main program. 
  3216.  
  3217.    2. Enter gcc -c p.ads to compile package P. 
  3218.  
  3219.    3. Edit file 'p.ads'. 
  3220.  
  3221.    4. Enter gnatbind hello. 
  3222.  
  3223.  At this point, the file 'p.ali' contains an out-of-date time stamp because the 
  3224.  file 'p.ads' has been edited. The attempt at binding fails, and the binder 
  3225.  generates the following error messages: 
  3226.  
  3227.                       error: "hello.adb" must be recompiled ("p.ads" has been modified)
  3228.                       error: "p.ads" has been modified and must be recompiled
  3229.  
  3230.  Now both files must be recompiled as indicated, and then the bind can succeed, 
  3231.  generating a main program. You need not normally be concerned with the 
  3232.  contents of this file, but it is similar to the following which is the binder 
  3233.  file generated for a simple "hello world" program. 
  3234.  
  3235.                       --  The package is called Ada_Main unless this name is actually used
  3236.                       --  as a unit name in the partition, in which case some other unique
  3237.                       --  name is used.
  3238.                       with System;
  3239.                       package Ada_Main is
  3240.                         --  The main program saves the parameters (argument count,
  3241.                         --  argument values, environment pointer) in global variables
  3242.                         --  for later access by other units including
  3243.                         --  Ada.Command_Line.
  3244.                         gnat_argc : Integer;
  3245.                         gnat_argv : System.Address;
  3246.                         gnat_envp : System.Address;
  3247.                         --  The actual variables are stored in a library routine. This
  3248.                         --  is useful for some shared library situations, where there
  3249.                         --  are problems if variables are not in the library.
  3250.                         pragma Import (C, gnat_argc);
  3251.                         pragma Import (C, gnat_argv);
  3252.                         pragma Import (C, gnat_envp);
  3253.                         --  The exit status is similarly an external location
  3254.                         gnat_exit_status : Integer;
  3255.                         pragma Import (C, gnat_exit_status);
  3256.                         --  This is the generated adafinal routine that performs
  3257.                         --  finalization at the end of execution. In the case where
  3258.                         --  Ada is the main program, this main program makes a call
  3259.                         --  to adafinal at program termination.
  3260.                         procedure adafinal;
  3261.                         pragma Export (C, adafinal);
  3262.                         --  This is the generated adainit routine that performs
  3263.                         --  initialization at the start of execution. In the case
  3264.                         --  where Ada is the main program, this main program makes
  3265.                         --  a call to adainit at program startup.
  3266.                         procedure adainit;
  3267.                         pragma Export (C, adainit);
  3268.                         --  This routine is called at the start of execution. It is
  3269.                         --  a dummy routine that is used by the debugger to breakpoint
  3270.                         --  at the start of execution.
  3271.                         procedure Break_Start;
  3272.                         pragma Import (C, Break_Start, "__gnat_break_start");
  3273.                         --  This is the actual generated main program (it would be
  3274.                         --  suppressed if the no main program swich were used). As
  3275.                         --  required by standard system conventions, this program has
  3276.                         --  the external name main.
  3277.                         function main
  3278.                          (argc : Integer;
  3279.                          argv : System.Address;
  3280.                          envp : System.Address)
  3281.                          return Integer;
  3282.                         pragma Export (C, main, "main");
  3283.                         --  The following set of constants give the version
  3284.                         --  identification values for every unit in the bound
  3285.                         --  partition. This identification is computed from all
  3286.                         --  dependent semantic units, and corresponds to the
  3287.                         --  string that would be returned by use of the
  3288.                         --  Body_Version or Version attributes.
  3289.                         u00001 : constant Integer := 16#425FD0AF#;
  3290.                         u00002 : constant Integer := 16#077A2651#;
  3291.                         u00003 : constant Integer := 16#08ADDC9E#;
  3292.                         u00004 : constant Integer := 16#1D370323#;
  3293.                         u00005 : constant Integer := 16#3043D77B#;
  3294.                         u00006 : constant Integer := 16#2359F9ED#;
  3295.                         u00007 : constant Integer := 16#0CA940CF#;
  3296.                         u00008 : constant Integer := 16#69BA6A59#;
  3297.                         u00009 : constant Integer := 16#156A40CF#;
  3298.                         u00010 : constant Integer := 16#033DABE0#;
  3299.                         u00011 : constant Integer := 16#6AB38FEA#;
  3300.                         u00012 : constant Integer := 16#7AAA368C#;
  3301.                         u00013 : constant Integer := 16#7D13B305#;
  3302.                         u00014 : constant Integer := 16#62D2B79D#;
  3303.                         u00015 : constant Integer := 16#2E865F1E#;
  3304.                         u00016 : constant Integer := 16#6379D875#;
  3305.                         u00017 : constant Integer := 16#72D6A51D#;
  3306.                         u00018 : constant Integer := 16#6E88E3D7#;
  3307.                         u00019 : constant Integer := 16#45C8383C#;
  3308.                         u00020 : constant Integer := 16#385E7AC2#;
  3309.                         u00021 : constant Integer := 16#08FE4C1F#;
  3310.                         u00022 : constant Integer := 16#23B87757#;
  3311.                         u00023 : constant Integer := 16#3A4BFD9A#;
  3312.                         u00024 : constant Integer := 16#4C9F3930#;
  3313.                         u00025 : constant Integer := 16#2F1EB794#;
  3314.                         u00026 : constant Integer := 16#0E2A461A#;
  3315.                         u00027 : constant Integer := 16#5570D114#;
  3316.                         u00028 : constant Integer := 16#501FA6BF#;
  3317.                         u00029 : constant Integer := 16#57692181#;
  3318.                         u00030 : constant Integer := 16#7C25DE96#;
  3319.                         u00031 : constant Integer := 16#521B9399#;
  3320.                         u00032 : constant Integer := 16#689CC1B9#;
  3321.                         u00033 : constant Integer := 16#0357E00A#;
  3322.                         u00034 : constant Integer := 16#1345CFE9#;
  3323.                         u00035 : constant Integer := 16#343244DE#;
  3324.                         u00036 : constant Integer := 16#6725DC79#;
  3325.                         u00037 : constant Integer := 16#2DAF477E#;
  3326.                         u00038 : constant Integer := 16#4F0184F2#;
  3327.                         u00039 : constant Integer := 16#0A0669D8#;
  3328.                         u00040 : constant Integer := 16#26610831#;
  3329.                         u00041 : constant Integer := 16#0B5A4DF9#;
  3330.                         u00042 : constant Integer := 16#1D4F93E8#;
  3331.                         u00043 : constant Integer := 16#30B2EC3D#;
  3332.                         u00044 : constant Integer := 16#34054F96#;
  3333.                         u00045 : constant Integer := 16#6598BA3E#;
  3334.                         u00046 : constant Integer := 16#2C9C021D#;
  3335.                         u00047 : constant Integer := 16#177A51F6#;
  3336.                         u00048 : constant Integer := 16#1CBC39CD#;
  3337.                         u00049 : constant Integer := 16#5461BB3E#;
  3338.                         u00050 : constant Integer := 16#03F36D98#;
  3339.                         u00051 : constant Integer := 16#208D3EF6#;
  3340.                         u00052 : constant Integer := 16#33AF4230#;
  3341.                         u00053 : constant Integer := 16#0B97C6BF#;
  3342.                         u00054 : constant Integer := 16#34B32999#;
  3343.                         --  The following Export pragms export the version numbers
  3344.                         --  with symbolic --  names ending in B (for body) or S
  3345.                         --  (for spec) so that they can be located in a link. The
  3346.                         --  information provided here is sufficient to track down
  3347.                         --  the exact versions of units used in a given build.
  3348.                         pragma Export (C, u00001, "helloB");
  3349.                         pragma Export (C, u00002, "system__standard_libraryB");
  3350.                         pragma Export (C, u00003, "system__standard_libraryS");
  3351.                         pragma Export (C, u00004, "systemS");
  3352.                         pragma Export (C, u00005, "system__exceptionsS");
  3353.                         pragma Export (C, u00006, "adaS");
  3354.                         pragma Export (C, u00007, "ada__exceptionsB");
  3355.                         pragma Export (C, u00008, "ada__exceptionsS");
  3356.                         pragma Export (C, u00009, "gnatS");
  3357.                         pragma Export (C, u00010, "gnat__heap_sort_aB");
  3358.                         pragma Export (C, u00011, "gnat__heap_sort_aS");
  3359.                         pragma Export (C, u00012, "system__exception_tableB");
  3360.                         pragma Export (C, u00013, "system__exception_tableS");
  3361.                         pragma Export (C, u00014, "gnat__htableB");
  3362.                         pragma Export (C, u00015, "gnat__htableS");
  3363.                         pragma Export (C, u00016, "system__machine_codeS");
  3364.                         pragma Export (C, u00017, "system__secondary_stackB");
  3365.                         pragma Export (C, u00018, "system__secondary_stackS");
  3366.                         pragma Export (C, u00019, "system__parametersB");
  3367.                         pragma Export (C, u00020, "system__parametersS");
  3368.                         pragma Export (C, u00021, "system__soft_linksB");
  3369.                         pragma Export (C, u00022, "system__soft_linksS");
  3370.                         pragma Export (C, u00023, "system__stack_checkingB");
  3371.                         pragma Export (C, u00024, "system__stack_checkingS");
  3372.                         pragma Export (C, u00025, "system__storage_elementsB");
  3373.                         pragma Export (C, u00026, "system__storage_elementsS");
  3374.                         pragma Export (C, u00027, "text_ioS");
  3375.                         pragma Export (C, u00028, "ada__text_ioB");
  3376.                         pragma Export (C, u00029, "ada__text_ioS");
  3377.                         pragma Export (C, u00030, "ada__streamsS");
  3378.                         pragma Export (C, u00031, "ada__tagsB");
  3379.                         pragma Export (C, u00032, "ada__tagsS");
  3380.                         pragma Export (C, u00033, "interfacesS");
  3381.                         pragma Export (C, u00034, "interfaces__c_streamsB");
  3382.                         pragma Export (C, u00035, "interfaces__c_streamsS");
  3383.                         pragma Export (C, u00036, "system__file_ioB");
  3384.                         pragma Export (C, u00037, "system__file_ioS");
  3385.                         pragma Export (C, u00038, "ada__finalizationB");
  3386.                         pragma Export (C, u00039, "ada__finalizationS");
  3387.                         pragma Export (C, u00040, "system__finalization_rootB");
  3388.                         pragma Export (C, u00041, "system__finalization_rootS");
  3389.                         pragma Export (C, u00042, "system__stream_attributesB");
  3390.                         pragma Export (C, u00043, "system__stream_attributesS");
  3391.                         pragma Export (C, u00044, "ada__io_exceptionsS");
  3392.                         pragma Export (C, u00045, "system__unsigned_typesS");
  3393.                         pragma Export (C, u00046, "system__finalization_implementationB");
  3394.                         pragma Export (C, u00047, "system__finalization_implementationS");
  3395.                         pragma Export (C, u00048, "system__string_ops_concat_3B");
  3396.                         pragma Export (C, u00049, "system__string_ops_concat_3S");
  3397.                         pragma Export (C, u00050, "system__string_opsB");
  3398.                         pragma Export (C, u00051, "system__string_opsS");
  3399.                         pragma Export (C, u00052, "system__file_control_blockS");
  3400.                         pragma Export (C, u00053, "ada__finalization__list_controllerB");
  3401.                         pragma Export (C, u00054, "ada__finalization__list_controllerS");
  3402.                       end Ada_Main;
  3403.                       --  The following source file name pragmas allow the generated file
  3404.                       --  names to be unique for different main programs. They are needed
  3405.                       --  since the package name will always be Ada_Main.
  3406.                       pragma Source_File_Name (Ada_Main, Spec_File_Name => "b~hello.ads");
  3407.                       pragma Source_File_Name (Ada_Main, Body_File_Name => "b~hello.adb");
  3408.                       package body Ada_Main is
  3409.                       --  Generated package body for Ada_Main starts here
  3410.                         -------------
  3411.                         -- adainit --
  3412.                         -------------
  3413.                         procedure adainit is
  3414.                          --  Set_Globals is a library routine that stores away the
  3415.                          --  value of the indicated set of global values in global
  3416.                          --  variables within the library.
  3417.                          procedure Set_Globals
  3418.                           (Main_Priority       : Integer;
  3419.                            Time_Slice_Value     : Integer;
  3420.                            WC_Encoding        : Character;
  3421.                            Locking_Policy      : Character;
  3422.                            Queuing_Policy      : Character;
  3423.                            Task_Dispatching_Policy  : Character;
  3424.                            Adafinal         : System.Address;
  3425.                            Unreserve_All_Interrupts : Boolean;
  3426.                            Exception_Tracebacks   : Boolean);
  3427.                          pragma Import (C, Set_Globals, "__gnat_set_globals");
  3428.                          --  SDP_Table_Build is a library routine used to build the
  3429.                          --  exception tables. See unit Ada.Exceptions in files
  3430.                          --  a-except.ads/adb for full details of how zero cost
  3431.                          --  exception handling works. This procedure, the call to
  3432.                          --  it, and the two following tables are all omitted if the
  3433.                          --  build is in longjmp/setjump exception mode.
  3434.                          procedure SDP_Table_Build
  3435.                           (SDP_Addresses  : System.Address;
  3436.                            SDP_Count    : Natural;
  3437.                            Elab_Addresses  : System.Address;
  3438.                            Elab_Addr_Count : Natural);
  3439.                          pragma Import (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
  3440.                          --  Table of Unit_Exception_Table addresses. Used for zero
  3441.                          --  cost exception handling to build the top level table.
  3442.                          ST : aliased constant array (1 ┬╖┬╖ 21) of System.Address := (
  3443.                           Hello'UET_Address,
  3444.                           Ada.Exceptions'UET_Address,
  3445.                           Gnat.Heap_Sort_A'UET_Address,
  3446.                           System.Exception_Table'UET_Address,
  3447.                           System.Secondary_Stack'UET_Address,
  3448.                           System.Parameters'UET_Address,
  3449.                           System.Soft_Links'UET_Address,
  3450.                           System.Stack_Checking'UET_Address,
  3451.                           Ada.Text_Io'UET_Address,
  3452.                           Ada.Streams'UET_Address,
  3453.                           Ada.Tags'UET_Address,
  3454.                           Interfaces.C_Streams'UET_Address,
  3455.                           System.File_Io'UET_Address,
  3456.                           Ada.Finalization'UET_Address,
  3457.                           System.Finalization_Root'UET_Address,
  3458.                           System.Stream_Attributes'UET_Address,
  3459.                           System.Finalization_Implementation'UET_Address,
  3460.                           System.String_Ops_Concat_3'UET_Address,
  3461.                           System.String_Ops'UET_Address,
  3462.                           System.File_Control_Block'UET_Address,
  3463.                           Ada.Finalization.List_Controller'UET_Address);
  3464.                          --  Table of addresses of elaboration routines. Used for
  3465.                          --  zero cost exception handling to make sure these
  3466.                          --  addresses are included in the top level procedure
  3467.                          --  address table.
  3468.                          EA : aliased constant array (1 ┬╖┬╖ 22) of System.Address := (
  3469.                           adainit'Code_Address,
  3470.                           adafinal'Code_Address,
  3471.                           Ada.Exceptions'Elab_Spec'Address,
  3472.                           System.Exceptions'Elab_Spec'Address,
  3473.                           Interfaces.C_Streams'Elab_Spec'Address,
  3474.                           System.Exception_Table'Elab_Body'Address,
  3475.                           Ada.Io_Exceptions'Elab_Spec'Address,
  3476.                           Ada.Tags'Elab_Spec'Address,
  3477.                           Ada.Tags'Elab_Body'Address,
  3478.                           Ada.Streams'Elab_Spec'Address,
  3479.                           System.Stack_Checking'Elab_Spec'Address,
  3480.                           System.Soft_Links'Elab_Body'Address,
  3481.                           System.Secondary_Stack'Elab_Body'Address,
  3482.                           Ada.Exceptions'Elab_Body'Address,
  3483.                           System.Finalization_Root'Elab_Spec'Address,
  3484.                           System.Finalization_Implementation'Elab_Spec'Address,
  3485.                           Ada.Finalization'Elab_Spec'Address,
  3486.                           Ada.Finalization.List_Controller'Elab_Spec'Address,
  3487.                           System.File_Control_Block'Elab_Spec'Address,
  3488.                           System.File_Io'Elab_Body'Address,
  3489.                           Ada.Text_Io'Elab_Spec'Address,
  3490.                           Ada.Text_Io'Elab_Body'Address);
  3491.                         --  Start of processing for adainit
  3492.                         begin
  3493.                          --  Call SDP_Table_Build to build the top level procedure
  3494.                          --  table for zero cost exception handling (omitted in
  3495.                          --  longjmp/setjump mode).
  3496.                          SDP_Table_Build (ST'Address, 21, EA'Address, 22);
  3497.                          --  Call Set_Globals to record various information for
  3498.                          --  this partition.  The values are derived by the binder
  3499.                          --  from information stored in the ali files by the compiler.
  3500.                          Set_Globals
  3501.                           (Main_Priority       => -1,
  3502.                            --  Priority of main program, -1 if no pragma Priority used
  3503.                            Time_Slice_Value     => -1,
  3504.                            --  Time slice from Time_Slice pragma, -1 if none used
  3505.                            WC_Encoding        => 'b',
  3506.                            --  Wide_Character encoding used, default is brackets
  3507.                            Locking_Policy      => ' ',
  3508.                            --  Locking_Policy used, default of space means not
  3509.                            --  specified, otherwise it is the first character of
  3510.                            --  the policy name.
  3511.                            Queuing_Policy      => ' ',
  3512.                            --  Queuing_Policy used, default of space means not
  3513.                            --  specified, otherwise it is the first character of
  3514.                            --  the policy name.
  3515.                            Task_Dispatching_Policy  => ' ',
  3516.                            --  Task_Dispatching_Policy used, default of space means
  3517.                            --  not specified, otherwise first character of the
  3518.                            --  policy name.
  3519.                            Adafinal         => adafinal'Address,
  3520.                            --  Address of generated ada final routine
  3521.                            Unreserve_All_Interrupts => False,
  3522.                            --  Set true if pragma Unreserve_All_Interrupts was used
  3523.                            Exception_Tracebacks   => False);
  3524.                            --  Indicates if exception tracebacks are enabled
  3525.                          --  Now we have the elaboration calls for all units in the
  3526.                          --  partition. The all is commented out if the given unit
  3527.                          --  has no elaboration code. We retain the commented out call
  3528.                          --  to indicate the full order chosen. The Elab_Spec and
  3529.                          --  Elab_Body attributes generate references to the implicit
  3530.                          --  elaboration procedures generated by the compiler for each
  3531.                          --  unit that requires elaboration.
  3532.                          -- System'Elab_Spec;
  3533.                          -- Ada'Elab_Spec;
  3534.                          -- Gnat'Elab_Spec;
  3535.                          -- Gnat.Heap_Sort_A'Elab_Spec;
  3536.                          -- Gnat.Htable'Elab_Spec;
  3537.                          -- Gnat.Htable'Elab_Body;
  3538.                          -- Interfaces'Elab_Spec;
  3539.                          -- System.Machine_Code'Elab_Spec;
  3540.                          -- System.Parameters'Elab_Spec;
  3541.                          -- System.Standard_Library'Elab_Spec;
  3542.                            Ada.Exceptions'Elab_Spec;
  3543.                            System.Exceptions'Elab_Spec;
  3544.                          -- System.Parameters'Elab_Body;
  3545.                          -- Gnat.Heap_Sort_A'Elab_Body;
  3546.                            Interfaces.C_Streams'Elab_Spec;
  3547.                          -- Interfaces.C_Streams'Elab_Body;
  3548.                          -- System.Exception_Table'Elab_Spec;
  3549.                            System.Exception_Table'Elab_Body;
  3550.                            Ada.Io_Exceptions'Elab_Spec;
  3551.                          -- System.Storage_Elements'Elab_Spec;
  3552.                          -- System.Storage_Elements'Elab_Body;
  3553.                          -- System.Secondary_Stack'Elab_Spec;
  3554.                            Ada.Tags'Elab_Spec;
  3555.                            Ada.Tags'Elab_Body;
  3556.                            Ada.Streams'Elab_Spec;
  3557.                            System.Stack_Checking'Elab_Spec;
  3558.                          -- System.Soft_Links'Elab_Spec;
  3559.                            System.Soft_Links'Elab_Body;
  3560.                          -- System.Stack_Checking'Elab_Body;
  3561.                            System.Secondary_Stack'Elab_Body;
  3562.                            Ada.Exceptions'Elab_Body;
  3563.                          -- System.Standard_Library'Elab_Body;
  3564.                          -- System.String_Ops'Elab_Spec;
  3565.                          -- System.String_Ops'Elab_Body;
  3566.                          -- System.String_Ops_Concat_3'Elab_Spec;
  3567.                          -- System.String_Ops_Concat_3'Elab_Body;
  3568.                          -- System.Unsigned_Types'Elab_Spec;
  3569.                          -- System.Stream_Attributes'Elab_Spec;
  3570.                          -- System.Stream_Attributes'Elab_Body;
  3571.                            System.Finalization_Root'Elab_Spec;
  3572.                          -- System.Finalization_Root'Elab_Body;
  3573.                            System.Finalization_Implementation'Elab_Spec;
  3574.                          -- System.Finalization_Implementation'Elab_Body;
  3575.                            Ada.Finalization'Elab_Spec;
  3576.                          -- Ada.Finalization'Elab_Body;
  3577.                            Ada.Finalization.List_Controller'Elab_Spec;
  3578.                          -- Ada.Finalization.List_Controller'Elab_Body;
  3579.                            System.File_Control_Block'Elab_Spec;
  3580.                          -- System.File_Io'Elab_Spec;
  3581.                            System.File_Io'Elab_Body;
  3582.                            Ada.Text_Io'Elab_Spec;
  3583.                            Ada.Text_Io'Elab_Body;
  3584.                          -- Text_Io'Elab_Spec;
  3585.                          -- hello'elab_body;
  3586.                          null;
  3587.                         end adainit;
  3588.                         --------------
  3589.                         -- adafinal --
  3590.                         --------------
  3591.                         procedure adafinal is
  3592.                          --  The actual finalization is performed by calling the
  3593.                          --  library routine in System.Finalization_Implementation.
  3594.                          procedure do_finalize;
  3595.                          pragma Import
  3596.                           (C, do_finalize,
  3597.                            "system__finalization_implementation__finalize_global_list");
  3598.                         begin
  3599.                          do_finalize;
  3600.                         end adafinal;
  3601.                         ----------
  3602.                         -- main --
  3603.                         ----------
  3604.                         --  main is actually a function, as in the ANSI C standard,
  3605.                         --  defined to return the exit status. The three parameters
  3606.                         --  are the argument count, argument values and environment
  3607.                         --  pointer.
  3608.                         function main
  3609.                          (argc : Integer;
  3610.                          argv : System.Address;
  3611.                          envp : System.Address)
  3612.                          return Integer
  3613.                         is
  3614.                          --  The initialize routine performs low level system
  3615.                          --  initialization using a standard library routine which
  3616.                          --  sets up signal handling and performs any other
  3617.                          --  required setup. The routine can be found in file
  3618.                          --  a-init.c.
  3619.                          procedure initialize;
  3620.                          pragma Import (C, initialize, "__gnat_initialize");
  3621.                          --  The finalize routine performs low level system
  3622.                          --  finalization using a standard library routine. The
  3623.                          --  routine is found in file a-final.c and in the standard
  3624.                          --  distribution is a dummy routine that does nothing, so
  3625.                          --  really this is a hook for special user finalization.
  3626.                          procedure finalize;
  3627.                          pragma Import (C, finalize, "__gnat_finalize");
  3628.                          --  We get to the main program of the partition by using
  3629.                          --  pragma Import because if we try to with the unit and
  3630.                          --  call it Ada style, then not only do we waste time
  3631.                          --  recompiling it, but also, we don't really know the right
  3632.                          --  switches (e.g. identifier character set) to be used
  3633.                          --  to compile it.
  3634.                          procedure Ada_Main_Program;
  3635.                          pragma Import (Ada, Ada_Main_Program, "_ada_hello");
  3636.                         --  Start of processing for main
  3637.                         begin
  3638.                          --  Save global variables
  3639.                          gnat_argc := argc;
  3640.                          gnat_argv := argv;
  3641.                          gnat_envp := envp;
  3642.                          --  Call low level system initialization
  3643.                          Initialize;
  3644.                          --  Call our generated Ada initialization routine
  3645.                          adainit;
  3646.                          --  This is the point at which we want the debugger to get
  3647.                          --  control
  3648.                          Break_Start;
  3649.                          --  Now we call the main program of the partition
  3650.                          Ada_Main_Program;
  3651.                          --  Perform Ada finalization
  3652.                          adafinal;
  3653.                          --  Perform low level system finalization
  3654.                          Finalize;
  3655.                          --  Return the proper exit status
  3656.                          return (gnat_exit_status);
  3657.                         end;
  3658.                       --  This section is entirely comments, so it has no effect on the
  3659.                       --  compilation of the Ada_Main package. It provides the list of
  3660.                       --  object files and linker options, as well as some standard
  3661.                       --  libraries needed for the link. The gnatlink utility parses
  3662.                       --  this b~hello.adb file to read these comment lines to generate
  3663.                       --  the appropriate command line arguments for the call to the
  3664.                       --  system linker. The BEGIN/END lines are used for sentinels for
  3665.                       --  this parsing operation.
  3666.                       --  The exact file names will of course depend on the environment,
  3667.                       --  host/target and location of files on the host system.
  3668.                       -- BEGIN Object file/option list
  3669.                         --  ./system.o
  3670.                         --  ./ada.o
  3671.                         --  ./gnat.o
  3672.                         --  ./g-htable.o
  3673.                         --  ./interfac.o
  3674.                         --  ./s-maccod.o
  3675.                         --  ./s-except.o
  3676.                         --  ./s-parame.o
  3677.                         --  ./g-hesora.o
  3678.                         --  ./i-cstrea.o
  3679.                         --  ./s-exctab.o
  3680.                         --  ./a-ioexce.o
  3681.                         --  ./s-stoele.o
  3682.                         --  ./a-tags.o
  3683.                         --  ./a-stream.o
  3684.                         --  ./s-soflin.o
  3685.                         --  ./s-stache.o
  3686.                         --  ./s-secsta.o
  3687.                         --  ./a-except.o
  3688.                         --  ./s-stalib.o
  3689.                         --  ./s-strops.o
  3690.                         --  ./s-sopco3.o
  3691.                         --  ./s-unstyp.o
  3692.                         --  ./s-stratt.o
  3693.                         --  ./s-finroo.o
  3694.                         --  ./s-finimp.o
  3695.                         --  ./a-finali.o
  3696.                         --  ./a-filico.o
  3697.                         --  ./s-ficobl.o
  3698.                         --  ./s-fileio.o
  3699.                         --  ./a-textio.o
  3700.                         --  ./text_io.o
  3701.                         --  ./hello.o
  3702.                         --  -L./
  3703.                       ┬╖┬╖┬╖  Target/System specific library search directives
  3704.                         --  -lgnat
  3705.                       -- END Object file/option list
  3706.                       end Ada_Main;
  3707.  
  3708.  The Ada code in the above example is exactly what is generated by the binder. 
  3709.  We have added comments to more clearly indicate the function of each part of 
  3710.  the generated Ada_Main package. 
  3711.  
  3712.  The code is standard Ada in all respects, and can be processed by any tools 
  3713.  that handle Ada. In particular, it is possible to use the debugger in Ada mode 
  3714.  to debug the generated Ada_Main package. For example, suppose that for reasons 
  3715.  that you do not understand, your program is blowing up during elaboration of 
  3716.  the body of Ada.Text_IO. To chase this bug down, you can place a breakpoint on 
  3717.  the call: 
  3718.  
  3719.                       Ada.Text_Io'Elab_Body;
  3720.  
  3721.  and trace the elaboration routine for this package to find out where the 
  3722.  problem might be (more usually of course you would be debugging elaboration 
  3723.  code in your own application). 
  3724.  
  3725.  
  3726. ΓòÉΓòÉΓòÉ 7.2. Generating The Binder Program in C ΓòÉΓòÉΓòÉ
  3727.  
  3728.  
  3729.  In most normal usage, the default mode of gnatbind which is to generate the 
  3730.  main package in Ada, as described in the previous section. In particular, this 
  3731.  means that any Ada programmer can read and understand the generated main 
  3732.  program. It can also be debugged just like any other Ada code provided the -g 
  3733.  switch is used for gnatbind and gnatlink. 
  3734.  
  3735.  However for some purposes it may be convenient to generate the main program in 
  3736.  C rather than Ada. This may for example be helpful when you are generating a 
  3737.  mixed language program with the main program in C. The GNAT compiler itself is 
  3738.  an example. The use of the -C switch for both gnatbind and gnatlink will cause 
  3739.  the program to be generated in C (and compiled using the gnu C compiler). The 
  3740.  following shows the C code generated for the same "Hello World" program: 
  3741.  
  3742.                       extern int gnat_argc;
  3743.                       extern char **gnat_argv;
  3744.                       extern char **gnat_envp;
  3745.                       extern int gnat_exit_status;
  3746.                       void adafinal ();
  3747.                       void adainit ()
  3748.                       {
  3749.                         extern void *__gnat_hello__SDP;
  3750.                         extern void *__gnat_ada__exceptions__SDP;
  3751.                         extern void *__gnat_gnat__heap_sort_a__SDP;
  3752.                         extern void *__gnat_system__exception_table__SDP;
  3753.                         extern void *__gnat_system__secondary_stack__SDP;
  3754.                         extern void *__gnat_system__parameters__SDP;
  3755.                         extern void *__gnat_system__soft_links__SDP;
  3756.                         extern void *__gnat_system__stack_checking__SDP;
  3757.                         extern void *__gnat_ada__text_io__SDP;
  3758.                         extern void *__gnat_ada__streams__SDP;
  3759.                         extern void *__gnat_ada__tags__SDP;
  3760.                         extern void *__gnat_interfaces__c_streams__SDP;
  3761.                         extern void *__gnat_system__file_io__SDP;
  3762.                         extern void *__gnat_ada__finalization__SDP;
  3763.                         extern void *__gnat_system__finalization_root__SDP;
  3764.                         extern void *__gnat_system__stream_attributes__SDP;
  3765.                         extern void *__gnat_system__finalization_implementation__SDP;
  3766.                         extern void *__gnat_system__string_ops_concat_3__SDP;
  3767.                         extern void *__gnat_system__string_ops__SDP;
  3768.                         extern void *__gnat_system__file_control_block__SDP;
  3769.                         extern void *__gnat_ada__finalization__list_controller__SDP;
  3770.                         void **st[21] = {
  3771.                          &__gnat_hello__SDP,
  3772.                          &__gnat_ada__exceptions__SDP,
  3773.                          &__gnat_gnat__heap_sort_a__SDP,
  3774.                          &__gnat_system__exception_table__SDP,
  3775.                          &__gnat_system__secondary_stack__SDP,
  3776.                          &__gnat_system__parameters__SDP,
  3777.                          &__gnat_system__soft_links__SDP,
  3778.                          &__gnat_system__stack_checking__SDP,
  3779.                          &__gnat_ada__text_io__SDP,
  3780.                          &__gnat_ada__streams__SDP,
  3781.                          &__gnat_ada__tags__SDP,
  3782.                          &__gnat_interfaces__c_streams__SDP,
  3783.                          &__gnat_system__file_io__SDP,
  3784.                          &__gnat_ada__finalization__SDP,
  3785.                          &__gnat_system__finalization_root__SDP,
  3786.                          &__gnat_system__stream_attributes__SDP,
  3787.                          &__gnat_system__finalization_implementation__SDP,
  3788.                          &__gnat_system__string_ops_concat_3__SDP,
  3789.                          &__gnat_system__string_ops__SDP,
  3790.                          &__gnat_system__file_control_block__SDP,
  3791.                          &__gnat_ada__finalization__list_controller__SDP};
  3792.                         extern void ada__exceptions___elabs ();
  3793.                         extern void system__exceptions___elabs ();
  3794.                         extern void interfaces__c_streams___elabs ();
  3795.                         extern void system__exception_table___elabb ();
  3796.                         extern void ada__io_exceptions___elabs ();
  3797.                         extern void ada__tags___elabs ();
  3798.                         extern void ada__tags___elabb ();
  3799.                         extern void ada__streams___elabs ();
  3800.                         extern void system__stack_checking___elabs ();
  3801.                         extern void system__soft_links___elabb ();
  3802.                         extern void system__secondary_stack___elabb ();
  3803.                         extern void ada__exceptions___elabb ();
  3804.                         extern void system__finalization_root___elabs ();
  3805.                         extern void system__finalization_implementation___elabs ();
  3806.                         extern void ada__finalization___elabs ();
  3807.                         extern void ada__finalization__list_controller___elabs ();
  3808.                         extern void system__file_control_block___elabs ();
  3809.                         extern void system__file_io___elabb ();
  3810.                         extern void ada__text_io___elabs ();
  3811.                         extern void ada__text_io___elabb ();
  3812.                         void (*ea[22]) () = {
  3813.                          adainit,
  3814.                          adafinal,
  3815.                          ada__exceptions___elabs,
  3816.                          system__exceptions___elabs,
  3817.                          interfaces__c_streams___elabs,
  3818.                          system__exception_table___elabb,
  3819.                          ada__io_exceptions___elabs,
  3820.                          ada__tags___elabs,
  3821.                          ada__tags___elabb,
  3822.                          ada__streams___elabs,
  3823.                          system__stack_checking___elabs,
  3824.                          system__soft_links___elabb,
  3825.                          system__secondary_stack___elabb,
  3826.                          ada__exceptions___elabb,
  3827.                          system__finalization_root___elabs,
  3828.                          system__finalization_implementation___elabs,
  3829.                          ada__finalization___elabs,
  3830.                          ada__finalization__list_controller___elabs,
  3831.                          system__file_control_block___elabs,
  3832.                          system__file_io___elabb,
  3833.                          ada__text_io___elabs,
  3834.                          ada__text_io___elabb};
  3835.                         __gnat_SDP_Table_Build (&st, 21, ea, 22);
  3836.                         __gnat_set_globals (
  3837.                          -1,    /* Main_Priority        */
  3838.                          -1,    /* Time_Slice_Value      */
  3839.                          'b',   /* WC_Encoding         */
  3840.                          ' ',   /* Locking_Policy       */
  3841.                          ' ',   /* Queuing_Policy       */
  3842.                          ' ',   /* Tasking_Dispatching_Policy */
  3843.                          adafinal,/* Finalization routine address */
  3844.                          0,    /* Unreserve_All_Interrupts */
  3845.                          0);    /* Exception_Tracebacks */
  3846.                       /* system___elabs (); */
  3847.                       /* ada___elabs (); */
  3848.                       /* gnat___elabs (); */
  3849.                       /* gnat__heap_sort_a___elabs (); */
  3850.                       /* gnat__htable___elabs (); */
  3851.                       /* gnat__htable___elabb (); */
  3852.                       /* interfaces___elabs (); */
  3853.                       /* system__machine_code___elabs (); */
  3854.                       /* system__parameters___elabs (); */
  3855.                       /* system__standard_library___elabs (); */
  3856.                         ada__exceptions___elabs ();
  3857.                         system__exceptions___elabs ();
  3858.                       /* system__parameters___elabb (); */
  3859.                       /* gnat__heap_sort_a___elabb (); */
  3860.                         interfaces__c_streams___elabs ();
  3861.                       /* interfaces__c_streams___elabb (); */
  3862.                       /* system__exception_table___elabs (); */
  3863.                         system__exception_table___elabb ();
  3864.                         ada__io_exceptions___elabs ();
  3865.                       /* system__storage_elements___elabs (); */
  3866.                       /* system__storage_elements___elabb (); */
  3867.                       /* system__secondary_stack___elabs (); */
  3868.                         ada__tags___elabs ();
  3869.                         ada__tags___elabb ();
  3870.                         ada__streams___elabs ();
  3871.                         system__stack_checking___elabs ();
  3872.                       /* system__soft_links___elabs (); */
  3873.                         system__soft_links___elabb ();
  3874.                       /* system__stack_checking___elabb (); */
  3875.                         system__secondary_stack___elabb ();
  3876.                         ada__exceptions___elabb ();
  3877.                       /* system__standard_library___elabb (); */
  3878.                       /* system__string_ops___elabs (); */
  3879.                       /* system__string_ops___elabb (); */
  3880.                       /* system__string_ops_concat_3___elabs (); */
  3881.                       /* system__string_ops_concat_3___elabb (); */
  3882.                       /* system__unsigned_types___elabs (); */
  3883.                       /* system__stream_attributes___elabs (); */
  3884.                       /* system__stream_attributes___elabb (); */
  3885.                         system__finalization_root___elabs ();
  3886.                       /* system__finalization_root___elabb (); */
  3887.                         system__finalization_implementation___elabs ();
  3888.                       /* system__finalization_implementation___elabb (); */
  3889.                         ada__finalization___elabs ();
  3890.                       /* ada__finalization___elabb (); */
  3891.                         ada__finalization__list_controller___elabs ();
  3892.                       /* ada__finalization__list_controller___elabb (); */
  3893.                         system__file_control_block___elabs ();
  3894.                       /* system__file_io___elabs (); */
  3895.                         system__file_io___elabb ();
  3896.                         ada__text_io___elabs ();
  3897.                         ada__text_io___elabb ();
  3898.                       /* text_io___elabs (); */
  3899.                       /* hello___elabb (); */
  3900.                       }
  3901.                       void adafinal () {
  3902.                         system__finalization_implementation__finalize_global_list ();
  3903.                       }
  3904.                       int main (argc, argv, envp)
  3905.                         int argc;
  3906.                         char **argv;
  3907.                         char **envp;
  3908.                       {
  3909.                         gnat_argc = argc;
  3910.                         gnat_argv = argv;
  3911.                         gnat_envp = envp;
  3912.                         __gnat_initialize();
  3913.                         adainit();
  3914.                         __gnat_break_start();
  3915.                         _ada_hello ();
  3916.                         adafinal();
  3917.                         __gnat_finalize();
  3918.                         exit (gnat_exit_status);
  3919.                       }
  3920.                       unsigned helloB = 0x425FD0AF;
  3921.                       unsigned system__standard_libraryB = 0x077A2651;
  3922.                       unsigned system__standard_libraryS = 0x08ADDC9E;
  3923.                       unsigned systemS = 0x1D370323;
  3924.                       unsigned system__exceptionsS = 0x3043D77B;
  3925.                       unsigned adaS = 0x2359F9ED;
  3926.                       unsigned ada__exceptionsB = 0x0CA940CF;
  3927.                       unsigned ada__exceptionsS = 0x69BA6A59;
  3928.                       unsigned gnatS = 0x156A40CF;
  3929.                       unsigned gnat__heap_sort_aB = 0x033DABE0;
  3930.                       unsigned gnat__heap_sort_aS = 0x6AB38FEA;
  3931.                       unsigned system__exception_tableB = 0x7AAA368C;
  3932.                       unsigned system__exception_tableS = 0x7D13B305;
  3933.                       unsigned gnat__htableB = 0x62D2B79D;
  3934.                       unsigned gnat__htableS = 0x2E865F1E;
  3935.                       unsigned system__machine_codeS = 0x6379D875;
  3936.                       unsigned system__secondary_stackB = 0x72D6A51D;
  3937.                       unsigned system__secondary_stackS = 0x6E88E3D7;
  3938.                       unsigned system__parametersB = 0x45C8383C;
  3939.                       unsigned system__parametersS = 0x385E7AC2;
  3940.                       unsigned system__soft_linksB = 0x08FE4C1F;
  3941.                       unsigned system__soft_linksS = 0x23B87757;
  3942.                       unsigned system__stack_checkingB = 0x3A4BFD9A;
  3943.                       unsigned system__stack_checkingS = 0x4C9F3930;
  3944.                       unsigned system__storage_elementsB = 0x2F1EB794;
  3945.                       unsigned system__storage_elementsS = 0x0E2A461A;
  3946.                       unsigned text_ioS = 0x5570D114;
  3947.                       unsigned ada__text_ioB = 0x501FA6BF;
  3948.                       unsigned ada__text_ioS = 0x57692181;
  3949.                       unsigned ada__streamsS = 0x7C25DE96;
  3950.                       unsigned ada__tagsB = 0x521B9399;
  3951.                       unsigned ada__tagsS = 0x689CC1B9;
  3952.                       unsigned interfacesS = 0x0357E00A;
  3953.                       unsigned interfaces__c_streamsB = 0x1345CFE9;
  3954.                       unsigned interfaces__c_streamsS = 0x343244DE;
  3955.                       unsigned system__file_ioB = 0x6725DC79;
  3956.                       unsigned system__file_ioS = 0x2DAF477E;
  3957.                       unsigned ada__finalizationB = 0x4F0184F2;
  3958.                       unsigned ada__finalizationS = 0x0A0669D8;
  3959.                       unsigned system__finalization_rootB = 0x26610831;
  3960.                       unsigned system__finalization_rootS = 0x0B5A4DF9;
  3961.                       unsigned system__stream_attributesB = 0x1D4F93E8;
  3962.                       unsigned system__stream_attributesS = 0x30B2EC3D;
  3963.                       unsigned ada__io_exceptionsS = 0x34054F96;
  3964.                       unsigned system__unsigned_typesS = 0x6598BA3E;
  3965.                       unsigned system__finalization_implementationB = 0x2C9C021D;
  3966.                       unsigned system__finalization_implementationS = 0x177A51F6;
  3967.                       unsigned system__string_ops_concat_3B = 0x1CBC39CD;
  3968.                       unsigned system__string_ops_concat_3S = 0x5461BB3E;
  3969.                       unsigned system__string_opsB = 0x03F36D98;
  3970.                       unsigned system__string_opsS = 0x208D3EF6;
  3971.                       unsigned system__file_control_blockS = 0x33AF4230;
  3972.                       unsigned ada__finalization__list_controllerB = 0x0B97C6BF;
  3973.                       unsigned ada__finalization__list_controllerS = 0x34B32999;
  3974.                       /* BEGIN Object file/option list
  3975.                       ┬╖/system.o
  3976.                       ┬╖/ada.o
  3977.                       ┬╖/gnat.o
  3978.                       ┬╖/g-htable.o
  3979.                       ┬╖/interfac.o
  3980.                       ┬╖/s-maccod.o
  3981.                       ┬╖/s-except.o
  3982.                       ┬╖/s-parame.o
  3983.                       ┬╖/g-hesora.o
  3984.                       ┬╖/i-cstrea.o
  3985.                       ┬╖/s-exctab.o
  3986.                       ┬╖/a-ioexce.o
  3987.                       ┬╖/s-stoele.o
  3988.                       ┬╖/a-tags.o
  3989.                       ┬╖/a-stream.o
  3990.                       ┬╖/s-soflin.o
  3991.                       ┬╖/s-stache.o
  3992.                       ┬╖/s-secsta.o
  3993.                       ┬╖/a-except.o
  3994.                       ┬╖/s-stalib.o
  3995.                       ┬╖/s-strops.o
  3996.                       ┬╖/s-sopco3.o
  3997.                       ┬╖/s-unstyp.o
  3998.                       ┬╖/s-stratt.o
  3999.                       ┬╖/s-finroo.o
  4000.                       ┬╖/s-finimp.o
  4001.                       ┬╖/a-finali.o
  4002.                       ┬╖/a-filico.o
  4003.                       ┬╖/s-ficobl.o
  4004.                       ┬╖/s-fileio.o
  4005.                       ┬╖/a-textio.o
  4006.                       ┬╖/text_io.o
  4007.                       ┬╖/hello.o
  4008.                       -L./
  4009.                       ┬╖┬╖┬╖  Target/System specific library search directives
  4010.                       -lgnat
  4011.                         END Object file/option list */
  4012.  
  4013.  Here again, the C code is exactly what is generated by the binder. The 
  4014.  functions of the various parts of this code correspond in an obvious manner 
  4015.  with the commented Ada code shown in the example in the previous section. 
  4016.  
  4017.  
  4018. ΓòÉΓòÉΓòÉ 7.3. Consistency-Checking Modes ΓòÉΓòÉΓòÉ
  4019.  
  4020.  
  4021.  As described in the previous section, by default gnatbind checks that object 
  4022.  files are consistent with one another and are consistent with any source files 
  4023.  it can locate. The following switches control binder access to sources. 
  4024.  
  4025.  -s 
  4026.            Require source files to be present. In this mode, the binder must be 
  4027.            able to locate all source files that are referenced, in order to 
  4028.            check their consistency. In normal mode, if a source file cannot be 
  4029.            located it is simply ignored. If you specify this switch, a missing 
  4030.            source file is an error. 
  4031.  
  4032.  -x 
  4033.            Exclude source files. In this mode, the binder only checks that ALI 
  4034.            files are consistent with one another. Source files are not 
  4035.            accessed. The binder runs faster in this mode, and there is still a 
  4036.            guarantee that the resulting program is self-consistent. If a source 
  4037.            file has been edited since it was last compiled, and you specify 
  4038.            this switch, the binder will not detect that the object file is out 
  4039.            of date with respect to the source file. Note that this is the mode 
  4040.            that is automatically used by gnatmake because in this case the 
  4041.            checking against sources has already been performed by gnatmake in 
  4042.            the course of compilation (i.e. before binding). 
  4043.  
  4044.  
  4045. ΓòÉΓòÉΓòÉ 7.4. Binder Error Message Control ΓòÉΓòÉΓòÉ
  4046.  
  4047.  
  4048.  The following switches provide control over the generation of error messages 
  4049.  from the binder: 
  4050.  
  4051.  -v 
  4052.            Verbose mode. In the normal mode, brief error messages are generated 
  4053.            to stderr. If this switch is present, a header is written to stdout 
  4054.            and any error messages are directed to stdout. All that is written 
  4055.            to stderr is a brief summary message. 
  4056.  
  4057.  -b 
  4058.            Generate brief error messages to stderr even if verbose mode is 
  4059.            specified. This is relevant only when used with the -v switch. 
  4060.  
  4061.  -mn 
  4062.            Limits the number of error messages to n, a decimal integer in the 
  4063.            range 1-999. The binder terminates immediately if this limit is 
  4064.            reached. 
  4065.  
  4066.  -Mxxx 
  4067.            Renames the generated main program from main to xxx. This is useful 
  4068.            in the case of some cross-building environments, where the actual 
  4069.            main program is separate from the one generated by gnatbind. 
  4070.  
  4071.  -ws 
  4072.            Suppress all warning messages. 
  4073.  
  4074.  -we 
  4075.            Treat any warning messages as fatal errors. 
  4076.  
  4077.  -t 
  4078.            The binder performs a number of consistency checks including: 
  4079.  
  4080.                1. Check that time stamps of a given source unit are consistent 
  4081.  
  4082.                2. Check that checksums of a given source unit are consistent 
  4083.  
  4084.                3. Check that consistent versions of GNAT were used for 
  4085.                   compilation 
  4086.  
  4087.                4. Check consistency of configuration pragmas as required 
  4088.  
  4089.  
  4090.              Normally failure of such checks, in accordance with the 
  4091.              consistency requirements of the Ada Reference Manual, causes error 
  4092.              messages to be generated which abort the binder and prevent the 
  4093.              output of a binder file and subsequent link to obtain an 
  4094.              executable. 
  4095.  
  4096.              The \-t\/NOTIME_STAMP_CHECK switch converts these error messages 
  4097.              into warnings, so that binding and linking can continue to 
  4098.              completion even in the presence of such errors. The result may be 
  4099.              a failed link (due to missing symbols), or a non-functional 
  4100.              executable which has undefined semantics. This means that -t 
  4101.              should be used only in unusual situations, with extreme care. 
  4102.  
  4103.  
  4104. ΓòÉΓòÉΓòÉ 7.5. Elaboration Control ΓòÉΓòÉΓòÉ
  4105.  
  4106.  
  4107.  The following switches provide additional control over the elaboration order. 
  4108.  For full details see See Elaboration Order Handling in GNAT. 
  4109.  
  4110.  -f 
  4111.            Instructs the binder to ignore directives from the compiler about 
  4112.            implied Elaborate_All pragmas, and to use full Ada 95 Reference 
  4113.            Manual semantics in an attempt to find a legal elaboration order, 
  4114.            even if it seems likely that this order will cause an elaboration 
  4115.            exception. 
  4116.  
  4117.  -p 
  4118.            Normally the binder attempts to choose an elaboration order that is 
  4119.            likely to minimize the likelihood of an elaboration order error 
  4120.            resulting in raising a Program_Error exception. This switch reverses 
  4121.            the action of the binder, and requests that it deliberately choose 
  4122.            an order that is likely to maximize the likelihood of an elaboration 
  4123.            error. This is useful in ensuring portability and avoiding 
  4124.            dependence on accidental fortuitous elaboration ordering. 
  4125.  
  4126.  
  4127. ΓòÉΓòÉΓòÉ 7.6. Output Control ΓòÉΓòÉΓòÉ
  4128.  
  4129.  
  4130.  The following switches allow additional control over the output generated by 
  4131.  the binder. 
  4132.  
  4133.  -A 
  4134.            Generate binder program in Ada (default). The binder program is 
  4135.            named 'b~mainprog.adb' by default. This can be changed with -o 
  4136.            gnatbind option. 
  4137.  
  4138.  -C 
  4139.            Generate binder program in C. The binder program is named 
  4140.            'b_mainprog.c'. This can be changed with -o gnatbind option. 
  4141.  
  4142.  -e 
  4143.            Output complete list of elaboration-order dependencies, showing the 
  4144.            reason for each dependency. This output can be rather extensive but 
  4145.            may be useful in diagnosing problems with elaboration order. The 
  4146.            output is written to stdout. 
  4147.  
  4148.  -h 
  4149.            Output usage information. The output is written to stdout. 
  4150.  
  4151.  -l 
  4152.            Output chosen elaboration order. The output is written to stdout. 
  4153.  
  4154.  -O 
  4155.            Output full names of all the object files that must be linked to 
  4156.            provide the Ada component of the program. The output is written to 
  4157.            stdout. This list includes the files explicitly supplied and 
  4158.            referenced by the user as well as implicitly referenced run-time 
  4159.            unit files. The latter are omitted if the corresponding units reside 
  4160.            in shared libraries. The directory names for the run-time units 
  4161.            depend on the system configuration. 
  4162.  
  4163.  -o file 
  4164.            Set name of output file to file instead of the normal 
  4165.            'b~mainprog.adb' default. Note that file denote the Ada binder 
  4166.            generated body filename. In C mode you would normally give file an 
  4167.            extension of '.c' because it will be a C source program. Note that 
  4168.            if this option is used, then linking must be done manually. It is 
  4169.            not possible to use gnatlink in this case, since it cannot locate 
  4170.            the binder file. 
  4171.  
  4172.  -c 
  4173.            Check only. Do not generate the binder output file. In this mode the 
  4174.            binder performs all error checks but does not generate an output 
  4175.            file. 
  4176.  
  4177.  
  4178. ΓòÉΓòÉΓòÉ 7.7. Binding with Non-Ada Main Programs ΓòÉΓòÉΓòÉ
  4179.  
  4180.  
  4181.  In our description so far we have assumed that the main program is in Ada, and 
  4182.  that the task of the binder is to generate a corresponding function main that 
  4183.  invokes this Ada main program. GNAT also supports the building of executable 
  4184.  programs where the main program is not in Ada, but some of the called routines 
  4185.  are written in Ada and compiled using GNAT (see Mixed Language Programming). 
  4186.  The following switch is used in this situation: 
  4187.  
  4188.  -n 
  4189.            No main program. The main program is not in Ada. 
  4190.  
  4191.  In this case, most of the functions of the binder are still required, but 
  4192.  instead of generating a main program, the binder generates a file containing 
  4193.  the following callable routines: 
  4194.  
  4195.  adainit 
  4196.            You must call this routine to initialize the Ada part of the program 
  4197.            by calling the necessary elaboration routines. A call to adainit is 
  4198.            required before the first call to an Ada subprogram. 
  4199.  
  4200.            Note that it is assumed that the basic execution environment must be 
  4201.            setup to be appropriate for Ada execution at the point where the 
  4202.            first Ada subprogram is called. In particular, if the Ada code will 
  4203.            do any floating-point operations, then the FPU must be setup in an 
  4204.            appropriate manner. For the case of the x86, for example, full 
  4205.            precision mode is required. The procedure GNAT.Float_Control.Reset 
  4206.            may be used to ensure that the FPU is in the right state. 
  4207.  
  4208.  adafinal 
  4209.            You must call this routine to perform any library-level finalization 
  4210.            required by the Ada subprograms. A call to adafinal is required 
  4211.            after the last call to an Ada subprogram, and before the program 
  4212.            terminates. 
  4213.  
  4214.  If the -n switch is given, more than one ALI file may appear on the command 
  4215.  line for gnatbind. The normal closure calculation is performed for each of the 
  4216.  specified units. Calculating the closure means finding out the set of units 
  4217.  involved by tracing with references. The reason it is necessary to be able to 
  4218.  specify more than one ALI file is that a given program may invoke two or more 
  4219.  quite separate groups of Ada units. 
  4220.  
  4221.  The binder takes the name of its output file from the last specified ALI file, 
  4222.  unless overridden by the use of the \-o file\/OUTPUT=file\. The output is an 
  4223.  Ada unit in source form that can be compiled with GNAT unless the -C switch is 
  4224.  used in which case the output is a C source file, which must be compiled using 
  4225.  the C compiler. This compilation occurs automatically as part of the gnatlink 
  4226.  processing. 
  4227.  
  4228.  Currently GNAT runtime requires a FPU using 80 bits mode precision. Under 
  4229.  targets where this is not the default it is required to call 
  4230.  GNAT.Float_Control.Reset before using floating point numbers (this include 
  4231.  float computation, float input and output) in the Ada code. A side effect is 
  4232.  that this could be the wrong mode for the foreign code where floating point 
  4233.  computation could be broken after this call. 
  4234.  
  4235.  
  4236. ΓòÉΓòÉΓòÉ 7.8. Binding Programs with no Main Subprogram ΓòÉΓòÉΓòÉ
  4237.  
  4238.  
  4239.  It is possible to have an Ada program which does not have a main subprogram. 
  4240.  This program will call the elaboration routines of all the packages, then the 
  4241.  finalization routines. 
  4242.  
  4243.  The following switch is used to bind programs organized in this manner: 
  4244.  
  4245.  -z 
  4246.            Normally the binder checks that the unit name given on the command 
  4247.            line corresponds to a suitable main subprogram. When this switch is 
  4248.            used, a list of ALI files can be given, and the execution of the 
  4249.            program consists of elaboration of these units in an appropriate 
  4250.            order. 
  4251.  
  4252.  
  4253. ΓòÉΓòÉΓòÉ 7.9. Summary of Binder Switches ΓòÉΓòÉΓòÉ
  4254.  
  4255.  
  4256.  The following are the switches available with gnatbind: 
  4257.  
  4258.  -aO 
  4259.            Specify directory to be searched for ALI files. 
  4260.  
  4261.  -aI 
  4262.            Specify directory to be searched for source file. 
  4263.  
  4264.  -A 
  4265.            Generate binder program in Ada (default) 
  4266.  
  4267.  -b 
  4268.            Generate brief messages to stderr even if verbose mode set. 
  4269.  
  4270.  -c 
  4271.            Check only, no generation of binder output file. 
  4272.  
  4273.  -C 
  4274.            Generate binder program in C 
  4275.  
  4276.  -e 
  4277.            Output complete list of elaboration-order dependencies. 
  4278.  
  4279.  -E 
  4280.            Store tracebacks in exception occurrences when the target supports 
  4281.            it. This is the default with the zero cost exception mechanism. This 
  4282.            option is currently only supported on Solaris, Linux and Windows 
  4283.            ix86. Under Solaris and Linux you need to use explicitly the gcc 
  4284.            flag -funwind-tables when compiling every file in your application. 
  4285.            See also the packages GNAT.Traceback and GNAT.Traceback.Symbolic. 
  4286.            Under Windows there is no specific option to use to enable this 
  4287.            feature but you must not use -fomit-frame-pointer gcc option. 
  4288.  
  4289.  -f 
  4290.            Full elaboration semantics. Follow Ada rules. No attempt to be kind 
  4291.  
  4292.  -h 
  4293.            Output usage (help) information 
  4294.  
  4295.  -I 
  4296.            Specify directory to be searched for source and ALI files. 
  4297.  
  4298.  -I- 
  4299.            Do not look for sources in the current directory where gnatbind was 
  4300.            invoked, and do not look for ALI files in the directory containing 
  4301.            the ALI file named in the gnatbind command line. 
  4302.  
  4303.  -l 
  4304.            Output chosen elaboration order. 
  4305.  
  4306.  -Mxyz 
  4307.            Rename generated main program from main to xyz 
  4308.  
  4309.  -mn 
  4310.            Limit number of detected errors to n (1-999). 
  4311.  
  4312.  -n 
  4313.            No main program. 
  4314.  
  4315.  -nostdinc 
  4316.            Do not look for sources in the system default directory. 
  4317.  
  4318.  -nostdlib 
  4319.            Do not look for library files in the system default directory. 
  4320.  
  4321.  -o file 
  4322.            Name the output file file (default is 'b~xxx.adb'). Note that if 
  4323.            this option is used, then linking must be done manually, gnatlink 
  4324.            cannot be used. 
  4325.  
  4326.  -O 
  4327.            Output object list. 
  4328.  
  4329.  -p 
  4330.            Pessimistic (worst-case) elaboration order 
  4331.  
  4332.  -s 
  4333.            Require all source files to be present. 
  4334.  
  4335.  -static 
  4336.            Link against a static GNAT run time. 
  4337.  
  4338.  -shared 
  4339.            Link against a shared GNAT run time when available. 
  4340.  
  4341.  -t 
  4342.            Tolerate time stamp and other consistency errors 
  4343.  
  4344.  -Tn 
  4345.            Set the time slice value to n microseconds. A value of zero means no 
  4346.            time slicing and also indicates to the tasking run time to match as 
  4347.            close as possible to the annex D requirements of the RM. 
  4348.  
  4349.  -v 
  4350.            Verbose mode. Write error messages, header, summary output to 
  4351.            stdout. 
  4352.  
  4353.  -wx 
  4354.            Warning mode (x=s/e for suppress/treat as error) 
  4355.  
  4356.  -x 
  4357.            Exclude source files (check object consistency only). 
  4358.  
  4359.  -z 
  4360.            No main subprogram. 
  4361.  
  4362.  You may obtain this listing by running the program gnatbind with no arguments. 
  4363.  
  4364.  
  4365. ΓòÉΓòÉΓòÉ 7.10. Command-Line Access ΓòÉΓòÉΓòÉ
  4366.  
  4367.  
  4368.  The package Ada.Command_Line provides access to the command-line arguments and 
  4369.  program name. In order for this interface to operate correctly, the two 
  4370.  variables 
  4371.  
  4372.                       int gnat_argc;
  4373.                       char **gnat_argv;
  4374.  
  4375.  are declared in one of the GNAT library routines. These variables must be set 
  4376.  from the actual argc and argv values passed to the main program. With no n 
  4377.  present, gnatbind generates the C main program to automatically set these 
  4378.  variables. If the n switch is used, there is no automatic way to set these 
  4379.  variables. If they are not set, the procedures in Ada.Command_Line will not be 
  4380.  available, and any attempt to use them will raise Constraint_Error. If command 
  4381.  line access is required, your main program must set gnat_argc and gnat_argv 
  4382.  from the argc and argv values passed to it. 
  4383.  
  4384.  
  4385. ΓòÉΓòÉΓòÉ 7.11. Search Paths for gnatbind ΓòÉΓòÉΓòÉ
  4386.  
  4387.  
  4388.  The binder takes the name of an ALI file as its argument and needs to locate 
  4389.  source files as well as other ALI files to verify object consistency. 
  4390.  
  4391.  For source files, it follows exactly the same search rules as gcc (see Search 
  4392.  Paths and the Run-Time Library (RTL)). For ALI files the directories searched 
  4393.  are: 
  4394.  
  4395.    1. The directory containing the ALI file named in the command line, unless 
  4396.       the switch -I- is specified. 
  4397.  
  4398.    2. All directories specified by -I switches on the gnatbind command line, in 
  4399.       the order given. 
  4400.  
  4401.    3. Each of the directories listed in the value of the ADA_OBJECTS_PATH 
  4402.       environment variable. Construct this value exactly as the PATH 
  4403.       environment variable: a list of directory names separated by colons. 
  4404.  
  4405.    4. The content of the "ada_object_path" file which is part of the GNAT 
  4406.       installation tree and is used to store standard libraries such as the 
  4407.       GNAT Run Time Library (RTL) unless the switch -nostdlib is specified. 
  4408.       Installing an Ada library 
  4409.  
  4410.  In the binder the switch -I is used to specify both source and library file 
  4411.  paths. Use -aI instead if you want to specify source paths only, and -aO if 
  4412.  you want to specify library paths only. This means that for the binder -Idir 
  4413.  is equivalent to -aIdir -aOdir. The binder generates the bind file (a C 
  4414.  language source file) in the current working directory. 
  4415.  
  4416.  The packages Ada, System, and Interfaces and their children make up the GNAT 
  4417.  Run-Time Library, together with the package GNAT and its children, which 
  4418.  contain a set of useful additional library functions provided by GNAT. The 
  4419.  sources for these units are needed by the compiler and are kept together in 
  4420.  one directory. The ALI files and object files generated by compiling the RTL 
  4421.  are needed by the binder and the linker and are kept together in one 
  4422.  directory, typically different from the directory containing the sources. In a 
  4423.  normal installation, you need not specify these directory names when compiling 
  4424.  or binding. Either the environment variables or the built-in defaults cause 
  4425.  these files to be found. 
  4426.  
  4427.  Besides simplifying access to the RTL, a major use of search paths is in 
  4428.  compiling sources from multiple directories. This can make development 
  4429.  environments much more flexible. 
  4430.  
  4431.  
  4432. ΓòÉΓòÉΓòÉ 7.12. Examples of gnatbind Usage ΓòÉΓòÉΓòÉ
  4433.  
  4434.  
  4435.  This section contains a number of examples of using the GNAT binding utility 
  4436.  gnatbind. 
  4437.  
  4438.  gnatbind hello 
  4439.            The main program Hello (source program in 'hello.adb') is bound 
  4440.            using the standard switch settings. The generated main program is 
  4441.            'b~hello.adb'. This is the normal, default use of the binder. 
  4442.  
  4443.  gnatbind hello -o mainprog.adb 
  4444.            The main program Hello (source program in 'hello.adb') is bound 
  4445.            using the standard switch settings. The generated main program is 
  4446.            'mainprog.adb' with the associated spec in 'mainprog.ads'. Note that 
  4447.            you must specify the body here not the spec, in the case where the 
  4448.            output is in Ada. Note that if this option is used, then linking 
  4449.            must be done manually, since gnatlink will not be able to find the 
  4450.            generated file. 
  4451.  
  4452.  gnatbind main -C -o mainprog.c -x 
  4453.            The main program Main (source program in 'main.adb') is bound, 
  4454.            excluding source files from the consistency checking, generating the 
  4455.            file 'mainprog.c'. 
  4456.  
  4457.  gnatbind -x main_program -C -o mainprog.c 
  4458.            This command is exactly the same as the previous example. Switches 
  4459.            may appear anywhere in the command line, and single letter switches 
  4460.            may be combined into a single switch. 
  4461.  
  4462.  gnatbind -n math dbase -C -o ada-control.c 
  4463.            The main program is in a language other than Ada, but calls to 
  4464.            subprograms in packages Math and Dbase appear. This call to gnatbind 
  4465.            generates the file 'ada-control.c' containing the adainit and 
  4466.            adafinal routines to be called before and after accessing the Ada 
  4467.            units. 
  4468.  
  4469.  
  4470. ΓòÉΓòÉΓòÉ 8. Linking Using gnatlink ΓòÉΓòÉΓòÉ
  4471.  
  4472.  
  4473.  This chapter discusses gnatlink, a utility program used to link Ada programs 
  4474.  and build an executable file. This is a simple program that invokes the UNIX 
  4475.  linker (via the gcc command) with a correct list of object files and library 
  4476.  references. gnatlink automatically determines the list of files and references 
  4477.  for the Ada part of a program. It uses the binder file generated by the binder 
  4478.  to determine this list. 
  4479.  
  4480.  Running gnatlink              Running gnatlink 
  4481.  Switches for gnatlink         Switches for gnatlink 
  4482.  
  4483.  
  4484. ΓòÉΓòÉΓòÉ 8.1. Running gnatlink ΓòÉΓòÉΓòÉ
  4485.  
  4486.  
  4487.  The form of the gnatlink command is 
  4488.  
  4489.                       $ gnatlink [switches] mainprog[.ali] [non-Ada objects] \
  4490.                        [linker options]
  4491.  
  4492.  'mainprog.ali' references the ALI file of the main program. The '.ali' 
  4493.  extension of this file can be omitted. From this reference, gnatlink locates 
  4494.  the corresponding binder file 'b~mainprog.adb' and, using the information in 
  4495.  this file along with the list of non-Ada objects and linker options, 
  4496.  constructs a UNIX linker command file to create the executable. 
  4497.  
  4498.  The arguments following 'mainprog.ali' are passed to the linker uninterpreted. 
  4499.  They typically include the names of object files for units written in other 
  4500.  languages than Ada and any library references required to resolve references 
  4501.  in any of these foreign language units, or in pragma Import statements in any 
  4502.  Ada units. 
  4503.  
  4504.  linker options is an optional list of linker specific switches. The default 
  4505.  linker called by gnatlink is gcc which in turn calls the appropriate system 
  4506.  linker usually called ld. Standard options for the linker such as -lmy_lib or 
  4507.  -Ldir can be added as is. For options that are not recognized by gcc as linker 
  4508.  options, the gcc switches -Xlinker or -Wl, shall be used. Refer to the GCC 
  4509.  documentation for details. Here is an example showing how to generate a linker 
  4510.  map assuming that the underlying linker is GNU ld: 
  4511.  
  4512.                       $ gnatlink my_prog -Wl,-Map,MAPFILE
  4513.  
  4514.  gnatlink determines the list of objects required by the Ada program and 
  4515.  prepends them to the list of objects passed to the linker. gnatlink also 
  4516.  gathers any arguments set by the use of pragma Linker_Options and adds them to 
  4517.  the list of arguments presented to the linker. 
  4518.  
  4519.  
  4520. ΓòÉΓòÉΓòÉ 8.2. Switches for gnatlink ΓòÉΓòÉΓòÉ
  4521.  
  4522.  
  4523.  The following switches are available with the gnatlink utility: 
  4524.  
  4525.  -A 
  4526.            The binder has generated code in Ada. This is the default. 
  4527.  
  4528.  -C 
  4529.            If instead of generating a file in Ada, the binder has generated one 
  4530.            in C, then the linker needs to know about it. Use this switch to 
  4531.            signal to gnatlink that the binder has generated C code rather than 
  4532.            Ada code. 
  4533.  
  4534.  -g 
  4535.            The option to include debugging information causes the Ada bind file 
  4536.            (in other words, 'b~mainprog.adb') to be compiled with -g. In 
  4537.            addition, the binder does not delete the 'b~mainprog.adb', 
  4538.            'b~mainprog.o' and 'b~mainprog.ali' files. Without -g, the binder 
  4539.            removes these files by default. The same procedure apply if a C bind 
  4540.            file was generated using -C gnatbind option, in this case the 
  4541.            filenames are 'b_mainprog.c' and 'b_mainprog.o'. 
  4542.  
  4543.  -n 
  4544.            Do not compile the file generated by the binder. This may be used 
  4545.            when a link is rerun with different options, but there is no need to 
  4546.            recompile the binder file. 
  4547.  
  4548.  -v 
  4549.            Causes additional information to be output, including a full list of 
  4550.            the included object files. This switch option is most useful when 
  4551.            you want to see what set of object files are being used in the link 
  4552.            step. 
  4553.  
  4554.  -v -v 
  4555.            Very verbose mode. Requests that the compiler operate in verbose 
  4556.            mode when it compiles the binder file, and that the system linker 
  4557.            run in verbose mode. 
  4558.  
  4559.  -o exec-name 
  4560.            exec-name specifies an alternate name for the generated executable 
  4561.            program. If this switch is omitted, the executable has the same name 
  4562.            as the main unit. For example, gnatlink try.ali creates an 
  4563.            executable called 'try'. 
  4564.  
  4565.  -b target 
  4566.            Compile your program to run on target, which is the name of a system 
  4567.            configuration. You must have a GNAT cross-compiler built if target 
  4568.            is not the same as your host system. 
  4569.  
  4570.  -Bdir 
  4571.            Load compiler executables (for example, gnat1, the Ada compiler) 
  4572.            from dir instead of the default location. Only use this switch when 
  4573.            multiple versions of the GNAT compiler are available. See the gcc 
  4574.            manual page for further details. You would normally use the -b or -V 
  4575.            switch instead. 
  4576.  
  4577.  --GCC=compiler_name 
  4578.            Program used for compiling the binder file. The default is gcc'. You 
  4579.            need to use quotes around compiler_name if compiler_name contains 
  4580.            spaces or other separator characters. As an example --GCC="foo -x 
  4581.            -y" will instruct gnatlink to use foo -x -y as your compiler. Note 
  4582.            that switch -c is always inserted after your command name. Thus in 
  4583.            the above example the compiler command that will be used by gnatlink 
  4584.            will be foo -c -x -y. 
  4585.  
  4586.  --LINK=name 
  4587.            name is the name of the linker to be invoked. This is especially 
  4588.            useful in mixed language programs since languages such as c++ 
  4589.            require their own linker to be used. When this switch is omitted, 
  4590.            the default name for the linker is ('gcc'). 
  4591.  
  4592.  
  4593. ΓòÉΓòÉΓòÉ 9. The GNAT Make Program gnatmake ΓòÉΓòÉΓòÉ
  4594.  
  4595.  Running gnatmake              Running gnatmake 
  4596.  Switches for gnatmake         Switches for gnatmake 
  4597.  Mode switches for gnatmake    Mode switches for gnatmake 
  4598.  Notes on the Command Line     Notes on the Command Line 
  4599.  How gnatmake Works            How gnatmake Works 
  4600.  Examples of gnatmake Usage    Examples of gnatmake Usage 
  4601.  
  4602.  A typical development cycle when working on an Ada program consists of the 
  4603.  following steps: 
  4604.  
  4605.    1. Edit some sources to fix bugs. 
  4606.  
  4607.    2. Add enhancements. 
  4608.  
  4609.    3. Compile all sources affected. 
  4610.  
  4611.    4. Rebind and relink. 
  4612.  
  4613.    5. Test. 
  4614.  
  4615.  The third step can be tricky, because not only do the modified files have to 
  4616.  be compiled, but any files depending on these files must also be recompiled. 
  4617.  The dependency rules in Ada can be quite complex, especially in the presence 
  4618.  of overloading, use clauses, generics and inlined subprograms. 
  4619.  
  4620.  gnatmake automatically takes care of the third and fourth steps of this 
  4621.  process. It determines which sources need to be compiled, compiles them, and 
  4622.  binds and links the resulting object files. 
  4623.  
  4624.  Unlike some other Ada make programs, the dependencies are always accurately 
  4625.  recomputed from the new sources. The source based approach of the GNAT 
  4626.  compilation model makes this possible. This means that if changes to the 
  4627.  source program cause corresponding changes in dependencies, they will always 
  4628.  be tracked exactly correctly by gnatmake. 
  4629.  
  4630.  
  4631. ΓòÉΓòÉΓòÉ 9.1. Running gnatmake ΓòÉΓòÉΓòÉ
  4632.  
  4633.  
  4634.  The form of the gnatmake command is 
  4635.  
  4636.                       $ gnatmake [switches] file_name [mode_switches]
  4637.  
  4638.  The only required argument is file_name, which specifies the compilation unit 
  4639.  that is the main program. If switches are present, they can be placed before 
  4640.  of after file_name. If mode_switches are present, they must always be placed 
  4641.  after file_name and all switches. 
  4642.  
  4643.  If you are using standard file extensions (.adb and .ads), then the extension 
  4644.  may be omitted from the file_name argument. However, if you are using 
  4645.  non-standard extensions, then it is required that the extension be given. A 
  4646.  relative or absolute directory path can be specified in file_name, in which 
  4647.  case, the input source file will be searched for in the specified directory 
  4648.  only. Otherwise, the input source file will first be searched in the directory 
  4649.  where gnatmake was invoked and if it is not found, it will be search on the 
  4650.  source path of the compiler as described in Search Paths and the Run-Time 
  4651.  Library (RTL). 
  4652.  
  4653.  All gnatmake output (except when you specify -M) is to stderr. The output 
  4654.  produced by the -M switch is send to stdout. 
  4655.  
  4656.  
  4657. ΓòÉΓòÉΓòÉ 9.2. Switches for gnatmake ΓòÉΓòÉΓòÉ
  4658.  
  4659.  
  4660.  You may specify any of the following switches to gnatmake: 
  4661.  
  4662.  --GCC=compiler_name 
  4663.            Program used for compiling. The default is gcc'. You need to use 
  4664.            quotes around compiler_name if compiler_name contains spaces or 
  4665.            other separator characters. As an example --GCC="foo -x -y" will 
  4666.            instruct gnatmake to use foo -x -y as your compiler. Note that 
  4667.            switch -c is always inserted after your command name. Thus in the 
  4668.            above example the compiler command that will be used by gnatmake 
  4669.            will be foo -c -x -y. 
  4670.  
  4671.  --GNATBIND=binder_name 
  4672.            Program used for binding. The default is gnatbind'. You need to use 
  4673.            quotes around binder_name if binder_name contains spaces or other 
  4674.            separator characters. As an example --GNATBIND="bar -x -y" will 
  4675.            instruct gnatmake to use bar -x -y as your binder. Binder switches 
  4676.            that are normally appended by gnatmake to gnatbind' are now appended 
  4677.            to the end of bar -x -y. 
  4678.  
  4679.  --GNATLINK=linker_name 
  4680.            Program used for linking. The default is gnatlink'. You need to use 
  4681.            quotes around linker_name if linker_name contains spaces or other 
  4682.            separator characters. As an example --GNATLINK="lan -x -y" will 
  4683.            instruct gnatmake to use lan -x -y as your linker. Linker switches 
  4684.            that are normally appended by gnatmake to gnatlink' are now appended 
  4685.            to the end of lan -x -y. 
  4686.  
  4687.  -a 
  4688.            Consider all files in the make process, even the GNAT internal 
  4689.            system files (for example, the predefined Ada library files), as 
  4690.            well as any locked files. Locked files are files whose ALI file is 
  4691.            write-protected. By default, gnatmake does not check these files, 
  4692.            because the assumption is that the GNAT internal files are properly 
  4693.            up to date, and also that any write protected ALI files have been 
  4694.            properly installed. Note that if there is an installation problem, 
  4695.            such that one of these files is not up to date, it will be properly 
  4696.            caught by the binder. You may have to specify this switch if you are 
  4697.            working on GNAT itself. -f is also useful in conjunction with -f if 
  4698.            you need to recompile an entire application, including run-time 
  4699.            files, using special configuration pragma settings, such as a 
  4700.            non-standard Float_Representation pragma. By default gnatmake -a 
  4701.            compiles all GNAT internal files with gcc -c -gnatg rather than gcc 
  4702.            -c. 
  4703.  
  4704.  -c 
  4705.            Compile only. Do not perform binding and linking. If the root unit 
  4706.            specified by file_name is not a main unit, this is the default. 
  4707.            Otherwise gnatmake will attempt binding and linking unless all 
  4708.            objects are up to date and the executable is more recent than the 
  4709.            objects. 
  4710.  
  4711.  -f 
  4712.            Force recompilations. Recompile all sources, even though some object 
  4713.            files may be up to date, but don't recompile predefined or GNAT 
  4714.            internal files or locked files (files with a write-protected ALI 
  4715.            file), unless the -a switch is also specified. 
  4716.  
  4717.  -i 
  4718.            In normal mode, gnatmake compiles all object files and ALI files 
  4719.            into the current directory. If the -i switch is used, then instead 
  4720.            object files and ALI files that already exist are overwritten in 
  4721.            place. This means that once a large project is organized into 
  4722.            separate directories in the desired manner, then gnatmake will 
  4723.            automatically maintain and update this organization. If no ALI files 
  4724.            are found on the Ada object path (Search Paths and the Run-Time 
  4725.            Library (RTL)), the new object and ALI files are created in the 
  4726.            directory containing the source being compiled. If another 
  4727.            organization is desired, where objects and sources are kept in 
  4728.            different directories, a useful technique is to create dummy ALI 
  4729.            files in the desired directories. When detecting such a dummy file, 
  4730.            gnatmake will be forced to recompile the corresponding source file, 
  4731.            and it will be put the resulting object and ALI files in the 
  4732.            directory where it found the dummy file. 
  4733.  
  4734.  -jn 
  4735.            Use n processes to carry out the (re)compilations. On a 
  4736.            multiprocessor machine compilations will occur in parallel. In the 
  4737.            event of compilation errors, messages from various compilations 
  4738.            might get interspersed (but gnatmake will give you the full ordered 
  4739.            list of failing compiles at the end). If this is problematic, rerun 
  4740.            the make process with n set to 1 to get a clean list of messages. 
  4741.  
  4742.  -k 
  4743.            Keep going. Continue as much as possible after a compilation error. 
  4744.            To ease the programmer's task in case of compilation errors, the 
  4745.            list of sources for which the compile fails is given when gnatmake 
  4746.            terminates. 
  4747.  
  4748.  -m 
  4749.            Specifies that the minimum necessary amount of recompilations be 
  4750.            performed. In this mode gnatmake ignores time stamp differences when 
  4751.            the only modifications to a source file consist in adding/removing 
  4752.            comments, empty lines, spaces or tabs. This means that if you have 
  4753.            changed the comments in a source file or have simply reformatted it, 
  4754.            using this switch will tell gnatmake not to recompile files that 
  4755.            depend on it (provided other sources on which these files depend 
  4756.            have undergone no semantic modifications). 
  4757.  
  4758.  -M 
  4759.            Check if all objects are up to date. If they are, output the object 
  4760.            dependences to stdout in a form that can be directly exploited in a 
  4761.            'Makefile'. By default, each source file is prefixed with its 
  4762.            (relative or absolute) directory name. This name is whatever you 
  4763.            specified in the various -aI and -I switches. If you use gnatmake -M 
  4764.            -q (see below), only the source file names, without relative paths, 
  4765.            are output. If you just specify the -M switch, dependencies of the 
  4766.            GNAT internal system files are omitted. This is typically what you 
  4767.            want. If you also specify the -a switch, dependencies of the GNAT 
  4768.            internal files are also listed. Note that dependencies of the 
  4769.            objects in external Ada libraries (see switch -aLdir in the 
  4770.            following list) are never reported. 
  4771.  
  4772.  -n 
  4773.            Don't compile, bind, or link. Checks if all objects are up to date. 
  4774.            If they are not, the full name of the first file that needs to be 
  4775.            recompiled is printed. Repeated use of this option, followed by 
  4776.            compiling the indicated source file, will eventually result in 
  4777.            recompiling all required units. 
  4778.  
  4779.  -o exec_name 
  4780.            Output executable name. The name of the final executable program 
  4781.            will be exec_name. If the -o switch is omitted the default name for 
  4782.            the executable will be the name of the input file in appropriate 
  4783.            form for an executable file on the host system. 
  4784.  
  4785.  -q 
  4786.            Quiet. When this flag is not set, the commands carried out by 
  4787.            gnatmake are displayed. 
  4788.  
  4789.  -s 
  4790.            Recompile if compiler switches have changed since last compilation. 
  4791.            All compiler switches but -I and -o are taken into account in the 
  4792.            following way: orders between different first letter'' switches are 
  4793.            ignored, but orders between same switches are taken into account. 
  4794.            For example, -O -O2 is different than -O2 -O, but -g -O is 
  4795.            equivalent to -O -g. 
  4796.  
  4797.  -v 
  4798.            Verbose. Displays the reason for all recompilations gnatmake decides 
  4799.            are necessary. 
  4800.  
  4801.  -z 
  4802.            No main subprogram. Bind and link the program even if the unit name 
  4803.            given on the command line is a package name. The resulting 
  4804.            executable will execute the elaboration routines of the package and 
  4805.            its closure, then the finalization routines. 
  4806.  
  4807.  gcc switches 
  4808.            The switch -g or any uppercase switch (other than -A, or -L) or any 
  4809.            switch that is more than one character is passed to gcc (e.g. -O, 
  4810.            -gnato, etc.) 
  4811.  
  4812.  Source and library search path switches: 
  4813.  
  4814.  -aIdir 
  4815.            When looking for source files also look in directory dir. The order 
  4816.            in which source files search is undertaken is described in Search 
  4817.            Paths and the Run-Time Library (RTL). 
  4818.  
  4819.  -aLdir 
  4820.            Consider dir as being an externally provided Ada library. Instructs 
  4821.            gnatmake to skip compilation units whose '.ali' files have been 
  4822.            located in directory dir. This allows you to have missing bodies for 
  4823.            the units in dir. You still need to specify the location of the 
  4824.            specs for these units by using the switches -aIdir or -Idir. Note: 
  4825.            this switch is provided for compatibility with previous versions of 
  4826.            gnatmake. The easier method of causing standard libraries to be 
  4827.            excluded from consideration is to write-protect the corresponding 
  4828.            ALI files. 
  4829.  
  4830.  -aOdir 
  4831.            When searching for library and object files, look in directory dir. 
  4832.            The order in which library files are searched is described in Search 
  4833.            Paths for gnatbind. 
  4834.  
  4835.  -Adir 
  4836.            Equivalent to -aLdir -aIdir. 
  4837.  
  4838.  -Idir 
  4839.            Equivalent to -aOdir -aIdir. 
  4840.  
  4841.  -I- 
  4842.            Do not look for source files in the directory containing the source 
  4843.            file named in the command line. Do not look for ALI or object files 
  4844.            in the directory where gnatmake was invoked. 
  4845.  
  4846.  -Ldir 
  4847.            Add directory dir to the list of directories in which the linker 
  4848.            will search for libraries. This is equivalent to -largs -Ldir. 
  4849.  
  4850.  -nostdinc 
  4851.            Do not look for source files in the system default directory. 
  4852.  
  4853.  -nostdlib 
  4854.            Do not look for library files in the system default directory. 
  4855.  
  4856.  
  4857. ΓòÉΓòÉΓòÉ 9.3. Mode switches for gnatmake ΓòÉΓòÉΓòÉ
  4858.  
  4859.  
  4860.  The mode switches (referred to as mode_switches) allow the inclusion of 
  4861.  switches that are to be passed to the compiler itself, the binder or the 
  4862.  linker. The effect of a mode switch is to cause all subsequent switches up to 
  4863.  the end of the switch list, or up to the next mode switch, to be interpreted 
  4864.  as switches to be passed on to the designated component of GNAT. 
  4865.  
  4866.  -cargs switches 
  4867.            Compiler switches. Here switches is a list of switches that are 
  4868.            valid switches for gcc. They will be passed on to all compile steps 
  4869.            performed by gnatmake. 
  4870.  
  4871.  -bargs switches 
  4872.            Binder switches. Here switches is a list of switches that are valid 
  4873.            switches for gcc. They will be passed on to all bind steps performed 
  4874.            by gnatmake. 
  4875.  
  4876.  -largs switches 
  4877.            Linker switches. Here switches is a list of switches that are valid 
  4878.            switches for gcc. They will be passed on to all link steps performed 
  4879.            by gnatmake. 
  4880.  
  4881.  
  4882. ΓòÉΓòÉΓòÉ 9.4. Notes on the Command Line ΓòÉΓòÉΓòÉ
  4883.  
  4884.  
  4885.  This section contains some additional useful notes on the operation of the 
  4886.  gnatmake command. 
  4887.  
  4888.      If gnatmake finds no ALI files, it recompiles the main program and all 
  4889.       other units required by the main program. This means that gnatmake can be 
  4890.       used for the initial compile, as well as during subsequent steps of the 
  4891.       development cycle. 
  4892.  
  4893.      If you enter gnatmake file.adb, where 'file.adb' is a subunit or body of 
  4894.       a generic unit, gnatmake recompiles 'file.adb' (because it finds no ALI) 
  4895.       and stops, issuing a warning. 
  4896.  
  4897.      In gnatmake the switch -I is used to specify both source and library file 
  4898.       paths. Use -aI instead if you just want to specify source paths only and 
  4899.       -aO if you want to specify library paths only. 
  4900.  
  4901.      gnatmake examines both an ALI file and its corresponding object file for 
  4902.       consistency. If an ALI is more recent than its corresponding object, or 
  4903.       if the object file is missing, the corresponding source will be 
  4904.       recompiled. Note that gnatmake expects an ALI and the corresponding 
  4905.       object file to be in the same directory. 
  4906.  
  4907.      gnatmake will ignore any files whose ALI file is write-protected. This 
  4908.       may conveniently be used to exclude standard libraries from consideration 
  4909.       and in particular it means that the use of the -f switch will not 
  4910.       recompile these files unless -a is also specified. 
  4911.  
  4912.      gnatmake has been designed to make the use of Ada libraries particularly 
  4913.       convenient. Assume you have an Ada library organized as follows: obj-dir 
  4914.       contains the objects and ALI files for of your Ada compilation units, 
  4915.       whereas include-dir contains the specs of these units, but no bodies. 
  4916.       Then to compile a unit stored in main.adb, which uses this Ada library 
  4917.       you would just type 
  4918.  
  4919.                       $ gnatmake -aIinclude-dir  -aLobj-dir  main
  4920.  
  4921.      Using gnatmake along with the -m (minimal recompilation) switch provides 
  4922.       an extremely powerful tool: you can freely update the comments/format of 
  4923.       your source files without having to recompile everything. Note, however, 
  4924.       that adding or deleting lines in a source files may render its debugging 
  4925.       info obsolete. If the file in question is a spec, the impact is rather 
  4926.       limited, as that debugging info will only be useful during the 
  4927.       elaboration phase of your program. For bodies the impact can be more 
  4928.       significant. In all events, your debugger will warn you if a source file 
  4929.       is more recent than the corresponding object, and therefore obsolescence 
  4930.       of debugging information will go unnoticed. 
  4931.  
  4932.  
  4933. ΓòÉΓòÉΓòÉ 9.5. How gnatmake Works ΓòÉΓòÉΓòÉ
  4934.  
  4935.  
  4936.  Generally gnatmake automatically performs all necessary recompilations and you 
  4937.  don't need to worry about how it works. However, it may be useful to have some 
  4938.  basic understanding of the gnatmake approach and in particular to understand 
  4939.  how it uses the results of previous compilations without incorrectly depending 
  4940.  on them. 
  4941.  
  4942.  First a definition: an object file is considered up to date if the 
  4943.  corresponding ALI file exists and its time stamp predates that of the object 
  4944.  file and if all the source files listed in the dependency section of this ALI 
  4945.  file have time stamps matching those in the ALI file. This means that neither 
  4946.  the source file itself nor any files that it depends on have been modified, 
  4947.  and hence there is no need to recompile this file. 
  4948.  
  4949.  gnatmake works by first checking if the specified main unit is up to date. If 
  4950.  so, no compilations are required for the main unit. If not, gnatmake compiles 
  4951.  the main program to build a new ALI file that reflects the latest sources. 
  4952.  Then the ALI file of the main unit is examined to find all the source files on 
  4953.  which the main program depends, and gnatmake recursively applies the above 
  4954.  procedure on all these files. 
  4955.  
  4956.  This process ensures that gnatmake only trusts the dependencies in an existing 
  4957.  ALI file if they are known to be correct. Otherwise it always recompiles to 
  4958.  determine a new, guaranteed accurate set of dependencies. As a result the 
  4959.  program is compiled "upside down" from what may be more familiar as the 
  4960.  required order of compilation in some other Ada systems. In particular, 
  4961.  clients are compiled before the units on which they depend. The ability of 
  4962.  GNAT to compile in any order is critical in allowing an order of compilation 
  4963.  to be chosen that guarantees that gnatmake will recompute a correct set of new 
  4964.  dependencies if necessary. 
  4965.  
  4966.  
  4967. ΓòÉΓòÉΓòÉ 9.6. Examples of gnatmake Usage ΓòÉΓòÉΓòÉ
  4968.  
  4969.  gnatmake hello.adb 
  4970.            Compile all files necessary to bind and link the main program 
  4971.            'hello.adb' (containing unit Hello) and bind and link the resulting 
  4972.            object files to generate an executable file 'hello'. 
  4973.  
  4974.  gnatmake -q Main_Unit -cargs -O2 -bargs -l 
  4975.            Compile all files necessary to bind and link the main program unit 
  4976.            Main_Unit (from file 'main_unit.adb'). All compilations will be done 
  4977.            with optimization level 2 and the order of elaboration will be 
  4978.            listed by the binder. gnatmake will operate in quiet mode, not 
  4979.            displaying commands it is executing. 
  4980.  
  4981.  
  4982. ΓòÉΓòÉΓòÉ 10. Renaming Files Using gnatchop ΓòÉΓòÉΓòÉ
  4983.  
  4984.  
  4985.  This chapter discusses how to handle files with multiple units by using the 
  4986.  gnatchop utility. This utility is also useful in renaming files to meet the 
  4987.  standard GNAT default file naming conventions. 
  4988.  
  4989.  Handling Files with Multiple UnitsHandling Files with Multiple Units 
  4990.  Operating gnatchop in Compilation ModeOperating gnatchop in Compilation Mode 
  4991.  Command Line for gnatchop     Command Line for gnatchop 
  4992.  Switches for gnatchop         Switches for gnatchop 
  4993.  Examples of gnatchop Usage    Examples of gnatchop Usage 
  4994.  
  4995.  
  4996. ΓòÉΓòÉΓòÉ 10.1. Handling Files with Multiple Units ΓòÉΓòÉΓòÉ
  4997.  
  4998.  
  4999.  The basic compilation model of GNAT requires that a file submitted to the 
  5000.  compiler have only one unit and there be a strict correspondence between the 
  5001.  file name and the unit name. 
  5002.  
  5003.  The gnatchop utility allows both of these rules to be relaxed, allowing GNAT 
  5004.  to process files which contain multiple compilation units and files with 
  5005.  arbitrary file names. gnatchop reads the specified file and generates one or 
  5006.  more output files, containing one unit per file. The unit and the file name 
  5007.  correspond, as required by GNAT. 
  5008.  
  5009.  If you want to permanently restructure a set of "foreign" files so that they 
  5010.  match the GNAT rules, and do the remaining development using the GNAT 
  5011.  structure, you can simply use gnatchop once, generate the new set of files and 
  5012.  work with them from that point on. 
  5013.  
  5014.  Alternatively, if you want to keep your files in the "foreign" format, perhaps 
  5015.  to maintain compatibility with some other Ada compilation system, you can set 
  5016.  up a procedure where you use gnatchop each time you compile, regarding the 
  5017.  source files that it writes as temporary files that you throw away. 
  5018.  
  5019.  
  5020. ΓòÉΓòÉΓòÉ 10.2. Operating gnatchop in Compilation Mode ΓòÉΓòÉΓòÉ
  5021.  
  5022.  
  5023.  The basic function of gnatchop is to take a file with multiple units and split 
  5024.  it into separate files. The boundary between files is reasonably clear, except 
  5025.  for the issue of comments and pragmas. In default mode, the rule is that any 
  5026.  pragmas between units belong to the previous unit, except that configuration 
  5027.  pragmas always belong to the following unit. Any comments belong to the 
  5028.  following unit. These rules almost always result in the right choice of the 
  5029.  split point without needing to mark it explicitly and most users will find 
  5030.  this default to be what they want. In this default mode it is incorrect to 
  5031.  submit a file containing only configuration pragmas, or one that ends in 
  5032.  configuration pragmas, to gnatchop. 
  5033.  
  5034.  However, using a special option to activate "compilation mode", gnatchop can 
  5035.  perform another function, which is to provide exactly the semantics required 
  5036.  by the RM for handling of configuration pragmas in a compilation. In the 
  5037.  absence of configuration pragmas (at the main file level), this option has no 
  5038.  effect, but it causes such configuration pragmas to be handled in a quite 
  5039.  different manner. 
  5040.  
  5041.  First, in compilation mode, if gnatchop is given a file that consists of only 
  5042.  configuration pragmas, then this file is appended to the 'gnat.adc' file in 
  5043.  the current directory. This behavior provides the required behavior described 
  5044.  in the RM for the actions to be taken on submitting such a file to the 
  5045.  compiler, namely that these pragmas should apply to all subsequent 
  5046.  compilations in the same compilation environment. Using GNAT, the current 
  5047.  directory, possibly containing a 'gnat.adc' file is the representation of a 
  5048.  compilation environment. For more information on the 'gnat.adc' file, see the 
  5049.  section on handling of configuration pragmas see Handling of Configuration 
  5050.  Pragmas. 
  5051.  
  5052.  Second, in compilation mode, if gnatchop is given a file that starts with 
  5053.  configuration pragmas, and contains one or more units, then these 
  5054.  configuration pragmas are prepended to each of the chopped files. This 
  5055.  behavior provides the required behavior described in the RM for the actions to 
  5056.  be taken on compiling such a file, namely that the pragmas apply to all units 
  5057.  in the compilation, but not to subsequently compiled units. 
  5058.  
  5059.  Finally, if configuration pragmas appear between units, they are appended to 
  5060.  the previous unit. This results in the previous unit being illegal, since the 
  5061.  compiler does not accept configuration pragmas that follow a unit. This 
  5062.  provides the required RM behavior that forbids configuration pragmas other 
  5063.  than those preceding the first compilation unit of a compilation. 
  5064.  
  5065.  For most purposes, gnatchop will be used in default mode. The compilation mode 
  5066.  described above is used only if you need exactly accurate behavior with 
  5067.  respect to compilations, and you have files that contain multiple units and 
  5068.  configuration pragmas. In this circumstance the use of gnatchop with the 
  5069.  compilation mode switch provides the required behavior, and is for example the 
  5070.  mode in which GNAT processes the ACVC tests. 
  5071.  
  5072.  
  5073. ΓòÉΓòÉΓòÉ 10.3. Command Line for gnatchop ΓòÉΓòÉΓòÉ
  5074.  
  5075.  
  5076.  The gnatchop command has the form: 
  5077.  
  5078.                       $ gnatchop switches file name [file name file name ┬╖┬╖┬╖] \
  5079.                        [directory]
  5080.  
  5081.  The only required argument is the file name of the file to be chopped. There 
  5082.  are no restrictions on the form of this file name. The file itself contains 
  5083.  one or more Ada units, in normal GNAT format, concatenated together. As shown, 
  5084.  more than one file may be presented to be chopped. 
  5085.  
  5086.  When run in default mode, gnatchop generates one output file in the current 
  5087.  directory for each unit in each of the files. 
  5088.  
  5089.  directory, if specified, gives the name of the directory to which the output 
  5090.  files will be written. If it is not specified, all files are written to the 
  5091.  current directory. 
  5092.  
  5093.  For example, given a file called 'hellofiles' containing 
  5094.  
  5095.                       procedure hello;
  5096.                       with Text_IO; use Text_IO;
  5097.                       procedure hello is
  5098.                       begin
  5099.                         Put_Line ("Hello");
  5100.                       end hello;
  5101.  
  5102.  the command 
  5103.  
  5104.                       $ gnatchop hellofiles
  5105.  
  5106.  generates two files in the current directory, one called 'hello.ads' 
  5107.  containing the single line that is the procedure spec, and the other called 
  5108.  'hello.adb' containing the remaining text. The original file is not affected. 
  5109.  The generated files can be compiled in the normal manner. 
  5110.  
  5111.  
  5112. ΓòÉΓòÉΓòÉ 10.4. Switches for gnatchop ΓòÉΓòÉΓòÉ
  5113.  
  5114.  
  5115.  gnatchop recognizes the following switches: 
  5116.  
  5117.  -c 
  5118.            Causes gnatchop to operate in compilation mode, in which 
  5119.            configuration pragmas are handled according to strict RM rules. See 
  5120.            previous section for a full description of this mode. 
  5121.  
  5122.  -gnatxxx 
  5123.            This passes the given -gnatxxx switch to gnat which is used to parse 
  5124.            the given file. Not all xxx options make sense, but for example, the 
  5125.            use of -gnati2 allows gnatchop to process a source file that uses 
  5126.            Latin-2 coding for identifiers. 
  5127.  
  5128.  -h 
  5129.            Causes gnatchop to generate a brief help summary to the standard 
  5130.            output file showing usage information. 
  5131.  
  5132.  -kmm 
  5133.            Limit generated file names to the specified number mm of characters. 
  5134.            This is useful if the resulting set of files is required to be 
  5135.            interoperable with systems which limit the length of file names. No 
  5136.            space is allowed between the -k and the numeric value. The numeric 
  5137.            value may be omitted in which case a default of -k8, suitable for 
  5138.            use with DOS-like file systems, is used. If no -k switch is present 
  5139.            then there is no limit on the length of file names. 
  5140.  
  5141.  -q 
  5142.            Causes output of informational messages indicating the set of 
  5143.            generated files to be suppressed. Warnings and error messages are 
  5144.            unaffected. 
  5145.  
  5146.  -r 
  5147.            Generate Source_Reference pragmas. Use this switch if the output 
  5148.            files are regarded as temporary and development is to be done in 
  5149.            terms of the original unchopped file. This switch causes 
  5150.            Source_Reference pragmas to be inserted into each of the generated 
  5151.            files to refers back to the original file name and line number. The 
  5152.            result is that all error messages refer back to the original 
  5153.            unchopped file. In addition, the debugging information placed into 
  5154.            the object file (when the -g switch of gcc or gnatmake is specified) 
  5155.            also refers back to this original file so that tools like profilers 
  5156.            and debuggers will give information in terms of the original 
  5157.            unchopped file. 
  5158.  
  5159.            If the original file to be chopped itself contains a 
  5160.            Source_Reference pragma referencing a third file, then gnatchop 
  5161.            respects this pragma, and the generated Source_Reference pragmas in 
  5162.            the chopped file refer to the original file, with appropriate line 
  5163.            numbers. This is particularly useful when gnatchop is used in 
  5164.            conjunction with gnatprep to compile files that contain 
  5165.            preprocessing statements and multiple units. 
  5166.  
  5167.  -v 
  5168.            Causes gnatchop to operate in verbose mode. The version number and 
  5169.            copyright notice are output, as well as exact copies of the gnat1 
  5170.            commands spawned to obtain the chop control information. 
  5171.  
  5172.  -w 
  5173.            Overwrite existing file names. Normally gnatchop regards it as a 
  5174.            fatal error if there is already a file with the same name as a file 
  5175.            it would otherwise output, in other words if the files to be chopped 
  5176.            contain duplicated units. This switch bypasses this check, and 
  5177.            causes all but the last instance of such duplicated units to be 
  5178.            skipped. 
  5179.  
  5180.  
  5181. ΓòÉΓòÉΓòÉ 10.5. Examples of gnatchop Usage ΓòÉΓòÉΓòÉ
  5182.  
  5183.  gnatchop -w hello_s.ada ichbiah/files 
  5184.            Chops the source file 'hello_s.ada'. The output files will be placed 
  5185.            in the directory 'ichbiah/files', overwriting any files with 
  5186.            matching names in that directory (no files in the current directory 
  5187.            are modified). 
  5188.  
  5189.  gnatchop archive 
  5190.            Chops the source file 'archive' into the current directory. One 
  5191.            useful application of gnatchop is in sending sets of sources around, 
  5192.            for example in email messages. The required sources are simply 
  5193.            concatenated (for example, using a UNIX cat command), and then 
  5194.            gnatchop is used at the other end to reconstitute the original file 
  5195.            names. 
  5196.  
  5197.  gnatchop file1 file2 file3 direc 
  5198.            Chops all units in files 'file1', 'file2', 'file3', placing the 
  5199.            resulting files in the directory 'direc'. Note that if any units 
  5200.            occur more than once anywhere within this set of files, an error 
  5201.            message is generated, and no files are written. To override this 
  5202.            check, use the -w switch, in which case the last occurrence in the 
  5203.            last file will be the one that is output, and earlier duplicate 
  5204.            occurrences for a given unit will be skipped. 
  5205.  
  5206.  
  5207. ΓòÉΓòÉΓòÉ 11. Configuration Pragmas ΓòÉΓòÉΓòÉ
  5208.  
  5209.  
  5210.  In Ada 95, configuration pragmas include those pragmas described as such in 
  5211.  the Ada 95 Reference Manual, as well as implementation-dependent pragmas that 
  5212.  are configuration pragmas. See the individual descriptions of pragmas in the 
  5213.  GNAT Reference Manual for details on these additional GNAT-specific 
  5214.  configuration pragmas. Most notably, the pragma Source_File_Name, which allows 
  5215.  specifying non-default names for source files, is a configuration pragma. 
  5216.  
  5217.  Handling of Configuration PragmasHandling of Configuration Pragmas 
  5218.  The Configuration Pragmas fileThe Configuration Pragmas file 
  5219.  
  5220.  
  5221. ΓòÉΓòÉΓòÉ 11.1. Handling of Configuration Pragmas ΓòÉΓòÉΓòÉ
  5222.  
  5223.  Configuration pragmas may either appear at the start of a compilation unit, in 
  5224.  which case they apply only to that unit, or they may apply to all compilations 
  5225.  performed in a given compilation environment. 
  5226.  
  5227.  GNAT also provides the gnatchop utility to provide an automatic way to handle 
  5228.  configuration pragmas following the semantics for compilations (that is, files 
  5229.  with multiple units), described in the RM. See section see Operating gnatchop 
  5230.  in Compilation Mode for details. However, for most purposes, it will be more 
  5231.  convenient to edit the 'gnat.adc' file that contains configuration pragmas 
  5232.  directly, as described in the following section. 
  5233.  
  5234.  
  5235. ΓòÉΓòÉΓòÉ 11.2. The Configuration Pragmas file ΓòÉΓòÉΓòÉ
  5236.  
  5237.  
  5238.  In GNAT a compilation environment is defined by the current directory at the 
  5239.  time that a compile command is given. This current directory is searched for a 
  5240.  file whose name is 'gnat.adc'. If this file is present, it is expected to 
  5241.  contain one or more configuration pragmas that will be applied to the current 
  5242.  compilation. 
  5243.  
  5244.  Configuration pragmas may be entered into the 'gnat.adc' file either by 
  5245.  running gnatchop on a source file that consists only of configuration pragmas, 
  5246.  or more conveniently  by direct editing of the 'gnat.adc' file, which is a 
  5247.  standard format source file. 
  5248.  
  5249.  
  5250. ΓòÉΓòÉΓòÉ 12. Elaboration Order Handling in GNAT ΓòÉΓòÉΓòÉ
  5251.  
  5252.  Elaboration Code in Ada 95    Elaboration Code in Ada 95 
  5253.  Checking the Elaboration Order in Ada 95Checking the Elaboration Order in Ada 
  5254.                                95 
  5255.  Controlling the Elaboration Order in Ada 95Controlling the Elaboration Order 
  5256.                                in Ada 95 
  5257.  Controlling Elaboration in GNAT - Internal CallsControlling Elaboration in 
  5258.                                GNAT - Internal Calls 
  5259.  Controlling Elaboration in GNAT - External CallsControlling Elaboration in 
  5260.                                GNAT - External Calls 
  5261.  Default Behavior in GNAT - Ensuring SafetyDefault Behavior in GNAT - Ensuring 
  5262.                                Safety 
  5263.  What to do if the Default Elaboration Behavior FailsWhat to do if the Default 
  5264.                                Elaboration Behavior Fails 
  5265.  Elaboration for Access-to-Subprogram ValuesElaboration for 
  5266.                                Access-to-Subprogram Values 
  5267.  Summary of Procedures for Elaboration ControlSummary of Procedures for 
  5268.                                Elaboration Control 
  5269.  
  5270.  This chapter describes the handling of elaboration code in Ada 95 and in GNAT, 
  5271.  and discusses how the order of elaboration of program units can be controlled 
  5272.  in GNAT, either automatically or with explicit programming features. 
  5273.  
  5274.  
  5275. ΓòÉΓòÉΓòÉ 12.1. Elaboration Code in Ada 95 ΓòÉΓòÉΓòÉ
  5276.  
  5277.  
  5278.  Ada 95 provides rather general mechanisms for executing code at elaboration 
  5279.  time, that is to say before the main program starts executing. Such code 
  5280.  arises in three contexts: 
  5281.  
  5282.  Initializers for variables. 
  5283.            Variables declared at the library level, in package specs or bodies, 
  5284.            can require initialization that is performed at elaboration time, as 
  5285.            in: 
  5286.  
  5287.                       Sqrt_Half : Float := Sqrt (0.5);
  5288.  
  5289.  Package initialization code 
  5290.            Code in a BEGIN-END section at the outer level of a package body is 
  5291.            executed as part of the package body elaboration code. 
  5292.  
  5293.  Library level task allocators 
  5294.            Tasks that are declared using task allocators at the library level 
  5295.            start executing immediately and hence can execute at elaboration 
  5296.            time. 
  5297.  
  5298.  Subprogram calls are possible in any of these contexts, which means that any 
  5299.  arbitrary part of the program may be executed as part of the elaboration code. 
  5300.  It is even possible to write a program which does all its work at elaboration 
  5301.  time, with a null main program, although stylistically this would usually be 
  5302.  considered an inappropriate way to structure a program. 
  5303.  
  5304.  An important concern arises in the context of elaboration code: we have to be 
  5305.  sure that it is executed in an appropriate order. What we have is numerous 
  5306.  sections of elaboration code, potentially one section for each unit in the 
  5307.  program. It is important that these execute in the correct order. Correctness 
  5308.  here means that, taking the above example of the declaration of Sqrt_Half, if 
  5309.  some other piece of elaboration code references Sqrt_Half, then it must run 
  5310.  after the section of elaboration code that contains the declaration of 
  5311.  Sqrt_Half. 
  5312.  
  5313.  There would never be any order of elaboration problem if we made a rule that 
  5314.  whenever you with a unit, you must elaborate both the spec and body of that 
  5315.  unit before elaborating the unit doing the with'ing: 
  5316.  
  5317.                       with Unit_1;
  5318.                       package Unit_2 is ┬╖┬╖┬╖
  5319.  
  5320.  would require that both the body and spec of Unit_1 be elaborated before the 
  5321.  spec of Unit_2. However, a rule like that would be far too restrictive. In 
  5322.  particular, it would make it impossible to have routines in separate packages 
  5323.  that were mutually recursive. 
  5324.  
  5325.  You might think that a clever enough compiler could look at the actual 
  5326.  elaboration code and determine an appropriate correct order of elaboration, 
  5327.  but in the general case, this is not possible. Consider the following example. 
  5328.  
  5329.  In the body of Unit_1, we have a procedure Func_1 that references the variable 
  5330.  Sqrt_1, which is declared in the elaboration code of the body of Unit_1: 
  5331.  
  5332.                       Sqrt_1 : Float := Sqrt (0.1);
  5333.  
  5334.  The elaboration code of the body of Unit_1 also contains: 
  5335.  
  5336.                       if expression_1 = 1 then
  5337.                         Q := Unit_2.Func_2;
  5338.                       end if;
  5339.  
  5340.  Unit_2 is exactly parallel, it has a procedure Func_2 that references the 
  5341.  variable Sqrt_2, which is declared in the elaboration code of the body Unit_2: 
  5342.  
  5343.                       Sqrt_2 : Float := Sqrt (0.1);
  5344.  
  5345.  The elaboration code of the body of Unit_2 also contains: 
  5346.  
  5347.                       if expression_2 = 2 then
  5348.                         Q := Unit_1.Func_1;
  5349.                       end if;
  5350.  
  5351.  Now the question is, which of the following orders of elaboration is 
  5352.  acceptable: 
  5353.  
  5354.                       Spec of Unit_1
  5355.                       Spec of Unit_2
  5356.                       Body of Unit_1
  5357.                       Body of Unit_2
  5358.  
  5359.  or 
  5360.  
  5361.                       Spec of Unit_2
  5362.                       Spec of Unit_1
  5363.                       Body of Unit_2
  5364.                       Body of Unit_1
  5365.  
  5366.  If you carefully analyze the flow here, you will see that you cannot tell at 
  5367.  compile time the answer to this question. If expression_1 is not equal to 1, 
  5368.  and expression_2 is not equal to 2, then either order is acceptable, because 
  5369.  neither of the function calls is executed. If both tests evaluate to true, 
  5370.  then neither order is acceptable and in fact there is no correct order. 
  5371.  
  5372.  If one of the two expressions is true, and the other is false, then one of the 
  5373.  above orders is correct, and the other is incorrect. For example, if 
  5374.  expression_1 = 1 and expression_2 /= 2, then the call to Func_2 will occur, 
  5375.  but not the call to Func_1. This means that it is essential to elaborate the 
  5376.  body of Unit_1 before the body of Unit_2, so the first order of elaboration is 
  5377.  correct and the second is wrong. 
  5378.  
  5379.  By making expression_1 and expression_2 depend on input data, or perhaps the 
  5380.  time of day, we can make it impossible for the compiler or binder to figure 
  5381.  out which of these expressions will be true, and hence it is impossible to 
  5382.  guarantee a safe order of elaboration at run time. 
  5383.  
  5384.  
  5385. ΓòÉΓòÉΓòÉ 12.2. Checking the Elaboration Order in Ada 95 ΓòÉΓòÉΓòÉ
  5386.  
  5387.  
  5388.  In some languages that involve the same kind of elaboration problems, e.g. 
  5389.  Java and C++, the programmer is expected to worry about these ordering 
  5390.  problems himself, and it is common to write a program in which an incorrect 
  5391.  elaboration order  gives surprising results, because it references variables 
  5392.  before they are initialized. Ada 95 is designed to be a safe language, and a 
  5393.  programmer-beware approach is clearly not sufficient. Consequently, the 
  5394.  language provides three lines of defense: 
  5395.  
  5396.  Standard rules 
  5397.            Some standard rules restrict the possible choice of elaboration 
  5398.            order. In particular, if you with a unit, then its spec is always 
  5399.            elaborated before the unit doing the with. Similarly, a parent spec 
  5400.            is always elaborated before the child spec, and finally a spec is 
  5401.            always elaborated before its corresponding body. 
  5402.  
  5403.  Dynamic elaboration checks 
  5404.            Dynamic checks are made at run time, so that if some entity is 
  5405.            accessed before it is elaborated (typically  by means of a 
  5406.            subprogram call) then the exception (Program_Error) is raised. 
  5407.  
  5408.  Elaboration control 
  5409.            Facilities are provided for the programmer to specify the desired 
  5410.            order of elaboration. 
  5411.  
  5412.  Let's look at these facilities in more detail. First, the rules for dynamic 
  5413.  checking. One possible rule would be simply to say that the exception is 
  5414.  raised if you access a variable which has not yet been elaborated. The trouble 
  5415.  with this approach is that it could require expensive checks on every variable 
  5416.  reference. Instead Ada 95 has two rules which are a little more restrictive, 
  5417.  but easier to check, and easier to state: 
  5418.  
  5419.  Restrictions on calls 
  5420.            A subprogram can only be called at elaboration time if its body has 
  5421.            been elaborated. The rules for elaboration given above guarantee 
  5422.            that the spec of the subprogram has been elaborated before the call, 
  5423.            but not the body. If this rule is violated, then the exception 
  5424.            Program_Error is raised. 
  5425.  
  5426.  Restrictions on instantiations 
  5427.            A generic unit can only be instantiated if the body of the generic 
  5428.            unit has been elaborated. Again, the rules for elaboration given 
  5429.            above guarantee that the spec of the generic unit has been 
  5430.            elaborated before the instantiation, but not the body. If this rule 
  5431.            is violated, then the exception Program_Error is raised. 
  5432.  
  5433.  The idea is that if the body has been elaborated, then any variables it 
  5434.  references must have been elaborated; by checking for the body being 
  5435.  elaborated we guarantee that none of its references causes any trouble. As we 
  5436.  noted above, this is a little too restrictive, because a subprogram that has 
  5437.  no non-local references in its body may in fact be safe to call. However, it 
  5438.  really would be unsafe to rely on this, because it would mean that the caller 
  5439.  was aware of details of the implementation in the body. This goes against the 
  5440.  basic tenets of Ada. 
  5441.  
  5442.  A plausible implementation can be described as follows. A Boolean variable is 
  5443.  associated with each subprogram and each generic unit. This variable is 
  5444.  initialized to False, and is set to True at the point body is elaborated. 
  5445.  Every call or instantiation checks the variable, and raises Program_Error if 
  5446.  the variable is False. 
  5447.  
  5448.  
  5449. ΓòÉΓòÉΓòÉ 12.3. Controlling the Elaboration Order in Ada 95 ΓòÉΓòÉΓòÉ
  5450.  
  5451.  
  5452.  In the previous section we discussed the rules in Ada 95 which ensure that 
  5453.  Program_Error is raised if an incorrect elaboration order is chosen. This 
  5454.  prevents erroneous executions, but we need mechanisms to specify a correct 
  5455.  execution and avoid the exception altogether. To achieve this, Ada 95 provides 
  5456.  a number of features for controlling the order of elaboration. We discuss 
  5457.  these features in this section. 
  5458.  
  5459.  First, there are several ways of indicating to the compiler that a given unit 
  5460.  has no elaboration problems: 
  5461.  
  5462.  packages that do not require a body 
  5463.            In Ada 95, a library package that does not require a body does not 
  5464.            permit a body. This means that if we have a such a package, as in: 
  5465.  
  5466.                       package Definitions is
  5467.                         generic
  5468.                          type m is new integer;
  5469.                         package Subp is
  5470.                          type a is array (1 ┬╖┬╖ 10) of m;
  5471.                          type b is array (1 ┬╖┬╖ 20) of m;
  5472.                         end Subp;
  5473.                       end Definitions;
  5474.  
  5475.  A package that with's Definitions may safely instantiate Definitions.Subp 
  5476.  because the compiler can determine that there definitely is no package body to 
  5477.  worry about in this case 
  5478.  
  5479.  pragma Pure 
  5480.            Places sufficient restrictions on a unit to guarantee that no call 
  5481.            to any subprogram in the unit can result in an elaboration problem. 
  5482.            This means that the compiler does not need to worry about the point 
  5483.            of elaboration of such units, and in particular, does not need to 
  5484.            check any calls to any subprograms in this unit. 
  5485.  
  5486.  pragma Preelaborate 
  5487.            This pragma places slightly less stringent restrictions on a unit 
  5488.            than does pragma Pure, but these restrictions are still sufficient 
  5489.            to ensure that there are no elaboration problems with any calls to 
  5490.            the unit. 
  5491.  
  5492.  pragma Elaborate_Body 
  5493.            This pragma requires that the body of a unit be elaborated 
  5494.            immediately after its spec. Suppose a unit A has such a pragma, and 
  5495.            unit B does a with of unit A. Recall that the standard rules require 
  5496.            the spec of unit A to be elaborated before the with'ing unit; given 
  5497.            the pragma in A, we also know that the body of A will be elaborated 
  5498.            before B, so that calls to A are safe and do not need a check. 
  5499.  
  5500.  Note that, unlike pragma Pure and pragma Preelaborate, the use of 
  5501.  Elaborate_Body does not guarantee that the program is free of elaboration 
  5502.  problems, because it may not be possible to satisfy the requested elaboration 
  5503.  order. Let's go back to the example with Unit_1 and Unit_2. If a programmer 
  5504.  marks Unit_1 as Elaborate_Body, and not Unit_2, then the order of elaboration 
  5505.  will be: 
  5506.  
  5507.                       Spec of Unit_2
  5508.                       Spec of Unit_1
  5509.                       Body of Unit_1
  5510.                       Body of Unit_2
  5511.  
  5512.  Now that means that the call to Func_1 in Unit_2 need not be checked, it must 
  5513.  be safe. But the call to Func_2 in Unit_1 may still fail if Expression_1 is 
  5514.  equal to 1, and the programmer must still take responsibility for this not 
  5515.  being the case. 
  5516.  
  5517.  If all units carry a pragma Elaborate_Body, then all problems are eliminated, 
  5518.  except for calls entirely within a body, which are in any case fully under 
  5519.  programmer control. However, using the pragma everywhere is not always 
  5520.  possible. In particular, for our Unit_1/Unit_2 example, if we marked both of 
  5521.  them as having pragma Elaborate_Body, then clearly there would be no possible 
  5522.  elaboration order. 
  5523.  
  5524.  The above pragmas allow a server to guarantee safe use by clients, and clearly 
  5525.  this is the preferable approach. Consequently a good rule in Ada 95 is to mark 
  5526.  units as Pure or Preelaborate if possible, and if this is not possible, mark 
  5527.  them as Elaborate_Body if possible. As we have seen, there are situation where 
  5528.  neither of these three pragmas can be used. So we also provide methods for 
  5529.  clients to control the order of elaboration of the servers on which they 
  5530.  depend: 
  5531.  
  5532.  pragma Elaborate (unit) 
  5533.            This pragma is placed in the context clause, after a with statement, 
  5534.            and it requires that the body of the named unit be elaborated before 
  5535.            the unit in which the pragma occurs. The idea is to use this pragma 
  5536.            if the current unit calls at elaboration time, directly or 
  5537.            indirectly, some subprogram in the named unit. 
  5538.  
  5539.  pragma Elaborate_All (unit) 
  5540.            This is a stronger version of the Elaborate pragma. Consider the 
  5541.            following example: 
  5542.  
  5543.                       Unit A with's unit B and calls B.Func in elab code
  5544.                       Unit B with's unit C, and B.Func calls C.Func
  5545.  
  5546.  Now if we put a pragma Elaborate (B) in unit A, this ensures that the body of 
  5547.  B is elaborated before the call, but not the body of C, so the call to C.Func 
  5548.  could still cause Program_Error to be raised. 
  5549.  
  5550.  The effect of a pragma Elaborate_All is stronger, it requires not only that 
  5551.  the body of the named unit be elaborated before the unit doing the with, but 
  5552.  also the bodies of all units that the named unit uses, following with links 
  5553.  transitively. For example, if we put a pragma Elaborate_All (B) in unit A, 
  5554.  then it requires not only that the body of B be elaborated before A, but also 
  5555.  the body of C, because B with's C. 
  5556.  
  5557.  We are now in a position to give a usage rule in Ada 95 for avoiding 
  5558.  elaboration problems, at least if dynamic dispatching and access to subprogram 
  5559.  values are not used. We will handle these cases separately later. 
  5560.  
  5561.  The rule is simple. If a unit has elaboration code that can directly or 
  5562.  indirectly make a call to a subprogram in a with'ed unit, or instantiate a 
  5563.  generic unit in a with'ed unit, then if the with'ed unit does not have pragma 
  5564.  Pure, Preelaborate, or Elaborate_Body, then the client should have an 
  5565.  Elaborate_All for the with'ed unit. By following this rule a client is assured 
  5566.  that calls can be made without risk of an exception. If this rule is not 
  5567.  followed, then a program may be in one of four states: 
  5568.  
  5569.  No order exists 
  5570.            No order of elaboration exists which follows the rules, taking into 
  5571.            account any Elaborate, Elaborate_All, or Elaborate_Body pragmas. In 
  5572.            this case, an Ada 95 compiler must diagnose the situation at bind 
  5573.            time, and refuse to build an executable program. 
  5574.  
  5575.  One or more orders exist, all incorrect 
  5576.            One or more acceptable elaboration orders exists, and all of them 
  5577.            generate an elaboration order problem. In this case, the binder can 
  5578.            build an executable program, but Program_Error will be raised when 
  5579.            the program is run. 
  5580.  
  5581.  Several orders exist, some right, some incorrect 
  5582.            One or more acceptable elaboration orders exists, and some of them 
  5583.            work, and some do not. The programmer has not controlled the order 
  5584.            of elaboration, so the binder may or may not pick one of the correct 
  5585.            orders, and the program may or may not raise an exception when it is 
  5586.            run. This is the worst case, because it means that the program may 
  5587.            fail when moved to another compiler, or even another version of the 
  5588.            same compiler. 
  5589.  
  5590.  One or more orders exists, all correct 
  5591.            One ore more acceptable elaboration orders exist, and all of them 
  5592.            work. In this case the program runs successfully. This state of 
  5593.            affairs can be guaranteed by following the rule we gave above, but 
  5594.            may be true even if the rule is not followed. 
  5595.  
  5596.  Note that one additional advantage of following our Elaborate_All rule is that 
  5597.  the program continues to stay in the ideal (all orders OK) state even if 
  5598.  maintenance changes some bodies of some subprograms. Conversely, if a program 
  5599.  that does not follow this rule happens to be safe at some point, this state of 
  5600.  affairs may deteriorate silently as a result of maintenance changes. 
  5601.  
  5602.  
  5603. ΓòÉΓòÉΓòÉ 12.4. Controlling Elaboration in GNAT - Internal Calls ΓòÉΓòÉΓòÉ
  5604.  
  5605.  
  5606.  In the case of internal calls, i.e. calls within a single package, the 
  5607.  programmer has full control over the order of elaboration, and it is up to the 
  5608.  programmer to elaborate declarations in an appropriate order. For example 
  5609.  writing: 
  5610.  
  5611.                       function One return Float;
  5612.                       Q : Float := One;
  5613.                       function One return Float is
  5614.                       begin
  5615.                          return 1.0;
  5616.                       end One;
  5617.  
  5618.  will obviously raise Program_Error at run time, because function One will be 
  5619.  called before its body is elaborated. In this case GNAT will generate a 
  5620.  warning that the call will raise Program_Error: 
  5621.  
  5622.                        1. procedure y is
  5623.                        2.   function One return Float;
  5624.                        3.
  5625.                        4.   Q : Float := One;
  5626.                                 |
  5627.                         >>> warning: cannot call "One" before body is elaborated
  5628.                         >>> warning: Program_Error will be raised at run time
  5629.                        5.
  5630.                        6.   function One return Float is
  5631.                        7.   begin
  5632.                        8.     return 1.0;
  5633.                        9.   end One;
  5634.                       10.
  5635.                       11. begin
  5636.                       12.   null;
  5637.                       13. end;
  5638.  
  5639.  Note that in this particular case, it is likely that the call is safe, because 
  5640.  the function One does not access any global variables. Nevertheless in Ada 95, 
  5641.  we do not want the validity of the check to depend on the contents of the body 
  5642.  (think about the separate compilation case), so this is still wrong, as we 
  5643.  discussed in the previous sections. 
  5644.  
  5645.  The error is easily corrected by rearranging the declarations so that the body 
  5646.  of One appears before the declaration containing the call (note that in Ada 
  5647.  95, declarations can appear in any order, so there is no restriction that 
  5648.  would prevent this reordering, and if we write: 
  5649.  
  5650.                       function One return Float;
  5651.                       function One return Float is
  5652.                       begin
  5653.                          return 1.0;
  5654.                       end One;
  5655.                       Q : Float := One;
  5656.  
  5657.  then all is well, no warning is generated, and no Program_Error exception will 
  5658.  be raised. Things are more complicated when a chain of subprograms is 
  5659.  executed: 
  5660.  
  5661.                       function A return Integer;
  5662.                       function B return Integer;
  5663.                       function C return Integer;
  5664.                       function B return Integer is begin return A; end;
  5665.                       function C return Integer is begin return B; end;
  5666.                       X : Integer := C;
  5667.                       function A return Integer is begin return 1; end;
  5668.  
  5669.  Now the call to C at elaboration time in the declaration of X is correct, 
  5670.  because the body of C is already elaborated, and the call to B within the body 
  5671.  of C is correct, but the call to A within the body of B is incorrect, because 
  5672.  the body of A has not been elaborated, so Program_Error will be raised on the 
  5673.  call to A. In this case GNAT will generate a warning that Program_Error may be 
  5674.  raised at the point of the call. Let's look at the warning: 
  5675.  
  5676.                        1. procedure x is
  5677.                        2.   function A return Integer;
  5678.                        3.   function B return Integer;
  5679.                        4.   function C return Integer;
  5680.                        5.
  5681.                        6.   function B return Integer is begin return A; end;
  5682.                                                 |
  5683.                         >>> warning: call to "A" before body is elaborated may
  5684.                                raise Program_Error
  5685.                         >>> warning: "B" called at line 7
  5686.                         >>> warning: "C" called at line 9
  5687.                        7.   function C return Integer is begin return B; end;
  5688.                        8.
  5689.                        9.   X : Integer := C;
  5690.                       10.
  5691.                       11.   function A return Integer is begin return 1; end;
  5692.                       12.
  5693.                       13. begin
  5694.                       14.   null;
  5695.                       15. end;
  5696.  
  5697.  Note that the message here says "may raise", instead of the direct case, where 
  5698.  the message says "will be raised". That's because whether A is actually called 
  5699.  depends in general on run-time flow of control. For example, if the body of B 
  5700.  said 
  5701.  
  5702.                       function B return Integer is
  5703.                       begin
  5704.                         if some-condition-depending-on-input-data then
  5705.                          return A;
  5706.                         else
  5707.                          return 1;
  5708.                         end if;
  5709.                       end B;
  5710.  
  5711.  then we could not know until run time whether the incorrect call to A would 
  5712.  actually occur, so Program_Error might or might not be raised. It is possible 
  5713.  for a compiler to do a better job of analyzing bodies, to determine whether or 
  5714.  not Program_Error might be raised, but it certainly couldn't do a perfect job 
  5715.  (that would require solving the halting problem and is provably impossible), 
  5716.  and because this is a warning anyway, it does not seem worth the effort to do 
  5717.  the analysis. Cases in which it would be relevant are rare. 
  5718.  
  5719.  In practice, warnings of either of the forms given above will usually 
  5720.  correspond to real errors, and should be examined carefully and eliminated. In 
  5721.  the rare case where a warning is bogus, it can be suppressed by any of the 
  5722.  following methods: 
  5723.  
  5724.      Compile with the -gnatws switch set 
  5725.  
  5726.      Suppress Elaboration_Checks for the called subprogram 
  5727.  
  5728.      Use pragma Warnings_Off to turn warnings off for the call 
  5729.  
  5730.  For the internal elaboration check case, GNAT by default generates the 
  5731.  necessary run-time checks to ensure that Program_Error is raised if any call 
  5732.  fails an elaboration check. Of course this can only happen if a warning has 
  5733.  been issued as described above. The use of pragma Suppress 
  5734.  (Elaboration_Checks) may (but is not guaranteed) to suppress some of these 
  5735.  checks, meaning that it may be possible (but is not guaranteed) for a program 
  5736.  to be able to call a subprogram whose body is not yet elaborated, without 
  5737.  raising a Program_Error exception. 
  5738.  
  5739.  
  5740. ΓòÉΓòÉΓòÉ 12.5. Controlling Elaboration in GNAT - External Calls ΓòÉΓòÉΓòÉ
  5741.  
  5742.  
  5743.  The previous section discussed the case in which the execution of a particular 
  5744.  thread of elaboration code occurred entirely within a single unit. This is the 
  5745.  easy case to handle, because a programmer has direct and total control over 
  5746.  the order of elaboration, and furthermore, checks need only be generated in 
  5747.  cases which are rare and which the compiler can easily detect. The situation 
  5748.  is more complex when separate compilation is taken into account. Consider the 
  5749.  following: 
  5750.  
  5751.                       package Math is
  5752.                         function Sqrt (Arg : Float) return Float;
  5753.                       end Math;
  5754.                       package body Math is
  5755.                         function Sqrt (Arg : Float) return Float is
  5756.                         begin
  5757.                            ┬╖┬╖┬╖
  5758.                         end Sqrt;
  5759.                       end Math;
  5760.                       with Math;
  5761.                       package Stuff is
  5762.                         X : Float := Math.Sqrt (0.5);
  5763.                       end Stuff;
  5764.                       with Stuff;
  5765.                       procedure Main is
  5766.                       begin
  5767.                         ┬╖┬╖┬╖
  5768.                       end Main;
  5769.  
  5770.  where Main is the main program. When this program is executed, the elaboration 
  5771.  code must first be executed, and one of the jobs of the binder is to determine 
  5772.  the order in which the units of a program are to be elaborated. In this case 
  5773.  we have four units: the spec and body of Math, the spec of Stuff and the body 
  5774.  of Main). In what order should the four separate sections of elaboration code 
  5775.  be executed? 
  5776.  
  5777.  There are some restrictions in the order of elaboration that the binder can 
  5778.  choose. In particular, if unit U has a with for a package X, then you are 
  5779.  assured that the spec of X is elaborated before U , but you are not assured 
  5780.  that the body of X is elaborated before U. This means that in the above case, 
  5781.  the binder is allowed to choose the order: 
  5782.  
  5783.                       spec of Math
  5784.                       spec of Stuff
  5785.                       body of Math
  5786.                       body of Main
  5787.  
  5788.  but that's not good, because now the call to Math.Sqrt that happens during the 
  5789.  elaboration of the Stuff spec happens before the body of Math.Sqrt is 
  5790.  elaborated, and hence causes Program_Error exception to be raised. At first 
  5791.  glance, one might say that the binder is misbehaving, because obviously you 
  5792.  want to elaborate the body of something you with first, but that is not a 
  5793.  general rule that can be followed in all cases. Consider 
  5794.  
  5795.                       package X is ┬╖┬╖┬╖
  5796.                       package Y is ┬╖┬╖┬╖
  5797.                       with X;
  5798.                       package body Y is ┬╖┬╖┬╖
  5799.                       with Y;
  5800.                       package body X is ┬╖┬╖┬╖
  5801.  
  5802.  This is a common arrangement, and, apart from the order of elaboration 
  5803.  problems that might arise in connection with elaboration code, this works 
  5804.  fine. A rule that says that you must first elaborate the body of anything you 
  5805.  with cannot work in this case (the body of X with's Y, which means you would 
  5806.  have to elaborate the body of Y first, but that with's X, which means you have 
  5807.  to elaborate the body of X first, but ┬╖┬╖┬╖ and we have a loop that cannot be 
  5808.  broken. 
  5809.  
  5810.  It is true that the binder can in many cases guess an order of elaboration 
  5811.  that is unlikely to cause a Program_Error exception to be raised, and it tries 
  5812.  to do so (in the above example of Math/Stuff/Spec, the GNAT binder will in 
  5813.  fact always elaborate the body of Math right after its spec, so all will be 
  5814.  well). 
  5815.  
  5816.  However, a program that blindly relies on the binder to be helpful can get 
  5817.  into trouble, as we discussed in the previous sections, so GNAT provides a 
  5818.  number of facilities for assisting the programmer in developing programs that 
  5819.  are robust with respect to elaboration order. 
  5820.  
  5821.  
  5822. ΓòÉΓòÉΓòÉ 12.6. Default Behavior in GNAT - Ensuring Safety ΓòÉΓòÉΓòÉ
  5823.  
  5824.  
  5825.  The default behavior in GNAT ensures elaboration safety. In its default mode 
  5826.  GNAT implements the rule we previously described as the right approach. Let's 
  5827.  restate it: 
  5828.  If a unit has elaboration code that can directly or indirectly make a call to 
  5829.  a subprogram in a with'ed unit, or instantiate a generic unit in a with'ed 
  5830.  unit, then if the with'ed unit does not have pragma Pure, Preelaborate, or 
  5831.  Elaborate_Body, then the client should have an Elaborate_All for the with'ed 
  5832.  unit. By following this rule a client is assured that calls and instantiations 
  5833.  can be made without risk of an exception. 
  5834.  
  5835.  In this mode GNAT traces all calls that are potentially made from elaboration 
  5836.  code, and puts in any missing implicit Elaborate_All pragmas. The advantage of 
  5837.  this approach is that no elaboration problems are possible if the binder can 
  5838.  find an elaboration order that is consistent with these implicit Elaborate_All 
  5839.  pragmas. The disadvantage of this approach is that no such order may exist. 
  5840.  
  5841.  If the binder does not generate any diagnostics, then it means that it has 
  5842.  found an elaboration order that is guaranteed to be safe. However, the binder 
  5843.  may still be relying on implicitly generated Elaborate_All pragmas so 
  5844.  portability to other compilers than GNAT is not guaranteed. 
  5845.  
  5846.  If it is important to guarantee portability, then the compilations should use 
  5847.  the -gnatwl (warn on elaboration problems) switch. This will cause warning 
  5848.  messages to be generated indicating the missing Elaborate_All pragmas. 
  5849.  Consider the following source program: 
  5850.  
  5851.                       with k;
  5852.                       package j is
  5853.                        m : integer := k.r;
  5854.                       end;
  5855.  
  5856.  where it is clear that there should be a pragma Elaborate_All for unit k. An 
  5857.  implicit pragma will be generated, and it is likely that the binder will be 
  5858.  able to honor it. However, it is safer to include the pragma explicitly in the 
  5859.  source. If this unit is compiled with the -gnatwl switch, then the compiler 
  5860.  outputs a warning: 
  5861.  
  5862.                       1. with k;
  5863.                       2. package j is
  5864.                       3.  m : integer := k.r;
  5865.                                  |
  5866.                         >>> warning: call to "r" may raise Program_Error
  5867.                         >>> warning: missing pragma Elaborate_All for "k"
  5868.                       4. end;
  5869.  
  5870.  and these warnings can be used as a guide for supplying manually the missing 
  5871.  pragmas. 
  5872.  
  5873.  
  5874. ΓòÉΓòÉΓòÉ 12.7. What to do if the Default Elaboration Behavior Fails ΓòÉΓòÉΓòÉ
  5875.  
  5876.  
  5877.  If the binder cannot find an acceptable order, it outputs detailed 
  5878.  diagnostics. For example: 
  5879.  
  5880.                       error: elaboration circularity detected
  5881.                       info:  "proc (body)" must be elaborated before "pack (body)"
  5882.                       info:   reason: Elaborate_All probably needed in unit "pack (body)"
  5883.                       info:   recompile "pack (body)" with -gnatwl
  5884.                       info:               for full details
  5885.                       info:    "proc (body)"
  5886.                       info:     is needed by its spec:
  5887.                       info:    "proc (spec)"
  5888.                       info:     which is withed by:
  5889.                       info:    "pack (body)"
  5890.                       info:  "pack (body)" must be elaborated before "proc (body)"
  5891.                       info:   reason: pragma Elaborate in unit "proc (body)"
  5892.  
  5893.  In this case we have a cycle that the binder cannot break. On the one hand, 
  5894.  there is an explicit pragma Elaborate in proc for pack. This means that the 
  5895.  body of pack must be elaborated before the body of proc. On the other hand, 
  5896.  there is elaboration code in pack that calls a subprogram in proc. This means 
  5897.  that for maximum safety, there should really be a pragma Elaborate_All in pack 
  5898.  for proc which would require that the body of proc be elaborated before the 
  5899.  body of pack. Clearly both requirements cannot be satisfied. Faced with a 
  5900.  circularity of this kind, you have three different options. 
  5901.  
  5902.  Fix the program 
  5903.            The most desirable option from the point of view of long-term 
  5904.            maintenance is to rearrange the program so that the elaboration 
  5905.            problems are avoided. One useful technique is to place the 
  5906.            elaboration code into separate child packages. Another is to move 
  5907.            some of the initialization code to explicitly called subprograms, 
  5908.            where the program controls the order of initialization explicitly. 
  5909.            Although this is the most desirable option, it may be impractical 
  5910.            and involve too much modification, especially in the case of complex 
  5911.            legacy code. 
  5912.  
  5913.  Perform dynamic checks 
  5914.            If the compilations are done using the -gnatE (dynamic elaboration 
  5915.            check) switch, then GNAT behaves in a quite different manner. 
  5916.            Dynamic checks are generated for all calls that could possibly 
  5917.            result in raising an exception. With this switch, the compiler does 
  5918.            not generate implicit Elaborate_All pragmas. The behavior then is 
  5919.            exactly as specified in the Ada 95 Reference Manual. The binder will 
  5920.            generate an executable program that may or may not raise 
  5921.            Program_Error, and then it is the programmer's job to ensure that it 
  5922.            does not raise an exception. Note that it is important to compile 
  5923.            all units with the switch, it cannot be used selectively. 
  5924.  
  5925.  Suppress checks 
  5926.            The drawback of dynamic checks is that they generate a significant 
  5927.            overhead at run time, both in space and time. If you are absolutely 
  5928.            sure that your program cannot raise any elaboration exceptions, then 
  5929.            you can use the -f switch for the gnatbind step, or -bargs -f if you 
  5930.            are using gnatmake. This switch tells the binder to ignore any 
  5931.            implicit Elaborate_All pragmas that were generated by the compiler, 
  5932.            and suppresses any circularity messages that they cause. The 
  5933.            resulting executable will work properly if there are no elaboration 
  5934.            problems, but if there are some order of elaboration problems they 
  5935.            will not be detected, and unexpected results may occur. 
  5936.  
  5937.  It is hard to generalize on which of these three approaches should be taken. 
  5938.  Obviously if it is possible to fix the program so that the default treatment 
  5939.  works, this is preferable, but this may not always be practical. It is 
  5940.  certainly simple enough to use -gnatE or -f but the danger in either case is 
  5941.  that, even if the GNAT binder finds a correct elaboration order, it may not 
  5942.  always do so, and certainly a binder from another Ada compiler might not. A 
  5943.  combination of testing and analysis (for which the warnings generated with the 
  5944.  -gnatwl switch can be useful) must be used to ensure that the program is free 
  5945.  of errors. One switch that is useful in this testing is the -h (horrible 
  5946.  elaboration order) switch for gnatbind. Normally the binder tries to find an 
  5947.  order that has the best chance of of avoiding elaboration problems. With this 
  5948.  switch, the binder plays a devil's advocate role, and tries to choose the 
  5949.  order that has the best chance of failing. If your program works even with 
  5950.  this switch, then it has a better chance of being error free, but this is 
  5951.  still not a guarantee. 
  5952.  
  5953.  For an example of this approach in action, consider the C-tests (executable 
  5954.  tests) from the ACVC suite. If these are compiled and run with the default 
  5955.  treatment, then all but one of them succeed without generating any error 
  5956.  diagnostics from the binder. However, there is one test that fails, and this 
  5957.  is not surprising, because the whole point of this test is to ensure that the 
  5958.  compiler can handle cases where it is impossible to determine a correct order 
  5959.  statically, and it checks that an exception is indeed raised at run time. 
  5960.  
  5961.  This one test must be compiled and run using the -gnatE switch, and then it 
  5962.  passes. Alternatively, the entire suite can be run using this switch. It is 
  5963.  never wrong to run with the dynamic elaboration switch if your code is 
  5964.  correct, and we assume that the C-tests are indeed correct (it is less 
  5965.  efficient, but efficiency is not a factor in running the ACVC tests.) 
  5966.  
  5967.  
  5968. ΓòÉΓòÉΓòÉ 12.8. Elaboration for Access-to-Subprogram Values ΓòÉΓòÉΓòÉ
  5969.  
  5970.  
  5971.  The introduction of access-to-subprogram types in Ada 95 complicates the 
  5972.  handling of elaboration. The trouble is that it becomes impossible to tell at 
  5973.  compile time which procedure is being called. This means that it is not 
  5974.  possible for the binder to analyze the elaboration requirements in this case. 
  5975.  
  5976.  If at the point at which  the access value is created, the body of the 
  5977.  subprogram is known to have been elaborated, then the access value is safe, 
  5978.  and its use does not require a check. This may be achieved by appropriate 
  5979.  arrangement of the order of declarations if the subprogram is in the current 
  5980.  unit, or, if the subprogram is in another unit, by using pragma Pure, 
  5981.  Preelaborate, or Elaborate_Body on the referenced unit. 
  5982.  
  5983.  If the referenced body is not known to have been elaborated at the point the 
  5984.  access value is created, then any use of the access value must do a dynamic 
  5985.  check, and this dynamic check will fail and raise a Program_Error exception if 
  5986.  the body has not been elaborated yet. GNAT will generate the necessary checks, 
  5987.  and in addition, if the -gnatwl switch is set, will generate warnings that 
  5988.  such checks are required. 
  5989.  
  5990.  The use of dynamic dispatching for tagged types similarly generates a 
  5991.  requirement for dynamic checks, and premature calls to any primitive operation 
  5992.  of a tagged type before the body of the operation has been elaborated, will 
  5993.  result in the raising of Program_Error. 
  5994.  
  5995.  
  5996. ΓòÉΓòÉΓòÉ 12.9. Summary of Procedures for Elaboration Control ΓòÉΓòÉΓòÉ
  5997.  
  5998.  
  5999.  First, compile your program with the default options, using none of the 
  6000.  special elaboration control switches. If the binder successfully binds your 
  6001.  program, then you can be confident that, apart from issues raised by the use 
  6002.  of access-to-subprogram types and dynamic dispatching, the program is free of 
  6003.  elaboration errors. If it is important that the program be portable, then use 
  6004.  the -gnatwl switch to generate warnings about missing Elaborate_All pragmas, 
  6005.  and supply the missing pragmas. 
  6006.  
  6007.  If the program fails to bind using the default static elaboration handling, 
  6008.  then you can fix the program to eliminate the binder message, or recompile the 
  6009.  entire program with the -gnatE switch to generate dynamic elaboration checks, 
  6010.  or, if you are sure there really are no elaboration problems, use the -f 
  6011.  switch for the binder to cause it to ignore implicit Elaborate_All pragmas 
  6012.  generated by the compiler. 
  6013.  
  6014.  
  6015. ΓòÉΓòÉΓòÉ 13. The cross-referencing tools gnatxref and gnatfind ΓòÉΓòÉΓòÉ
  6016.  
  6017.  
  6018.  The compiler generates cross-referencing information (unless you set the 
  6019.  '-gnatx' switch), which are saved in the '.ali' files. This information 
  6020.  indicates where in the source each entity is declared and referenced. 
  6021.  
  6022.  Before using any of these two tools, you need to compile successfully your 
  6023.  application, so that GNAT gets a chance to generate the cross-referencing 
  6024.  information. 
  6025.  
  6026.  The two tools gnatxref and gnatfind take advantage of this information to 
  6027.  provide the user with the capability to easily locate the declaration and 
  6028.  references to an entity. These tools are quite similar, the difference being 
  6029.  that gnatfind is intended for locating definitions and/or references to a 
  6030.  specified entity or entities, whereas gnatxref is oriented to generating a 
  6031.  full report of all cross-references. 
  6032.  
  6033.  To use these tools, you must not compile your application using the '-gnatx' 
  6034.  switch on the 'gnatmake' command line (information will not be generated. 
  6035.  
  6036.  Gnatxref switches             Gnatxref switches 
  6037.  Gnatfind switches             Gnatfind switches 
  6038.  Project files                 Project files 
  6039.  Regular expressions in gnatfind and gnatxrefRegular expressions in gnatfind 
  6040.                                and gnatxref 
  6041.  Examples of gnatxref usage    Examples of gnatxref usage 
  6042.  Examples of gnatfind usage    Examples of gnatfind usage 
  6043.  
  6044.  
  6045. ΓòÉΓòÉΓòÉ 13.1. Gnatxref switches ΓòÉΓòÉΓòÉ
  6046.  
  6047.  
  6048.  The command lines for gnatxref is: 
  6049.  
  6050.                       $ gnatxref [switches] sourcefile1 [sourcefile2 ┬╖┬╖┬╖]
  6051.  
  6052.  where 
  6053.  
  6054.  sourcefile1, sourcefile2 
  6055.            identifies the source files for which a report is to be generated. 
  6056.            The 'with'ed units will be processed too. You must provide at least 
  6057.            one file. 
  6058.  
  6059.            These file names are considered to be regular expressions, so for 
  6060.            instance specifying 'source*.adb' is the same as giving every file 
  6061.            in the current directory whose name starts with 'source' and whose 
  6062.            extension is 'adb'. 
  6063.  
  6064.  The switches can be : 
  6065.  
  6066.  -a 
  6067.            If this switch is present, gnatfind and gnatxref will parse the 
  6068.            read-only files found in the library search path. Otherwise, these 
  6069.            files will be ignored. This option can be used to protect Gnat 
  6070.            sources or your own libraries from being parsed, thus making 
  6071.            gnatfind and gnatxref much faster, and their output much smaller. 
  6072.  
  6073.  -aIDIR 
  6074.            When looking for source files also look in directory DIR. The order 
  6075.            in which source file search is undertaken is the same as for 
  6076.            'gnatmake'. 
  6077.  
  6078.  -aODIR 
  6079.            When searching for library and object files, look in directory DIR. 
  6080.            The order in which library files are searched is the same as for 
  6081.            'gnatmake'. 
  6082.  
  6083.  -d 
  6084.            If this switch is set gnatxref will output the parent type reference 
  6085.            for each matching derived types. 
  6086.  
  6087.  -f 
  6088.            If this switch is set, the output file names will be preceded by 
  6089.            their directory (if the file was found in the search path). If this 
  6090.            switch is not set, the directory will not be printed. 
  6091.  
  6092.  -g 
  6093.            If this switch is set, information is output only for library-level 
  6094.            entities, ignoring local entities. The use of this switch may 
  6095.            accelerate gnatfind and gnatxref. 
  6096.  
  6097.  -IDIR 
  6098.            Equivalent to '-aODIR -aIDIR'. 
  6099.  
  6100.  -pFILE 
  6101.            Specify a project file to use See Project files. By default, 
  6102.            gnatxref and gnatfind will try to locate a project file in the 
  6103.            current directory. 
  6104.  
  6105.            If a project file is either specified or found by the tools, then 
  6106.            the content of the source directory and object directory lines are 
  6107.            added as if they had been specified respectively by '-aI' and '-aO'. 
  6108.  
  6109.  -u 
  6110.            Output only unused symbols. This may be really useful if you give 
  6111.            your main compilation unit on the command line, as gnatxref will 
  6112.            then display every unused entity and 'with'ed package. 
  6113.  
  6114.  -v 
  6115.            Instead of producing the default output, gnatxref will generate a 
  6116.            'tags' file that can be used by vi. For examples how to use this 
  6117.            feature, see See Examples of gnatxref usage. The tags file is output 
  6118.            to the standard output, thus you will have to redirect it to a file. 
  6119.  
  6120.  All these switches may be in any order on the command line, and may even 
  6121.  appear after the file names. They need not be separated by spaces, thus you 
  6122.  can say 'gnatxref -ag' instead of 'gnatxref -a -g'. 
  6123.  
  6124.  
  6125. ΓòÉΓòÉΓòÉ 13.2. Gnatfind switches ΓòÉΓòÉΓòÉ
  6126.  
  6127.  
  6128.  The command line for gnatfind is: 
  6129.  
  6130.                       $ gnatfind [switches] pattern[:sourcefile[:line[:column]]] \
  6131.                        [file1 file2 ┬╖┬╖┬╖]
  6132.  
  6133.  where 
  6134.  
  6135.  pattern 
  6136.            An entity will be output only if it matches the regular expression 
  6137.            found in 'pattern', see See Regular expressions in gnatfind and 
  6138.            gnatxref. 
  6139.  
  6140.            Omitting the pattern is equivalent to specifying '*', which will 
  6141.            match any entity. Note that if you do not provide a pattern, you 
  6142.            have to provide both a sourcefile and a line. 
  6143.  
  6144.            Entity names are given in Latin-1, with uppercase/lowercase 
  6145.            equivalence for matching purposes. At the current time there is no 
  6146.            support for 8-bit codes other than Latin-1, or for wide characters 
  6147.            in identifiers. 
  6148.  
  6149.  sourcefile 
  6150.            gnatfind will look for references, bodies or declarations of symbols 
  6151.            referenced in 'sourcefile', at line 'line' and column 'column'. See 
  6152.            see Examples of gnatfind usage for syntax examples. 
  6153.  
  6154.  line 
  6155.            is a decimal integer identifying the line number containing the 
  6156.            reference to the entity (or entities) to be located. 
  6157.  
  6158.  column 
  6159.            is a decimal integer identifying the exact location on the line of 
  6160.            the first character of the identifier for the entity reference. 
  6161.            Columns are numbered from 1. 
  6162.  
  6163.  file1 file2 ┬╖┬╖┬╖ 
  6164.            The search will be restricted to these files. If none are given, 
  6165.            then the search will be done for every library file in the search 
  6166.            path. These file must appear only after the pattern or sourcefile. 
  6167.  
  6168.            These file names are considered to be regular expressions, so for 
  6169.            instance specifying 'source*.adb' is the same as giving every file 
  6170.            in the current directory whose name starts with 'source' and whose 
  6171.            extension is 'adb'. 
  6172.  
  6173.            Not that if you specify at least one file in this part, gnatfind may 
  6174.            sometimes not be able to find the body of the subprograms┬╖┬╖┬╖ 
  6175.  
  6176.  At least one of 'sourcefile' or 'pattern' has to be present on the command 
  6177.  line. 
  6178.  
  6179.  The following switches are available: 
  6180.  
  6181.  -a 
  6182.            If this switch is present, gnatfind and gnatxref will parse the 
  6183.            read-only files found in the library search path. Otherwise, these 
  6184.            files will be ignored. This option can be used to protect Gnat 
  6185.            sources or your own libraries from being parsed, thus making 
  6186.            gnatfind and gnatxref much faster, and their output much smaller. 
  6187.  
  6188.  -aIDIR 
  6189.            When looking for source files also look in directory DIR. The order 
  6190.            in which source file search is undertaken is the same as for 
  6191.            'gnatmake'. 
  6192.  
  6193.  -aODIR 
  6194.            When searching for library and object files, look in directory DIR. 
  6195.            The order in which library files are searched is the same as for 
  6196.            'gnatmake'. 
  6197.  
  6198.  -d 
  6199.            If this switch is set, then gnatfind will output the parent type 
  6200.            reference for each matching derived types. 
  6201.  
  6202.  -e 
  6203.            By default, gnatfind accept the simple regular expression set for 
  6204.            'pattern'. If this switch is set, then the pattern will be 
  6205.            considered as full Unix-style regular expression. 
  6206.  
  6207.  -f 
  6208.            If this switch is set, the output file names will be preceded by 
  6209.            their directory (if the file was found in the search path). If this 
  6210.            switch is not set, the directory will not be printed. 
  6211.  
  6212.  -g 
  6213.            If this switch is set, information is output only for library-level 
  6214.            entities, ignoring local entities. The use of this switch may 
  6215.            accelerate gnatfind and gnatxref. 
  6216.  
  6217.  -IDIR 
  6218.            Equivalent to '-aODIR -aIDIR'. 
  6219.  
  6220.  -pFILE 
  6221.            Specify a project file (see Project files) to use. By default, 
  6222.            gnatxref and gnatfind will try to locate a project file in the 
  6223.            current directory. 
  6224.  
  6225.            If a project file is either specified or found by the tools, then 
  6226.            the content of the source directory and object directory lines are 
  6227.            added as if they had been specified respectively by '-aI' and '-aO'. 
  6228.  
  6229.  -r 
  6230.            By default, gnatfind will output only the information about the 
  6231.            declaration, body or type completion of the entities. If this switch 
  6232.            is set, the gnatfind will locate every reference to the entities in 
  6233.            the files specified on the command line (or in every file in the 
  6234.            search path if no file is given on the command line). 
  6235.  
  6236.  -s 
  6237.            If this switch is set, then gnatfind will output the content of the 
  6238.            Ada source file lines were the entity was found. 
  6239.  
  6240.  -t 
  6241.            If this switch is set, then gnatfind will output the type hierarchy 
  6242.            for the specified type. It act like -d option but recursively from 
  6243.            parent type to parent type. When this switch is set it is not 
  6244.            possible to specify more than one file. 
  6245.  
  6246.  All these switches may be in any order on the command line, and may even 
  6247.  appear after the file names. They need not be separated by spaces, thus you 
  6248.  can say 'gnatxref -ag' instead of 'gnatxref -a -g'. 
  6249.  
  6250.  As stated previously, gnatfind will search in every directory in the search 
  6251.  path. You can force it to look only in the current directory if you specify * 
  6252.  at the end of the command line. 
  6253.  
  6254.  
  6255. ΓòÉΓòÉΓòÉ 13.3. Project files ΓòÉΓòÉΓòÉ
  6256.  
  6257.  
  6258.  The project files allows a programmer to specify how to compile its 
  6259.  application, where to find sources,┬╖┬╖┬╖ These files are used primarily by the 
  6260.  Emacs Ada mode, but they can also be used by the two tools gnatxref and 
  6261.  gnatfind. 
  6262.  
  6263.  A project file name must end with '.adp'. If a single one is present in the 
  6264.  current directory, then gnatxref and gnatfind will extract the information 
  6265.  from it. If multiple project files are found, none of them is read, and you 
  6266.  have to use the '-p' switch to specify the one you want to use. 
  6267.  
  6268.  The following lines can be included, even though most of them have default 
  6269.  values which can be used in most cases. The lines can be entered in any order 
  6270.  in the file. Except for 'src_dir' and 'obj_dir', you can only have one 
  6271.  instance of each line. If you have multiple instances, only the last one is 
  6272.  taken into account. 
  6273.  
  6274.  'src_dir=DIR     [default: "./"]' 
  6275.            specifies a directory where to look for source files. Multiple 
  6276.            src_dir lines can be specified and they will be searched in the 
  6277.            order they are specified. 
  6278.  
  6279.  'obj_dir=DIR     [default: "./"]' 
  6280.            specifies a directory where to look for object and library files. 
  6281.            Multiple obj_dir lines can be specified and they will be searched in 
  6282.            the order they are specified 
  6283.  
  6284.  'comp_opt=SWITCHES  [default: ""]' 
  6285.            creates a variable which can be referred to subsequently by using 
  6286.            the '${comp_opt}' notation. This is intended to store the default 
  6287.            switches given to 'gnatmake' and 'gcc'. 
  6288.  
  6289.  'bind_opt=SWITCHES  [default: ""]' 
  6290.            creates a variable which can be referred to subsequently by using 
  6291.            the '${bind_opt}' notation. This is intended to store the default 
  6292.            switches given to 'gnatbind'. 
  6293.  
  6294.  'link_opt=SWITCHES  [default: ""]' 
  6295.            creates a variable which can be referred to subsequently by using 
  6296.            the '${link_opt}' notation. This is intended to store the default 
  6297.            switches given to 'gnatlink'. 
  6298.  
  6299.  'main=EXECUTABLE   [default: ""]' 
  6300.            specifies the name of the executable for the application. This 
  6301.            variable can be referred to in the following lines by using the 
  6302.            '${main}' notation. 
  6303.  
  6304.  'comp_cmd=COMMAND   [default: "gcc -c -I${src_dir} -g -gnatq"]' 
  6305.            specifies the command used to compile a single file in the 
  6306.            application. 
  6307.  
  6308.  'make_cmd=COMMAND   [default: "gnatmake ${main} -aI${src_dir} -aO${obj_dir} -g 
  6309.  -gnatq -cargs ${comp_opt} -bargs ${bind_opt} -largs ${link_opt}"]' 
  6310.            specifies the command used to recompile the whole application. 
  6311.  
  6312.  'run_cmd=COMMAND   [default: "${main}"]' 
  6313.            specifies the command used to run the application. 
  6314.  
  6315.  'debug_cmd=COMMAND  [default: "gdb ${main}"]' 
  6316.            specifies the command used to debug the application 
  6317.  
  6318.  gnatxref and gnatfind only take into account the 'src_dir' and 'obj_dir' 
  6319.  lines, and ignore the others. 
  6320.  
  6321.  
  6322. ΓòÉΓòÉΓòÉ 13.4. Regular expressions in gnatfind and gnatxref ΓòÉΓòÉΓòÉ
  6323.  
  6324.  
  6325.  As specified in the section about gnatfind, the pattern can be a regular 
  6326.  expression. Actually, there are to set of regular expressions which are 
  6327.  recognized by the program : 
  6328.  
  6329.  'globbing patterns' 
  6330.            These are the most usual regular expression. They are the same that 
  6331.            you generally used in a Unix shell command line, or in a DOS 
  6332.            session. 
  6333.  
  6334.            Here is a more formal grammar : 
  6335.  
  6336.                       regexp ::= term
  6337.                       term  ::= elmt       -- matches elmt
  6338.                       term  ::= elmt elmt    -- concatenation (elmt then elmt)
  6339.                       term  ::= *        -- any string of 0 or more characters
  6340.                       term  ::= ?        -- matches any character
  6341.                       term  ::= [char {char}] -- matches any character listed
  6342.                       term  ::= [char - char]  -- matches any character in range
  6343.  
  6344.  'full regular expression' 
  6345.            The second set of regular expressions is much more powerful. This is 
  6346.            the type of regular expressions recognized by utilities such a 
  6347.            'grep'. 
  6348.  
  6349.            The following is the form of a regular expression, expressed in Ada 
  6350.            reference manual style BNF is as follows 
  6351.  
  6352.                       regexp ::= term {| term} -- alternation (term or term ┬╖┬╖┬╖)
  6353.                       term ::= item {item}   -- concatenation (item then item)
  6354.                       item ::= elmt        -- match elmt
  6355.                       item ::= elmt *       -- zero or more elmt's
  6356.                       item ::= elmt +       -- one or more elmt's
  6357.                       item ::= elmt ?       -- matches elmt or nothing
  6358.                       elmt ::= nschar       -- matches given character
  6359.                       elmt ::= [nschar {nschar}]  -- matches any character listed
  6360.                       elmt ::= [^ nschar {nschar}] -- matches any character not listed
  6361.                       elmt ::= [char - char]   -- matches chars in given range
  6362.                       elmt ::= \ char       -- matches given character
  6363.                       elmt ::= .         -- matches any single character
  6364.                       elmt ::= ( regexp )     -- parens used for grouping
  6365.                       char ::= any character, including special characters
  6366.                       nschar ::= any character except ()[].*+?^
  6367.  
  6368.  Following are a few examples : 
  6369.  
  6370.              'abcde|fghi' 
  6371.                          will match any of the two strings 'abcde' and 'fghi'. 
  6372.  
  6373.              'abc*d' 
  6374.                          will match any string like 'abd', 'abcd', 'abccd', 
  6375.                          'abcccd', and so on 
  6376.  
  6377.              '[a-z]+' 
  6378.                          will match any string which has only lowercase 
  6379.                          characters in it (and at least one character 
  6380.  
  6381.  
  6382. ΓòÉΓòÉΓòÉ 13.5. Examples of gnatxref usage ΓòÉΓòÉΓòÉ
  6383.  
  6384.  
  6385. ΓòÉΓòÉΓòÉ 13.5.1. General usage ΓòÉΓòÉΓòÉ
  6386.  
  6387.  
  6388.  For the following examples, we will consider the following units : 
  6389.  
  6390.                       main.ads:
  6391.                       1: with Bar;
  6392.                       2: package Main is
  6393.                       3:   procedure Foo (B : in Integer);
  6394.                       4:   C : Integer;
  6395.                       5: private
  6396.                       6:   D : Integer;
  6397.                       7: end Main;
  6398.                       main.adb:
  6399.                       1: package body Main is
  6400.                       2:   procedure Foo (B : in Integer) is
  6401.                       3:   begin
  6402.                       4:     C := B;
  6403.                       5:     D := B;
  6404.                       6:     Bar.Print (B);
  6405.                       7:     Bar.Print (C);
  6406.                       8:   end Foo;
  6407.                       9: end Main;
  6408.                       bar.ads:
  6409.                       1: package Bar is
  6410.                       2:   procedure Print (B : Integer);
  6411.                       3: end bar;
  6412.  
  6413.  The first thing to do is to recompile your application (for instance, in that 
  6414.  case just by doing a 'gnatmake main', so that GNAT generates the 
  6415.  cross-referencing information. You can then issue any of the following 
  6416.  commands: 
  6417.  
  6418.  gnatxref main.adb 
  6419.            gnatxref generates cross-reference information for main.adb and 
  6420.            every unit 'with'ed by main.adb. 
  6421.  
  6422.            The output would be: 
  6423.  
  6424.                       B                            Type: Integer
  6425.                        Decl: bar.ads      2:22
  6426.                       B                            Type: Integer
  6427.                        Decl: main.ads      3:20
  6428.                        Body: main.adb      2:20
  6429.                        Ref:  main.adb      4:13   5:13   6:19
  6430.                       Bar                           Type: Unit
  6431.                        Decl: bar.ads      1:9
  6432.                        Ref:  main.adb      6:8    7:8
  6433.                           main.ads      1:6
  6434.                       C                            Type: Integer
  6435.                        Decl: main.ads      4:5
  6436.                        Modi: main.adb      4:8
  6437.                        Ref:  main.adb      7:19
  6438.                       D                            Type: Integer
  6439.                        Decl: main.ads      6:5
  6440.                        Modi: main.adb      5:8
  6441.                       Foo                           Type: Unit
  6442.                        Decl: main.ads      3:15
  6443.                        Body: main.adb      2:15
  6444.                       Main                           Type: Unit
  6445.                        Decl: main.ads      2:9
  6446.                        Body: main.adb      1:14
  6447.                       Print                          Type: Unit
  6448.                        Decl: bar.ads      2:15
  6449.                        Ref:  main.adb      6:12   7:12
  6450.  
  6451.  that is the entity Main is declared in main.ads, line 2, column 9, its body is 
  6452.  in main.adb, line 1, column 14 and is not referenced any where. 
  6453.  
  6454.  The entity Print is declared in bar.ads, line 2, column 15 and it it 
  6455.  referenced in main.adb, line 6 column 12 and line 7 column 12. 
  6456.  
  6457.  gnatxref package1.adb package2.ads 
  6458.            gnatxref will generates cross-reference information for 
  6459.            package1.adb, package2.ads and any other package 'with'ed by any of 
  6460.            these. 
  6461.  
  6462.  
  6463. ΓòÉΓòÉΓòÉ 13.5.2. Using gnatxref with vi ΓòÉΓòÉΓòÉ
  6464.  
  6465.  gnatxref can generate a tags file output, which can be used directly from 
  6466.  'vi'. Note that the standard version of 'vi' will not work properly with 
  6467.  overloaded symbols. Consider using another free implementation of 'vi', such 
  6468.  as 'vim'. 
  6469.  
  6470.                       $ gnatxref -v gnatfind.adb > tags
  6471.  
  6472.  will generate the tags file for gnatfind itself (if the sources are in the 
  6473.  search path!). 
  6474.  
  6475.  From 'vi', you can then use the command ':tag entity' (replacing entity by 
  6476.  whatever you are looking for), and vi will display a new file with the 
  6477.  corresponding declaration of entity. 
  6478.  
  6479.  
  6480. ΓòÉΓòÉΓòÉ 13.6. Examples of gnatfind usage ΓòÉΓòÉΓòÉ
  6481.  
  6482.  gnatfind -f xyz:main.adb 
  6483.            Find declarations for all entities xyz referenced at least once in 
  6484.            main.adb. The references are search in every library file in the 
  6485.            search path. 
  6486.  
  6487.            The directories will be printed as well (as the '-f' switch is set) 
  6488.  
  6489.            The output will look like: 
  6490.  
  6491.                       directory/main.ads:106:14: xyz <= declaration
  6492.                       directory/main.adb:24:10: xyz <= body
  6493.                       directory/foo.ads:45:23: xyz <= declaration
  6494.  
  6495.  that is to say, one of the entities xyz found in main.adb is declared at line 
  6496.  12 of main.ads (and its body is in main.adb), and another one is declared at 
  6497.  line 45 of foo.ads 
  6498.  
  6499.  gnatfind -fs xyz:main.adb 
  6500.            This is the same command as the previous one, instead gnatfind will 
  6501.            display the content of the Ada source file lines. 
  6502.  
  6503.            The output will look like: 
  6504.  
  6505.                       directory/main.ads:106:14: xyz <= declaration
  6506.                         procedure xyz;
  6507.                       directory/main.adb:24:10: xyz <= body
  6508.                         procedure xyz is
  6509.                       directory/foo.ads:45:23: xyz <= declaration
  6510.                         xyz : Integer;
  6511.  
  6512.  This can make it easier to find exactly the location your are looking for. 
  6513.  
  6514.  gnatfind -r "*x*":main.ads:123 foo.adb 
  6515.            Find references to all entities containing an x that are referenced 
  6516.            on line 123 of main.ads. The references will be searched only in 
  6517.            main.adb and foo.adb. 
  6518.  
  6519.  gnatfind main.ads:123 
  6520.            Find declarations and bodies for all entities that are referenced on 
  6521.            line 123 of main.ads. 
  6522.  
  6523.            This is the same as gnatfind "*":main.adb:123. 
  6524.  
  6525.  gnatfind mydir/main.adb:123:45 
  6526.            Find the declaration for the entity referenced at column 45 in line 
  6527.            123 of file main.adb in directory mydir. Note that it is usual to 
  6528.            omit the identifier name when the column is given, since the column 
  6529.            position identifies a unique reference. 
  6530.  
  6531.            The column has to be the beginning of the identifier, and should not 
  6532.            point to any character in the middle of the identifier. 
  6533.  
  6534.  
  6535. ΓòÉΓòÉΓòÉ 14. File Name Krunching Using gnatkr ΓòÉΓòÉΓòÉ
  6536.  
  6537.  
  6538.  This chapter discusses the method used by the compiler to shorten the default 
  6539.  file names chosen for Ada units so that they do not exceed the maximum length 
  6540.  permitted. It also describes the gnatkr utility that can be used to determine 
  6541.  the result of applying this shortening. 
  6542.  
  6543.  About gnatkr                  About gnatkr 
  6544.  Using gnatkr                  Using gnatkr 
  6545.  Krunching Method              Krunching Method 
  6546.  Examples of gnatkr Usage      Examples of gnatkr Usage 
  6547.  
  6548.  
  6549. ΓòÉΓòÉΓòÉ 14.1. About gnatkr ΓòÉΓòÉΓòÉ
  6550.  
  6551.  
  6552.  The default file naming rule in GNAT is that the file name must be derived 
  6553.  from the unit name. The exact default rule is as follows: 
  6554.  
  6555.      Take the unit name and replace all dots by hyphens. 
  6556.  
  6557.      If such a replacement occurs in the second character position of a name, 
  6558.       and the first character is a, g, s, or i then replace the dot by the 
  6559.       character ~ (tilde) instead of a minus. 
  6560.  The reason for this exception is to avoid clashes with the standard names for 
  6561.  children of System, Ada, Interfaces, and GNAT, which use the prefixes s- a- i- 
  6562.  and g- respectively. 
  6563.  
  6564.  The -gnatknn switch of the compiler activates a "krunching" circuit that 
  6565.  limits file names to nn characters (where nn is a decimal integer). For 
  6566.  example, using OpenVMS, where the maximum file name length is 39, the value of 
  6567.  nn is usually set to 39, but if you want to generate a set of files that would 
  6568.  be usable if ported to a system with some different maximum file length, then 
  6569.  a different value can be specified. The default value of 39 for OpenVMS need 
  6570.  not be specified. 
  6571.  
  6572.  The gnatkr utility can be used to determine the krunched name for a given 
  6573.  file, when krunched to a specified maximum length. 
  6574.  
  6575.  
  6576. ΓòÉΓòÉΓòÉ 14.2. Using gnatkr ΓòÉΓòÉΓòÉ
  6577.  
  6578.  
  6579.  The gnatkr command has the form 
  6580.  
  6581.                       $ gnatkr name [length]
  6582.  
  6583.  name can be an Ada name with dots or the GNAT name of the unit, where the dots 
  6584.  representing child units or subunit are replaced by hyphens. The only 
  6585.  confusion arises if a name ends in .ads or .adb. gnatkr takes this to be an 
  6586.  extension if there are no other dots in the name and the whole name is in 
  6587.  lowercase. 
  6588.  
  6589.  length represents the length of the krunched name. The default when no 
  6590.  argument is given is 8 characters. A length of zero stands for unlimited, in 
  6591.  other words do not chop except for system files which are always 8. 
  6592.  The output is the krunched name. The output has an extension only if the 
  6593.  original argument was a file name with an extension. 
  6594.  
  6595.  
  6596. ΓòÉΓòÉΓòÉ 14.3. Krunching Method ΓòÉΓòÉΓòÉ
  6597.  
  6598.  
  6599.  The initial file name is determined by the name of the unit that the file 
  6600.  contains. The name is formed by taking the full expanded name of the unit and 
  6601.  replacing the separating dots with hyphens and using lowercase for all 
  6602.  letters, except that a hyphen in the second character position is replaced by 
  6603.  a tilde if the first character is a, i, g, or s. The extension is .ads for a 
  6604.  specification and .adb for a body. Krunching does not affect the extension, 
  6605.  but the file name is shortened to the specified length by following these 
  6606.  rules: 
  6607.  
  6608.      The name is divided into segments separated by hyphens, tildes or 
  6609.       underscores and all hyphens, tildes, and underscores are eliminated. If 
  6610.       this leaves the name short enough, we are done. 
  6611.  
  6612.      If the name is too long, the longest segment is located (left-most if 
  6613.       there are two of equal length), and shortened by dropping its last 
  6614.       character. This is repeated until the name is short enough. 
  6615.  
  6616.       As an example, consider the krunching of 
  6617.       'our-strings-wide_fixed.adb' to fit the name into 8 characters as 
  6618.       required by some operating systems. 
  6619.  
  6620.                       our-strings-wide_fixed 22
  6621.                       our strings wide fixed 19
  6622.                       our string  wide fixed 18
  6623.                       our strin  wide fixed 17
  6624.                       our stri   wide fixed 16
  6625.                       our stri   wide fixe  15
  6626.                       our str   wide fixe  14
  6627.                       our str   wid  fixe  13
  6628.                       our str   wid  fix  12
  6629.                       ou  str   wid  fix  11
  6630.                       ou  st    wid  fix  10
  6631.                       ou  st    wi  fix  9
  6632.                       ou  st    wi  fi   8
  6633.                       Final file name: oustwifi.adb
  6634.  
  6635.      The file names for all predefined units are always krunched to eight 
  6636.       characters. The krunching of these predefined units uses the following 
  6637.       special prefix replacements: 
  6638.  
  6639.       ada- 
  6640.                      replaced by 'a-' 
  6641.  
  6642.       gnat- 
  6643.                      replaced by 'g-' 
  6644.  
  6645.       interfaces- 
  6646.                      replaced by 'i-' 
  6647.  
  6648.       system- 
  6649.                      replaced by 's-' 
  6650.  
  6651.       These system files have a hyphen in the second character position. That 
  6652.       is why normal user files replace such a character with a tilde, to avoid 
  6653.       confusion with system file names. 
  6654.  
  6655.       As an example of this special rule, consider 
  6656.       'ada-strings-wide_fixed.adb', which gets krunched as follows: 
  6657.  
  6658.                                 ada-strings-wide_fixed 22
  6659.                                 a-  strings wide fixed 18
  6660.                                 a-  string  wide fixed 17
  6661.                                 a-  strin  wide fixed 16
  6662.                                 a-  stri   wide fixed 15
  6663.                                 a-  stri   wide fixe  14
  6664.                                 a-  str   wide fixe  13
  6665.                                 a-  str   wid  fixe  12
  6666.                                 a-  str   wid  fix  11
  6667.                                 a-  st    wid  fix  10
  6668.                                 a-  st    wi  fix  9
  6669.                                 a-  st    wi  fi   8
  6670.                                 Final file name: a-stwifi.adb
  6671.  
  6672.  Of course no file shortening algorithm can guarantee uniqueness over all 
  6673.  possible unit names, and if file name krunching is used then it is your 
  6674.  responsibility to ensure that no name clashes occur. The utility program 
  6675.  gnatkr is supplied for conveniently determining the krunched name of a file. 
  6676.  
  6677.  
  6678. ΓòÉΓòÉΓòÉ 14.4. Examples of gnatkr Usage ΓòÉΓòÉΓòÉ
  6679.  
  6680.                       $ gnatkr very_long_unit_name.ads    --> velounna.ads
  6681.                       $ gnatkr grandparent-parent-child.ads --> grparchi.ads
  6682.                       $ gnatkr Grandparent.Parent.Child   --> grparchi
  6683.                       $ gnatkr very_long_unit_name.ads/count=6 --> vlunna.ads
  6684.                       $ gnatkr very_long_unit_name.ads/count=0 --> very_long_unit_name.ads
  6685.  
  6686.  
  6687. ΓòÉΓòÉΓòÉ 15. Preprocessing Using gnatprep ΓòÉΓòÉΓòÉ
  6688.  
  6689.  
  6690.  The gnatprep utility provides a simple preprocessing capability for Ada 
  6691.  programs. It is designed for use with GNAT, but is not dependent on any 
  6692.  special features of GNAT. 
  6693.  
  6694.  Using gnatprep                Using gnatprep 
  6695.  Switches for gnatprep         Switches for gnatprep 
  6696.  Form of definitions file      Form of definitions file 
  6697.  Form of input text for gnatprepForm of input text for gnatprep 
  6698.  
  6699.  
  6700. ΓòÉΓòÉΓòÉ 15.1. Using gnatprep ΓòÉΓòÉΓòÉ
  6701.  
  6702.  
  6703.  To call gnatprep use 
  6704.  
  6705.                       $ gnatprep [-bcrsu] [-Dsymbol=value] infile outfile [deffile]
  6706.  
  6707.  where 
  6708.  
  6709.  infile 
  6710.            is the full name of the input file, which is an Ada source file 
  6711.            containing preprocessor directives. 
  6712.  
  6713.  outfile 
  6714.            is the full name of the output file, which is an Ada source in 
  6715.            standard Ada form. When used with GNAT, this file name will normally 
  6716.            have an ads or adb suffix. 
  6717.  
  6718.  deffile 
  6719.            is the full name of a text file containing definitions of symbols to 
  6720.            be referenced by the preprocessor. This argument is optional, and 
  6721.            can be replaced by the use of the -D switch. 
  6722.  
  6723.  switches 
  6724.            is an optional sequence of switches as described in the next 
  6725.            section. 
  6726.  
  6727.  
  6728. ΓòÉΓòÉΓòÉ 15.2. Switches for gnatprep ΓòÉΓòÉΓòÉ
  6729.  
  6730.  -b 
  6731.            Causes both preprocessor lines and the lines deleted by 
  6732.            preprocessing to be replaced by blank lines in the output source 
  6733.            file, preserving line numbers in the output file. 
  6734.  
  6735.  -c 
  6736.            Causes both preprocessor lines and the lines deleted by 
  6737.            preprocessing to be retained in the output source as comments marked 
  6738.            with the special string "--! ". This option will result in line 
  6739.            numbers being preserved in the output file. 
  6740.  
  6741.  -Dsymbol=value 
  6742.            Defines a new symbol, associated with value. If no value is given on 
  6743.            the command line, then symbol is considered to be True. This switch 
  6744.            can be used in place of a definition file. 
  6745.  
  6746.  -r 
  6747.            Causes a Source_Reference pragma to be generated that references the 
  6748.            original input file, so that error messages will use the file name 
  6749.            of this original file. The use of this switch implies that 
  6750.            preprocessor lines are not to be removed from the file, so its use 
  6751.            will force -b mode if -c has not been specified explicitly. 
  6752.  
  6753.            Note that if the file to be preprocessed contains multiple units, 
  6754.            then it will be necessary to gnatchop the output file from gnatprep. 
  6755.            If a Source_Reference pragma is present in the preprocessed file, it 
  6756.            will be respected by gnatchop -r so that the final chopped files 
  6757.            will correctly refer to the original input source file for gnatprep. 
  6758.  
  6759.  -s 
  6760.            Causes a sorted list of symbol names and values to be listed on the 
  6761.            standard output file. 
  6762.  
  6763.  -u 
  6764.            Causes undefined symbols to be treated as having the value FALSE in 
  6765.            the context of a preprocessor test. In the absence of this option, 
  6766.            an undefined symbol in a #if or #elsif test will be treated as an 
  6767.            error. 
  6768.  
  6769.  Note: if neither -b nor -c is present, then preprocessor lines and deleted 
  6770.  lines are completely removed from the output, unless -r is specified, in which 
  6771.  case -b is assumed. 
  6772.  
  6773.  
  6774. ΓòÉΓòÉΓòÉ 15.3. Form of definitions file ΓòÉΓòÉΓòÉ
  6775.  
  6776.  
  6777.  The definitions file contains lines of the form 
  6778.  
  6779.                       symbol := value
  6780.  
  6781.  where symbol is an identifier, following normal Ada (case-insensitive) rules 
  6782.  for its syntax, and value is one of the following: 
  6783.  
  6784.      Empty, corresponding to a null substitution 
  6785.  
  6786.      A string literal using normal Ada syntax 
  6787.  
  6788.      Any sequence of characters from the set (letters, digits, period, 
  6789.       underline). 
  6790.  
  6791.  Comment lines may also appear in the definitions file, starting with the usual 
  6792.  --, and comments may be added to the definitions lines. 
  6793.  
  6794.  
  6795. ΓòÉΓòÉΓòÉ 15.4. Form of input text for gnatprep ΓòÉΓòÉΓòÉ
  6796.  
  6797.  
  6798.  The input text may contain preprocessor conditional inclusion lines, as well 
  6799.  as general symbol substitution sequences. The preprocessor conditional 
  6800.  inclusion commands have the form 
  6801.  
  6802.                       #if expression [then]
  6803.                         lines
  6804.                       #elsif expression [then]
  6805.                         lines
  6806.                       #elsif expression [then]
  6807.                         lines
  6808.                       ┬╖┬╖┬╖
  6809.                       #else
  6810.                         lines
  6811.                       #end if;
  6812.  
  6813.  In this example, expression is defined by the following grammar: 
  6814.  
  6815.                       expression ::=  <symbol>
  6816.                       expression ::=  <symbol> = "<value>"
  6817.                       expression ::=  <symbol> = <symbol>
  6818.                       expression ::=  <symbol> 'Defined
  6819.                       expression ::=  not expression
  6820.                       expression ::=  expression and expression
  6821.                       expression ::=  expression or expression
  6822.                       expression ::=  expression and then expression
  6823.                       expression ::=  expression or else expression
  6824.                       expression ::=  ( expression )
  6825.  
  6826.  For the first test (expression ::= <symbol>) the symbol must have either the 
  6827.  value true or false, that is to say the right-hand of the symbol definition 
  6828.  must be one of the (case-insensitive) literals True or False. If the value is 
  6829.  true, then the corresponding lines are included, and if the value is false, 
  6830.  they are excluded. 
  6831.  
  6832.  The test (expression ::= <symbol> 'Defined) is true only if the symbol has 
  6833.  been defined in the definition file or by a -D switch on the command line. 
  6834.  Otherwise, the test is false. 
  6835.  
  6836.  The equality tests are case insensitive, as are all the preprocessor lines. 
  6837.  
  6838.  If the symbol referenced is not defined in the symbol definitions file, then 
  6839.  the effect depends on whether or not switch -u is specified. If so, then the 
  6840.  symbol is treated as if it had the value false and the test fails. If this 
  6841.  switch is not specified, then it is an error to reference an undefined symbol. 
  6842.  It is also an error to reference a symbol that is defined with a value other 
  6843.  than True or False. 
  6844.  
  6845.  The use of the not operator inverts the sense of this logical test, so that 
  6846.  the lines are included only if the symbol is not defined. The then keyword is 
  6847.  optional as shown 
  6848.  
  6849.  The # must be the first non-blank character on a line, but otherwise the 
  6850.  format is free form. Spaces or tabs may appear between the # and the keyword. 
  6851.  The keywords and the symbols are case insensitive as in normal Ada code. 
  6852.  Comments may be used on a preprocessor line, but other than that, no other 
  6853.  tokens may appear on a preprocessor line. Any number of elsif clauses can be 
  6854.  present, including none at all. The else is optional, as in Ada. 
  6855.  
  6856.  The # marking the start of a preprocessor line must be the first non-blank 
  6857.  character on the line, i.e. it must be preceded only by spaces or horizontal 
  6858.  tabs. 
  6859.  
  6860.  Symbol substitution outside of preprocessor lines is obtained by using the 
  6861.  sequence 
  6862.  
  6863.                       $symbol
  6864.  
  6865.  anywhere within a source line, except in a comment. The identifier following 
  6866.  the $ must match one of the symbols defined in the symbol definition file, and 
  6867.  the result is to substitute the value of the symbol in place of $symbol in the 
  6868.  output file. 
  6869.  
  6870.  
  6871. ΓòÉΓòÉΓòÉ 16. The GNAT library browser gnatls ΓòÉΓòÉΓòÉ
  6872.  
  6873.  
  6874.  gnatls is a tool that outputs information about compiled units. It gives the 
  6875.  relationship between objects, unit names and source files. It can also be used 
  6876.  to check the source dependencies of a unit as well as various characteristics. 
  6877.  
  6878.  Running gnatls                Running gnatls 
  6879.  Switches for gnatls           Switches for gnatls 
  6880.  Examples of gnatls Usage      Examples of gnatls Usage 
  6881.  
  6882.  
  6883. ΓòÉΓòÉΓòÉ 16.1. Running gnatls ΓòÉΓòÉΓòÉ
  6884.  
  6885.  
  6886.  The gnatls command has the form 
  6887.  
  6888.                       $ gnatls switches object_or_ali_file
  6889.  
  6890.  The main argument is the list of object or 'ali' files (see The Ada Library 
  6891.  Information Files) for which information is requested. 
  6892.  
  6893.  In normal mode, without additional option, gnatls produces a four-column 
  6894.  listing. Each line represents information for a specific object. The first 
  6895.  column gives the full path of the object, the second column gives the name of 
  6896.  the principal unit in this object, the third column gives the status of the 
  6897.  source and the fourth column gives the full path of the source representing 
  6898.  this unit. Here is a simple example of use: 
  6899.  
  6900.                       $ gnatls *.o
  6901.                       ┬╖/demo1.o       demo1       DIF demo1.adb
  6902.                       ┬╖/demo2.o       demo2       OK demo2.adb
  6903.                       ┬╖/hello.o       h1         OK hello.adb
  6904.                       ┬╖/instr-child.o    instr.child    MOK instr-child.adb
  6905.                       ┬╖/instr.o       instr       OK instr.adb
  6906.                       ┬╖/tef.o        tef        DIF tef.adb
  6907.                       ┬╖/text_io_example.o  text_io_example  OK text_io_example.adb
  6908.                       ┬╖/tgef.o       tgef       DIF tgef.adb
  6909.  
  6910.  The first line can be interpreted as follows: the main unit which is contained 
  6911.  in object file 'demo1.o' is demo1, whose main source is in 'demo1.adb'. 
  6912.  Furthermore, the version of the source used for the compilation of demo1 has 
  6913.  been modified (DIF). Each source file has a status qualifier which can be: 
  6914.  
  6915.  OK (unchanged) 
  6916.            The version of the source file used for the compilation of the 
  6917.            specified unit corresponds exactly to the actual source file. 
  6918.  
  6919.  MOK (slightly modified) 
  6920.            The version of the source file used for the compilation of the 
  6921.            specified unit differs from the actual source file but not enough to 
  6922.            require recompilation. If you use gnatmake with the qualifier -m 
  6923.            (minimal recompilation), a file marked MOK will not be recompiled. 
  6924.  
  6925.  DIF (modified) 
  6926.            No version of the source found on the path corresponds to the source 
  6927.            used to build this object. 
  6928.  
  6929.  ??? (file not found) 
  6930.            No source file was found for this unit. 
  6931.  
  6932.  HID (hidden,  unchanged version not first on PATH) 
  6933.            The version of the source that corresponds exactly to the source 
  6934.            used for compilation has been found on the path but it is hidden by 
  6935.            another version of the same source that has been modified. 
  6936.  
  6937.  
  6938. ΓòÉΓòÉΓòÉ 16.2. Switches for gnatls ΓòÉΓòÉΓòÉ
  6939.  
  6940.  
  6941.  gnatls recognizes the following switches: 
  6942.  
  6943.  -a 
  6944.            Consider all units, including those of the predefined Ada library. 
  6945.            Especially useful with -d. 
  6946.  
  6947.  -d 
  6948.            List sources from which specified units depend on. 
  6949.  
  6950.  -h 
  6951.            Output the list of options. 
  6952.  
  6953.  -o 
  6954.            Only output information about object files. 
  6955.  
  6956.  -s 
  6957.            Only output information about source files. 
  6958.  
  6959.  -u 
  6960.            Only output information about compilation units. 
  6961.  
  6962.  -aOdir 
  6963.  
  6964.  -aIdir 
  6965.  
  6966.  -Idir 
  6967.  
  6968.  -I- 
  6969.  
  6970.  -nostdinc 
  6971.            Source and Object path manipulation. Same meaning as the equivalent 
  6972.            $ gnatmake flags Switches for gnatmake 
  6973.  
  6974.  -v 
  6975.            Verbose mode. Output the complete source and object paths. Do not 
  6976.            use the default column layout but instead use long format giving as 
  6977.            much as information possible on each requested units, including 
  6978.            special characteristics such as: 
  6979.  
  6980.              Preelaborable 
  6981.                          The unit is preelaborable in the Ada 95 sense. 
  6982.  
  6983.              No_Elab_Code 
  6984.                          No elaboration code has been produced by the compiler 
  6985.                          for this unit. 
  6986.  
  6987.              Pure 
  6988.                          The unit is pure in the Ada 95 sense. 
  6989.  
  6990.              Elaborate_Body 
  6991.                          The unit contains a pragma Elaborate_Body. 
  6992.  
  6993.              Remote_Types 
  6994.                          The unit contains a pragma Remote_Types. 
  6995.  
  6996.              Shared_Passive 
  6997.                          The unit contains a pragma Shared_Passive. 
  6998.  
  6999.              Predefined 
  7000.                          This unit is part of the predefined environment and 
  7001.                          cannot be modified by the user. 
  7002.  
  7003.              Remote_Call_Interface 
  7004.                          The unit contains a pragma Remote_Call_Interface. 
  7005.  
  7006.  
  7007. ΓòÉΓòÉΓòÉ 16.3. Example of gnatls Usage ΓòÉΓòÉΓòÉ
  7008.  
  7009.  
  7010.  Example of using the verbose switch. Note how the source and object paths are 
  7011.  affected by the -I switch. 
  7012.  
  7013.                       $ gnatls -v -I┬╖┬╖ demo1.o
  7014.                       GNATLS 3.10w (970212) Copyright 1999 Free Software Foundation, Inc.
  7015.                       Source Search Path:
  7016.                         <Current_Directory>
  7017.                         ┬╖┬╖/
  7018.                         /home/comar/local/adainclude/
  7019.                       Object Search Path:
  7020.                         <Current_Directory>
  7021.                         ┬╖┬╖/
  7022.                         /home/comar/local/lib/gcc-lib/mips-sni-sysv4/2.7.2/adalib/
  7023.                       ┬╖/demo1.o
  7024.                         Unit =>
  7025.                          Name  => demo1
  7026.                          Kind  => subprogram body
  7027.                          Flags  => No_Elab_Code
  7028.                          Source => demo1.adb   modified
  7029.  
  7030.  The following is an example of use of the dependency list. Note the use of the 
  7031.  -s switch which gives a straight list of source files. This can be useful for 
  7032.  building specialized scripts. 
  7033.  
  7034.                       $ gnatls -d demo2.o
  7035.                       ┬╖/demo2.o  demo2     OK demo2.adb
  7036.                                    OK gen_list.ads
  7037.                                    OK gen_list.adb
  7038.                                    OK instr.ads
  7039.                                    OK instr-child.ads
  7040.                       $ gnatls -d -s -a demo1.o
  7041.                       demo1.adb
  7042.                       /home/comar/local/adainclude/ada.ads
  7043.                       /home/comar/local/adainclude/a-finali.ads
  7044.                       /home/comar/local/adainclude/a-filico.ads
  7045.                       /home/comar/local/adainclude/a-stream.ads
  7046.                       /home/comar/local/adainclude/a-tags.ads
  7047.                       gen_list.ads
  7048.                       gen_list.adb
  7049.                       /home/comar/local/adainclude/gnat.ads
  7050.                       /home/comar/local/adainclude/g-io.ads
  7051.                       instr.ads
  7052.                       /home/comar/local/adainclude/system.ads
  7053.                       /home/comar/local/adainclude/s-exctab.ads
  7054.                       /home/comar/local/adainclude/s-finimp.ads
  7055.                       /home/comar/local/adainclude/s-finroo.ads
  7056.                       /home/comar/local/adainclude/s-secsta.ads
  7057.                       /home/comar/local/adainclude/s-stalib.ads
  7058.                       /home/comar/local/adainclude/s-stoele.ads
  7059.                       /home/comar/local/adainclude/s-stratt.ads
  7060.                       /home/comar/local/adainclude/s-tasoli.ads
  7061.                       /home/comar/local/adainclude/s-unstyp.ads
  7062.                       /home/comar/local/adainclude/unchconv.ads
  7063.  
  7064.  
  7065. ΓòÉΓòÉΓòÉ 17. GNAT and libraries ΓòÉΓòÉΓòÉ
  7066.  
  7067.  
  7068.  This chapter addresses some of the issues related to building and using a 
  7069.  library with GNAT. It also shows how the GNAT runtime library can be 
  7070.  recompiled. 
  7071.  
  7072.  Creating an Ada library       Creating an Ada library 
  7073.  Installing an Ada library     Installing an Ada library 
  7074.  Using an Ada library          Using an Ada library 
  7075.  Rebuilding the GNAT runtime libraryRebuilding the GNAT runtime library 
  7076.  
  7077.  
  7078. ΓòÉΓòÉΓòÉ 17.1. Creating an Ada library ΓòÉΓòÉΓòÉ
  7079.  
  7080.  
  7081.  In the GNAT environment, a library has two components: 
  7082.  
  7083.      Source files. 
  7084.  
  7085.      Compiled code and Ali files. See The Ada Library Information Files. 
  7086.  
  7087.  In order to use other packages The GNAT Compilation Model requires a certain 
  7088.  number of sources to be available to the compiler. The minimal set of sources 
  7089.  required includes the specs of all the packages that make up the visible part 
  7090.  of the library as well as all the sources upon which they depend. The bodies 
  7091.  of all visible generic units must also be provided. 
  7092.  Although it is not strictly mandatory, it is recommended that all sources 
  7093.  needed to recompile the library be provided, so that the user can make full 
  7094.  use of interunit inlining and source-level debugging. This can also make the 
  7095.  situation easier for users that need to upgrade their compilation toolchain 
  7096.  and thus need to recompile the library from sources. 
  7097.  The compiled code can be provided in different ways. The simplest way is to 
  7098.  provide directly the set of objects produced by the compiler during the 
  7099.  compilation of the library. It is also possible to group the objects into an 
  7100.  archive using whatever commands are provided by the operating system. Finally, 
  7101.  it is also possible to create a shared library (see option -shared in the GCC 
  7102.  manual). 
  7103.  There are various possibilities for compiling the units that make up the 
  7104.  library: for example with a Makefile Using the GNU make utility, or with a 
  7105.  conventional script. For simple libraries, it is also possible to create a 
  7106.  dummy main program which depends upon all the packages that comprise the 
  7107.  interface of the library. This dummy main program can then be given to 
  7108.  gnatmake, in order to build all the necessary objects. Here is an example of 
  7109.  such a dummy program and the generic commands used to build an archive or a 
  7110.  shared library. 
  7111.  
  7112.                       with My_Lib.Service1;
  7113.                       with My_Lib.Service2;
  7114.                       with My_Lib.Service3;
  7115.                       procedure My_Lib_Dummy is
  7116.                       begin
  7117.                         null;
  7118.                       end;
  7119.                       # compiling the library
  7120.                       $ gnatmake -c my_lib_dummy.adb
  7121.                       # we don't need the dummy object itself
  7122.                       $ rm my_lib_dummy.o my_lib_dummy.ali
  7123.                       # create an archive with the remaining objects
  7124.                       $ ar rc libmy_lib.a *.o
  7125.                       # some systems may require "ranlib" to be run as well
  7126.                       # or create a shared library
  7127.                       $ gcc -shared -o libmy_lib.so *.o
  7128.                       # some systems may require the code to have been compiled with -fPIC
  7129.  
  7130.  When the objects are grouped in an archive or a shared library, the user needs 
  7131.  to specify the desired library at link time, unless a pragma linker_options 
  7132.  has been used in one of the sources: 
  7133.  
  7134.                       pragma Linker_Options ("-lmy_lib");
  7135.  
  7136.  
  7137. ΓòÉΓòÉΓòÉ 17.2. Installing an Ada library ΓòÉΓòÉΓòÉ
  7138.  
  7139.  
  7140.  In the GNAT model, installing a library consists in copying into a specific 
  7141.  location the files that make up this library. It is possible to install the 
  7142.  sources in a different directory from the other files (ALI, objects, archives) 
  7143.  since the source path and the object path can easily be specified separately. 
  7144.  For general purpose libraries, it is possible for the system administrator to 
  7145.  put those libraries in the default compiler paths. To achieve this, he must 
  7146.  specify their location in the configuration files "ada_source_path" and 
  7147.  "ada_object_path" that must be located in the GNAT installation tree at the 
  7148.  same place as the gcc spec file. The location of the gcc spec file can be 
  7149.  determined as follows: 
  7150.  
  7151.                       $ gcc -v
  7152.  
  7153.  The configuration files mentioned above have simple format: each line in them 
  7154.  must contain one unique directory name. Those names are added to the 
  7155.  corresponding path in their order of appearance in the file. The names can be 
  7156.  either absolute or relative, in the latter case, they are relative to where 
  7157.  theses files are located. 
  7158.  "ada_source_path" and "ada_object_path" might actually not be present in a 
  7159.  GNAT installation, in which case, GNAT will look for its runtime library in 
  7160.  the directories "adainclude" for the sources and "adalib" for the objects and 
  7161.  ALI files. When the files exist, the compiler does not look in "adainclude" 
  7162.  and "adalib" at all, and thus the "ada_source_path" file must contain the 
  7163.  location for the GNAT runtime sources (which can simply be "adainclude"). In 
  7164.  the same way, the "ada_object_path" file must contain the location for the 
  7165.  GNAT runtime objects (which can simply be "adalib"). 
  7166.  It is possible to install a library before or after the standard GNAT library, 
  7167.  by reordering the lines in the configuration files. In general, a library must 
  7168.  be installed before the GNAT library if it redefines any part of it. 
  7169.  
  7170.  
  7171. ΓòÉΓòÉΓòÉ 17.3. Using an Ada library ΓòÉΓòÉΓòÉ
  7172.  
  7173.  
  7174.  In order to use a Ada library, you need to make sure that this library is on 
  7175.  both your source and object path Search Paths and the Run-Time Library (RTL) 
  7176.  and Search Paths for gnatbind. For instance, you can use the library "mylib" 
  7177.  installed in "/dir/my_lib_src" and "/dir/my_lib_obj" with the following 
  7178.  commands: 
  7179.  
  7180.                       $ gnatmake -aI/dir/my_lib_src -aO/dir/my_lib_obj my_appl \
  7181.                        -largs -lmy_lib
  7182.  
  7183.  This can be simplified down to the following: 
  7184.  
  7185.                       $ gnatmake my_appl
  7186.  when the following conditions are met: 
  7187.  
  7188.      "/dir/my_lib_src" has been added by the user to the environment variable 
  7189.       "ADA_INCLUDE_PATH", or by the administrator to the file "ada_source_path" 
  7190.  
  7191.      "/dir/my_lib_obj" has been added by the user to the environment variable 
  7192.       "ADA_OBJECTS_PATH", or by the administrator to the file "ada_object_path" 
  7193.  
  7194.      a pragma linker_options, as mentioned in Creating an Ada library as been 
  7195.       added to the sources. 
  7196.  
  7197.  
  7198. ΓòÉΓòÉΓòÉ 17.4. Rebuilding the GNAT runtime library ΓòÉΓòÉΓòÉ
  7199.  
  7200.  
  7201.  It may be useful to recompile the GNAT library in various contexts, the most 
  7202.  important one being the use of partition-wide configuration pragmas such as 
  7203.  Normalize_Scalar. A special Makefile called Makefile.adalib is provided to 
  7204.  that effect and can be found in the directory containing the GNAT library. The 
  7205.  location of this directory depends on the way the GNAT environment has been 
  7206.  installed and can be determined by means of the command: 
  7207.  
  7208.                       $ gnatls -v
  7209.  
  7210.  The last line of the Object Search Path usually contains the gnat library. 
  7211.  This Makefile contains its own documentation and in particular the set of 
  7212.  instructions needed to rebuild a new library and to use it. 
  7213.  
  7214.  
  7215. ΓòÉΓòÉΓòÉ 18. Using the GNU make utility ΓòÉΓòÉΓòÉ
  7216.  
  7217.  
  7218.  This chapter offers some examples of makefiles that solve specific problems. 
  7219.  It does not explain how to write a makefile (see the GNU make documentation), 
  7220.  nor does it try to replace the gnatmake utility (see The GNAT Make Program 
  7221.  gnatmake). 
  7222.  
  7223.  All the examples in this section are specific to the GNU version of make. 
  7224.  Although make is a standard utility, and the basic language is the same, these 
  7225.  examples use some advanced features found only in GNU make. 
  7226.  
  7227.  Using gnatmake in a Makefile  Using gnatmake in a Makefile 
  7228.  Automatically creating a list of directoriesAutomatically creating a list of 
  7229.                                directories 
  7230.  Generating the command line switchesGenerating the command line switches 
  7231.  Overcoming command line length limitsOvercoming command line length limits 
  7232.  
  7233.  
  7234. ΓòÉΓòÉΓòÉ 18.1. Using gnatmake in a Makefile ΓòÉΓòÉΓòÉ
  7235.  
  7236.  
  7237.  Complex project organizations can be handled in a very powerful way by using 
  7238.  GNU make combined with gnatmake. For instance, here is a Makefile which allows 
  7239.  you to build each subsystem of a big project into a separate shared library. 
  7240.  Such a makefile allows you to significantly reduce the link time of very big 
  7241.  applications while maintaining full coherence at each step of the build 
  7242.  process. 
  7243.  
  7244.  The list of dependencies are handled automatically by gnatmake. The Makefile 
  7245.  is simply used to call gnatmake in each of the appropriate directories. 
  7246.  
  7247.  Note that you should also read the example on how to automatically create the 
  7248.  list of directories (see Automatically creating a list of directories) which 
  7249.  might help you in case your project has a lot of subdirectories. 
  7250.  
  7251.                       ## This Makefile is intended to be used with the following directory
  7252.                       ## configuration:
  7253.                       ##  - The sources are split into a series of csc (computer software components)
  7254.                       ##   Each of these csc is put in its own directory.
  7255.                       ##   Their name are referenced by the directory names.
  7256.                       ##   They will be compiled into shared library (although this would also work
  7257.                       ##   with static libraries
  7258.                       ##  - The main program (and possibly other packages that do not belong to any
  7259.                       ##   csc is put in the top level directory (where the Makefile is).
  7260.                       ##    toplevel_dir __ first_csc  (sources) __ lib (will contain the library)
  7261.                       ##           \_ second_csc (sources) __ lib (will contain the library)
  7262.                       ##           \_ ┬╖┬╖┬╖
  7263.                       ## Although this Makefile is build for shared library, it is easy to modify
  7264.                       ## to build partial link objects instead (modify the lines with -shared and
  7265.                       ## gnatlink below)
  7266.                       ##
  7267.                       ## With this makefile, you can change any file in the system or add any new
  7268.                       ## file, and everything will be recompiled correctly (only the relevant shared
  7269.                       ## objects will be recompiled, and the main program will be re-linked).
  7270.                       # The list of computer software component for your project. This might be
  7271.                       # generated automatically.
  7272.                       CSC_LIST=aa bb cc
  7273.                       # Name of the main program (no extension)
  7274.                       MAIN=main
  7275.                       # If we need to build objects with -fPIC, uncomment the following line
  7276.                       #NEED_FPIC=-fPIC
  7277.                       # The following variable should give the directory containing libgnat.so
  7278.                       # You can get this directory through 'gnatls -v'. This is usually the last
  7279.                       # directory in the Object_Path.
  7280.                       GLIB=┬╖┬╖┬╖
  7281.                       # The directories for the libraries
  7282.                       # (This macro expands the list of CSC to the list of shared libraries, you
  7283.                       # could simply use the expanded form :
  7284.                       # LIB_DIR=aa/lib/libaa.so bb/lib/libbb.so cc/lib/libcc.so
  7285.                       LIB_DIR=${foreach dir,${CSC_LIST},${dir}/lib/lib${dir}.so}
  7286.                       ${MAIN}: objects ${LIB_DIR}
  7287.                           gnatbind ${MAIN} ${CSC_LIST:%=-aO%/lib} -shared
  7288.                           gnatlink ${MAIN} ${CSC_LIST:%=-l%}
  7289.                       objects::
  7290.                           # recompile the sources
  7291.                           gnatmake -c -i ${MAIN}.adb ${NEED_FPIC} ${CSC_LIST:%=-I%}
  7292.                       # Note: In a future version of GNAT, the following commands will be simplified
  7293.                       # by a new tool, gnatmlib
  7294.                       ${LIB_DIR}:
  7295.                           mkdir -p ${dir $@ }
  7296.                           cd ${dir $@ }; gcc -shared -o ${notdir $@ } ┬╖┬╖/*.o -L${GLIB} -lgnat
  7297.                           cd ${dir $@ }; cp -f ┬╖┬╖/*.ali .
  7298.                       # The dependencies for the modules
  7299.                       aa/lib/libaa.so: aa/*.o
  7300.                       bb/lib/libbb.so: bb/*.o
  7301.                       bb/lib/libcc.so: cc/*.o
  7302.                       # Make sure all of the shared libraries are in the path before starting the
  7303.                       # program
  7304.                       run::
  7305.                           LD_LIBRARY_PATH=pwd/aa/lib:pwd/bb/lib:pwd/cc/lib ./${MAIN}
  7306.                       clean::
  7307.                           ${RM} -rf ${CSC_LIST:%=%/lib}
  7308.                           ${RM} ${CSC_LIST:%=%/*.ali}
  7309.                           ${RM} ${CSC_LIST:%=%/*.o}
  7310.                           ${RM} *.o *.ali ${MAIN}
  7311.  
  7312.  
  7313. ΓòÉΓòÉΓòÉ 18.2. Automatically creating a list of directories ΓòÉΓòÉΓòÉ
  7314.  
  7315.  
  7316.  In most makefiles, you will have to specify a list of directories, and store 
  7317.  it in a variable. For small projects, it is often easier to specify each of 
  7318.  them by hand, since you then have full control over what is the proper order 
  7319.  for these directories, which ones should be included┬╖┬╖┬╖ 
  7320.  
  7321.  However, in larger projects, which might involve hundreds of subdirectories, 
  7322.  it might be more convenient to generate this list automatically. 
  7323.  
  7324.  The example below presents two methods. The first one, altough less general, 
  7325.  gives you more control over the list. It involves wildcard characters, that 
  7326.  are automatically expanded by make. Its shortcoming is that you need to 
  7327.  explicitly specify some of the organization of your project, such as for 
  7328.  instance the directory tree depth, whether some directories are found in a 
  7329.  separate tree,┬╖┬╖┬╖ 
  7330.  
  7331.  The second method is the most general one. It requires an external program, 
  7332.  called find, which is standard on all Unix systems. All the directories found 
  7333.  under a given root directory will be added to the list. 
  7334.  
  7335.                       # The examples below are based on the following directory hierarchy:
  7336.                       # All the directories can contain any number of files
  7337.                       # ROOT_DIRECTORY ->  a  ->  aa  ->  aaa
  7338.                       #            ->  ab
  7339.                       #            ->  ac
  7340.                       #         ->  b  ->  ba  ->  baa
  7341.                       #            ->  bb
  7342.                       #            ->  bc
  7343.                       # This Makefile creates a variable called DIRS, that can be reused any time
  7344.                       # you need this list (see the other examples in this section)
  7345.                       # The root of your project's directory hierarchy
  7346.                       ROOT_DIRECTORY=.
  7347.                       ####
  7348.                       # First method: specify explicitly the list of directories
  7349.                       # This allows you to specify any subset of all the directories you need.
  7350.                       ####
  7351.                       DIRS := a/aa/ a/ab/ b/ba/
  7352.                       ####
  7353.                       # Second method: use wildcards
  7354.                       # Note that the argument(s) to wildcard below should end with a '/'.
  7355.                       # Since wildcards also return file names, we have to filter them out
  7356.                       # to avoid duplicate directory names.
  7357.                       # We thus use make's dir and sort functions.
  7358.                       # It sets DIRs to the following value (note that the directories aaa and baa
  7359.                       # are not given, unless you change the arguments to wildcard).
  7360.                       # DIRS= ./a/a/ ./b/ ./a/aa/ ./a/ab/ ./a/ac/ ./b/ba/ ./b/bb/ ./b/bc/
  7361.                       ####
  7362.                       DIRS := ${sort ${dir ${wildcard ${ROOT_DIRECTORY}/*/ ${ROOT_DIRECTORY}/*/*/}}}
  7363.                       ####
  7364.                       # Third method: use an external program
  7365.                       # This command is much faster if run on local disks, avoiding NFS slowdowns.
  7366.                       # This is the most complete command: it sets DIRs to the following value:
  7367.                       # DIRS= ./a ./a/aa ./a/aa/aaa ./a/ab ./a/ac ./b ./b/ba ./b/ba/baa ./b/bb ./b/bc
  7368.                       ####
  7369.                       DIRS := ${shell find ${ROOT_DIRECTORY} -type d -print}
  7370.  
  7371.  
  7372. ΓòÉΓòÉΓòÉ 18.3. Generating the command line switches ΓòÉΓòÉΓòÉ
  7373.  
  7374.  
  7375.  Once you have created the list of directories as explained in the previous 
  7376.  section (see Automatically creating a list of directories), you can easily 
  7377.  generate the command line arguments to pass to gnatmake. 
  7378.  
  7379.  For the sake of completness, this example assumes that the source path is not 
  7380.  the same as the object path, and that you have two separate lists of 
  7381.  directories. 
  7382.  
  7383.                       # see "Automatically creating a list of directories" to create
  7384.                       # these variables
  7385.                       SOURCE_DIRS=
  7386.                       OBJECT_DIRS=
  7387.                       GNATMAKE_SWITCHES := ${patsubst %,-aI%,${SOURCE_DIRS}}
  7388.                       GNATMAKE_SWITCHES += ${patsubst %,-aO%,${OBJECT_DIRS}}
  7389.                       all:
  7390.                           gnatmake ${GNATMAKE_SWITCHES} main_unit
  7391.  
  7392.  
  7393. ΓòÉΓòÉΓòÉ 18.4. Overcoming command line length limits ΓòÉΓòÉΓòÉ
  7394.  
  7395.  
  7396.  One problem that might be encountered on big projects is that many operating 
  7397.  systems limit the length of the command line. It is thus hard to give gnatmake 
  7398.  the list of source and object directories. 
  7399.  
  7400.  This example shows how you can set up environment variables, which will make 
  7401.  gnatmake behave exactly as if the directories had been specified on the 
  7402.  command line, but have a much higher length limit (or even none on most 
  7403.  systems). 
  7404.  
  7405.  It assumes that you have created a list of directories in your Makefile, using 
  7406.  one of the methods presented in Automatically creating a list of directories. 
  7407.  For the sake of completness, we assume that the object path (where the ALI 
  7408.  files are found) is different from the sources patch. 
  7409.  
  7410.  Note a small trick in the Makefile below: for efficiency reasons, we create 
  7411.  two temporary variables (SOURCE_LIST and OBJECT_LIST), that are expanded 
  7412.  immediatly by make. This way we overcome the standard make behavior which is 
  7413.  to expand the variables only when they are actually used. 
  7414.  
  7415.                       # In this example, we create both ADA_INCLUDE_PATH and ADA_OBJECT_PATH.
  7416.                       # This is the same thing as putting the -I arguments on the command line.
  7417.                       # (the equivalent of using -aI on the command line would be to define
  7418.                       #  only ADA_INCLUDE_PATH, the equivalent of -aO is ADA_OBJECT_PATH).
  7419.                       # You can of course have different values for these variables.
  7420.                       #
  7421.                       # Note also that we need to keep the previous values of these variables, since
  7422.                       # they might have been set before running 'make' to specify where the GNAT
  7423.                       # library is installed.
  7424.                       # see "Automatically creating a list of directories" to create these
  7425.                       # variables
  7426.                       SOURCE_DIRS=
  7427.                       OBJECT_DIRS=
  7428.                       empty:=
  7429.                       space:=${empty} ${empty}
  7430.                       SOURCE_LIST := ${subst ${space},:,${SOURCE_DIRS}}
  7431.                       OBJECT_LIST := ${subst ${space},:,${OBJECT_DIRS}}
  7432.                       ADA_INCLUDE_PATH += ${SOURCE_LIST}
  7433.                       ADA_OBJECT_PATH += ${OBJECT_LIST}
  7434.                       export ADA_INCLUDE_PATH
  7435.                       export ADA_OBJECT_PATH
  7436.                       all:
  7437.                           gnatmake main_unit
  7438.  
  7439.  
  7440. ΓòÉΓòÉΓòÉ 19. Finding memory problems with gnatmem ΓòÉΓòÉΓòÉ
  7441.  
  7442.  
  7443.  gnatmem, is a tool that monitors dynamic allocation and deallocation activity 
  7444.  in a program, and displays information about incorrect deallocations and 
  7445.  possible sources of memory leaks. Gnatmem provides three type of information: 
  7446.  
  7447.      General information concerning memory management, such as the total 
  7448.       number of allocations and deallocations, the amount of allocated memory 
  7449.       and the high water mark, i.e. the largest amount of allocated memory in 
  7450.       the course of program execution. 
  7451.  
  7452.      Backtraces for all incorrect deallocations, that is to say deallocations 
  7453.       which do not correspond to a valid allocation. 
  7454.  
  7455.      Information on each allocation that is potentially the origin of a memory 
  7456.       leak. 
  7457.  
  7458.  Running gnatmem               Running gnatmem 
  7459.  Switches for gnatmem          Switches for gnatmem 
  7460.  Examples of gnatmem Usage     Examples of gnatmem Usage 
  7461.  Implementation note           Implementation note 
  7462.  
  7463.  
  7464. ΓòÉΓòÉΓòÉ 19.1. Running gnatmem ΓòÉΓòÉΓòÉ
  7465.  
  7466.  
  7467.  The gnatmem command has the form 
  7468.  
  7469.                         $ gnatmem [n] [-o file] user_program [program_arg]*
  7470.                       or
  7471.                         $ gnatmem [n] -i file
  7472.  
  7473.  Gnatmem must be supplied with the executable to examine, followed by its 
  7474.  run-time inputs. For example, if a program is executed with the command: 
  7475.  
  7476.                       $ my_program arg1 arg2
  7477.  then it can be run under gnatmem control using the command: 
  7478.  
  7479.                       $ gnatmem my_program arg1 arg2
  7480.  
  7481.  The program is transparently executed under the control of the debugger The 
  7482.  GNAT Debugger GDB. This does not affect the behavior of the program, except 
  7483.  for sensitive real-time programs. When the program has completed execution, 
  7484.  gnatmem outputs a report containing general allocation/deallocation 
  7485.  information and potential memory leak. For better results, the user program 
  7486.  should be compiled with debugging options Switches for gcc. 
  7487.  
  7488.  Here is a simple example of use: 
  7489.  
  7490.  *************** debut cc 
  7491.  
  7492.                       $ gnatmem test_gm
  7493.                       Global information
  7494.                       ------------------
  7495.                         Total number of allocations     :  45
  7496.                         Total number of deallocations    :  6
  7497.                         Final Water Mark (non freed mem)  :  11.29 Kilobytes
  7498.                         High Water Mark           :  11.40 Kilobytes
  7499.                       ┬╖
  7500.                       ┬╖
  7501.                       ┬╖
  7502.                       Allocation Root # 2
  7503.                       -------------------
  7504.                        Number of non freed allocations   :  11
  7505.                        Final Water Mark (non freed mem)  :  1.16 Kilobytes
  7506.                        High Water Mark           :  1.27 Kilobytes
  7507.                        Backtrace              :
  7508.                         test_gm.adb:23 test_gm.alloc
  7509.                       ┬╖
  7510.                       ┬╖
  7511.                       ┬╖
  7512.  
  7513.  The first block of output give general information. In this case, the Ada 
  7514.  construct "new" was executed 45 times, and only 6 calls to an unchecked 
  7515.  deallocation routine occurred. 
  7516.  
  7517.  Subsequent paragraphs display  information on all allocation roots. An 
  7518.  allocation root is a specific point in the execution of the program that 
  7519.  generates some dynamic allocation, such as a "new" construct. This root is 
  7520.  represented by an execution backtrace (or subprogram call stack). By default 
  7521.  the backtrace depth for allocations roots is 1, so that a root corresponds 
  7522.  exactly to a source location. The backtrace can be made deeper, to make the 
  7523.  root more specific. 
  7524.  
  7525.  
  7526. ΓòÉΓòÉΓòÉ 19.2. Switches for gnatmem ΓòÉΓòÉΓòÉ
  7527.  
  7528.  
  7529.  gnatmem recognizes the following switches: 
  7530.  
  7531.  -q 
  7532.            Quiet. Gives the minimum output needed to identify the origin of the 
  7533.            memory leaks. Omit statistical information. 
  7534.  
  7535.  n 
  7536.            N is an integer literal (usually between 1 and 10) which controls 
  7537.            the depth of the backtraces defining allocation root. The default 
  7538.            value for N is 1. The deeper the backtrace, the more precise the 
  7539.            localization of the root. Note that the total number of roots can 
  7540.            depend on this parameter. 
  7541.  
  7542.  -o file 
  7543.            Direct the gdb output to the specified file. The gdb script used to 
  7544.            generate this output is also saved in the file 'gnatmem.tmp'. 
  7545.  
  7546.  -i file 
  7547.            Do the gnatmem processing starting from file which has been 
  7548.            generated by a previous call to gnatmem with the -o switch. This is 
  7549.            useful for post mortem processing. 
  7550.  
  7551.  
  7552. ΓòÉΓòÉΓòÉ 19.3. Example of gnatmem Usage ΓòÉΓòÉΓòÉ
  7553.  
  7554.  
  7555.  The first example shows the use of gnatmem on a simple leaking program. 
  7556.  Suppose that we have the following Ada program: 
  7557.  
  7558.                       with Unchecked_Deallocation;
  7559.                       procedure Test_Gm is
  7560.                         type T is array (1┬╖┬╖1000) of Integer;
  7561.                         type Ptr is access T;
  7562.                         procedure Free is new Unchecked_Deallocation (T, Ptr);
  7563.                         A : Ptr;
  7564.                         procedure My_Alloc is
  7565.                         begin
  7566.                          A := new T;
  7567.                         end My_Alloc;
  7568.                         procedure My_DeAlloc is
  7569.                          B : Ptr := A;
  7570.                         begin
  7571.                          Free (B);
  7572.                         end My_DeAlloc;
  7573.                       begin
  7574.                         My_Alloc;
  7575.                         for I in 1 ┬╖┬╖ 5 loop
  7576.                          for J in I ┬╖┬╖ 5 loop
  7577.                            My_Alloc;
  7578.                          end loop;
  7579.                          My_Dealloc;
  7580.                         end loop;
  7581.                       end;
  7582.  
  7583.  The program needs to be compiled with debugging option: 
  7584.  
  7585.                       $ gnatmake -g test_gm
  7586.  
  7587.  gnatmem is invoked simply with 
  7588.  
  7589.                       $ gnatmem test_gm
  7590.  
  7591.  which produces the following output: 
  7592.  
  7593.                       Global information
  7594.                       ------------------
  7595.                         Total number of allocations     :  18
  7596.                         Total number of deallocations    :  5
  7597.                         Final Water Mark (non freed mem)  :  53.00 Kilobytes
  7598.                         High Water Mark           :  56.90 Kilobytes
  7599.                       Allocation Root # 1
  7600.                       -------------------
  7601.                        Number of non freed allocations   :  11
  7602.                        Final Water Mark (non freed mem)  :  42.97 Kilobytes
  7603.                        High Water Mark           :  46.88 Kilobytes
  7604.                        Backtrace              :
  7605.                         test_gm.adb:11 test_gm.my_alloc
  7606.                       Allocation Root # 2
  7607.                       -------------------
  7608.                        Number of non freed allocations   :  1
  7609.                        Final Water Mark (non freed mem)  :  10.02 Kilobytes
  7610.                        High Water Mark           :  10.02 Kilobytes
  7611.                        Backtrace              :
  7612.                         s-secsta.adb:81 system.secondary_stack.ss_init
  7613.                       Allocation Root # 3
  7614.                       -------------------
  7615.                        Number of non freed allocations   :  1
  7616.                        Final Water Mark (non freed mem)  :  12 Bytes
  7617.                        High Water Mark           :  12 Bytes
  7618.                        Backtrace              :
  7619.                         s-secsta.adb:181 system.secondary_stack.ss_init
  7620.  
  7621.  Note that the GNAT run time contains itself a certain number of allocations 
  7622.  that have no  corresponding deallocation, as shown here for root #2 and root 
  7623.  #1. This is a normal behavior when the number of non freed allocations is one, 
  7624.  it locates dynamic data structures that the run time needs for the complete 
  7625.  lifetime of the program. Note also that there is only one allocation root in 
  7626.  the user program with a single line back trace: test_gm.adb:11 
  7627.  test_gm.my_alloc, whereas a careful analysis of the program shows that 
  7628.  'My_Alloc' is called at 2 different points in the source (line 21 and line 
  7629.  24). If those two allocation roots need to be distinguished, the backtrace 
  7630.  depth parameter can be used: 
  7631.  
  7632.                       $ gnatmem 3 test_gm
  7633.  
  7634.  which will give the following output: 
  7635.  
  7636.                       Global information
  7637.                       ------------------
  7638.                         Total number of allocations     :  18
  7639.                         Total number of deallocations    :  5
  7640.                         Final Water Mark (non freed mem)  :  53.00 Kilobytes
  7641.                         High Water Mark           :  56.90 Kilobytes
  7642.                       Allocation Root # 1
  7643.                       -------------------
  7644.                        Number of non freed allocations   :  10
  7645.                        Final Water Mark (non freed mem)  :  39.06 Kilobytes
  7646.                        High Water Mark           :  42.97 Kilobytes
  7647.                        Backtrace              :
  7648.                         test_gm.adb:11 test_gm.my_alloc
  7649.                         test_gm.adb:24 test_gm
  7650.                         b_test_gm.c:52 main
  7651.                       Allocation Root # 2
  7652.                       -------------------
  7653.                        Number of non freed allocations   :  1
  7654.                        Final Water Mark (non freed mem)  :  10.02 Kilobytes
  7655.                        High Water Mark           :  10.02 Kilobytes
  7656.                        Backtrace              :
  7657.                         s-secsta.adb:81  system.secondary_stack.ss_init
  7658.                         s-secsta.adb:283 <system__secondary_stack___elabb>
  7659.                         b_test_gm.c:33  adainit
  7660.                       Allocation Root # 3
  7661.                       -------------------
  7662.                        Number of non freed allocations   :  1
  7663.                        Final Water Mark (non freed mem)  :  3.91 Kilobytes
  7664.                        High Water Mark           :  3.91 Kilobytes
  7665.                        Backtrace              :
  7666.                         test_gm.adb:11 test_gm.my_alloc
  7667.                         test_gm.adb:21 test_gm
  7668.                         b_test_gm.c:52 main
  7669.                       Allocation Root # 4
  7670.                       -------------------
  7671.                        Number of non freed allocations   :  1
  7672.                        Final Water Mark (non freed mem)  :  12 Bytes
  7673.                        High Water Mark           :  12 Bytes
  7674.                        Backtrace              :
  7675.                         s-secsta.adb:181 system.secondary_stack.ss_init
  7676.                         s-secsta.adb:283 <system__secondary_stack___elabb>
  7677.                         b_test_gm.c:33  adainit
  7678.  
  7679.  The allocation root #1 of the first example has been split in 2 roots #1 and 
  7680.  #3 thanks to the more precise associated backtrace. 
  7681.  
  7682.  
  7683. ΓòÉΓòÉΓòÉ 19.4. Implementation note ΓòÉΓòÉΓòÉ
  7684.  
  7685.  
  7686.  gnatmem executes the user program under the control of gdb using a script that 
  7687.  sets breakpoints and gathers information on each dynamic allocation and 
  7688.  deallocation. The output of the script is then analyzed by gnatmem in order to 
  7689.  locate memory leaks and their origin in the program. Gnatmem works by 
  7690.  recording each address returned by the allocation procedure (__gnat_malloc) 
  7691.  along with the backtrace at the allocation point. On each deallocation, the 
  7692.  deallocated address is matched with the corresponding allocation. At the end 
  7693.  of the processing, the unmatched allocations are considered potential leaks. 
  7694.  All the allocations associated with the same backtrace are grouped together 
  7695.  and form an allocation root. The allocation roots are then sorted so that 
  7696.  those with the biggest number of unmatched allocation are printed first. A 
  7697.  delicate aspect of this technique is to distinguish between the data produced 
  7698.  by the user program and the data produced by the gdb script. Currently, on 
  7699.  systems that allow probing the terminal, the gdb command "tty" is used to 
  7700.  force the program output to be redirected to the current terminal while the 
  7701.  gdb output is directed to a file or to a pipe in order to be processed 
  7702.  subsequently by gnatmem. 
  7703.  
  7704.  
  7705. ΓòÉΓòÉΓòÉ 20. Finding memory problems with GNAT Debug Pool ΓòÉΓòÉΓòÉ
  7706.  
  7707.  
  7708.  The use of unchecked deallocation and unchecked conversion can easily lead to 
  7709.  incorrect memory references. The problems generated by such references are 
  7710.  usually difficult to tackle because the symptoms can be very remote from the 
  7711.  origin of the problem. In such cases, it is very helpful to detect the problem 
  7712.  as early as possible. This is the purpose of the Storage Pool provided by 
  7713.  GNAT.Debug_Pools. 
  7714.  In order to use the GNAT specifc debugging pool, the user must associate a 
  7715.  debug pool object with each of the access types that may be related to 
  7716.  suspected memory problems. See Ada Reference Manual 13.11. 
  7717.  
  7718.                       type Ptr is access Some_Type;
  7719.                       Pool : GNAT.Debug_Pools.Debug_Pool;
  7720.                       for Ptr'Storage_Pool use Pool;
  7721.  
  7722.  GNAT.Debug_Pools is derived from of a GNAT-specific kind of pool: the 
  7723.  Checked_Pool. Such pools, like standard Ada storage pools, allow the user to 
  7724.  redefine allocation and deallocation strategies. They also provide a 
  7725.  checkpoint for each dereference, through the use of the primitive operation 
  7726.  Dereference which is implicitly called at each dereference of an access value. 
  7727.  
  7728.  Once an access type has been associated with a debug pool, operations on 
  7729.  values of the type may raise four distinct exceptions, which correspond to 
  7730.  four potential kinds of memory corruption: 
  7731.  
  7732.      GNAT.Debug_Pools.Accessing_Not_Allocated_Storage 
  7733.  
  7734.      GNAT.Debug_Pools.Accessing_Deallocated_Storage 
  7735.  
  7736.      GNAT.Debug_Pools.Freeing_Not_Allocated_Storage 
  7737.  
  7738.      GNAT.Debug_Pools.Freeing_Deallocated_Storage 
  7739.  
  7740.  For types associated with a Debug_Pool, dynamic allocation is performed using 
  7741.  the standard GNAT allocation routine. References to all allocated chunks of 
  7742.  memory are kept in an internal dictionary. The deallocation strategy consists 
  7743.  in not releasing the memory to the underlying system but rather to fill it 
  7744.  with a memory pattern easily recognizable during debugging sessions: The 
  7745.  memory pattern is the old IBM hexadecimal convention: 16#DEADBEEF#. Upon each 
  7746.  dereference, a check is made that the access value denotes a properly 
  7747.  allocated memory location. Here is a complete example of use of Debug_Pools, 
  7748.  that includes typical instances of  memory corruption: 
  7749.  
  7750.                       with Gnat.Io; use Gnat.Io;
  7751.                       with Unchecked_Deallocation;
  7752.                       with Unchecked_Conversion;
  7753.                       with GNAT.Debug_Pools;
  7754.                       with System.Storage_Elements;
  7755.                       with Ada.Exceptions; use Ada.Exceptions;
  7756.                       procedure Debug_Pool_Test is
  7757.                         type T is access Integer;
  7758.                         type U is access all T;
  7759.                         P : GNAT.Debug_Pools.Debug_Pool;
  7760.                         for T'Storage_Pool use P;
  7761.                         procedure Free is new Unchecked_Deallocation (Integer, T);
  7762.                         function UC is new Unchecked_Conversion (U, T);
  7763.                         A, B : aliased T;
  7764.                         procedure Info is new GNAT.Debug_Pools.Print_Info(Put_Line);
  7765.                       begin
  7766.                         Info (P);
  7767.                         A := new Integer;
  7768.                         B := new Integer;
  7769.                         B := A;
  7770.                         Info (P);
  7771.                         Free (A);
  7772.                         begin
  7773.                          Put_Line (Integer'Image(B.all));
  7774.                         exception
  7775.                          when E : others => Put_Line ("raised: " & Exception_Name (E));
  7776.                         end;
  7777.                         begin
  7778.                          Free (B);
  7779.                         exception
  7780.                          when E : others => Put_Line ("raised: " & Exception_Name (E));
  7781.                         end;
  7782.                         B := UC(A'Access);
  7783.                         begin
  7784.                          Put_Line (Integer'Image(B.all));
  7785.                         exception
  7786.                          when E : others => Put_Line ("raised: " & Exception_Name (E));
  7787.                         end;
  7788.                         begin
  7789.                          Free (B);
  7790.                         exception
  7791.                          when E : others => Put_Line ("raised: " & Exception_Name (E));
  7792.                         end;
  7793.                         Info (P);
  7794.                       end Debug_Pool_Test;
  7795.  
  7796.  The debug pool mechanism provides the following precise diagnostics on the 
  7797.  execution of this erroneous program: 
  7798.  
  7799.                       Debug Pool info:
  7800.                        Total allocated bytes :  0
  7801.                        Total deallocated bytes :  0
  7802.                        Current Water Mark:  0
  7803.                        High Water Mark:  0
  7804.                       Debug Pool info:
  7805.                        Total allocated bytes :  8
  7806.                        Total deallocated bytes :  0
  7807.                        Current Water Mark:  8
  7808.                        High Water Mark:  8
  7809.                       raised: GNAT.DEBUG_POOLS.ACCESSING_DEALLOCATED_STORAGE
  7810.                       raised: GNAT.DEBUG_POOLS.FREEING_DEALLOCATED_STORAGE
  7811.                       raised: GNAT.DEBUG_POOLS.ACCESSING_NOT_ALLOCATED_STORAGE
  7812.                       raised: GNAT.DEBUG_POOLS.FREEING_NOT_ALLOCATED_STORAGE
  7813.                       Debug Pool info:
  7814.                        Total allocated bytes :  8
  7815.                        Total deallocated bytes :  4
  7816.                        Current Water Mark:  4
  7817.                        High Water Mark:  8
  7818.  
  7819.  
  7820. ΓòÉΓòÉΓòÉ 21. Creating Sample Bodies Using gnatstub ΓòÉΓòÉΓòÉ
  7821.  
  7822.  
  7823.  gnatstub creates body stubs, that is, empty but compilable bodies for library 
  7824.  unit declarations. 
  7825.  
  7826.  To create a body stub, gnatstub has to compile the library unit declaration. 
  7827.  Therefore, bodies can be created only for legal library units. Moreover, if a 
  7828.  library unit depends semantically upon units located outside the current 
  7829.  directory, you have to provide the source search path when calling gnatstub, 
  7830.  see the description of gnatstub switches below. 
  7831.  
  7832.  Running gnatstub              Running gnatstub 
  7833.  Switches for gnatstub         Switches for gnatstub 
  7834.  
  7835.  
  7836. ΓòÉΓòÉΓòÉ 21.1. Running gnatstub ΓòÉΓòÉΓòÉ
  7837.  
  7838.  
  7839.  gnatstub has the command-line interface of the form 
  7840.  
  7841.                       $ gnatstub [switches] filename [directory]
  7842.  
  7843.  where 
  7844.  
  7845.  filename 
  7846.            is the name of the source file that contains a library unit 
  7847.            declaration for which a body must be created. This name should 
  7848.            follow the GNAT file name conventions. No crunching is allowed for 
  7849.            this file name. The file name may contain the path information. 
  7850.  
  7851.  directory 
  7852.            indicates the directory to place a body stub (default is the current 
  7853.            directory) 
  7854.  
  7855.  switches 
  7856.            is an optional sequence of switches as described in the next section 
  7857.  
  7858.  
  7859. ΓòÉΓòÉΓòÉ 21.2. Switches for gnatstub ΓòÉΓòÉΓòÉ
  7860.  
  7861.  -f 
  7862.            If the destination directory already contains a file with a name of 
  7863.            the body file for the argument spec file, replace it with the 
  7864.            generated body stub. 
  7865.  
  7866.  -hs 
  7867.            Put the comment header (i.e. all the comments preceding the 
  7868.            compilation unit) from the source of the library unit declaration 
  7869.            into the body stub. 
  7870.  
  7871.  -hg 
  7872.            Put a sample comment header into the body stub. 
  7873.  
  7874.  -IDIR 
  7875.  
  7876.  -I- 
  7877.            These switches have the same meaning as in calls to gcc. They define 
  7878.            the source search path in the call to gcc issued by gnatstub to 
  7879.            compile an argument source file. 
  7880.  
  7881.  -in 
  7882.            (n is a decimal natural number). Set the indentation level in the 
  7883.            generated body sample to n, '-i0' means "no indentation", the 
  7884.            default indentation is 3. 
  7885.  
  7886.  -k 
  7887.            Do not remove the tree file (i.e. the snapshot of the compiler 
  7888.            internal structures used by gnatstub) after creating the body stub. 
  7889.  
  7890.  -ln 
  7891.            (n is a decimal positive number) Set the maximum line length in the 
  7892.            body stub to n, the default is 78. 
  7893.  
  7894.  -q 
  7895.            Quiet mode: do not generate a confirmation when a body is 
  7896.            successfully created or a message when a body is not required for an 
  7897.            argument unit. 
  7898.  
  7899.  -r 
  7900.            Reuse the tree file (if it exists) instead of creating it: instead 
  7901.            of creating the tree file for the library unit declaration, gnatstub 
  7902.            tries to find it in the current directory and use it for creating a 
  7903.            body. If the tree file is not found, no body is created. -r also 
  7904.            implies -k, whether or not -k is set explicitly. 
  7905.  
  7906.  -t 
  7907.            Overwrite the existing tree file: if the current directory already 
  7908.            contains the file which, according to the GNAT file name rules 
  7909.            should be considered as a tree file for the argument source file, 
  7910.            gnatstub will refuse to create the tree file needed to create a body 
  7911.            sampler, unless -t option is set 
  7912.  
  7913.  -v 
  7914.            Verbose mode: generate version information. 
  7915.  
  7916.  
  7917. ΓòÉΓòÉΓòÉ 22. Reducing the Size of Ada Executables with gnatelim ΓòÉΓòÉΓòÉ
  7918.  
  7919.  About gnatelim                About gnatelim 
  7920.  Eliminate pragma              Eliminate pragma 
  7921.  Tree Files                    Tree Files 
  7922.  Preparing Tree and Bind Files for gnatelimPreparing Tree and Bind Files for 
  7923.                                gnatelim 
  7924.  Running gnatelim              Running gnatelim 
  7925.  Correcting the List of Eliminate PragmasCorrecting the List of Eliminate 
  7926.                                Pragmas 
  7927.  Making your Executables smallerMaking your Executables smaller 
  7928.  Summary of the gnatelim Usage CycleSummary of the gnatelim Usage Cycle 
  7929.  
  7930.  
  7931. ΓòÉΓòÉΓòÉ 22.1. About gnatelim ΓòÉΓòÉΓòÉ
  7932.  
  7933.  
  7934.  When a program shares a set of Ada packages with other programs, it may happen 
  7935.  that this program uses only a fraction of the subprograms defined in these 
  7936.  packages. The code created for these unused subprograms increases the size of 
  7937.  the executable. 
  7938.  
  7939.  gnatelim tracks unused subprograms in an Ada program and outputs a list of 
  7940.  GNAT-specific Eliminate pragmas (see next section) marking all the subprograms 
  7941.  that are declared but never called. By placing the list of Eliminate pragmas 
  7942.  in the GNAT configuration file 'gnat.adc' and recompiling your program, you 
  7943.  may decrease the size of its executable, because the compiler will not 
  7944.  generate the code for 'eliminated' subprograms. 
  7945.  
  7946.  gnatelim needs as its input data a set of tree files (see Tree Files) 
  7947.  representing all the components of a program to process and a bind file for a 
  7948.  main subprogram (see Preparing Tree and Bind Files for gnatelim). Both of 
  7949.  these must be present in the current directory. 
  7950.  
  7951.  
  7952. ΓòÉΓòÉΓòÉ 22.2. Eliminate pragma ΓòÉΓòÉΓòÉ
  7953.  
  7954.  
  7955.  The simplified syntax of Eliminate pragma that gnatelim makes use of is 
  7956.  
  7957.                       pragma Eliminate (Library_Unit_Name, Subprogram_Name);
  7958.  
  7959.  where 
  7960.  
  7961.  Library_Unit_Name 
  7962.            full expanded Ada name of a library unit 
  7963.  
  7964.  Subprogram_Name 
  7965.            a simple or expanded name of a subprogram declared within this 
  7966.            compilation unit 
  7967.  
  7968.  The effect of an Eliminate pragma placed in the GNAT configuration file 
  7969.  'gnat.adc' is: 
  7970.  
  7971.      If the subprogram Subprogram_Name is declared within the library unit 
  7972.       Library_Unit_Name, the compiler will not generate code for this 
  7973.       subprogram. This applies to all overloaded subprograms denoted by 
  7974.       Subprogram_Name. 
  7975.  
  7976.      If a subprogram marked by the pragma Eliminate is used (called) in a 
  7977.       program, the compiler will produce an error message in the place where it 
  7978.       is called. 
  7979.  
  7980.  
  7981. ΓòÉΓòÉΓòÉ 22.3. Tree Files ΓòÉΓòÉΓòÉ
  7982.  
  7983.  
  7984.  A tree file stores a snapshot of the compiler internal data structures in the 
  7985.  very end of a successful compilation. It contains all the syntactical and 
  7986.  semantic information about the unit being compiled and all the units upon 
  7987.  which it depends semantically. Some tools need tree files to obtain this 
  7988.  information. 
  7989.  
  7990.  To use some of these tools, a user should take care of producing the right set 
  7991.  of tree files for them. 
  7992.  
  7993.  GNAT produces correct tree files when -gnatt -gnatc options are set in a gcc 
  7994.  call. The tree files have an .adt extension. 
  7995.  
  7996.  Therefore, to produce a tree file for the compilation unit contained in a file 
  7997.  named 'foo.adb', you must use the command 
  7998.  
  7999.                       $ gcc -c -gnatc -gnatt foo.adb
  8000.  
  8001.  and you will get the tree file 'foo.adt' as a result of this compilation. 
  8002.  
  8003.  
  8004. ΓòÉΓòÉΓòÉ 22.4. Preparing Tree and Bind Files for gnatelim ΓòÉΓòÉΓòÉ
  8005.  
  8006.  
  8007.  Let Main_Prog be the name of a main subprogram, and suppose this subprogram is 
  8008.  in a file named 'main_prog.adb'. 
  8009.  
  8010.  To create a bind file for gnatelim, run gnatbind for the main subprogram. 
  8011.  gnatelim can work with both Ada and C bind files; when both are present, it 
  8012.  uses the Ada bind file. The following commands will build the program and 
  8013.  create the bind file: 
  8014.  
  8015.                       $ gnatmake -c Main_Prog
  8016.                       $ gnatbind main_prog
  8017.  
  8018.  To create a minimal set of tree files covering the whole program, call 
  8019.  gnatmake for this program as follows: 
  8020.  
  8021.                       $ gnatmake -f -c -gnatc -gnatt Main_Prog
  8022.  
  8023.  The -c gnatmake option turns off the bind and link phases, that are impossible 
  8024.  anyway because the sources are compiled with -gnatc option which turns off 
  8025.  code generation. 
  8026.  
  8027.   the -f gnatmake option forces recompilation of all the needed sources. 
  8028.  
  8029.  Such sequence of actions will create all the data needed by gnatelim from 
  8030.  scratch and therefore guarantee its consistency. 
  8031.  
  8032.  Note, that gnatelim needs neither object nor ALI files, so they can be deleted 
  8033.  at this stage. 
  8034.  
  8035.  
  8036. ΓòÉΓòÉΓòÉ 22.5. Running gnatelim ΓòÉΓòÉΓòÉ
  8037.  
  8038.  
  8039.  gnatelim has the following command-line interface: 
  8040.  
  8041.                       $ gnatelim [options] name
  8042.  
  8043.  name should be a full expanded Ada name of a main subprogram of a program 
  8044.  (partition). 
  8045.  
  8046.  gnatelim options: 
  8047.  
  8048.  -q 
  8049.            Quiet mode: by default gnatelim version information is printed as 
  8050.            Ada comments to the standard output stream. Various debugging 
  8051.            information and information reflecting some details of the analysis 
  8052.            done by gnatelim is output to the standard error stream. 
  8053.  
  8054.  -a 
  8055.            Also look for subprograms from the GNAT runtime that can be 
  8056.            eliminated. 
  8057.  
  8058.  -m 
  8059.            Check if any tree files are missing for an accurate result. 
  8060.  
  8061.  -dx 
  8062.            Activate internal debugging switches.  x is a letter or digit, or 
  8063.            string of letters or digits, which specifies the type of debugging 
  8064.            mode desired.  Normally these are used only for internal development 
  8065.            or system debugging purposes. You can find full documentation for 
  8066.            these switches in the body of the Gnatelim.Options unit in the 
  8067.            compiler source file 'gnatelim-options.adb'. 
  8068.  
  8069.  gnatelim sends its output to the standard output stream, so in order to 
  8070.  produce a proper GNAT configuration file 'gnat.adc', redirection must be used: 
  8071.  
  8072.                       $ gnatelim Main_Prog > gnat.adc
  8073.  
  8074.  or 
  8075.  
  8076.                       $ gnatelim Main_Prog >> gnat.adc
  8077.  
  8078.  In order to append the gnatelim output to the existing contents of 'gnat.adc'. 
  8079.  
  8080.  
  8081. ΓòÉΓòÉΓòÉ 22.6. Correcting the List of Eliminate Pragmas ΓòÉΓòÉΓòÉ
  8082.  
  8083.  
  8084.  In some rare cases it may happen that gnatelim will try to eliminate 
  8085.  subprograms which are actually called in the program. In this case, the 
  8086.  compiler will generate an error message of the form: 
  8087.  
  8088.                       file.adb:106:07: cannot call eliminated subprogram "My_Prog"
  8089.  
  8090.  You will need to manually remove the wrong Eliminate pragmas from the 
  8091.  'gnat.adc' file. It is advised that you recompile your program from scratch 
  8092.  after that because you need a consistent 'gnat.adc' file during the entire 
  8093.  compilation. 
  8094.  
  8095.  
  8096. ΓòÉΓòÉΓòÉ 22.7. Making your Executables smaller ΓòÉΓòÉΓòÉ
  8097.  
  8098.  
  8099.  In order to get a smaller executable for your program you now have to 
  8100.  recompile the program completely with the new 'gnat.adc' file created by 
  8101.  gnatelim in your current directory: 
  8102.  
  8103.                       $ gnatmake -f Main_Prog
  8104.  
  8105.  (you will need -f option for gnatmake to recompile everything with the set of 
  8106.  pragmas Eliminate you have obtained with gnatelim). 
  8107.  
  8108.  Be aware that the set of Eliminate pragmas is specific to each program. It is 
  8109.  not recommended to merge sets of Eliminate pragmas created for different 
  8110.  programs in one 'gnat.adc' file. 
  8111.  
  8112.  
  8113. ΓòÉΓòÉΓòÉ 22.8. Summary of the gnatelim Usage Cycle ΓòÉΓòÉΓòÉ
  8114.  
  8115.  
  8116.  Here is a quick summary of the steps to be taken in order to reduce the size 
  8117.  of your executables with gnatelim. You may use other GNAT options to control 
  8118.  the optimization level, to produce the debugging information, to set search 
  8119.  path, etc. 
  8120.  
  8121.    1. Produce a bind file and a set of tree files 
  8122.  
  8123.                       $ gnatmake -c Main_Prog
  8124.                       $ gnatbind main_prog
  8125.                       $ gnatmake -f -c -gnatc -gnatt Main_Prog
  8126.  
  8127.    2. Generate a list of Eliminate pragmas 
  8128.  
  8129.                       $ gnatelim Main_Prog >[>] gnat.adc
  8130.  
  8131.    3. Recompile the application 
  8132.  
  8133.                       $ gnatmake -f Main_Prog
  8134.  
  8135.  
  8136. ΓòÉΓòÉΓòÉ 23. Other Utility Programs ΓòÉΓòÉΓòÉ
  8137.  
  8138.  
  8139.  This chapter discusses some other utility programs available in the Ada 
  8140.  environment. 
  8141.  
  8142.  Using Other Utility Programs With GNATUsing Other Utility Programs With GNAT 
  8143.  The gnatpsys Utility Program  The gnatpsys Utility Program 
  8144.  The gnatpsta Utility Program  The gnatpsta Utility Program 
  8145.  The External Symbol Naming Scheme of GNATThe External Symbol Naming Scheme of 
  8146.                                GNAT 
  8147.  Ada Mode for emacs            Ada Mode for emacs 
  8148.  Converting Ada files to html using gnathtmlConverting Ada files to html using 
  8149.                                gnathtml 
  8150.  Installing gnathtml           Installing gnathtml 
  8151.  
  8152.  
  8153. ΓòÉΓòÉΓòÉ 23.1. Using Other Utility Programs With GNAT ΓòÉΓòÉΓòÉ
  8154.  
  8155.  
  8156.  The object files generated by GNAT are in standard system format and in 
  8157.  particular the debugging information uses this format. This means programs 
  8158.  generated by GNAT can be used with existing utilities that depend on these 
  8159.  formats. 
  8160.  
  8161.  In general, any utility program that works with C will also often work with 
  8162.  Ada programs generated by GNAT. This includes software utilities such as gprof 
  8163.  (a profiling program), gdb (the FSF debugger), and utilities such as Purify. 
  8164.  
  8165.  
  8166. ΓòÉΓòÉΓòÉ 23.2. The gnatpsys Utility Program ΓòÉΓòÉΓòÉ
  8167.  
  8168.  
  8169.  Many of the definitions in package System are implementation-dependent. 
  8170.  Furthermore, although the source of the package System is available for 
  8171.  inspection, it uses special attributes for parameterizing many of the critical 
  8172.  values, so the source is not informative for the casual user. 
  8173.  
  8174.  The gnatpsys utility is designed to deal with this situation. It is an Ada 
  8175.  program that dynamically determines the values of all the relevant parameters 
  8176.  in System, and prints them out in the form of an Ada source listing for 
  8177.  System, displaying all the values of interest. This output is generated to 
  8178.  'stdout'. 
  8179.  
  8180.  To determine the value of any parameter in package System, simply run gnatpsys 
  8181.  with no qualifiers or arguments, and examine the output. This is preferable to 
  8182.  consulting documentation, because you know that the values you are getting are 
  8183.  the actual ones provided by the executing system. 
  8184.  
  8185.  
  8186. ΓòÉΓòÉΓòÉ 23.3. The gnatpsta Utility Program ΓòÉΓòÉΓòÉ
  8187.  
  8188.  
  8189.  Many of the definitions in package Standard are implementation-dependent. 
  8190.  However, the source of this package does not exist as an Ada source file, so 
  8191.  these values cannot be determined by inspecting the source. They can be 
  8192.  determined by examining in detail the coding of 'cstand.adb' which creates the 
  8193.  image of Standard in the compiler, but this is awkward and requires a great 
  8194.  deal of internal knowledge about the system. 
  8195.  
  8196.  The gnatpsta utility is designed to deal with this situation. It is an Ada 
  8197.  program that dynamically determines the values of all the relevant parameters 
  8198.  in Standard, and prints them out in the form of an Ada source listing for 
  8199.  Standard, displaying all the values of interest. This output is generated to 
  8200.  'stdout'. 
  8201.  
  8202.  To determine the value of any parameter in package Standard, simply run 
  8203.  gnatpsta with no qualifiers or arguments, and examine the output. This is 
  8204.  preferable to consulting documentation, because you know that the values you 
  8205.  are getting are the actual ones provided by the executing system. 
  8206.  
  8207.  
  8208. ΓòÉΓòÉΓòÉ 23.4. The External Symbol Naming Scheme of GNAT ΓòÉΓòÉΓòÉ
  8209.  
  8210.  
  8211.  In order to interpret the output from GNAT, when using tools that are 
  8212.  originally intended for use with other languages, it is useful to understand 
  8213.  the conventions used to generate link names from the Ada entity names. 
  8214.  
  8215.  All link names are in all lowercase letters. With the exception of library 
  8216.  procedure names, the mechanism used is simply to use the full expanded Ada 
  8217.  name with dots replaced by double underscores. For example, suppose we have 
  8218.  the following package spec: 
  8219.  
  8220.                       package QRS is
  8221.                         MN : Integer;
  8222.                       end QRS;
  8223.  
  8224.  The variable MN has a full expanded Ada name of QRS.MN, so the corresponding 
  8225.  link name is qrs__mn. Of course if a pragma Export is used this may be 
  8226.  overridden: 
  8227.  
  8228.                       package Exports is
  8229.                         Var1 : Integer;
  8230.                         pragma Export (Var1, C, External_Name => "var1_name");
  8231.                         Var2 : Integer;
  8232.                         pragma Export (Var2, C, Link_Name => "var2_link_name");
  8233.                       end Exports;
  8234.  
  8235.  In this case, the link name for Var1 is var1_name, and the link name for Var2 
  8236.  is var2_link_name. 
  8237.  
  8238.  One exception occurs for library level procedures. A potential ambiguity 
  8239.  arises between the required name _main for the C main program, and the name we 
  8240.  would otherwise assign to an Ada library level procedure called Main (which 
  8241.  might well not be the main program). 
  8242.  
  8243.  To avoid this ambiguity, we attach the prefix _ada_ to such names. So if we 
  8244.  have a library level procedure such as 
  8245.  
  8246.                       procedure Hello (S : String);
  8247.  
  8248.  the external name of this procedure will be _ada_hello. 
  8249.  
  8250.  
  8251. ΓòÉΓòÉΓòÉ 23.5. Ada Mode for emacs ΓòÉΓòÉΓòÉ
  8252.  
  8253.  
  8254.  The Emacs mode for programming in Ada (both, Ada83 and Ada95) helps the user 
  8255.  in understanding existing code and facilitates writing new code. It 
  8256.  furthermore provides some utility functions for easier integration of standard 
  8257.  Emacs features when programming in Ada. 
  8258.  
  8259.  
  8260. ΓòÉΓòÉΓòÉ 23.6. General features: ΓòÉΓòÉΓòÉ
  8261.  
  8262.      Full Integrated Development Environment : 
  8263.  
  8264.         -  support of 'project files' for the configuration (directories, 
  8265.            compilation options,┬╖┬╖┬╖) 
  8266.  
  8267.         -  compiling and stepping through error messages. 
  8268.  
  8269.         -  running and debugging your applications within Emacs. 
  8270.  
  8271.      easy to use for beginners by pull-down menus, 
  8272.  
  8273.      user configurable by many user-option variables. 
  8274.  
  8275.  
  8276. ΓòÉΓòÉΓòÉ 23.7. Ada mode features that help understanding code: ΓòÉΓòÉΓòÉ
  8277.  
  8278.      functions for easy and quick stepping through Ada code, 
  8279.  
  8280.      getting cross reference information for identifiers (e.g. find the 
  8281.       defining place by a keystroke), 
  8282.  
  8283.      displaying an index menu of types and subprograms and move point to the 
  8284.       chosen one, 
  8285.  
  8286.      automatic color highlighting of the various entities in Ada code. 
  8287.  
  8288.  
  8289. ΓòÉΓòÉΓòÉ 23.8. Emacs support for writing Ada code: ΓòÉΓòÉΓòÉ
  8290.  
  8291.      switching between spec and body files with possible autogeneration of 
  8292.       body files, 
  8293.  
  8294.      automatic formating of subprograms parameter lists. 
  8295.  
  8296.      automatic smart indentation according to Ada syntax, 
  8297.  
  8298.      automatic completion of identifiers, 
  8299.  
  8300.      automatic casing of identifiers, keywords, and attributes, 
  8301.  
  8302.      insertion of statement templates, 
  8303.  
  8304.      filling comment paragraphs like filling normal text, 
  8305.  
  8306.  For more information, please see See Ada Mode for emacs. 
  8307.  
  8308.  
  8309. ΓòÉΓòÉΓòÉ 23.9. Converting Ada files to html using gnathtml ΓòÉΓòÉΓòÉ
  8310.  
  8311.  
  8312.  This Perl script allows Ada source files to be browsed using standard Web 
  8313.  browsers. For installation procedure, see the section See Installing gnathtml. 
  8314.  
  8315.  Ada reserved keywords are highlighted in a bold font and Ada comments in a 
  8316.  blue font. Unless your program was compiled with the gcc -gnatx switch to 
  8317.  suppress the generation of cross-referencing information, user defined 
  8318.  variables and types will appear in a different color; you will be able to 
  8319.  click on any identifier and go to its declaration. 
  8320.  
  8321.  The command line is as follow: 
  8322.  
  8323.                       $ perl gnathtml.pl [switches] ada-files
  8324.  
  8325.  You can pass it as many Ada files as you want. gnathtml will generate an html 
  8326.  file for every ada file, and a global file called 'index.htm'. This file is an 
  8327.  index of every identifier defined in the files. 
  8328.  
  8329.  The available switches are the following ones : 
  8330.  
  8331.  -83 
  8332.            Only the subset on the Ada 83 keywords will be highlighted, not the 
  8333.            full Ada 95 keywords set. 
  8334.  
  8335.  -cc color 
  8336.            This option allows you to change the color used for comments. The 
  8337.            default value is green. The color argument can be any name accepted 
  8338.            by html. 
  8339.  
  8340.  -d 
  8341.            If the ada files depend on some other files (using for instance the 
  8342.            with command, the latter will also be converted to html. Only the 
  8343.            files in the user project will be converted to html, not the files 
  8344.            in the runtime library itself. 
  8345.  
  8346.  -D 
  8347.            This command is the same as -d above, but gnathtml will also look 
  8348.            for files in the runtime library, and generate html files for them. 
  8349.  
  8350.  -f 
  8351.            By default, gnathtml will generate html links only for global 
  8352.            entities ('with'ed units, global variables and types,┬╖┬╖┬╖). If you 
  8353.            specify the -f on the command line, then links will be generated for 
  8354.            local entities too. 
  8355.  
  8356.  -l number 
  8357.            If this switch is provided and number is not 0, then gnathtml will 
  8358.            number the html files every number line. 
  8359.  
  8360.  -I dir 
  8361.            Specify a directory to search for library files ('.ali' files) and 
  8362.            source files. You can provide several -I switches on the command 
  8363.            line, and the directories will be parsed in the order of the command 
  8364.            line. 
  8365.  
  8366.  -o dir 
  8367.            Specify the output directory for html files. By default, gnathtml 
  8368.            will saved the generated html files in a subdirectory named 'html/'. 
  8369.  
  8370.  -p file 
  8371.            If you are using Emacs and the most recent Emacs Ada mode, which 
  8372.            provides a full Integrated Development Environment for compiling, 
  8373.            checking, running and debugging applications, you may be using 
  8374.            '.adp' files to give the directories where Emacs can find sources 
  8375.            and object files. 
  8376.  
  8377.            Using this switch, you can tell gnathtml to use these files. This 
  8378.            allows you to get an html version of your application, even if it is 
  8379.            spread over multiple directories. 
  8380.  
  8381.  -sc color 
  8382.            This option allows you to change the color used for symbol 
  8383.            definitions. The default value is red. The color argument can be any 
  8384.            name accepted by html. 
  8385.  
  8386.  -t file 
  8387.            This switch provides the name of a file. This file contains a list 
  8388.            of file names to be converted, and the effect is exactly as though 
  8389.            they had appeared explicitly on the command line. This is the 
  8390.            recommended way to work around the command line length limit on some 
  8391.            systems. 
  8392.  
  8393.  
  8394. ΓòÉΓòÉΓòÉ 23.10. Installing gnathtml ΓòÉΓòÉΓòÉ
  8395.  
  8396.  
  8397.  Perl needs to be installed on your machine to run this script. Perl is freely 
  8398.  available for almost every architecture and Operating System via the Internet. 
  8399.  
  8400.  On Unix systems, you  may want to modify  the  first line of  the script 
  8401.  gnathtml,  to explicitly  tell  the Operating  system  where Perl is. The 
  8402.  syntax of this line is : 
  8403.  
  8404.                       #!full_path_name_to_perl
  8405.  
  8406.  Alternatively, you may run the script using the following command line: 
  8407.  
  8408.                       $ perl gnathtml.pl [switches] files
  8409.  
  8410.  
  8411. ΓòÉΓòÉΓòÉ 24. Running and Debugging Ada Programs ΓòÉΓòÉΓòÉ
  8412.  
  8413.  
  8414.  This chapter discusses how to debug Ada programs. An incorrect Ada program may 
  8415.  be handled in three ways by the GNAT compiler: 
  8416.  
  8417.    1. The illegality may be a violation of the static semantics of Ada. In that 
  8418.       case GNAT diagnoses the constructs in the program that are illegal. It is 
  8419.       then a straightforward matter for the user to modify those parts of the 
  8420.       program. 
  8421.  
  8422.    2. The illegality may be a violation of the dynamic semantics of Ada. In 
  8423.       that case the program compiles and executes, but may generate incorrect 
  8424.       results, or may terminate abnormally with some exception. 
  8425.  
  8426.    3. When presented with a program that contains convoluted errors, GNAT 
  8427.       itself may terminate abnormally without providing full diagnostics on the 
  8428.       incorrect user program. 
  8429.  
  8430.  The GNAT Debugger GDB         The GNAT Debugger GDB 
  8431.  Running GDB                   Running GDB 
  8432.  Introduction to GDB Commands  Introduction to GDB Commands 
  8433.  Using Ada Expressions         Using Ada Expressions 
  8434.  Calling User-Defined SubprogramsCalling User-Defined Subprograms 
  8435.  Ada Exceptions                Ada Exceptions 
  8436.  Ada Tasks                     Ada Tasks 
  8437.  Debugging Generic Units       Debugging Generic Units 
  8438.  GNAT Abnormal Termination     GNAT Abnormal Termination 
  8439.  Naming Conventions for GNAT Source FilesNaming Conventions for GNAT Source 
  8440.                                Files 
  8441.  Getting Internal Debugging InformationGetting Internal Debugging Information 
  8442.  
  8443.  
  8444. ΓòÉΓòÉΓòÉ 24.1. The GNAT Debugger GDB ΓòÉΓòÉΓòÉ
  8445.  
  8446.  
  8447.  GDB is a general purpose, platform-independent debugger that can be used to 
  8448.  debug mixed-language programs compiled with GCC, and in particular is capable 
  8449.  of debugging Ada programs compiled with GNAT. The latest versions of GDB are 
  8450.  Ada-aware and can handle complex Ada data structures. The manual Debugging 
  8451.  with GDB contains full details on the usage of GDB, including a section on its 
  8452.  usage on programs. This manual should be consulted for full details. The 
  8453.  section that follows is a brief introduction to the philosophy and use of GDB. 
  8454.  
  8455.  When GNAT programs are compiled, the compiler optionally writes debugging 
  8456.  information into the generated object file, including information on line 
  8457.  numbers, and on declared types and variables. This information is separate 
  8458.  from the generated code. It makes the object files considerably larger, but it 
  8459.  does not add to the size of the actual executable that will be loaded into 
  8460.  memory, and has no impact on run-time performance. The generation of debug 
  8461.  information is triggered by the use of the -g switch in the gcc or gnatmake 
  8462.  command used to carry out the compilations. It is important to emphasize that 
  8463.  the use of these options does not change the generated code. 
  8464.  
  8465.  The debugging information is written in standard system formats that are used 
  8466.  by many tools, including debuggers and profilers. The format of the 
  8467.  information is typically designed to describe C types and semantics, but GNAT 
  8468.  implements a translation scheme which allows full details about Ada types and 
  8469.  variables to be encoded into these standard C formats. Details of this 
  8470.  encoding scheme may be found in the file exp_dbug.ads in the GNAT source 
  8471.  distribution. However, the details of this encoding are, in general, of no 
  8472.  interest to a user, since GDB automatically performs the necessary decoding. 
  8473.  
  8474.  When a program is bound and linked, the debugging information is collected 
  8475.  from the object files, and stored in the executable image of the program. 
  8476.  Again, this process significantly increases the size of the generated 
  8477.  executable file, but it does not increase the size of the executable program 
  8478.  itself. Furthermore, if this program is run in the normal manner, it runs 
  8479.  exactly as if the debug information were not present, and takes no more actual 
  8480.  memory. 
  8481.  
  8482.  However, if the program is run under control of GDB, the debugger is 
  8483.  activated. The image of the program is loaded, at which point it is ready to 
  8484.  run. If a run command is given, then the program will run exactly as it would 
  8485.  have if GDB were not present. This is a crucial part of the GDB design 
  8486.  philosophy. GDB is entirely non-intrusive until a breakpoint is encountered. 
  8487.  If no breakpoint is ever hit, the program will run exactly as it would if no 
  8488.  debugger were present. When a breakpoint is hit, GDB accesses the debugging 
  8489.  information and can respond to user commands to inspect variables, and more 
  8490.  generally to report on the state of execution. 
  8491.  
  8492.  
  8493. ΓòÉΓòÉΓòÉ 24.2. Running GDB ΓòÉΓòÉΓòÉ
  8494.  
  8495.  
  8496.  The debugger can be launched directly and simply from emacs which allows to 
  8497.  browse and modify directly the source code during the debugging session, See 
  8498.  Ada Mode for emacs. Here is described the basic use of GDB is text mode. 
  8499.  The command to run GDB is 
  8500.  
  8501.                       $ gdb program
  8502.  
  8503.  where program is the name of the executable file. This activates the debugger 
  8504.  and results in a prompt for debugger commands. The simplest command is simply 
  8505.  run, which causes the program to run exactly as if the debugger were not 
  8506.  present. The following section describes some of the additional commands that 
  8507.  can be given to GDB. 
  8508.  
  8509.  
  8510. ΓòÉΓòÉΓòÉ 24.3. Introduction to GDB Commands ΓòÉΓòÉΓòÉ
  8511.  
  8512.  
  8513.  GDB contains a large repertoire of commands. The manual Debugging with GDB 
  8514.  includes extensive documentation on the use of these commands, together with 
  8515.  examples of their use. Furthermore, the command help invoked from within GDB 
  8516.  activates a simple help facility which summarizes the available commands and 
  8517.  their options. In this section we summarize a few of the most commonly used 
  8518.  commands to give an idea of what GDB is about. You should create a simple 
  8519.  program with debugging information and experiment with the use of these GDB 
  8520.  commands on the program as you read through the following section. 
  8521.  
  8522.  set args arguments 
  8523.            The arguments list above is a list of arguments to be passed to the 
  8524.            program on a subsequent run command, just as though the arguments 
  8525.            had been entered on a normal invocation of the program. The set args 
  8526.            command is not needed if the program does not require arguments. 
  8527.  
  8528.  run 
  8529.            The run command causes execution of the program to start from the 
  8530.            beginning. If the program is already running, that is to say if you 
  8531.            are currently positioned  at a breakpoint, then a prompt will ask 
  8532.            for confirmation that you want to abandon the current execution and 
  8533.            restart. 
  8534.  
  8535.  breakpoint location 
  8536.            The breakpoint command sets a breakpoint, that is to say a point at 
  8537.            which execution will halt and GDB will await further commands. 
  8538.            location is either a line number within a file, given in the format 
  8539.            file:linenumber, or it is the name of a subprogram. If you request 
  8540.            that a breakpoint be set on a subprogram that is overloaded, a 
  8541.            prompt will ask you to specify on which of those subprograms you 
  8542.            want to breakpoint. You can also specify that all of them should be 
  8543.            breakpointed. If the program is run and execution encounters the 
  8544.            breakpoint, then the program stops and GDB signals that the 
  8545.            breakpoint was encountered by printing the line of code before which 
  8546.            the program is halted. 
  8547.  
  8548.  breakpoint exception name 
  8549.            A special form of the breakpoint command which breakpoints whenever 
  8550.            exception name is raised. If name is omitted, then a breakpoint will 
  8551.            occur when any exception is raised. 
  8552.  
  8553.  print expression 
  8554.            This will print the value of the given expression. Most simple Ada 
  8555.            expression formats are properly handled by GDB, so the expression 
  8556.            can contain function calls, variables, operators, and attribute 
  8557.            references. 
  8558.  
  8559.  continue 
  8560.            Continues execution following a breakpoint, until the next 
  8561.            breakpoint or the termination of the program. 
  8562.  
  8563.  step 
  8564.            Executes a single line after a breakpoint. If the next statement is 
  8565.            a subprogram call, execution continues into (the first statement of) 
  8566.            the called subprogram. 
  8567.  
  8568.  next 
  8569.            Executes a single line. If this line is a subprogram call, executes 
  8570.            and returns from the call. 
  8571.  
  8572.  list 
  8573.            Lists a few lines around the current source location. In practice, 
  8574.            it is usually more convenient to have a separate edit window open 
  8575.            with the relevant source file displayed. Successive applications of 
  8576.            this command print subsequent lines. The command can be given an 
  8577.            argument which is a line number, in which case it displays a few 
  8578.            lines around the specified one. 
  8579.  
  8580.  backtrace 
  8581.            Displays a backtrace of the call chain. This command is typically 
  8582.            used after a breakpoint has occurred, to examine the sequence of 
  8583.            calls that leads to the current breakpoint. The display includes one 
  8584.            line for each activation record (frame) corresponding to an active 
  8585.            subprogram. 
  8586.  
  8587.  up 
  8588.            At a breakpoint, GDB can display the values of variables local to 
  8589.            the current frame. The command up can be used to examine the 
  8590.            contents of other active frames, by moving the focus up the stack, 
  8591.            that is to say from callee to caller, one frame at a time. 
  8592.  
  8593.  down 
  8594.            Moves the focus of GDB down from the frame currently being examined 
  8595.            to the frame of its callee (the reverse of the previous command), 
  8596.  
  8597.  frame n 
  8598.            Inspect the frame with the given number. The value 0 denotes the 
  8599.            frame of the current breakpoint, that is to say the top of the call 
  8600.            stack. 
  8601.  
  8602.  The above list is a very short introduction to the commands that GDB provides. 
  8603.  Important additional capabilities, including conditional breakpoints, the 
  8604.  ability to execute command sequences on a breakpoint, the ability to debug at 
  8605.  the machine instruction level and many other features are described in detail 
  8606.  in Debugging with GDB. Note that most commands can be abbreviated (for 
  8607.  example, c for continue, bt for backtrace). 
  8608.  
  8609.  
  8610. ΓòÉΓòÉΓòÉ 24.4. Using Ada Expressions ΓòÉΓòÉΓòÉ
  8611.  
  8612.  
  8613.  GDB supports a fairly large subset of Ada expression syntax, with some 
  8614.  extensions. The philosophy behind the design of this subset is 
  8615.  
  8616.      That GDB should provide basic literals and access to operations for 
  8617.       arithmetic, dereferencing, field selection, indexing, and subprogram 
  8618.       calls, leaving more sophisticated computations to subprograms written 
  8619.       into the program (which therefore may be called from GDB). 
  8620.  
  8621.      That type safety and strict adherence to Ada language restrictions are 
  8622.       not particularly important to the GDB user. 
  8623.  
  8624.      That brevity is important to the GDB user. 
  8625.  
  8626.  Thus, for brevity, the debugger acts as if there were implicit with and use 
  8627.  clauses in effect for all user-written packages, thus making it unnecessary to 
  8628.  fully qualify most names with their packages, regardless of context. Where 
  8629.  this causes ambiguity, GDB asks the user's intent. 
  8630.  
  8631.  For details on the supported Ada syntax Debugging with GDB. 
  8632.  
  8633.  
  8634. ΓòÉΓòÉΓòÉ 24.5. Calling User-Defined Subprograms ΓòÉΓòÉΓòÉ
  8635.  
  8636.  
  8637.  An important capability of GDB is the ability to call user-defined subprograms 
  8638.  while debugging. This is achieved simply by entering a subprogram call 
  8639.  statement in the form: 
  8640.  
  8641.                       call subprogram-name (parameters)
  8642.  
  8643.  The keyword call can be omitted in the normal case where the subprogram-name 
  8644.  does not coincide with any of the predefined GDB commands. 
  8645.  
  8646.  The effect is to invoke the given subprogram, passing it the list of 
  8647.  parameters that is supplied. The parameters can be expressions and can include 
  8648.  variables from the program being debugged. The subprogram must be defined at 
  8649.  the library level within your program, and GDB will call the subprogram within 
  8650.  the environment of your program execution (which means that the subprogram is 
  8651.  free to access or even modify variables within your program). 
  8652.  
  8653.  The most important use of this facility is in allowing the inclusion of 
  8654.  debugging routines that are tailored to particular data structures in your 
  8655.  program. Such debugging routines can be written to provide a suitably 
  8656.  high-level description of an abstract type, rather than a low-level dump of 
  8657.  its physical layout. After all, the standard GDB print command only knows the 
  8658.  physical layout of your types, not their abstract meaning. Debugging routines 
  8659.  can provide information at the desired semantic level and are thus enormously 
  8660.  useful. 
  8661.  
  8662.  For example, when debugging GNAT itself, it is crucial to have access to the 
  8663.  contents of the tree nodes used to represent the program internally. But tree 
  8664.  nodes are represented simply by an integer value (which in turn is an index 
  8665.  into a table of nodes). Using the print command on a tree node would simply 
  8666.  print this integer value, which is not very useful. But the PN routine 
  8667.  (defined in file treepr.adb in the GNAT sources) takes a tree node as input, 
  8668.  and displays a useful high level representation of the tree node, which 
  8669.  includes the syntactic category of the node, its position in the source, the 
  8670.  integers that denote descendant nodes and parent node, as well as varied 
  8671.  semantic information. To study this example in more detail, you might want to 
  8672.  look at the body of the PN procedure in the stated file. 
  8673.  
  8674.  
  8675. ΓòÉΓòÉΓòÉ 24.6. Breaking on Ada Exceptions ΓòÉΓòÉΓòÉ
  8676.  
  8677.  
  8678.  You can set breakpoints that trip when your program raises selected 
  8679.  exceptions. 
  8680.  
  8681.  break exception 
  8682.            Set a breakpoint that trips whenever (any task in the) program 
  8683.            raises any exception. 
  8684.  
  8685.  break exception name 
  8686.            Set a breakpoint that trips whenever (any task in the) program 
  8687.            raises the exception name. 
  8688.  
  8689.  break exception unhandled 
  8690.            Set a breakpoint that trips whenever (any task in the) program 
  8691.            raises an exception for which there is no handler. 
  8692.  
  8693.  info exceptions 
  8694.  
  8695.  info exceptions regexp 
  8696.            The info exceptions command permits the user to examine all defined 
  8697.            exceptions within Ada programs. With a regular expression, regexp, 
  8698.            as argument, prints out only those exceptions whose name matches 
  8699.            regexp. 
  8700.  
  8701.  
  8702. ΓòÉΓòÉΓòÉ 24.7. Ada Tasks ΓòÉΓòÉΓòÉ
  8703.  
  8704.  
  8705.  GDB allows the following task-related commands: 
  8706.  
  8707.  info tasks 
  8708.            This command shows a list of current Ada tasks, as in the following 
  8709.            example: 
  8710.  
  8711.                       (gdb) info tasks
  8712.                        ID    TID P-ID  Thread Pri State         Name
  8713.                         1  8088000  0  807e000  15 Child Activation Wait main_task
  8714.                         2  80a4000  1  80ae000  15 Accept/Select Wait   b
  8715.                         3  809a800  1  80a4800  15 Child Activation Wait a
  8716.                       *  4  80ae800  3  80b8000  15 Running        c
  8717.  
  8718.  In this listing, the asterisk before the first task indicates it to be the 
  8719.  currently running task. The first column lists the task ID that is used to 
  8720.  refer to tasks in the following commands. 
  8721.  
  8722.  break linespec task taskid 
  8723.  
  8724.  break linespec task taskid if ┬╖┬╖┬╖ 
  8725.            These commands are like the break ┬╖┬╖┬╖ thread ┬╖┬╖┬╖. linespec specifies 
  8726.            source lines. 
  8727.  
  8728.            Use the qualifier 'task taskid' with a breakpoint command to specify 
  8729.            that you only want GDB to stop the program when a particular Ada 
  8730.            task reaches this breakpoint. taskid is one of the numeric task 
  8731.            identifiers assigned by GDB, shown in the first column of the 'info 
  8732.            tasks' display. 
  8733.  
  8734.            If you do not specify 'task taskid' when you set a breakpoint, the 
  8735.            breakpoint applies to all tasks of your program. 
  8736.  
  8737.            You can use the task qualifier on conditional breakpoints as well; 
  8738.            in this case, place 'task taskid' before the breakpoint condition 
  8739.            (before the if). 
  8740.  
  8741.  task taskno 
  8742.            This command allows to switch to the task referred by taskno. In 
  8743.            particular, This allows to browse the backtrace of the specified 
  8744.            task. It is advised to switch back to the original task before 
  8745.            continuing execution otherwise the scheduling of the program may be 
  8746.            perturbated. 
  8747.  
  8748.  For more detailed information on the tasking support Debugging with GDB. 
  8749.  
  8750.  
  8751. ΓòÉΓòÉΓòÉ 24.8. Debugging Generic Units ΓòÉΓòÉΓòÉ
  8752.  
  8753.  
  8754.  GNAT always uses code expansion for generic instantiation. This means that 
  8755.  each time an instantiation occurs, a complete copy of the original code is 
  8756.  made, with appropriate substitutions of formals by actuals. 
  8757.  
  8758.  It is not possible to refer to the original generic entities in GDB, but it is 
  8759.  always possible to debug a particular instance of a generic, by using the 
  8760.  appropriate expanded names. For example, if we have 
  8761.  
  8762.                       procedure g is
  8763.                         generic package k is
  8764.                          procedure kp (v1 : in out integer);
  8765.                         end k;
  8766.                         package body k is
  8767.                          procedure kp (v1 : in out integer) is
  8768.                          begin
  8769.                            v1 := v1 + 1;
  8770.                          end kp;
  8771.                         end k;
  8772.                         package k1 is new k;
  8773.                         package k2 is new k;
  8774.                         var : integer := 1;
  8775.                       begin
  8776.                         k1.kp (var);
  8777.                         k2.kp (var);
  8778.                         k1.kp (var);
  8779.                         k2.kp (var);
  8780.                       end;
  8781.  
  8782.  Then to break on a call to procedure kp in the k2 instance, simply use the 
  8783.  command: 
  8784.  
  8785.                       (gdb) break g.k2.kp
  8786.  
  8787.  When the breakpoint occurs, you can step through the code of the instance in 
  8788.  the normal manner and examine the values of local variables, as for other 
  8789.  units. 
  8790.  
  8791.  
  8792. ΓòÉΓòÉΓòÉ 24.9. GNAT Abnormal Termination ΓòÉΓòÉΓòÉ
  8793.  
  8794.  
  8795.  When presented with programs that contain serious errors in syntax or 
  8796.  semantics, GNAT may on rare occasions  experience problems in operation, such 
  8797.  as aborting with a segmentation fault or illegal memory access, raising an 
  8798.  internal exception, or terminating abnormally. In such cases, you can activate 
  8799.  various features of GNAT that can help you pinpoint the construct in your 
  8800.  program that is the likely source of the problem. 
  8801.  
  8802.  The following strategies are presented in increasing order of difficulty, 
  8803.  corresponding to your programming skills and your familiarity with compiler 
  8804.  internals. 
  8805.  
  8806.    1. Run gcc with the -gnatf and -gnate switches. The first switch causes all 
  8807.       errors on a given line to be reported. In its absence, only the first 
  8808.       error on a line is displayed. 
  8809.  
  8810.       The -gnate switch causes errors to be displayed as soon as they are 
  8811.       encountered, rather than after compilation is terminated. If GNAT 
  8812.       terminates prematurely, the last error message displayed is likely to 
  8813.       pinpoint the culprit. 
  8814.  
  8815.    2. Run gcc with the -v (verbose) switch. In this mode, gcc produces ongoing 
  8816.       information about the progress of the compilation and provides the name 
  8817.       of each procedure as code is generated. This switch allows you to find 
  8818.       which Ada procedure was being compiled when it encountered a code 
  8819.       generation problem. 
  8820.  
  8821.    3. Run gcc with the -gnatdc switch. This is a GNAT specific switch that does 
  8822.       for the front-end what -v does for the back end. The system prints the 
  8823.       name of each unit, either a compilation unit or nested unit, as it is 
  8824.       being analyzed. 
  8825.  
  8826.    4. Finally, you can start gdb directly on the gnat1 executable. gnat1 is the 
  8827.       front-end of GNAT, and can be run independently (normally it is just 
  8828.       called from gcc). You can use gdb on gnat1 as you would on a C program 
  8829.       (but see The GNAT Debugger GDB for caveats). The where command is the 
  8830.       first line of attack; the variable lineno (seen by print lineno), used by 
  8831.       the second phase of gnat1 and by the gcc backend, indicates the source 
  8832.       line at which the execution stopped, and input_file name indicates the 
  8833.       name of the source file. 
  8834.  
  8835.  
  8836. ΓòÉΓòÉΓòÉ 24.10. Naming Conventions for GNAT Source Files ΓòÉΓòÉΓòÉ
  8837.  
  8838.  
  8839.  In order to examine the workings of the GNAT system, the following brief 
  8840.  description of its organization may be helpful: 
  8841.  
  8842.      Files with prefix 'sc' contain the lexical scanner. 
  8843.  
  8844.      All files prefixed with 'par' are components of the parser. The numbers 
  8845.       correspond to chapters of the Ada 95 Reference Manual. For example, 
  8846.       parsing of select statements can be found in 'par-ch9.adb'. 
  8847.  
  8848.      All files prefixed with 'sem' perform semantic analysis. The numbers 
  8849.       correspond to chapters of the Ada standard. For example, all issues 
  8850.       involving context clauses can be found in 'sem_ch10.adb'. In addition, 
  8851.       some features of the language require sufficient special processing to 
  8852.       justify their own semantic files: sem_aggr for aggregates, sem_disp for 
  8853.       dynamic dispatching, etc. 
  8854.  
  8855.      All files prefixed with 'exp' perform normalization and expansion of the 
  8856.       intermediate representation (abstract syntax tree, or AST). these files 
  8857.       use the same numbering scheme as the parser and semantics files. For 
  8858.       example, the construction of record initialization procedures is done in 
  8859.       'exp_ch3.adb'. 
  8860.  
  8861.      The files prefixed with 'bind' implement the binder, which verifies the 
  8862.       consistency of the compilation, determines an order of elaboration, and 
  8863.       generates the bind file. 
  8864.  
  8865.      The files 'atree.ads' and 'atree.adb' detail the low-level data 
  8866.       structures used by the front-end. 
  8867.  
  8868.      The files 'sinfo.ads' and 'sinfo.adb' detail the structure of the 
  8869.       abstract syntax tree as produced by the parser. 
  8870.  
  8871.      The files 'einfo.ads' and 'einfo.adb' detail the attributes of all 
  8872.       entities, computed during semantic analysis. 
  8873.  
  8874.      Library management issues are dealt with in files with prefix 'lib'. 
  8875.  
  8876.      Ada files with the prefix 'a-' are children of Ada, as defined in Annex 
  8877.       A. 
  8878.  
  8879.      Files with prefix 'i-' are children of Interfaces, as defined in Annex B. 
  8880.  
  8881.      Files with prefix 's-' are children of System. This includes both 
  8882.       language-defined children and GNAT run-time routines. 
  8883.  
  8884.      Files with prefix 'g-' are children of GNAT. These are useful 
  8885.       general-purpose packages, fully documented in their specifications. All 
  8886.       the other '.c' files are modifications of common gcc files. 
  8887.  
  8888.  
  8889. ΓòÉΓòÉΓòÉ 24.11. Getting Internal Debugging Information ΓòÉΓòÉΓòÉ
  8890.  
  8891.  
  8892.  Most compilers have internal debugging switches and modes. GNAT does also, 
  8893.  except GNAT internal debugging switches and modes are not secret. A summary 
  8894.  and full description of all the compiler and binder debug flags are in the 
  8895.  file 'debug.adb'. You must obtain the sources of the compiler to see the full 
  8896.  detailed effects of these flags. 
  8897.  
  8898.  The switches that print the source of the program (reconstructed from the 
  8899.  internal tree) are of general interest for user programs, as are the options 
  8900.  to print the full internal tree, and the entity table (the symbol table 
  8901.  information). The reconstructed source provides a readable version of the 
  8902.  program after the front-end has completed analysis and  expansion, and is 
  8903.  useful when studying the performance of specific constructs. For example, 
  8904.  constraint checks are indicated, complex aggregates are replaced with loops 
  8905.  and assignments, and tasking primitives are replaced with run-time calls. 
  8906.  
  8907.  
  8908. ΓòÉΓòÉΓòÉ 25. Performance Considerations ΓòÉΓòÉΓòÉ
  8909.  
  8910.  
  8911.  The GNAT system provides a number of options that allow a trade-off between 
  8912.  
  8913.      performance of the generated code 
  8914.  
  8915.      speed of compilation 
  8916.  
  8917.      minimization of dependences and recompilation 
  8918.  
  8919.      the degree of run-time checking. 
  8920.  
  8921.  The defaults (if no options are selected) aim at improving the speed of 
  8922.  compilation and minimizing dependences, at the expense of performance of the 
  8923.  generated code: 
  8924.  
  8925.      no optimization 
  8926.  
  8927.      no inlining of subprogram calls 
  8928.  
  8929.      all run-time checks enabled except overflow and elaboration checks 
  8930.  
  8931.  These options are suitable for most program development purposes. This chapter 
  8932.  describes how you can modify these choices. 
  8933.  
  8934.  Controlling Run-time Checks   Controlling Run-time Checks 
  8935.  Optimization Levels           Optimization Levels 
  8936.  Inlining of Subprograms       Inlining of Subprograms 
  8937.  
  8938.  
  8939. ΓòÉΓòÉΓòÉ 25.1. Controlling Run-time Checks ΓòÉΓòÉΓòÉ
  8940.  
  8941.  
  8942.  By default, GNAT produces all run-time checks, except arithmetic overflow 
  8943.  checking for integer operations (that includes division by zero) and checks 
  8944.  for access before elaboration on subprogram calls. Two gnat switches, -gnatp 
  8945.  and -gnato allow this default to be modified. See Run-time Checks. 
  8946.  
  8947.  Our experience is that the default is suitable for most development purposes. 
  8948.  
  8949.  We treat integer overflow specially because these are quite expensive and in 
  8950.  our experience are not as important as other run-time checks in the 
  8951.  development process. 
  8952.  
  8953.  Elaboration checks are off by default, and also not needed by default, since 
  8954.  GNAT uses a static elaboration analysis approach that avoids the need for 
  8955.  run-time checking. This manual contains a full chapter discussing the issue of 
  8956.  elaboration checks, and if the default is not satisfactory for your use, you 
  8957.  should read this chapter. 
  8958.  
  8959.  Note that the setting of the switches controls the default setting of the 
  8960.  checks. They may be modified using either pragma Suppress (to remove checks) 
  8961.  or pragma Unsuppress (to add back suppressed checks) in the program source. 
  8962.  
  8963.  
  8964. ΓòÉΓòÉΓòÉ 25.2. Optimization Levels ΓòÉΓòÉΓòÉ
  8965.  
  8966.  
  8967.  The default is optimization off. This results in the fastest compile times, 
  8968.  but GNAT makes absolutely no attempt to optimize, and the generated programs 
  8969.  are considerably larger and slower than when optimization is enabled. You can 
  8970.  use the -On switch, where n is an integer from 0 to 3, on the gcc command line 
  8971.  to control the optimization level: 
  8972.  
  8973.  -O0 
  8974.            no optimization (the default) 
  8975.  
  8976.  -O1 
  8977.            medium level optimization 
  8978.  
  8979.  -O2 
  8980.            full optimization 
  8981.  
  8982.  -O3 
  8983.            full optimization, and also attempt automatic inlining of small 
  8984.            subprograms within a unit (see Inlining of Subprograms). 
  8985.  
  8986.  Higher optimization levels perform more global transformations on the program 
  8987.  and apply more expensive analysis algorithms in order to generate faster and 
  8988.  more compact code. The price in compilation time, and the resulting 
  8989.  improvement in execution time, both depend on the particular application and 
  8990.  the hardware environment. You should experiment to find the best level for 
  8991.  your application. 
  8992.  
  8993.  Note: Unlike some other compilation systems, gcc has been tested extensively 
  8994.  at all optimization levels. There are some bugs which appear only with 
  8995.  optimization turned on, but there have also been bugs which show up only in 
  8996.  unoptimized code. Selecting a lower level of optimization does not improve the 
  8997.  reliability of the code generator, which in practice is highly reliable at all 
  8998.  optimization levels. 
  8999.  
  9000.  
  9001. ΓòÉΓòÉΓòÉ 25.3. Inlining of Subprograms ΓòÉΓòÉΓòÉ
  9002.  
  9003.  
  9004.  A call to a subprogram in the current unit is inlined if all the following 
  9005.  conditions are met: 
  9006.  
  9007.      The optimization level is at least -O1. 
  9008.  
  9009.      The called subprogram is suitable for inlining: It must be small enough 
  9010.       and not contain nested subprograms or anything else that gcc cannot 
  9011.       support in inlined subprograms. 
  9012.  
  9013.      The call occurs after the definition of the body of the subprogram. 
  9014.  
  9015.      Either pragma Inline applies to the subprogram or it is small and 
  9016.       automatic inlining (optimization level -O3) is specified. 
  9017.  
  9018.  Calls to subprograms in with'ed units are normally not inlined. To achieve 
  9019.  this level of inlining, the following conditions must all be true: 
  9020.  
  9021.      The optimization level is at least -O1. 
  9022.  
  9023.      The called subprogram is suitable for inlining: It must be small enough 
  9024.       and not contain nested subprograms or anything else gcc cannot support in 
  9025.       inlined subprograms. 
  9026.  
  9027.      The call appears in a body (not in a package spec). 
  9028.  
  9029.      There is a pragma Inline for the subprogram. 
  9030.  
  9031.      The -gnatn switch is used in the gcc command line 
  9032.  
  9033.  Note that specifying the -gnatn switch causes additional compilation 
  9034.  dependencies. Consider the following: 
  9035.  
  9036.                       package R is
  9037.                         procedure Q;
  9038.                         pragma Inline (Q);
  9039.                       end R;
  9040.                       package body R is
  9041.                         ┬╖┬╖┬╖
  9042.                       end R;
  9043.                       with R;
  9044.                       procedure Main is
  9045.                       begin
  9046.                         ┬╖┬╖┬╖
  9047.                         R.Q;
  9048.                       end Main;
  9049.  
  9050.  With the default behavior (no -gnatn switch specified), the compilation of the 
  9051.  Main procedure depends only on its own source, 'main.adb', and the spec of the 
  9052.  package in file 'r.ads'. This means that editing the body of R does not 
  9053.  require recompiling Main. 
  9054.  
  9055.  On the other hand, the call R.Q is not inlined under these circumstances. If 
  9056.  the -gnatn switch is present when Main is compiled, the call will be inlined 
  9057.  if the body of Q is small enough, but now Main depends on the body of R in 
  9058.  'r.adb' as well as on the spec. This means that if this body is edited, the 
  9059.  main program must be recompiled. Note that this extra dependency occurs 
  9060.  whether or not the call is in fact inlined by gcc. 
  9061.  
  9062.  Note: The -fno-inline switch can be used to prevent all inlining. This switch 
  9063.  overrides all other conditions and ensures that no inlining occurs. The extra 
  9064.  dependences resulting from -gnatn will still be active, even if this switch is 
  9065.  used to suppress the resulting inlining actions. 
  9066.  
  9067.  
  9068. ΓòÉΓòÉΓòÉ 26. Index ΓòÉΓòÉΓòÉ
  9069.  
  9070.  'gnat.adc'                                        Using Other File Names 
  9071.                                                    The Configuration Pragmas 
  9072.                                                    file 
  9073.  --GCC=compiler_name (gnatlink)                    Switches for gnatlink 
  9074.  --GCC=compiler_name (gnatmake)                    Switches for gnatmake 
  9075.  --GNATBIND=binder_name (gnatmake)                 Switches for gnatmake 
  9076.  --GNATLINK=linker_name (gnatmake)                 Switches for gnatmake 
  9077.  --LINK= (gnatlink)                                Switches for gnatlink 
  9078.  -83 (gnathtml)                                    Converting Ada files to html 
  9079.                                                    using gnathtml 
  9080.  -A (gnatbind)                                     Output Control 
  9081.  -A (gnatlink)                                     Switches for gnatlink 
  9082.  -a (gnatls)                                       Switches for gnatls 
  9083.  -a (gnatmake)                                     Switches for gnatmake 
  9084.                                                    Switches for gnatmake 
  9085.  -aI (gnatmake)                                    Switches for gnatmake 
  9086.  -aL (gnatmake)                                    Switches for gnatmake 
  9087.  -aO (gnatmake)                                    Switches for gnatmake 
  9088.  -b (gcc)                                          Switches for gcc 
  9089.                                                    Switches for gcc 
  9090.  -b (gnatbind)                                     Binder Error Message Control 
  9091.  -b (gnatlink)                                     Switches for gnatlink 
  9092.                                                    Switches for gnatlink 
  9093.  -bargs (gnatmake)                                 Mode switches for gnatmake 
  9094.  -c (gcc)                                          Switches for gcc 
  9095.  -C (gnatbind)                                     Output Control 
  9096.                                                    Output Control 
  9097.  -c (gnatchop)                                     Switches for gnatchop 
  9098.  -C (gnatlink)                                     Switches for gnatlink 
  9099.  -c (gnatmake)                                     Switches for gnatmake 
  9100.  -cargs (gnatmake)                                 Mode switches for gnatmake 
  9101.  -d (gnathtml)                                     Converting Ada files to html 
  9102.                                                    using gnathtml 
  9103.  -d (gnatls)                                       Switches for gnatls 
  9104.  -e (gnatbind)                                     Output Control 
  9105.  -f (gnatbind)                                     Elaboration Control 
  9106.  -f (gnathtml)                                     Converting Ada files to html 
  9107.                                                    using gnathtml 
  9108.  -f (gnatmake)                                     Switches for gnatmake 
  9109.  -fno-inline (gcc)                                 Inlining of Subprograms 
  9110.  -fstack-check                                     Stack Overflow Checking 
  9111.  -g (gcc)                                          Switches for gcc 
  9112.  -g (gnatlink)                                     Switches for gnatlink 
  9113.  -gnat83 (gcc)                                     Compiling Ada 83 Programs 
  9114.  -gnat95 (gcc)                                     Compiling Ada 83 Programs 
  9115.  -gnata (gcc)                                      Debugging and Assertion 
  9116.                                                    Control 
  9117.  -gnatb (gcc)                                      Output and Error Message 
  9118.                                                    Control 
  9119.  -gnatc (gcc)                                      Using gcc for Semantic 
  9120.                                                    Checking 
  9121.  -gnatD (gcc)                                      Debugging Control 
  9122.  -gnatdc switch                                    GNAT Abnormal Termination 
  9123.  -gnate (gcc)                                      Output and Error Message 
  9124.                                                    Control 
  9125.                                                    Run-time Checks 
  9126.  -gnatf (gcc)                                      Output and Error Message 
  9127.                                                    Control 
  9128.  -gnatg (gcc)                                      Reference Manual Style 
  9129.                                                    Checking 
  9130.                                                    Debugging Control 
  9131.  -gnati (gcc)                                      Character Set Control 
  9132.  -gnatk (gcc)                                      File Naming Control 
  9133.  -gnatl (gcc)                                      Output and Error Message 
  9134.                                                    Control 
  9135.  -gnatm (gcc)                                      Output and Error Message 
  9136.                                                    Control 
  9137.  -gnatn (gcc)                                      Subprogram Inlining Control 
  9138.                                                    Inlining of Subprograms 
  9139.  -gnatn switch                                     Source Dependencies 
  9140.  -gnato (gcc)                                      Run-time Checks 
  9141.                                                    Controlling Run-time Checks 
  9142.  -gnatp (gcc)                                      Run-time Checks 
  9143.                                                    Controlling Run-time Checks 
  9144.  -gnatq (gcc)                                      Output and Error Message 
  9145.                                                    Control 
  9146.  -gnatR (gcc)                                      Output and Error Message 
  9147.                                                    Control 
  9148.                                                    Reference Manual Style 
  9149.                                                    Checking 
  9150.  -gnats (gcc)                                      Using gcc for Syntax 
  9151.                                                    Checking 
  9152.  -gnatT (gcc)                                      Run-time Control 
  9153.                                                    Auxiliary Output Control 
  9154.  -gnatU (gcc)                                      Output and Error Message 
  9155.                                                    Control 
  9156.                                                    Auxiliary Output Control 
  9157.  -gnatv (gcc)                                      Output and Error Message 
  9158.                                                    Control 
  9159.  -gnatW (gcc)                                      Character Set Control 
  9160.  -gnatwa (gcc)                                     Output and Error Message 
  9161.                                                    Control 
  9162.                                                    Output and Error Message 
  9163.                                                    Control 
  9164.  -gnatwc (gcc)                                     Output and Error Message 
  9165.                                                    Control 
  9166.                                                    Output and Error Message 
  9167.                                                    Control 
  9168.  -gnatwe (gcc)                                     Output and Error Message 
  9169.                                                    Control 
  9170.  -gnatwl (gcc)                                     Output and Error Message 
  9171.                                                    Control 
  9172.                                                    Output and Error Message 
  9173.                                                    Control 
  9174.  -gnatws (gcc)                                     Output and Error Message 
  9175.                                                    Control 
  9176.  -gnatwu (gcc)                                     Output and Error Message 
  9177.                                                    Control 
  9178.                                                    Output and Error Message 
  9179.                                                    Control 
  9180.  -gnatx (gcc)                                      Output and Error Message 
  9181.                                                    Control 
  9182.  -h (gnatbind)                                     Elaboration Control 
  9183.                                                    Output Control 
  9184.  -h (gnatls)                                       Switches for gnatls 
  9185.  -I (gcc)                                          Switches for gcc 
  9186.  -I (gnathtml)                                     Converting Ada files to html 
  9187.                                                    using gnathtml 
  9188.  -i (gnatmake)                                     Switches for gnatmake 
  9189.                                                    Switches for gnatmake 
  9190.  -i (gnatmem)                                      Switches for gnatmem 
  9191.  -I- (gcc)                                         Switches for gcc 
  9192.  -I- (gnatmake)                                    Switches for gnatmake 
  9193.  -j (gnatmake)                                     Switches for gnatmake 
  9194.  -k (gnatchop)                                     Switches for gnatchop 
  9195.  -k (gnatmake)                                     Switches for gnatmake 
  9196.  -l (gnatbind)                                     Output Control 
  9197.  -l (gnathtml)                                     Converting Ada files to html 
  9198.                                                    using gnathtml 
  9199.  -L (gnatmake)                                     Switches for gnatmake 
  9200.  -largs (gnatmake)                                 Mode switches for gnatmake 
  9201.  -m (gnatbind)                                     Binder Error Message Control 
  9202.                                                    Binder Error Message Control 
  9203.  -m (gnatmake)                                     Switches for gnatmake 
  9204.                                                    Switches for gnatmake 
  9205.  -n (gnatbind)                                     Binding with Non-Ada Main 
  9206.                                                    Programs 
  9207.  -n (gnatlink)                                     Switches for gnatlink 
  9208.  -n (gnatmake)                                     Switches for gnatmake 
  9209.  -nostdinc (gnatmake)                              Switches for gnatmake 
  9210.  -nostdlib (gnatmake)                              Switches for gnatmake 
  9211.  -o (gcc)                                          Switches for gcc 
  9212.                                                    Switches for gcc 
  9213.                                                    Optimization Levels 
  9214.  -O (gnatbind)                                     Output Control 
  9215.                                                    Output Control 
  9216.  -o (gnathtml)                                     Converting Ada files to html 
  9217.                                                    using gnathtml 
  9218.  -o (gnatlink)                                     Switches for gnatlink 
  9219.  -o (gnatls)                                       Switches for gnatls 
  9220.  -o (gnatmake)                                     Switches for gnatmake 
  9221.  -o (gnatmem)                                      Switches for gnatmem 
  9222.  -p (gnathtml)                                     Converting Ada files to html 
  9223.                                                    using gnathtml 
  9224.  -q (gnatchop)                                     Switches for gnatchop 
  9225.  -q (gnatmake)                                     Switches for gnatmake 
  9226.  -q (gnatmem)                                      Switches for gnatmem 
  9227.  -r (gnatchop)                                     Switches for gnatchop 
  9228.  -S (gcc)                                          Switches for gcc 
  9229.  -s (gnatbind)                                     Consistency-Checking Modes 
  9230.  -s (gnatls)                                       Switches for gnatls 
  9231.                                                    Switches for gnatls 
  9232.  -s (gnatmake)                                     Switches for gnatmake 
  9233.  -sc (gnathtml)                                    Converting Ada files to html 
  9234.                                                    using gnathtml 
  9235.  -t (gnatbind)                                     Binder Error Message Control 
  9236.  -t (gnathtml)                                     Converting Ada files to html 
  9237.                                                    using gnathtml 
  9238.  -u (gnatls)                                       Switches for gnatls 
  9239.  -v (gcc)                                          Switches for gcc 
  9240.                                                    Switches for gcc 
  9241.  -v (gnatbind)                                     Binder Error Message Control 
  9242.  -v (gnatchop)                                     Switches for gnatchop 
  9243.  -v (gnatlink)                                     Switches for gnatlink 
  9244.  -v (gnatmake)                                     Switches for gnatmake 
  9245.  -v -v (gnatlink)                                  Switches for gnatlink 
  9246.  -w (gnatchop)                                     Switches for gnatchop 
  9247.  -we (gnatbind)                                    Binder Error Message Control 
  9248.  -ws (gnatbind)                                    Binder Error Message Control 
  9249.  -x (gnatbind)                                     Consistency-Checking Modes 
  9250.  -z (gnatbind)                                     Binding Programs with no 
  9251.                                                    Main Subprogram 
  9252.  -z (gnatmake)                                     Switches for gnatmake 
  9253.  Access before elaboration                         Run-time Checks 
  9254.  Access-to-subprogram                              Elaboration for 
  9255.                                                    Access-to-Subprogram Values 
  9256.  ACVC, Ada 83 tests                                Compiling Ada 83 Programs 
  9257.  Ada 83 compatibility                              Compiling Ada 83 Programs 
  9258.  Ada 95 Language Reference Manual                  What You Should Know Before 
  9259.                                                    Reading This Guide 
  9260.  Ada expressions                                   Using Ada Expressions 
  9261.  Annex A                                           Naming Conventions for GNAT 
  9262.                                                    Source Files 
  9263.  Annex B                                           Naming Conventions for GNAT 
  9264.                                                    Source Files 
  9265.  Assertions                                        Debugging and Assertion 
  9266.                                                    Control 
  9267.  Binder consistency checks                         Binder Error Message Control 
  9268.  Binder output file                                Interfacing to C 
  9269.  Binder, multiple input files                      Binding with Non-Ada Main 
  9270.                                                    Programs 
  9271.  Breakpoints and tasks                             Ada Tasks 
  9272.  Calling Conventions                               Calling Conventions 
  9273.  Check, elaboration                                Run-time Checks 
  9274.  Check, overflow                                   Run-time Checks 
  9275.  Checks, access before elaboration                 Run-time Checks 
  9276.  Checks, division by zero                          Run-time Checks 
  9277.  Checks, elaboration                               Checking the Elaboration 
  9278.                                                    Order in Ada 95 
  9279.  Checks, overflow                                  Controlling Run-time Checks 
  9280.  Checks, suppressing                               Run-time Checks 
  9281.  code page 437                                     Other 8-Bit Codes 
  9282.  code page 850                                     Other 8-Bit Codes 
  9283.  Combining GNAT switches                           Switches for gcc 
  9284.  Compilation model                                 The GNAT Compilation Model 
  9285.  Configuration pragmas                             Configuration Pragmas 
  9286.  Consistency checks, in binder                     Binder Error Message Control 
  9287.  Convention Ada                                    Calling Conventions 
  9288.  Convention Asm                                    Calling Conventions 
  9289.  Convention Assembler                              Calling Conventions 
  9290.  Convention C                                      Calling Conventions 
  9291.  Convention C++                                    Calling Conventions 
  9292.  Convention COBOL                                  Calling Conventions 
  9293.  Convention Fortran                                Calling Conventions 
  9294.  Convention Stdcall                                Calling Conventions 
  9295.  Convention Stubbed                                Calling Conventions 
  9296.  Conventions                                       Conventions 
  9297.  Debugger                                          Running and Debugging Ada 
  9298.                                                    Programs 
  9299.  Debugging                                         Running and Debugging Ada 
  9300.                                                    Programs 
  9301.  Debugging Generic Units                           Debugging Generic Units 
  9302.  Debugging information, including                  Switches for gnatlink 
  9303.  Debugging options                                 Debugging Control 
  9304.  Dependencies, producing list                      Switches for gnatmake 
  9305.  Dependency rules                                  The GNAT Make Program 
  9306.                                                    gnatmake 
  9307.  Division by zero                                  Run-time Checks 
  9308.  Elaboration checks                                Run-time Checks 
  9309.                                                    Checking the Elaboration 
  9310.                                                    Order in Ada 95 
  9311.  Elaboration control                               Elaboration Order Handling 
  9312.                                                    in GNAT 
  9313.                                                    Summary of Procedures for 
  9314.                                                    Elaboration Control 
  9315.  Elaboration order control                         Comparison between GNAT and 
  9316.                                                    C/C++ Compilation Models 
  9317.  End of source file                                Source Representation 
  9318.  Error messages, suppressing                       Output and Error Message 
  9319.                                                    Control 
  9320.  EUC Coding                                        Wide Character Encodings 
  9321.  Exceptions                                        Breaking on Ada Exceptions 
  9322.  File names                                        Using Other File Names 
  9323.  Foreign Languages                                 Calling Conventions 
  9324.  Generic formal parameters                         Compiling Ada 83 Programs 
  9325.  Generics                                          Generating Object Files 
  9326.                                                    Debugging Generic Units 
  9327.  GNAT Abnormal Termination                         GNAT Abnormal Termination 
  9328.  GNAT compilation model                            The GNAT Compilation Model 
  9329.  GNAT library                                      Comparison between GNAT and 
  9330.                                                    Conventional Ada Library 
  9331.                                                    Models 
  9332.  GNAT_STACK_LIMIT                                  Stack Overflow Checking 
  9333.  GNU make                                          Using gnatmake in a Makefile 
  9334.  Inlining                                          Comparison between GNAT and 
  9335.                                                    Conventional Ada Library 
  9336.                                                    Models 
  9337.  Interfacing to Ada                                Calling Conventions 
  9338.  Interfacing to Assembler                          Calling Conventions 
  9339.  Interfacing to C                                  Calling Conventions 
  9340.  Interfacing to C++                                Calling Conventions 
  9341.  Interfacing to COBOL                              Calling Conventions 
  9342.  Interfacing to Fortran                            Calling Conventions 
  9343.  Internal trees, writing to file                   Auxiliary Output Control 
  9344.  Latin-1                                           Source Representation 
  9345.                                                    Latin-1 
  9346.  Latin-2                                           Other 8-Bit Codes 
  9347.  Latin-3                                           Other 8-Bit Codes 
  9348.  Latin-4                                           Other 8-Bit Codes 
  9349.  Library browser                                   The GNAT library browser 
  9350.                                                    gnatls 
  9351.  Library, building, installing                     GNAT and libraries 
  9352.  Linker libraries                                  Switches for gnatmake 
  9353.  Mixed Language Programming                        Mixed Language Programming 
  9354.  Multiple units, syntax checking                   Using gcc for Syntax 
  9355.                                                    Checking 
  9356.  n (gnatmem)                                       Switches for gnatmem 
  9357.  No code generated                                 Compiling Programs 
  9358.  Order of elaboration                              Elaboration Order Handling 
  9359.                                                    in GNAT 
  9360.  Other Ada compilers                               Calling Conventions 
  9361.  Overflow checks                                   Run-time Checks 
  9362.                                                    Controlling Run-time Checks 
  9363.  Parallel make                                     Switches for gnatmake 
  9364.  Performance                                       Performance Considerations 
  9365.  pragma Elaborate                                  The Ada Library Information 
  9366.                                                    Files 
  9367.                                                    Controlling the Elaboration 
  9368.                                                    Order in Ada 95 
  9369.  pragma Elaborate_All                              The Ada Library Information 
  9370.                                                    Files 
  9371.                                                    Controlling the Elaboration 
  9372.                                                    Order in Ada 95 
  9373.  pragma Elaborate_Body                             The Ada Library Information 
  9374.                                                    Files 
  9375.                                                    Controlling the Elaboration 
  9376.                                                    Order in Ada 95 
  9377.  pragma Inline                                     Inlining of Subprograms 
  9378.  pragma Preelaborate                               The Ada Library Information 
  9379.                                                    Files 
  9380.                                                    Controlling the Elaboration 
  9381.                                                    Order in Ada 95 
  9382.  pragma Pure                                       The Ada Library Information 
  9383.                                                    Files 
  9384.                                                    Controlling the Elaboration 
  9385.                                                    Order in Ada 95 
  9386.  pragma Remote_Call_Interface                      The Ada Library Information 
  9387.                                                    Files 
  9388.  pragma Remote_Types                               The Ada Library Information 
  9389.                                                    Files 
  9390.  pragma Shared_Passive                             The Ada Library Information 
  9391.                                                    Files 
  9392.  pragma Suppress                                   Controlling Run-time Checks 
  9393.  pragma Unsuppress                                 Controlling Run-time Checks 
  9394.  Pragmas, configuration                            Configuration Pragmas 
  9395.  Recompilation, by gnatmake                        Notes on the Command Line 
  9396.  RTL                                               Switches for gcc 
  9397.                                                    Switches for gcc 
  9398.  Search paths, for gnatmake                        Switches for gnatmake 
  9399.  Shift JIS Coding                                  Wide Character Encodings 
  9400.  Source file, end                                  Source Representation 
  9401.  Source files, suppressing search                  Switches for gnatmake 
  9402.  Source files, use by binder                       Running gnatbind 
  9403.  Source_File_Name pragma                           Using Other File Names 
  9404.  Stack Overflow Checking                           Stack Overflow Checking 
  9405.  storage, pool, memory corruption                  Finding memory problems with 
  9406.                                                    GNAT Debug Pool 
  9407.  Subunits                                          Generating Object Files 
  9408.  Suppressing checks                                Run-time Checks 
  9409.  Task switching                                    Ada Tasks 
  9410.  Tasks                                             Ada Tasks 
  9411.  Time Slicing                                      Run-time Control 
  9412.  Time stamp checks, in binder                      Binder Error Message Control 
  9413.  Tree file                                         Tree Files 
  9414.  Typographical conventions                         Conventions 
  9415.  Upper-Half Coding                                 Wide Character Encodings 
  9416.  Warning messages                                  Output and Error Message 
  9417.                                                    Control 
  9418.  Warnings                                          Binder Error Message Control 
  9419.  Writing internal trees                            Auxiliary Output Control 
  9420.