Once started, program execution continues until one of the following events occurs:
Whenever the debugger suspends execution of the program, the main
window display is updated and the current-location pointer marks which
line of code will execute next.
10.3.3 Executing Your Program One Source Line at a Time
To execute one source line of your program, click on the STEP button in the push button view or enter the STEP command in the command view. This debugging technique (called stepping) is one of the most commonly used.
After the line executes, the source view is updated and the current-location pointer marks which line of code will execute next.
Note the following points about source lines and the stepping behavior:
Keep in mind that if you optimized your code at compilation time, the
source code displayed might not reflect the code that is actually
executing (see Section 1.2).
10.3.4 Stepping into a Called Routine
When program execution is paused at a routine call statement, clicking on the STEP button typically executes the called routine in one step (depending on the coding style used), and the debugger suspends execution at the next source line in the calling routine (assuming no breakpoint was set within the called routine). This enables you to step through the code quickly without having to trace execution through any called routines (some of which might be system or library routines). This is called stepping over called routines.
To step into a called routine so that you can execute it one line at a time:
Once execution is within the called routine, click on the STEP button to execute the routine line by line.
Clicking on the S/in button when execution is not paused at a routine
call statement is the same as clicking on the STEP button.
10.3.5 Returning from a Called Routine
When execution is suspended within a called routine, you can execute your program directly to the end of that routine by clicking on the S/ret button in the push button view, or enter the STEP/RETURN command at the DBG> prompt.
The debugger suspends execution just before the routine's return instruction executes. At that point, the routine's call frame has not been deleted from the call stack, so you can still get the values of variables local to that routine, and so on.
You can also use the S/call button in the push button view (or enter the STEP/CALL command at the DBG> prompt) to execute the program directly to the next Return or Call instruction.
The S/ret button is particularly useful if you have inadvertently
stepped into a system or library routine (see Section 10.1.3).
10.4 Suspending Execution by Setting Breakpoints
A breakpoint is a location in your program at which you want execution to stop so that you can check the current value of a variable, step into a routine, and so on.
When using the debugger's DECwindows Motif interface, you can set breakpoints on:
Note
If you are stopped at a breakpoint in a routine that has control of the mouse pointer by a PointerGrab or a KeyboardGrab, your workstation will hang.To work around this problem, debug your program using two workstations. For more information, see Section 9.7.3.1.
The debugger provides two ways to qualify breakpoints:
You can set a breakpoint that is both a conditional and action breakpoint.
The following sections explain these breakpoint options.
10.4.1 Setting Breakpoints on Source Lines
You can set a breakpoint on any source line that has a button to its left in the source display. These are the lines for which the compiler has generated executable code (routine declarations, assignment statements, and so on).
To set a breakpoint on a source line:
Figure 10-4 shows that a breakpoint has been set on the start of line 37.
Figure 10-4 Setting a Breakpoint on a Source Line
Setting a breakpoint on a routine enables you to move execution directly to the routine and inspect the local environment.
To set a breakpoint on a routine:
Figure 10-5 Setting a Breakpoint on a Routine
An exception breakpoint suspends execution when an exception is signaled and before any exception handler declared by your program executes. This enables you to step into the exception handler (if one is available) to check the flow of control.
To set an exception breakpoint, choose On Exception from the Break menu
on the main window or the optional views window. The exception
breakpoint triggers whenever any exception is signaled.
10.4.4 Identifying the Currently Set Breakpoints
There are three ways to determine which breakpoints are currently set:
After a breakpoint is set, you can deactivate, activate, or delete it.
Deactivating a breakpoint causes the debugger to ignore the breakpoint during program execution. However, the debugger keeps the breakpoint listed in the breakpoint view so that you can activate it at a later time, for example, when you rerun the program (see Section 9.3). Note the following points:
Activating a breakpoint causes it to take effect during program execution:
When you cancel a breakpoint, it is no longer listed in the breakpoint view so that later you cannot activate it from that list. You have to reset the breakpoint as explained in Section 10.4.1 and Section 10.4.2. Note the following points:
A conditional breakpoint suspends execution only when a specified expression is evaluated as true. For example, you can specify that a breakpoint take effect when the value of a variable in your program is 4. The breakpoint is ignored if the value is other than 4.
The debugger evaluates the conditional expression when the breakpoint triggers during execution of your program.
The following procedure sets a conditional breakpoint, whether or not a breakpoint was previously set at that location:
Figure 10-6 Setting a Conditional Breakpoint
The following procedure modifies a conditional breakpoint; that is, it can be used to change the location or condition associated with an existing conditional breakpoint, or to change an unqualified breakpoint into a conditional breakpoint:
When an action breakpoint triggers, the debugger suspends execution and then executes a specified list of commands.
To set an action breakpoint, whether or not a breakpoint was previously set at that location:
Figure 10-7 Setting an Action Breakpoint
The following procedure modifies an action breakpoint; that is, it can be used to change the location or command associated with an existing action breakpoint, or to change an unqualified breakpoint into an action breakpoint:
This section explains how to:
See Section 10.6, which also applies to all operations on variables.
10.5.1 Selecting Variable Names from Windows
Use the following techniques to select variable names from windows for the operations described in the sections that follow (see Section 10.5.2 for examples).
When selecting names, follow the syntax of the source programming language:
Select character strings from windows as follows:
To display the current value of a variable:
Figure 10-8, Figure 10-9, and Figure 10-10 show how to display the value of an integer variable, array aggregate, and array element, respectively.
Figure 10-8 Displaying the Value of an Integer Variable
Figure 10-9 Displaying the Value of an Array Aggregate
Figure 10-10 Displaying the Value of an Array Element
To display the current value in a different type or radix, use the following alternative method:
The value, altered to your specification, appears in the command view.
Figure 10-11 shows that the variable j has been typecast as long.
Figure 10-11 Typecasting the Value of a Variable
To change the current value of a variable:
The new value, altered to your specification, appears in the command view and is assigned to the variable.
Figure 10-12 shows a new value for the variable safe.
Figure 10-12 Changing the Value of a Variable
When you monitor a variable, the debugger displays the value in the monitor view and checks and updates the displayed value whenever the debugger regains control from your program (for example, after a step or at a breakpoint).
Note
You can monitor only a variable, including an aggregate such as an array or structure (record). You cannot monitor a composite expression or memory address.
To monitor a variable (see Figure 10-13):
You can typecast the output value when monitoring variables by choosing the Typecast item in the Monitor menu.
You can change the output radix when monitoring variables as follows:
To remove a monitored element from the monitor view, choose Remove from the Monitor menu.
Figure 10-13 Monitoring a Variable
If you select the name of an aggregate variable, such as an array or structure (record) and click on the MON button, the debugger displays the word Aggregate in the Value/Deposit column of the monitor view. To display the values of all elements (components) of an aggregate variable, double click on the variable name in the Monitor Expression column (or choose Expand in the Monitor menu). The displayed element names are indented relative to the parent name (see Figure 10-14). If an element is also an aggregate, you can double click on its name to display its elements, and so on.
Figure 10-14 Expanded Aggregate Variable (Array) in Monitor View
To collapse an expanded display so that only the aggregate parent name is shown in the monitor view, double click on the name in the Monitor Expression column (or choose Collapse from the Monitor menu).
If you have selected a component of an aggregate variable, and the
component expression is itself a variable, the debugger monitors the
component that was active when you made the selection. For example, if
you select the array component arr[i] and the current value of
i is 9, the debugger monitors arr[9] even if
the value of i subsequently changes to 10.
10.5.4.2 Monitoring a Pointer (Access) Variable
If you select the name of a pointer (access) variable and click on the
MON button, the debugger displays the address of the referenced object
in the
Value/Deposit column of the monitor view (see the top entry in
Figure 10-15).
To monitor the value of the referenced object (to dereference the pointer variable), double click on the pointer name in the Monitor Expression column. This adds an entry for the referenced object in the monitor view, indented under the pointer entry (see the bottom entry in Figure 10-15). If a referenced object is an aggregate, you can double click on its name to display its elements, and so on.
Figure 10-15 Pointer Variable and Referenced Object in Monitor View
Whenever the program changes the value of a watched variable, the debugger suspends execution and displays the old and new values in the command view.
To watch a variable (also known as setting a watchpoint on a variable):
Figure 10-16 Watched Variable in Monitor View
To deactivate a watchpoint, clear its Watched button in the monitor view (by clicking on the button) or choose Toggle Watchpoint in the Monitor menu. To activate a watchpoint, fill in its Watched button or choose Toggle Watchpoint in the Monitor menu.
Section 10.6.1 explains static and nonstatic (automatic) variables and how to access them. The debugger deactivates a nonstatic watchpoint when execution moves out of (returns from) the variable's defining routine. When a nonstatic variable is no longer active, its entry is dimmed in the monitor view and its Watched button is cleared.
The debugger does not automatically reactivate nonstatic watchpoints if
execution later returns to the variable's defining routine. You must
reactivate nonstatic watchpoints explicitly.
10.5.6 Changing the Value of a Monitored Scalar Variable
To change the value of a scalar (nonaggregate) variable, such as an integer or Boolean type (see Figure 10-17):
Figure 10-17 Changing the Value of a Monitored Scalar Variable
4538P016.HTM OSSG Documentation 22-NOV-1996 13:01:54.50
Copyright © Digital Equipment Corporation 1996. All Rights Reserved.