Program debugging – Remote Processing CAMBASIC User Manual

Page 184

Advertising
background image

Program debugging - 1

PROGRAM DEBUGGING

CAM BASIC has several constructs which can be used to debug a program . This section will outline the methods and give
examples.

Using the STOP statement

When a STOP statement is e ncounter ed, progr am exe cution halts and th e line num ber con taining the stop statem ent is
displayed.

By inserting the STOP statement in different sections of the program, you can determ ine whether these sections are being
executed. F or example, you can test a conditional branch:

10 INPUT A
20 IF A=2 THEN 50 ELSE 80
30 '
40 '
50 B=23
55 STOP
60 '
70 B=25
75 STOP
80 '

I n th is e xa m p le , a li ne n um b e r f o ll ow e d by a r em a r k ( ' ) s ta t em e n t m e a ns th a t t hi s l in e w ou ld b e a p ar t of y ou r p ro g r am .

In the example above, ST OP statements are inserted at lines 55 and 75 to determine if the branch at line 20 is operating
correctly. When you input 2, the progr am should stop at line 55. Otherwise, it should always stop at line 75.

USING THE PRINT AND INPUT STATEMENTS

The exam ple above shows how the INPU T statement can b e inserted so that you can m anually change the value of X to test
this progr am fr agmen t.

The PRINT statement can also be used to print out the value of any variable or memory location after the program has
halted.

T R O N / T R O FF T R A C ES E X E CU T I O N P A T H S

TRO N turn s on the line num ber tr acing function . L ine numb ers ar e printed a s they are executed. No other inform ation is
printed. H owever, all PRINT statements execute proper ly. Because the line numbers are printed, execution is slowed.
T h e s lo w do w n i s l es s n o ti ce a bl e a t h ig h er b au d ra te s. T o tu r n t he tr a ce o ff , e xe c ut e T R O F F .

Use TROFF to turn off the trace function. These two statements are most useful when tracing portions, rather than entire
p r o gr a m s. B e lo w is a te s t p r o gr a m :

10 A$ = "Down"
20 TRON
30 FOR X = 0 TO 2
40 GOSUB 90

Advertising