Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/gnat_ugn.texi @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
19 @definfoenclose emph,`,' | 19 @definfoenclose emph,`,' |
20 @c %**end of header | 20 @c %**end of header |
21 | 21 |
22 @copying | 22 @copying |
23 @quotation | 23 @quotation |
24 GNAT User's Guide for Native Platforms , Oct 20, 2017 | 24 GNAT User's Guide for Native Platforms , Aug 20, 2018 |
25 | 25 |
26 AdaCore | 26 AdaCore |
27 | 27 |
28 Copyright @copyright{} 2008-2017, Free Software Foundation | 28 Copyright @copyright{} 2008-2018, Free Software Foundation |
29 @end quotation | 29 @end quotation |
30 | 30 |
31 @end copying | 31 @end copying |
32 | 32 |
33 @titlepage | 33 @titlepage |
347 * Installing gnathtml:: | 347 * Installing gnathtml:: |
348 | 348 |
349 GNAT and Program Execution | 349 GNAT and Program Execution |
350 | 350 |
351 * Running and Debugging Ada Programs:: | 351 * Running and Debugging Ada Programs:: |
352 * Code Coverage and Profiling:: | 352 * Profiling:: |
353 * Improving Performance:: | 353 * Improving Performance:: |
354 * Overflow Check Handling in GNAT:: | 354 * Overflow Check Handling in GNAT:: |
355 * Performing Dimensionality Analysis in GNAT:: | 355 * Performing Dimensionality Analysis in GNAT:: |
356 * Stack Related Facilities:: | 356 * Stack Related Facilities:: |
357 * Memory Management Issues:: | 357 * Memory Management Issues:: |
377 Stack Traceback | 377 Stack Traceback |
378 | 378 |
379 * Non-Symbolic Traceback:: | 379 * Non-Symbolic Traceback:: |
380 * Symbolic Traceback:: | 380 * Symbolic Traceback:: |
381 | 381 |
382 Code Coverage and Profiling | 382 Profiling |
383 | 383 |
384 * Code Coverage of Ada Programs with gcov:: | |
385 * Profiling an Ada Program with gprof:: | 384 * Profiling an Ada Program with gprof:: |
386 | |
387 Code Coverage of Ada Programs with gcov | |
388 | |
389 * Quick startup guide:: | |
390 * GNAT specifics:: | |
391 | 385 |
392 Profiling an Ada Program with gprof | 386 Profiling an Ada Program with gprof |
393 | 387 |
394 * Compilation for profiling:: | 388 * Compilation for profiling:: |
395 * Program execution:: | 389 * Program execution:: |
444 | 438 |
445 Platform-Specific Information | 439 Platform-Specific Information |
446 | 440 |
447 * Run-Time Libraries:: | 441 * Run-Time Libraries:: |
448 * Specifying a Run-Time Library:: | 442 * Specifying a Run-Time Library:: |
443 * GNU/Linux Topics:: | |
449 * Microsoft Windows Topics:: | 444 * Microsoft Windows Topics:: |
450 * Mac OS Topics:: | 445 * Mac OS Topics:: |
451 | 446 |
452 Run-Time Libraries | 447 Run-Time Libraries |
453 | 448 |
454 * Summary of Run-Time Configurations:: | 449 * Summary of Run-Time Configurations:: |
455 | 450 |
456 Specifying a Run-Time Library | 451 Specifying a Run-Time Library |
457 | 452 |
458 * Choosing the Scheduling Policy:: | 453 * Choosing the Scheduling Policy:: |
454 | |
455 GNU/Linux Topics | |
456 | |
457 * Required Packages on GNU/Linux:: | |
459 | 458 |
460 Microsoft Windows Topics | 459 Microsoft Windows Topics |
461 | 460 |
462 * Using GNAT on Windows:: | 461 * Using GNAT on Windows:: |
463 * Using a network installation of GNAT:: | 462 * Using a network installation of GNAT:: |
535 * Controlling the Elaboration Order in GNAT:: | 534 * Controlling the Elaboration Order in GNAT:: |
536 * Common Elaboration-model Traits:: | 535 * Common Elaboration-model Traits:: |
537 * Dynamic Elaboration Model in GNAT:: | 536 * Dynamic Elaboration Model in GNAT:: |
538 * Static Elaboration Model in GNAT:: | 537 * Static Elaboration Model in GNAT:: |
539 * SPARK Elaboration Model in GNAT:: | 538 * SPARK Elaboration Model in GNAT:: |
539 * Legacy Elaboration Model in GNAT:: | |
540 * Mixing Elaboration Models:: | 540 * Mixing Elaboration Models:: |
541 * Elaboration Circularities:: | 541 * Elaboration Circularities:: |
542 * Resolving Elaboration Circularities:: | 542 * Resolving Elaboration Circularities:: |
543 * Resolving Task Issues:: | 543 * Resolving Task Issues:: |
544 * Elaboration-related Compiler Switches:: | 544 * Elaboration-related Compiler Switches:: |
796 | 796 |
797 @item | 797 @item |
798 @ref{24,,Running and Debugging Ada Programs} | 798 @ref{24,,Running and Debugging Ada Programs} |
799 | 799 |
800 @item | 800 @item |
801 @ref{25,,Code Coverage and Profiling} | 801 @ref{25,,Profiling} |
802 | 802 |
803 @item | 803 @item |
804 @ref{26,,Improving Performance} | 804 @ref{26,,Improving Performance} |
805 | 805 |
806 @item | 806 @item |
6454 pragma CPP_Constructor (New_Animal); | 6454 pragma CPP_Constructor (New_Animal); |
6455 pragma Import (CPP, New_Animal, "_ZN6AnimalC1Ev"); | 6455 pragma Import (CPP, New_Animal, "_ZN6AnimalC1Ev"); |
6456 | 6456 |
6457 type Dog is new Animal and Carnivore and Domestic with record | 6457 type Dog is new Animal and Carnivore and Domestic with record |
6458 Tooth_Count : Natural; | 6458 Tooth_Count : Natural; |
6459 Owner : String (1 .. 30); | 6459 Owner : Chars_Ptr; |
6460 end record; | 6460 end record; |
6461 pragma Import (C_Plus_Plus, Dog); | 6461 pragma Import (C_Plus_Plus, Dog); |
6462 | 6462 |
6463 function Number_Of_Teeth (A : Dog) return Natural; | 6463 function Number_Of_Teeth (A : Dog) return Natural; |
6464 pragma Import (C_Plus_Plus, Number_Of_Teeth); | 6464 pragma Import (C_Plus_Plus, Number_Of_Teeth); |
8155 | 8155 |
8156 @table @asis | 8156 @table @asis |
8157 | 8157 |
8158 @item @code{--RTS=@emph{rts-path}} | 8158 @item @code{--RTS=@emph{rts-path}} |
8159 | 8159 |
8160 Specifies the default location of the runtime library. GNAT looks for the | 8160 Specifies the default location of the run-time library. GNAT looks for the |
8161 runtime | 8161 run-time |
8162 in the following directories, and stops as soon as a valid runtime is found | 8162 in the following directories, and stops as soon as a valid run-time is found |
8163 (@code{adainclude} or @code{ada_source_path}, and @code{adalib} or | 8163 (@code{adainclude} or @code{ada_source_path}, and @code{adalib} or |
8164 @code{ada_object_path} present): | 8164 @code{ada_object_path} present): |
8165 | 8165 |
8166 | 8166 |
8167 @itemize * | 8167 @itemize * |
8823 approach is that the compiler can do a whole-program analysis and choose | 8823 approach is that the compiler can do a whole-program analysis and choose |
8824 the best interprocedural optimization strategy based on a complete view | 8824 the best interprocedural optimization strategy based on a complete view |
8825 of the program, instead of a fragmentary view with the usual approach. | 8825 of the program, instead of a fragmentary view with the usual approach. |
8826 This can also speed up the compilation of big programs and reduce the | 8826 This can also speed up the compilation of big programs and reduce the |
8827 size of the executable, compared with a traditional per-unit compilation | 8827 size of the executable, compared with a traditional per-unit compilation |
8828 with inlining across modules enabled by the @code{-gnatn} switch. | 8828 with inlining across units enabled by the @code{-gnatn} switch. |
8829 The drawback of this approach is that it may require more memory and that | 8829 The drawback of this approach is that it may require more memory and that |
8830 the debugging information generated by -g with it might be hardly usable. | 8830 the debugging information generated by -g with it might be hardly usable. |
8831 The switch, as well as the accompanying @code{-Ox} switches, must be | 8831 The switch, as well as the accompanying @code{-Ox} switches, must be |
8832 specified both for the compilation and the link phases. | 8832 specified both for the compilation and the link phases. |
8833 If the @code{n} parameter is specified, the optimization and final code | 8833 If the @code{n} parameter is specified, the optimization and final code |
9168 Detect_Aliasing (Obj, Obj); | 9168 Detect_Aliasing (Obj, Obj); |
9169 Detect_Aliasing (Obj, Self (Obj)); | 9169 Detect_Aliasing (Obj, Self (Obj)); |
9170 @end example | 9170 @end example |
9171 | 9171 |
9172 In the example above, the first call to @code{Detect_Aliasing} fails with a | 9172 In the example above, the first call to @code{Detect_Aliasing} fails with a |
9173 @code{Program_Error} at runtime because the actuals for @code{Val_1} and | 9173 @code{Program_Error} at run time because the actuals for @code{Val_1} and |
9174 @code{Val_2} denote the same object. The second call executes without raising | 9174 @code{Val_2} denote the same object. The second call executes without raising |
9175 an exception because @code{Self(Obj)} produces an anonymous object which does | 9175 an exception because @code{Self(Obj)} produces an anonymous object which does |
9176 not share the memory location of @code{Obj}. | 9176 not share the memory location of @code{Obj}. |
9177 @end table | 9177 @end table |
9178 | 9178 |
9427 Long_Long_Size : Pos; -- Standard.Long_Long_Integer'Size | 9427 Long_Long_Size : Pos; -- Standard.Long_Long_Integer'Size |
9428 Long_Size : Pos; -- Standard.Long_Integer'Size | 9428 Long_Size : Pos; -- Standard.Long_Integer'Size |
9429 Maximum_Alignment : Pos; -- Maximum permitted alignment | 9429 Maximum_Alignment : Pos; -- Maximum permitted alignment |
9430 Max_Unaligned_Field : Pos; -- Maximum size for unaligned bit field | 9430 Max_Unaligned_Field : Pos; -- Maximum size for unaligned bit field |
9431 Pointer_Size : Pos; -- System.Address'Size | 9431 Pointer_Size : Pos; -- System.Address'Size |
9432 Short_Enums : Nat; -- Short foreign convention enums? | 9432 Short_Enums : Nat; -- Foreign enums use short size? |
9433 Short_Size : Pos; -- Standard.Short_Integer'Size | 9433 Short_Size : Pos; -- Standard.Short_Integer'Size |
9434 Strict_Alignment : Nat; -- Strict alignment? | 9434 Strict_Alignment : Nat; -- Strict alignment? |
9435 System_Allocator_Alignment : Nat; -- Alignment for malloc calls | 9435 System_Allocator_Alignment : Nat; -- Alignment for malloc calls |
9436 Wchar_T_Size : Pos; -- Interfaces.C.wchar_t'Size | 9436 Wchar_T_Size : Pos; -- Interfaces.C.wchar_t'Size |
9437 Words_BE : Nat; -- Words stored big-endian? | 9437 Words_BE : Nat; -- Words stored big-endian? |
9438 @end example | 9438 @end example |
9439 | |
9440 @code{Bits_Per_Unit} is the number of bits in a storage unit, the equivalent of | |
9441 GCC macro @code{BITS_PER_UNIT} documented as follows: @cite{Define this macro to be the number of bits in an addressable storage unit (byte); normally 8.} | |
9442 | |
9443 @code{Bits_Per_Word} is the number of bits in a machine word, the equivalent of | |
9444 GCC macro @code{BITS_PER_WORD} documented as follows: @cite{Number of bits in a word; normally 32.} | |
9445 | |
9446 @code{Double_Scalar_Alignment} is the alignment for a scalar whose size is two | |
9447 machine words. It should be the same as the alignment for C @code{long_long} on | |
9448 most targets. | |
9449 | |
9450 @code{Maximum_Alignment} is the maximum alignment that the compiler might choose | |
9451 by default for a type or object, which is also the maximum alignment that can | |
9452 be specified in GNAT. It is computed for GCC backends as @code{BIGGEST_ALIGNMENT | |
9453 / BITS_PER_UNIT} where GCC macro @code{BIGGEST_ALIGNMENT} is documented as | |
9454 follows: @cite{Biggest alignment that any data type can require on this machine@comma{} in bits.} | |
9455 | |
9456 @code{Max_Unaligned_Field} is the maximum size for unaligned bit field, which is | |
9457 64 for the majority of GCC targets (but can be different on some targets like | |
9458 AAMP). | |
9459 | |
9460 @code{Strict_Alignment} is the equivalent of GCC macro @code{STRICT_ALIGNMENT} | |
9461 documented as follows: @cite{Define this macro to be the value 1 if instructions will fail to work if given data not on the nominal alignment. If instructions will merely go slower in that case@comma{} define this macro as 0.} | |
9462 | |
9463 @code{System_Allocator_Alignment} is the guaranteed alignment of data returned | |
9464 by calls to @code{malloc}. | |
9439 | 9465 |
9440 The format of the input file is as follows. First come the values of | 9466 The format of the input file is as follows. First come the values of |
9441 the variables defined above, with one line per value: | 9467 the variables defined above, with one line per value: |
9442 | 9468 |
9443 @example | 9469 @example |
9575 | 9601 |
9576 @table @asis | 9602 @table @asis |
9577 | 9603 |
9578 @item @code{-gnatg} | 9604 @item @code{-gnatg} |
9579 | 9605 |
9580 Internal GNAT implementation mode. This should not be used for | 9606 Internal GNAT implementation mode. This should not be used for applications |
9581 applications programs, it is intended only for use by the compiler | 9607 programs, it is intended only for use by the compiler and its run-time |
9582 and its run-time library. For documentation, see the GNAT sources. | 9608 library. For documentation, see the GNAT sources. Note that @code{-gnatg} |
9583 Note that @code{-gnatg} implies | 9609 implies @code{-gnatw.ge} and @code{-gnatyg} so that all standard |
9584 @code{-gnatw.ge} and | 9610 warnings and all standard style options are turned on. All warnings and style |
9585 @code{-gnatyg} | 9611 messages are treated as errors. |
9586 so that all standard warnings and all standard style options are turned on. | |
9587 All warnings and style messages are treated as errors. | |
9588 @end table | 9612 @end table |
9589 | 9613 |
9590 @geindex -gnatG[nn] (gcc) | 9614 @geindex -gnatG[nn] (gcc) |
9591 | 9615 |
9592 | 9616 |
9603 @table @asis | 9627 @table @asis |
9604 | 9628 |
9605 @item @code{-gnath} | 9629 @item @code{-gnath} |
9606 | 9630 |
9607 Output usage information. The output is written to @code{stdout}. | 9631 Output usage information. The output is written to @code{stdout}. |
9632 @end table | |
9633 | |
9634 @geindex -gnatH (gcc) | |
9635 | |
9636 | |
9637 @table @asis | |
9638 | |
9639 @item @code{-gnatH} | |
9640 | |
9641 Legacy elaboration-checking mode enabled. When this switch is in effect, the | |
9642 pre-18.x access-before-elaboration model becomes the de facto model. | |
9608 @end table | 9643 @end table |
9609 | 9644 |
9610 @geindex -gnati (gcc) | 9645 @geindex -gnati (gcc) |
9611 | 9646 |
9612 | 9647 |
9652 @item @code{-gnatj@emph{nn}} | 9687 @item @code{-gnatj@emph{nn}} |
9653 | 9688 |
9654 Reformat error messages to fit on @code{nn} character lines | 9689 Reformat error messages to fit on @code{nn} character lines |
9655 @end table | 9690 @end table |
9656 | 9691 |
9692 @geindex -gnatJ (gcc) | |
9693 | |
9694 | |
9695 @table @asis | |
9696 | |
9697 @item @code{-gnatJ} | |
9698 | |
9699 Permissive elaboration-checking mode enabled. When this switch is in effect, | |
9700 the post-18.x access-before-elaboration model ignores potential issues with: | |
9701 | |
9702 | |
9703 @itemize - | |
9704 | |
9705 @item | |
9706 Accept statements | |
9707 | |
9708 @item | |
9709 Activations of tasks defined in instances | |
9710 | |
9711 @item | |
9712 Assertion pragmas | |
9713 | |
9714 @item | |
9715 Calls from within an instance to its enclosing context | |
9716 | |
9717 @item | |
9718 Calls through generic formal parameters | |
9719 | |
9720 @item | |
9721 Calls to subprograms defined in instances | |
9722 | |
9723 @item | |
9724 Entry calls | |
9725 | |
9726 @item | |
9727 Indirect calls using 'Access | |
9728 | |
9729 @item | |
9730 Requeue statements | |
9731 | |
9732 @item | |
9733 Select statements | |
9734 | |
9735 @item | |
9736 Synchronous task suspension | |
9737 @end itemize | |
9738 | |
9739 and does not emit compile-time diagnostics or run-time checks. | |
9740 @end table | |
9741 | |
9657 @geindex -gnatk (gcc) | 9742 @geindex -gnatk (gcc) |
9658 | 9743 |
9659 | 9744 |
9660 @table @asis | 9745 @table @asis |
9661 | 9746 |
9708 | 9793 |
9709 @table @asis | 9794 @table @asis |
9710 | 9795 |
9711 @item @code{-gnatn[12]} | 9796 @item @code{-gnatn[12]} |
9712 | 9797 |
9713 Activate inlining across modules for subprograms for which pragma @code{Inline} | 9798 Activate inlining across units for subprograms for which pragma @code{Inline} |
9714 is specified. This inlining is performed by the GCC back-end. An optional | 9799 is specified. This inlining is performed by the GCC back-end. An optional |
9715 digit sets the inlining level: 1 for moderate inlining across modules | 9800 digit sets the inlining level: 1 for moderate inlining across units |
9716 or 2 for full inlining across modules. If no inlining level is specified, | 9801 or 2 for full inlining across units. If no inlining level is specified, |
9717 the compiler will pick it based on the optimization level. | 9802 the compiler will pick it based on the optimization level. |
9718 @end table | 9803 @end table |
9719 | 9804 |
9720 @geindex -gnatN (gcc) | 9805 @geindex -gnatN (gcc) |
9721 | 9806 |
9890 @geindex -gnatR (gcc) | 9975 @geindex -gnatR (gcc) |
9891 | 9976 |
9892 | 9977 |
9893 @table @asis | 9978 @table @asis |
9894 | 9979 |
9895 @item @code{-gnatR[0/1/2/3][e][m][s]} | 9980 @item @code{-gnatR[0|1|2|3][e][j][m][s]} |
9896 | 9981 |
9897 Output representation information for declared types, objects and | 9982 Output representation information for declared types, objects and |
9898 subprograms. Note that this switch is not allowed if a previous | 9983 subprograms. Note that this switch is not allowed if a previous |
9899 @code{-gnatD} switch has been given, since these two switches | 9984 @code{-gnatD} switch has been given, since these two switches |
9900 are not compatible. | 9985 are not compatible. |
10193 | 10278 |
10194 @table @asis | 10279 @table @asis |
10195 | 10280 |
10196 @item @code{--RTS=@emph{rts-path}} | 10281 @item @code{--RTS=@emph{rts-path}} |
10197 | 10282 |
10198 Specifies the default location of the runtime library. Same meaning as the | 10283 Specifies the default location of the run-time library. Same meaning as the |
10199 equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}). | 10284 equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}). |
10200 @end table | 10285 @end table |
10201 | 10286 |
10202 @geindex -S (gcc) | 10287 @geindex -S (gcc) |
10203 | 10288 |
12721 | 12806 |
12722 @item | 12807 @item |
12723 @code{-gnatwD} | 12808 @code{-gnatwD} |
12724 | 12809 |
12725 @item | 12810 @item |
12811 @code{-gnatw.D} | |
12812 | |
12813 @item | |
12726 @code{-gnatwF} | 12814 @code{-gnatwF} |
12727 | 12815 |
12728 @item | 12816 @item |
12817 @code{-gnatw.F} | |
12818 | |
12819 @item | |
12729 @code{-gnatwg} | 12820 @code{-gnatwg} |
12730 | 12821 |
12731 @item | 12822 @item |
12732 @code{-gnatwH} | 12823 @code{-gnatwH} |
12733 | 12824 |
12734 @item | 12825 @item |
12826 @code{-gnatw.H} | |
12827 | |
12828 @item | |
12735 @code{-gnatwi} | 12829 @code{-gnatwi} |
12736 | 12830 |
12737 @item | 12831 @item |
12738 @code{-gnatw.I} | |
12739 | |
12740 @item | |
12741 @code{-gnatwJ} | 12832 @code{-gnatwJ} |
12742 | 12833 |
12743 @item | 12834 @item |
12835 @code{-gnatw.J} | |
12836 | |
12837 @item | |
12744 @code{-gnatwK} | 12838 @code{-gnatwK} |
12745 | 12839 |
12746 @item | 12840 @item |
12841 @code{-gnatw.K} | |
12842 | |
12843 @item | |
12747 @code{-gnatwL} | 12844 @code{-gnatwL} |
12748 | 12845 |
12749 @item | 12846 @item |
12750 @code{-gnatw.L} | 12847 @code{-gnatw.L} |
12751 | 12848 |
12757 | 12854 |
12758 @item | 12855 @item |
12759 @code{-gnatwn} | 12856 @code{-gnatwn} |
12760 | 12857 |
12761 @item | 12858 @item |
12859 @code{-gnatw.N} | |
12860 | |
12861 @item | |
12762 @code{-gnatwo} | 12862 @code{-gnatwo} |
12763 | 12863 |
12764 @item | 12864 @item |
12765 @code{-gnatw.O} | 12865 @code{-gnatw.O} |
12766 | 12866 |
12787 | 12887 |
12788 @item | 12888 @item |
12789 @code{-gnatwT} | 12889 @code{-gnatwT} |
12790 | 12890 |
12791 @item | 12891 @item |
12792 @code{-gnatw.T} | 12892 @code{-gnatw.t} |
12793 | 12893 |
12794 @item | 12894 @item |
12795 @code{-gnatwU} | 12895 @code{-gnatwU} |
12796 | 12896 |
12797 @item | 12897 @item |
12898 @code{-gnatw.U} | |
12899 | |
12900 @item | |
12798 @code{-gnatwv} | 12901 @code{-gnatwv} |
12799 | 12902 |
12800 @item | 12903 @item |
12904 @code{-gnatw.v} | |
12905 | |
12906 @item | |
12801 @code{-gnatww} | 12907 @code{-gnatww} |
12802 | 12908 |
12803 @item | 12909 @item |
12804 @code{-gnatw.W} | 12910 @code{-gnatw.W} |
12805 | 12911 |
12811 | 12917 |
12812 @item | 12918 @item |
12813 @code{-gnatwy} | 12919 @code{-gnatwy} |
12814 | 12920 |
12815 @item | 12921 @item |
12922 @code{-gnatw.Y} | |
12923 | |
12924 @item | |
12816 @code{-gnatwz} | 12925 @code{-gnatwz} |
12926 | |
12927 @item | |
12928 @code{-gnatw.z} | |
12817 @end itemize | 12929 @end itemize |
12818 @end quotation | 12930 @end quotation |
12819 | 12931 |
12820 @node Debugging and Assertion Control,Validity Checking,Warning Message Control,Compiler Switches | 12932 @node Debugging and Assertion Control,Validity Checking,Warning Message Control,Compiler Switches |
12821 @anchor{gnat_ugn/building_executable_programs_with_gnat debugging-and-assertion-control}@anchor{100}@anchor{gnat_ugn/building_executable_programs_with_gnat id16}@anchor{101} | 12933 @anchor{gnat_ugn/building_executable_programs_with_gnat debugging-and-assertion-control}@anchor{100}@anchor{gnat_ugn/building_executable_programs_with_gnat id16}@anchor{101} |
13952 checking code is zero or near-zero, the compiler will generate it even | 14064 checking code is zero or near-zero, the compiler will generate it even |
13953 if checks are suppressed. In particular, if the compiler can prove | 14065 if checks are suppressed. In particular, if the compiler can prove |
13954 that a certain check will necessarily fail, it will generate code to | 14066 that a certain check will necessarily fail, it will generate code to |
13955 do an unconditional 'raise', even if checks are suppressed. The | 14067 do an unconditional 'raise', even if checks are suppressed. The |
13956 compiler warns in this case. Another case in which checks may not be | 14068 compiler warns in this case. Another case in which checks may not be |
13957 eliminated is when they are embedded in certain run time routines such | 14069 eliminated is when they are embedded in certain run-time routines such |
13958 as math library routines. | 14070 as math library routines. |
13959 | 14071 |
13960 Of course, run-time checks are omitted whenever the compiler can prove | 14072 Of course, run-time checks are omitted whenever the compiler can prove |
13961 that they will not fail, whether or not checks are suppressed. | 14073 that they will not fail, whether or not checks are suppressed. |
13962 | 14074 |
14622 @item @code{-gnatn[12]} | 14734 @item @code{-gnatn[12]} |
14623 | 14735 |
14624 The @code{n} here is intended to suggest the first syllable of the word 'inline'. | 14736 The @code{n} here is intended to suggest the first syllable of the word 'inline'. |
14625 GNAT recognizes and processes @code{Inline} pragmas. However, for inlining to | 14737 GNAT recognizes and processes @code{Inline} pragmas. However, for inlining to |
14626 actually occur, optimization must be enabled and, by default, inlining of | 14738 actually occur, optimization must be enabled and, by default, inlining of |
14627 subprograms across modules is not performed. If you want to additionally | 14739 subprograms across units is not performed. If you want to additionally |
14628 enable inlining of subprograms specified by pragma @code{Inline} across modules, | 14740 enable inlining of subprograms specified by pragma @code{Inline} across units, |
14629 you must also specify this switch. | 14741 you must also specify this switch. |
14630 | 14742 |
14631 In the absence of this switch, GNAT does not attempt inlining across modules | 14743 In the absence of this switch, GNAT does not attempt inlining across units |
14632 and does not access the bodies of subprograms for which @code{pragma Inline} is | 14744 and does not access the bodies of subprograms for which @code{pragma Inline} is |
14633 specified if they are not in the current unit. | 14745 specified if they are not in the current unit. |
14634 | 14746 |
14635 You can optionally specify the inlining level: 1 for moderate inlining across | 14747 You can optionally specify the inlining level: 1 for moderate inlining across |
14636 modules, which is a good compromise between compilation times and performances | 14748 units, which is a good compromise between compilation times and performances |
14637 at run time, or 2 for full inlining across modules, which may bring about | 14749 at run time, or 2 for full inlining across units, which may bring about |
14638 longer compilation times. If no inlining level is specified, the compiler will | 14750 longer compilation times. If no inlining level is specified, the compiler will |
14639 pick it based on the optimization level: 1 for @code{-O1}, @code{-O2} or | 14751 pick it based on the optimization level: 1 for @code{-O1}, @code{-O2} or |
14640 @code{-Os} and 2 for @code{-O3}. | 14752 @code{-Os} and 2 for @code{-O3}. |
14641 | 14753 |
14642 If you specify this switch the compiler will access these bodies, | 14754 If you specify this switch the compiler will access these bodies, |
14978 @geindex -gnatR (gcc) | 15090 @geindex -gnatR (gcc) |
14979 | 15091 |
14980 | 15092 |
14981 @table @asis | 15093 @table @asis |
14982 | 15094 |
14983 @item @code{-gnatR[0|1|2|3][e][m][s]} | 15095 @item @code{-gnatR[0|1|2|3][e][j][m][s]} |
14984 | 15096 |
14985 This switch controls output from the compiler of a listing showing | 15097 This switch controls output from the compiler of a listing showing |
14986 representation information for declared types, objects and subprograms. | 15098 representation information for declared types, objects and subprograms. |
14987 For @code{-gnatR0}, no information is output (equivalent to omitting | 15099 For @code{-gnatR0}, no information is output (equivalent to omitting |
14988 the @code{-gnatR} switch). For @code{-gnatR1} (which is the default, | 15100 the @code{-gnatR} switch). For @code{-gnatR1} (which is the default, |
15006 | 15118 |
15007 If the switch is followed by an @code{m} (e.g. @code{-gnatRm}), then | 15119 If the switch is followed by an @code{m} (e.g. @code{-gnatRm}), then |
15008 subprogram conventions and parameter passing mechanisms for all the | 15120 subprogram conventions and parameter passing mechanisms for all the |
15009 subprograms are included. | 15121 subprograms are included. |
15010 | 15122 |
15123 If the switch is followed by a @code{j} (e.g., @code{-gnatRj}), then | |
15124 the output is in the JSON data interchange format specified by the | |
15125 ECMA-404 standard. The semantic description of this JSON output is | |
15126 available in the specification of the Repinfo unit present in the | |
15127 compiler sources. | |
15128 | |
15011 If the switch is followed by an @code{s} (e.g., @code{-gnatR3s}), then | 15129 If the switch is followed by an @code{s} (e.g., @code{-gnatR3s}), then |
15012 the output is to a file with the name @code{file.rep} where file is | 15130 the output is to a file with the name @code{file.rep} where file is |
15013 the name of the corresponding source file. | 15131 the name of the corresponding source file, except if @cite{j`} is also |
15132 specified, in which case the file name is @code{file.json}. | |
15014 | 15133 |
15015 Note that it is possible for record components to have zero size. In | 15134 Note that it is possible for record components to have zero size. In |
15016 this case, the component clause uses an obvious extension of permitted | 15135 this case, the component clause uses an obvious extension of permitted |
15017 Ada syntax, for example @code{at 0 range 0 .. -1}. | 15136 Ada syntax, for example @code{at 0 range 0 .. -1}. |
15018 @end table | 15137 @end table |
15053 @node Exception Handling Control,Units to Sources Mapping Files,Debugging Control,Compiler Switches | 15172 @node Exception Handling Control,Units to Sources Mapping Files,Debugging Control,Compiler Switches |
15054 @anchor{gnat_ugn/building_executable_programs_with_gnat id28}@anchor{114}@anchor{gnat_ugn/building_executable_programs_with_gnat exception-handling-control}@anchor{115} | 15173 @anchor{gnat_ugn/building_executable_programs_with_gnat id28}@anchor{114}@anchor{gnat_ugn/building_executable_programs_with_gnat exception-handling-control}@anchor{115} |
15055 @subsection Exception Handling Control | 15174 @subsection Exception Handling Control |
15056 | 15175 |
15057 | 15176 |
15058 GNAT uses two methods for handling exceptions at run-time. The | 15177 GNAT uses two methods for handling exceptions at run time. The |
15059 @code{setjmp/longjmp} method saves the context when entering | 15178 @code{setjmp/longjmp} method saves the context when entering |
15060 a frame with an exception handler. Then when an exception is | 15179 a frame with an exception handler. Then when an exception is |
15061 raised, the context can be restored immediately, without the | 15180 raised, the context can be restored immediately, without the |
15062 need for tracing stack frames. This method provides very fast | 15181 need for tracing stack frames. This method provides very fast |
15063 exception propagation, but introduces significant overhead for | 15182 exception propagation, but introduces significant overhead for |
15477 | 15596 |
15478 @table @asis | 15597 @table @asis |
15479 | 15598 |
15480 @item @code{-D@emph{nn}[k|m]} | 15599 @item @code{-D@emph{nn}[k|m]} |
15481 | 15600 |
15482 This switch can be used to change the default secondary stack size value | 15601 Set the default secondary stack size to @code{nn}. The suffix indicates whether |
15483 to a specified size @code{nn}, which is expressed in bytes by default, or | 15602 the size is in bytes (no suffix), kilobytes (@code{k} suffix) or megabytes |
15484 in kilobytes when suffixed with @code{k} or in megabytes when suffixed | 15603 (@code{m} suffix). |
15485 with @code{m}. | 15604 |
15486 | 15605 The secondary stack holds objects of unconstrained types that are returned by |
15487 The secondary stack is used to deal with functions that return a variable | 15606 functions, for example unconstrained Strings. The size of the secondary stack |
15488 sized result, for example a function returning an unconstrained | 15607 can be dynamic or fixed depending on the target. |
15489 String. There are two ways in which this secondary stack is allocated. | 15608 |
15490 | 15609 For most targets, the secondary stack grows on demand and is implemented as |
15491 For most targets, the secondary stack grows on demand and is allocated | 15610 a chain of blocks in the heap. In this case, the default secondary stack size |
15492 as a chain of blocks in the heap. The -D option is not very | 15611 determines the initial size of the secondary stack for each task and the |
15493 relevant. It only give some control over the size of the allocated | 15612 smallest amount the secondary stack can grow by. |
15494 blocks (whose size is the minimum of the default secondary stack size value, | 15613 |
15495 and the actual size needed for the current allocation request). | 15614 For Ravenscar, ZFP, and Cert run-times the size of the secondary stack is |
15496 | 15615 fixed. This switch can be used to change the default size of these stacks. |
15497 For certain targets, notably VxWorks 653 and bare board targets, | 15616 The default secondary stack size can be overridden on a per-task basis if |
15498 the secondary stack is allocated by carving off a chunk of the primary task | 15617 individual tasks have different secondary stack requirements. This is |
15499 stack. By default this is a fixed percentage of the primary task stack as | 15618 achieved through the Secondary_Stack_Size aspect that takes the size of the |
15500 defined by System.Parameter.Sec_Stack_Percentage. This can be overridden per | 15619 secondary stack in bytes. |
15501 task using the Secondary_Stack_Size pragma/aspect. The -D option is used to | |
15502 define the size of the environment task's secondary stack. | |
15503 @end table | 15620 @end table |
15504 | 15621 |
15505 @geindex -e (gnatbind) | 15622 @geindex -e (gnatbind) |
15506 | 15623 |
15507 | 15624 |
15672 | 15789 |
15673 @geindex --RTS (gnatbind) | 15790 @geindex --RTS (gnatbind) |
15674 | 15791 |
15675 @item @code{--RTS=@emph{rts-path}} | 15792 @item @code{--RTS=@emph{rts-path}} |
15676 | 15793 |
15677 Specifies the default location of the runtime library. Same meaning as the | 15794 Specifies the default location of the run-time library. Same meaning as the |
15678 equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}). | 15795 equivalent @code{gnatmake} flag (@ref{dc,,Switches for gnatmake}). |
15679 | 15796 |
15680 @geindex -o (gnatbind) | 15797 @geindex -o (gnatbind) |
15681 | 15798 |
15682 @item @code{-o @emph{file}} | 15799 @item @code{-o @emph{file}} |
15789 | 15906 |
15790 @table @asis | 15907 @table @asis |
15791 | 15908 |
15792 @item @code{-static} | 15909 @item @code{-static} |
15793 | 15910 |
15794 Link against a static GNAT run time. | 15911 Link against a static GNAT run-time. |
15795 | 15912 |
15796 @geindex -shared (gnatbind) | 15913 @geindex -shared (gnatbind) |
15797 | 15914 |
15798 @item @code{-shared} | 15915 @item @code{-shared} |
15799 | 15916 |
15800 Link against a shared GNAT run time when available. | 15917 Link against a shared GNAT run-time when available. |
15801 | 15918 |
15802 @geindex -t (gnatbind) | 15919 @geindex -t (gnatbind) |
15803 | 15920 |
15804 @item @code{-t} | 15921 @item @code{-t} |
15805 | 15922 |
15814 is used. If the system does not support specific time slice values, but | 15931 is used. If the system does not support specific time slice values, but |
15815 does support some general notion of round-robin scheduling, then any | 15932 does support some general notion of round-robin scheduling, then any |
15816 nonzero value will activate round-robin scheduling. | 15933 nonzero value will activate round-robin scheduling. |
15817 | 15934 |
15818 A value of zero is treated specially. It turns off time | 15935 A value of zero is treated specially. It turns off time |
15819 slicing, and in addition, indicates to the tasking run time that the | 15936 slicing, and in addition, indicates to the tasking run-time that the |
15820 semantics should match as closely as possible the Annex D | 15937 semantics should match as closely as possible the Annex D |
15821 requirements of the Ada RM, and in particular sets the default | 15938 requirements of the Ada RM, and in particular sets the default |
15822 scheduling policy to @code{FIFO_Within_Priorities}. | 15939 scheduling policy to @code{FIFO_Within_Priorities}. |
15823 | 15940 |
15824 @geindex -u (gnatbind) | 15941 @geindex -u (gnatbind) |
16332 | 16449 |
16333 The output is an Ada unit in source form that can be compiled with GNAT. | 16450 The output is an Ada unit in source form that can be compiled with GNAT. |
16334 This compilation occurs automatically as part of the @code{gnatlink} | 16451 This compilation occurs automatically as part of the @code{gnatlink} |
16335 processing. | 16452 processing. |
16336 | 16453 |
16337 Currently the GNAT run time requires a FPU using 80 bits mode | 16454 Currently the GNAT run-time requires a FPU using 80 bits mode |
16338 precision. Under targets where this is not the default it is required to | 16455 precision. Under targets where this is not the default it is required to |
16339 call GNAT.Float_Control.Reset before using floating point numbers (this | 16456 call GNAT.Float_Control.Reset before using floating point numbers (this |
16340 include float computation, float input and output) in the Ada code. A | 16457 include float computation, float input and output) in the Ada code. A |
16341 side effect is that this could be the wrong mode for the foreign code | 16458 side effect is that this could be the wrong mode for the foreign code |
16342 where floating point computation could be broken after this call. | 16459 where floating point computation could be broken after this call. |
16457 of GNAT). | 16574 of GNAT). |
16458 | 16575 |
16459 @item | 16576 @item |
16460 The content of the @code{ada_object_path} file which is part of the GNAT | 16577 The content of the @code{ada_object_path} file which is part of the GNAT |
16461 installation tree and is used to store standard libraries such as the | 16578 installation tree and is used to store standard libraries such as the |
16462 GNAT Run Time Library (RTL) unless the switch @code{-nostdlib} is | 16579 GNAT Run-Time Library (RTL) unless the switch @code{-nostdlib} is |
16463 specified. See @ref{87,,Installing a library} | 16580 specified. See @ref{87,,Installing a library} |
16464 @end itemize | 16581 @end itemize |
16465 | 16582 |
16466 @geindex -I (gnatbind) | 16583 @geindex -I (gnatbind) |
16467 | 16584 |
16733 | 16850 |
16734 @code{exec-name} specifies an alternate name for the generated | 16851 @code{exec-name} specifies an alternate name for the generated |
16735 executable program. If this switch is omitted, the executable has the same | 16852 executable program. If this switch is omitted, the executable has the same |
16736 name as the main unit. For example, @code{gnatlink try.ali} creates | 16853 name as the main unit. For example, @code{gnatlink try.ali} creates |
16737 an executable called @code{try}. | 16854 an executable called @code{try}. |
16738 @end table | |
16739 | |
16740 @geindex -b (gnatlink) | |
16741 | |
16742 | |
16743 @table @asis | |
16744 | |
16745 @item @code{-b @emph{target}} | |
16746 | |
16747 Compile your program to run on @code{target}, which is the name of a | |
16748 system configuration. You must have a GNAT cross-compiler built if | |
16749 @code{target} is not the same as your host system. | |
16750 @end table | 16855 @end table |
16751 | 16856 |
16752 @geindex -B (gnatlink) | 16857 @geindex -B (gnatlink) |
16753 | 16858 |
16754 | 16859 |
17936 | 18041 |
17937 @item @code{--ext=@emph{extension}} | 18042 @item @code{--ext=@emph{extension}} |
17938 | 18043 |
17939 Specify an alternate ali file extension. The default is @code{ali} and other | 18044 Specify an alternate ali file extension. The default is @code{ali} and other |
17940 extensions (e.g. @code{gli} for C/C++ sources) may be specified via this switch. | 18045 extensions (e.g. @code{gli} for C/C++ sources) may be specified via this switch. |
17941 Note that if this switch overrides the default, which means that only the | 18046 Note that if this switch overrides the default, only the new extension will |
17942 new extension will be considered. | 18047 be considered. |
17943 @end table | 18048 @end table |
17944 | 18049 |
17945 @geindex --RTS (gnatxref) | 18050 @geindex --RTS (gnatxref) |
17946 | 18051 |
17947 | 18052 |
18193 @table @asis | 18298 @table @asis |
18194 | 18299 |
18195 @item @code{--ext=@emph{extension}} | 18300 @item @code{--ext=@emph{extension}} |
18196 | 18301 |
18197 Specify an alternate ali file extension. The default is @code{ali} and other | 18302 Specify an alternate ali file extension. The default is @code{ali} and other |
18198 extensions (e.g. @code{gli} for C/C++ sources when using @code{-fdump-xref}) | 18303 extensions may be specified via this switch. Note that if this switch |
18199 may be specified via this switch. Note that if this switch overrides the | 18304 overrides the default, only the new extension will be considered. |
18200 default, which means that only the new extension will be considered. | |
18201 @end table | 18305 @end table |
18202 | 18306 |
18203 @geindex --RTS (gnatfind) | 18307 @geindex --RTS (gnatfind) |
18204 | 18308 |
18205 | 18309 |
18911 | 19015 |
18912 | 19016 |
18913 | 19017 |
18914 | 19018 |
18915 | 19019 |
19020 | |
18916 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit | 19021 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit |
18917 | 19022 |
18918 @node GNAT and Program Execution,Platform-Specific Information,GNAT Utility Programs,Top | 19023 @node GNAT and Program Execution,Platform-Specific Information,GNAT Utility Programs,Top |
18919 @anchor{gnat_ugn/gnat_and_program_execution gnat-and-program-execution}@anchor{c}@anchor{gnat_ugn/gnat_and_program_execution doc}@anchor{165}@anchor{gnat_ugn/gnat_and_program_execution id1}@anchor{166} | 19024 @anchor{gnat_ugn/gnat_and_program_execution gnat-and-program-execution}@anchor{c}@anchor{gnat_ugn/gnat_and_program_execution doc}@anchor{165}@anchor{gnat_ugn/gnat_and_program_execution id1}@anchor{166} |
18920 @chapter GNAT and Program Execution | 19025 @chapter GNAT and Program Execution |
18927 | 19032 |
18928 @item | 19033 @item |
18929 @ref{167,,Running and Debugging Ada Programs} | 19034 @ref{167,,Running and Debugging Ada Programs} |
18930 | 19035 |
18931 @item | 19036 @item |
18932 @ref{168,,Code Coverage and Profiling} | 19037 @ref{25,,Profiling} |
18933 | 19038 |
18934 @item | 19039 @item |
18935 @ref{169,,Improving Performance} | 19040 @ref{168,,Improving Performance} |
18936 | 19041 |
18937 @item | 19042 @item |
18938 @ref{16a,,Overflow Check Handling in GNAT} | 19043 @ref{169,,Overflow Check Handling in GNAT} |
18939 | 19044 |
18940 @item | 19045 @item |
18941 @ref{16b,,Performing Dimensionality Analysis in GNAT} | 19046 @ref{16a,,Performing Dimensionality Analysis in GNAT} |
18942 | 19047 |
18943 @item | 19048 @item |
18944 @ref{16c,,Stack Related Facilities} | 19049 @ref{16b,,Stack Related Facilities} |
18945 | 19050 |
18946 @item | 19051 @item |
18947 @ref{16d,,Memory Management Issues} | 19052 @ref{16c,,Memory Management Issues} |
18948 @end itemize | 19053 @end itemize |
18949 | 19054 |
18950 @menu | 19055 @menu |
18951 * Running and Debugging Ada Programs:: | 19056 * Running and Debugging Ada Programs:: |
18952 * Code Coverage and Profiling:: | 19057 * Profiling:: |
18953 * Improving Performance:: | 19058 * Improving Performance:: |
18954 * Overflow Check Handling in GNAT:: | 19059 * Overflow Check Handling in GNAT:: |
18955 * Performing Dimensionality Analysis in GNAT:: | 19060 * Performing Dimensionality Analysis in GNAT:: |
18956 * Stack Related Facilities:: | 19061 * Stack Related Facilities:: |
18957 * Memory Management Issues:: | 19062 * Memory Management Issues:: |
18958 | 19063 |
18959 @end menu | 19064 @end menu |
18960 | 19065 |
18961 @node Running and Debugging Ada Programs,Code Coverage and Profiling,,GNAT and Program Execution | 19066 @node Running and Debugging Ada Programs,Profiling,,GNAT and Program Execution |
18962 @anchor{gnat_ugn/gnat_and_program_execution id2}@anchor{167}@anchor{gnat_ugn/gnat_and_program_execution running-and-debugging-ada-programs}@anchor{24} | 19067 @anchor{gnat_ugn/gnat_and_program_execution id2}@anchor{167}@anchor{gnat_ugn/gnat_and_program_execution running-and-debugging-ada-programs}@anchor{24} |
18963 @section Running and Debugging Ada Programs | 19068 @section Running and Debugging Ada Programs |
18964 | 19069 |
18965 | 19070 |
18966 @geindex Debugging | 19071 @geindex Debugging |
19011 * Pretty-Printers for the GNAT runtime:: | 19116 * Pretty-Printers for the GNAT runtime:: |
19012 | 19117 |
19013 @end menu | 19118 @end menu |
19014 | 19119 |
19015 @node The GNAT Debugger GDB,Running GDB,,Running and Debugging Ada Programs | 19120 @node The GNAT Debugger GDB,Running GDB,,Running and Debugging Ada Programs |
19016 @anchor{gnat_ugn/gnat_and_program_execution the-gnat-debugger-gdb}@anchor{16e}@anchor{gnat_ugn/gnat_and_program_execution id3}@anchor{16f} | 19121 @anchor{gnat_ugn/gnat_and_program_execution the-gnat-debugger-gdb}@anchor{16d}@anchor{gnat_ugn/gnat_and_program_execution id3}@anchor{16e} |
19017 @subsection The GNAT Debugger GDB | 19122 @subsection The GNAT Debugger GDB |
19018 | 19123 |
19019 | 19124 |
19020 @code{GDB} is a general purpose, platform-independent debugger that | 19125 @code{GDB} is a general purpose, platform-independent debugger that |
19021 can be used to debug mixed-language programs compiled with @code{gcc}, | 19126 can be used to debug mixed-language programs compiled with @code{gcc}, |
19068 debugger were present. When a breakpoint is hit, @code{GDB} accesses | 19173 debugger were present. When a breakpoint is hit, @code{GDB} accesses |
19069 the debugging information and can respond to user commands to inspect | 19174 the debugging information and can respond to user commands to inspect |
19070 variables, and more generally to report on the state of execution. | 19175 variables, and more generally to report on the state of execution. |
19071 | 19176 |
19072 @node Running GDB,Introduction to GDB Commands,The GNAT Debugger GDB,Running and Debugging Ada Programs | 19177 @node Running GDB,Introduction to GDB Commands,The GNAT Debugger GDB,Running and Debugging Ada Programs |
19073 @anchor{gnat_ugn/gnat_and_program_execution id4}@anchor{170}@anchor{gnat_ugn/gnat_and_program_execution running-gdb}@anchor{171} | 19178 @anchor{gnat_ugn/gnat_and_program_execution id4}@anchor{16f}@anchor{gnat_ugn/gnat_and_program_execution running-gdb}@anchor{170} |
19074 @subsection Running GDB | 19179 @subsection Running GDB |
19075 | 19180 |
19076 | 19181 |
19077 This section describes how to initiate the debugger. | 19182 This section describes how to initiate the debugger. |
19078 | 19183 |
19095 The simplest command is simply @code{run}, which causes the program to run | 19200 The simplest command is simply @code{run}, which causes the program to run |
19096 exactly as if the debugger were not present. The following section | 19201 exactly as if the debugger were not present. The following section |
19097 describes some of the additional commands that can be given to @code{GDB}. | 19202 describes some of the additional commands that can be given to @code{GDB}. |
19098 | 19203 |
19099 @node Introduction to GDB Commands,Using Ada Expressions,Running GDB,Running and Debugging Ada Programs | 19204 @node Introduction to GDB Commands,Using Ada Expressions,Running GDB,Running and Debugging Ada Programs |
19100 @anchor{gnat_ugn/gnat_and_program_execution introduction-to-gdb-commands}@anchor{172}@anchor{gnat_ugn/gnat_and_program_execution id5}@anchor{173} | 19205 @anchor{gnat_ugn/gnat_and_program_execution introduction-to-gdb-commands}@anchor{171}@anchor{gnat_ugn/gnat_and_program_execution id5}@anchor{172} |
19101 @subsection Introduction to GDB Commands | 19206 @subsection Introduction to GDB Commands |
19102 | 19207 |
19103 | 19208 |
19104 @code{GDB} contains a large repertoire of commands. | 19209 @code{GDB} contains a large repertoire of commands. |
19105 See @cite{Debugging with GDB} for extensive documentation on the use | 19210 See @cite{Debugging with GDB} for extensive documentation on the use |
19303 features are described in detail in @cite{Debugging with GDB}. | 19408 features are described in detail in @cite{Debugging with GDB}. |
19304 Note that most commands can be abbreviated | 19409 Note that most commands can be abbreviated |
19305 (for example, c for continue, bt for backtrace). | 19410 (for example, c for continue, bt for backtrace). |
19306 | 19411 |
19307 @node Using Ada Expressions,Calling User-Defined Subprograms,Introduction to GDB Commands,Running and Debugging Ada Programs | 19412 @node Using Ada Expressions,Calling User-Defined Subprograms,Introduction to GDB Commands,Running and Debugging Ada Programs |
19308 @anchor{gnat_ugn/gnat_and_program_execution id6}@anchor{174}@anchor{gnat_ugn/gnat_and_program_execution using-ada-expressions}@anchor{175} | 19413 @anchor{gnat_ugn/gnat_and_program_execution id6}@anchor{173}@anchor{gnat_ugn/gnat_and_program_execution using-ada-expressions}@anchor{174} |
19309 @subsection Using Ada Expressions | 19414 @subsection Using Ada Expressions |
19310 | 19415 |
19311 | 19416 |
19312 @geindex Ada expressions (in gdb) | 19417 @geindex Ada expressions (in gdb) |
19313 | 19418 |
19341 @code{GDB} asks the user's intent. | 19446 @code{GDB} asks the user's intent. |
19342 | 19447 |
19343 For details on the supported Ada syntax, see @cite{Debugging with GDB}. | 19448 For details on the supported Ada syntax, see @cite{Debugging with GDB}. |
19344 | 19449 |
19345 @node Calling User-Defined Subprograms,Using the next Command in a Function,Using Ada Expressions,Running and Debugging Ada Programs | 19450 @node Calling User-Defined Subprograms,Using the next Command in a Function,Using Ada Expressions,Running and Debugging Ada Programs |
19346 @anchor{gnat_ugn/gnat_and_program_execution id7}@anchor{176}@anchor{gnat_ugn/gnat_and_program_execution calling-user-defined-subprograms}@anchor{177} | 19451 @anchor{gnat_ugn/gnat_and_program_execution id7}@anchor{175}@anchor{gnat_ugn/gnat_and_program_execution calling-user-defined-subprograms}@anchor{176} |
19347 @subsection Calling User-Defined Subprograms | 19452 @subsection Calling User-Defined Subprograms |
19348 | 19453 |
19349 | 19454 |
19350 An important capability of @code{GDB} is the ability to call user-defined | 19455 An important capability of @code{GDB} is the ability to call user-defined |
19351 subprograms while debugging. This is achieved simply by entering | 19456 subprograms while debugging. This is achieved simply by entering |
19400 address the array elements. In such a case, instead of trying to print the | 19505 address the array elements. In such a case, instead of trying to print the |
19401 elements directly from GDB, you can write a callable procedure that prints | 19506 elements directly from GDB, you can write a callable procedure that prints |
19402 the elements in the desired format. | 19507 the elements in the desired format. |
19403 | 19508 |
19404 @node Using the next Command in a Function,Stopping When Ada Exceptions Are Raised,Calling User-Defined Subprograms,Running and Debugging Ada Programs | 19509 @node Using the next Command in a Function,Stopping When Ada Exceptions Are Raised,Calling User-Defined Subprograms,Running and Debugging Ada Programs |
19405 @anchor{gnat_ugn/gnat_and_program_execution using-the-next-command-in-a-function}@anchor{178}@anchor{gnat_ugn/gnat_and_program_execution id8}@anchor{179} | 19510 @anchor{gnat_ugn/gnat_and_program_execution using-the-next-command-in-a-function}@anchor{177}@anchor{gnat_ugn/gnat_and_program_execution id8}@anchor{178} |
19406 @subsection Using the @emph{next} Command in a Function | 19511 @subsection Using the @emph{next} Command in a Function |
19407 | 19512 |
19408 | 19513 |
19409 When you use the @code{next} command in a function, the current source | 19514 When you use the @code{next} command in a function, the current source |
19410 location will advance to the next statement as usual. A special case | 19515 location will advance to the next statement as usual. A special case |
19423 the start of the function. You should simply ignore this odd jump. | 19528 the start of the function. You should simply ignore this odd jump. |
19424 The value returned is always that from the first return statement | 19529 The value returned is always that from the first return statement |
19425 that was stepped through. | 19530 that was stepped through. |
19426 | 19531 |
19427 @node Stopping When Ada Exceptions Are Raised,Ada Tasks,Using the next Command in a Function,Running and Debugging Ada Programs | 19532 @node Stopping When Ada Exceptions Are Raised,Ada Tasks,Using the next Command in a Function,Running and Debugging Ada Programs |
19428 @anchor{gnat_ugn/gnat_and_program_execution stopping-when-ada-exceptions-are-raised}@anchor{17a}@anchor{gnat_ugn/gnat_and_program_execution id9}@anchor{17b} | 19533 @anchor{gnat_ugn/gnat_and_program_execution stopping-when-ada-exceptions-are-raised}@anchor{179}@anchor{gnat_ugn/gnat_and_program_execution id9}@anchor{17a} |
19429 @subsection Stopping When Ada Exceptions Are Raised | 19534 @subsection Stopping When Ada Exceptions Are Raised |
19430 | 19535 |
19431 | 19536 |
19432 @geindex Exceptions (in gdb) | 19537 @geindex Exceptions (in gdb) |
19433 | 19538 |
19480 @end itemize | 19585 @end itemize |
19481 | 19586 |
19482 @geindex Tasks (in gdb) | 19587 @geindex Tasks (in gdb) |
19483 | 19588 |
19484 @node Ada Tasks,Debugging Generic Units,Stopping When Ada Exceptions Are Raised,Running and Debugging Ada Programs | 19589 @node Ada Tasks,Debugging Generic Units,Stopping When Ada Exceptions Are Raised,Running and Debugging Ada Programs |
19485 @anchor{gnat_ugn/gnat_and_program_execution ada-tasks}@anchor{17c}@anchor{gnat_ugn/gnat_and_program_execution id10}@anchor{17d} | 19590 @anchor{gnat_ugn/gnat_and_program_execution ada-tasks}@anchor{17b}@anchor{gnat_ugn/gnat_and_program_execution id10}@anchor{17c} |
19486 @subsection Ada Tasks | 19591 @subsection Ada Tasks |
19487 | 19592 |
19488 | 19593 |
19489 @code{GDB} allows the following task-related commands: | 19594 @code{GDB} allows the following task-related commands: |
19490 | 19595 |
19567 @geindex Debugging Generic Units | 19672 @geindex Debugging Generic Units |
19568 | 19673 |
19569 @geindex Generics | 19674 @geindex Generics |
19570 | 19675 |
19571 @node Debugging Generic Units,Remote Debugging with gdbserver,Ada Tasks,Running and Debugging Ada Programs | 19676 @node Debugging Generic Units,Remote Debugging with gdbserver,Ada Tasks,Running and Debugging Ada Programs |
19572 @anchor{gnat_ugn/gnat_and_program_execution debugging-generic-units}@anchor{17e}@anchor{gnat_ugn/gnat_and_program_execution id11}@anchor{17f} | 19677 @anchor{gnat_ugn/gnat_and_program_execution debugging-generic-units}@anchor{17d}@anchor{gnat_ugn/gnat_and_program_execution id11}@anchor{17e} |
19573 @subsection Debugging Generic Units | 19678 @subsection Debugging Generic Units |
19574 | 19679 |
19575 | 19680 |
19576 GNAT always uses code expansion for generic instantiation. This means that | 19681 GNAT always uses code expansion for generic instantiation. This means that |
19577 each time an instantiation occurs, a complete copy of the original code is | 19682 each time an instantiation occurs, a complete copy of the original code is |
19626 other units. | 19731 other units. |
19627 | 19732 |
19628 @geindex Remote Debugging with gdbserver | 19733 @geindex Remote Debugging with gdbserver |
19629 | 19734 |
19630 @node Remote Debugging with gdbserver,GNAT Abnormal Termination or Failure to Terminate,Debugging Generic Units,Running and Debugging Ada Programs | 19735 @node Remote Debugging with gdbserver,GNAT Abnormal Termination or Failure to Terminate,Debugging Generic Units,Running and Debugging Ada Programs |
19631 @anchor{gnat_ugn/gnat_and_program_execution remote-debugging-with-gdbserver}@anchor{180}@anchor{gnat_ugn/gnat_and_program_execution id12}@anchor{181} | 19736 @anchor{gnat_ugn/gnat_and_program_execution remote-debugging-with-gdbserver}@anchor{17f}@anchor{gnat_ugn/gnat_and_program_execution id12}@anchor{180} |
19632 @subsection Remote Debugging with gdbserver | 19737 @subsection Remote Debugging with gdbserver |
19633 | 19738 |
19634 | 19739 |
19635 On platforms where gdbserver is supported, it is possible to use this tool | 19740 On platforms where gdbserver is supported, it is possible to use this tool |
19636 to debug your application remotely. This can be useful in situations | 19741 to debug your application remotely. This can be useful in situations |
19684 GNAT provides support for gdbserver on x86-linux, x86-windows and x86_64-linux. | 19789 GNAT provides support for gdbserver on x86-linux, x86-windows and x86_64-linux. |
19685 | 19790 |
19686 @geindex Abnormal Termination or Failure to Terminate | 19791 @geindex Abnormal Termination or Failure to Terminate |
19687 | 19792 |
19688 @node GNAT Abnormal Termination or Failure to Terminate,Naming Conventions for GNAT Source Files,Remote Debugging with gdbserver,Running and Debugging Ada Programs | 19793 @node GNAT Abnormal Termination or Failure to Terminate,Naming Conventions for GNAT Source Files,Remote Debugging with gdbserver,Running and Debugging Ada Programs |
19689 @anchor{gnat_ugn/gnat_and_program_execution gnat-abnormal-termination-or-failure-to-terminate}@anchor{182}@anchor{gnat_ugn/gnat_and_program_execution id13}@anchor{183} | 19794 @anchor{gnat_ugn/gnat_and_program_execution gnat-abnormal-termination-or-failure-to-terminate}@anchor{181}@anchor{gnat_ugn/gnat_and_program_execution id13}@anchor{182} |
19690 @subsection GNAT Abnormal Termination or Failure to Terminate | 19795 @subsection GNAT Abnormal Termination or Failure to Terminate |
19691 | 19796 |
19692 | 19797 |
19693 When presented with programs that contain serious errors in syntax | 19798 When presented with programs that contain serious errors in syntax |
19694 or semantics, | 19799 or semantics, |
19739 @item | 19844 @item |
19740 Finally, you can start | 19845 Finally, you can start |
19741 @code{gdb} directly on the @code{gnat1} executable. @code{gnat1} is the | 19846 @code{gdb} directly on the @code{gnat1} executable. @code{gnat1} is the |
19742 front-end of GNAT, and can be run independently (normally it is just | 19847 front-end of GNAT, and can be run independently (normally it is just |
19743 called from @code{gcc}). You can use @code{gdb} on @code{gnat1} as you | 19848 called from @code{gcc}). You can use @code{gdb} on @code{gnat1} as you |
19744 would on a C program (but @ref{16e,,The GNAT Debugger GDB} for caveats). The | 19849 would on a C program (but @ref{16d,,The GNAT Debugger GDB} for caveats). The |
19745 @code{where} command is the first line of attack; the variable | 19850 @code{where} command is the first line of attack; the variable |
19746 @code{lineno} (seen by @code{print lineno}), used by the second phase of | 19851 @code{lineno} (seen by @code{print lineno}), used by the second phase of |
19747 @code{gnat1} and by the @code{gcc} backend, indicates the source line at | 19852 @code{gnat1} and by the @code{gcc} backend, indicates the source line at |
19748 which the execution stopped, and @code{input_file name} indicates the name of | 19853 which the execution stopped, and @code{input_file name} indicates the name of |
19749 the source file. | 19854 the source file. |
19750 @end itemize | 19855 @end itemize |
19751 | 19856 |
19752 @node Naming Conventions for GNAT Source Files,Getting Internal Debugging Information,GNAT Abnormal Termination or Failure to Terminate,Running and Debugging Ada Programs | 19857 @node Naming Conventions for GNAT Source Files,Getting Internal Debugging Information,GNAT Abnormal Termination or Failure to Terminate,Running and Debugging Ada Programs |
19753 @anchor{gnat_ugn/gnat_and_program_execution naming-conventions-for-gnat-source-files}@anchor{184}@anchor{gnat_ugn/gnat_and_program_execution id14}@anchor{185} | 19858 @anchor{gnat_ugn/gnat_and_program_execution naming-conventions-for-gnat-source-files}@anchor{183}@anchor{gnat_ugn/gnat_and_program_execution id14}@anchor{184} |
19754 @subsection Naming Conventions for GNAT Source Files | 19859 @subsection Naming Conventions for GNAT Source Files |
19755 | 19860 |
19756 | 19861 |
19757 In order to examine the workings of the GNAT system, the following | 19862 In order to examine the workings of the GNAT system, the following |
19758 brief description of its organization may be helpful: | 19863 brief description of its organization may be helpful: |
19829 general-purpose packages, fully documented in their specs. All | 19934 general-purpose packages, fully documented in their specs. All |
19830 the other @code{.c} files are modifications of common @code{gcc} files. | 19935 the other @code{.c} files are modifications of common @code{gcc} files. |
19831 @end itemize | 19936 @end itemize |
19832 | 19937 |
19833 @node Getting Internal Debugging Information,Stack Traceback,Naming Conventions for GNAT Source Files,Running and Debugging Ada Programs | 19938 @node Getting Internal Debugging Information,Stack Traceback,Naming Conventions for GNAT Source Files,Running and Debugging Ada Programs |
19834 @anchor{gnat_ugn/gnat_and_program_execution id15}@anchor{186}@anchor{gnat_ugn/gnat_and_program_execution getting-internal-debugging-information}@anchor{187} | 19939 @anchor{gnat_ugn/gnat_and_program_execution id15}@anchor{185}@anchor{gnat_ugn/gnat_and_program_execution getting-internal-debugging-information}@anchor{186} |
19835 @subsection Getting Internal Debugging Information | 19940 @subsection Getting Internal Debugging Information |
19836 | 19941 |
19837 | 19942 |
19838 Most compilers have internal debugging switches and modes. GNAT | 19943 Most compilers have internal debugging switches and modes. GNAT |
19839 does also, except GNAT internal debugging switches and modes are not | 19944 does also, except GNAT internal debugging switches and modes are not |
19857 @geindex stack traceback | 19962 @geindex stack traceback |
19858 | 19963 |
19859 @geindex stack unwinding | 19964 @geindex stack unwinding |
19860 | 19965 |
19861 @node Stack Traceback,Pretty-Printers for the GNAT runtime,Getting Internal Debugging Information,Running and Debugging Ada Programs | 19966 @node Stack Traceback,Pretty-Printers for the GNAT runtime,Getting Internal Debugging Information,Running and Debugging Ada Programs |
19862 @anchor{gnat_ugn/gnat_and_program_execution stack-traceback}@anchor{188}@anchor{gnat_ugn/gnat_and_program_execution id16}@anchor{189} | 19967 @anchor{gnat_ugn/gnat_and_program_execution stack-traceback}@anchor{187}@anchor{gnat_ugn/gnat_and_program_execution id16}@anchor{188} |
19863 @subsection Stack Traceback | 19968 @subsection Stack Traceback |
19864 | 19969 |
19865 | 19970 |
19866 Traceback is a mechanism to display the sequence of subprogram calls that | 19971 Traceback is a mechanism to display the sequence of subprogram calls that |
19867 leads to a specified execution point in a program. Often (but not always) | 19972 leads to a specified execution point in a program. Often (but not always) |
19886 * Symbolic Traceback:: | 19991 * Symbolic Traceback:: |
19887 | 19992 |
19888 @end menu | 19993 @end menu |
19889 | 19994 |
19890 @node Non-Symbolic Traceback,Symbolic Traceback,,Stack Traceback | 19995 @node Non-Symbolic Traceback,Symbolic Traceback,,Stack Traceback |
19891 @anchor{gnat_ugn/gnat_and_program_execution non-symbolic-traceback}@anchor{18a}@anchor{gnat_ugn/gnat_and_program_execution id17}@anchor{18b} | 19996 @anchor{gnat_ugn/gnat_and_program_execution non-symbolic-traceback}@anchor{189}@anchor{gnat_ugn/gnat_and_program_execution id17}@anchor{18a} |
19892 @subsubsection Non-Symbolic Traceback | 19997 @subsubsection Non-Symbolic Traceback |
19893 | 19998 |
19894 | 19999 |
19895 Note: this feature is not supported on all platforms. See | 20000 Note: this feature is not supported on all platforms. See |
19896 @code{GNAT.Traceback} spec in @code{g-traceb.ads} | 20001 @code{GNAT.Traceback} spec in @code{g-traceb.ads} |
20171 | 20276 |
20172 @geindex traceback | 20277 @geindex traceback |
20173 @geindex symbolic | 20278 @geindex symbolic |
20174 | 20279 |
20175 @node Symbolic Traceback,,Non-Symbolic Traceback,Stack Traceback | 20280 @node Symbolic Traceback,,Non-Symbolic Traceback,Stack Traceback |
20176 @anchor{gnat_ugn/gnat_and_program_execution id18}@anchor{18c}@anchor{gnat_ugn/gnat_and_program_execution symbolic-traceback}@anchor{18d} | 20281 @anchor{gnat_ugn/gnat_and_program_execution id18}@anchor{18b}@anchor{gnat_ugn/gnat_and_program_execution symbolic-traceback}@anchor{18c} |
20177 @subsubsection Symbolic Traceback | 20282 @subsubsection Symbolic Traceback |
20178 | 20283 |
20179 | 20284 |
20180 A symbolic traceback is a stack traceback in which procedure names are | 20285 A symbolic traceback is a stack traceback in which procedure names are |
20181 associated with each code location. | 20286 associated with each code location. |
20299 This will cause the Exception_Information to contain a symbolic traceback, | 20404 This will cause the Exception_Information to contain a symbolic traceback, |
20300 which will also be printed if an unhandled exception terminates the | 20405 which will also be printed if an unhandled exception terminates the |
20301 program. | 20406 program. |
20302 | 20407 |
20303 @node Pretty-Printers for the GNAT runtime,,Stack Traceback,Running and Debugging Ada Programs | 20408 @node Pretty-Printers for the GNAT runtime,,Stack Traceback,Running and Debugging Ada Programs |
20304 @anchor{gnat_ugn/gnat_and_program_execution id19}@anchor{18e}@anchor{gnat_ugn/gnat_and_program_execution pretty-printers-for-the-gnat-runtime}@anchor{18f} | 20409 @anchor{gnat_ugn/gnat_and_program_execution id19}@anchor{18d}@anchor{gnat_ugn/gnat_and_program_execution pretty-printers-for-the-gnat-runtime}@anchor{18e} |
20305 @subsection Pretty-Printers for the GNAT runtime | 20410 @subsection Pretty-Printers for the GNAT runtime |
20306 | 20411 |
20307 | 20412 |
20308 As discussed in @cite{Calling User-Defined Subprograms}, GDB's | 20413 As discussed in @cite{Calling User-Defined Subprograms}, GDB's |
20309 @code{print} command only knows about the physical layout of program data | 20414 @code{print} command only knows about the physical layout of program data |
20403 @end quotation | 20508 @end quotation |
20404 | 20509 |
20405 Finer control of pretty-printers is also possible: see GDB's online documentation@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Commands} | 20510 Finer control of pretty-printers is also possible: see GDB's online documentation@footnote{http://docs.adacore.com/gdb-docs/html/gdb.html#Pretty_002dPrinter-Commands} |
20406 for more information. | 20511 for more information. |
20407 | 20512 |
20408 @geindex Code Coverage | |
20409 | |
20410 @geindex Profiling | 20513 @geindex Profiling |
20411 | 20514 |
20412 @node Code Coverage and Profiling,Improving Performance,Running and Debugging Ada Programs,GNAT and Program Execution | 20515 @node Profiling,Improving Performance,Running and Debugging Ada Programs,GNAT and Program Execution |
20413 @anchor{gnat_ugn/gnat_and_program_execution id20}@anchor{168}@anchor{gnat_ugn/gnat_and_program_execution code-coverage-and-profiling}@anchor{25} | 20516 @anchor{gnat_ugn/gnat_and_program_execution profiling}@anchor{25}@anchor{gnat_ugn/gnat_and_program_execution id20}@anchor{18f} |
20414 @section Code Coverage and Profiling | 20517 @section Profiling |
20415 | 20518 |
20416 | 20519 |
20417 This section describes how to use the @code{gcov} coverage testing tool and | 20520 This section describes how to use the the @code{gprof} profiler tool on Ada |
20418 the @code{gprof} profiler tool on Ada programs. | 20521 programs. |
20419 | 20522 |
20420 @geindex gcov | 20523 @geindex gprof |
20524 | |
20525 @geindex Profiling | |
20421 | 20526 |
20422 @menu | 20527 @menu |
20423 * Code Coverage of Ada Programs with gcov:: | |
20424 * Profiling an Ada Program with gprof:: | 20528 * Profiling an Ada Program with gprof:: |
20425 | 20529 |
20426 @end menu | 20530 @end menu |
20427 | 20531 |
20428 @node Code Coverage of Ada Programs with gcov,Profiling an Ada Program with gprof,,Code Coverage and Profiling | 20532 @node Profiling an Ada Program with gprof,,,Profiling |
20429 @anchor{gnat_ugn/gnat_and_program_execution id21}@anchor{190}@anchor{gnat_ugn/gnat_and_program_execution code-coverage-of-ada-programs-with-gcov}@anchor{191} | 20533 @anchor{gnat_ugn/gnat_and_program_execution id21}@anchor{190}@anchor{gnat_ugn/gnat_and_program_execution profiling-an-ada-program-with-gprof}@anchor{191} |
20430 @subsection Code Coverage of Ada Programs with gcov | |
20431 | |
20432 | |
20433 @code{gcov} is a test coverage program: it analyzes the execution of a given | |
20434 program on selected tests, to help you determine the portions of the program | |
20435 that are still untested. | |
20436 | |
20437 @code{gcov} is part of the GCC suite, and is described in detail in the GCC | |
20438 User's Guide. You can refer to this documentation for a more complete | |
20439 description. | |
20440 | |
20441 This chapter provides a quick startup guide, and | |
20442 details some GNAT-specific features. | |
20443 | |
20444 @menu | |
20445 * Quick startup guide:: | |
20446 * GNAT specifics:: | |
20447 | |
20448 @end menu | |
20449 | |
20450 @node Quick startup guide,GNAT specifics,,Code Coverage of Ada Programs with gcov | |
20451 @anchor{gnat_ugn/gnat_and_program_execution id22}@anchor{192}@anchor{gnat_ugn/gnat_and_program_execution quick-startup-guide}@anchor{193} | |
20452 @subsubsection Quick startup guide | |
20453 | |
20454 | |
20455 In order to perform coverage analysis of a program using @code{gcov}, several | |
20456 steps are needed: | |
20457 | |
20458 | |
20459 @enumerate | |
20460 | |
20461 @item | |
20462 Instrument the code during the compilation process, | |
20463 | |
20464 @item | |
20465 Execute the instrumented program, and | |
20466 | |
20467 @item | |
20468 Invoke the @code{gcov} tool to generate the coverage results. | |
20469 @end enumerate | |
20470 | |
20471 @geindex -fprofile-arcs (gcc) | |
20472 | |
20473 @geindex -ftest-coverage (gcc | |
20474 | |
20475 @geindex -fprofile-arcs (gnatbind) | |
20476 | |
20477 The code instrumentation needed by gcov is created at the object level. | |
20478 The source code is not modified in any way, because the instrumentation code is | |
20479 inserted by gcc during the compilation process. To compile your code with code | |
20480 coverage activated, you need to recompile your whole project using the | |
20481 switches | |
20482 @code{-fprofile-arcs} and @code{-ftest-coverage}, and link it using | |
20483 @code{-fprofile-arcs}. | |
20484 | |
20485 @quotation | |
20486 | |
20487 @example | |
20488 $ gnatmake -P my_project.gpr -f -cargs -fprofile-arcs -ftest-coverage \\ | |
20489 -largs -fprofile-arcs | |
20490 @end example | |
20491 @end quotation | |
20492 | |
20493 This compilation process will create @code{.gcno} files together with | |
20494 the usual object files. | |
20495 | |
20496 Once the program is compiled with coverage instrumentation, you can | |
20497 run it as many times as needed -- on portions of a test suite for | |
20498 example. The first execution will produce @code{.gcda} files at the | |
20499 same location as the @code{.gcno} files. Subsequent executions | |
20500 will update those files, so that a cumulative result of the covered | |
20501 portions of the program is generated. | |
20502 | |
20503 Finally, you need to call the @code{gcov} tool. The different options of | |
20504 @code{gcov} are described in the GCC User's Guide, section @emph{Invoking gcov}. | |
20505 | |
20506 This will create annotated source files with a @code{.gcov} extension: | |
20507 @code{my_main.adb} file will be analyzed in @code{my_main.adb.gcov}. | |
20508 | |
20509 @node GNAT specifics,,Quick startup guide,Code Coverage of Ada Programs with gcov | |
20510 @anchor{gnat_ugn/gnat_and_program_execution gnat-specifics}@anchor{194}@anchor{gnat_ugn/gnat_and_program_execution id23}@anchor{195} | |
20511 @subsubsection GNAT specifics | |
20512 | |
20513 | |
20514 Because of Ada semantics, portions of the source code may be shared among | |
20515 several object files. This is the case for example when generics are | |
20516 involved, when inlining is active or when declarations generate initialisation | |
20517 calls. In order to take | |
20518 into account this shared code, you need to call @code{gcov} on all | |
20519 source files of the tested program at once. | |
20520 | |
20521 The list of source files might exceed the system's maximum command line | |
20522 length. In order to bypass this limitation, a new mechanism has been | |
20523 implemented in @code{gcov}: you can now list all your project's files into a | |
20524 text file, and provide this file to gcov as a parameter, preceded by a @code{@@} | |
20525 (e.g. @code{gcov @@mysrclist.txt}). | |
20526 | |
20527 Note that on AIX compiling a static library with @code{-fprofile-arcs} is | |
20528 not supported as there can be unresolved symbols during the final link. | |
20529 | |
20530 @geindex gprof | |
20531 | |
20532 @geindex Profiling | |
20533 | |
20534 @node Profiling an Ada Program with gprof,,Code Coverage of Ada Programs with gcov,Code Coverage and Profiling | |
20535 @anchor{gnat_ugn/gnat_and_program_execution profiling-an-ada-program-with-gprof}@anchor{196}@anchor{gnat_ugn/gnat_and_program_execution id24}@anchor{197} | |
20536 @subsection Profiling an Ada Program with gprof | 20534 @subsection Profiling an Ada Program with gprof |
20537 | 20535 |
20538 | 20536 |
20539 This section is not meant to be an exhaustive documentation of @code{gprof}. | 20537 This section is not meant to be an exhaustive documentation of @code{gprof}. |
20540 Full documentation for it can be found in the @cite{GNU Profiler User's Guide} | 20538 Full documentation for it can be found in the @cite{GNU Profiler User's Guide} |
20550 | 20548 |
20551 @itemize * | 20549 @itemize * |
20552 | 20550 |
20553 @item | 20551 @item |
20554 linux x86/x86_64 | 20552 linux x86/x86_64 |
20555 | |
20556 @item | |
20557 solaris sparc/sparc64/x86 | |
20558 | 20553 |
20559 @item | 20554 @item |
20560 windows x86 | 20555 windows x86 |
20561 @end itemize | 20556 @end itemize |
20562 | 20557 |
20587 * Interpretation of profiling results:: | 20582 * Interpretation of profiling results:: |
20588 | 20583 |
20589 @end menu | 20584 @end menu |
20590 | 20585 |
20591 @node Compilation for profiling,Program execution,,Profiling an Ada Program with gprof | 20586 @node Compilation for profiling,Program execution,,Profiling an Ada Program with gprof |
20592 @anchor{gnat_ugn/gnat_and_program_execution id25}@anchor{198}@anchor{gnat_ugn/gnat_and_program_execution compilation-for-profiling}@anchor{199} | 20587 @anchor{gnat_ugn/gnat_and_program_execution id22}@anchor{192}@anchor{gnat_ugn/gnat_and_program_execution compilation-for-profiling}@anchor{193} |
20593 @subsubsection Compilation for profiling | 20588 @subsubsection Compilation for profiling |
20594 | 20589 |
20595 | 20590 |
20596 @geindex -pg (gcc) | 20591 @geindex -pg (gcc) |
20597 @geindex for profiling | 20592 @geindex for profiling |
20615 Note that only the objects that were compiled with the @code{-pg} switch will | 20610 Note that only the objects that were compiled with the @code{-pg} switch will |
20616 be profiled; if you need to profile your whole project, use the @code{-f} | 20611 be profiled; if you need to profile your whole project, use the @code{-f} |
20617 gnatmake switch to force full recompilation. | 20612 gnatmake switch to force full recompilation. |
20618 | 20613 |
20619 @node Program execution,Running gprof,Compilation for profiling,Profiling an Ada Program with gprof | 20614 @node Program execution,Running gprof,Compilation for profiling,Profiling an Ada Program with gprof |
20620 @anchor{gnat_ugn/gnat_and_program_execution program-execution}@anchor{19a}@anchor{gnat_ugn/gnat_and_program_execution id26}@anchor{19b} | 20615 @anchor{gnat_ugn/gnat_and_program_execution program-execution}@anchor{194}@anchor{gnat_ugn/gnat_and_program_execution id23}@anchor{195} |
20621 @subsubsection Program execution | 20616 @subsubsection Program execution |
20622 | 20617 |
20623 | 20618 |
20624 Once the program has been compiled for profiling, you can run it as usual. | 20619 Once the program has been compiled for profiling, you can run it as usual. |
20625 | 20620 |
20630 Once the program completes execution, a data file called @code{gmon.out} is | 20625 Once the program completes execution, a data file called @code{gmon.out} is |
20631 generated in the directory where the program was launched from. If this file | 20626 generated in the directory where the program was launched from. If this file |
20632 already exists, it will be overwritten. | 20627 already exists, it will be overwritten. |
20633 | 20628 |
20634 @node Running gprof,Interpretation of profiling results,Program execution,Profiling an Ada Program with gprof | 20629 @node Running gprof,Interpretation of profiling results,Program execution,Profiling an Ada Program with gprof |
20635 @anchor{gnat_ugn/gnat_and_program_execution running-gprof}@anchor{19c}@anchor{gnat_ugn/gnat_and_program_execution id27}@anchor{19d} | 20630 @anchor{gnat_ugn/gnat_and_program_execution running-gprof}@anchor{196}@anchor{gnat_ugn/gnat_and_program_execution id24}@anchor{197} |
20636 @subsubsection Running gprof | 20631 @subsubsection Running gprof |
20637 | 20632 |
20638 | 20633 |
20639 The @code{gprof} tool is called as follow: | 20634 The @code{gprof} tool is called as follow: |
20640 | 20635 |
20743 may be given; only one @code{function_name} may be indicated with each | 20738 may be given; only one @code{function_name} may be indicated with each |
20744 @code{-F} option. The @code{-F} option overrides the @code{-E} option. | 20739 @code{-F} option. The @code{-F} option overrides the @code{-E} option. |
20745 @end table | 20740 @end table |
20746 | 20741 |
20747 @node Interpretation of profiling results,,Running gprof,Profiling an Ada Program with gprof | 20742 @node Interpretation of profiling results,,Running gprof,Profiling an Ada Program with gprof |
20748 @anchor{gnat_ugn/gnat_and_program_execution id28}@anchor{19e}@anchor{gnat_ugn/gnat_and_program_execution interpretation-of-profiling-results}@anchor{19f} | 20743 @anchor{gnat_ugn/gnat_and_program_execution id25}@anchor{198}@anchor{gnat_ugn/gnat_and_program_execution interpretation-of-profiling-results}@anchor{199} |
20749 @subsubsection Interpretation of profiling results | 20744 @subsubsection Interpretation of profiling results |
20750 | 20745 |
20751 | 20746 |
20752 The results of the profiling analysis are represented by two arrays: the | 20747 The results of the profiling analysis are represented by two arrays: the |
20753 'flat profile' and the 'call graph'. Full documentation of those outputs | 20748 'flat profile' and the 'call graph'. Full documentation of those outputs |
20759 | 20754 |
20760 The call graph shows, for each subprogram, the subprograms that call it, | 20755 The call graph shows, for each subprogram, the subprograms that call it, |
20761 and the subprograms that it calls. It also provides an estimate of the time | 20756 and the subprograms that it calls. It also provides an estimate of the time |
20762 spent in each of those callers/called subprograms. | 20757 spent in each of those callers/called subprograms. |
20763 | 20758 |
20764 @node Improving Performance,Overflow Check Handling in GNAT,Code Coverage and Profiling,GNAT and Program Execution | 20759 @node Improving Performance,Overflow Check Handling in GNAT,Profiling,GNAT and Program Execution |
20765 @anchor{gnat_ugn/gnat_and_program_execution id29}@anchor{169}@anchor{gnat_ugn/gnat_and_program_execution improving-performance}@anchor{26} | 20760 @anchor{gnat_ugn/gnat_and_program_execution improving-performance}@anchor{26}@anchor{gnat_ugn/gnat_and_program_execution id26}@anchor{168} |
20766 @section Improving Performance | 20761 @section Improving Performance |
20767 | 20762 |
20768 | 20763 |
20769 @geindex Improving performance | 20764 @geindex Improving performance |
20770 | 20765 |
20782 * Reducing Size of Executables with Unused Subprogram/Data Elimination:: | 20777 * Reducing Size of Executables with Unused Subprogram/Data Elimination:: |
20783 | 20778 |
20784 @end menu | 20779 @end menu |
20785 | 20780 |
20786 @node Performance Considerations,Text_IO Suggestions,,Improving Performance | 20781 @node Performance Considerations,Text_IO Suggestions,,Improving Performance |
20787 @anchor{gnat_ugn/gnat_and_program_execution performance-considerations}@anchor{1a0}@anchor{gnat_ugn/gnat_and_program_execution id30}@anchor{1a1} | 20782 @anchor{gnat_ugn/gnat_and_program_execution performance-considerations}@anchor{19a}@anchor{gnat_ugn/gnat_and_program_execution id27}@anchor{19b} |
20788 @subsection Performance Considerations | 20783 @subsection Performance Considerations |
20789 | 20784 |
20790 | 20785 |
20791 The GNAT system provides a number of options that allow a trade-off | 20786 The GNAT system provides a number of options that allow a trade-off |
20792 between | 20787 between |
20843 * Passive Task Optimization:: | 20838 * Passive Task Optimization:: |
20844 | 20839 |
20845 @end menu | 20840 @end menu |
20846 | 20841 |
20847 @node Controlling Run-Time Checks,Use of Restrictions,,Performance Considerations | 20842 @node Controlling Run-Time Checks,Use of Restrictions,,Performance Considerations |
20848 @anchor{gnat_ugn/gnat_and_program_execution controlling-run-time-checks}@anchor{1a2}@anchor{gnat_ugn/gnat_and_program_execution id31}@anchor{1a3} | 20843 @anchor{gnat_ugn/gnat_and_program_execution id28}@anchor{19c}@anchor{gnat_ugn/gnat_and_program_execution controlling-run-time-checks}@anchor{19d} |
20849 @subsubsection Controlling Run-Time Checks | 20844 @subsubsection Controlling Run-Time Checks |
20850 | 20845 |
20851 | 20846 |
20852 By default, GNAT generates all run-time checks, except stack overflow | 20847 By default, GNAT generates all run-time checks, except stack overflow |
20853 checks, and checks for access before elaboration on subprogram | 20848 checks, and checks for access before elaboration on subprogram |
20895 the checks. They may be modified using either @code{pragma Suppress} (to | 20890 the checks. They may be modified using either @code{pragma Suppress} (to |
20896 remove checks) or @code{pragma Unsuppress} (to add back suppressed | 20891 remove checks) or @code{pragma Unsuppress} (to add back suppressed |
20897 checks) in the program source. | 20892 checks) in the program source. |
20898 | 20893 |
20899 @node Use of Restrictions,Optimization Levels,Controlling Run-Time Checks,Performance Considerations | 20894 @node Use of Restrictions,Optimization Levels,Controlling Run-Time Checks,Performance Considerations |
20900 @anchor{gnat_ugn/gnat_and_program_execution id32}@anchor{1a4}@anchor{gnat_ugn/gnat_and_program_execution use-of-restrictions}@anchor{1a5} | 20895 @anchor{gnat_ugn/gnat_and_program_execution id29}@anchor{19e}@anchor{gnat_ugn/gnat_and_program_execution use-of-restrictions}@anchor{19f} |
20901 @subsubsection Use of Restrictions | 20896 @subsubsection Use of Restrictions |
20902 | 20897 |
20903 | 20898 |
20904 The use of pragma Restrictions allows you to control which features are | 20899 The use of pragma Restrictions allows you to control which features are |
20905 permitted in your program. Apart from the obvious point that if you avoid | 20900 permitted in your program. Apart from the obvious point that if you avoid |
20930 It is recommended that these restriction pragmas be used if possible. Note | 20925 It is recommended that these restriction pragmas be used if possible. Note |
20931 that this also means that you can write code without worrying about the | 20926 that this also means that you can write code without worrying about the |
20932 possibility of an immediate abort at any point. | 20927 possibility of an immediate abort at any point. |
20933 | 20928 |
20934 @node Optimization Levels,Debugging Optimized Code,Use of Restrictions,Performance Considerations | 20929 @node Optimization Levels,Debugging Optimized Code,Use of Restrictions,Performance Considerations |
20935 @anchor{gnat_ugn/gnat_and_program_execution id33}@anchor{1a6}@anchor{gnat_ugn/gnat_and_program_execution optimization-levels}@anchor{fc} | 20930 @anchor{gnat_ugn/gnat_and_program_execution id30}@anchor{1a0}@anchor{gnat_ugn/gnat_and_program_execution optimization-levels}@anchor{fc} |
20936 @subsubsection Optimization Levels | 20931 @subsubsection Optimization Levels |
20937 | 20932 |
20938 | 20933 |
20939 @geindex -O (gcc) | 20934 @geindex -O (gcc) |
20940 | 20935 |
21054 ought not to be automatically preferred over that of level @code{-O2}, | 21049 ought not to be automatically preferred over that of level @code{-O2}, |
21055 since it often results in larger executables which may run more slowly. | 21050 since it often results in larger executables which may run more slowly. |
21056 See further discussion of this point in @ref{10f,,Inlining of Subprograms}. | 21051 See further discussion of this point in @ref{10f,,Inlining of Subprograms}. |
21057 | 21052 |
21058 @node Debugging Optimized Code,Inlining of Subprograms,Optimization Levels,Performance Considerations | 21053 @node Debugging Optimized Code,Inlining of Subprograms,Optimization Levels,Performance Considerations |
21059 @anchor{gnat_ugn/gnat_and_program_execution id34}@anchor{1a7}@anchor{gnat_ugn/gnat_and_program_execution debugging-optimized-code}@anchor{1a8} | 21054 @anchor{gnat_ugn/gnat_and_program_execution debugging-optimized-code}@anchor{1a1}@anchor{gnat_ugn/gnat_and_program_execution id31}@anchor{1a2} |
21060 @subsubsection Debugging Optimized Code | 21055 @subsubsection Debugging Optimized Code |
21061 | 21056 |
21062 | 21057 |
21063 @geindex Debugging optimized code | 21058 @geindex Debugging optimized code |
21064 | 21059 |
21182 Note that if you use @code{-g} you can then use the @code{strip} program | 21177 Note that if you use @code{-g} you can then use the @code{strip} program |
21183 on the resulting executable, | 21178 on the resulting executable, |
21184 which removes both debugging information and global symbols. | 21179 which removes both debugging information and global symbols. |
21185 | 21180 |
21186 @node Inlining of Subprograms,Floating_Point_Operations,Debugging Optimized Code,Performance Considerations | 21181 @node Inlining of Subprograms,Floating_Point_Operations,Debugging Optimized Code,Performance Considerations |
21187 @anchor{gnat_ugn/gnat_and_program_execution id35}@anchor{1a9}@anchor{gnat_ugn/gnat_and_program_execution inlining-of-subprograms}@anchor{10f} | 21182 @anchor{gnat_ugn/gnat_and_program_execution id32}@anchor{1a3}@anchor{gnat_ugn/gnat_and_program_execution inlining-of-subprograms}@anchor{10f} |
21188 @subsubsection Inlining of Subprograms | 21183 @subsubsection Inlining of Subprograms |
21189 | 21184 |
21190 | 21185 |
21191 A call to a subprogram in the current unit is inlined if all the | 21186 A call to a subprogram in the current unit is inlined if all the |
21192 following conditions are met: | 21187 following conditions are met: |
21321 automatically assume that @code{-O3} is better than @code{-O2}, and | 21316 automatically assume that @code{-O3} is better than @code{-O2}, and |
21322 indeed you should use @code{-O3} only if tests show that it actually | 21317 indeed you should use @code{-O3} only if tests show that it actually |
21323 improves performance for your program. | 21318 improves performance for your program. |
21324 | 21319 |
21325 @node Floating_Point_Operations,Vectorization of loops,Inlining of Subprograms,Performance Considerations | 21320 @node Floating_Point_Operations,Vectorization of loops,Inlining of Subprograms,Performance Considerations |
21326 @anchor{gnat_ugn/gnat_and_program_execution id36}@anchor{1aa}@anchor{gnat_ugn/gnat_and_program_execution floating-point-operations}@anchor{1ab} | 21321 @anchor{gnat_ugn/gnat_and_program_execution floating-point-operations}@anchor{1a4}@anchor{gnat_ugn/gnat_and_program_execution id33}@anchor{1a5} |
21327 @subsubsection Floating_Point_Operations | 21322 @subsubsection Floating_Point_Operations |
21328 | 21323 |
21329 | 21324 |
21330 @geindex Floating-Point Operations | 21325 @geindex Floating-Point Operations |
21331 | 21326 |
21369 Note that the ABI has the same form for both floating-point models, | 21364 Note that the ABI has the same form for both floating-point models, |
21370 so it is permissible to mix units compiled with and without these | 21365 so it is permissible to mix units compiled with and without these |
21371 switches. | 21366 switches. |
21372 | 21367 |
21373 @node Vectorization of loops,Other Optimization Switches,Floating_Point_Operations,Performance Considerations | 21368 @node Vectorization of loops,Other Optimization Switches,Floating_Point_Operations,Performance Considerations |
21374 @anchor{gnat_ugn/gnat_and_program_execution id37}@anchor{1ac}@anchor{gnat_ugn/gnat_and_program_execution vectorization-of-loops}@anchor{1ad} | 21369 @anchor{gnat_ugn/gnat_and_program_execution id34}@anchor{1a6}@anchor{gnat_ugn/gnat_and_program_execution vectorization-of-loops}@anchor{1a7} |
21375 @subsubsection Vectorization of loops | 21370 @subsubsection Vectorization of loops |
21376 | 21371 |
21377 | 21372 |
21378 @geindex Optimization Switches | 21373 @geindex Optimization Switches |
21379 | 21374 |
21520 | 21515 |
21521 placed immediately within the loop will tell the compiler that it can safely | 21516 placed immediately within the loop will tell the compiler that it can safely |
21522 omit the non-vectorized version of the loop as well as the run-time test. | 21517 omit the non-vectorized version of the loop as well as the run-time test. |
21523 | 21518 |
21524 @node Other Optimization Switches,Optimization and Strict Aliasing,Vectorization of loops,Performance Considerations | 21519 @node Other Optimization Switches,Optimization and Strict Aliasing,Vectorization of loops,Performance Considerations |
21525 @anchor{gnat_ugn/gnat_and_program_execution other-optimization-switches}@anchor{1ae}@anchor{gnat_ugn/gnat_and_program_execution id38}@anchor{1af} | 21520 @anchor{gnat_ugn/gnat_and_program_execution other-optimization-switches}@anchor{1a8}@anchor{gnat_ugn/gnat_and_program_execution id35}@anchor{1a9} |
21526 @subsubsection Other Optimization Switches | 21521 @subsubsection Other Optimization Switches |
21527 | 21522 |
21528 | 21523 |
21529 @geindex Optimization Switches | 21524 @geindex Optimization Switches |
21530 | 21525 |
21537 on appropriate machines). For full details of these switches, see | 21532 on appropriate machines). For full details of these switches, see |
21538 the @emph{Submodel Options} section in the @emph{Hardware Models and Configurations} | 21533 the @emph{Submodel Options} section in the @emph{Hardware Models and Configurations} |
21539 chapter of @cite{Using the GNU Compiler Collection (GCC)}. | 21534 chapter of @cite{Using the GNU Compiler Collection (GCC)}. |
21540 | 21535 |
21541 @node Optimization and Strict Aliasing,Aliased Variables and Optimization,Other Optimization Switches,Performance Considerations | 21536 @node Optimization and Strict Aliasing,Aliased Variables and Optimization,Other Optimization Switches,Performance Considerations |
21542 @anchor{gnat_ugn/gnat_and_program_execution optimization-and-strict-aliasing}@anchor{f3}@anchor{gnat_ugn/gnat_and_program_execution id39}@anchor{1b0} | 21537 @anchor{gnat_ugn/gnat_and_program_execution optimization-and-strict-aliasing}@anchor{f3}@anchor{gnat_ugn/gnat_and_program_execution id36}@anchor{1aa} |
21543 @subsubsection Optimization and Strict Aliasing | 21538 @subsubsection Optimization and Strict Aliasing |
21544 | 21539 |
21545 | 21540 |
21546 @geindex Aliasing | 21541 @geindex Aliasing |
21547 | 21542 |
21777 @code{-O2} with strict aliasing in effect, then you should | 21772 @code{-O2} with strict aliasing in effect, then you should |
21778 review any uses of unchecked conversion of access types, | 21773 review any uses of unchecked conversion of access types, |
21779 particularly if you are getting the warnings described above. | 21774 particularly if you are getting the warnings described above. |
21780 | 21775 |
21781 @node Aliased Variables and Optimization,Atomic Variables and Optimization,Optimization and Strict Aliasing,Performance Considerations | 21776 @node Aliased Variables and Optimization,Atomic Variables and Optimization,Optimization and Strict Aliasing,Performance Considerations |
21782 @anchor{gnat_ugn/gnat_and_program_execution aliased-variables-and-optimization}@anchor{1b1}@anchor{gnat_ugn/gnat_and_program_execution id40}@anchor{1b2} | 21777 @anchor{gnat_ugn/gnat_and_program_execution id37}@anchor{1ab}@anchor{gnat_ugn/gnat_and_program_execution aliased-variables-and-optimization}@anchor{1ac} |
21783 @subsubsection Aliased Variables and Optimization | 21778 @subsubsection Aliased Variables and Optimization |
21784 | 21779 |
21785 | 21780 |
21786 @geindex Aliasing | 21781 @geindex Aliasing |
21787 | 21782 |
21835 inhibits optimizations that assume the value cannot be assigned. | 21830 inhibits optimizations that assume the value cannot be assigned. |
21836 This means that the above example will in fact "work" reliably, | 21831 This means that the above example will in fact "work" reliably, |
21837 that is, it will produce the expected results. | 21832 that is, it will produce the expected results. |
21838 | 21833 |
21839 @node Atomic Variables and Optimization,Passive Task Optimization,Aliased Variables and Optimization,Performance Considerations | 21834 @node Atomic Variables and Optimization,Passive Task Optimization,Aliased Variables and Optimization,Performance Considerations |
21840 @anchor{gnat_ugn/gnat_and_program_execution atomic-variables-and-optimization}@anchor{1b3}@anchor{gnat_ugn/gnat_and_program_execution id41}@anchor{1b4} | 21835 @anchor{gnat_ugn/gnat_and_program_execution atomic-variables-and-optimization}@anchor{1ad}@anchor{gnat_ugn/gnat_and_program_execution id38}@anchor{1ae} |
21841 @subsubsection Atomic Variables and Optimization | 21836 @subsubsection Atomic Variables and Optimization |
21842 | 21837 |
21843 | 21838 |
21844 @geindex Atomic | 21839 @geindex Atomic |
21845 | 21840 |
21916 GNAT Reference Manual. If performance is critical, and | 21911 GNAT Reference Manual. If performance is critical, and |
21917 such synchronization code is not required, it may be | 21912 such synchronization code is not required, it may be |
21918 useful to disable it. | 21913 useful to disable it. |
21919 | 21914 |
21920 @node Passive Task Optimization,,Atomic Variables and Optimization,Performance Considerations | 21915 @node Passive Task Optimization,,Atomic Variables and Optimization,Performance Considerations |
21921 @anchor{gnat_ugn/gnat_and_program_execution id42}@anchor{1b5}@anchor{gnat_ugn/gnat_and_program_execution passive-task-optimization}@anchor{1b6} | 21916 @anchor{gnat_ugn/gnat_and_program_execution passive-task-optimization}@anchor{1af}@anchor{gnat_ugn/gnat_and_program_execution id39}@anchor{1b0} |
21922 @subsubsection Passive Task Optimization | 21917 @subsubsection Passive Task Optimization |
21923 | 21918 |
21924 | 21919 |
21925 @geindex Passive Task | 21920 @geindex Passive Task |
21926 | 21921 |
21961 arise, and update those particular tasks to be protected types. Note | 21956 arise, and update those particular tasks to be protected types. Note |
21962 that typically clients of the tasks who call entries, will not have | 21957 that typically clients of the tasks who call entries, will not have |
21963 to be modified, only the task definition itself. | 21958 to be modified, only the task definition itself. |
21964 | 21959 |
21965 @node Text_IO Suggestions,Reducing Size of Executables with Unused Subprogram/Data Elimination,Performance Considerations,Improving Performance | 21960 @node Text_IO Suggestions,Reducing Size of Executables with Unused Subprogram/Data Elimination,Performance Considerations,Improving Performance |
21966 @anchor{gnat_ugn/gnat_and_program_execution text-io-suggestions}@anchor{1b7}@anchor{gnat_ugn/gnat_and_program_execution id43}@anchor{1b8} | 21961 @anchor{gnat_ugn/gnat_and_program_execution text-io-suggestions}@anchor{1b1}@anchor{gnat_ugn/gnat_and_program_execution id40}@anchor{1b2} |
21967 @subsection @code{Text_IO} Suggestions | 21962 @subsection @code{Text_IO} Suggestions |
21968 | 21963 |
21969 | 21964 |
21970 @geindex Text_IO and performance | 21965 @geindex Text_IO and performance |
21971 | 21966 |
21984 performance is an important factor, use a designated file instead | 21979 performance is an important factor, use a designated file instead |
21985 of the standard output file, or change the standard output file to | 21980 of the standard output file, or change the standard output file to |
21986 be buffered using @code{Interfaces.C_Streams.setvbuf}. | 21981 be buffered using @code{Interfaces.C_Streams.setvbuf}. |
21987 | 21982 |
21988 @node Reducing Size of Executables with Unused Subprogram/Data Elimination,,Text_IO Suggestions,Improving Performance | 21983 @node Reducing Size of Executables with Unused Subprogram/Data Elimination,,Text_IO Suggestions,Improving Performance |
21989 @anchor{gnat_ugn/gnat_and_program_execution id44}@anchor{1b9}@anchor{gnat_ugn/gnat_and_program_execution reducing-size-of-executables-with-unused-subprogram-data-elimination}@anchor{1ba} | 21984 @anchor{gnat_ugn/gnat_and_program_execution id41}@anchor{1b3}@anchor{gnat_ugn/gnat_and_program_execution reducing-size-of-executables-with-unused-subprogram-data-elimination}@anchor{1b4} |
21990 @subsection Reducing Size of Executables with Unused Subprogram/Data Elimination | 21985 @subsection Reducing Size of Executables with Unused Subprogram/Data Elimination |
21991 | 21986 |
21992 | 21987 |
21993 @geindex Uunused subprogram/data elimination | 21988 @geindex Uunused subprogram/data elimination |
21994 | 21989 |
22001 * Example of unused subprogram/data elimination:: | 21996 * Example of unused subprogram/data elimination:: |
22002 | 21997 |
22003 @end menu | 21998 @end menu |
22004 | 21999 |
22005 @node About unused subprogram/data elimination,Compilation options,,Reducing Size of Executables with Unused Subprogram/Data Elimination | 22000 @node About unused subprogram/data elimination,Compilation options,,Reducing Size of Executables with Unused Subprogram/Data Elimination |
22006 @anchor{gnat_ugn/gnat_and_program_execution id45}@anchor{1bb}@anchor{gnat_ugn/gnat_and_program_execution about-unused-subprogram-data-elimination}@anchor{1bc} | 22001 @anchor{gnat_ugn/gnat_and_program_execution id42}@anchor{1b5}@anchor{gnat_ugn/gnat_and_program_execution about-unused-subprogram-data-elimination}@anchor{1b6} |
22007 @subsubsection About unused subprogram/data elimination | 22002 @subsubsection About unused subprogram/data elimination |
22008 | 22003 |
22009 | 22004 |
22010 By default, an executable contains all code and data of its composing objects | 22005 By default, an executable contains all code and data of its composing objects |
22011 (directly linked or coming from statically linked libraries), even data or code | 22006 (directly linked or coming from statically linked libraries), even data or code |
22017 This functionality is available on all Linux platforms except for the IA-64 | 22012 This functionality is available on all Linux platforms except for the IA-64 |
22018 architecture and on all cross platforms using the ELF binary file format. | 22013 architecture and on all cross platforms using the ELF binary file format. |
22019 In both cases GNU binutils version 2.16 or later are required to enable it. | 22014 In both cases GNU binutils version 2.16 or later are required to enable it. |
22020 | 22015 |
22021 @node Compilation options,Example of unused subprogram/data elimination,About unused subprogram/data elimination,Reducing Size of Executables with Unused Subprogram/Data Elimination | 22016 @node Compilation options,Example of unused subprogram/data elimination,About unused subprogram/data elimination,Reducing Size of Executables with Unused Subprogram/Data Elimination |
22022 @anchor{gnat_ugn/gnat_and_program_execution id46}@anchor{1bd}@anchor{gnat_ugn/gnat_and_program_execution compilation-options}@anchor{1be} | 22017 @anchor{gnat_ugn/gnat_and_program_execution id43}@anchor{1b7}@anchor{gnat_ugn/gnat_and_program_execution compilation-options}@anchor{1b8} |
22023 @subsubsection Compilation options | 22018 @subsubsection Compilation options |
22024 | 22019 |
22025 | 22020 |
22026 The operation of eliminating the unused code and data from the final executable | 22021 The operation of eliminating the unused code and data from the final executable |
22027 is directly performed by the linker. | 22022 is directly performed by the linker. |
22056 The GNAT static library is now compiled with -ffunction-sections and | 22051 The GNAT static library is now compiled with -ffunction-sections and |
22057 -fdata-sections on some platforms. This allows you to eliminate the unused code | 22052 -fdata-sections on some platforms. This allows you to eliminate the unused code |
22058 and data of the GNAT library from your executable. | 22053 and data of the GNAT library from your executable. |
22059 | 22054 |
22060 @node Example of unused subprogram/data elimination,,Compilation options,Reducing Size of Executables with Unused Subprogram/Data Elimination | 22055 @node Example of unused subprogram/data elimination,,Compilation options,Reducing Size of Executables with Unused Subprogram/Data Elimination |
22061 @anchor{gnat_ugn/gnat_and_program_execution id47}@anchor{1bf}@anchor{gnat_ugn/gnat_and_program_execution example-of-unused-subprogram-data-elimination}@anchor{1c0} | 22056 @anchor{gnat_ugn/gnat_and_program_execution example-of-unused-subprogram-data-elimination}@anchor{1b9}@anchor{gnat_ugn/gnat_and_program_execution id44}@anchor{1ba} |
22062 @subsubsection Example of unused subprogram/data elimination | 22057 @subsubsection Example of unused subprogram/data elimination |
22063 | 22058 |
22064 | 22059 |
22065 Here is a simple example: | 22060 Here is a simple example: |
22066 | 22061 |
22127 | 22122 |
22128 @geindex Checks (overflow) | 22123 @geindex Checks (overflow) |
22129 | 22124 |
22130 | 22125 |
22131 @node Overflow Check Handling in GNAT,Performing Dimensionality Analysis in GNAT,Improving Performance,GNAT and Program Execution | 22126 @node Overflow Check Handling in GNAT,Performing Dimensionality Analysis in GNAT,Improving Performance,GNAT and Program Execution |
22132 @anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{16a}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{27} | 22127 @anchor{gnat_ugn/gnat_and_program_execution id50}@anchor{169}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{27} |
22133 @section Overflow Check Handling in GNAT | 22128 @section Overflow Check Handling in GNAT |
22134 | 22129 |
22135 | 22130 |
22136 This section explains how to control the handling of overflow checks. | 22131 This section explains how to control the handling of overflow checks. |
22137 | 22132 |
22143 * Implementation Notes:: | 22138 * Implementation Notes:: |
22144 | 22139 |
22145 @end menu | 22140 @end menu |
22146 | 22141 |
22147 @node Background,Management of Overflows in GNAT,,Overflow Check Handling in GNAT | 22142 @node Background,Management of Overflows in GNAT,,Overflow Check Handling in GNAT |
22148 @anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{1c1}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{1c2} | 22143 @anchor{gnat_ugn/gnat_and_program_execution id51}@anchor{1bb}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{1bc} |
22149 @subsection Background | 22144 @subsection Background |
22150 | 22145 |
22151 | 22146 |
22152 Overflow checks are checks that the compiler may make to ensure | 22147 Overflow checks are checks that the compiler may make to ensure |
22153 that intermediate results are not out of range. For example: | 22148 that intermediate results are not out of range. For example: |
22269 is True, but at run time we may (but are not guaranteed to) get an | 22264 is True, but at run time we may (but are not guaranteed to) get an |
22270 exception raised because of the intermediate overflow (and we really | 22265 exception raised because of the intermediate overflow (and we really |
22271 would prefer this precondition to be considered True at run time). | 22266 would prefer this precondition to be considered True at run time). |
22272 | 22267 |
22273 @node Management of Overflows in GNAT,Specifying the Desired Mode,Background,Overflow Check Handling in GNAT | 22268 @node Management of Overflows in GNAT,Specifying the Desired Mode,Background,Overflow Check Handling in GNAT |
22274 @anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{1c3}@anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1c4} | 22269 @anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1bd}@anchor{gnat_ugn/gnat_and_program_execution id52}@anchor{1be} |
22275 @subsection Management of Overflows in GNAT | 22270 @subsection Management of Overflows in GNAT |
22276 | 22271 |
22277 | 22272 |
22278 To deal with the portability issue, and with the problem of | 22273 To deal with the portability issue, and with the problem of |
22279 mathematical versus run-time interpretation of the expressions in | 22274 mathematical versus run-time interpretation of the expressions in |
22383 constrained floating-point type, and range checks will be carried | 22378 constrained floating-point type, and range checks will be carried |
22384 out in the normal manner (with infinite values always failing all | 22379 out in the normal manner (with infinite values always failing all |
22385 range checks). | 22380 range checks). |
22386 | 22381 |
22387 @node Specifying the Desired Mode,Default Settings,Management of Overflows in GNAT,Overflow Check Handling in GNAT | 22382 @node Specifying the Desired Mode,Default Settings,Management of Overflows in GNAT,Overflow Check Handling in GNAT |
22388 @anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{f8}@anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1c5} | 22383 @anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{f8}@anchor{gnat_ugn/gnat_and_program_execution id53}@anchor{1bf} |
22389 @subsection Specifying the Desired Mode | 22384 @subsection Specifying the Desired Mode |
22390 | 22385 |
22391 | 22386 |
22392 @geindex pragma Overflow_Mode | 22387 @geindex pragma Overflow_Mode |
22393 | 22388 |
22507 @code{-gnato11}, | 22502 @code{-gnato11}, |
22508 causing all intermediate operations to be computed using the base | 22503 causing all intermediate operations to be computed using the base |
22509 type (@code{STRICT} mode). | 22504 type (@code{STRICT} mode). |
22510 | 22505 |
22511 @node Default Settings,Implementation Notes,Specifying the Desired Mode,Overflow Check Handling in GNAT | 22506 @node Default Settings,Implementation Notes,Specifying the Desired Mode,Overflow Check Handling in GNAT |
22512 @anchor{gnat_ugn/gnat_and_program_execution id59}@anchor{1c6}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1c7} | 22507 @anchor{gnat_ugn/gnat_and_program_execution id54}@anchor{1c0}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1c1} |
22513 @subsection Default Settings | 22508 @subsection Default Settings |
22514 | 22509 |
22515 | 22510 |
22516 The default mode for overflow checks is | 22511 The default mode for overflow checks is |
22517 | 22512 |
22554 The pragma @code{Unsuppress (Overflow_Check)} enables overflow | 22549 The pragma @code{Unsuppress (Overflow_Check)} enables overflow |
22555 checking, but it has no effect on the method used for computing | 22550 checking, but it has no effect on the method used for computing |
22556 intermediate results. | 22551 intermediate results. |
22557 | 22552 |
22558 @node Implementation Notes,,Default Settings,Overflow Check Handling in GNAT | 22553 @node Implementation Notes,,Default Settings,Overflow Check Handling in GNAT |
22559 @anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1c8}@anchor{gnat_ugn/gnat_and_program_execution id60}@anchor{1c9} | 22554 @anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{1c2}@anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1c3} |
22560 @subsection Implementation Notes | 22555 @subsection Implementation Notes |
22561 | 22556 |
22562 | 22557 |
22563 In practice on typical 64-bit machines, the @code{MINIMIZED} mode is | 22558 In practice on typical 64-bit machines, the @code{MINIMIZED} mode is |
22564 reasonably efficient, and can be generally used. It also helps | 22559 reasonably efficient, and can be generally used. It also helps |
22602 Currently, the @code{ELIMINATED} mode is only available on target | 22597 Currently, the @code{ELIMINATED} mode is only available on target |
22603 platforms for which @code{Long_Long_Integer} is 64-bits (nearly all GNAT | 22598 platforms for which @code{Long_Long_Integer} is 64-bits (nearly all GNAT |
22604 platforms). | 22599 platforms). |
22605 | 22600 |
22606 @node Performing Dimensionality Analysis in GNAT,Stack Related Facilities,Overflow Check Handling in GNAT,GNAT and Program Execution | 22601 @node Performing Dimensionality Analysis in GNAT,Stack Related Facilities,Overflow Check Handling in GNAT,GNAT and Program Execution |
22607 @anchor{gnat_ugn/gnat_and_program_execution id61}@anchor{16b}@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{28} | 22602 @anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{16a}@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{28} |
22608 @section Performing Dimensionality Analysis in GNAT | 22603 @section Performing Dimensionality Analysis in GNAT |
22609 | 22604 |
22610 | 22605 |
22611 @geindex Dimensionality analysis | 22606 @geindex Dimensionality analysis |
22612 | 22607 |
22635 @geindex System.Dim.Mks package (GNAT library) | 22630 @geindex System.Dim.Mks package (GNAT library) |
22636 | 22631 |
22637 @geindex MKS_Type type | 22632 @geindex MKS_Type type |
22638 | 22633 |
22639 The simplest way to impose dimensionality checking on a computation is to make | 22634 The simplest way to impose dimensionality checking on a computation is to make |
22640 use of the package @code{System.Dim.Mks}, | 22635 use of one of the instantiations of the package @code{System.Dim.Generic_Mks}, which |
22641 which is part of the GNAT library. This | 22636 are part of the GNAT library. This generic package defines a floating-point |
22642 package defines a floating-point type @code{MKS_Type}, | 22637 type @code{MKS_Type}, for which a sequence of dimension names are specified, |
22643 for which a sequence of | 22638 together with their conventional abbreviations. The following should be read |
22644 dimension names are specified, together with their conventional abbreviations. | 22639 together with the full specification of the package, in file |
22645 The following should be read together with the full specification of the | 22640 @code{s-digemk.ads}. |
22646 package, in file @code{s-dimmks.ads}. | |
22647 | 22641 |
22648 @quotation | 22642 @quotation |
22649 | 22643 |
22650 @geindex s-dimmks.ads file | 22644 @geindex s-digemk.ads file |
22651 | 22645 |
22652 @example | 22646 @example |
22653 type Mks_Type is new Long_Long_Float | 22647 type Mks_Type is new Float_Type |
22654 with | 22648 with |
22655 Dimension_System => ( | 22649 Dimension_System => ( |
22656 (Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'), | 22650 (Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'), |
22657 (Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M'), | 22651 (Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M'), |
22658 (Unit_Name => Second, Unit_Symbol => 's', Dim_Symbol => 'T'), | 22652 (Unit_Name => Second, Unit_Symbol => 's', Dim_Symbol => 'T'), |
22703 day : constant Time := 60.0 * 24.0 * min; | 22697 day : constant Time := 60.0 * 24.0 * min; |
22704 ... | 22698 ... |
22705 @end example | 22699 @end example |
22706 @end quotation | 22700 @end quotation |
22707 | 22701 |
22708 Using this package, you can then define a derived unit by | 22702 There are three instantiations of @code{System.Dim.Generic_Mks} defined in the |
22709 providing the aspect that | 22703 GNAT library: |
22710 specifies its dimensions within the MKS system, as well as the string to | 22704 |
22711 be used for output of a value of that unit: | 22705 |
22706 @itemize * | |
22707 | |
22708 @item | |
22709 @code{System.Dim.Float_Mks} based on @code{Float} defined in @code{s-diflmk.ads}. | |
22710 | |
22711 @item | |
22712 @code{System.Dim.Long_Mks} based on @code{Long_Float} defined in @code{s-dilomk.ads}. | |
22713 | |
22714 @item | |
22715 @code{System.Dim.Mks} based on @code{Long_Long_Float} defined in @code{s-dimmks.ads}. | |
22716 @end itemize | |
22717 | |
22718 Using one of these packages, you can then define a derived unit by providing | |
22719 the aspect that specifies its dimensions within the MKS system, as well as the | |
22720 string to be used for output of a value of that unit: | |
22712 | 22721 |
22713 @quotation | 22722 @quotation |
22714 | 22723 |
22715 @example | 22724 @example |
22716 subtype Acceleration is Mks_Type | 22725 subtype Acceleration is Mks_Type |
22975 requires @code{DV(Source)} = @code{DV(Target)}, and analogously for parameter | 22984 requires @code{DV(Source)} = @code{DV(Target)}, and analogously for parameter |
22976 passing (the dimension vector for the actual parameter must be equal to the | 22985 passing (the dimension vector for the actual parameter must be equal to the |
22977 dimension vector for the formal parameter). | 22986 dimension vector for the formal parameter). |
22978 | 22987 |
22979 @node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution | 22988 @node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution |
22980 @anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{29}@anchor{gnat_ugn/gnat_and_program_execution id62}@anchor{16c} | 22989 @anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{16b}@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{29} |
22981 @section Stack Related Facilities | 22990 @section Stack Related Facilities |
22982 | 22991 |
22983 | 22992 |
22984 This section describes some useful tools associated with stack | 22993 This section describes some useful tools associated with stack |
22985 checking and analysis. In | 22994 checking and analysis. In |
22991 * Dynamic Stack Usage Analysis:: | 23000 * Dynamic Stack Usage Analysis:: |
22992 | 23001 |
22993 @end menu | 23002 @end menu |
22994 | 23003 |
22995 @node Stack Overflow Checking,Static Stack Usage Analysis,,Stack Related Facilities | 23004 @node Stack Overflow Checking,Static Stack Usage Analysis,,Stack Related Facilities |
22996 @anchor{gnat_ugn/gnat_and_program_execution id63}@anchor{1ca}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{f4} | 23005 @anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1c4}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{f4} |
22997 @subsection Stack Overflow Checking | 23006 @subsection Stack Overflow Checking |
22998 | 23007 |
22999 | 23008 |
23000 @geindex Stack Overflow Checking | 23009 @geindex Stack Overflow Checking |
23001 | 23010 |
23026 Units compiled with this option will generate extra instructions to check | 23035 Units compiled with this option will generate extra instructions to check |
23027 that any use of the stack (for procedure calls or for declaring local | 23036 that any use of the stack (for procedure calls or for declaring local |
23028 variables in declare blocks) does not exceed the available stack space. | 23037 variables in declare blocks) does not exceed the available stack space. |
23029 If the space is exceeded, then a @code{Storage_Error} exception is raised. | 23038 If the space is exceeded, then a @code{Storage_Error} exception is raised. |
23030 | 23039 |
23031 For declared tasks, the stack size is controlled by the size | 23040 For declared tasks, the default stack size is defined by the GNAT runtime, |
23032 given in an applicable @code{Storage_Size} pragma or by the value specified | 23041 whose size may be modified at bind time through the @code{-d} bind switch |
23033 at bind time with @code{-d} (@ref{11f,,Switches for gnatbind}) or is set to | 23042 (@ref{11f,,Switches for gnatbind}). Task specific stack sizes may be set using the |
23034 the default size as defined in the GNAT runtime otherwise. | 23043 @code{Storage_Size} pragma. |
23035 | 23044 |
23036 @geindex GNAT_STACK_LIMIT | 23045 For the environment task, the stack size is determined by the operating system. |
23037 | 23046 Consequently, to modify the size of the environment task please refer to your |
23038 For the environment task, the stack size depends on | 23047 operating system documentation. |
23039 system defaults and is unknown to the compiler. Stack checking | |
23040 may still work correctly if a fixed | |
23041 size stack is allocated, but this cannot be guaranteed. | |
23042 To ensure that a clean exception is signalled for stack | |
23043 overflow, set the environment variable | |
23044 @geindex GNAT_STACK_LIMIT | |
23045 @geindex environment variable; GNAT_STACK_LIMIT | |
23046 @code{GNAT_STACK_LIMIT} to indicate the maximum | |
23047 stack area that can be used, as in: | |
23048 | |
23049 @quotation | |
23050 | |
23051 @example | |
23052 $ SET GNAT_STACK_LIMIT 1600 | |
23053 @end example | |
23054 @end quotation | |
23055 | |
23056 The limit is given in kilobytes, so the above declaration would | |
23057 set the stack limit of the environment task to 1.6 megabytes. | |
23058 Note that the only purpose of this usage is to limit the amount | |
23059 of stack used by the environment task. If it is necessary to | |
23060 increase the amount of stack for the environment task, then this | |
23061 is an operating systems issue, and must be addressed with the | |
23062 appropriate operating systems commands. | |
23063 | 23048 |
23064 @node Static Stack Usage Analysis,Dynamic Stack Usage Analysis,Stack Overflow Checking,Stack Related Facilities | 23049 @node Static Stack Usage Analysis,Dynamic Stack Usage Analysis,Stack Overflow Checking,Stack Related Facilities |
23065 @anchor{gnat_ugn/gnat_and_program_execution id64}@anchor{1cb}@anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{f5} | 23050 @anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{f5}@anchor{gnat_ugn/gnat_and_program_execution id59}@anchor{1c5} |
23066 @subsection Static Stack Usage Analysis | 23051 @subsection Static Stack Usage Analysis |
23067 | 23052 |
23068 | 23053 |
23069 @geindex Static Stack Usage Analysis | 23054 @geindex Static Stack Usage Analysis |
23070 | 23055 |
23109 A unit compiled with @code{-Wstack-usage} will issue a warning for each | 23094 A unit compiled with @code{-Wstack-usage} will issue a warning for each |
23110 subprogram whose stack usage might be larger than the specified amount of | 23095 subprogram whose stack usage might be larger than the specified amount of |
23111 bytes. The wording is in keeping with the qualifier documented above. | 23096 bytes. The wording is in keeping with the qualifier documented above. |
23112 | 23097 |
23113 @node Dynamic Stack Usage Analysis,,Static Stack Usage Analysis,Stack Related Facilities | 23098 @node Dynamic Stack Usage Analysis,,Static Stack Usage Analysis,Stack Related Facilities |
23114 @anchor{gnat_ugn/gnat_and_program_execution id65}@anchor{1cc}@anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{121} | 23099 @anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{121}@anchor{gnat_ugn/gnat_and_program_execution id60}@anchor{1c6} |
23115 @subsection Dynamic Stack Usage Analysis | 23100 @subsection Dynamic Stack Usage Analysis |
23116 | 23101 |
23117 | 23102 |
23118 It is possible to measure the maximum amount of stack used by a task, by | 23103 It is possible to measure the maximum amount of stack used by a task, by |
23119 adding a switch to @code{gnatbind}, as: | 23104 adding a switch to @code{gnatbind}, as: |
23169 In order to prevent overflow, the stack | 23154 In order to prevent overflow, the stack |
23170 is not entirely analyzed, and it's not possible to know exactly how | 23155 is not entirely analyzed, and it's not possible to know exactly how |
23171 much has actually been used. | 23156 much has actually been used. |
23172 @end itemize | 23157 @end itemize |
23173 | 23158 |
23174 The environment task stack, e.g., the stack that contains the main unit, is | 23159 By default the environment task stack, the stack that contains the main unit, |
23175 only processed when the environment variable GNAT_STACK_LIMIT is set. | 23160 is not processed. To enable processing of the environment task stack, the |
23161 environment variable GNAT_STACK_LIMIT needs to be set to the maximum size of | |
23162 the environment task stack. This amount is given in kilobytes. For example: | |
23163 | |
23164 @quotation | |
23165 | |
23166 @example | |
23167 $ set GNAT_STACK_LIMIT 1600 | |
23168 @end example | |
23169 @end quotation | |
23170 | |
23171 would specify to the analyzer that the environment task stack has a limit | |
23172 of 1.6 megabytes. Any stack usage beyond this will be ignored by the analysis. | |
23176 | 23173 |
23177 The package @code{GNAT.Task_Stack_Usage} provides facilities to get | 23174 The package @code{GNAT.Task_Stack_Usage} provides facilities to get |
23178 stack usage reports at run-time. See its body for the details. | 23175 stack-usage reports at run time. See its body for the details. |
23179 | 23176 |
23180 @node Memory Management Issues,,Stack Related Facilities,GNAT and Program Execution | 23177 @node Memory Management Issues,,Stack Related Facilities,GNAT and Program Execution |
23181 @anchor{gnat_ugn/gnat_and_program_execution id66}@anchor{16d}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{2a} | 23178 @anchor{gnat_ugn/gnat_and_program_execution id61}@anchor{16c}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{2a} |
23182 @section Memory Management Issues | 23179 @section Memory Management Issues |
23183 | 23180 |
23184 | 23181 |
23185 This section describes some useful memory pools provided in the GNAT library | 23182 This section describes some useful memory pools provided in the GNAT library |
23186 and in particular the GNAT Debug Pool facility, which can be used to detect | 23183 and in particular the GNAT Debug Pool facility, which can be used to detect |
23192 * The GNAT Debug Pool Facility:: | 23189 * The GNAT Debug Pool Facility:: |
23193 | 23190 |
23194 @end menu | 23191 @end menu |
23195 | 23192 |
23196 @node Some Useful Memory Pools,The GNAT Debug Pool Facility,,Memory Management Issues | 23193 @node Some Useful Memory Pools,The GNAT Debug Pool Facility,,Memory Management Issues |
23197 @anchor{gnat_ugn/gnat_and_program_execution id67}@anchor{1cd}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1ce} | 23194 @anchor{gnat_ugn/gnat_and_program_execution id62}@anchor{1c7}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1c8} |
23198 @subsection Some Useful Memory Pools | 23195 @subsection Some Useful Memory Pools |
23199 | 23196 |
23200 | 23197 |
23201 @geindex Memory Pool | 23198 @geindex Memory Pool |
23202 | 23199 |
23273 for T1'Storage_Size use 10_000; | 23270 for T1'Storage_Size use 10_000; |
23274 @end example | 23271 @end example |
23275 @end quotation | 23272 @end quotation |
23276 | 23273 |
23277 @node The GNAT Debug Pool Facility,,Some Useful Memory Pools,Memory Management Issues | 23274 @node The GNAT Debug Pool Facility,,Some Useful Memory Pools,Memory Management Issues |
23278 @anchor{gnat_ugn/gnat_and_program_execution id68}@anchor{1cf}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1d0} | 23275 @anchor{gnat_ugn/gnat_and_program_execution id63}@anchor{1c9}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1ca} |
23279 @subsection The GNAT Debug Pool Facility | 23276 @subsection The GNAT Debug Pool Facility |
23280 | 23277 |
23281 | 23278 |
23282 @geindex Debug Pool | 23279 @geindex Debug Pool |
23283 | 23280 |
23436 | 23433 |
23437 @c -- Non-breaking space in running text | 23434 @c -- Non-breaking space in running text |
23438 @c -- E.g. Ada |nbsp| 95 | 23435 @c -- E.g. Ada |nbsp| 95 |
23439 | 23436 |
23440 @node Platform-Specific Information,Example of Binder Output File,GNAT and Program Execution,Top | 23437 @node Platform-Specific Information,Example of Binder Output File,GNAT and Program Execution,Top |
23441 @anchor{gnat_ugn/platform_specific_information platform-specific-information}@anchor{d}@anchor{gnat_ugn/platform_specific_information doc}@anchor{1d1}@anchor{gnat_ugn/platform_specific_information id1}@anchor{1d2} | 23438 @anchor{gnat_ugn/platform_specific_information platform-specific-information}@anchor{d}@anchor{gnat_ugn/platform_specific_information doc}@anchor{1cb}@anchor{gnat_ugn/platform_specific_information id1}@anchor{1cc} |
23442 @chapter Platform-Specific Information | 23439 @chapter Platform-Specific Information |
23443 | 23440 |
23444 | 23441 |
23445 This appendix contains information relating to the implementation | 23442 This appendix contains information relating to the implementation |
23446 of run-time libraries on various platforms and also covers | 23443 of run-time libraries on various platforms and also covers |
23447 topics related to the GNAT implementation on Windows and Mac OS. | 23444 topics related to the GNAT implementation on Windows and Mac OS. |
23448 | 23445 |
23449 @menu | 23446 @menu |
23450 * Run-Time Libraries:: | 23447 * Run-Time Libraries:: |
23451 * Specifying a Run-Time Library:: | 23448 * Specifying a Run-Time Library:: |
23449 * GNU/Linux Topics:: | |
23452 * Microsoft Windows Topics:: | 23450 * Microsoft Windows Topics:: |
23453 * Mac OS Topics:: | 23451 * Mac OS Topics:: |
23454 | 23452 |
23455 @end menu | 23453 @end menu |
23456 | 23454 |
23457 @node Run-Time Libraries,Specifying a Run-Time Library,,Platform-Specific Information | 23455 @node Run-Time Libraries,Specifying a Run-Time Library,,Platform-Specific Information |
23458 @anchor{gnat_ugn/platform_specific_information id2}@anchor{1d3}@anchor{gnat_ugn/platform_specific_information run-time-libraries}@anchor{2b} | 23456 @anchor{gnat_ugn/platform_specific_information id2}@anchor{1cd}@anchor{gnat_ugn/platform_specific_information run-time-libraries}@anchor{2b} |
23459 @section Run-Time Libraries | 23457 @section Run-Time Libraries |
23460 | 23458 |
23461 | 23459 |
23462 @geindex Tasking and threads libraries | 23460 @geindex Tasking and threads libraries |
23463 | 23461 |
23514 * Summary of Run-Time Configurations:: | 23512 * Summary of Run-Time Configurations:: |
23515 | 23513 |
23516 @end menu | 23514 @end menu |
23517 | 23515 |
23518 @node Summary of Run-Time Configurations,,,Run-Time Libraries | 23516 @node Summary of Run-Time Configurations,,,Run-Time Libraries |
23519 @anchor{gnat_ugn/platform_specific_information summary-of-run-time-configurations}@anchor{1d4}@anchor{gnat_ugn/platform_specific_information id3}@anchor{1d5} | 23517 @anchor{gnat_ugn/platform_specific_information summary-of-run-time-configurations}@anchor{1ce}@anchor{gnat_ugn/platform_specific_information id3}@anchor{1cf} |
23520 @subsection Summary of Run-Time Configurations | 23518 @subsection Summary of Run-Time Configurations |
23521 | 23519 |
23522 | 23520 |
23523 | 23521 |
23524 @multitable {xxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxx} | 23522 @multitable {xxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxx} |
23613 ZCX | 23611 ZCX |
23614 | 23612 |
23615 @end multitable | 23613 @end multitable |
23616 | 23614 |
23617 | 23615 |
23618 @node Specifying a Run-Time Library,Microsoft Windows Topics,Run-Time Libraries,Platform-Specific Information | 23616 @node Specifying a Run-Time Library,GNU/Linux Topics,Run-Time Libraries,Platform-Specific Information |
23619 @anchor{gnat_ugn/platform_specific_information specifying-a-run-time-library}@anchor{1d6}@anchor{gnat_ugn/platform_specific_information id4}@anchor{1d7} | 23617 @anchor{gnat_ugn/platform_specific_information specifying-a-run-time-library}@anchor{1d0}@anchor{gnat_ugn/platform_specific_information id4}@anchor{1d1} |
23620 @section Specifying a Run-Time Library | 23618 @section Specifying a Run-Time Library |
23621 | 23619 |
23622 | 23620 |
23623 The @code{adainclude} subdirectory containing the sources of the GNAT | 23621 The @code{adainclude} subdirectory containing the sources of the GNAT |
23624 run-time library, and the @code{adalib} subdirectory containing the | 23622 run-time library, and the @code{adalib} subdirectory containing the |
23701 | 23699 |
23702 @geindex --RTS option | 23700 @geindex --RTS option |
23703 | 23701 |
23704 Selecting another run-time library temporarily can be | 23702 Selecting another run-time library temporarily can be |
23705 achieved by using the @code{--RTS} switch, e.g., @code{--RTS=sjlj} | 23703 achieved by using the @code{--RTS} switch, e.g., @code{--RTS=sjlj} |
23706 @anchor{gnat_ugn/platform_specific_information choosing-the-scheduling-policy}@anchor{1d8} | 23704 @anchor{gnat_ugn/platform_specific_information choosing-the-scheduling-policy}@anchor{1d2} |
23707 @geindex SCHED_FIFO scheduling policy | 23705 @geindex SCHED_FIFO scheduling policy |
23708 | 23706 |
23709 @geindex SCHED_RR scheduling policy | 23707 @geindex SCHED_RR scheduling policy |
23710 | 23708 |
23711 @geindex SCHED_OTHER scheduling policy | 23709 @geindex SCHED_OTHER scheduling policy |
23714 * Choosing the Scheduling Policy:: | 23712 * Choosing the Scheduling Policy:: |
23715 | 23713 |
23716 @end menu | 23714 @end menu |
23717 | 23715 |
23718 @node Choosing the Scheduling Policy,,,Specifying a Run-Time Library | 23716 @node Choosing the Scheduling Policy,,,Specifying a Run-Time Library |
23719 @anchor{gnat_ugn/platform_specific_information id5}@anchor{1d9} | 23717 @anchor{gnat_ugn/platform_specific_information id5}@anchor{1d3} |
23720 @subsection Choosing the Scheduling Policy | 23718 @subsection Choosing the Scheduling Policy |
23721 | 23719 |
23722 | 23720 |
23723 When using a POSIX threads implementation, you have a choice of several | 23721 When using a POSIX threads implementation, you have a choice of several |
23724 scheduling policies: @code{SCHED_FIFO}, @code{SCHED_RR} and @code{SCHED_OTHER}. | 23722 scheduling policies: @code{SCHED_FIFO}, @code{SCHED_RR} and @code{SCHED_OTHER}. |
23768 @end quotation | 23766 @end quotation |
23769 | 23767 |
23770 It gets the effective user id, and if it's not 0 (i.e. root), it raises | 23768 It gets the effective user id, and if it's not 0 (i.e. root), it raises |
23771 Program_Error. | 23769 Program_Error. |
23772 | 23770 |
23771 @geindex Linux | |
23772 | |
23773 @geindex GNU/Linux | |
23774 | |
23775 @node GNU/Linux Topics,Microsoft Windows Topics,Specifying a Run-Time Library,Platform-Specific Information | |
23776 @anchor{gnat_ugn/platform_specific_information id6}@anchor{1d4}@anchor{gnat_ugn/platform_specific_information gnu-linux-topics}@anchor{1d5} | |
23777 @section GNU/Linux Topics | |
23778 | |
23779 | |
23780 This section describes topics that are specific to GNU/Linux platforms. | |
23781 | |
23782 @menu | |
23783 * Required Packages on GNU/Linux:: | |
23784 | |
23785 @end menu | |
23786 | |
23787 @node Required Packages on GNU/Linux,,,GNU/Linux Topics | |
23788 @anchor{gnat_ugn/platform_specific_information id7}@anchor{1d6}@anchor{gnat_ugn/platform_specific_information required-packages-on-gnu-linux}@anchor{1d7} | |
23789 @subsection Required Packages on GNU/Linux | |
23790 | |
23791 | |
23792 GNAT requires the C library developer's package to be installed. | |
23793 The name of of that package depends on your GNU/Linux distribution: | |
23794 | |
23795 | |
23796 @itemize * | |
23797 | |
23798 @item | |
23799 RedHat, SUSE: @code{glibc-devel}; | |
23800 | |
23801 @item | |
23802 Debian, Ubuntu: @code{libc6-dev} (normally installed by default). | |
23803 @end itemize | |
23804 | |
23805 If using the 32-bit version of GNAT on a 64-bit version of GNU/Linux, | |
23806 you'll need the 32-bit version of the following packages: | |
23807 | |
23808 | |
23809 @itemize * | |
23810 | |
23811 @item | |
23812 RedHat, SUSE: @code{glibc.i686}, @code{glibc-devel.i686}, @code{ncurses-libs.i686} | |
23813 | |
23814 @item | |
23815 Debian, Ubuntu: @code{libc6:i386}, @code{libc6-dev:i386}, @code{lib32ncursesw5} | |
23816 @end itemize | |
23817 | |
23818 Other GNU/Linux distributions might be choosing a different name | |
23819 for those packages. | |
23820 | |
23773 @geindex Windows | 23821 @geindex Windows |
23774 | 23822 |
23775 @node Microsoft Windows Topics,Mac OS Topics,Specifying a Run-Time Library,Platform-Specific Information | 23823 @node Microsoft Windows Topics,Mac OS Topics,GNU/Linux Topics,Platform-Specific Information |
23776 @anchor{gnat_ugn/platform_specific_information id6}@anchor{1da}@anchor{gnat_ugn/platform_specific_information microsoft-windows-topics}@anchor{2c} | 23824 @anchor{gnat_ugn/platform_specific_information microsoft-windows-topics}@anchor{2c}@anchor{gnat_ugn/platform_specific_information id8}@anchor{1d8} |
23777 @section Microsoft Windows Topics | 23825 @section Microsoft Windows Topics |
23778 | 23826 |
23779 | 23827 |
23780 This section describes topics that are specific to the Microsoft Windows | 23828 This section describes topics that are specific to the Microsoft Windows |
23781 platforms. | 23829 platforms. |
23794 * Windows Specific Add-Ons:: | 23842 * Windows Specific Add-Ons:: |
23795 | 23843 |
23796 @end menu | 23844 @end menu |
23797 | 23845 |
23798 @node Using GNAT on Windows,Using a network installation of GNAT,,Microsoft Windows Topics | 23846 @node Using GNAT on Windows,Using a network installation of GNAT,,Microsoft Windows Topics |
23799 @anchor{gnat_ugn/platform_specific_information using-gnat-on-windows}@anchor{1db}@anchor{gnat_ugn/platform_specific_information id7}@anchor{1dc} | 23847 @anchor{gnat_ugn/platform_specific_information using-gnat-on-windows}@anchor{1d9}@anchor{gnat_ugn/platform_specific_information id9}@anchor{1da} |
23800 @subsection Using GNAT on Windows | 23848 @subsection Using GNAT on Windows |
23801 | 23849 |
23802 | 23850 |
23803 One of the strengths of the GNAT technology is that its tool set | 23851 One of the strengths of the GNAT technology is that its tool set |
23804 (@code{gcc}, @code{gnatbind}, @code{gnatlink}, @code{gnatmake}, the | 23852 (@code{gcc}, @code{gnatbind}, @code{gnatlink}, @code{gnatmake}, the |
23871 time, as well as some minimal book-keeping information needed to correctly | 23919 time, as well as some minimal book-keeping information needed to correctly |
23872 uninstall or integrate different GNAT products. | 23920 uninstall or integrate different GNAT products. |
23873 @end itemize | 23921 @end itemize |
23874 | 23922 |
23875 @node Using a network installation of GNAT,CONSOLE and WINDOWS subsystems,Using GNAT on Windows,Microsoft Windows Topics | 23923 @node Using a network installation of GNAT,CONSOLE and WINDOWS subsystems,Using GNAT on Windows,Microsoft Windows Topics |
23876 @anchor{gnat_ugn/platform_specific_information id8}@anchor{1dd}@anchor{gnat_ugn/platform_specific_information using-a-network-installation-of-gnat}@anchor{1de} | 23924 @anchor{gnat_ugn/platform_specific_information id10}@anchor{1db}@anchor{gnat_ugn/platform_specific_information using-a-network-installation-of-gnat}@anchor{1dc} |
23877 @subsection Using a network installation of GNAT | 23925 @subsection Using a network installation of GNAT |
23878 | 23926 |
23879 | 23927 |
23880 Make sure the system on which GNAT is installed is accessible from the | 23928 Make sure the system on which GNAT is installed is accessible from the |
23881 current machine, i.e., the install location is shared over the network. | 23929 current machine, i.e., the install location is shared over the network. |
23898 Be aware that every compilation using the network installation results in the | 23946 Be aware that every compilation using the network installation results in the |
23899 transfer of large amounts of data across the network and will likely cause | 23947 transfer of large amounts of data across the network and will likely cause |
23900 serious performance penalty. | 23948 serious performance penalty. |
23901 | 23949 |
23902 @node CONSOLE and WINDOWS subsystems,Temporary Files,Using a network installation of GNAT,Microsoft Windows Topics | 23950 @node CONSOLE and WINDOWS subsystems,Temporary Files,Using a network installation of GNAT,Microsoft Windows Topics |
23903 @anchor{gnat_ugn/platform_specific_information console-and-windows-subsystems}@anchor{1df}@anchor{gnat_ugn/platform_specific_information id9}@anchor{1e0} | 23951 @anchor{gnat_ugn/platform_specific_information id11}@anchor{1dd}@anchor{gnat_ugn/platform_specific_information console-and-windows-subsystems}@anchor{1de} |
23904 @subsection CONSOLE and WINDOWS subsystems | 23952 @subsection CONSOLE and WINDOWS subsystems |
23905 | 23953 |
23906 | 23954 |
23907 @geindex CONSOLE Subsystem | 23955 @geindex CONSOLE Subsystem |
23908 | 23956 |
23923 $ gnatmake winprog -largs -mwindows | 23971 $ gnatmake winprog -largs -mwindows |
23924 @end example | 23972 @end example |
23925 @end quotation | 23973 @end quotation |
23926 | 23974 |
23927 @node Temporary Files,Disabling Command Line Argument Expansion,CONSOLE and WINDOWS subsystems,Microsoft Windows Topics | 23975 @node Temporary Files,Disabling Command Line Argument Expansion,CONSOLE and WINDOWS subsystems,Microsoft Windows Topics |
23928 @anchor{gnat_ugn/platform_specific_information id10}@anchor{1e1}@anchor{gnat_ugn/platform_specific_information temporary-files}@anchor{1e2} | 23976 @anchor{gnat_ugn/platform_specific_information id12}@anchor{1df}@anchor{gnat_ugn/platform_specific_information temporary-files}@anchor{1e0} |
23929 @subsection Temporary Files | 23977 @subsection Temporary Files |
23930 | 23978 |
23931 | 23979 |
23932 @geindex Temporary files | 23980 @geindex Temporary files |
23933 | 23981 |
23962 file will be created. This is particularly useful in networked | 24010 file will be created. This is particularly useful in networked |
23963 environments where you may not have write access to some | 24011 environments where you may not have write access to some |
23964 directories. | 24012 directories. |
23965 | 24013 |
23966 @node Disabling Command Line Argument Expansion,Mixed-Language Programming on Windows,Temporary Files,Microsoft Windows Topics | 24014 @node Disabling Command Line Argument Expansion,Mixed-Language Programming on Windows,Temporary Files,Microsoft Windows Topics |
23967 @anchor{gnat_ugn/platform_specific_information disabling-command-line-argument-expansion}@anchor{1e3} | 24015 @anchor{gnat_ugn/platform_specific_information disabling-command-line-argument-expansion}@anchor{1e1} |
23968 @subsection Disabling Command Line Argument Expansion | 24016 @subsection Disabling Command Line Argument Expansion |
23969 | 24017 |
23970 | 24018 |
23971 @geindex Command Line Argument Expansion | 24019 @geindex Command Line Argument Expansion |
23972 | 24020 |
24033 @example | 24081 @example |
24034 Ada.Command_Line.Argument (1) -> "'*.txt'" | 24082 Ada.Command_Line.Argument (1) -> "'*.txt'" |
24035 @end example | 24083 @end example |
24036 | 24084 |
24037 @node Mixed-Language Programming on Windows,Windows Specific Add-Ons,Disabling Command Line Argument Expansion,Microsoft Windows Topics | 24085 @node Mixed-Language Programming on Windows,Windows Specific Add-Ons,Disabling Command Line Argument Expansion,Microsoft Windows Topics |
24038 @anchor{gnat_ugn/platform_specific_information id11}@anchor{1e4}@anchor{gnat_ugn/platform_specific_information mixed-language-programming-on-windows}@anchor{1e5} | 24086 @anchor{gnat_ugn/platform_specific_information id13}@anchor{1e2}@anchor{gnat_ugn/platform_specific_information mixed-language-programming-on-windows}@anchor{1e3} |
24039 @subsection Mixed-Language Programming on Windows | 24087 @subsection Mixed-Language Programming on Windows |
24040 | 24088 |
24041 | 24089 |
24042 Developing pure Ada applications on Windows is no different than on | 24090 Developing pure Ada applications on Windows is no different than on |
24043 other GNAT-supported platforms. However, when developing or porting an | 24091 other GNAT-supported platforms. However, when developing or porting an |
24055 | 24103 |
24056 @item | 24104 @item |
24057 Encapsulate your C++ code in a DLL to be linked with your Ada | 24105 Encapsulate your C++ code in a DLL to be linked with your Ada |
24058 application. In this case, use the Microsoft or whatever environment to | 24106 application. In this case, use the Microsoft or whatever environment to |
24059 build the DLL and use GNAT to build your executable | 24107 build the DLL and use GNAT to build your executable |
24060 (@ref{1e6,,Using DLLs with GNAT}). | 24108 (@ref{1e4,,Using DLLs with GNAT}). |
24061 | 24109 |
24062 @item | 24110 @item |
24063 Or you can encapsulate your Ada code in a DLL to be linked with the | 24111 Or you can encapsulate your Ada code in a DLL to be linked with the |
24064 other part of your application. In this case, use GNAT to build the DLL | 24112 other part of your application. In this case, use GNAT to build the DLL |
24065 (@ref{1e7,,Building DLLs with GNAT Project files}) and use the Microsoft | 24113 (@ref{1e5,,Building DLLs with GNAT Project files}) and use the Microsoft |
24066 or whatever environment to build your executable. | 24114 or whatever environment to build your executable. |
24067 @end itemize | 24115 @end itemize |
24068 | 24116 |
24069 In addition to the description about C main in | 24117 In addition to the description about C main in |
24070 @ref{44,,Mixed Language Programming} section, if the C main uses a | 24118 @ref{44,,Mixed Language Programming} section, if the C main uses a |
24117 * Setting Heap Size from gnatlink:: | 24165 * Setting Heap Size from gnatlink:: |
24118 | 24166 |
24119 @end menu | 24167 @end menu |
24120 | 24168 |
24121 @node Windows Calling Conventions,Introduction to Dynamic Link Libraries DLLs,,Mixed-Language Programming on Windows | 24169 @node Windows Calling Conventions,Introduction to Dynamic Link Libraries DLLs,,Mixed-Language Programming on Windows |
24122 @anchor{gnat_ugn/platform_specific_information windows-calling-conventions}@anchor{1e8}@anchor{gnat_ugn/platform_specific_information id12}@anchor{1e9} | 24170 @anchor{gnat_ugn/platform_specific_information windows-calling-conventions}@anchor{1e6}@anchor{gnat_ugn/platform_specific_information id14}@anchor{1e7} |
24123 @subsubsection Windows Calling Conventions | 24171 @subsubsection Windows Calling Conventions |
24124 | 24172 |
24125 | 24173 |
24126 @geindex Stdcall | 24174 @geindex Stdcall |
24127 | 24175 |
24162 * DLL Calling Convention:: | 24210 * DLL Calling Convention:: |
24163 | 24211 |
24164 @end menu | 24212 @end menu |
24165 | 24213 |
24166 @node C Calling Convention,Stdcall Calling Convention,,Windows Calling Conventions | 24214 @node C Calling Convention,Stdcall Calling Convention,,Windows Calling Conventions |
24167 @anchor{gnat_ugn/platform_specific_information c-calling-convention}@anchor{1ea}@anchor{gnat_ugn/platform_specific_information id13}@anchor{1eb} | 24215 @anchor{gnat_ugn/platform_specific_information c-calling-convention}@anchor{1e8}@anchor{gnat_ugn/platform_specific_information id15}@anchor{1e9} |
24168 @subsubsection @code{C} Calling Convention | 24216 @subsubsection @code{C} Calling Convention |
24169 | 24217 |
24170 | 24218 |
24171 This is the default calling convention used when interfacing to C/C++ | 24219 This is the default calling convention used when interfacing to C/C++ |
24172 routines compiled with either @code{gcc} or Microsoft Visual C++. | 24220 routines compiled with either @code{gcc} or Microsoft Visual C++. |
24204 @code{External_Name} with a leading underscore. | 24252 @code{External_Name} with a leading underscore. |
24205 | 24253 |
24206 When importing a variable defined in C, you should always use the @code{C} | 24254 When importing a variable defined in C, you should always use the @code{C} |
24207 calling convention unless the object containing the variable is part of a | 24255 calling convention unless the object containing the variable is part of a |
24208 DLL (in which case you should use the @code{Stdcall} calling | 24256 DLL (in which case you should use the @code{Stdcall} calling |
24209 convention, @ref{1ec,,Stdcall Calling Convention}). | 24257 convention, @ref{1ea,,Stdcall Calling Convention}). |
24210 | 24258 |
24211 @node Stdcall Calling Convention,Win32 Calling Convention,C Calling Convention,Windows Calling Conventions | 24259 @node Stdcall Calling Convention,Win32 Calling Convention,C Calling Convention,Windows Calling Conventions |
24212 @anchor{gnat_ugn/platform_specific_information stdcall-calling-convention}@anchor{1ec}@anchor{gnat_ugn/platform_specific_information id14}@anchor{1ed} | 24260 @anchor{gnat_ugn/platform_specific_information stdcall-calling-convention}@anchor{1ea}@anchor{gnat_ugn/platform_specific_information id16}@anchor{1eb} |
24213 @subsubsection @code{Stdcall} Calling Convention | 24261 @subsubsection @code{Stdcall} Calling Convention |
24214 | 24262 |
24215 | 24263 |
24216 This convention, which was the calling convention used for Pascal | 24264 This convention, which was the calling convention used for Pascal |
24217 programs, is used by Microsoft for all the routines in the Win32 API for | 24265 programs, is used by Microsoft for all the routines in the Win32 API for |
24304 | 24352 |
24305 Note that to ease building cross-platform bindings this convention | 24353 Note that to ease building cross-platform bindings this convention |
24306 will be handled as a @code{C} calling convention on non-Windows platforms. | 24354 will be handled as a @code{C} calling convention on non-Windows platforms. |
24307 | 24355 |
24308 @node Win32 Calling Convention,DLL Calling Convention,Stdcall Calling Convention,Windows Calling Conventions | 24356 @node Win32 Calling Convention,DLL Calling Convention,Stdcall Calling Convention,Windows Calling Conventions |
24309 @anchor{gnat_ugn/platform_specific_information win32-calling-convention}@anchor{1ee}@anchor{gnat_ugn/platform_specific_information id15}@anchor{1ef} | 24357 @anchor{gnat_ugn/platform_specific_information win32-calling-convention}@anchor{1ec}@anchor{gnat_ugn/platform_specific_information id17}@anchor{1ed} |
24310 @subsubsection @code{Win32} Calling Convention | 24358 @subsubsection @code{Win32} Calling Convention |
24311 | 24359 |
24312 | 24360 |
24313 This convention, which is GNAT-specific is fully equivalent to the | 24361 This convention, which is GNAT-specific is fully equivalent to the |
24314 @code{Stdcall} calling convention described above. | 24362 @code{Stdcall} calling convention described above. |
24315 | 24363 |
24316 @node DLL Calling Convention,,Win32 Calling Convention,Windows Calling Conventions | 24364 @node DLL Calling Convention,,Win32 Calling Convention,Windows Calling Conventions |
24317 @anchor{gnat_ugn/platform_specific_information dll-calling-convention}@anchor{1f0}@anchor{gnat_ugn/platform_specific_information id16}@anchor{1f1} | 24365 @anchor{gnat_ugn/platform_specific_information id18}@anchor{1ee}@anchor{gnat_ugn/platform_specific_information dll-calling-convention}@anchor{1ef} |
24318 @subsubsection @code{DLL} Calling Convention | 24366 @subsubsection @code{DLL} Calling Convention |
24319 | 24367 |
24320 | 24368 |
24321 This convention, which is GNAT-specific is fully equivalent to the | 24369 This convention, which is GNAT-specific is fully equivalent to the |
24322 @code{Stdcall} calling convention described above. | 24370 @code{Stdcall} calling convention described above. |
24323 | 24371 |
24324 @node Introduction to Dynamic Link Libraries DLLs,Using DLLs with GNAT,Windows Calling Conventions,Mixed-Language Programming on Windows | 24372 @node Introduction to Dynamic Link Libraries DLLs,Using DLLs with GNAT,Windows Calling Conventions,Mixed-Language Programming on Windows |
24325 @anchor{gnat_ugn/platform_specific_information introduction-to-dynamic-link-libraries-dlls}@anchor{1f2}@anchor{gnat_ugn/platform_specific_information id17}@anchor{1f3} | 24373 @anchor{gnat_ugn/platform_specific_information id19}@anchor{1f0}@anchor{gnat_ugn/platform_specific_information introduction-to-dynamic-link-libraries-dlls}@anchor{1f1} |
24326 @subsubsection Introduction to Dynamic Link Libraries (DLLs) | 24374 @subsubsection Introduction to Dynamic Link Libraries (DLLs) |
24327 | 24375 |
24328 | 24376 |
24329 @geindex DLL | 24377 @geindex DLL |
24330 | 24378 |
24404 | 24452 |
24405 As a side note, an interesting difference between Microsoft DLLs and | 24453 As a side note, an interesting difference between Microsoft DLLs and |
24406 Unix shared libraries, is the fact that on most Unix systems all public | 24454 Unix shared libraries, is the fact that on most Unix systems all public |
24407 routines are exported by default in a Unix shared library, while under | 24455 routines are exported by default in a Unix shared library, while under |
24408 Windows it is possible (but not required) to list exported routines in | 24456 Windows it is possible (but not required) to list exported routines in |
24409 a definition file (see @ref{1f4,,The Definition File}). | 24457 a definition file (see @ref{1f2,,The Definition File}). |
24410 | 24458 |
24411 @node Using DLLs with GNAT,Building DLLs with GNAT Project files,Introduction to Dynamic Link Libraries DLLs,Mixed-Language Programming on Windows | 24459 @node Using DLLs with GNAT,Building DLLs with GNAT Project files,Introduction to Dynamic Link Libraries DLLs,Mixed-Language Programming on Windows |
24412 @anchor{gnat_ugn/platform_specific_information id18}@anchor{1f5}@anchor{gnat_ugn/platform_specific_information using-dlls-with-gnat}@anchor{1e6} | 24460 @anchor{gnat_ugn/platform_specific_information id20}@anchor{1f3}@anchor{gnat_ugn/platform_specific_information using-dlls-with-gnat}@anchor{1e4} |
24413 @subsubsection Using DLLs with GNAT | 24461 @subsubsection Using DLLs with GNAT |
24414 | 24462 |
24415 | 24463 |
24416 To use the services of a DLL, say @code{API.dll}, in your Ada application | 24464 To use the services of a DLL, say @code{API.dll}, in your Ada application |
24417 you must have: | 24465 you must have: |
24498 * Creating an Import Library:: | 24546 * Creating an Import Library:: |
24499 | 24547 |
24500 @end menu | 24548 @end menu |
24501 | 24549 |
24502 @node Creating an Ada Spec for the DLL Services,Creating an Import Library,,Using DLLs with GNAT | 24550 @node Creating an Ada Spec for the DLL Services,Creating an Import Library,,Using DLLs with GNAT |
24503 @anchor{gnat_ugn/platform_specific_information creating-an-ada-spec-for-the-dll-services}@anchor{1f6}@anchor{gnat_ugn/platform_specific_information id19}@anchor{1f7} | 24551 @anchor{gnat_ugn/platform_specific_information id21}@anchor{1f4}@anchor{gnat_ugn/platform_specific_information creating-an-ada-spec-for-the-dll-services}@anchor{1f5} |
24504 @subsubsection Creating an Ada Spec for the DLL Services | 24552 @subsubsection Creating an Ada Spec for the DLL Services |
24505 | 24553 |
24506 | 24554 |
24507 A DLL typically comes with a C/C++ header file which provides the | 24555 A DLL typically comes with a C/C++ header file which provides the |
24508 definitions of the routines and variables exported by the DLL. The Ada | 24556 definitions of the routines and variables exported by the DLL. The Ada |
24538 end API; | 24586 end API; |
24539 @end example | 24587 @end example |
24540 @end quotation | 24588 @end quotation |
24541 | 24589 |
24542 @node Creating an Import Library,,Creating an Ada Spec for the DLL Services,Using DLLs with GNAT | 24590 @node Creating an Import Library,,Creating an Ada Spec for the DLL Services,Using DLLs with GNAT |
24543 @anchor{gnat_ugn/platform_specific_information id20}@anchor{1f8}@anchor{gnat_ugn/platform_specific_information creating-an-import-library}@anchor{1f9} | 24591 @anchor{gnat_ugn/platform_specific_information id22}@anchor{1f6}@anchor{gnat_ugn/platform_specific_information creating-an-import-library}@anchor{1f7} |
24544 @subsubsection Creating an Import Library | 24592 @subsubsection Creating an Import Library |
24545 | 24593 |
24546 | 24594 |
24547 @geindex Import library | 24595 @geindex Import library |
24548 | 24596 |
24552 section if @code{API.dll} or @code{libAPI.dll} is built with GNU tools | 24600 section if @code{API.dll} or @code{libAPI.dll} is built with GNU tools |
24553 as in this case it is possible to link directly against the | 24601 as in this case it is possible to link directly against the |
24554 DLL. Otherwise read on. | 24602 DLL. Otherwise read on. |
24555 | 24603 |
24556 @geindex Definition file | 24604 @geindex Definition file |
24557 @anchor{gnat_ugn/platform_specific_information the-definition-file}@anchor{1f4} | 24605 @anchor{gnat_ugn/platform_specific_information the-definition-file}@anchor{1f2} |
24558 @subsubheading The Definition File | 24606 @subsubheading The Definition File |
24559 | 24607 |
24560 | 24608 |
24561 As previously mentioned, and unlike Unix systems, the list of symbols | 24609 As previously mentioned, and unlike Unix systems, the list of symbols |
24562 that are exported from a DLL must be provided explicitly in Windows. | 24610 that are exported from a DLL must be provided explicitly in Windows. |
24600 get | 24648 get |
24601 @end example | 24649 @end example |
24602 @end table | 24650 @end table |
24603 | 24651 |
24604 Note that you must specify the correct suffix (@code{@@@emph{nn}}) | 24652 Note that you must specify the correct suffix (@code{@@@emph{nn}}) |
24605 (see @ref{1e8,,Windows Calling Conventions}) for a Stdcall | 24653 (see @ref{1e6,,Windows Calling Conventions}) for a Stdcall |
24606 calling convention function in the exported symbols list. | 24654 calling convention function in the exported symbols list. |
24607 | 24655 |
24608 There can actually be other sections in a definition file, but these | 24656 There can actually be other sections in a definition file, but these |
24609 sections are not relevant to the discussion at hand. | 24657 sections are not relevant to the discussion at hand. |
24610 @anchor{gnat_ugn/platform_specific_information create-def-file-automatically}@anchor{1fa} | 24658 @anchor{gnat_ugn/platform_specific_information create-def-file-automatically}@anchor{1f8} |
24611 @subsubheading Creating a Definition File Automatically | 24659 @subsubheading Creating a Definition File Automatically |
24612 | 24660 |
24613 | 24661 |
24614 You can automatically create the definition file @code{API.def} | 24662 You can automatically create the definition file @code{API.def} |
24615 (see @ref{1f4,,The Definition File}) from a DLL. | 24663 (see @ref{1f2,,The Definition File}) from a DLL. |
24616 For that use the @code{dlltool} program as follows: | 24664 For that use the @code{dlltool} program as follows: |
24617 | 24665 |
24618 @quotation | 24666 @quotation |
24619 | 24667 |
24620 @example | 24668 @example |
24621 $ dlltool API.dll -z API.def --export-all-symbols | 24669 $ dlltool API.dll -z API.def --export-all-symbols |
24622 @end example | 24670 @end example |
24623 | 24671 |
24624 Note that if some routines in the DLL have the @code{Stdcall} convention | 24672 Note that if some routines in the DLL have the @code{Stdcall} convention |
24625 (@ref{1e8,,Windows Calling Conventions}) with stripped @code{@@@emph{nn}} | 24673 (@ref{1e6,,Windows Calling Conventions}) with stripped @code{@@@emph{nn}} |
24626 suffix then you'll have to edit @code{api.def} to add it, and specify | 24674 suffix then you'll have to edit @code{api.def} to add it, and specify |
24627 @code{-k} to @code{gnatdll} when creating the import library. | 24675 @code{-k} to @code{gnatdll} when creating the import library. |
24628 | 24676 |
24629 Here are some hints to find the right @code{@@@emph{nn}} suffix. | 24677 Here are some hints to find the right @code{@@@emph{nn}} suffix. |
24630 | 24678 |
24644 If you have a message about a missing symbol at link time the compiler | 24692 If you have a message about a missing symbol at link time the compiler |
24645 tells you what symbol is expected. You just have to go back to the | 24693 tells you what symbol is expected. You just have to go back to the |
24646 definition file and add the right suffix. | 24694 definition file and add the right suffix. |
24647 @end itemize | 24695 @end itemize |
24648 @end quotation | 24696 @end quotation |
24649 @anchor{gnat_ugn/platform_specific_information gnat-style-import-library}@anchor{1fb} | 24697 @anchor{gnat_ugn/platform_specific_information gnat-style-import-library}@anchor{1f9} |
24650 @subsubheading GNAT-Style Import Library | 24698 @subsubheading GNAT-Style Import Library |
24651 | 24699 |
24652 | 24700 |
24653 To create a static import library from @code{API.dll} with the GNAT tools | 24701 To create a static import library from @code{API.dll} with the GNAT tools |
24654 you should create the .def file, then use @code{gnatdll} tool | 24702 you should create the .def file, then use @code{gnatdll} tool |
24655 (see @ref{1fc,,Using gnatdll}) as follows: | 24703 (see @ref{1fa,,Using gnatdll}) as follows: |
24656 | 24704 |
24657 @quotation | 24705 @quotation |
24658 | 24706 |
24659 @example | 24707 @example |
24660 $ gnatdll -e API.def -d API.dll | 24708 $ gnatdll -e API.def -d API.dll |
24666 computed from the name of the definition file as follows: if the | 24714 computed from the name of the definition file as follows: if the |
24667 definition file name is @code{xyz.def}, the import library name will | 24715 definition file name is @code{xyz.def}, the import library name will |
24668 be @code{libxyz.a}. Note that in the previous example option | 24716 be @code{libxyz.a}. Note that in the previous example option |
24669 @code{-e} could have been removed because the name of the definition | 24717 @code{-e} could have been removed because the name of the definition |
24670 file (before the @code{.def} suffix) is the same as the name of the | 24718 file (before the @code{.def} suffix) is the same as the name of the |
24671 DLL (@ref{1fc,,Using gnatdll} for more information about @code{gnatdll}). | 24719 DLL (@ref{1fa,,Using gnatdll} for more information about @code{gnatdll}). |
24672 @end quotation | 24720 @end quotation |
24673 @anchor{gnat_ugn/platform_specific_information msvs-style-import-library}@anchor{1fd} | 24721 @anchor{gnat_ugn/platform_specific_information msvs-style-import-library}@anchor{1fb} |
24674 @subsubheading Microsoft-Style Import Library | 24722 @subsubheading Microsoft-Style Import Library |
24675 | 24723 |
24676 | 24724 |
24677 A Microsoft import library is needed only if you plan to make an | 24725 A Microsoft import library is needed only if you plan to make an |
24678 Ada DLL available to applications developed with Microsoft | 24726 Ada DLL available to applications developed with Microsoft |
24679 tools (@ref{1e5,,Mixed-Language Programming on Windows}). | 24727 tools (@ref{1e3,,Mixed-Language Programming on Windows}). |
24680 | 24728 |
24681 To create a Microsoft-style import library for @code{API.dll} you | 24729 To create a Microsoft-style import library for @code{API.dll} you |
24682 should create the .def file, then build the actual import library using | 24730 should create the .def file, then build the actual import library using |
24683 Microsoft's @code{lib} utility: | 24731 Microsoft's @code{lib} utility: |
24684 | 24732 |
24698 See the Microsoft documentation for further details about the usage of | 24746 See the Microsoft documentation for further details about the usage of |
24699 @code{lib}. | 24747 @code{lib}. |
24700 @end quotation | 24748 @end quotation |
24701 | 24749 |
24702 @node Building DLLs with GNAT Project files,Building DLLs with GNAT,Using DLLs with GNAT,Mixed-Language Programming on Windows | 24750 @node Building DLLs with GNAT Project files,Building DLLs with GNAT,Using DLLs with GNAT,Mixed-Language Programming on Windows |
24703 @anchor{gnat_ugn/platform_specific_information id21}@anchor{1fe}@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat-project-files}@anchor{1e7} | 24751 @anchor{gnat_ugn/platform_specific_information id23}@anchor{1fc}@anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat-project-files}@anchor{1e5} |
24704 @subsubsection Building DLLs with GNAT Project files | 24752 @subsubsection Building DLLs with GNAT Project files |
24705 | 24753 |
24706 | 24754 |
24707 @geindex DLLs | 24755 @geindex DLLs |
24708 @geindex building | 24756 @geindex building |
24714 Due to a system limitation, it is not possible under Windows to create threads | 24762 Due to a system limitation, it is not possible under Windows to create threads |
24715 when inside the @code{DllMain} routine which is used for auto-initialization | 24763 when inside the @code{DllMain} routine which is used for auto-initialization |
24716 of shared libraries, so it is not possible to have library level tasks in SALs. | 24764 of shared libraries, so it is not possible to have library level tasks in SALs. |
24717 | 24765 |
24718 @node Building DLLs with GNAT,Building DLLs with gnatdll,Building DLLs with GNAT Project files,Mixed-Language Programming on Windows | 24766 @node Building DLLs with GNAT,Building DLLs with gnatdll,Building DLLs with GNAT Project files,Mixed-Language Programming on Windows |
24719 @anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat}@anchor{1ff}@anchor{gnat_ugn/platform_specific_information id22}@anchor{200} | 24767 @anchor{gnat_ugn/platform_specific_information building-dlls-with-gnat}@anchor{1fd}@anchor{gnat_ugn/platform_specific_information id24}@anchor{1fe} |
24720 @subsubsection Building DLLs with GNAT | 24768 @subsubsection Building DLLs with GNAT |
24721 | 24769 |
24722 | 24770 |
24723 @geindex DLLs | 24771 @geindex DLLs |
24724 @geindex building | 24772 @geindex building |
24745 @end example | 24793 @end example |
24746 | 24794 |
24747 It is important to note that in this case all symbols found in the | 24795 It is important to note that in this case all symbols found in the |
24748 object files are automatically exported. It is possible to restrict | 24796 object files are automatically exported. It is possible to restrict |
24749 the set of symbols to export by passing to @code{gcc} a definition | 24797 the set of symbols to export by passing to @code{gcc} a definition |
24750 file (see @ref{1f4,,The Definition File}). | 24798 file (see @ref{1f2,,The Definition File}). |
24751 For example: | 24799 For example: |
24752 | 24800 |
24753 @example | 24801 @example |
24754 $ gcc -shared -shared-libgcc -o api.dll api.def obj1.o obj2.o ... | 24802 $ gcc -shared -shared-libgcc -o api.dll api.def obj1.o obj2.o ... |
24755 @end example | 24803 @end example |
24783 $ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI | 24831 $ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI |
24784 @end example | 24832 @end example |
24785 @end quotation | 24833 @end quotation |
24786 | 24834 |
24787 @node Building DLLs with gnatdll,Ada DLLs and Finalization,Building DLLs with GNAT,Mixed-Language Programming on Windows | 24835 @node Building DLLs with gnatdll,Ada DLLs and Finalization,Building DLLs with GNAT,Mixed-Language Programming on Windows |
24788 @anchor{gnat_ugn/platform_specific_information building-dlls-with-gnatdll}@anchor{201}@anchor{gnat_ugn/platform_specific_information id23}@anchor{202} | 24836 @anchor{gnat_ugn/platform_specific_information building-dlls-with-gnatdll}@anchor{1ff}@anchor{gnat_ugn/platform_specific_information id25}@anchor{200} |
24789 @subsubsection Building DLLs with gnatdll | 24837 @subsubsection Building DLLs with gnatdll |
24790 | 24838 |
24791 | 24839 |
24792 @geindex DLLs | 24840 @geindex DLLs |
24793 @geindex building | 24841 @geindex building |
24794 | 24842 |
24795 Note that it is preferred to use GNAT Project files | 24843 Note that it is preferred to use GNAT Project files |
24796 (@ref{1e7,,Building DLLs with GNAT Project files}) or the built-in GNAT | 24844 (@ref{1e5,,Building DLLs with GNAT Project files}) or the built-in GNAT |
24797 DLL support (@ref{1ff,,Building DLLs with GNAT}) or to build DLLs. | 24845 DLL support (@ref{1fd,,Building DLLs with GNAT}) or to build DLLs. |
24798 | 24846 |
24799 This section explains how to build DLLs containing Ada code using | 24847 This section explains how to build DLLs containing Ada code using |
24800 @code{gnatdll}. These DLLs will be referred to as Ada DLLs in the | 24848 @code{gnatdll}. These DLLs will be referred to as Ada DLLs in the |
24801 remainder of this section. | 24849 remainder of this section. |
24802 | 24850 |
24808 | 24856 |
24809 @item | 24857 @item |
24810 You need to mark each Ada entity exported by the DLL with a @code{C} or | 24858 You need to mark each Ada entity exported by the DLL with a @code{C} or |
24811 @code{Stdcall} calling convention to avoid any Ada name mangling for the | 24859 @code{Stdcall} calling convention to avoid any Ada name mangling for the |
24812 entities exported by the DLL | 24860 entities exported by the DLL |
24813 (see @ref{203,,Exporting Ada Entities}). You can | 24861 (see @ref{201,,Exporting Ada Entities}). You can |
24814 skip this step if you plan to use the Ada DLL only from Ada applications. | 24862 skip this step if you plan to use the Ada DLL only from Ada applications. |
24815 | 24863 |
24816 @item | 24864 @item |
24817 Your Ada code must export an initialization routine which calls the routine | 24865 Your Ada code must export an initialization routine which calls the routine |
24818 @code{adainit} generated by @code{gnatbind} to perform the elaboration of | 24866 @code{adainit} generated by @code{gnatbind} to perform the elaboration of |
24819 the Ada code in the DLL (@ref{204,,Ada DLLs and Elaboration}). The initialization | 24867 the Ada code in the DLL (@ref{202,,Ada DLLs and Elaboration}). The initialization |
24820 routine exported by the Ada DLL must be invoked by the clients of the DLL | 24868 routine exported by the Ada DLL must be invoked by the clients of the DLL |
24821 to initialize the DLL. | 24869 to initialize the DLL. |
24822 | 24870 |
24823 @item | 24871 @item |
24824 When useful, the DLL should also export a finalization routine which calls | 24872 When useful, the DLL should also export a finalization routine which calls |
24825 routine @code{adafinal} generated by @code{gnatbind} to perform the | 24873 routine @code{adafinal} generated by @code{gnatbind} to perform the |
24826 finalization of the Ada code in the DLL (@ref{205,,Ada DLLs and Finalization}). | 24874 finalization of the Ada code in the DLL (@ref{203,,Ada DLLs and Finalization}). |
24827 The finalization routine exported by the Ada DLL must be invoked by the | 24875 The finalization routine exported by the Ada DLL must be invoked by the |
24828 clients of the DLL when the DLL services are no further needed. | 24876 clients of the DLL when the DLL services are no further needed. |
24829 | 24877 |
24830 @item | 24878 @item |
24831 You must provide a spec for the services exported by the Ada DLL in each | 24879 You must provide a spec for the services exported by the Ada DLL in each |
24832 of the programming languages to which you plan to make the DLL available. | 24880 of the programming languages to which you plan to make the DLL available. |
24833 | 24881 |
24834 @item | 24882 @item |
24835 You must provide a definition file listing the exported entities | 24883 You must provide a definition file listing the exported entities |
24836 (@ref{1f4,,The Definition File}). | 24884 (@ref{1f2,,The Definition File}). |
24837 | 24885 |
24838 @item | 24886 @item |
24839 Finally you must use @code{gnatdll} to produce the DLL and the import | 24887 Finally you must use @code{gnatdll} to produce the DLL and the import |
24840 library (@ref{1fc,,Using gnatdll}). | 24888 library (@ref{1fa,,Using gnatdll}). |
24841 @end itemize | 24889 @end itemize |
24842 | 24890 |
24843 Note that a relocatable DLL stripped using the @code{strip} | 24891 Note that a relocatable DLL stripped using the @code{strip} |
24844 binutils tool will not be relocatable anymore. To build a DLL without | 24892 binutils tool will not be relocatable anymore. To build a DLL without |
24845 debug information pass @code{-largs -s} to @code{gnatdll}. This | 24893 debug information pass @code{-largs -s} to @code{gnatdll}. This |
24855 * Ada DLLs and Elaboration:: | 24903 * Ada DLLs and Elaboration:: |
24856 | 24904 |
24857 @end menu | 24905 @end menu |
24858 | 24906 |
24859 @node Limitations When Using Ada DLLs from Ada,Exporting Ada Entities,,Building DLLs with gnatdll | 24907 @node Limitations When Using Ada DLLs from Ada,Exporting Ada Entities,,Building DLLs with gnatdll |
24860 @anchor{gnat_ugn/platform_specific_information limitations-when-using-ada-dlls-from-ada}@anchor{206} | 24908 @anchor{gnat_ugn/platform_specific_information limitations-when-using-ada-dlls-from-ada}@anchor{204} |
24861 @subsubsection Limitations When Using Ada DLLs from Ada | 24909 @subsubsection Limitations When Using Ada DLLs from Ada |
24862 | 24910 |
24863 | 24911 |
24864 When using Ada DLLs from Ada applications there is a limitation users | 24912 When using Ada DLLs from Ada applications there is a limitation users |
24865 should be aware of. Because on Windows the GNAT run-time is not in a DLL of | 24913 should be aware of. Because on Windows the GNAT run-time is not in a DLL of |
24876 | 24924 |
24877 It is completely safe to exchange plain elementary, array or record types, | 24925 It is completely safe to exchange plain elementary, array or record types, |
24878 Windows object handles, etc. | 24926 Windows object handles, etc. |
24879 | 24927 |
24880 @node Exporting Ada Entities,Ada DLLs and Elaboration,Limitations When Using Ada DLLs from Ada,Building DLLs with gnatdll | 24928 @node Exporting Ada Entities,Ada DLLs and Elaboration,Limitations When Using Ada DLLs from Ada,Building DLLs with gnatdll |
24881 @anchor{gnat_ugn/platform_specific_information exporting-ada-entities}@anchor{203}@anchor{gnat_ugn/platform_specific_information id24}@anchor{207} | 24929 @anchor{gnat_ugn/platform_specific_information exporting-ada-entities}@anchor{201}@anchor{gnat_ugn/platform_specific_information id26}@anchor{205} |
24882 @subsubsection Exporting Ada Entities | 24930 @subsubsection Exporting Ada Entities |
24883 | 24931 |
24884 | 24932 |
24885 @geindex Export table | 24933 @geindex Export table |
24886 | 24934 |
24976 @end quotation | 25024 @end quotation |
24977 | 25025 |
24978 Note that if you do not export the Ada entities with a @code{C} or | 25026 Note that if you do not export the Ada entities with a @code{C} or |
24979 @code{Stdcall} convention you will have to provide the mangled Ada names | 25027 @code{Stdcall} convention you will have to provide the mangled Ada names |
24980 in the definition file of the Ada DLL | 25028 in the definition file of the Ada DLL |
24981 (@ref{208,,Creating the Definition File}). | 25029 (@ref{206,,Creating the Definition File}). |
24982 | 25030 |
24983 @node Ada DLLs and Elaboration,,Exporting Ada Entities,Building DLLs with gnatdll | 25031 @node Ada DLLs and Elaboration,,Exporting Ada Entities,Building DLLs with gnatdll |
24984 @anchor{gnat_ugn/platform_specific_information ada-dlls-and-elaboration}@anchor{204}@anchor{gnat_ugn/platform_specific_information id25}@anchor{209} | 25032 @anchor{gnat_ugn/platform_specific_information ada-dlls-and-elaboration}@anchor{202}@anchor{gnat_ugn/platform_specific_information id27}@anchor{207} |
24985 @subsubsection Ada DLLs and Elaboration | 25033 @subsubsection Ada DLLs and Elaboration |
24986 | 25034 |
24987 | 25035 |
24988 @geindex DLLs and elaboration | 25036 @geindex DLLs and elaboration |
24989 | 25037 |
24997 before using any of the DLL services. This elaboration routine must call | 25045 before using any of the DLL services. This elaboration routine must call |
24998 the Ada elaboration routine @code{adainit} generated by the GNAT binder | 25046 the Ada elaboration routine @code{adainit} generated by the GNAT binder |
24999 (@ref{b4,,Binding with Non-Ada Main Programs}). See the body of | 25047 (@ref{b4,,Binding with Non-Ada Main Programs}). See the body of |
25000 @code{Initialize_Api} for an example. Note that the GNAT binder is | 25048 @code{Initialize_Api} for an example. Note that the GNAT binder is |
25001 automatically invoked during the DLL build process by the @code{gnatdll} | 25049 automatically invoked during the DLL build process by the @code{gnatdll} |
25002 tool (@ref{1fc,,Using gnatdll}). | 25050 tool (@ref{1fa,,Using gnatdll}). |
25003 | 25051 |
25004 When a DLL is loaded, Windows systematically invokes a routine called | 25052 When a DLL is loaded, Windows systematically invokes a routine called |
25005 @code{DllMain}. It would therefore be possible to call @code{adainit} | 25053 @code{DllMain}. It would therefore be possible to call @code{adainit} |
25006 directly from @code{DllMain} without having to provide an explicit | 25054 directly from @code{DllMain} without having to provide an explicit |
25007 initialization routine. Unfortunately, it is not possible to call | 25055 initialization routine. Unfortunately, it is not possible to call |
25010 the system (that is, only a single thread can execute 'through' it at a | 25058 the system (that is, only a single thread can execute 'through' it at a |
25011 time), which means that the GNAT run-time will deadlock waiting for the | 25059 time), which means that the GNAT run-time will deadlock waiting for the |
25012 newly created task to complete its initialization. | 25060 newly created task to complete its initialization. |
25013 | 25061 |
25014 @node Ada DLLs and Finalization,Creating a Spec for Ada DLLs,Building DLLs with gnatdll,Mixed-Language Programming on Windows | 25062 @node Ada DLLs and Finalization,Creating a Spec for Ada DLLs,Building DLLs with gnatdll,Mixed-Language Programming on Windows |
25015 @anchor{gnat_ugn/platform_specific_information ada-dlls-and-finalization}@anchor{205}@anchor{gnat_ugn/platform_specific_information id26}@anchor{20a} | 25063 @anchor{gnat_ugn/platform_specific_information id28}@anchor{208}@anchor{gnat_ugn/platform_specific_information ada-dlls-and-finalization}@anchor{203} |
25016 @subsubsection Ada DLLs and Finalization | 25064 @subsubsection Ada DLLs and Finalization |
25017 | 25065 |
25018 | 25066 |
25019 @geindex DLLs and finalization | 25067 @geindex DLLs and finalization |
25020 | 25068 |
25025 routine @code{adafinal} generated by the GNAT binder | 25073 routine @code{adafinal} generated by the GNAT binder |
25026 (@ref{b4,,Binding with Non-Ada Main Programs}). | 25074 (@ref{b4,,Binding with Non-Ada Main Programs}). |
25027 See the body of @code{Finalize_Api} for an | 25075 See the body of @code{Finalize_Api} for an |
25028 example. As already pointed out the GNAT binder is automatically invoked | 25076 example. As already pointed out the GNAT binder is automatically invoked |
25029 during the DLL build process by the @code{gnatdll} tool | 25077 during the DLL build process by the @code{gnatdll} tool |
25030 (@ref{1fc,,Using gnatdll}). | 25078 (@ref{1fa,,Using gnatdll}). |
25031 | 25079 |
25032 @node Creating a Spec for Ada DLLs,GNAT and Windows Resources,Ada DLLs and Finalization,Mixed-Language Programming on Windows | 25080 @node Creating a Spec for Ada DLLs,GNAT and Windows Resources,Ada DLLs and Finalization,Mixed-Language Programming on Windows |
25033 @anchor{gnat_ugn/platform_specific_information id27}@anchor{20b}@anchor{gnat_ugn/platform_specific_information creating-a-spec-for-ada-dlls}@anchor{20c} | 25081 @anchor{gnat_ugn/platform_specific_information id29}@anchor{209}@anchor{gnat_ugn/platform_specific_information creating-a-spec-for-ada-dlls}@anchor{20a} |
25034 @subsubsection Creating a Spec for Ada DLLs | 25082 @subsubsection Creating a Spec for Ada DLLs |
25035 | 25083 |
25036 | 25084 |
25037 To use the services exported by the Ada DLL from another programming | 25085 To use the services exported by the Ada DLL from another programming |
25038 language (e.g., C), you have to translate the specs of the exported Ada | 25086 language (e.g., C), you have to translate the specs of the exported Ada |
25086 * Using gnatdll:: | 25134 * Using gnatdll:: |
25087 | 25135 |
25088 @end menu | 25136 @end menu |
25089 | 25137 |
25090 @node Creating the Definition File,Using gnatdll,,Creating a Spec for Ada DLLs | 25138 @node Creating the Definition File,Using gnatdll,,Creating a Spec for Ada DLLs |
25091 @anchor{gnat_ugn/platform_specific_information id28}@anchor{20d}@anchor{gnat_ugn/platform_specific_information creating-the-definition-file}@anchor{208} | 25139 @anchor{gnat_ugn/platform_specific_information creating-the-definition-file}@anchor{206}@anchor{gnat_ugn/platform_specific_information id30}@anchor{20b} |
25092 @subsubsection Creating the Definition File | 25140 @subsubsection Creating the Definition File |
25093 | 25141 |
25094 | 25142 |
25095 The definition file is the last file needed to build the DLL. It lists | 25143 The definition file is the last file needed to build the DLL. It lists |
25096 the exported symbols. As an example, the definition file for a DLL | 25144 the exported symbols. As an example, the definition file for a DLL |
25122 api__initialize_api | 25170 api__initialize_api |
25123 @end example | 25171 @end example |
25124 @end quotation | 25172 @end quotation |
25125 | 25173 |
25126 @node Using gnatdll,,Creating the Definition File,Creating a Spec for Ada DLLs | 25174 @node Using gnatdll,,Creating the Definition File,Creating a Spec for Ada DLLs |
25127 @anchor{gnat_ugn/platform_specific_information id29}@anchor{20e}@anchor{gnat_ugn/platform_specific_information using-gnatdll}@anchor{1fc} | 25175 @anchor{gnat_ugn/platform_specific_information using-gnatdll}@anchor{1fa}@anchor{gnat_ugn/platform_specific_information id31}@anchor{20c} |
25128 @subsubsection Using @code{gnatdll} | 25176 @subsubsection Using @code{gnatdll} |
25129 | 25177 |
25130 | 25178 |
25131 @geindex gnatdll | 25179 @geindex gnatdll |
25132 | 25180 |
25333 asks @code{gnatlink} to generate the routines @code{DllMain} and | 25381 asks @code{gnatlink} to generate the routines @code{DllMain} and |
25334 @code{DllMainCRTStartup} that are called by the Windows loader when the DLL | 25382 @code{DllMainCRTStartup} that are called by the Windows loader when the DLL |
25335 is loaded into memory. | 25383 is loaded into memory. |
25336 | 25384 |
25337 @item | 25385 @item |
25338 @code{gnatdll} uses @code{dlltool} (see @ref{20f,,Using dlltool}) to build the | 25386 @code{gnatdll} uses @code{dlltool} (see @ref{20d,,Using dlltool}) to build the |
25339 export table (@code{api.exp}). The export table contains the relocation | 25387 export table (@code{api.exp}). The export table contains the relocation |
25340 information in a form which can be used during the final link to ensure | 25388 information in a form which can be used during the final link to ensure |
25341 that the Windows loader is able to place the DLL anywhere in memory. | 25389 that the Windows loader is able to place the DLL anywhere in memory. |
25342 | 25390 |
25343 @example | 25391 @example |
25372 @example | 25420 @example |
25373 $ gnatbind -n api | 25421 $ gnatbind -n api |
25374 $ gnatlink api api.exp -o api.dll -mdll | 25422 $ gnatlink api api.exp -o api.dll -mdll |
25375 @end example | 25423 @end example |
25376 @end itemize | 25424 @end itemize |
25377 @anchor{gnat_ugn/platform_specific_information using-dlltool}@anchor{20f} | 25425 @anchor{gnat_ugn/platform_specific_information using-dlltool}@anchor{20d} |
25378 @subsubheading Using @code{dlltool} | 25426 @subsubheading Using @code{dlltool} |
25379 | 25427 |
25380 | 25428 |
25381 @code{dlltool} is the low-level tool used by @code{gnatdll} to build | 25429 @code{dlltool} is the low-level tool used by @code{gnatdll} to build |
25382 DLLs and static import libraries. This section summarizes the most | 25430 DLLs and static import libraries. This section summarizes the most |
25431 @table @asis | 25479 @table @asis |
25432 | 25480 |
25433 @item @code{-k} | 25481 @item @code{-k} |
25434 | 25482 |
25435 Kill @code{@@@emph{nn}} from exported names | 25483 Kill @code{@@@emph{nn}} from exported names |
25436 (@ref{1e8,,Windows Calling Conventions} | 25484 (@ref{1e6,,Windows Calling Conventions} |
25437 for a discussion about @code{Stdcall}-style symbols. | 25485 for a discussion about @code{Stdcall}-style symbols. |
25438 @end table | 25486 @end table |
25439 | 25487 |
25440 @geindex --help (dlltool) | 25488 @geindex --help (dlltool) |
25441 | 25489 |
25487 | 25535 |
25488 Use @code{assembler-name} as the assembler. The default is @code{as}. | 25536 Use @code{assembler-name} as the assembler. The default is @code{as}. |
25489 @end table | 25537 @end table |
25490 | 25538 |
25491 @node GNAT and Windows Resources,Using GNAT DLLs from Microsoft Visual Studio Applications,Creating a Spec for Ada DLLs,Mixed-Language Programming on Windows | 25539 @node GNAT and Windows Resources,Using GNAT DLLs from Microsoft Visual Studio Applications,Creating a Spec for Ada DLLs,Mixed-Language Programming on Windows |
25492 @anchor{gnat_ugn/platform_specific_information gnat-and-windows-resources}@anchor{210}@anchor{gnat_ugn/platform_specific_information id30}@anchor{211} | 25540 @anchor{gnat_ugn/platform_specific_information gnat-and-windows-resources}@anchor{20e}@anchor{gnat_ugn/platform_specific_information id32}@anchor{20f} |
25493 @subsubsection GNAT and Windows Resources | 25541 @subsubsection GNAT and Windows Resources |
25494 | 25542 |
25495 | 25543 |
25496 @geindex Resources | 25544 @geindex Resources |
25497 @geindex windows | 25545 @geindex windows |
25582 * Using Resources:: | 25630 * Using Resources:: |
25583 | 25631 |
25584 @end menu | 25632 @end menu |
25585 | 25633 |
25586 @node Building Resources,Compiling Resources,,GNAT and Windows Resources | 25634 @node Building Resources,Compiling Resources,,GNAT and Windows Resources |
25587 @anchor{gnat_ugn/platform_specific_information building-resources}@anchor{212}@anchor{gnat_ugn/platform_specific_information id31}@anchor{213} | 25635 @anchor{gnat_ugn/platform_specific_information building-resources}@anchor{210}@anchor{gnat_ugn/platform_specific_information id33}@anchor{211} |
25588 @subsubsection Building Resources | 25636 @subsubsection Building Resources |
25589 | 25637 |
25590 | 25638 |
25591 @geindex Resources | 25639 @geindex Resources |
25592 @geindex building | 25640 @geindex building |
25602 It is not our objective to explain how to write a resource file. A | 25650 It is not our objective to explain how to write a resource file. A |
25603 complete description of the resource script language can be found in the | 25651 complete description of the resource script language can be found in the |
25604 Microsoft documentation. | 25652 Microsoft documentation. |
25605 | 25653 |
25606 @node Compiling Resources,Using Resources,Building Resources,GNAT and Windows Resources | 25654 @node Compiling Resources,Using Resources,Building Resources,GNAT and Windows Resources |
25607 @anchor{gnat_ugn/platform_specific_information compiling-resources}@anchor{214}@anchor{gnat_ugn/platform_specific_information id32}@anchor{215} | 25655 @anchor{gnat_ugn/platform_specific_information compiling-resources}@anchor{212}@anchor{gnat_ugn/platform_specific_information id34}@anchor{213} |
25608 @subsubsection Compiling Resources | 25656 @subsubsection Compiling Resources |
25609 | 25657 |
25610 | 25658 |
25611 @geindex rc | 25659 @geindex rc |
25612 | 25660 |
25644 $ windres -i myres.res -o myres.o | 25692 $ windres -i myres.res -o myres.o |
25645 @end example | 25693 @end example |
25646 @end quotation | 25694 @end quotation |
25647 | 25695 |
25648 @node Using Resources,,Compiling Resources,GNAT and Windows Resources | 25696 @node Using Resources,,Compiling Resources,GNAT and Windows Resources |
25649 @anchor{gnat_ugn/platform_specific_information using-resources}@anchor{216}@anchor{gnat_ugn/platform_specific_information id33}@anchor{217} | 25697 @anchor{gnat_ugn/platform_specific_information using-resources}@anchor{214}@anchor{gnat_ugn/platform_specific_information id35}@anchor{215} |
25650 @subsubsection Using Resources | 25698 @subsubsection Using Resources |
25651 | 25699 |
25652 | 25700 |
25653 @geindex Resources | 25701 @geindex Resources |
25654 @geindex using | 25702 @geindex using |
25664 $ gnatmake myprog -largs myres.o | 25712 $ gnatmake myprog -largs myres.o |
25665 @end example | 25713 @end example |
25666 @end quotation | 25714 @end quotation |
25667 | 25715 |
25668 @node Using GNAT DLLs from Microsoft Visual Studio Applications,Debugging a DLL,GNAT and Windows Resources,Mixed-Language Programming on Windows | 25716 @node Using GNAT DLLs from Microsoft Visual Studio Applications,Debugging a DLL,GNAT and Windows Resources,Mixed-Language Programming on Windows |
25669 @anchor{gnat_ugn/platform_specific_information using-gnat-dll-from-msvs}@anchor{218}@anchor{gnat_ugn/platform_specific_information using-gnat-dlls-from-microsoft-visual-studio-applications}@anchor{219} | 25717 @anchor{gnat_ugn/platform_specific_information using-gnat-dll-from-msvs}@anchor{216}@anchor{gnat_ugn/platform_specific_information using-gnat-dlls-from-microsoft-visual-studio-applications}@anchor{217} |
25670 @subsubsection Using GNAT DLLs from Microsoft Visual Studio Applications | 25718 @subsubsection Using GNAT DLLs from Microsoft Visual Studio Applications |
25671 | 25719 |
25672 | 25720 |
25673 @geindex Microsoft Visual Studio | 25721 @geindex Microsoft Visual Studio |
25674 @geindex use with GNAT DLLs | 25722 @geindex use with GNAT DLLs |
25698 @enumerate 2 | 25746 @enumerate 2 |
25699 | 25747 |
25700 @item | 25748 @item |
25701 Produce a .def file for the symbols you need to interface with, either by | 25749 Produce a .def file for the symbols you need to interface with, either by |
25702 hand or automatically with possibly some manual adjustments | 25750 hand or automatically with possibly some manual adjustments |
25703 (see @ref{1fa,,Creating Definition File Automatically}): | 25751 (see @ref{1f8,,Creating Definition File Automatically}): |
25704 @end enumerate | 25752 @end enumerate |
25705 | 25753 |
25706 @quotation | 25754 @quotation |
25707 | 25755 |
25708 @example | 25756 @example |
25715 | 25763 |
25716 @item | 25764 @item |
25717 Make sure that MSVS command-line tools are accessible on the path. | 25765 Make sure that MSVS command-line tools are accessible on the path. |
25718 | 25766 |
25719 @item | 25767 @item |
25720 Create the Microsoft-style import library (see @ref{1fd,,MSVS-Style Import Library}): | 25768 Create the Microsoft-style import library (see @ref{1fb,,MSVS-Style Import Library}): |
25721 @end enumerate | 25769 @end enumerate |
25722 | 25770 |
25723 @quotation | 25771 @quotation |
25724 | 25772 |
25725 @example | 25773 @example |
25757 Before running the executable, make sure you have set the PATH to the DLL, | 25805 Before running the executable, make sure you have set the PATH to the DLL, |
25758 or copy the DLL into into the directory containing the .exe. | 25806 or copy the DLL into into the directory containing the .exe. |
25759 @end enumerate | 25807 @end enumerate |
25760 | 25808 |
25761 @node Debugging a DLL,Setting Stack Size from gnatlink,Using GNAT DLLs from Microsoft Visual Studio Applications,Mixed-Language Programming on Windows | 25809 @node Debugging a DLL,Setting Stack Size from gnatlink,Using GNAT DLLs from Microsoft Visual Studio Applications,Mixed-Language Programming on Windows |
25762 @anchor{gnat_ugn/platform_specific_information id34}@anchor{21a}@anchor{gnat_ugn/platform_specific_information debugging-a-dll}@anchor{21b} | 25810 @anchor{gnat_ugn/platform_specific_information id36}@anchor{218}@anchor{gnat_ugn/platform_specific_information debugging-a-dll}@anchor{219} |
25763 @subsubsection Debugging a DLL | 25811 @subsubsection Debugging a DLL |
25764 | 25812 |
25765 | 25813 |
25766 @geindex DLL debugging | 25814 @geindex DLL debugging |
25767 | 25815 |
25795 * Program Built with Foreign Tools and DLL Built with GCC/GNAT:: | 25843 * Program Built with Foreign Tools and DLL Built with GCC/GNAT:: |
25796 | 25844 |
25797 @end menu | 25845 @end menu |
25798 | 25846 |
25799 @node Program and DLL Both Built with GCC/GNAT,Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Debugging a DLL | 25847 @node Program and DLL Both Built with GCC/GNAT,Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Debugging a DLL |
25800 @anchor{gnat_ugn/platform_specific_information program-and-dll-both-built-with-gcc-gnat}@anchor{21c}@anchor{gnat_ugn/platform_specific_information id35}@anchor{21d} | 25848 @anchor{gnat_ugn/platform_specific_information id37}@anchor{21a}@anchor{gnat_ugn/platform_specific_information program-and-dll-both-built-with-gcc-gnat}@anchor{21b} |
25801 @subsubsection Program and DLL Both Built with GCC/GNAT | 25849 @subsubsection Program and DLL Both Built with GCC/GNAT |
25802 | 25850 |
25803 | 25851 |
25804 This is the simplest case. Both the DLL and the program have @code{GDB} | 25852 This is the simplest case. Both the DLL and the program have @code{GDB} |
25805 compatible debugging information. It is then possible to break anywhere in | 25853 compatible debugging information. It is then possible to break anywhere in |
25806 the process. Let's suppose here that the main procedure is named | 25854 the process. Let's suppose here that the main procedure is named |
25807 @code{ada_main} and that in the DLL there is an entry point named | 25855 @code{ada_main} and that in the DLL there is an entry point named |
25808 @code{ada_dll}. | 25856 @code{ada_dll}. |
25809 | 25857 |
25810 The DLL (@ref{1f2,,Introduction to Dynamic Link Libraries (DLLs)}) and | 25858 The DLL (@ref{1f1,,Introduction to Dynamic Link Libraries (DLLs)}) and |
25811 program must have been built with the debugging information (see GNAT -g | 25859 program must have been built with the debugging information (see GNAT -g |
25812 switch). Here are the step-by-step instructions for debugging it: | 25860 switch). Here are the step-by-step instructions for debugging it: |
25813 | 25861 |
25814 | 25862 |
25815 @itemize * | 25863 @itemize * |
25845 At this stage a breakpoint is set inside the DLL. From there on | 25893 At this stage a breakpoint is set inside the DLL. From there on |
25846 you can use the standard approach to debug the whole program | 25894 you can use the standard approach to debug the whole program |
25847 (@ref{24,,Running and Debugging Ada Programs}). | 25895 (@ref{24,,Running and Debugging Ada Programs}). |
25848 | 25896 |
25849 @node Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Program and DLL Both Built with GCC/GNAT,Debugging a DLL | 25897 @node Program Built with Foreign Tools and DLL Built with GCC/GNAT,,Program and DLL Both Built with GCC/GNAT,Debugging a DLL |
25850 @anchor{gnat_ugn/platform_specific_information id36}@anchor{21e}@anchor{gnat_ugn/platform_specific_information program-built-with-foreign-tools-and-dll-built-with-gcc-gnat}@anchor{21f} | 25898 @anchor{gnat_ugn/platform_specific_information program-built-with-foreign-tools-and-dll-built-with-gcc-gnat}@anchor{21c}@anchor{gnat_ugn/platform_specific_information id38}@anchor{21d} |
25851 @subsubsection Program Built with Foreign Tools and DLL Built with GCC/GNAT | 25899 @subsubsection Program Built with Foreign Tools and DLL Built with GCC/GNAT |
25852 | 25900 |
25853 | 25901 |
25854 In this case things are slightly more complex because it is not possible to | 25902 In this case things are slightly more complex because it is not possible to |
25855 start the main program and then break at the beginning to load the DLL and the | 25903 start the main program and then break at the beginning to load the DLL and the |
25862 First suppose that the main procedure is named @code{main} (this is for | 25910 First suppose that the main procedure is named @code{main} (this is for |
25863 example some C code built with Microsoft Visual C) and that there is a | 25911 example some C code built with Microsoft Visual C) and that there is a |
25864 DLL named @code{test.dll} containing an Ada entry point named | 25912 DLL named @code{test.dll} containing an Ada entry point named |
25865 @code{ada_dll}. | 25913 @code{ada_dll}. |
25866 | 25914 |
25867 The DLL (see @ref{1f2,,Introduction to Dynamic Link Libraries (DLLs)}) must have | 25915 The DLL (see @ref{1f1,,Introduction to Dynamic Link Libraries (DLLs)}) must have |
25868 been built with debugging information (see the GNAT @code{-g} option). | 25916 been built with debugging information (see the GNAT @code{-g} option). |
25869 | 25917 |
25870 @subsubheading Debugging the DLL Directly | 25918 @subsubheading Debugging the DLL Directly |
25871 | 25919 |
25872 | 25920 |
26001 the breakpoint we have set. From there you can use the standard | 26049 the breakpoint we have set. From there you can use the standard |
26002 approach to debug a program as described in | 26050 approach to debug a program as described in |
26003 @ref{24,,Running and Debugging Ada Programs}. | 26051 @ref{24,,Running and Debugging Ada Programs}. |
26004 | 26052 |
26005 @node Setting Stack Size from gnatlink,Setting Heap Size from gnatlink,Debugging a DLL,Mixed-Language Programming on Windows | 26053 @node Setting Stack Size from gnatlink,Setting Heap Size from gnatlink,Debugging a DLL,Mixed-Language Programming on Windows |
26006 @anchor{gnat_ugn/platform_specific_information id37}@anchor{220}@anchor{gnat_ugn/platform_specific_information setting-stack-size-from-gnatlink}@anchor{136} | 26054 @anchor{gnat_ugn/platform_specific_information setting-stack-size-from-gnatlink}@anchor{136}@anchor{gnat_ugn/platform_specific_information id39}@anchor{21e} |
26007 @subsubsection Setting Stack Size from @code{gnatlink} | 26055 @subsubsection Setting Stack Size from @code{gnatlink} |
26008 | 26056 |
26009 | 26057 |
26010 It is possible to specify the program stack size at link time. On modern | 26058 It is possible to specify the program stack size at link time. On modern |
26011 versions of Windows, starting with XP, this is mostly useful to set the size of | 26059 versions of Windows, starting with XP, this is mostly useful to set the size of |
26044 @code{-Wl} option it is not possible to set the stack commit size | 26092 @code{-Wl} option it is not possible to set the stack commit size |
26045 because the comma is a separator for this option. | 26093 because the comma is a separator for this option. |
26046 @end itemize | 26094 @end itemize |
26047 | 26095 |
26048 @node Setting Heap Size from gnatlink,,Setting Stack Size from gnatlink,Mixed-Language Programming on Windows | 26096 @node Setting Heap Size from gnatlink,,Setting Stack Size from gnatlink,Mixed-Language Programming on Windows |
26049 @anchor{gnat_ugn/platform_specific_information setting-heap-size-from-gnatlink}@anchor{137}@anchor{gnat_ugn/platform_specific_information id38}@anchor{221} | 26097 @anchor{gnat_ugn/platform_specific_information setting-heap-size-from-gnatlink}@anchor{137}@anchor{gnat_ugn/platform_specific_information id40}@anchor{21f} |
26050 @subsubsection Setting Heap Size from @code{gnatlink} | 26098 @subsubsection Setting Heap Size from @code{gnatlink} |
26051 | 26099 |
26052 | 26100 |
26053 Under Windows systems, it is possible to specify the program heap size from | 26101 Under Windows systems, it is possible to specify the program heap size from |
26054 @code{gnatlink} using either of the following: | 26102 @code{gnatlink} using either of the following: |
26077 @code{-Wl} option it is not possible to set the heap commit size | 26125 @code{-Wl} option it is not possible to set the heap commit size |
26078 because the comma is a separator for this option. | 26126 because the comma is a separator for this option. |
26079 @end itemize | 26127 @end itemize |
26080 | 26128 |
26081 @node Windows Specific Add-Ons,,Mixed-Language Programming on Windows,Microsoft Windows Topics | 26129 @node Windows Specific Add-Ons,,Mixed-Language Programming on Windows,Microsoft Windows Topics |
26082 @anchor{gnat_ugn/platform_specific_information windows-specific-add-ons}@anchor{222}@anchor{gnat_ugn/platform_specific_information win32-specific-addons}@anchor{223} | 26130 @anchor{gnat_ugn/platform_specific_information windows-specific-add-ons}@anchor{220}@anchor{gnat_ugn/platform_specific_information win32-specific-addons}@anchor{221} |
26083 @subsection Windows Specific Add-Ons | 26131 @subsection Windows Specific Add-Ons |
26084 | 26132 |
26085 | 26133 |
26086 This section describes the Windows specific add-ons. | 26134 This section describes the Windows specific add-ons. |
26087 | 26135 |
26090 * wPOSIX:: | 26138 * wPOSIX:: |
26091 | 26139 |
26092 @end menu | 26140 @end menu |
26093 | 26141 |
26094 @node Win32Ada,wPOSIX,,Windows Specific Add-Ons | 26142 @node Win32Ada,wPOSIX,,Windows Specific Add-Ons |
26095 @anchor{gnat_ugn/platform_specific_information win32ada}@anchor{224}@anchor{gnat_ugn/platform_specific_information id39}@anchor{225} | 26143 @anchor{gnat_ugn/platform_specific_information win32ada}@anchor{222}@anchor{gnat_ugn/platform_specific_information id41}@anchor{223} |
26096 @subsubsection Win32Ada | 26144 @subsubsection Win32Ada |
26097 | 26145 |
26098 | 26146 |
26099 Win32Ada is a binding for the Microsoft Win32 API. This binding can be | 26147 Win32Ada is a binding for the Microsoft Win32 API. This binding can be |
26100 easily installed from the provided installer. To use the Win32Ada | 26148 easily installed from the provided installer. To use the Win32Ada |
26121 gprbuild p.gpr | 26169 gprbuild p.gpr |
26122 @end example | 26170 @end example |
26123 @end quotation | 26171 @end quotation |
26124 | 26172 |
26125 @node wPOSIX,,Win32Ada,Windows Specific Add-Ons | 26173 @node wPOSIX,,Win32Ada,Windows Specific Add-Ons |
26126 @anchor{gnat_ugn/platform_specific_information wposix}@anchor{226}@anchor{gnat_ugn/platform_specific_information id40}@anchor{227} | 26174 @anchor{gnat_ugn/platform_specific_information id42}@anchor{224}@anchor{gnat_ugn/platform_specific_information wposix}@anchor{225} |
26127 @subsubsection wPOSIX | 26175 @subsubsection wPOSIX |
26128 | 26176 |
26129 | 26177 |
26130 wPOSIX is a minimal POSIX binding whose goal is to help with building | 26178 wPOSIX is a minimal POSIX binding whose goal is to help with building |
26131 cross-platforms applications. This binding is not complete though, as | 26179 cross-platforms applications. This binding is not complete though, as |
26154 gprbuild p.gpr | 26202 gprbuild p.gpr |
26155 @end example | 26203 @end example |
26156 @end quotation | 26204 @end quotation |
26157 | 26205 |
26158 @node Mac OS Topics,,Microsoft Windows Topics,Platform-Specific Information | 26206 @node Mac OS Topics,,Microsoft Windows Topics,Platform-Specific Information |
26159 @anchor{gnat_ugn/platform_specific_information mac-os-topics}@anchor{2d}@anchor{gnat_ugn/platform_specific_information id41}@anchor{228} | 26207 @anchor{gnat_ugn/platform_specific_information mac-os-topics}@anchor{2d}@anchor{gnat_ugn/platform_specific_information id43}@anchor{226} |
26160 @section Mac OS Topics | 26208 @section Mac OS Topics |
26161 | 26209 |
26162 | 26210 |
26163 @geindex OS X | 26211 @geindex OS X |
26164 | 26212 |
26169 * Codesigning the Debugger:: | 26217 * Codesigning the Debugger:: |
26170 | 26218 |
26171 @end menu | 26219 @end menu |
26172 | 26220 |
26173 @node Codesigning the Debugger,,,Mac OS Topics | 26221 @node Codesigning the Debugger,,,Mac OS Topics |
26174 @anchor{gnat_ugn/platform_specific_information codesigning-the-debugger}@anchor{229} | 26222 @anchor{gnat_ugn/platform_specific_information codesigning-the-debugger}@anchor{227} |
26175 @subsection Codesigning the Debugger | 26223 @subsection Codesigning the Debugger |
26176 | 26224 |
26177 | 26225 |
26178 The Darwin Kernel requires the debugger to have special permissions | 26226 The Darwin Kernel requires the debugger to have special permissions |
26179 before it is allowed to control other processes. These permissions | 26227 before it is allowed to control other processes. These permissions |
26250 name chosen above, and <gnat_install_prefix> should be replaced by | 26298 name chosen above, and <gnat_install_prefix> should be replaced by |
26251 the location where you installed GNAT. Also, be sure that users are | 26299 the location where you installed GNAT. Also, be sure that users are |
26252 in the Unix group @code{_developer}. | 26300 in the Unix group @code{_developer}. |
26253 | 26301 |
26254 @node Example of Binder Output File,Elaboration Order Handling in GNAT,Platform-Specific Information,Top | 26302 @node Example of Binder Output File,Elaboration Order Handling in GNAT,Platform-Specific Information,Top |
26255 @anchor{gnat_ugn/example_of_binder_output example-of-binder-output-file}@anchor{e}@anchor{gnat_ugn/example_of_binder_output doc}@anchor{22a}@anchor{gnat_ugn/example_of_binder_output id1}@anchor{22b} | 26303 @anchor{gnat_ugn/example_of_binder_output example-of-binder-output-file}@anchor{e}@anchor{gnat_ugn/example_of_binder_output doc}@anchor{228}@anchor{gnat_ugn/example_of_binder_output id1}@anchor{229} |
26256 @chapter Example of Binder Output File | 26304 @chapter Example of Binder Output File |
26257 | 26305 |
26258 | 26306 |
26259 @geindex Binder output (example) | 26307 @geindex Binder output (example) |
26260 | 26308 |
27002 elaboration code in your own application). | 27050 elaboration code in your own application). |
27003 | 27051 |
27004 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit | 27052 @c -- Example: A |withing| unit has a |with| clause, it |withs| a |withed| unit |
27005 | 27053 |
27006 @node Elaboration Order Handling in GNAT,Inline Assembler,Example of Binder Output File,Top | 27054 @node Elaboration Order Handling in GNAT,Inline Assembler,Example of Binder Output File,Top |
27007 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order-handling-in-gnat}@anchor{f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat doc}@anchor{22c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id1}@anchor{22d} | 27055 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order-handling-in-gnat}@anchor{f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat doc}@anchor{22a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id1}@anchor{22b} |
27008 @chapter Elaboration Order Handling in GNAT | 27056 @chapter Elaboration Order Handling in GNAT |
27009 | 27057 |
27010 | 27058 |
27011 @geindex Order of elaboration | 27059 @geindex Order of elaboration |
27012 | 27060 |
27024 * Controlling the Elaboration Order in GNAT:: | 27072 * Controlling the Elaboration Order in GNAT:: |
27025 * Common Elaboration-model Traits:: | 27073 * Common Elaboration-model Traits:: |
27026 * Dynamic Elaboration Model in GNAT:: | 27074 * Dynamic Elaboration Model in GNAT:: |
27027 * Static Elaboration Model in GNAT:: | 27075 * Static Elaboration Model in GNAT:: |
27028 * SPARK Elaboration Model in GNAT:: | 27076 * SPARK Elaboration Model in GNAT:: |
27077 * Legacy Elaboration Model in GNAT:: | |
27029 * Mixing Elaboration Models:: | 27078 * Mixing Elaboration Models:: |
27030 * Elaboration Circularities:: | 27079 * Elaboration Circularities:: |
27031 * Resolving Elaboration Circularities:: | 27080 * Resolving Elaboration Circularities:: |
27032 * Resolving Task Issues:: | 27081 * Resolving Task Issues:: |
27033 * Elaboration-related Compiler Switches:: | 27082 * Elaboration-related Compiler Switches:: |
27035 * Inspecting the Chosen Elaboration Order:: | 27084 * Inspecting the Chosen Elaboration Order:: |
27036 | 27085 |
27037 @end menu | 27086 @end menu |
27038 | 27087 |
27039 @node Elaboration Code,Elaboration Order,,Elaboration Order Handling in GNAT | 27088 @node Elaboration Code,Elaboration Order,,Elaboration Order Handling in GNAT |
27040 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-code}@anchor{22e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id2}@anchor{22f} | 27089 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-code}@anchor{22c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id2}@anchor{22d} |
27041 @section Elaboration Code | 27090 @section Elaboration Code |
27042 | 27091 |
27043 | 27092 |
27044 Ada defines the term @emph{execution} as the process by which a construct achieves | 27093 Ada defines the term @emph{execution} as the process by which a construct achieves |
27045 its run-time effect. This process is also referred to as @strong{elaboration} for | 27094 its run-time effect. This process is also referred to as @strong{elaboration} for |
27177 result, the call to @code{Proc} will be executed when the body of @code{Client} is | 27226 result, the call to @code{Proc} will be executed when the body of @code{Client} is |
27178 elaborated. | 27227 elaborated. |
27179 @end itemize | 27228 @end itemize |
27180 | 27229 |
27181 @node Elaboration Order,Checking the Elaboration Order,Elaboration Code,Elaboration Order Handling in GNAT | 27230 @node Elaboration Order,Checking the Elaboration Order,Elaboration Code,Elaboration Order Handling in GNAT |
27182 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order}@anchor{230}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id3}@anchor{231} | 27231 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-order}@anchor{22e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id3}@anchor{22f} |
27183 @section Elaboration Order | 27232 @section Elaboration Order |
27184 | 27233 |
27185 | 27234 |
27186 The sequence by which the elaboration code of all units within a partition is | 27235 The sequence by which the elaboration code of all units within a partition is |
27187 executed is referred to as @strong{elaboration order}. | 27236 executed is referred to as @strong{elaboration order}. |
27327 unit categorization, and elaboration control pragmas. Ideally an order which | 27376 unit categorization, and elaboration control pragmas. Ideally an order which |
27328 avoids ABE problems should be chosen, however a compiler may not always find | 27377 avoids ABE problems should be chosen, however a compiler may not always find |
27329 such an order due to complications with respect to control and data flow. | 27378 such an order due to complications with respect to control and data flow. |
27330 | 27379 |
27331 @node Checking the Elaboration Order,Controlling the Elaboration Order in Ada,Elaboration Order,Elaboration Order Handling in GNAT | 27380 @node Checking the Elaboration Order,Controlling the Elaboration Order in Ada,Elaboration Order,Elaboration Order Handling in GNAT |
27332 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id4}@anchor{232}@anchor{gnat_ugn/elaboration_order_handling_in_gnat checking-the-elaboration-order}@anchor{233} | 27381 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id4}@anchor{230}@anchor{gnat_ugn/elaboration_order_handling_in_gnat checking-the-elaboration-order}@anchor{231} |
27333 @section Checking the Elaboration Order | 27382 @section Checking the Elaboration Order |
27334 | 27383 |
27335 | 27384 |
27336 To avoid placing the entire elaboration order burden on the programmer, Ada | 27385 To avoid placing the entire elaboration order burden on the programmer, Ada |
27337 provides three lines of defense: | 27386 provides three lines of defense: |
27389 Pragmas are provided for the programmer to specify the desired elaboration | 27438 Pragmas are provided for the programmer to specify the desired elaboration |
27390 order. | 27439 order. |
27391 @end itemize | 27440 @end itemize |
27392 | 27441 |
27393 @node Controlling the Elaboration Order in Ada,Controlling the Elaboration Order in GNAT,Checking the Elaboration Order,Elaboration Order Handling in GNAT | 27442 @node Controlling the Elaboration Order in Ada,Controlling the Elaboration Order in GNAT,Checking the Elaboration Order,Elaboration Order Handling in GNAT |
27394 @anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-ada}@anchor{234}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id5}@anchor{235} | 27443 @anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-ada}@anchor{232}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id5}@anchor{233} |
27395 @section Controlling the Elaboration Order in Ada | 27444 @section Controlling the Elaboration Order in Ada |
27396 | 27445 |
27397 | 27446 |
27398 Ada provides several idioms and pragmas to aid the programmer with specifying | 27447 Ada provides several idioms and pragmas to aid the programmer with specifying |
27399 the desired elaboration order and avoiding ABE problems altogether. | 27448 the desired elaboration order and avoiding ABE problems altogether. |
27717 Note that one additional advantage of using @code{Elaborate} and @code{Elaborate_All} | 27766 Note that one additional advantage of using @code{Elaborate} and @code{Elaborate_All} |
27718 is that the program continues to stay in the last state (one or more correct | 27767 is that the program continues to stay in the last state (one or more correct |
27719 orders exist) even if maintenance changes the bodies of targets. | 27768 orders exist) even if maintenance changes the bodies of targets. |
27720 | 27769 |
27721 @node Controlling the Elaboration Order in GNAT,Common Elaboration-model Traits,Controlling the Elaboration Order in Ada,Elaboration Order Handling in GNAT | 27770 @node Controlling the Elaboration Order in GNAT,Common Elaboration-model Traits,Controlling the Elaboration Order in Ada,Elaboration Order Handling in GNAT |
27722 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id6}@anchor{236}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-gnat}@anchor{237} | 27771 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id6}@anchor{234}@anchor{gnat_ugn/elaboration_order_handling_in_gnat controlling-the-elaboration-order-in-gnat}@anchor{235} |
27723 @section Controlling the Elaboration Order in GNAT | 27772 @section Controlling the Elaboration Order in GNAT |
27724 | 27773 |
27725 | 27774 |
27726 In addition to Ada semantics and rules synthesized from them, GNAT offers | 27775 In addition to Ada semantics and rules synthesized from them, GNAT offers |
27727 three elaboration models to aid the programmer with specifying the correct | 27776 three elaboration models to aid the programmer with specifying the correct |
27773 The SPARK model is in effect only when a scenario and a target reside in a | 27822 The SPARK model is in effect only when a scenario and a target reside in a |
27774 region subject to SPARK_Mode On, otherwise the dynamic or static model is in | 27823 region subject to SPARK_Mode On, otherwise the dynamic or static model is in |
27775 effect. | 27824 effect. |
27776 @end itemize | 27825 @end itemize |
27777 | 27826 |
27827 @geindex Legacy elaboration model | |
27828 | |
27829 | |
27830 @itemize * | |
27831 | |
27832 @item | |
27833 @emph{Legacy elaboration model} | |
27834 | |
27835 In addition to the three elaboration models outlined above, GNAT provides the | |
27836 elaboration model of pre-18.x versions referred to as @cite{legacy elaboration model}. The legacy elaboration model is enabled with compiler switch | |
27837 @code{-gnatH}. | |
27838 @end itemize | |
27839 | |
27840 @geindex Relaxed elaboration mode | |
27841 | |
27842 The dynamic, legacy, and static models can be relaxed using compiler switch | |
27843 @code{-gnatJ}, making them more permissive. Note that in this mode, GNAT | |
27844 may not diagnose certain elaboration issues or install run-time checks. | |
27845 | |
27778 @node Common Elaboration-model Traits,Dynamic Elaboration Model in GNAT,Controlling the Elaboration Order in GNAT,Elaboration Order Handling in GNAT | 27846 @node Common Elaboration-model Traits,Dynamic Elaboration Model in GNAT,Controlling the Elaboration Order in GNAT,Elaboration Order Handling in GNAT |
27779 @anchor{gnat_ugn/elaboration_order_handling_in_gnat common-elaboration-model-traits}@anchor{238}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id7}@anchor{239} | 27847 @anchor{gnat_ugn/elaboration_order_handling_in_gnat common-elaboration-model-traits}@anchor{236}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id7}@anchor{237} |
27780 @section Common Elaboration-model Traits | 27848 @section Common Elaboration-model Traits |
27781 | 27849 |
27782 | 27850 |
27783 All three GNAT models are able to detect elaboration problems related to | 27851 All three GNAT models are able to detect elaboration problems related to |
27784 dispatching calls and a particular kind of ABE referred to as @emph{guaranteed ABE}. | 27852 dispatching calls and a particular kind of ABE referred to as @emph{guaranteed ABE}. |
27839 @end itemize | 27907 @end itemize |
27840 | 27908 |
27841 Note that GNAT emits warnings rather than hard errors whenever it encounters an | 27909 Note that GNAT emits warnings rather than hard errors whenever it encounters an |
27842 elaboration problem. This is because the elaboration model in effect may be too | 27910 elaboration problem. This is because the elaboration model in effect may be too |
27843 conservative, or a particular scenario may not be elaborated or executed due to | 27911 conservative, or a particular scenario may not be elaborated or executed due to |
27844 data and control flow. The warnings can be suppressed with compiler switch | 27912 data and control flow. The warnings can be suppressed selectively with @code{pragma |
27845 @code{-gnatws}. | 27913 Warnigns (Off)} or globally with compiler switch @code{-gnatwL}. |
27846 | 27914 |
27847 @node Dynamic Elaboration Model in GNAT,Static Elaboration Model in GNAT,Common Elaboration-model Traits,Elaboration Order Handling in GNAT | 27915 @node Dynamic Elaboration Model in GNAT,Static Elaboration Model in GNAT,Common Elaboration-model Traits,Elaboration Order Handling in GNAT |
27848 @anchor{gnat_ugn/elaboration_order_handling_in_gnat dynamic-elaboration-model-in-gnat}@anchor{23a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id8}@anchor{23b} | 27916 @anchor{gnat_ugn/elaboration_order_handling_in_gnat dynamic-elaboration-model-in-gnat}@anchor{238}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id8}@anchor{239} |
27849 @section Dynamic Elaboration Model in GNAT | 27917 @section Dynamic Elaboration Model in GNAT |
27850 | 27918 |
27851 | 27919 |
27852 The dynamic model assumes that all code within all units in a partition is | 27920 The dynamic model assumes that all code within all units in a partition is |
27853 elaboration code. As a result, run-time checks are installed for each scenario | 27921 elaboration code. As a result, run-time checks are installed for each scenario |
27900 | 27968 |
27901 4. end Dynamic_Model; | 27969 4. end Dynamic_Model; |
27902 @end example | 27970 @end example |
27903 | 27971 |
27904 @node Static Elaboration Model in GNAT,SPARK Elaboration Model in GNAT,Dynamic Elaboration Model in GNAT,Elaboration Order Handling in GNAT | 27972 @node Static Elaboration Model in GNAT,SPARK Elaboration Model in GNAT,Dynamic Elaboration Model in GNAT,Elaboration Order Handling in GNAT |
27905 @anchor{gnat_ugn/elaboration_order_handling_in_gnat static-elaboration-model-in-gnat}@anchor{23c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id9}@anchor{23d} | 27973 @anchor{gnat_ugn/elaboration_order_handling_in_gnat static-elaboration-model-in-gnat}@anchor{23a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id9}@anchor{23b} |
27906 @section Static Elaboration Model in GNAT | 27974 @section Static Elaboration Model in GNAT |
27907 | 27975 |
27908 | 27976 |
27909 In contrast to the dynamic model, the static model is more precise in its | 27977 In contrast to the dynamic model, the static model is more precise in its |
27910 analysis of elaboration code. The model makes a clear distinction between | 27978 analysis of elaboration code. The model makes a clear distinction between |
27917 @item | 27985 @item |
27918 @emph{Internal targets} | 27986 @emph{Internal targets} |
27919 | 27987 |
27920 The static model performs extensive diagnostics on scenarios which elaborate | 27988 The static model performs extensive diagnostics on scenarios which elaborate |
27921 or execute internal targets. The warnings resulting from these diagnostics | 27989 or execute internal targets. The warnings resulting from these diagnostics |
27922 are enabled by default, but can be suppressed using compiler switch | 27990 are enabled by default, but can be suppressed selectively with @code{pragma |
27923 @code{-gnatws}. | 27991 Warnings (Off)} or globally with compiler switch @code{-gnatwL}. |
27924 | 27992 |
27925 @example | 27993 @example |
27926 1. package body Static_Model is | 27994 1. package body Static_Model is |
27927 2. generic | 27995 2. generic |
27928 3. with function Func return Integer; | 27996 3. with function Func return Integer; |
28042 @code{Server}. The pragma guarantees that both the spec and body of @code{Server}, | 28110 @code{Server}. The pragma guarantees that both the spec and body of @code{Server}, |
28043 along with any additional dependencies that @code{Server} may require, are | 28111 along with any additional dependencies that @code{Server} may require, are |
28044 elaborated prior to the body of @code{Static_Model}. | 28112 elaborated prior to the body of @code{Static_Model}. |
28045 @end itemize | 28113 @end itemize |
28046 | 28114 |
28047 @node SPARK Elaboration Model in GNAT,Mixing Elaboration Models,Static Elaboration Model in GNAT,Elaboration Order Handling in GNAT | 28115 @node SPARK Elaboration Model in GNAT,Legacy Elaboration Model in GNAT,Static Elaboration Model in GNAT,Elaboration Order Handling in GNAT |
28048 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id10}@anchor{23e}@anchor{gnat_ugn/elaboration_order_handling_in_gnat spark-elaboration-model-in-gnat}@anchor{23f} | 28116 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id10}@anchor{23c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat spark-elaboration-model-in-gnat}@anchor{23d} |
28049 @section SPARK Elaboration Model in GNAT | 28117 @section SPARK Elaboration Model in GNAT |
28050 | 28118 |
28051 | 28119 |
28052 The SPARK model is identical to the static model in its handling of internal | 28120 The SPARK model is identical to the static model in its handling of internal |
28053 targets. The SPARK model, however, requires explicit @code{Elaborate} or | 28121 targets. The SPARK model, however, requires explicit @code{Elaborate} or |
28065 >>> function "Func" called at line 3 | 28133 >>> function "Func" called at line 3 |
28066 | 28134 |
28067 4. end SPARK_Model; | 28135 4. end SPARK_Model; |
28068 @end example | 28136 @end example |
28069 | 28137 |
28070 @node Mixing Elaboration Models,Elaboration Circularities,SPARK Elaboration Model in GNAT,Elaboration Order Handling in GNAT | 28138 @node Legacy Elaboration Model in GNAT,Mixing Elaboration Models,SPARK Elaboration Model in GNAT,Elaboration Order Handling in GNAT |
28071 @anchor{gnat_ugn/elaboration_order_handling_in_gnat mixing-elaboration-models}@anchor{240}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id11}@anchor{241} | 28139 @anchor{gnat_ugn/elaboration_order_handling_in_gnat legacy-elaboration-model-in-gnat}@anchor{23e} |
28140 @section Legacy Elaboration Model in GNAT | |
28141 | |
28142 | |
28143 The legacy elaboration model is provided for compatibility with code bases | |
28144 developed with pre-18.x versions of GNAT. It is similar in functionality to | |
28145 the dynamic and static models of post-18.x version of GNAT, but may differ | |
28146 in terms of diagnostics and run-time checks. The legacy elaboration model is | |
28147 enabled with compiler switch @code{-gnatH}. | |
28148 | |
28149 @node Mixing Elaboration Models,Elaboration Circularities,Legacy Elaboration Model in GNAT,Elaboration Order Handling in GNAT | |
28150 @anchor{gnat_ugn/elaboration_order_handling_in_gnat mixing-elaboration-models}@anchor{23f}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id11}@anchor{240} | |
28072 @section Mixing Elaboration Models | 28151 @section Mixing Elaboration Models |
28073 | 28152 |
28074 | 28153 |
28075 It is possible to mix units compiled with a different elaboration model, | 28154 It is possible to mix units compiled with a different elaboration model, |
28076 however the following rules must be observed: | 28155 however the following rules must be observed: |
28110 @end example | 28189 @end example |
28111 | 28190 |
28112 The warnings can be suppressed by binder switch @code{-ws}. | 28191 The warnings can be suppressed by binder switch @code{-ws}. |
28113 | 28192 |
28114 @node Elaboration Circularities,Resolving Elaboration Circularities,Mixing Elaboration Models,Elaboration Order Handling in GNAT | 28193 @node Elaboration Circularities,Resolving Elaboration Circularities,Mixing Elaboration Models,Elaboration Order Handling in GNAT |
28115 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id12}@anchor{242}@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-circularities}@anchor{243} | 28194 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id12}@anchor{241}@anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-circularities}@anchor{242} |
28116 @section Elaboration Circularities | 28195 @section Elaboration Circularities |
28117 | 28196 |
28118 | 28197 |
28119 If the binder cannot find an acceptable elaboration order, it outputs detailed | 28198 If the binder cannot find an acceptable elaboration order, it outputs detailed |
28120 diagnostics describing an @strong{elaboration circularity}. | 28199 diagnostics describing an @strong{elaboration circularity}. |
28169 @emph{with}s @code{Client}, implying that @code{Client} must be elaborated prior to | 28248 @emph{with}s @code{Client}, implying that @code{Client} must be elaborated prior to |
28170 @code{Server}. The end result is that @code{Client} must be elaborated prior to | 28249 @code{Server}. The end result is that @code{Client} must be elaborated prior to |
28171 @code{Client}, and this leads to a circularity. | 28250 @code{Client}, and this leads to a circularity. |
28172 | 28251 |
28173 @node Resolving Elaboration Circularities,Resolving Task Issues,Elaboration Circularities,Elaboration Order Handling in GNAT | 28252 @node Resolving Elaboration Circularities,Resolving Task Issues,Elaboration Circularities,Elaboration Order Handling in GNAT |
28174 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id13}@anchor{244}@anchor{gnat_ugn/elaboration_order_handling_in_gnat resolving-elaboration-circularities}@anchor{245} | 28253 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id13}@anchor{243}@anchor{gnat_ugn/elaboration_order_handling_in_gnat resolving-elaboration-circularities}@anchor{244} |
28175 @section Resolving Elaboration Circularities | 28254 @section Resolving Elaboration Circularities |
28176 | 28255 |
28177 | 28256 |
28178 When faced with an elaboration circularity, a programmer has several options | 28257 When faced with an elaboration circularity, a programmer has several options |
28179 available. | 28258 available. |
28201 implicit @code{Elaborate} and @code{Elaborate_All} pragmas, resulting in a behavior | 28280 implicit @code{Elaborate} and @code{Elaborate_All} pragmas, resulting in a behavior |
28202 identical to that specified by the Ada Reference Manual. The binder will | 28281 identical to that specified by the Ada Reference Manual. The binder will |
28203 generate an executable program that may or may not raise @code{Program_Error}, | 28282 generate an executable program that may or may not raise @code{Program_Error}, |
28204 and it is the programmer's responsibility to ensure that it does not raise | 28283 and it is the programmer's responsibility to ensure that it does not raise |
28205 @code{Program_Error}. | 28284 @code{Program_Error}. |
28285 | |
28286 If the compilation was performed using a post-18.x version of GNAT, consider | |
28287 using the legacy elaboration model, in the following order: | |
28288 | |
28289 | |
28290 @itemize - | |
28291 | |
28292 @item | |
28293 Use the legacy static elaboration model, with compiler switch | |
28294 @code{-gnatH}. | |
28295 | |
28296 @item | |
28297 Use the legacy dynamic elaboration model, with compiler switches | |
28298 @code{-gnatH} @code{-gnatE}. | |
28299 | |
28300 @item | |
28301 Use the relaxed legacy static elaboration model, with compiler switches | |
28302 @code{-gnatH} @code{-gnatJ}. | |
28303 | |
28304 @item | |
28305 Use the relaxed legacy dynamic elaboration model, with compiler switches | |
28306 @code{-gnatH} @code{-gnatJ} @code{-gnatE}. | |
28307 @end itemize | |
28206 | 28308 |
28207 @item | 28309 @item |
28208 @emph{Suppress all elaboration checks} | 28310 @emph{Suppress all elaboration checks} |
28209 | 28311 |
28210 The drawback of run-time checks is that they generate overhead at run time, | 28312 The drawback of run-time checks is that they generate overhead at run time, |
28314 run-time checks. | 28416 run-time checks. |
28315 @end itemize | 28417 @end itemize |
28316 @end itemize | 28418 @end itemize |
28317 | 28419 |
28318 @node Resolving Task Issues,Elaboration-related Compiler Switches,Resolving Elaboration Circularities,Elaboration Order Handling in GNAT | 28420 @node Resolving Task Issues,Elaboration-related Compiler Switches,Resolving Elaboration Circularities,Elaboration Order Handling in GNAT |
28319 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id14}@anchor{246}@anchor{gnat_ugn/elaboration_order_handling_in_gnat resolving-task-issues}@anchor{247} | 28421 @anchor{gnat_ugn/elaboration_order_handling_in_gnat id14}@anchor{245}@anchor{gnat_ugn/elaboration_order_handling_in_gnat resolving-task-issues}@anchor{246} |
28320 @section Resolving Task Issues | 28422 @section Resolving Task Issues |
28321 | 28423 |
28322 | 28424 |
28323 The model of execution in Ada dictates that elaboration must first take place, | 28425 The model of execution in Ada dictates that elaboration must first take place, |
28324 and only then can the main program be started. Tasks which are activated during | 28426 and only then can the main program be started. Tasks which are activated during |
28610 In addition to the change in behavior with respect to task bodies, the | 28712 In addition to the change in behavior with respect to task bodies, the |
28611 static model will verify that no entry calls take place at elaboration time. | 28713 static model will verify that no entry calls take place at elaboration time. |
28612 @end itemize | 28714 @end itemize |
28613 | 28715 |
28614 @node Elaboration-related Compiler Switches,Summary of Procedures for Elaboration Control,Resolving Task Issues,Elaboration Order Handling in GNAT | 28716 @node Elaboration-related Compiler Switches,Summary of Procedures for Elaboration Control,Resolving Task Issues,Elaboration Order Handling in GNAT |
28615 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-related-compiler-switches}@anchor{248}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id15}@anchor{249} | 28717 @anchor{gnat_ugn/elaboration_order_handling_in_gnat elaboration-related-compiler-switches}@anchor{247}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id15}@anchor{248} |
28616 @section Elaboration-related Compiler Switches | 28718 @section Elaboration-related Compiler Switches |
28617 | 28719 |
28618 | 28720 |
28619 GNAT has several switches that affect the elaboration model and consequently | 28721 GNAT has several switches that affect the elaboration model and consequently |
28620 the elaboration order chosen by the binder. | 28722 the elaboration order chosen by the binder. |
28621 | |
28622 @geindex -gnatdE (gnat) | |
28623 | |
28624 | |
28625 @table @asis | |
28626 | |
28627 @item @code{-gnatdE} | |
28628 | |
28629 Elaboration checks on predefined units | |
28630 | |
28631 When this switch is in effect, GNAT will consider scenarios and targets that | |
28632 come from the Ada, GNAT, Interfaces, and System hierarchies. This switch is | |
28633 useful when a programmer has defined a custom grandchild of those packages. | |
28634 @end table | |
28635 | |
28636 @geindex -gnatd.G (gnat) | |
28637 | |
28638 | |
28639 @table @asis | |
28640 | |
28641 @item @code{-gnatd.G} | |
28642 | |
28643 Ignore calls through generic formal parameters for elaboration | |
28644 | |
28645 When this switch is in effect, GNAT will ignore calls that invoke generic | |
28646 actual entries, operators, or subprograms via generic formal subprograms. As | |
28647 a result, GNAT will not generate implicit @code{Elaborate} and @code{Elaborate_All} | |
28648 pragmas, and run-time checks for such calls. Note that this switch does not | |
28649 overlap with @code{-gnatdL}. | |
28650 | |
28651 @example | |
28652 package body Ignore_Calls is | |
28653 function ABE return Integer; | |
28654 | |
28655 generic | |
28656 with function Gen_Formal return Integer; | |
28657 package Gen is | |
28658 Val : constant Integer := Gen_Formal; | |
28659 end Gen; | |
28660 | |
28661 package Inst is new Gen (ABE); | |
28662 | |
28663 function ABE return Integer is | |
28664 begin | |
28665 ... | |
28666 end ABE; | |
28667 end Ignore_Calls; | |
28668 @end example | |
28669 | |
28670 In the example above, the call to function @code{ABE} will be ignored because it | |
28671 occurs during the elaboration of instance @code{Inst}, through a call to generic | |
28672 formal subprogram @code{Gen_Formal}. | |
28673 @end table | |
28674 | |
28675 @geindex -gnatdL (gnat) | |
28676 | |
28677 | |
28678 @table @asis | |
28679 | |
28680 @item @code{-gnatdL} | |
28681 | |
28682 Ignore external calls from instances for elaboration | |
28683 | |
28684 When this switch is in effect, GNAT will ignore calls that originate from | |
28685 within an instance and directly target an entry, operator, or subprogram | |
28686 defined outside the instance. As a result, GNAT will not generate implicit | |
28687 @code{Elaborate} and @code{Elaborate_All} pragmas, and run-time checks for such | |
28688 calls. Note that this switch does not overlap with @code{-gnatd.G}. | |
28689 | |
28690 @example | |
28691 package body Ignore_Calls is | |
28692 function ABE return Integer; | |
28693 | |
28694 generic | |
28695 package Gen is | |
28696 Val : constant Integer := ABE; | |
28697 end Gen; | |
28698 | |
28699 package Inst is new Gen; | |
28700 | |
28701 function ABE return Integer is | |
28702 begin | |
28703 ... | |
28704 end ABE; | |
28705 end Ignore_Calls; | |
28706 @end example | |
28707 | |
28708 In the example above, the call to function @code{ABE} will be ignored because it | |
28709 originates from within an instance and targets a subprogram defined outside | |
28710 the instance. | |
28711 @end table | |
28712 | |
28713 @geindex -gnatd.o (gnat) | |
28714 | |
28715 | |
28716 @table @asis | |
28717 | |
28718 @item @code{-gnatd.o} | |
28719 | |
28720 Conservative elaboration order for indirect calls | |
28721 | |
28722 When this switch is in effect, GNAT will treat @code{'Access} of an entry, | |
28723 operator, or subprogram as an immediate call to that target. As a result, | |
28724 GNAT will generate implicit @code{Elaborate} and @code{Elaborate_All} pragmas as | |
28725 well as run-time checks for such attribute references. | |
28726 | |
28727 @example | |
28728 1. package body Attribute_Call is | |
28729 2. function Func return Integer; | |
28730 3. type Func_Ptr is access function return Integer; | |
28731 4. | |
28732 5. Ptr : constant Func_Ptr := Func'Access; | |
28733 | | |
28734 >>> warning: cannot call "Func" before body seen | |
28735 >>> warning: Program_Error may be raised at run time | |
28736 >>> warning: body of unit "Attribute_Call" elaborated | |
28737 >>> warning: "Access" of "Func" taken at line 5 | |
28738 >>> warning: function "Func" called at line 5 | |
28739 | |
28740 6. | |
28741 7. function Func return Integer is | |
28742 8. begin | |
28743 9. ... | |
28744 10. end Func; | |
28745 11. end Attribute_Call; | |
28746 @end example | |
28747 | |
28748 In the example above, the elaboration of declaration @code{Ptr} is assigned | |
28749 @code{Func'Access} before the body of @code{Func} has been elaborated. | |
28750 @end table | |
28751 | |
28752 @geindex -gnatd.U (gnat) | |
28753 | |
28754 | |
28755 @table @asis | |
28756 | |
28757 @item @code{-gnatd.U} | |
28758 | |
28759 Ignore indirect calls for static elaboration | |
28760 | |
28761 When this switch is in effect, GNAT will ignore @code{'Access} of an entry, | |
28762 operator, or subprogram when the static model is in effect. | |
28763 @end table | |
28764 | |
28765 @geindex -gnatd.v (gnat) | |
28766 | |
28767 | |
28768 @table @asis | |
28769 | |
28770 @item @code{-gnatd.v} | |
28771 | |
28772 Enforce SPARK elaboration rules in SPARK code | |
28773 | |
28774 When this switch is in effect, GNAT will enforce the SPARK rules of | |
28775 elaboration as defined in the SPARK Reference Manual, section 7.7. As a | |
28776 result, constructs which violate the SPARK elaboration rules are no longer | |
28777 accepted, even if GNAT is able to statically ensure that these constructs | |
28778 will not lead to ABE problems. | |
28779 @end table | |
28780 | |
28781 @geindex -gnatd.y (gnat) | |
28782 | |
28783 | |
28784 @table @asis | |
28785 | |
28786 @item @code{-gnatd.y} | |
28787 | |
28788 Disable implicit pragma Elaborate[_All] on task bodies | |
28789 | |
28790 When this switch is in effect, GNAT will not generate @code{Elaborate} and | |
28791 @code{Elaborate_All} pragmas if the need for the pragma came directly or | |
28792 indirectly from a task body. | |
28793 | |
28794 @example | |
28795 with Server; | |
28796 package body Disable_Task is | |
28797 task T; | |
28798 | |
28799 task body T is | |
28800 begin | |
28801 Server.Proc; | |
28802 end T; | |
28803 end Disable_Task; | |
28804 @end example | |
28805 | |
28806 In the example above, the activation of single task @code{T} invokes | |
28807 @code{Server.Proc}, which implies that @code{Server} requires @code{Elaborate_All}, | |
28808 however GNAT will not generate the pragma. | |
28809 @end table | |
28810 | 28723 |
28811 @geindex -gnatE (gnat) | 28724 @geindex -gnatE (gnat) |
28812 | 28725 |
28813 | 28726 |
28814 @table @asis | 28727 @table @asis |
28863 >>> info: "Elaborate_All" requirement for unit "Server" met by pragma at line 1 | 28776 >>> info: "Elaborate_All" requirement for unit "Server" met by pragma at line 1 |
28864 | 28777 |
28865 4. end Client; | 28778 4. end Client; |
28866 @end example | 28779 @end example |
28867 @end itemize | 28780 @end itemize |
28781 @end table | |
28782 | |
28783 @geindex -gnatH (gnat) | |
28784 | |
28785 | |
28786 @table @asis | |
28787 | |
28788 @item @code{-gnatH} | |
28789 | |
28790 Legacy elaboration checking mode enabled | |
28791 | |
28792 When this switch is in effect, GNAT will utilize the pre-18.x elaboration | |
28793 model. | |
28794 @end table | |
28795 | |
28796 @geindex -gnatJ (gnat) | |
28797 | |
28798 | |
28799 @table @asis | |
28800 | |
28801 @item @code{-gnatJ} | |
28802 | |
28803 Relaxed elaboration checking mode enabled | |
28804 | |
28805 When this switch is in effect, GNAT will not process certain scenarios, | |
28806 resulting in a more permissive elaboration model. Note that this may | |
28807 eliminate some diagnostics and run-time checks. | |
28868 @end table | 28808 @end table |
28869 | 28809 |
28870 @geindex -gnatw.f (gnat) | 28810 @geindex -gnatw.f (gnat) |
28871 | 28811 |
28872 | 28812 |
28901 | 28841 |
28902 In the example above, the elaboration of declaration @code{Ptr} is assigned | 28842 In the example above, the elaboration of declaration @code{Ptr} is assigned |
28903 @code{Func'Access} before the body of @code{Func} has been elaborated. | 28843 @code{Func'Access} before the body of @code{Func} has been elaborated. |
28904 @end table | 28844 @end table |
28905 | 28845 |
28846 @geindex -gnatwl (gnat) | |
28847 | |
28848 | |
28849 @table @asis | |
28850 | |
28851 @item @code{-gnatwl} | |
28852 | |
28853 Turn on warnings for elaboration problems | |
28854 | |
28855 When this switch is in effect, GNAT emits diagnostics in the form of warnings | |
28856 concerning various elaboration problems. The warnings are enabled by default. | |
28857 The switch is provided in case all warnings are suppressed, but elaboration | |
28858 warnings are still desired. | |
28859 | |
28860 @item @code{-gnatwL} | |
28861 | |
28862 Turn off warnings for elaboration problems | |
28863 | |
28864 When this switch is in effect, GNAT no longer emits any diagnostics in the | |
28865 form of warnings. Selective suppression of elaboration problems is possible | |
28866 using @code{pragma Warnings (Off)}. | |
28867 | |
28868 @example | |
28869 1. package body Selective_Suppression is | |
28870 2. function ABE return Integer; | |
28871 3. | |
28872 4. Val_1 : constant Integer := ABE; | |
28873 | | |
28874 >>> warning: cannot call "ABE" before body seen | |
28875 >>> warning: Program_Error will be raised at run time | |
28876 | |
28877 5. | |
28878 6. pragma Warnings (Off); | |
28879 7. Val_2 : constant Integer := ABE; | |
28880 8. pragma Warnings (On); | |
28881 9. | |
28882 10. function ABE return Integer is | |
28883 11. begin | |
28884 12. ... | |
28885 13. end ABE; | |
28886 14. end Selective_Suppression; | |
28887 @end example | |
28888 | |
28889 Note that suppressing elaboration warnings does not eliminate run-time | |
28890 checks. The example above will still fail at run time with an ABE. | |
28891 @end table | |
28892 | |
28906 @node Summary of Procedures for Elaboration Control,Inspecting the Chosen Elaboration Order,Elaboration-related Compiler Switches,Elaboration Order Handling in GNAT | 28893 @node Summary of Procedures for Elaboration Control,Inspecting the Chosen Elaboration Order,Elaboration-related Compiler Switches,Elaboration Order Handling in GNAT |
28907 @anchor{gnat_ugn/elaboration_order_handling_in_gnat summary-of-procedures-for-elaboration-control}@anchor{24a}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id16}@anchor{24b} | 28894 @anchor{gnat_ugn/elaboration_order_handling_in_gnat summary-of-procedures-for-elaboration-control}@anchor{249}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id16}@anchor{24a} |
28908 @section Summary of Procedures for Elaboration Control | 28895 @section Summary of Procedures for Elaboration Control |
28909 | 28896 |
28910 | 28897 |
28911 A programmer should first compile the program with the default options, using | 28898 A programmer should first compile the program with the default options, using |
28912 none of the binder or compiler switches. If the binder succeeds in finding an | 28899 none of the binder or compiler switches. If the binder succeeds in finding an |
28913 elaboration order, then apart from possible cases involing dispatching calls | 28900 elaboration order, then apart from possible cases involing dispatching calls |
28914 and access-to-subprogram types, the program is free of elaboration errors. | 28901 and access-to-subprogram types, the program is free of elaboration errors. |
28902 | |
28915 If it is important for the program to be portable to compilers other than GNAT, | 28903 If it is important for the program to be portable to compilers other than GNAT, |
28916 then the programmer should use compiler switch @code{-gnatel} and consider | 28904 then the programmer should use compiler switch @code{-gnatel} and consider |
28917 the messages about missing or implicitly created @code{Elaborate} and | 28905 the messages about missing or implicitly created @code{Elaborate} and |
28918 @code{Elaborate_All} pragmas. | 28906 @code{Elaborate_All} pragmas. |
28919 | 28907 |
28922 | 28910 |
28923 | 28911 |
28924 @itemize * | 28912 @itemize * |
28925 | 28913 |
28926 @item | 28914 @item |
28927 Ensure that warnings are enabled. This will allow the static model to output | 28915 Ensure that elaboration warnings are enabled. This will allow the static |
28928 trace information of elaboration issues. The trace information could shed | 28916 model to output trace information of elaboration issues. The trace |
28929 light on previously unforeseen dependencies, as well as their origins. | 28917 information could shed light on previously unforeseen dependencies, as well |
28918 as their origins. Elaboration warnings are enabled with compiler switch | |
28919 @code{-gnatwl}. | |
28930 | 28920 |
28931 @item | 28921 @item |
28932 Use switch @code{-gnatel} to obtain messages on generated implicit | 28922 Use switch @code{-gnatel} to obtain messages on generated implicit |
28933 @code{Elaborate} and @code{Elaborate_All} pragmas. The trace information could | 28923 @code{Elaborate} and @code{Elaborate_All} pragmas. The trace information could |
28934 indicate why a server unit must be elaborated prior to a client unit. | 28924 indicate why a server unit must be elaborated prior to a client unit. |
28935 | 28925 |
28936 @item | 28926 @item |
28937 If the warnings produced by the static model indicate that a task is | 28927 If the warnings produced by the static model indicate that a task is |
28938 involved, consider the options in the section on resolving task issues as | 28928 involved, consider the options in section @ref{245,,Resolving Task Issues}. |
28939 well as compiler switch @code{-gnatd.y}. | 28929 |
28940 | 28930 @item |
28941 @item | 28931 If none of the steps outlined above resolve the circularity, use a more |
28942 If the warnings produced by the static model indicate that an generic | 28932 permissive elaboration model, in the following order: |
28943 instantiations are involved, consider using compiler switches | 28933 |
28944 @code{-gnatd.G} and @code{-gnatdL}. | 28934 |
28945 | 28935 @itemize - |
28946 @item | 28936 |
28947 If none of the steps outlined above resolve the circularity, recompile the | 28937 @item |
28948 program using the dynamic model by using compiler switch @code{-gnatE}. | 28938 Use the dynamic elaboration model, with compiler switch @code{-gnatE}. |
28939 | |
28940 @item | |
28941 Use the legacy static elaboration model, with compiler switch | |
28942 @code{-gnatH}. | |
28943 | |
28944 @item | |
28945 Use the legacy dynamic elaboration model, with compiler switches | |
28946 @code{-gnatH} @code{-gnatE}. | |
28947 | |
28948 @item | |
28949 Use the relaxed legacy static elaboration model, with compiler switches | |
28950 @code{-gnatH} @code{-gnatJ}. | |
28951 | |
28952 @item | |
28953 Use the relaxed legacy dynamic elaboration model, with compiler switches | |
28954 @code{-gnatH} @code{-gnatJ} @code{-gnatE}. | |
28949 @end itemize | 28955 @end itemize |
28956 @end itemize | |
28950 | 28957 |
28951 @node Inspecting the Chosen Elaboration Order,,Summary of Procedures for Elaboration Control,Elaboration Order Handling in GNAT | 28958 @node Inspecting the Chosen Elaboration Order,,Summary of Procedures for Elaboration Control,Elaboration Order Handling in GNAT |
28952 @anchor{gnat_ugn/elaboration_order_handling_in_gnat inspecting-the-chosen-elaboration-order}@anchor{24c}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id17}@anchor{24d} | 28959 @anchor{gnat_ugn/elaboration_order_handling_in_gnat inspecting-the-chosen-elaboration-order}@anchor{24b}@anchor{gnat_ugn/elaboration_order_handling_in_gnat id17}@anchor{24c} |
28953 @section Inspecting the Chosen Elaboration Order | 28960 @section Inspecting the Chosen Elaboration Order |
28954 | 28961 |
28955 | 28962 |
28956 To see the elaboration order chosen by the binder, inspect the contents of file | 28963 To see the elaboration order chosen by the binder, inspect the contents of file |
28957 @cite{b~xxx.adb}. On certain targets, this file appears as @cite{b_xxx.adb}. The | 28964 @cite{b~xxx.adb}. On certain targets, this file appears as @cite{b_xxx.adb}. The |
29084 text_io (spec) | 29091 text_io (spec) |
29085 gdbstr (body) | 29092 gdbstr (body) |
29086 @end example | 29093 @end example |
29087 | 29094 |
29088 @node Inline Assembler,GNU Free Documentation License,Elaboration Order Handling in GNAT,Top | 29095 @node Inline Assembler,GNU Free Documentation License,Elaboration Order Handling in GNAT,Top |
29089 @anchor{gnat_ugn/inline_assembler inline-assembler}@anchor{10}@anchor{gnat_ugn/inline_assembler doc}@anchor{24e}@anchor{gnat_ugn/inline_assembler id1}@anchor{24f} | 29096 @anchor{gnat_ugn/inline_assembler inline-assembler}@anchor{10}@anchor{gnat_ugn/inline_assembler doc}@anchor{24d}@anchor{gnat_ugn/inline_assembler id1}@anchor{24e} |
29090 @chapter Inline Assembler | 29097 @chapter Inline Assembler |
29091 | 29098 |
29092 | 29099 |
29093 @geindex Inline Assembler | 29100 @geindex Inline Assembler |
29094 | 29101 |
29143 * Other Asm Functionality:: | 29150 * Other Asm Functionality:: |
29144 | 29151 |
29145 @end menu | 29152 @end menu |
29146 | 29153 |
29147 @node Basic Assembler Syntax,A Simple Example of Inline Assembler,,Inline Assembler | 29154 @node Basic Assembler Syntax,A Simple Example of Inline Assembler,,Inline Assembler |
29148 @anchor{gnat_ugn/inline_assembler id2}@anchor{250}@anchor{gnat_ugn/inline_assembler basic-assembler-syntax}@anchor{251} | 29155 @anchor{gnat_ugn/inline_assembler id2}@anchor{24f}@anchor{gnat_ugn/inline_assembler basic-assembler-syntax}@anchor{250} |
29149 @section Basic Assembler Syntax | 29156 @section Basic Assembler Syntax |
29150 | 29157 |
29151 | 29158 |
29152 The assembler used by GNAT and gcc is based not on the Intel assembly | 29159 The assembler used by GNAT and gcc is based not on the Intel assembly |
29153 language, but rather on a language that descends from the AT&T Unix | 29160 language, but rather on a language that descends from the AT&T Unix |
29259 @end display | 29266 @end display |
29260 | 29267 |
29261 | 29268 |
29262 | 29269 |
29263 @node A Simple Example of Inline Assembler,Output Variables in Inline Assembler,Basic Assembler Syntax,Inline Assembler | 29270 @node A Simple Example of Inline Assembler,Output Variables in Inline Assembler,Basic Assembler Syntax,Inline Assembler |
29264 @anchor{gnat_ugn/inline_assembler a-simple-example-of-inline-assembler}@anchor{252}@anchor{gnat_ugn/inline_assembler id3}@anchor{253} | 29271 @anchor{gnat_ugn/inline_assembler a-simple-example-of-inline-assembler}@anchor{251}@anchor{gnat_ugn/inline_assembler id3}@anchor{252} |
29265 @section A Simple Example of Inline Assembler | 29272 @section A Simple Example of Inline Assembler |
29266 | 29273 |
29267 | 29274 |
29268 The following example will generate a single assembly language statement, | 29275 The following example will generate a single assembly language statement, |
29269 @code{nop}, which does nothing. Despite its lack of run-time effect, | 29276 @code{nop}, which does nothing. Despite its lack of run-time effect, |
29408 input file, so you can easily find and correct any mistakes you made. | 29415 input file, so you can easily find and correct any mistakes you made. |
29409 If there are no errors, @code{as} will generate an object file | 29416 If there are no errors, @code{as} will generate an object file |
29410 @code{nothing.out}. | 29417 @code{nothing.out}. |
29411 | 29418 |
29412 @node Output Variables in Inline Assembler,Input Variables in Inline Assembler,A Simple Example of Inline Assembler,Inline Assembler | 29419 @node Output Variables in Inline Assembler,Input Variables in Inline Assembler,A Simple Example of Inline Assembler,Inline Assembler |
29413 @anchor{gnat_ugn/inline_assembler id4}@anchor{254}@anchor{gnat_ugn/inline_assembler output-variables-in-inline-assembler}@anchor{255} | 29420 @anchor{gnat_ugn/inline_assembler id4}@anchor{253}@anchor{gnat_ugn/inline_assembler output-variables-in-inline-assembler}@anchor{254} |
29414 @section Output Variables in Inline Assembler | 29421 @section Output Variables in Inline Assembler |
29415 | 29422 |
29416 | 29423 |
29417 The examples in this section, showing how to access the processor flags, | 29424 The examples in this section, showing how to access the processor flags, |
29418 illustrate how to specify the destination operands for assembly language | 29425 illustrate how to specify the destination operands for assembly language |
29775 end Get_Flags_3; | 29782 end Get_Flags_3; |
29776 @end example | 29783 @end example |
29777 @end quotation | 29784 @end quotation |
29778 | 29785 |
29779 @node Input Variables in Inline Assembler,Inlining Inline Assembler Code,Output Variables in Inline Assembler,Inline Assembler | 29786 @node Input Variables in Inline Assembler,Inlining Inline Assembler Code,Output Variables in Inline Assembler,Inline Assembler |
29780 @anchor{gnat_ugn/inline_assembler id5}@anchor{256}@anchor{gnat_ugn/inline_assembler input-variables-in-inline-assembler}@anchor{257} | 29787 @anchor{gnat_ugn/inline_assembler id5}@anchor{255}@anchor{gnat_ugn/inline_assembler input-variables-in-inline-assembler}@anchor{256} |
29781 @section Input Variables in Inline Assembler | 29788 @section Input Variables in Inline Assembler |
29782 | 29789 |
29783 | 29790 |
29784 The example in this section illustrates how to specify the source operands | 29791 The example in this section illustrates how to specify the source operands |
29785 for assembly language statements. | 29792 for assembly language statements. |
29864 ret | 29871 ret |
29865 @end example | 29872 @end example |
29866 @end quotation | 29873 @end quotation |
29867 | 29874 |
29868 @node Inlining Inline Assembler Code,Other Asm Functionality,Input Variables in Inline Assembler,Inline Assembler | 29875 @node Inlining Inline Assembler Code,Other Asm Functionality,Input Variables in Inline Assembler,Inline Assembler |
29869 @anchor{gnat_ugn/inline_assembler id6}@anchor{258}@anchor{gnat_ugn/inline_assembler inlining-inline-assembler-code}@anchor{259} | 29876 @anchor{gnat_ugn/inline_assembler id6}@anchor{257}@anchor{gnat_ugn/inline_assembler inlining-inline-assembler-code}@anchor{258} |
29870 @section Inlining Inline Assembler Code | 29877 @section Inlining Inline Assembler Code |
29871 | 29878 |
29872 | 29879 |
29873 For a short subprogram such as the @code{Incr} function in the previous | 29880 For a short subprogram such as the @code{Incr} function in the previous |
29874 section, the overhead of the call and return (creating / deleting the stack | 29881 section, the overhead of the call and return (creating / deleting the stack |
29935 @end quotation | 29942 @end quotation |
29936 | 29943 |
29937 thus saving the overhead of stack frame setup and an out-of-line call. | 29944 thus saving the overhead of stack frame setup and an out-of-line call. |
29938 | 29945 |
29939 @node Other Asm Functionality,,Inlining Inline Assembler Code,Inline Assembler | 29946 @node Other Asm Functionality,,Inlining Inline Assembler Code,Inline Assembler |
29940 @anchor{gnat_ugn/inline_assembler other-asm-functionality}@anchor{25a}@anchor{gnat_ugn/inline_assembler id7}@anchor{25b} | 29947 @anchor{gnat_ugn/inline_assembler other-asm-functionality}@anchor{259}@anchor{gnat_ugn/inline_assembler id7}@anchor{25a} |
29941 @section Other @code{Asm} Functionality | 29948 @section Other @code{Asm} Functionality |
29942 | 29949 |
29943 | 29950 |
29944 This section describes two important parameters to the @code{Asm} | 29951 This section describes two important parameters to the @code{Asm} |
29945 procedure: @code{Clobber}, which identifies register usage; | 29952 procedure: @code{Clobber}, which identifies register usage; |
29950 * The Volatile Parameter:: | 29957 * The Volatile Parameter:: |
29951 | 29958 |
29952 @end menu | 29959 @end menu |
29953 | 29960 |
29954 @node The Clobber Parameter,The Volatile Parameter,,Other Asm Functionality | 29961 @node The Clobber Parameter,The Volatile Parameter,,Other Asm Functionality |
29955 @anchor{gnat_ugn/inline_assembler the-clobber-parameter}@anchor{25c}@anchor{gnat_ugn/inline_assembler id8}@anchor{25d} | 29962 @anchor{gnat_ugn/inline_assembler the-clobber-parameter}@anchor{25b}@anchor{gnat_ugn/inline_assembler id8}@anchor{25c} |
29956 @subsection The @code{Clobber} Parameter | 29963 @subsection The @code{Clobber} Parameter |
29957 | 29964 |
29958 | 29965 |
29959 One of the dangers of intermixing assembly language and a compiled language | 29966 One of the dangers of intermixing assembly language and a compiled language |
29960 such as Ada is that the compiler needs to be aware of which registers are | 29967 such as Ada is that the compiler needs to be aware of which registers are |
30014 @item | 30021 @item |
30015 Use 'register' name @code{memory} if you changed a memory location | 30022 Use 'register' name @code{memory} if you changed a memory location |
30016 @end itemize | 30023 @end itemize |
30017 | 30024 |
30018 @node The Volatile Parameter,,The Clobber Parameter,Other Asm Functionality | 30025 @node The Volatile Parameter,,The Clobber Parameter,Other Asm Functionality |
30019 @anchor{gnat_ugn/inline_assembler the-volatile-parameter}@anchor{25e}@anchor{gnat_ugn/inline_assembler id9}@anchor{25f} | 30026 @anchor{gnat_ugn/inline_assembler the-volatile-parameter}@anchor{25d}@anchor{gnat_ugn/inline_assembler id9}@anchor{25e} |
30020 @subsection The @code{Volatile} Parameter | 30027 @subsection The @code{Volatile} Parameter |
30021 | 30028 |
30022 | 30029 |
30023 @geindex Volatile parameter | 30030 @geindex Volatile parameter |
30024 | 30031 |
30050 important for efficiency. In general, you should set @code{Volatile} | 30057 important for efficiency. In general, you should set @code{Volatile} |
30051 to @code{True} only if the compiler's optimizations have created | 30058 to @code{True} only if the compiler's optimizations have created |
30052 problems. | 30059 problems. |
30053 | 30060 |
30054 @node GNU Free Documentation License,Index,Inline Assembler,Top | 30061 @node GNU Free Documentation License,Index,Inline Assembler,Top |
30055 @anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license doc}@anchor{260}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{261} | 30062 @anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license doc}@anchor{25f}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{260} |
30056 @chapter GNU Free Documentation License | 30063 @chapter GNU Free Documentation License |
30057 | 30064 |
30058 | 30065 |
30059 Version 1.3, 3 November 2008 | 30066 Version 1.3, 3 November 2008 |
30060 | 30067 |