ksh Expressions

There are two types of expressions in dbx, ksh expressions and language expressions. The first type supports only 32-bit integer values and the following operators (as in C):

|| && | & ^ == != > < >= <= >> << + - * / % ! ~ ()
= += -= *= /= %= &= |= ^= <<= >>=

To evaluate a ksh expression, merely wrap it in (()). The $ is permitted but not required for a reference to a ksh variable. It must not be used on the left side of an assignment.

The second type supports all the data types of the target language and most of its operators (except the assignment operators). To evaluate a language expression, wrap it in $[]. $[] can appear inside (()), but not vice versa. An expression in $[] is evaluated in the current language (see language Command). The print flags are recognized; see print Command.

For example:

(dbx) typeset -i x      # x is stored internally as an integer  
(dbx) z=3 x=5           # z is (by default) a string; (()) not required 
(dbx)                   # for simple integer assignment
(dbx) ((ww = z << x))   # (()) required here, spaces are permitted
(dbx) echo $ww
96
(dbx) z=$[p->x[3]]      # z is assigned the (string) result; p is
(dbx)                   # a pointer in the target process
(dbx) ((s = z/$[sizeof double])) # $[] embedded in (())

dbx will print L LL and U as suffixes for variable values when it knows the type of the variable (long, long long, and unsigned respectively). Here is an example of two ways to assign a program variable into a ksh variable by removing this suffix.

(dbx) whatis i
long long i;
(dbx) print i
i = 8LL
(dbx) z=$[-flld i] 
(dbx) echo $z
8
(dbx) z=$[(int) i]
(dbx) echo $z
8
(dbx)