|
| 1 | +*********************** |
| 2 | +:toolname:`GNATstack` |
| 3 | +*********************** |
| 4 | + |
| 5 | +.. container:: PRELUDE BEGIN |
| 6 | + |
| 7 | +.. container:: PRELUDE ROLES |
| 8 | + |
| 9 | +.. role:: ada(code) |
| 10 | + :language: Ada |
| 11 | + |
| 12 | +.. role:: C(code) |
| 13 | + :language: C |
| 14 | + |
| 15 | +.. role:: cpp(code) |
| 16 | + :language: C++ |
| 17 | + |
| 18 | +.. role:: rust(code) |
| 19 | + :language: Rust |
| 20 | + |
| 21 | +.. container:: PRELUDE SYMBOLS |
| 22 | + |
| 23 | +.. |rightarrow| replace:: :math:`\rightarrow` |
| 24 | +.. |forall| replace:: :math:`\forall` |
| 25 | +.. |exists| replace:: :math:`\exists` |
| 26 | +.. |equivalent| replace:: :math:`\iff` |
| 27 | +.. |le| replace:: :math:`\le` |
| 28 | +.. |ge| replace:: :math:`\ge` |
| 29 | +.. |lt| replace:: :math:`<` |
| 30 | +.. |gt| replace:: :math:`>` |
| 31 | +.. |checkmark| replace:: :math:`\checkmark` |
| 32 | + |
| 33 | +.. container:: PRELUDE REQUIRES |
| 34 | + |
| 35 | +.. container:: PRELUDE PROVIDES |
| 36 | + |
| 37 | +.. container:: PRELUDE END |
| 38 | + |
| 39 | +============== |
| 40 | +Introduction |
| 41 | +============== |
| 42 | + |
| 43 | +-------------------------------- |
| 44 | +Determining Maximum Stack Size |
| 45 | +-------------------------------- |
| 46 | + |
| 47 | +* :toolname:`GNATstack` statically computes maximum stack space |
| 48 | + |
| 49 | + * For each application entry point (including tasks) |
| 50 | + |
| 51 | +* **Static** Analysis |
| 52 | + |
| 53 | + * Analyzes artifacts of compiler (not run-time execution) |
| 54 | + * Computes worst-case stack requirements |
| 55 | + * When no assumptions made, stack size never exceeds analyzed value |
| 56 | + |
| 57 | +--------- |
| 58 | +Outputs |
| 59 | +--------- |
| 60 | + |
| 61 | +* Worst-case stack requirements for each entry point |
| 62 | + |
| 63 | + * Entry points can be deduced from source or specified by user |
| 64 | + |
| 65 | +* Path leading to each scenario |
| 66 | + |
| 67 | +* :dfn:`Visualization of Compiler Graphs (VCG)` |
| 68 | + |
| 69 | + * File containing complete call tree for application |
| 70 | + * Contains both local and accumulated stack usage |
| 71 | + |
| 72 | +--------------------------- |
| 73 | +Optional Analysis Outputs |
| 74 | +--------------------------- |
| 75 | + |
| 76 | +* **Indirect calls** (including dispatching) |
| 77 | + |
| 78 | + * Number of indirect calls from any subprogram |
| 79 | + |
| 80 | +* **External calls** |
| 81 | + |
| 82 | + * All subprograms reachable from entry point where no stack/call graph information is available |
| 83 | + |
| 84 | +* **Unbounded frames** |
| 85 | + |
| 86 | + * All subprograms reachable from entry point with unbounded stack requirements |
| 87 | + * Stack size depends on arguments passed to the subprogram |
| 88 | + |
| 89 | +* **Cycles** |
| 90 | + |
| 91 | + * Detect call cycles in the call graph |
| 92 | + * Represent potential recursion for possibly unbounded stack consumption |
| 93 | + |
| 94 | +=============================== |
| 95 | +Running :toolname:`GNATstack` |
| 96 | +=============================== |
| 97 | + |
| 98 | +------------------------------- |
| 99 | +Running :toolname:`GNATstack` |
| 100 | +------------------------------- |
| 101 | + |
| 102 | +:command:`gnatstack [switches] {filename}` |
| 103 | + |
| 104 | +where :filename:`{filename}` can be a package spec or body |
| 105 | + |
| 106 | +* Package spec |
| 107 | + |
| 108 | + * :toolname:`GNATstack` will generate a package body containing "dummy" bodies for subprograms defined but not completed in the spec |
| 109 | + |
| 110 | +* Package body |
| 111 | + |
| 112 | + * For any subprogram defined as :ada:`separate` in the package body, a file will be created containing a body for the subprogram |
| 113 | + |
| 114 | +.. note:: Need to specify :command:`--subunits` switch |
| 115 | + |
| 116 | +---------------------- |
| 117 | +Example Subprogram |
| 118 | +---------------------- |
| 119 | + |
| 120 | +.. code:: Ada |
| 121 | + :number-lines: 1 |
| 122 | +
|
| 123 | + procedure Main_Unit is |
| 124 | + type Data_Type is array (1 .. 5) of Integer; |
| 125 | +
|
| 126 | + function Inverse (Input : Data_Type) return Data_Type is |
| 127 | + Result : Data_Type; |
| 128 | + begin |
| 129 | + for Index in Data_Type'Range loop |
| 130 | + Result (Index) := Input (Data_Type'Last - |
| 131 | + (Index - Data_Type'First)); |
| 132 | + end loop; |
| 133 | +
|
| 134 | + return Result; |
| 135 | + end Inverse; |
| 136 | +
|
| 137 | + Data : Data_Type := (1, 2, 3, 4, 5); |
| 138 | + Result : Data_Type; |
| 139 | + begin |
| 140 | + Result := Inverse (Data); |
| 141 | + end Main_Unit; |
| 142 | +
|
| 143 | +================================ |
| 144 | +:toolname:`GNATstack` Switches |
| 145 | +================================ |
| 146 | + |
| 147 | +---------------------------------- |
| 148 | +Controlling Behavior When Called |
| 149 | +---------------------------------- |
| 150 | + |
| 151 | +* TBD |
| 152 | + |
| 153 | +--------------------------- |
| 154 | +TBD |
| 155 | +--------------------------- |
| 156 | + |
| 157 | +* TBD |
| 158 | + |
| 159 | +===== |
| 160 | +Lab |
| 161 | +===== |
| 162 | + |
| 163 | +--------------------------- |
| 164 | +TBD |
| 165 | +--------------------------- |
| 166 | + |
| 167 | +* include:: labs/200_gnatstack/lab.rst |
| 168 | + |
| 169 | +========= |
| 170 | +Summary |
| 171 | +========= |
| 172 | + |
| 173 | +------------------------------------ |
| 174 | +Improving on :toolname:`GNATstack` |
| 175 | +------------------------------------ |
| 176 | + |
| 177 | +* TBD |
0 commit comments