[next] [previous] [contents]

  4.7 A Sample Debugging Session
  This section shows a sample debugging session using a BASIC
  program that contains a logic error.

  The following program compiles and links without diagnostic
  messages from either the compiler or the linker. However,
  after printing the headers, the program is caught in a loop
  printing the same figures indefinitely.
    1 10 !SAMPLE program for DEBUG illustration
    2 DECLARE INTEGER Number
    3 Print_headers:
    4 PRINT "NUMBER", "SQUARE", "SQUARE ROOT"
    5 PRINT
    6 Print_loop:
    7 FOR Number = 10 TO 1 STEP -1
    8 PRINT Number, Number^2, SQR(Number)
    9 Number = Number + 1
  10 NEXT Number
  11 PRINT
  12 END

  The following text shows the terminal dialogue for a de-
  bugging session which helps locate the error in the program
  SAMPLE. The callouts are keyed to explanatory notes that
  follow the dialogue.
  
EXAMPLE: Click to display example.

  The following explains the terminal dialogue in the above
  example:

    1 Compile SAMPLE.BAS with the /LIST and /DEBUG
        qualifiers. The listing file may be useful while you are in
        the debugging session.
    2
Link SAMPLE.BAS with the /DEBUG qualifier.
    3
The debugger identifies itself and displays the debugger
        prompt after you invoke the debugger with the RUN
        command.
    4
Step through 2 executable statements to the FOR state-
        ment.
    5
The headers print successfully and the program reaches
        the FOR statement.
    6
Step through one iteration of the loop.
    7
Request the contents of the variable Number .
    8
The debugger shows the contents of the loop index to be
        10.
    9
Step through another iteration of the loop.
    10
Examine the value of the loop index again.
    11
The debugger shows that the loop index is still 10. The
        loop index has not changed from its initial setting in the
        FOR statement.
    12
Deposit the correct value into Number .
    13
Step through another iteration of the loop.
    14
Examine the contents of Number again.
    15
Observe that the number has not been changed yet.
    16
Step through just one statement to discover what is inter-
        fering with the value of Number during execution of the
        loop.
    17
Observe that this statement does not affect the value of
        Number
.
    18
Step through another statement in the loop.
    19
Observe that this statement counteracts the change in the
        loop index.
    20
Exit from the debugger. You can now edit the program
        to delete line 9 and reprocess the program. Alternatively,
        you could use the EDIT command while in the debugger
        environment.

  This debugging session shows that the FOR...NEXT loop in-
  dex ( Number ) is not being changed correctly. An examination
  of the statements in the loop shows that the variable Number
  is being decreased by one during each execution of the FOR
  statement, but incremented by one with each execution of the
  loop statements. From this you can determine that the loop
  index will not change at all and the program will loop indef-
  initely. To correct the problem, you must delete the incorrect
  statement and recompile the source program.