Chapter 14. Debugging programs using Debug Tool 359
The correct output is shown in Figure 14-15. Notice the lack of 0s, and the 1 in the upper
left-hand corner.
Figure 14-15 Debug Tool - PLI - Correct program output
14.2.2 Debugging a PL/I application using a full-screen interface
The knight program used as our example determines a knight’s tour (the moves a knight
makes) as it lands on each square once and only once when it starts in the upper left-hand
corner of the board. This program intentionally contains some errors for our example. In this
section we demonstrate how to use Debug Tool to find those errors.
For your convenience, the source for the program is as shown in Example 14-3. As listed
here, there are two bugs in the code. We will use Debug Tool to identify them. Take a moment
to read through the program comments to familiarize yourself with the structure and function
of this program.
Example 14-3 The knight program
*PROCESS STMT SOURCE LANGLVL(SAA2);
knight: proc options(main);
/************************************************************/
/* this program determines a knight's tour starting from */
/* a square in the corner of the board. */
/**************************************************************/
/* the size of the board is established here. */
/**************************************************************/
dcl size fixed bin(31) value(8);
/**************************************************************/
/* rowjump and coljump define the numbers of rows and */
/* columns respectively in each of the 8 possible moves */
/* that a knight can make. */
/* thus rowjump(1) and coljump(1) represent the move */
/* from "a" to "b" in the following diagram */
/* - - - - - */
/* |a| | | | | */
/* - - - - - */
/* | | | | | | */
360 Supporting On Demand Business Applications with the IBM Problem Determination Tools
/* - - - - - */
/* | |b| | | | */
/* - - - - - */
/**************************************************************/
dcl rowjump(8) fixed bin(15)
static init(-2,-1,+2,-1,+1,+1,+2,-2);
dcl coljump(8) fixed bin(15)
static init(+1,+2,-1,-2,+2,-2,-1,-1);
/**************************************************************/
/* the land array holds for each square the number of the */
/* move when the knight landed on that square. */
/**************************************************************/
dcl land(size,size) pic'ZZZ9';
/**************************************************************/
/* the rank array holds a ranking for each square to which */
/* the knight could move - this includes squares in the */
/* two imaginary rows and columns that surround the board. */
/* the knight will move to the square with the lowest */
/* positive rank. */
/* the rank of all squares off the board is zero, and */
/* consequently the knight will never move off the board. */
/* the rank of all other squares is equal to the number */
/* of moves possible from that square. thus, initially */
/* the rank of the four corner squares is 2. */
/**************************************************************/
dcl rank(-1:2+size,-1:2+size) fixed bin(7);
/**************************************************************/
/* the following variables are used for temporary purposes. */
/**************************************************************/
dcl (minrank,minmove) fixed bin(15);
dcl testrank fixed bin(15);
dcl (m,r,c,k) fixed bin(15);
/**************************************************************/
/* note that rankings are kept for two rows or columns */
/* beyond the real edges of the board. */
/* initialize all those rankings */
/* the rank of a square to which the knight should not move */
/* will be zero. hence the initial rank of all the squares */
/* off the board is zero. */
/**************************************************************/
call initialize_Rankings;
/**************************************************************/
/* initialize all those moves to zero. */
/**************************************************************/
land = 0;
/**************************************************************/
/* make the first move in the tour */
/**************************************************************/
m = 1;
r = 1; c = 1;
land(r,c) = m;
/**************************************************************/
/* determine the moves in the tour */
/**************************************************************/
do while ( m < size*size ) until ( minrank = 0 );

Get Supporting On Demand Business Applications with the IBM Problem Determination Tools (APA, DT, DT with Advanced Facilities, FA, File Export, FM, WS) now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.