Adding Variables to the Debugger Visualizer

There are three ways to add a variable to the visualizer. Two of them work when the debugger has stopped at a breakpoint:

  1. With the mouse, from the hint the debugger shows when you hover over the variable.
  2. With the keyboard shortcut SHIFT+CTRL+F6, when the keyboard cursor is within the name of the variable. The variable is added only if it is recognized.

The third works also while the application is running, not only while stepping:

  1. Enter the name of the variable into the Variable edit box and press Enter:

The Variable edit box

A name entered directly is always added to the list of tracked variables, even when it is not recognized. Press Show the variables to show the list of tracked variables. A variable is added to the list even when it is not within the current scope of the debugger:

The list of tracked variables

In this example bVar was added: it shows the address 0, an unknown type and an undefined value. Variables can be added to this list also while the debugged application is running.

Debugger global variables

The list of tracked variables is visible from all visualizer windows. That is why these variables are called debugger global: they show the same content in all windows. Press Delete to remove a variable from the list. Double-click a variable to display its content in the grid or on the chart, whichever is active. Different visualizer windows can show the content of different variables. A variable in this list keeps one copy of its data for all visualizer windows, which reduces the memory used.

The Variable edit box accepts any expression the debugger recognizes, for example:

myForm1.MyComp.MyField[i].GetSymbol()

The expression is passed to the debugger with "Allow side effects" enabled. It helps to add a more complex expression to the debugger as a watch first: the debugger shows more detailed reasons when an expression cannot be evaluated. A complex expression cannot be used in a script. That is why the list of debugger global variables has a second column, Name in script: right-click the list, and its popup menu changes that name into something shorter to reference.

Because the debugger evaluates the expression with side effects enabled, more caution is needed to keep the debugger stable. The visualizer detects and avoids dangling pointers with special logic for the key types of the MtxVec library. That does not work for other types, which can occur in a more complex expression. Dangling or invalid non-zero pointers can crash the debugger session in general, with or without a visualizer.

Pinning variables

An expression cannot always be evaluated, because its variable can go out of scope. Pinning extends its reach: when a variable is pinned, the visualizer uses the last known address of the variable to obtain its current content. The popup menu of the list of debugger global variables has four commands for pinning:

The pinning commands of the popup menu

Re-pinning evaluates the expression again within the current scope of the debugger and obtains its new address. Pinning is also useful to track a variable into a subroutine, where its local name can be different.

Supported types

These object types are recognized by the visualizer:

TypePinnableDangling pointer protection
TVecYesYes
TMtxYesYes
TVecIntYesYes
TMtxIntYesYes
VectorYesYes
MatrixYesYes
VectorIntYesYes
MatrixIntYesYes
TOpenCLVectorYesYes
TOpenCLMatrixYesYes
clVectorYesYes
clMatrixYesYes
TStringsYesNo
TStringListYesNo
StringListYesNo
TSignalYesNo

TSignal is defined by DSP Master, in the SignalTools unit. StringList is a record defined by MtxVec, in the StringVar unit.

These records, scalars and dynamic arrays are recognized too, without dangling pointer protection:

TypePinnable
TCplx, TSCplxYes
ShortInt, SmallInt, Integer, Int64, Byte, Word, Cardinal, UInt64Yes
Single, DoubleYes
StringYes
array of T and TArray<T>, T one of Integer, Boolean, Cardinal, Word, Int64, UInt64, Byte, ShortInt, SmallInt, Double, SingleNo
TIntegerArray, TBooleanArray, TCardinalArray, TWordArray, TInt64Array, TUInt64Array, TByteArray, TShortIntArray, TSmallIntArray, TDoubleArray, TSingleArrayNo
array of array of T, T one of Integer, SmallInt, ShortInt, Byte, Double, SingleNo
T2DIntegerArray, T2DSmallIntArray, T2DShortIntArray, T2DByteArray, T2DDoubleArray, T2DSingleArrayNo

The array types are recognized by their name: a type of the same name declared in another unit is recognized as well, but if its layout is different, it crashes the visualizer and the debugger. Arrays are not pinnable yet.

Global variables

Global variables make a quick copy of the current content of a variable, to compare it with the stored copy later. They are available from all visualizer windows, and their content persists between debugger sessions; the content of debugger global variables and of local variables does not. The visualizer shows the global variables on a list of their own:

The list of global variables

The only way to add a variable to the list of global variables is the command Copy to global variable... of the popup menu of the list of debugger global variables. Delete removes a global variable, and the popup menu of the list has the commands Delete and Clear. Double-click the row of a global variable to inspect its content.

Local variables

Local variables are accessible only from the visualizer window that defines them. To share the result of a script between visualizer windows, assign the result of the expression or of the script to a global variable. The type of a global variable and of a debugger global variable cannot be changed once it is defined: on an attempt to change it, the scripting engine returns the error "The type is locked".

Local variables are defined with a single-line expression or with a script. All global variables are shown on the list of local variables too:

The list of local variables

In this example aVar is not on the list, but its script name xStep is; the same holds for a1 and a. Delete removes a local variable too. If the selection is also a global variable or a debugger global variable, that variable is deleted as well.

When a local variable is deleted or the list of local variables cleared, the expression or the script is evaluated again at once, which can add the deleted variable back to the list. Watch the time stamp of the expression or the script to notice the updates.

Clear of the popup menu of the local variables does not remove the global and the debugger global variables. The expression is evaluated again at once, adding back the local variables it defines, and the remaining global and debugger global variables are added back to the list.