Tech Tips: Debugging COBOL code in Visual Studio - Breakpoints and Watchpoints

Micro Focus Expert
Micro Focus Expert
3 0 909

Introduction

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.

Breakpoints

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

BP.png

 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.

BP1.png

 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.

BP3.png

 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 :

BP2l.png

 

For example, setting the conditions as follows :

BPlast.png

 

will pause execution the second time item-c is modified.

Conclusion

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.

About the Author
Visual Studio IDE
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.