An important part of the software development and maintenance process involves debugging code to fix problems or develop new functionality. Setting breakpoints and querying and modifying data items are key features of the debugging environment and both Visual Studio and Eclipse provide support for developers working with COBOL code to do so when debugging. This article gives an overview of the support for setting breakpoints and watchpoints in the Visual Studio development environment. Querying and modifying data is covered in a separate article.
Once the debugger has started the line of code that is about to be executed is highlighted. It is possible to use the Step Into, Step Out and Step Over commands to step through the code and the Run command to run the code continuously but typically only specific areas in the code are of interest and setting breakpoints and watchpoints allows the execution to be paused and those areas to be debugged.
There are a few ways to set a breakpoint ie a location at which the execution will be paused
- press F9 or Toggle Breakpoint on the Debug menu to set a breakpoint on the selected line
- click the mouse on the left column on the text window
- right-click the mouse on the selected line, select Breakpoint and Insert Breakpoint
An icon, normally a red circle, indicates that a breakpoint has been set and the Breakpoints tool window will contain the breakpoint information. When execution reaches a statement with a breakpoint the debugger will pause execution.
The Breakpoints tool window allows breakpoints to be enabled, disabled or deleted and also allows conditions to be applied. Applying conditions to a breakpoint will ensure that execution only pauses at the breakpoint location when the specified conditions are met. To add a condition to a breakpoint right-click the breakpoint and select Settings. Examples of possible conditions would be
Select Conditions in the dialog and choose Conditional Expression. In a program with a data item named myitem the condition could be set to
myitem = 10
When debugging, execution will only pause on the statement if the value of myitem is 10.
Another example :
Select Conditions in the dialog and choose Hit Count and set the count to 3.
When debugging, execution will only pause the third time the statement is reached.
Program breakpoints - native code only
Program breakpoints are a special type of breakpoint providing a means of pausing executing as soon as a program is entered. They can be set by right-clicking in a COBOL program and selecting Add COBOL Program Breakpoint from the context menu or the program name can be added directly in the Program Breakpoints tool window which can be displayed by selecting the Debug menu, then Windows and then Program Breakpoints (Native COBOL). The Program Breakpoints tool window allows the program breakpoints to be enabled, disabled or deleted and new program breakpoints to be added.
Watchpoints - native code only
Watchpoints are a special type of breakpoint that are not associated with a statement in the code, but with a data item. Setting a watchpoint on a data item will pause execution whenever the value of the item is changed.
To set a watchpoint select a data item in the source code and right-click to display the context menu or the item can be added directly in the Watchpoints tool window, displayed by selecting the Debug menu then Windows and then Watchpoints (Native COBOL). The Watchpoints tool window allows watchpoints to be enabled, disabled or deleted and new watchpoints to be added.
When debugging, whenever any of the data items with watchpoints are modified the debugger will pause and the modified item will be highlighted in the Watchpoints tool window showing the modified value. Here is an example showing a watchpoint on an item named item-c.
New feature – Conditional watchpoints
A new feature in the forthcoming versions of Visual COBOL and Enterprise Developer is functionality to specify conditions for watchpoints similar to the existing functionality for breakpoints. In the Watchpoints tool window select the data item to apply a condition by either double-clicking the mouse or select the ‘Conditions’ context menu item and a dialog is displayed allowing selection of the required condition.
For example, setting the conditions as follows :
For example, setting the conditions as follows :
will pause execution the second time item-c is modified.
The Micro Focus Visual COBOL and Enterprise Developer products running in the Visual Studio IDE provide a powerful and flexible debugging environment, vital to a developer working with COBOL code, and we continue to add new features to further enhance the debugging experience.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.