このデバッグ セッションでは、Open PL/I でコンパイルされたプログラムのデバッグ時に CodeWatch のコマンドおよび機能を使用する方法を示します。セッションの後に、サンプル PL/I プログラムのソース リストを示してあります。このプログラムのソース ファイルは CodeWatch インストール メディアにも収録されています。
サンプル プログラム primes.pl1 は、特定の範囲内の素数の数を計算するプログラムですが、適切に機能しないことがあります。プログラムのどこかに、実際よりも多くの値が出力される原因となるバグがあります。次の出力について調べます。
*** Sieve of Eratosthenes *** Input maximum prime boundary: 10 Number of primes found was 6 1 2 3 5 7 11
このプログラムは、デバッガーに必要な情報を生成する -deb オプションとリスティング ファイルを生成する -l オプションを使用してコンパイルした後、Ipild を使用してリンクされています。次に例を示します。
mfpli primes.pl1 -deb -l ldpli primes.o -o primes
このサンプル セッションにおいて、行頭文字が付いた項目はコメント (セッションの一部ではない部分) です。システム プロンプトは $ です。ユーザーが指定するテキストは bold typewriter フォントで示してあります。明確にするために、コマンドの省略形は、前に完全な形式でスペルアウトしたコマンドに対してのみ使用しています。
$ cwcmd primes ****************************************************************************** * CodeWatch, 08.00 * * ---------------- * * Copyright 2009 Micro Focus * ****************************************************************************** Initial evaluation environment is PRIMES:(inactive)
CodeWatch> FIND main 3: primes: procedure options (main); CodeWatch> FIND main 109: /* main procedure */
CodeWatch> PRINT 20 109 /* main procedure */ 110 111 declare n fixed binary(31); 112 113 put skip; 114 put list (' *** Sieve of Eratosthenes ***'); 115 put skip (2); 116 117 call read_input(n); 118 119 do while (n > 1); 120 call sift(n); 121 call read_input(n); 122 end; 123 124 end; 125 BOTTOM
CodeWatch> BREAK 119
CodeWatch> CONTINUE *** Sieve of Eratosthenes *** Input maximum prime boundary: 10 Break at PRIMES\119
CodeWatch> P 119: do while (n > 1); CodeWatch> EVALUATE n N = 10 {fixed binary (31)}
CodeWatch> TYPE n N fixed binary (31) automatic
CodeWatch> DSTEP [P] CodeWatch> STEP Step at PRIMES\120 120: call sift(n);
CodeWatch> S IN Step at PRIMES.SIFT\%ENTRY 77: sift: procedure (n);
CodeWatch> ARGUMENTS N = 10 {fixed binary (31)}
CodeWatch> STACK /ALL Stack contains 7 frame(s). Current execution point is PRIMES.SIFT\%ENTRY 7: Owner is "PRIMES.SIFT" In [ primes.exe ] Called from PRIMES\121 6: Owner is "PRIMES" In [ primes.exe ] Called from _lpi_main+0x71 (non-debug) 5: Owner is "_lpi_main" In [ primes.exe ] Called from _tmainCRTStartup+0x10f (non-debug) 4: Owner is "_tmainCRTStartup" In [ primes.exe ] Called from 0x750c339a 3: Owner is "0x750c339a" In [ C:\Windows\syswow64\kernel32.dll ] Called from 0x76f69ef2 2: Owner is "0x76f69ef2" In [ C:\Windows\syswow64\ntdll.dll ] Called from 0x76f69ec5 1: Owner is "0x76f69ec5"
CodeWatch> POINT 98 98: do while (k < n); CodeWatch> P 5 98: do while (k < n); 99: /* cancel all multiples */ 100: flags(k) = FALSE; 101: k = k + this_prime; 102: end;
CodeWatch> B 100 CodeWatch> C Break at PRIMES.SIFT\100
CodeWatch> TRACE STATEMENT CodeWatch> C **** PRIMES.SIFT\101 **** PRIMES.SIFT\102 **** PRIMES.SIFT\98 Break at PRIMES.SIFT\100 CodeWatch> C **** PRIMES.SIFT\101 **** PRIMES.SIFT\102 **** PRIMES.SIFT\98 Break at PRIMES.SIFT\100
CodeWatch> MACRO fig=[FIND /IGNORE] CodeWatch> fig PRINT_OUT 105: call print_out(primes,count); /* should be count - 1 */
CodeWatch> NBREAK CodeWatch> B 105 CodeWatch> NTRACE S CodeWatch> C Break at PRIMES.SIFT\105
CodeWatch> E count COUNT = 6 {fixed binary (31)}
CodeWatch> B sift\%ENTRY CodeWatch> RELOAD Command line : "primes" Reloading..ok Initial evaluation environment is PRIMES:(inactive) CodeWatch> C *** Sieve of Eratosthenes *** Input maximum prime boundary: 10 Break at PRIMES\119 CodeWatch> C Break at PRIMES.SIFT\%ENTRY
CodeWatch> S Step at PRIMES.SIFT\85 85: do I = 1 to n; CodeWatch> P 15 85: do I = 1 to n; 86: flags(I) = TRUE; 87: end; 88: 89: count = 1; 90: primes(1) = 1; 91: 92: do I = 1 to n; 93: if flags(I) = TRUE then do; 94: this_prime = I + 1; 95: count = count + 1; 96: primes(count) = this_prime; 97: k = I + this_prime; 98: do while (k < n); 99: /* cancel all multiples */
CodeWatch> B 95 /IF {count > 4} /ELSE [E count] CodeWatch> C COUNT = 1 {fixed binary (31)} COUNT = 2 {fixed binary (31)} COUNT = 3 {fixed binary (31)} COUNT = 4 {fixed binary (31)} Break at PRIMES.SIFT\95 Break at PRIMES.SIFT\105
CodeWatch> NB CodeWatch> P Break at PRIMES.SIFT\105 105: call print_out(primes,count); /* should be count - 1 */
CodeWatch> E count COUNT 6 {fixed binary (31)} CodeWatch> LET count=count-1 CodeWatch> C Number of primes found was (prime itself) 5 1 2 3 5 7 Input maximum prime boundary: 10 Break at PRIMES\119
CodeWatch> RE Command line : "primes" Reloading..ok Initial evaluation environment is PRIMES:(inactive) CodeWatch> NBREAK /ALL
CodeWatch> B 105 /SILENT [LET count=count-1;C] CodeWatch> C *** Sieve of Eratosthenes *** Input maximum prime boundary: 10 Number of primes found was (prime itself) 5 1 2 3 5 7 Input maximum prime boundary: 100 Number of primes found was 26 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Input maximum prime boundary: 0 Program exited with status 0 Reloading..ok Initial evaluation environment is PRIMES:(inactive)
call print_out(primes,count);
上記を次のように変更します。
call print_out(primes,count-1);
これで、プログラムが正しく動作するようになります。デバッガー セッションを終了します。
CodeWatch> QUIT CodeWatch Quit...Bye!