English 中文(简体)
Rexx - Debugging
  • 时间:2024-12-22

Rexx - Debugging


Previous Page Next Page  

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 utipty 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.

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.

Let’s take a look at an example of the trace command.

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 0

From 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 pne number along with the statement executed is added to the trace output.

    Each pne 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

None

Return 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 number 

The first pne 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 pke 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 pne runs.

The general syntax is as follows −

Syntax

trace ?options 

Where, 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.

Let’s take a look at an example of implementing active tracing.

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 pne of code; then you need to press the Enter button to move onto the next pne of code.

  This is an incorrect number
       +++ "LINUX COMMAND /home/cg/root/5798511/main.rex"
     5 *-* n = 100.45 if datatype( n, wholenumber ) then 
+++ Interactive trace. "Trace Off" to end debug, ENTER to Continue. +++
     6 *-* signal msg 
    10 *-* msg :
    10 *-* say  This is an incorrect number 
Advertisements