int Expression(t_result *result,wchar_t *expression,uchar *data,ulong base,ulong size,ulong threadid,ulong a,ulong b,ulong mode);
Evaluates expression to numerical and/or text value in one step. In fact, this is a shortcut that calls first Cexpression() (expression parser) then Eexpression() (expression estimator). Does not support multi-expression strings. If value of expression must be calculated several times, split this call in two or consider use of Fastexpression().
Parameters:
result
(out) Structure of type t_result that receives results of the evaluation
expression
(in) Pointer to the expression, zero-terminated UNICODE string. The syntax of expressions is described here. Note that Expression() is unable to process multi-expression strings in form "<expression1>,<expression2>, ..."
data
(in) Pointer to the optional copy of memory contents. If data is NULL, flag EMOD_NOMEMORY is not set and expression includes contents of memory, Expression() reads memory of debugged process. If data is not NULL and expression accesses memory in the range [base..base+size-1], contents of memory is taken from the data. In all other cases attempt to access memory will result in the failure
base
(in) Base address of the supplied data block, ignored if data is NULL
size
(in) Size of the supplied data block, ignored if data is NULL
threadid
(in) Identifier of the thread containing CPU registers used in the evaluation of the expression. If expression specifies register and threadid is 0, Expression() will fail
a
(in) First parameter, determines value of the pseudovariable %A in expression
b
(in) Second parameter, determines value of the pseudovariable %B in expression
mode
(in) Evaluation mode, combination of zero or more of the following flags:
EMOD_CHKEXTRA - reports error "Extra characters on line" if the first non-blank symbol after syntactically complete expression of maximal length is neither '\0' nor semicolon (starts comment)
EMOD_NOVALUE - requests not to convert the binary value of the expression (result->data) to text (result->value)
EMOD_NOMEMORY - forbids reading of the Debuggee's memory. If expression includes contents of memory and data is not supplied, evaluation will fail
EMOD_MULTI - not allowed in calls to Expression()
EMOD_CHKEXTRA - reports error "Extra characters on line" if the first non-blank symbol after syntactically complete expression of maximal length is neither '\0' nor semicolon (starts comment)
EMOD_NOVALUE - requests not to convert the binary value of the expression (result->data) to text (result->value)
EMOD_NOMEMORY - forbids reading of the Debuggee's memory. If expression includes contents of memory and data is not supplied, evaluation will fail
EMOD_MULTI - not allowed in calls to Expression()
Return values:
Number of processed UNICODE characters in expression.
If expression is syntactically invalid, this is roughly the location of
the syntax error. The inability to estimate the value of the
syntaxically correct expression is indicated by the type EXPR_INVALID in result->datatype
Example:
This is the drawing function of the Watches window:
typedef struct t_watch { // Watch descriptor
ulong addr; // 0-based watch index
ulong size; // Reserved, always 1
ulong type; // Service information, TY_xxx
wchar_t expr[TEXTLEN]; // Watch expression
} t_watch;
// Drawing function of watch window.
int Watchdraw(wchar_t *s,uchar *mask,int *select,
t_table *pt,t_drawheader *ph,int column,void *cache) {
int n=0;
t_watch *pwatch=(t_watch *)ph;
t_result result;
switch (column) {
case DF_CACHESIZE: // Request for draw cache size
return 0;
case DF_FILLCACHE: // Request to fill draw cache
return 0;
case DF_FREECACHE: // Request to free cached resources
return 0;
case DF_NEWROW: // Request to start new row in window
return 0;
case 0: // Expression
n=StrcopyW(s,TEXTLEN,pwatch->expr);
break;
case 1: // Value of expression
if (pwatch->addr==(ulong)watch.sorted.n-1)
break; // Last expression is always empty
Expression(&result,pwatch->expr,NULL,0,0,
Getcputhreadid(),0,0,EMOD_CHKEXTRA);
if (result.datatype==EXPR_INVALID)
*select=DRAW_HILITE|DRAW_TEXT;
n=StrcopyW(s,TEXTLEN,result.value);
break;
default: break; };
return n;
};
typedef struct t_watch { // Watch descriptor
ulong addr; // 0-based watch index
ulong size; // Reserved, always 1
ulong type; // Service information, TY_xxx
wchar_t expr[TEXTLEN]; // Watch expression
} t_watch;
// Drawing function of watch window.
int Watchdraw(wchar_t *s,uchar *mask,int *select,
t_table *pt,t_drawheader *ph,int column,void *cache) {
int n=0;
t_watch *pwatch=(t_watch *)ph;
t_result result;
switch (column) {
case DF_CACHESIZE: // Request for draw cache size
return 0;
case DF_FILLCACHE: // Request to fill draw cache
return 0;
case DF_FREECACHE: // Request to free cached resources
return 0;
case DF_NEWROW: // Request to start new row in window
return 0;
case 0: // Expression
n=StrcopyW(s,TEXTLEN,pwatch->expr);
break;
case 1: // Value of expression
if (pwatch->addr==(ulong)watch.sorted.n-1)
break; // Last expression is always empty
Expression(&result,pwatch->expr,NULL,0,0,
Getcputhreadid(),0,0,EMOD_CHKEXTRA);
if (result.datatype==EXPR_INVALID)
*select=DRAW_HILITE|DRAW_TEXT;
n=StrcopyW(s,TEXTLEN,result.value);
break;
default: break; };
return n;
};
See also: