### 13.8 Stack Analysis

GPS provides an interface to `GNATstack`, the static stack analysis tool. This interface is enabled only if you have the `gnatstack` executable installed on your system and available on the path.

Stack usage information can be computed from, loaded and visualized in GPS for the entire project hierarchy used in GPS. Stack usage information for unknown and unbounded calls can be edited in GPS.

Once computed and loaded, the stack usage information is summarized in a report, and used to decorate source code through stack usage annotations. The largest stack usage path is filled into the The Locations View.

Stack usage information for undefined subprograms can be specified by adding a `.ci` file to the set of GNATStack switches in the `Switches` attribute of the `Stack` package of your root project, e.g:

         project P is
            package Stack is
               for Switches use ("my.ci");
            end Stack;
         end P;

You can also specify this information by using the `GNATStack` page of the `Switches` section in the The Project Properties Editor. Several files can be specified.

The Stack Usage Editor can be used to edit stack usage information for undefined subprograms.

#### 13.8.1 The Stack Analysis Menu

All stack analysis related operations are reachable via the `Tools->Stack Analysis` menu:

`Analyze stack usage`
  Generates stack usage information for the root project.
`Open undefined subprograms editor`
  Opens undefined subprograms editor.
`Load last stack usage`
  Loads or re-loads last stack usage information for the root project.
`Clear stack usage data`
  Removes stack analysis data loaded in GPS and any associated information such as annotations in source editors.

#### 13.8.2 The Contextual Menu

When clicking on a project, file or subprogram entity (including the entities listed in the coverage report), you have access to a `Stack Analysis` submenu.

This submenu contains the following entries, related to the entity selected:

`Show stack usage`
  Shows stack usage information for every subprogram of currently selected file.
`Hide stack usage`
  Hides stack usage information for every subprogram of currently selected file.
`Call tree for xxx`
  Opens Call Tree view for currently selected subprogram.

#### 13.8.3 The Stack Usage Report

When the stack usage information is loaded, a report is displayed containing a summary of the stack analysis.

#### 13.8.4 The Stack Usage Editor

The Stack Usage Editor allows to specify stack usage for undefined subprograms and use these values to refine results of future analysis.

The Stack Usage Editor consists of two main areas. The notebook in the top area allows to select the file to edit. It displays the contents of the file and allows changing the stack usage of subprograms. The table in the bottom area displays all subprograms whose stack usage information is not specified so that they can be set.

Stack usage information for subprograms can be specified or changed by clicking in the stack usage column on the right of the subprogram's name. When a value is specified in the bottom area table, the subprogram is moved to the top table of the currently selected file. When a negative value is specified, the subprogram is moved to the bottom table.

All changes are saved when the stack usage editor window is closed.