S-Lang Run-Time Library Reference: Version 1.4.0: Debugging Functions

Next Previous Contents

## 17. Debugging Functions

## 17.1 _clear_error

Synopsis

  Clear an error condition

Usage

  `_clear_error ()`

Description

  This function may be used in error-blocks to clear the error that triggered execution of the error block. Execution resumes following the statement, in the scope of the error-block, that triggered the error.

Example

  Consider the following wrapper around the `putenv` function:

  > `

  >         define try_putenv (name, value)
  >         {
  >            variable status;
  >            ERROR_BLOCK
  >             {
  >               _clear_error ();
  >               status = -1;
  >             }
  >            status = 0;
  >            putenv (sprintf ("%s=%s", name, value);
  >            return status;
  >         }

  > `

  If `putenv` fails, it generates an error condition, which the `try_putenv` function catches and clears. Thus `try_putenv` is a function that returns `-1` upon failure and `0` upon success.
See Also

  `_trace_function, _slangtrace, _traceback`

## 17.2 _debug_info

Synopsis

  Configure debugging information

Usage

  `Integer_Type _debug_info`

Description

  The `_debug_info` variable controls whether or not extra code should be generated for additional debugging and traceback information. Currently, if `_debug_info` is zero, no extra code will be generated; otherwise extra code will be inserted into the compiled bytecode for additional debugging data.

  The value of this variable is is local to each compilation unit and setting its value in one unit has no effect upon its value in other units.

Example

  > `

  >         _debug_info = 1;   % Enable debugging information

  > `

Notes

  Setting this variable to a non-zero value may slow down the interpreter somewhat.

See Also

  `_traceback, _slangtrace`

## 17.3 _slangtrace

Synopsis

  Turn function tracing on or off.

Usage

  `Integer_Type _slangtrace`

Description

  The `_slangtrace` variable is a debugging aid that when set to a non-zero value enables tracing when function declared by `_trace_function` is entered. If the value is greater than zero, both intrinsic and user defined functions will get traced. However, if set to a value less than zero, intrinsic functions will not get traced.

See Also

  `_trace_function, _traceback, _print_stack`

## 17.4 _trace_function

Synopsis

  Set the function to trace

Usage

  `_trace_function (String_Type f)`

Description

  `_trace_function` declares that the S-lang function with name `f` is to be traced when it is called. Calling `_trace_function` does not in itself turn tracing on. Tracing is turned on only when the variable `_slangtrace` is non-zero.

See Also

  `_slangtrace, _traceback`

## 17.5 _traceback

Synopsis

  Generate a traceback upon error

Usage

  `Integer_Type _traceback`

Description

  `_traceback` is an intrinsic integer variable whose value controls whether or not a traceback of the call stack is to be generated upon error. If `_traceback` is greater than zero, a full traceback will be generated, which includes the values of local variables. If the value is less than zero, a traceback will be generated without local variable information, and if `_traceback` is zero the traceback will not be generated.

  Local variables are represented in the form `$n` where `n` is an integer numbered from zero. More explicitly, `$0` represents the first local variable, `$1` represents the second, and so on. Please note that function parameters are local variables and that the first parameter corresponds to `$0`.

See Also

  `_slangtrace, error`

Next Previous Contents