5.4. Expressions

5.4.1. Listing local variable

When a program is running under the control of the debugger, the Locals list window can be opened by choosing View->Locals

Local variables of the current frame (the current funtion in which the program control is present) are displayed in the Locals list window. During execution of the program (eg. during single stepping), local variables will be updated. If any varialble value was changed in the last debugging step, its value will be highlight in red. The variables are presented in a tree form for easy view.

Figure 5-4. Local variables

The value of a local variable can be modified by selecting it and clicking in the value column.

Note

Gdb is more and more often used as a back end for a graphical front end. It has been improved recently in this area. It is recommanded to use the latest version (6.6) of gdb. On older version, gdb can crash when the front end ask for an pointer with an invalid (but not used) value.

5.4.2. Listing watched expressions

Inspecting or evaluating an expression provides the result only once. To continuously monitor some variables or expressions, use expression watch.

Choose the menu item View->Watch Window to display the expression watch window.

5.4.3. Adding an expression to watch

Right-click on the expression watch window to open the Operation menu. Choose the menu item Add Watch…. Alternatively, you can use Debug->Add Watch… A dialog prompting for the expression will appear. Enter the expression and click OK.

By default watch expression are updated automatically each time the program is stopped. This can be changed in the add watch dialog or later using the Automatic update menu item in the expression watch window popup menu. A watched expression can be update manually by choosing Update Watch or Update All in the previous menu.

It is not necessary to have the debugger running to add a new watch expression. If the debugger is not running or the corresponding expression cannot be found, the front end will try to create the watch expression, each time the program is stopped.

5.4.4. Removing an expression from watch

Select the watch expression that you want to remove in the expression watch window, then open the Operation menu, clicking with the right mouse button, and choose the menu item Remove to remove it.

All watch can be removed by choosing Remove All in the popup menu of the expression watch window.

5.4.5. Evaluating expressions

When control is returned from a program — possibly at a breakpoint — it is possible to evaluate expressions or inspect the values of variables in the program. Choose the menu item Debug->Inspect/Evaluate …, Inspect/Evaluate … in the popup menu of the editor or click the Inspect button on the Debug Toolbar.

A window will appear showing the result of the evaluation.

If an expression is highlighted in the editor, it is already displayed else the window is empty. In both cases, you an select a new expression by clicking on the name column and writing the new expression.

The expression can be added directly in the list of watched expressions by clicking on Add button.