NetRexx Overview, version 2.05 Copyright (c) IBM Corporation, 2005. All rights reserved. © | 14 Jan 2005
[previous | contents | next]

## Tracing

NetRexx tracing is defined as part of the language. The flow of execution of programs may be traced, and this trace can be viewed as it occurs (or captured in a file). The trace can show each clause as it is executed, and optionally show the results of expressions, etc. For example, the trace results in the program ‘`trace1.nrx`’:

      trace results
      number=1/7
      parse number before ’.’ after
      say after’.’before

would result in:

         --- trace1.nrx
       2 *=* number=1/7
         >v> number "0.142857143"
       3 *=* parse number before ’.’ after
         >v> before "0"
         >v> after "142857143"
       4 *=* say after’.’before
         >>> "142857143.0"
      142857143.0

where the line marked with ‘`---`’ indicates the context of the trace, lines marked with ‘`*=*`’ are the instructions in the program, lines with ‘`>v>`’ show results assigned to local variables, and lines with ‘`>>>`’ show results of un-named expressions.

Further, trace methods lets you trace the use of all methods in a class, along with the values of the arguments passed to each method. Here’s the result of adding `trace methods` to the Oblong class shown earlier and then running `tryOblong`:

          --- Oblong.nrx
        8 *=*     method Oblong(newwidth, newheight)
          >a> newwidth "5"
          >a> newheight "3"
       26 *=*     method print
      Oblong 5 x 3
       20 *=*     method relsize(relwidth, relheight)-
       21 *-*                   returns Oblong
          >a> relwidth "1"
          >a> relheight "1"
       26 *=*     method print
      Oblong 6 x 4
       10 *=*     method Oblong(newwidth, newheight)
          >a> newwidth "1"
          >a> newheight "2"
       26 *=*     method print
      Oblong 1 x 2

where lines with ‘`>a>`’ show the names and values of the arguments.

It’s often useful to be able to find out when (and where) a variable’s value is changed. The trace var instruction does just that; it adds names to or removes names from a list of monitored variables. If the name of a variable in the current class or method is in the list, then trace results is turned on for any assignment, loop, or parse instruction that assigns a new value to the named variable.

Variable names to be added to the list are specified by listing them after the var keyword. Any name may be optionally prefixed by a `-` sign., which indicates that the variable is to be removed from the list.

For example, the program ‘`trace2.nrx`’:

      trace var a b
      -- now variables a and b will be traced
      a=3
      b=4
      c=5
      trace var -b c
      -- now variables a and c will be traced
      a=a+1
      b=b+1
      c=c+1
      say a b c

would result in:

          --- trace2.nrx
        3 *=* a=3
          >v> a "3"
        4 *=* b=4
          >v> b "4"
        8 *=* a=a+1
          >v> a "4"
       10 *=* c=c+1
          >v> c "6"
      4 5 6

[previous | contents | next]

From The NetRexx Language by Mike Cowlishaw, mfc@uk.ibm.com (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).