Debug the 'Hello COBOL World' application

This tutorial uses the Hello COBOL World application which you created earlier to demonstrate how debugging works in Eclipse.

Modify your application

You are going to add some extra code to your application that will help demonstrate some of the debugging features:

  1. Open the helloworld.cbl program in the editor.
  2. Add the following code in the Working-Storage section:
    01 source-string pic x(10) value "AAbbAAbbCC".
  3. Add the following code in the Procedure Division section before the line for the COPY statement:
    inspect source-string replacing all 'A' by 'D'
    display source-string
    inspect source-string replacing characters by 'Q' 
            before initial 'C'
    display source-string
    

The source-string variable is a string that has an initial value of "AAbbAAbbCC". Some of the string characters are replaced during the execution of this program.

Create a debug configuration

  1. Select HelloCOBOLWorld in COBOL Explorer and from the main menu click Run > Debug Configurations.
  2. Double-click the COBOL Application tree item to create a new debug configuration.
  3. Specify HelloCOBOLWorld as the name of the configuration.

    This configuration uses HelloCOBOLWorld as the project to run and New_Configuration.bin/HelloCOBOLWorld.exe (Windows) or New_Configuration.bin/HelloCOBOLWorld (UNIX) as the main program to run.

  4. Click Debug.

    You get prompted to switch to the debug perspective. Click Yes to confirm. This starts the debugger and it stops on the first line in the PROCEDURE DIVISION.

    Some of the views of the Debug perspective you can see are:

    • Debug view - shows the currently active threads.
    • Editor - shows the helloworld.cbl program and the position of the debugger in the program.
    • Variables - shows the SOURCE-STRING variable and its initial value.
    • Outline - shows an outline of the structure of the program you're stepping through.
    • Breakpoints -

Step through the code

You can now step through the code and see how the value of the SOURCE-STRING changes:

  1. Press F5, Step Into, to start stepping the code.

    The first line in the program executes and the cursor moves to the next line in the code.

  2. Check the Variables view to see that the value of SOURCE-STRING has changed as instructed by the first line of code.
  3. Press F5 again.

    This executes the DISPLAY statement. Check the Windows Task bar for the application's console window which now also displays the value of SOURCE-STRING.

  4. Step through the next two lines in the same way and see how the value of the SOURCE-STRING variable changes.

    The cursor moves to the line that has the COPY statement and the debugger opens the HELLO.cpy copybook.

  5. Press F5 to return to the COBOL program and press it one more time to exit the program.

    Debugging stops and if you want to see the project, click the COBOL button in the right upper corner of Eclipse to change the perspective to the COBOL one.

You can save the project for future reference.

What Next?

Complete this Introduction with the following chapter on how to extend Eclipse with additional plug-ins.