Debug - step through

From J Wiki
Jump to navigation Jump to search


<=   =>

In an earlier section you added a debugging line to a verb definition that allowed you to see the results of intermediate steps when the verb was run. Sometimes you need more powerful tools than that.

In recent versions of J the debug utilities are included, but if they are not you can always load 'debug' to load the debug utilities.

Open your script file cf.ijs and run it.

Let's execute centigrade, but with a stop on each line so that you can take a look at exactly what is going on.

   dbss 'centigrade *:*'


The dbss (Set Stop) argument requests a stop before executing all, indicated by *:*, lines in centigrade.

   dbr 1


dbr with an argument of 1 requests that the system suspend execution when an error or stop occurs. When a verb is suspended it is halted in mid execution. You can examine definitions, change definitions, and you can resume execution of the suspended verb.

   centigrade 212
|stop
|       t1=.y-32
|centigrade[0]


The error report (bars at the left margin) indicates execution stopped on line 0 of centigrade and shows the sentence from that line.

The execution of centigrade is suspended and the indent of six spaces, rather than three, indicates the suspension. The variable y is the argument.

      y
212


The stop occurs before the line is executed, so t1 has not been defined and if you try to look at it you will get a value error.

Use dbrun to continue execution. It will run the current line, and because stops are set on all lines it will then stop on the next line.

      dbrun ''
|stop
|       t2=.t1*5
|centigrade[1]
      t1
180
      t1*5
900


centigrade is now stopped on line 1, and as you can see, you are able to check the value of local t1 that was defined in line 0. Step through the next lines and examine locals.

      dbrun ''
|stop
|       t3=.t2%9
|centigrade[2]
      t2
900
      t2%9
100
      dbrun ''
100



You are no longer suspended in centigrade and you are back to the normal indent of three spaces.

Turn off the request for debug suspensions and reset to have no stops.

   dbr 0
   dbss ''


<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106