Next Previous Contents

17. Debugging

The current implementation provides no support for an interactive debugger, although a future version will. Nevertheless, S-Lang has several features that aid the programmer in tracking down problems, including function call tracebacks and the tracing of function calls. However, the biggest debugging aid stems from the fact that the language is interpreted permitting one to easily add debugging statements to the code.

To enable debugging information, add the lines

    _debug_info = 1;
    _traceback = 1;
to the top of the source file of the code containing the bug and the reload the file. Setting the _debug_info variable to 1 causes line number information to be compiled into the functions when the file is loaded. The _traceback variable controls whether or not traceback information should be generated. If it is set to 1, the values of local variables will be dumped when the traceback is generated. Setting this variable to -1 will cause only function names to be reported in the traceback.

Here is an example of a traceback report:

    S-Lang Traceback: error
    S-Lang Traceback: verror
    S-Lang Traceback: (Error occurred on line 65)
    S-Lang Traceback: search_generic_search
      Local Variables:
        $0: Type: String_Type,  Value:  "Search forward:"
        $1: Type: Integer_Type, Value:  1
        $2: Type: Ref_Type,     Value:  _function_return_1
        $3: Type: String_Type,  Value:  "abcdefg"
        $4: Type: Integer_Type, Value:  1
    S-Lang Traceback: (Error occurred on line 72)
    S-Lang Traceback: search_forward
There are several ways to read this report; perhaps the simplest is to read it from the bottom. This report says that on line 72, the search_forward function called the search_generic_search function. On line 65 it called the verror function, which called error. The search_generic_search function contains 5 local variables and are represented symbolically as $0 through $4.


Next Previous Contents