Next: , Previous: Building a New Program with Glide, Up: Introduction to Glide and GVD

1.6.2 Simple Debugging with GVD

This section describes how to set breakpoints, examine/modify variables, and step through execution.

In order to enable debugging, you need to pass the -g switch to both the compiler and to gnatlink. If you are using the command line, passing -g to gnatmake will have this effect. You can then launch GVD, e.g. on the hello program, by issuing the command:

     $ gvd hello

If you are using Glide, then -g is passed to the relevant tools by default when you do a build. Start the debugger by selecting the Ada menu item, and then Debug.

GVD comes up in a multi-part window. One pane shows the names of files comprising your executable; another pane shows the source code of the current unit (initially your main subprogram), another pane shows the debugger output and user interactions, and the fourth pane (the data canvas at the top of the window) displays data objects that you have selected.

To the left of the source file pane, you will notice green dots adjacent to some lines. These are lines for which object code exists and where breakpoints can thus be set. You set/reset a breakpoint by clicking the green dot. When a breakpoint is set, the dot is replaced by an X in a red circle. Clicking the circle toggles the breakpoint off, and the red circle is replaced by the green dot.

For this example, set a breakpoint at the statement where Put_Line is invoked.

Start program execution by selecting the Run button on the top menu bar. (The Start button will also start your program, but it will cause program execution to break at the entry to your main subprogram.) Evidence of reaching the breakpoint will appear: the source file line will be highlighted, and the debugger interactions pane will display a relevant message.

You can examine the values of variables in several ways. Move the mouse over an occurrence of Ind in the for loop, and you will see the value (now 1) displayed. Alternatively, right-click on Ind and select Display Ind; a box showing the variable's name and value will appear in the data canvas.

Although a loop index is a constant with respect to Ada semantics, you can change its value in the debugger. Right-click in the box for Ind, and select the Set Value of Ind item. Enter 2 as the new value, and press OK. The box for Ind shows the update.

Press the Step button on the top menu bar; this will step through one line of program text (the invocation of Put_Line), and you can observe the effect of having modified Ind since the value displayed is 2.

Remove the breakpoint, and resume execution by selecting the Cont button. You will see the remaining output lines displayed in the debugger interaction window, along with a message confirming normal program termination.