Attach to Process

You can debug a running application in one of the following ways:

Attach to a running process

You can attach to and debug applications as running processes:

  1. Ensure the application sources are stored on your local machine. Open the folder that contains the source files in Visual Studio Code.
  2. Click Run > Start Debugging.

    Select the configuration you want to use, if prompted. This creates a launch.json inside a .vscode subfolder in the folder that contains your sources. The launch.json includes two default configurations - one for launching an application, and the other one for attaching to a process. For example:

            {
                "type": "cobol",
                "request": "attach",
                "name": "COBOL: Attach to process",
                "processId": "${command:pickProcess}"
            },
  3. In the Activity bar, click to open the Run panel.
  4. Select the attach configuration, COBOL: Attach to process, from the configuration launcher, and click (Start Debugging).

    This opens the Attach to process widget.

  5. Start typing the name of the executable you want to debug, and then select it.

Wait for a debuggable attachment

  1. Ensure the application sources are stored on your local machine. Open the folder that contains the source files in Visual Studio Code.
  2. Click Debug > Start Debugging.

    This creates a launch.json inside a .vscode subfolder in the folder that contains your sources, and opens the file in the editor.

  3. Click Add Configuration in the bottom right corner.

    This opens a pop-up with the available configurations.

  4. Use the arrow keys to select the COBOL: Wait for attachment configuration and add it to the launch.json file:
            {
                "type": "COBOL",
                "request": "launch",
                "name": "COBOL: Wait for attachment",
                "waitForAttachment": {options}
    
            }

    Where the supported options are:

    • any - Waits for and then attaches to the next COBOL program that calls CBL_DEBUGBREAK, or is launched with the COBSW environment variable set to +A.
    • directory - Waits for and then attaches to the next COBOL program that is launched with its working directory set to either the folder specified, or a subfolder of it.
    • id - Waits for and then attaches to the next COBOL program which calls CBL_DEBUG_START with the identifier you specify in the ID field as an argument. When using the id option the debugger always returns to the waiting state when the program being debugged exits.
    • returnToWait - Only supported with the any and directory options. Optional. Returns the debugger to a waiting state when the program being debugged exits.
  5. Select COBOL: Wait for attachment from the configuration launcher, and click (Start Debugging).
  6. Visual Studio Code starts the debugger and displays a message Waiting for debug connection.