6 Environments

In this chapter we'll learn how to examine and use the environment, i. e., how to access the values of variables. In fact, we need to distinguish between different kinds of environments. First, there is the toplevel environment. This is the environment relative to which code was compiled (in the case of ozc, this normally is the Base Environment defined in ``The Oz Base Environment''). The procedure NewName is one example, the module String is another. Then there exist environments for each procedure (and accordingly, for each frame of a thread's stack). For one there is a procedure's global environment, which contains variables referenced within the procedure, but defined outside it (i. e., global to the procedure); for the purpose of debugging, we consider this to not contain all toplevel variables since they are always visible. Finally, there come the procedure's local variables, which include its formal parameters.

6.1 Inspecting the Environment

Environment inspection is easy with Ozcar. In fact, it is done automatically for you. Whenever you select a stack frame, the variables visible at the program point corresponding to this frame are displayed in the Environment Views. You can further examine the values using the Inspector by clicking on them.

6.2 Using Values

Ozcar allows you to access the value you have last clicked to inspect it. It can be requested by the expression

{Ozcar.object lastClickedValue($)}

6.3 Compiling against the Environment

There are situations where you want to operate on the values found in the local or global environment, for example, to convert a data structure, or to bind a logic variable which causes your program to hang. In these cases, you can use the Query dialog, opened by selecting the Query ... entry in the Stack menu.

Evaluating Expressions

Using the Query dialog, you can evaluate arbitrary Oz expressions in the environment of the selected stack frame. Just enter the expression to evaluate on the Query line and press the Eval button to make the result appear on the Result line. Picture 6.1 shows an example.


Picture 6.1: Evaluating Arbitrary Expressions


Executing Statements

Besides evaluating expressions, the Query dialog allows to execute statements using the Exec button. The result of executing a statement will always be unit. Picture 6.2 shows an example scenario: An unbound variable, G2, is bound to the value 7. (Note that the Environment Views are only updated when the stack frame is selected again.)


Picture 6.2: Executing Statements


Compilation Environment

The exact environment used for compiling the code in the Query line is the currently active toplevel environment of the OPI (or the full default OPI environment when running standalone). Over this the selected frame's global environment is adjoined, and again the local environment is adjoined. Since the exact toplevel environment relative to which the code currently being debugged has been compiled is not available, this may be an incorrect approximation. Note also that the environment is constructed using the frame selected at the time the Eval or Exec button is pressed, not when the Query dialog is opened.

Multiple Queries

You can have as many Query dialogs as you like. This makes it possible to evaluate multiple pieces of code more than once without retyping them.


Benjamin Lorenz and Leif Kornstaedt
Version 1.4.0 (20080702)