comparison gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
114 Running GDB 114 Running GDB
115 ----------- 115 -----------
116 116
117 This section describes how to initiate the debugger. 117 This section describes how to initiate the debugger.
118 118
119 The debugger can be launched from a ``GPS`` menu or 119 The debugger can be launched from a ``GNAT Studio`` menu or
120 directly from the command line. The description below covers the latter use. 120 directly from the command line. The description below covers the latter use.
121 All the commands shown can be used in the ``GPS`` debug console window, 121 All the commands shown can be used in the ``GNAT Studio`` debug console window,
122 but there are usually more GUI-based ways to achieve the same effect. 122 but there are usually more GUI-based ways to achieve the same effect.
123 123
124 The command to run ``GDB`` is 124 The command to run ``GDB`` is
125 125
126 :: 126 ::
1212 .. _Profiling: 1212 .. _Profiling:
1213 1213
1214 Profiling 1214 Profiling
1215 ========= 1215 =========
1216 1216
1217 This section describes how to use the the ``gprof`` profiler tool on Ada 1217 This section describes how to use the ``gprof`` profiler tool on Ada programs.
1218 programs.
1219 1218
1220 .. index:: ! gprof 1219 .. index:: ! gprof
1221 .. index:: Profiling 1220 .. index:: Profiling
1222 1221
1223 .. _Profiling_an_Ada_Program_with_gprof: 1222 .. _Profiling_an_Ada_Program_with_gprof:
1404 1403
1405 This section presents several topics related to program performance. 1404 This section presents several topics related to program performance.
1406 It first describes some of the tradeoffs that need to be considered 1405 It first describes some of the tradeoffs that need to be considered
1407 and some of the techniques for making your program run faster. 1406 and some of the techniques for making your program run faster.
1408 1407
1409 .. only:: PRO or GPL 1408 It then documents the unused subprogram/data elimination feature,
1410 1409 which can reduce the size of program executables.
1411 It then documents the unused subprogram/data elimination feature
1412 and the ``gnatelim`` tool,
1413 which can reduce the size of program executables.
1414
1415
1416 .. only:: FSF
1417
1418 It then documents the unused subprogram/data elimination feature,
1419 which can reduce the size of program executables.
1420
1421 1410
1422 .. _Performance_Considerations: 1411 .. _Performance_Considerations:
1423 1412
1424 Performance Considerations 1413 Performance Considerations
1425 -------------------------- 1414 --------------------------
2594 2583
2595 It can be observed that the procedure ``Unused`` and the object 2584 It can be observed that the procedure ``Unused`` and the object
2596 ``Unused_Data`` are removed by the linker when using the 2585 ``Unused_Data`` are removed by the linker when using the
2597 appropriate options. 2586 appropriate options.
2598 2587
2599 .. only:: PRO or GPL
2600
2601 .. _Reducing_Size_of_Ada_Executables_with_gnatelim:
2602
2603 Reducing Size of Ada Executables with ``gnatelim``
2604 --------------------------------------------------
2605
2606 .. index:: gnatelim
2607
2608 This section describes ``gnatelim``, a tool which detects unused
2609 subprograms and helps the compiler to create a smaller executable for your
2610 program.
2611
2612 ``gnatelim`` is a project-aware tool.
2613 (See :ref:`Using_Project_Files_with_GNAT_Tools` for a description of
2614 the project-related switches but note that ``gnatelim`` does not support
2615 the :samp:`-U {main_unit}`, :samp:`--subdirs={dir}`, or
2616 :samp:`--no_objects_dir` switches.)
2617 The project file package that can specify
2618 ``gnatelim`` switches is named ``Eliminate``.
2619
2620 .. _About_gnatelim:
2621
2622 About ``gnatelim``
2623 ^^^^^^^^^^^^^^^^^^
2624
2625 When a program shares a set of Ada
2626 packages with other programs, it may happen that this program uses
2627 only a fraction of the subprograms defined in these packages. The code
2628 created for these unused subprograms increases the size of the executable.
2629
2630 ``gnatelim`` tracks unused subprograms in an Ada program and
2631 outputs a list of GNAT-specific pragmas ``Eliminate`` marking all the
2632 subprograms that are declared but never called. By placing the list of
2633 ``Eliminate`` pragmas in the GNAT configuration file :file:`gnat.adc` and
2634 recompiling your program, you may decrease the size of its executable,
2635 because the compiler will not generate the code for 'eliminated' subprograms.
2636 See ``Pragma_Eliminate`` in the :title:`GNAT_Reference_Manual` for more
2637 information about this pragma.
2638
2639 ``gnatelim`` needs as its input data the name of the main subprogram.
2640
2641 If a set of source files is specified as ``gnatelim`` arguments, it
2642 treats these files as a complete set of sources making up a program to
2643 analyse, and analyses only these sources.
2644
2645 If ``gnatelim`` is called with a project file and :samp:`-U` option is
2646 used, then in process all the files from the argument project but
2647 not just the closure of the main subprogram.
2648
2649 In all the other cases (that are typical cases of ``gnatelim`` usage, when
2650 the only ``gnatelim`` parameter is the name of the source file containing
2651 the main subprogram) gnatelim needs the full closure of the main subprogram.
2652 When called with a project file, gnatelim computes this closure itself.
2653 Otherwise it assumes that it can reuse the results of the previous
2654 build of the main subprogram.
2655
2656 If the set of sources to be processed by ``gnatelim`` contains sources with
2657 preprocessing directives
2658 then the needed options should be provided to run preprocessor as a part of
2659 the ``gnatelim`` call, and the generated set of pragmas ``Eliminate``
2660 will correspond to preprocessed sources.
2661
2662
2663 .. _Running_gnatelim:
2664
2665 Running ``gnatelim``
2666 ^^^^^^^^^^^^^^^^^^^^
2667
2668 ``gnatelim`` has the following command-line interface:
2669
2670
2671 ::
2672
2673 $ gnatelim [switches] -main=`main_unit_name {filename} [-cargs gcc_switches]
2674
2675 ``main_unit_name`` should be a name of a source file that contains the main
2676 subprogram of a program (partition).
2677
2678 Each ``filename`` is the name (including the extension) of a source
2679 file to process. 'Wildcards' are allowed, and
2680 the file name may contain path information.
2681
2682 ``gcc_switches`` is a list of switches for
2683 ``gcc``. They will be passed on to all compiler invocations made by
2684 ``gnatelim`` to generate the ASIS trees. Here you can provide
2685 :switch:`-I` switches to form the source search path,
2686 use the :switch:`-gnatec` switch to set the configuration file,
2687 use the :switch:`-gnat05` switch if sources should be compiled in
2688 Ada 2005 mode etc.
2689
2690 ``gnatelim`` has the following switches:
2691
2692
2693 .. index:: --version (gnatelim)
2694
2695 :samp:`--version`
2696 Display Copyright and version, then exit disregarding all other options.
2697
2698
2699 .. index:: --help (gnatelim)
2700
2701 :samp:`--help`
2702 Display usage, then exit disregarding all other options.
2703
2704
2705 .. index:: -P (gnatelim)
2706
2707 :samp:`-P {file}`
2708 Indicates the name of the project file that describes the set of sources
2709 to be processed.
2710
2711
2712 .. index:: -X (gnatelim)
2713
2714 :samp:`-X{name}={value}`
2715 Indicates that external variable ``name`` in the argument project
2716 has the value ``value``. Has no effect if no project is specified as
2717 tool argument.
2718
2719
2720 .. index:: --RTS (gnatelim)
2721
2722 :samp:`--RTS={rts-path}`
2723 Specifies the default location of the runtime library. Same meaning as the
2724 equivalent ``gnatmake`` flag (:ref:`Switches_for_gnatmake`).
2725
2726
2727 .. index:: -U (gnatelim)
2728
2729 :samp:`-U`
2730 Process all the sources from the argument project. If no project file
2731 is specified, this option has no effect. If this option is used with the
2732 project file, ``gnatelim`` does not require the preliminary build of the
2733 argument main subprogram.
2734
2735
2736 .. index:: -files (gnatelim)
2737
2738 :samp:`-files={filename}`
2739 Take the argument source files from the specified file. This file should be an
2740 ordinary text file containing file names separated by spaces or
2741 line breaks. You can use this switch more than once in the same call to
2742 ``gnatelim``. You also can combine this switch with
2743 an explicit list of files.
2744
2745
2746 .. index:: -log (gnatelim)
2747
2748 :samp:`-log`
2749 Duplicate all the output sent to :file:`stderr` into a log file. The log file
2750 is named :file:`gnatelim.log` and is located in the current directory.
2751
2752 .. index:: --no-elim-dispatch (gnatelim)
2753
2754 :samp:`--no-elim-dispatch`
2755 Do not generate pragmas for dispatching operations.
2756
2757
2758 .. index:: --ignore (gnatelim)
2759
2760 :samp:`--ignore={filename}`
2761 Do not generate pragmas for subprograms declared in the sources
2762 listed in a specified file
2763
2764 .. index:: -o (gnatelim)
2765
2766
2767 :samp:`-o={report_file}`
2768 Put ``gnatelim`` output into a specified file. If this file already exists,
2769 it is overridden. If this switch is not used, ``gnatelim`` outputs its results
2770 into :file:`stderr`
2771
2772
2773 .. index:: -j (gnatelim)
2774
2775 :samp:`-j{n}`
2776 Use ``n`` processes to carry out the tree creations (internal representations
2777 of the argument sources). On a multiprocessor machine this speeds up processing
2778 of big sets of argument sources. If ``n`` is 0, then the maximum number of
2779 parallel tree creations is the number of core processors on the platform.
2780 This possibility is disabled if ``gnatelim`` has to compute the closure
2781 of the main unit.
2782
2783
2784 .. index:: -q (gnatelim)
2785
2786 :samp:`-q`
2787 Quiet mode: by default ``gnatelim`` outputs to the standard error
2788 stream the number of program units left to be processed. This option turns
2789 this trace off.
2790
2791 .. index:: -t (gnatelim)
2792
2793
2794 :samp:`-t`
2795 Print out execution time.
2796
2797
2798 .. index:: -v (gnatelim)
2799
2800 :samp:`-v`
2801 Verbose mode: ``gnatelim`` version information is printed as Ada
2802 comments to the standard output stream. Also, in addition to the number of
2803 program units left ``gnatelim`` will output the name of the current unit
2804 being processed.
2805
2806
2807 .. index:: -wq (gnatelim)
2808
2809 :samp:`-wq`
2810 Quiet warning mode - some warnings are suppressed. In particular warnings that
2811 indicate that the analysed set of sources is incomplete to make up a
2812 partition and that some subprogram bodies are missing are not generated.
2813
2814
2815
2816 .. _Processing_Precompiled_Libraries:
2817
2818 Processing Precompiled Libraries
2819 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2820
2821 If some program uses a precompiled Ada library, it can be processed by
2822 ``gnatelim`` in a usual way. ``gnatelim`` will newer generate an
2823 Eliminate pragma for a subprogram if the body of this subprogram has not
2824 been analysed, this is a typical case for subprograms from precompiled
2825 libraries. Switch :switch:`-wq` may be used to suppress
2826 warnings about missing source files and non-analyzed subprogram bodies
2827 that can be generated when processing precompiled Ada libraries.
2828
2829
2830 .. _Correcting_the_List_of_Eliminate_Pragmas:
2831
2832 Correcting the List of Eliminate Pragmas
2833 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2834
2835 In some rare cases ``gnatelim`` may try to eliminate
2836 subprograms that are actually called in the program. In this case, the
2837 compiler will generate an error message of the form:
2838
2839 ::
2840
2841 main.adb:4:08: cannot reference subprogram "P" eliminated at elim.out:5
2842
2843 You will need to manually remove the wrong ``Eliminate`` pragmas from
2844 the configuration file indicated in the error message. You should recompile
2845 your program from scratch after that, because you need a consistent
2846 configuration file(s) during the entire compilation.
2847
2848 If ``gnatelim`` is called with a project file and with ``-U`` option
2849 the generated set of pragmas may contain pragmas for subprograms that
2850 does not belong to the closure of the argument main subprogram. These
2851 pragmas has no effect when the set of pragmas is used to reduce the size
2852 of executable.
2853
2854 2588
2855 .. index:: Overflow checks 2589 .. index:: Overflow checks
2856 .. index:: Checks (overflow) 2590 .. index:: Checks (overflow)
2857 2591
2858 .. _Overflow_Check_Handling_in_GNAT: 2592 .. _Overflow_Check_Handling_in_GNAT:
3228 automatically include an appropriate arbitrary precision 2962 automatically include an appropriate arbitrary precision
3229 integer arithmetic package. The compiler will make calls 2963 integer arithmetic package. The compiler will make calls
3230 to this package, though only in cases where it cannot be 2964 to this package, though only in cases where it cannot be
3231 sure that ``Long_Long_Integer`` is sufficient to guard against 2965 sure that ``Long_Long_Integer`` is sufficient to guard against
3232 intermediate overflows. This package does not use dynamic 2966 intermediate overflows. This package does not use dynamic
3233 alllocation, but it does use the secondary stack, so an 2967 allocation, but it does use the secondary stack, so an
3234 appropriate secondary stack package must be present (this 2968 appropriate secondary stack package must be present (this
3235 is always true for standard full Ada, but may require 2969 is always true for standard full Ada, but may require
3236 specific steps for restricted run times such as ZFP). 2970 specific steps for restricted run times such as ZFP).
3237 2971
3238 Although ``ELIMINATED`` mode causes expressions to use arbitrary 2972 Although ``ELIMINATED`` mode causes expressions to use arbitrary
3659 3393
3660 :: 3394 ::
3661 3395
3662 $ gnatbind -u0 file 3396 $ gnatbind -u0 file
3663 3397
3664 With this option, at each task termination, its stack usage is output on 3398 With this option, at each task termination, its stack usage is output on
3665 :file:`stderr`. 3399 :file:`stderr`.
3400 Note that this switch is not compatible with tools like
3401 Valgrind and DrMemory; they will report errors.
3402
3666 It is not always convenient to output the stack usage when the program 3403 It is not always convenient to output the stack usage when the program
3667 is still running. Hence, it is possible to delay this output until program 3404 is still running. Hence, it is possible to delay this output until program
3668 termination. for a given number of tasks specified as the argument of the 3405 termination. for a given number of tasks specified as the argument of the
3669 ``-u`` option. For instance: 3406 ``-u`` option. For instance:
3670 3407
3970 3707
3971 The ``gnatmem`` command has the form 3708 The ``gnatmem`` command has the form
3972 3709
3973 :: 3710 ::
3974 3711
3975 $ gnatmem [ switches ] user_program 3712 $ gnatmem [ switches ] [ DEPTH ] user_program
3976 3713
3977 The program must have been linked with the instrumented version of the 3714 The program must have been linked with the instrumented version of the
3978 allocation and deallocation routines. This is done by linking with the 3715 allocation and deallocation routines. This is done by linking with the
3979 :file:`libgmem.a` library. For correct symbolic backtrace information, 3716 :file:`libgmem.a` library. For correct symbolic backtrace information,
3980 the user program should be compiled with debugging options 3717 the user program should be compiled with debugging options
4060 :samp:`-q` 3797 :samp:`-q`
4061 Quiet. Gives the minimum output needed to identify the origin of the 3798 Quiet. Gives the minimum output needed to identify the origin of the
4062 memory leaks. Omits statistical information. 3799 memory leaks. Omits statistical information.
4063 3800
4064 3801
4065 .. index:: N switch (gnatmem) 3802 .. index:: DEPTH switch (gnatmem)
4066 3803
4067 :samp:`{N}` 3804 :samp:`{DEPTH}`
4068 ``N`` is an integer literal (usually between 1 and 10) which controls the 3805 ``DEPTH`` is an integer literal (usually between 1 and 10) which controls
4069 depth of the backtraces defining allocation root. The default value for 3806 the depth of the backtraces defining allocation root. The default value for
4070 N is 1. The deeper the backtrace, the more precise the localization of 3807 DEPTH is 1. The deeper the backtrace, the more precise the localization of
4071 the root. Note that the total number of roots can depend on this 3808 the root. Note that the total number of roots can depend on this
4072 parameter. This parameter must be specified *before* the name of the 3809 parameter, in other words there may be more roots when the requested
4073 executable to be analyzed, to avoid ambiguity. 3810 backtrace depth is higher. This parameter must be specified *before* the
3811 name of the executable to be analyzed, to avoid ambiguity.
4074 3812
4075 3813
4076 .. index:: -b (gnatmem) 3814 .. index:: -b (gnatmem)
4077 3815
4078 :samp:`-b {N}` 3816 :samp:`-b {N}`