Evaluating Variables and Expressions

This section discusses how to use dbx to evaluate variables and expressions.

Verifying Which Variable dbx Uses

If you are not sure which variable dbx is evaluating, use the which command to see the fully qualified name dbx is using.

To see other functions and files in which a variable name is defined, use the whereis command.

For information on the commands, see which Command and whereis Command.

Variables Outside the Scope of the Current Function

When you want to evaluate or monitor a variable outside the scope of the current function:

Printing the Value of a Variable, Expression, or Identifier

An expression should follow current language syntax, with the exception of the meta syntax that dbx introduces to deal with scope and arrays.

To evaluate a vari able or expression in native code, type:

print expression 

You can use the print command to evaluate an expression, local variable, or parameter in Java code.

For more information, see print Command.

dbx supports the C++ dynamic_cast and typeid operators. When evaluating expressions with these two operators, dbx makes calls to certain rtti functions made available by the compiler. If the source doesn’t explicitly use the operators, those functions might not have been generated by the compiler, and dbx fails to evaluate the expression.

Using Pretty-Printing

Pretty-printing lets your program provide its own rendition of an expression's value through a function call. If you specify the -p option to the print command, rprint command, display command, or watch command, dbx searches for a function of the form const chars *db_pretty_print(const T *, int flags, const char *fmt) and calls it, substituting the returned value for print or display.

The value passed in the flags argument of the function is bit-wise or one of the following:

Not currently implemented, always set

-f (if set, fmt is the format part)

The db_pretty_print() function can be either a static member function or a standalone function.

If the dbx environment variable output_pretty_print is set to on, -p is passed to the print command, rprint command, or display command as the default. Use +p to override this behavior.

Consider also the following: