APPLICATIONSPROGRAMMATION ★ TRACEBACK ★

Traceback (The Amstrad User)Applications Programmation
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

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:

  • FOR/NEXT
  • WHILE/WEND
  • [ON] GOSUB/RETURN
  • AFTER GOSUB/RETURN
  • EVERY GOSUB/RETURN
  • ON SO GOSUB/RETURN
  • ON BREAK GOSUB/RETURN

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:

  1. The control structure was invoked in the normal course of program execution. Traceback displays the type of control structure and the line number of it's invocation.
  2. The control structure was invoked from the key board (eg. by typing GOSUB 2000 from the Ready prompt). Traceback displays the type of control structure together with the word "Keybd"
  3. The control structure was invoked abnormally as a result of an interrupt (eg. periodically as a result of an EVERY statement). Traceback displays the word .

"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:

  • '40 Data byte 0' would indicate 40 DATA up,down,left
  • '40 Data byte 8" would indicate 40 DATA up,down ,left
  • "0 Data byte 0' would indicate Data exhausted.

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
20 FOR i=1 TO 7
30 FOR j=1 TO 3
40 WHILE m=4
50 WEND
60 GOSUB 120
70 NEXT j
80 NEXT i
90 GOSUB 120
100 END
110 DATA 0,1,2
120 REM S/F
130 READ n:m=i/n
110 RETURN

when run, it aborts "Division by zero in 130"', Line 130 is seen to be within the .subroutine starling at line 120. This subroutine is railed from lines 60 and 90. Which of these calls resulted in the program aborting?

To find out. execute Traceback by typing GOSUB 50000. The program will display the following:

110 Data byte 2

KeybdGosub(latest stacked item)
60Gosub
30For
20For(earliest stacked item)
*No more*

This display shows:

  1. The next DATA item to be read is the "1" on line 110.
  2. A GOSUB was typed from the keyboard. In this case we simply ignore it as it happens to be the GOSUB 50000 used to run Traceback. This line could have been suppressed by using GOTO 50000 instead as GOTO information is not stacked.
  3. The current subroutine (starting at line 120) was called from line 60 (answering the question posed earlier) which is inside the FOR/NEXT loop starting at line 30. which in turn is inside a FOR/ NEXT loop starting at line 20.
  4. The fact that the WHILE/WEND loop is not mentioned indicates that it has been completed.

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.

50100 50060 50120 50240
50220 50180 50200
b.% 50040 50110 50240
C.% 50120 50140 50150 50160 50170 50230 50240
d.% 50020 50050 50070
L.! 50070 50080 50190 50200 50210
o.! 50050 50060 50070
o.% 50070 50090 50130 50150 50160 50170 50180 50190
p.% 50030 50100
s.% 50010 50110 50120 50150 50190 50230 50240
t.$ 50130 50140 50150 50160 50170 50220

★ PUBLISHER: THE AMSTRAD USER (AUSTRALIA)
★ YEARS: 1990 , 1987
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: TONY JORDAN
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» TraceBack    LISTINGDATE: 2013-08-02
DL: 202
TYPE: PDF
SiZE: 107Ko
NOTE: 1 page/PDFlib v1.6

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » CPC-Fehlerroutine (CPC Magazin)
» Applications » Comal-80 (CPC Amstrad International)
» Applications » Systeme Expert
» Applications » Rampak (The Amstrad User)
» Applications » Bankman nos seus Programas (Amstrad Magazine)
» Applications » Label-Basic (CPC Magazin)
Je participe au site:
» Pour ce titre nous ne disposons de fichier executable sur CPC (Dump, Saisie du listing) , alors si vous avez ça dans vos cartons ou vous désirez usé vos petit doigts boudinés sur votre clavier faites le nous savoir.
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop
Page créée en 195 millisecondes et consultée 1715 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.