Debugging is an important feature in any programming language. It
helps the developer to diagnose errors, find the root cause and then
resolve them accordingly. In Rexx, the trace utility is used for
debugging. The trace instruction can be implemented in 2 ways, one is
the batch mode and the other is the interactive mode. Let’s look at how
to implement both options.
The general syntax of the trace statement is shown as follows −
The general syntax is as follows −
Trace in Batch Mode
The trace command is used to give a detailed level of each Rexx command which is executed.The general syntax of the trace statement is shown as follows −
Syntax
trace [setting]Where the setting can be anyone of the following options −
- A − Traces all the commands.
- C − Only traces the host commands which are sent to the operating system.
- E − Only traces the host commands which are sent to the operating system which have resulted in an error.
- F − Only traces the host commands which are sent to the operating system which have resulted in a failure.
- I − This provides an intermediate level tracing of Rexx commands.
- L − This option is if you want to label the tracing as it happens.
- N − This is the default option in which no tracing happens.
Example
/* Main program */ trace A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say ' This is an incorrect number 'The output of the above program will be as follows −
5 *-* n = 100.45 if datatype( n, wholenumber ) then signal msg 7 *-* say 'This is a whole number This is a whole number 8 *-* return 0From the output, you can see that an additional trace was added to the output of the program. The following things can be noted about the output −
- The line number along with the statement executed is added to the trace output.
- Each line that gets executed is shown in the trace output.
Trace Function
Trace can also be enabled with the help of the trace function. The general syntax and example are shown below.Syntax
trace()The above function returns the current trace level.
Parameters
NoneReturn Value
The above function gives the current trace level.Example
/* Main program */ say trace() /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say 'This is an incorrect number 'The output of the above program will be as follows.
N This is an incorrect numberThe first line of N denotes that the trace is set to Normal.
Setting Trace Value
The trace level can be set with the trace function. The general syntax and example are shown below.Syntax
trace(travel_level)
Parameters
- trace_level − This is similar to the options available for setting the trace level.
Return Value
The above function gives the current trace level.Example
/* Main program */ say trace() current_trace = trace('A') say current_trace /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say ' This is an incorrect number 'The output of the above program will be as follows −
N 4 *-* say current_trace N 6 *-* n = 100.45 7 *-* if \ datatype( n, wholenumber ) then 8 *-* signal msg 12 *-* say 'This is an incorrect number' 'This is an incorrect number'
Interactive Tracing
Interactive tracing is wherein, tracing is carried out as the program runs. Just like in an IDE such as Visual Studio for .Net, in which you can add breakpoints and see how each statement executes, similarly here also you can see the program as each code line runs.The general syntax is as follows −
Syntax
trace ?optionsWhere, options are the same for the trace command as shown below.
- A − Traces all the commands
- C − Only traces the host commands which are sent to the operating system.
- E − Only traces the host commands which are sent to the operating system which have resulted in an error.
- F − Only traces the host commands which are sent to the operating system which have resulted in a failure.
- I − This provides an intermediate level tracing of Rexx commands.
- L − This option is if you want to label the tracing as it happens.
- N − This is the default option in which no tracing happens.
Example
/* Main program */ trace ?A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say 'This is an incorrect number'The output of the above program will be as shown in the following program. The trace will stop at each line of code; then you need to press the Enter button to move onto the next line of code.
4 *-* n=100.45 +++ Interactive trace. "Trace Off" to end debug. ENTER to continue. 5 *-* if \ datatype( n, wholenumber ) then 6 *-* signal msg 10 *-* say 'Incorrect number , should be a whole number' Incorrect number , should be a whole number
No comments:
Post a Comment