Debugging Windows Services

Restriction: This topic applies to native COBOL only.

To debug a Windows service you must be logged on to the console of the computer running the service.

You can debug the service either using library routines or using JIT debugging.

Using library routines

If you are using a Visual Studio project to build the Windows service:

  1. Start Visual Studio as an administrator.
  2. Add a call to CBL_DEBUGBREAK or CBL_DEBUG_START in the application.
  3. Configure your project properties to launch using Wait for application attachment.
  4. Start debugging.
  5. When CBL_DEBUGBREAK or CBL_DEBUG_START is executed, Visual Studio starts debugging the service.

    If you use CBL_DEBUG_START you can then use CBL_DEBUG_STOP to detach the debugger from the application, which resumes running without the debugging features.

If the Windows Service is not built in a project, you need to specify the path to the Service's .idy files, and the Service must include calls to CBL_DEBUGBREAK or CBL_DEBUG_START:

  1. Start Visual Studio as an administrator.
  2. Open the main COBOL program file for your service.
  3. Using the banner at the top of the editor, browse for program symbols files (.idy files) and add them to the program properties.
  4. Add a call to CBL_DEBUGBREAK or CBL_DEBUG_START in your Windows service code.
  5. Run your Windows Service.
  6. The debugger starts automatically when CBL_DEBUGBREAK or CBL_DEBUG_START is executed.

    If you use CBL_DEBUG_START, you can then use CBL_DEBUG_STOP to detach the debugger from the application, which resumes running without the debugging features.

Using JIT debugging

  1. Enable just-in-time debugging.
  2. Add a call to CBL_DEBUGBREAK or CBL_DEBUG_START in your Windows service code.
  3. Run your Windows Service.
  4. The debugger starts automatically when CBL_DEBUGBREAK or CBL_DEBUG_START is executed.