Tech Tips: Debugging COBOL code in Visual Studio – Data Items

Micro Focus Expert
Micro Focus Expert
3 0 759

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 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.

Pinning 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.

QuickWatch

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.

quickwatch.png

 

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.

Display formats

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.

For example

item,h

always displays the value of 'item' in hexadecimal format regardless of the debugger mode.

item,d

always displays a numeric item in decimal format regardless of the debugger mode. A full list of qualifiers is provided in the product documentation.

Modifying values

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:

COBOLVis.png

 

Text tab selected:

COBOLVis2.png

 

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 developers working with COBOL code, and we continue to add new features to further enhance the debugging experience.

Tags (1)
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.