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 query and modify COBOL data items when debugging. This article gives an overview of the support in Visual Studio. Setting breakpoints and watchpoints is covered in a separate article.
Querying data items
A key part of any debugging session is monitoring code execution and examining values of data items to help identify potential issues in the code. There are a number of ways to view and edit the values of items.
The current value of a data item can be displayed simply by moving the mouse over the item. But the debugger also provides functionality to monitor (Watch) items as the code executes.
Adding a Watch item
To monitor an item do either of the following
- Move the mouse over the item to be viewed. Right-click the mouse to display a context menu and select Add Watch.
- Select the Debug menu then Windows, Watch, Watch 1 or the keyboard shortcut Ctrl Alt W,1 to display the Watch tool window, then type the name of the item in the window.
This adds the item to the Watch tool window showing the name, value and picture string. Group items and tables can be expanded to show the values of individual fields and the values of items can be modified. The value shown is updated as the code is executed.
Visual Studio provides up to four Watch windows, each of which may contain multiple items.
Move the mouse over a data item. A popup window is displayed showing the item's name and value. The item can be pinned by clicking on the icon resembling a pin and it continues to be displayed in the popup at that position as the code is executed.
To display the QuickWatch dialog move the text caret to a data item and display the context menu and select QuickWatch or press Shift F9. The data item name and value can be viewed or edited, a new item can be selected in the Expression field and the item can be added to the Watch window.
Memory window - native code
The Memory tool window, which can be displayed from Debug -> Windows -> Memory -> Memory 1 or Ctrl Alt M,1 displays the contents of memory starting at the address of the selected item. The name of an item can be entered directly into the Address text box or the item can be selected and dragged and dropped into the window to display the memory contents.
Up to four separate Memory windows can be displayed.
In each of the options it is possible to use the context menu to switch the debugger to and from hexadecimal mode. This applies to all of the items being displayed in the debugger, however individual items can be displayed in a specific format by adding a qualifier to the item.
always displays the value of 'item' in hexadecimal format regardless of the debugger mode.
always displays a numeric item in decimal format regardless of the debugger mode. A full list of qualifiers is provided in the product documentation.
Each of the options for viewing data items allows the value to be modified by selecting the Value field and typing the new value.
Other debug windows
When debugging, other tabs are displayed with the Watch window tab - Autos and Locals. The Autos window automatically displays the names and values of data items referenced on the current and previous statements. The Locals window displays variables local to the current method and will contain information when debugging managed code.
COBOL Visualizer – New feature
Lastly, and new in the forthcoming releases of Visual COBOL and Enterprise Developer, is the COBOL Visualizer. In the views above, various data types including alphanumeric items and group items show a magnifying glass icon to the right of the item name. That icon allows a visualizer to be displayed for the content. Visual Studio provides standard visualizers allowing an item's value to be displayed as Text, Html, Xml or Json but when debugging COBOL code the COBOL Visualizer can also be selected which allows the value to be displayed and edited in either hexadecimal or text. The visualizer makes editing the hexadecimal value more straightforward and also allows editing in text mode when an item contains non-displayable characters such as null bytes.
This is an example of the COBOL Visualizer displaying the value of a data item named testItem
With the Hex tab selected:
Text tab selected:
The Micro Focus Visual COBOL and Enterprise Developer products running in the Visual Studio IDE provide a powerful and flexible debugging environment, vital to developers working with COBOL code, and we continue to add new features to further enhance the debugging experience.