★ APPLICATIONS ★ PROGRAMMATION ★ TRACEBACK ★ |
Traceback (The Amstrad User) | Applications Programmation |
An alternative to the TRON command and arguably more useful if the 464 traceback routine from Tony Jordan. Suppose you have just written a Basic program and you are now ready to try it out. You type RUN and hit the enter key. For a while the program rims normally then suddenly It crashes with an error message. You discover it has stopped In the middle of a sub-routine which should not yet have been reached. How on earth did the program enter that sub-routine? You could, of course, turn on trace with TRON at the 'Ready' prompt and rerun the program, but this is usually a slow and frustrating method of debugging. There is now a better solution with the Trace-back routine. OPERATION Traceback provides a post-mortem summary of what a program was doing before it crashed. It does this by (mainly) analysing Basic's run time stack. The stack is used: amongst other things, for keeping track of program flow during use of (he following control structures:
When a control structure is Invoked, usually causing a jump to a subroutine, details are pushed onto the run time stack; subsequent termination of the control structure; (eg. executing a Return) causes these details to be unstacked. Traceback uses the stacked details to determine the line number of the statement which was executing when the control structure was invoked. There are three main possibilities:
"Interrupted" and the line number to which control will-be passed when the interrupt sub-routine returns. It; Is unable to describe the type of interruption (i.e. the type of control structure) as this information is not stacked. As a bonus, Traceback also identifies where Basic's READ/RESTORE data pointer is pointing. If Traceback displayed "40 Data byte "n" this would indicate the pointer was positioned in the nth position of line 40. For example:
The data items following the indicated byte would have been retrieved by a subsequent READ statement. As an example consider this trivial program: 10 REM TEST PROGRAM |
Keybd | Gosub | (latest stacked item) |
60 | Gosub | |
30 | For | |
20 | For | (earliest stacked item) |
*No more* |
This display shows:
WARNINGS
Traceback is a program development tool and as such should be a permanent part of a Basic program until it is debugged. This is because tape operations such as LOAD and MERGE destroy the run-time stack; if a program crashes and you then try to load and run Traceback you will always get a "Stack Empty" message. As written. Traceback is only suitable for use with the CPC464. For other CPCs it may be necessary to change the values of d.%. p.% and b.%. I do not know what these changes should be and if anyone does, please write in. Note: The command in line 50010 is DI (disable interrupt).
XREF OF TRACEBACK
48 References to 12 Symbols using 28 out of 600 nodes.
|
|