User Guide
Chapters
Table of Contents
Format Specification
QTAwk Invocation

Trace Statements



Trace Statements

QTAwk has added a facility for debugging utilities. This facility is activated through the built-in variable TRACE. QTAwk can trace the loop control statements:

  1. if
  2. while
  3. do/while
  4. for (both forms)
  5. switch

In addition, built-in functions and user-defined functions are traced.

By default, TRACE is set to FALSE and no tracing is done. The variable may be set to any value, numeric, string or regular expression and the value will determine the statements traced. If TRACE has a nonzero numeric value then QTAwk will trace all statements of the type listed.

Selective Statement Tracing

If TRACE has a string value, then the string is compared against the keywords:

  1. if
  2. while
  3. do
  4. for
  5. switch
  6. function_b (built-in functions)
  7. function_u (user-defined functions)

If an exact match (case is important) is found, then the statement is traced. If TRACE is set to a regular expression, then the keywords are matched against the regular expression. If a match is found, then the statement is traced.

Trace Output

In tracing a statement, QTAwk issues a message to the standard output file. The message issued will have the form:

Stmt Trace:  stmt_str value_str
Action File line: xxxx
Scanning File: FILENAME
Line: xxxxx
Record: xxxxxx

where stmt_str is the appropriate keyword listed above for the statement traced and value_str is a value dependent upon the statement traced as listed below:
keyword

value string
if ==> 0/1 conditional expression TRUE/FALSE
while ==> 0/1 conditional expression TRUE/FALSE
do ==> 0/1 conditional expression TRUE/FALSE
for ==> 0/1 conditional expression TRUE/FALSE
for ==> subscript value
switch ==> switch expression value
function_b ==> function name
function_u ==> function name

When a statement that can be traced is encountered, the value of the statement is determined, e.g., for an if statement, the value of the conditional is evaluated before issuing the trace statement.

The following TRACE values will trace the statements indicated:

TRACE = "if";
This value will trace all 'if' statements, indicating the TRUE/FALSE value of the conditional.
TRACE = /^[iwd]/;
This value will trace all 'if', 'while' and 'do' statements, indicating the TRUE/FALSE value of the conditional.
TRACE = /_u$/;
This value will trace all user-defined functions, indicating the function name in the trace message.

TOP
User Guide
Chapters
Table of Contents
Format Specification
QTAwk Invocation