THE COBOL DEBUGGER

 

We will be using the lab1 program to learn how to run the debugger.

 

Press the top right corner button, the one that looks like a box (not the dot) to maximize your terminal window. You can toggle this button to enlarge and reduce your terminal window. You MUST maximize your terminal window to run the debugger (actually, you only need to maximize the terminal window before the runcbl command). Once you have maximized your terminal window, type the following commands to first compile the lab with debugging information and then to run the lab using the debugger (fyi: the –zd and the –d are unix command switches):  

 

ccbl  -zd  prelab.cob 

runcbl  –prelab

 

You will see a menu at the top of the window (press F10 to activate the menu at the top of the screen, if necessary), then a source code area, and a command area, with a blinking command line prompt, at the bottom. A list of debugger commands can be accessed by typing help in the command area (use the up and down arrow keys to get around the help screen and press enter to exit the help screen). If you want to exit the debugger at any time, type q! on the command line. Notice that a black box exists to the left of the OPEN statement in paragraph 100-MAIN-MODULE.  This is the cursor for the debugger. This cursor indicates i.e. is pointing to, the next statement to be executed.  That is, the statement the debugger cursor is “sitting on” has not yet been executed!

 

A few commands that you will use frequently are given below (do not try them yet!):

s à means to single step; when you press s and enter, the cursor in the source code area will move to the next executable statement in your program

d à means to display the memory contents of a variable; when you type in d employee-record and enter, the value contained in the memory location which employee-record refers to will be shown in the command area

b à is used to set a break point so that you can stop at a particular point in the program; however, a break point can only be set at the paragraph level (not the statement level); to use this command, you can type b 200-wage-routine and enter; this command is especially useful to check information when working inside a looping structure.

gp à execute to the end of the paragraph

g à execute until you reach a break point or the end of the program

 

OK – here we go… follow the directions and answer the questions…

1.      Single step 4 times (i.e. type s and press enter 4 times).  What command is the debugger cursor on (i.e. and about to execute, but hasn’t yet)?

2.      Display the input file record data (i.e. d employee-record and press enter).  What is in employee-record?

3.      Single step 1 time. What is in employee-record? (i.e. s enter, then d employee-record)

4.      Is the debugger case-sensitive (use the display command again to check)? 

5.      Single step 1 time.  What statement is the debugger cursor on?

6.      Single step 4 times.  What is in… hours-worked-in? hourly-rate-in? weekly-wages-out?

7.      Single step 1 time.  What is in… hours-worked-in? hourly-rate-in? weekly-wages-out?

8.      What is in print-rec?

9.      Single step 1 time.  What is in print-rec?

10.  What is in employee-record?

11.  Single step one time.  What statement are you on?  What is in employee-record?

12.  Set a breakpoint by typing in:  b 200-wage-routine.  Remember, breakpoints can only be set on paragraph names.  Notice the letter B that appears to the left of the 200-wage-routine paragraph name.

13.  Type g.  This executes the program either until a breakpoint or until the end of the program.  What statement are you on?

14.  What is in employee-record?

15.  Type gp.  What statement are you on?

16.  Type gp again.  What statement are you on?

17.  Type g.  What statement are you on?

18.  What is in employee-record?

19.  Type help to determine how to clear all breakpoints.

20.  What command would you use to clear all breakpoints? Use the up and down arrow keys to move through the list of debugger commands. Press the enter key to exit from help. 

Clear all breakpoints. Type g to finish executing the program. At any time, you can type q! to quit the debugger.

Let's review what you just did. The b command sets a breakpoint at the declaration of a paragraph. That is, when you run/execute your program, this command tells the program to stop execution before the given paragraph is executed. At this point, you can single step through the program (s command as many times as you like) or display information you might want to see (d command). Using the g command continues the execution of the program either until it encounters a breakpoint or the end of the program, whichever comes first. The gp command will execute the program until the current paragraph finishes executing, at which point it will stop and give you a chance to enter another command. Remember, each time you stop, you will start at that point (not at the beginning) to continue executing the program.