Here are some tips and tricks on debugging COBOL applications in the Visual Studio IDE:
- Add a Watch
- Right-click a variable in the editor and choose
Add Watch.
- Attach to a Running Process
- See
To attach to a running process and debug.
- Attach to a 64-bit Running Process
- See
To attach to a 64-bit running process and debug.
- Autos Window
- Displays the variables used in the current and in the previous statements and enables you to change their values or add watches to them. To display the window, click
Debug > Windows > Autos.
For variables in a copybook that are modified by COPY… REPLACING statements in your code, the Autos window displays all values defined in the source code.
When there are multiple COBOL programs in your project that perform a COPY… REPLACING in a copybook, the Autos window only uses the replacing values found in the first COBOL program.
- Breakpoint-Setting
- Double-click in the left margin of editor next the a line of code, or position the cursor on the line and press
F9. You can also choose
Debug > Toggle Breakpoint or choose
Breakpoint > Insert Breakpoint from the editor context menu.
- Note: Tracepoints are supported only when debugging managed code.
- Breakpoints Window
- Displays a list of all breakpoints and tracepoints set in the code. Double-click on a breakpoint in the window to position the cursor on the line for which it has been added.
- Break on Data Change
- Works with COBOL watchpoints. When the value of a data item on which a watchpoint has been set changes, the debugger breaks the execution of the program and highlights the line after the data change. The IDE opens the
COBOL Watchpoints window and highlights the data item that was changed in it. Works for native code only.
- COBOL Source Information
- COBOL Source Information (CSI) provides a quick and easy way of providing you with information about your program when you are working on it. You enter a query in
the CSI query control and CSI returns the results of the query in the
Micro Focus Code Analysis window.
- COBOL Watchpoint-Setting
-
Note: COBOL watchpoints are supported in native COBOL only.
To add a watchpoint from the editor, right-click a data item and select
Add COBOL Watchpoint. Alternatively, you can add watchpoints from the
Watchpoints (Native COBOL) window. To disable or remove the watchpoints, choose
Debug > COBOL Watchpoints > Disable/Delete All Watchpoints.
- DataTips and Pin To Source
- Provide information about the variables in the source code. To display the DataTip for a variable, you can hover it. This works only in break mode when the execution stops and with variables that are used at run time.
If you need to keep the DataTip for a variable open, right-click on the variable in the code and choose
Pin To Source.
- Debug Tooltip for Subscripted OCCURS Items
- Shows all items in an array or the value of an expression. To configure the tooltip style, select
Tools > Options > Text Editor > Micro Focus COBOL > Advanced and specify your preference for the
Debug tooltip style for OCCURS items setting. Use the following default key sequence to change the style of the tooltip in the editor - ALT+T, T.
- Debugging single COBOL files
- This only applies to native COBOL. The recommended way to work with
Visual COBOL is to include all source files in a project because this enables full support for the IDE editing, compiling and debugging features. There is limited support in the IDE for single files, such that are not part of a project and
Visual COBOL provides a path to create projects for these files in order to enable full editor, build and debug functionality. To create a project from a single file, right-click in the editor and click
Create COBOL Project.
You can debug single COBOL files in the IDE without a project as follows:
- Recompile the file if you have made any edits to it since you last compiled.
You need to do this because the IDE does not recompile the file when you start debugging. Recompiling ensures that the IDE will use your latest changes when you start debugging.
- Insert any breakpoints as necessary.
- Right-click the file in the editor, and click
Debug to start a debug session.
- Step through the code in the usual manner.
- When you have finished debugging, click
Debug > Stop debugging.
If you need to make changes to the code to fix problems, you must recompile before you start debugging again.
- Find All References
- In the editor, right-click a COBOL data item, a section or a paragraph name in the code and select
Find All References. A list of all places in the solution that contain the reference to the item is displayed in the
Find Symbol Results window. Double-clicking on an item in the list positions the cursor on the line of code that includes the element.
- Find Symbol Results Window
- To display the window, click
View > Find Results > Find Symbols Results. Displays the results of
Find All References command in the editor. Double-click an item in the list to position the cursor on the line that includes the referenced item.
- Go To Location Toolbar
- To display the toolbar choose
Tools > Customize > Toolbars and select
COBOL. The
Go To Location toolbar is indicated by
and enables you to locate the definition of a variable by typing the variable name or an expression in which it is used. Equivalent to pointing to the variable in the editor and pressing
F12. The toolbar keeps a history of your searches. To return to where you were in the code, click "Navigate Backwards",
.
- Just-In-Time Debugging
-
Enables just-in-time debugging for when an application causes an error. To enable Just-In-Time Debugging for native COBOL code, click
Tools > Options > Debugging > Just-In-Time Debugging. Check
Micro Focus Native Debugger. Works with native code only.
- Memory Window
- Allows you to see the contents of memory for a given address. This can be a pointer reference, the address of data-item or an integer value. To display the window, click
Debug > Windows > Memory > Memory
n. Works for native COBOL only.
- Program Breakpoints
-
Note: Program breakpoints are supported in native COBOL only, and are not supported with nested programs.
You can break into a program whenever it or one of its entry points is called.
- In the
Program Breakpoints (Native COBOL) window, click
New and type the name of the source file, without the extension. For multi-program source files, to set a break for a sub-program, use its program-id.
- To display the
Program Breakpoints (Native COBOL) window, click
.
- Quick Browse
- The Quick Browse dialog box (click
in the COBOL toolbar to open it), part of the COBOL Source Information (CSI) functionality, enables you to run CSI queries and returns the results of the queries in the Output window's COBOL Source Information tab.
- Remote Debugging
- You can debug a process running on a remote system if the machines are connected using TCP/IP. See
Remote Debugging.
- Ensure that the local and remote systems are networked using TCP/IP. To connect to the remote machine and debug a program, choose
Project >
projectProperties and go to the
Debug tab. Check
Enable remote machine and fill in the name or the IP address of the remote machine and the TCP port number.
- Run To Cursor
- Right-click a line of code in the editor and select
Run To Cursor. This starts a debugging session and executes the code till the line on which you positioned the cursor.
- Start Debugging
- Choose
Debug > Start Debugging or, alternatively, press
F5 or
F11.
F5 starts debugging and runs the application until a breakpoint or an error occurs.
F11 starts debugging and breaks on the first statement that can be debugged.
- Stop Debugging
- Choose
Debug > Stop Debugging. You can also click
in the
Debug toolbar.
- Threads Window
- Shows all threads that are running in the process. To display the window, choose
Debug > Windows > Threads.
- Tracepoint-Setting
- Tracepoints are conditional breakpoints. When the debugger hits a tracepoint, it performs an action instead of or before stopping the execution. To set a tracepoint, click on the line of code where you need to set one and choose
Debug > Toggle Tracepoint or from the context menu choose
Breakpoint > Insert Tracepoint and specify the action to perform. Tracepoints are supported only when debugging managed code.
- Variable Windows
- Include windows, such as for example
Autos,
Locals,
Quick Watch,
Watch, for monitoring and editing values and expressions.
- Watch Window
- Enables you to watch the values of variables and expressions. To open the window, click
Debug > Windows > Watch > Watch
n while debugging. To change the format of displaying the values from decimal to hexadecimal, right-lick in the window, and click
Hexadecimal Display.
To change the format of display of the values on individual rows in the Watch window, click a row, press
F2, and type:
Variable,h or
Variable,x to always display the values in hexadecimal format;
Variable,d to always display the values of variables in decimal format, and of strings - as text.
- Watchpoints (Native COBOL) Window
- Enables you to add data items as watchpoints, and monitor their values in a decimal or hexadecimal display. To open the window, click
Debug > Windows > COBOL Watchpoints.