dbg.y 16.8 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
%{
Alexandre Julliard's avatar
Alexandre Julliard committed
2 3
/*
 * Parser for command lines in the Wine debugger
Alexandre Julliard's avatar
Alexandre Julliard committed
4
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
5
 * Copyright 1993 Eric Youngdale
Alexandre Julliard's avatar
Alexandre Julliard committed
6
 * Copyright 1995 Morten Welinder
7
 * Copyright 2000 Eric Pouech
Alexandre Julliard's avatar
Alexandre Julliard committed
8 9
 */

Patrik Stridvall's avatar
Patrik Stridvall committed
10 11
#include "config.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
12
#include <stdio.h>
13 14
#include <stdlib.h>
#include <string.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
15
#include <signal.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
16
#include <unistd.h>
17

Patrik Stridvall's avatar
Patrik Stridvall committed
18
#include "wine/exception.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
19
#include "debugger.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21
#include "expr.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
22 23
extern FILE * yyin;

24 25
static void issue_prompt(void);
static void mode_command(int);
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28
int yylex(void);
int yyerror(char *);

Alexandre Julliard's avatar
Alexandre Julliard committed
29 30
%}

Alexandre Julliard's avatar
Alexandre Julliard committed
31 32
%union
{
33
    DBG_VALUE        value;
Alexandre Julliard's avatar
Alexandre Julliard committed
34 35
    char *           string;
    int              integer;
Alexandre Julliard's avatar
Alexandre Julliard committed
36 37
    struct list_id   listing;
    struct expr *    expression;
38
    struct datatype* type;
Alexandre Julliard's avatar
Alexandre Julliard committed
39
}
Alexandre Julliard's avatar
Alexandre Julliard committed
40

41
%token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
42
%token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT tVM86
Alexandre Julliard's avatar
Alexandre Julliard committed
43
%token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
44
%token tPROCESS tTHREAD tMODREF tEOL
Alexandre Julliard's avatar
Alexandre Julliard committed
45
%token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
46
%token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS
Alexandre Julliard's avatar
Alexandre Julliard committed
47
%token <string> tPATH
48
%token <string> tIDENTIFIER tSTRING tDEBUGSTR tINTVAR
Alexandre Julliard's avatar
Alexandre Julliard committed
49
%token <integer> tNUM tFORMAT
50
%token tSYMBOLFILE tRUN tATTACH tNOPROCESS
Alexandre Julliard's avatar
Alexandre Julliard committed
51

Alexandre Julliard's avatar
Alexandre Julliard committed
52 53 54
%token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED 
%token tSTRUCT tUNION tENUM

Alexandre Julliard's avatar
Alexandre Julliard committed
55 56 57 58 59 60 61 62 63 64 65 66
/* %left ',' */
/* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
         OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
         OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
/* %left OP_COND */ /* ... ? ... : ... */
%left OP_LOR
%left OP_LAND
%left '|'
%left '^'
%left '&'
%left OP_EQ OP_NE
%left '<' '>' OP_LE OP_GE
Alexandre Julliard's avatar
Alexandre Julliard committed
67
%left OP_SHL OP_SHR
Alexandre Julliard's avatar
Alexandre Julliard committed
68 69 70
%left '+' '-'
%left '*' '/' '%'
%left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
Alexandre Julliard's avatar
Alexandre Julliard committed
71
%left '.' '[' OP_DRF
Alexandre Julliard's avatar
Alexandre Julliard committed
72 73
%nonassoc ':'

Alexandre Julliard's avatar
Alexandre Julliard committed
74 75
%type <expression> expr lval lvalue 
%type <type> type_cast type_expr
76
%type <value> expr_addr lval_addr
Alexandre Julliard's avatar
Alexandre Julliard committed
77 78 79 80
%type <integer> expr_value
%type <string> pathname

%type <listing> list_arg
Alexandre Julliard's avatar
Alexandre Julliard committed
81 82 83

%%

84 85
input: line                   	{ issue_prompt(); }
    | input line                { issue_prompt(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
86 87 88

line: command 
    | tEOL
89
    | error tEOL               	{ yyerrok; }
Alexandre Julliard's avatar
Alexandre Julliard committed
90 91

command:
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
      tQUIT tEOL		{ return FALSE; }
    | tHELP tEOL                { DEBUG_Help(); }
    | tHELP tINFO tEOL          { DEBUG_HelpInfo(); }
    | tCONT tEOL                { DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_CONT; return TRUE; }
    | tPASS tEOL                { DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_PASS; return TRUE; }
    | tCONT tNUM tEOL         	{ DEBUG_CurrThread->dbg_exec_count = $2; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_CONT; return TRUE; }
    | tSTEP tEOL               	{ DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_INSTR; return TRUE; }
    | tNEXT tEOL                { DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_OVER; return TRUE; }
    | tSTEP tNUM tEOL           { DEBUG_CurrThread->dbg_exec_count = $2; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_INSTR; return TRUE; }
    | tNEXT tNUM tEOL           { DEBUG_CurrThread->dbg_exec_count = $2; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_OVER; return TRUE; }
    | tSTEPI tEOL               { DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_INSTR; return TRUE; }
    | tNEXTI tEOL               { DEBUG_CurrThread->dbg_exec_count = 1; 
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_OVER; return TRUE; }
    | tSTEPI tNUM tEOL          { DEBUG_CurrThread->dbg_exec_count = $2; 
			 	  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_INSTR; return TRUE; }
    | tNEXTI tNUM tEOL          { DEBUG_CurrThread->dbg_exec_count = $2; 
                                  DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_OVER; return TRUE; }
    | tABORT tEOL              	{ kill(getpid(), SIGABRT); }
    | tMODE tNUM tEOL          	{ mode_command($2); }
119
    | tMODE tVM86 tEOL         	{ DEBUG_CurrThread->dbg_mode = MODE_VM86; }
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    | tENABLE tNUM tEOL        	{ DEBUG_EnableBreakpoint( $2, TRUE ); }
    | tDISABLE tNUM tEOL       	{ DEBUG_EnableBreakpoint( $2, FALSE ); }
    | tDELETE tBREAK tNUM tEOL 	{ DEBUG_DelBreakpoint( $3 ); }
    | tBACKTRACE tEOL	       	{ DEBUG_BackTrace(TRUE); }
    | tUP tEOL		       	{ DEBUG_SetFrame( curr_frame + 1 );  }
    | tUP tNUM tEOL	       	{ DEBUG_SetFrame( curr_frame + $2 ); }
    | tDOWN tEOL	       	{ DEBUG_SetFrame( curr_frame - 1 );  }
    | tDOWN tNUM tEOL	       	{ DEBUG_SetFrame( curr_frame - $2 ); }
    | tFRAME tNUM tEOL         	{ DEBUG_SetFrame( $2 ); }
    | tFINISH tEOL	       	{ DEBUG_CurrThread->dbg_exec_count = 0;
				  DEBUG_CurrThread->dbg_exec_mode = EXEC_FINISH; return TRUE; }
    | tSHOW tDIR tEOL	       	{ DEBUG_ShowDir(); }
    | tDIR pathname tEOL       	{ DEBUG_AddPath( $2 ); }
    | tDIR tEOL		       	{ DEBUG_NukePath(); }
    | tDISPLAY tEOL	       	{ DEBUG_InfoDisplay(); }
    | tDISPLAY expr tEOL       	{ DEBUG_AddDisplay($2, 1, 0); }
    | tDISPLAY tFORMAT expr tEOL{ DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
    | tDELETE tDISPLAY tNUM tEOL{ DEBUG_DelDisplay( $3 ); }
    | tDELETE tDISPLAY tEOL    	{ DEBUG_DelDisplay( -1 ); }
    | tUNDISPLAY tNUM tEOL     	{ DEBUG_DelDisplay( $2 ); }
    | tUNDISPLAY tEOL          	{ DEBUG_DelDisplay( -1 ); }
    | tCOND tNUM tEOL          	{ DEBUG_AddBPCondition($2, NULL); }
    | tCOND tNUM expr tEOL	{ DEBUG_AddBPCondition($2, $3); }
    | tSYMBOLFILE pathname tEOL	{ DEBUG_ReadSymbolTable($2); }
    | tWHATIS expr_addr tEOL	{ DEBUG_PrintType(&$2); DEBUG_FreeExprMem(); }
    | tATTACH tNUM tEOL		{ DEBUG_Attach($2, FALSE); return TRUE; }
Alexandre Julliard's avatar
Alexandre Julliard committed
146
    | list_command
Alexandre Julliard's avatar
Alexandre Julliard committed
147
    | disassemble_command
Alexandre Julliard's avatar
Alexandre Julliard committed
148 149 150 151
    | set_command
    | x_command
    | print_command
    | break_command
152
    | watch_command
Alexandre Julliard's avatar
Alexandre Julliard committed
153 154
    | info_command
    | walk_command
155 156
    | run_command
    | noprocess_state
Alexandre Julliard's avatar
Alexandre Julliard committed
157 158

set_command:
159
      tSET lval_addr '=' expr_value tEOL   { DEBUG_WriteMemory( &$2, $4 );
Alexandre Julliard's avatar
Alexandre Julliard committed
160 161 162
 					     DEBUG_FreeExprMem(); }

pathname:
163 164
      tIDENTIFIER              { $$ = $1; }
    | tPATH		       { $$ = $1; }
Alexandre Julliard's avatar
Alexandre Julliard committed
165

Alexandre Julliard's avatar
Alexandre Julliard committed
166 167 168 169 170
disassemble_command:
      tDISASSEMBLE tEOL              { DEBUG_Disassemble( NULL, NULL, 10 ); }
    | tDISASSEMBLE expr_addr tEOL    { DEBUG_Disassemble( & $2, NULL, 10 ); }
    | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }

Alexandre Julliard's avatar
Alexandre Julliard committed
171 172 173 174 175 176 177 178 179 180 181 182
list_command:
      tLIST tEOL               { DEBUG_List( NULL, NULL, 10 ); }
    | tLIST '-' tEOL	       { DEBUG_List( NULL, NULL, -10 ); }
    | tLIST list_arg tEOL      { DEBUG_List( & $2, NULL, 10 ); }
    | tLIST ',' list_arg tEOL  { DEBUG_List( NULL, & $3, -10 ); }
    | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }

list_arg:
      tNUM		       { $$.sourcefile = NULL; $$.line = $1; }
    | pathname ':' tNUM	       { $$.sourcefile = $1; $$.line = $3; }
    | tIDENTIFIER	       { DEBUG_GetFuncInfo( & $$, NULL, $1); }
    | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
183 184
    | '*' expr_addr	       { DEBUG_FindNearestSymbol( & $2.addr, FALSE, NULL, 0, & $$ ); 
                                 DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
185 186

x_command:
187
      tEXAM expr_addr tEOL     { DEBUG_ExamineMemory( &$2, 1, 'x'); DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
188
    | tEXAM tFORMAT expr_addr tEOL  { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff ); 
189
 				      DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
190 191

print_command:
192
      tPRINT expr_addr tEOL    { DEBUG_Print( &$2, 1, 0, 0 ); DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
193
    | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 ); 
194
 				      DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
195 196

break_command:
197 198 199 200 201
      tBREAK '*' expr_addr tEOL{ DEBUG_AddBreakpoint( &$3, NULL ); DEBUG_FreeExprMem(); }
    | tBREAK tIDENTIFIER tEOL  { DEBUG_AddBreakpointFromId($2, -1); }
    | tBREAK tIDENTIFIER ':' tNUM tEOL  { DEBUG_AddBreakpointFromId($2, $4); }
    | tBREAK tNUM tEOL	       { DEBUG_AddBreakpointFromLineno($2); }
    | tBREAK tEOL              { DEBUG_AddBreakpointFromLineno(-1); }
Alexandre Julliard's avatar
Alexandre Julliard committed
202

203
watch_command:
204 205
      tWATCH '*' expr_addr tEOL { DEBUG_AddWatchpoint( &$3, 1 ); DEBUG_FreeExprMem(); }
    | tWATCH tIDENTIFIER tEOL   { DEBUG_AddWatchpointFromId($2, -1); }
206

Alexandre Julliard's avatar
Alexandre Julliard committed
207 208
info_command:
      tINFO tBREAK tEOL         { DEBUG_InfoBreakpoints(); }
209
    | tINFO tCLASS tSTRING tEOL	{ DEBUG_InfoClass( $3 ); }
Alexandre Julliard's avatar
Alexandre Julliard committed
210
    | tINFO tSHARE tEOL		{ DEBUG_InfoShare(); }
211 212
    | tINFO tMODULE expr_value tEOL   { DEBUG_DumpModule( $3 ); DEBUG_FreeExprMem(); }
    | tINFO tQUEUE expr_value tEOL    { DEBUG_DumpQueue( $3 ); DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
213
    | tINFO tREGS tEOL          { DEBUG_InfoRegisters(); }
214 215
    | tINFO tSEGMENTS expr_value tEOL { DEBUG_InfoSegments( $3, 1 ); DEBUG_FreeExprMem(); }
    | tINFO tSEGMENTS tEOL      { DEBUG_InfoSegments( 0, -1 ); }
Alexandre Julliard's avatar
Alexandre Julliard committed
216
    | tINFO tSTACK tEOL         { DEBUG_InfoStack(); }
217
    | tINFO tMAPS tEOL          { DEBUG_InfoVirtual(); }
218
    | tINFO tWND expr_value tEOL{ DEBUG_InfoWindow( (HWND)$3 ); DEBUG_FreeExprMem(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
219
    | tINFO tLOCAL tEOL         { DEBUG_InfoLocals(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
220
    | tINFO tDISPLAY tEOL       { DEBUG_InfoDisplay(); }
Alexandre Julliard's avatar
Alexandre Julliard committed
221 222

walk_command:
223 224 225 226
      tWALK tCLASS tEOL         { DEBUG_WalkClasses(); }
    | tWALK tMODULE tEOL        { DEBUG_WalkModules(); }
    | tWALK tQUEUE tEOL         { DEBUG_WalkQueues(); }
    | tWALK tWND tEOL           { DEBUG_WalkWindows( 0, 0 ); }
227
    | tWALK tWND tNUM tEOL      { DEBUG_WalkWindows( (HWND)$3, 0 ); }
228
    | tWALK tPROCESS tEOL       { DEBUG_WalkProcess(); }
229
    | tWALK tTHREAD tEOL        { DEBUG_WalkThreads(); }
230 231 232 233 234
    | tWALK tMODREF expr_value tEOL   { DEBUG_WalkModref( $3 ); DEBUG_FreeExprMem(); }

run_command:
      tRUN tEOL                 { DEBUG_Run(NULL); }
    | tRUN tSTRING tEOL         { DEBUG_Run($2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
235

236 237 238
noprocess_state:
      tNOPROCESS tEOL		{} /* <CR> shall not barf anything */
    | tNOPROCESS tSTRING tEOL	{ DEBUG_Printf(DBG_CHN_MESG, "No process loaded, cannot execute '%s'\n", $2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
239 240 241 242 243 244

type_cast: 
      '(' type_expr ')'		{ $$ = $2; }

type_expr:
      type_expr '*'		{ $$ = DEBUG_FindOrMakePointerType($1); }
245 246 247 248 249 250
    |  tINT			{ $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
    | tCHAR			{ $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
    | tLONG tINT		{ $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
    | tUNSIGNED tINT		{ $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
    | tLONG tUNSIGNED tINT	{ $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
    | tLONG tLONG tINT		{ $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
251
    | tLONG tLONG tUNSIGNED tINT{ $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
252 253 254 255 256 257 258 259 260 261
    | tSHORT tINT		{ $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
    | tSHORT tUNSIGNED tINT	{ $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
    | tSIGNED tCHAR		{ $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
    | tUNSIGNED tCHAR		{ $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
    | tFLOAT			{ $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
    | tDOUBLE			{ $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
    | tLONG tDOUBLE		{ $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
    | tSTRUCT tIDENTIFIER	{ $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
    | tUNION tIDENTIFIER	{ $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
    | tENUM tIDENTIFIER		{ $$ = DEBUG_TypeCast(DT_ENUM, $2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
262

Alexandre Julliard's avatar
Alexandre Julliard committed
263
expr_addr:
264
      expr			{ $$ = DEBUG_EvalExpr($1); }
Alexandre Julliard's avatar
Alexandre Julliard committed
265

Alexandre Julliard's avatar
Alexandre Julliard committed
266
expr_value:
267 268 269 270
      expr        		{ DBG_VALUE	value = DEBUG_EvalExpr($1); 
                                  /* expr_value is typed as an integer */
                                  $$ = DEBUG_ReadMemory(&value); }

Alexandre Julliard's avatar
Alexandre Julliard committed
271 272 273 274 275 276
/*
 * The expr rule builds an expression tree.  When we are done, we call
 * EvalExpr to evaluate the value of the expression.  The advantage of
 * the two-step approach is that it is possible to save expressions for
 * use in 'display' commands, and in conditional watchpoints.
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
277
expr:
Alexandre Julliard's avatar
Alexandre Julliard committed
278 279
      tNUM                       { $$ = DEBUG_ConstExpr($1); }
    | tSTRING			 { $$ = DEBUG_StringExpr($1); }
280
    | tINTVAR                    { $$ = DEBUG_IntVarExpr($1); }
Alexandre Julliard's avatar
Alexandre Julliard committed
281 282 283 284 285
    | tIDENTIFIER		 { $$ = DEBUG_SymbolExpr($1); }
    | expr OP_DRF tIDENTIFIER	 { $$ = DEBUG_StructPExpr($1, $3); } 
    | expr '.' tIDENTIFIER	 { $$ = DEBUG_StructExpr($1, $3); } 
    | tIDENTIFIER '(' ')'	 { $$ = DEBUG_CallExpr($1, 0); } 
    | tIDENTIFIER '(' expr ')'	 { $$ = DEBUG_CallExpr($1, 1, $3); } 
286
    | tIDENTIFIER '(' expr ',' expr ')'	 { $$ = DEBUG_CallExpr($1, 2, $3, $5); } 
Alexandre Julliard's avatar
Alexandre Julliard committed
287
    | tIDENTIFIER '(' expr ',' expr ',' expr ')'	 { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); } 
288 289
    | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')'	 { $$ = DEBUG_CallExpr($1, 4, $3, $5, $7, $9); } 
    | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')'	 { $$ = DEBUG_CallExpr($1, 5, $3, $5, $7, $9, $11); } 
Alexandre Julliard's avatar
Alexandre Julliard committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
    | expr '[' expr ']'		 { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); } 
    | expr ':' expr		 { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); } 
    | expr OP_LOR expr           { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
    | expr OP_LAND expr          { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
    | expr '|' expr              { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
    | expr '&' expr              { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
    | expr '^' expr              { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
    | expr OP_EQ expr            { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
    | expr '>' expr              { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
    | expr '<' expr              { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
    | expr OP_GE expr            { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
    | expr OP_LE expr            { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
    | expr OP_NE expr            { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
    | expr OP_SHL expr           { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
    | expr OP_SHR expr           { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
    | expr '+' expr              { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
    | expr '-' expr              { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
    | expr '*' expr              { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
    | expr '/' expr              { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
    | expr '%' expr              { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
    | '-' expr %prec OP_SIGN     { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
311
    | '+' expr %prec OP_SIGN     { $$ = $2; }
Alexandre Julliard's avatar
Alexandre Julliard committed
312 313
    | '!' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
    | '~' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
314
    | '(' expr ')'               { $$ = $2; }
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
    | '*' expr %prec OP_DEREF    { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
    | '&' expr %prec OP_DEREF    { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
Alexandre Julliard's avatar
Alexandre Julliard committed
317
    | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); } 
Alexandre Julliard's avatar
Alexandre Julliard committed
318 319 320 321 322 323
	
/*
 * The lvalue rule builds an expression tree.  This is a limited form
 * of expression that is suitable to be used as an lvalue.
 */
lval_addr:
Alexandre Julliard's avatar
Alexandre Julliard committed
324
    lval			 { $$ = DEBUG_EvalExpr($1); }
Alexandre Julliard's avatar
Alexandre Julliard committed
325 326 327 328 329 330 331

lval:
      lvalue                     { $$ = $1; }
    | '*' expr			 { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
	
lvalue:
      tNUM                       { $$ = DEBUG_ConstExpr($1); }
332
    | tINTVAR                    { $$ = DEBUG_IntVarExpr($1); }
Alexandre Julliard's avatar
Alexandre Julliard committed
333 334 335 336
    | tIDENTIFIER		 { $$ = DEBUG_SymbolExpr($1); }
    | lvalue OP_DRF tIDENTIFIER	 { $$ = DEBUG_StructPExpr($1, $3); } 
    | lvalue '.' tIDENTIFIER	 { $$ = DEBUG_StructExpr($1, $3); } 
    | lvalue '[' expr ']'	 { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); } 
Alexandre Julliard's avatar
Alexandre Julliard committed
337 338 339
	
%%

340 341
static void issue_prompt(void)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
342
#ifdef DONT_USE_READLINE
343
   DEBUG_Printf(DBG_CHN_MESG, "Wine-dbg>");
Alexandre Julliard's avatar
Alexandre Julliard committed
344 345 346
#endif
}

347
static void mode_command(int newmode)
Alexandre Julliard's avatar
Alexandre Julliard committed
348
{
349 350 351 352 353 354
    switch(newmode)
    {
    case 16: DEBUG_CurrThread->dbg_mode = MODE_16; break;
    case 32: DEBUG_CurrThread->dbg_mode = MODE_32; break;
    default: DEBUG_Printf(DBG_CHN_MESG,"Invalid mode (use 16, 32 or vm86)\n");
    }
355 356 357 358 359
}

void DEBUG_Exit(DWORD ec)
{
   ExitProcess(ec);
Alexandre Julliard's avatar
Alexandre Julliard committed
360 361
}

362
static WINE_EXCEPTION_FILTER(wine_dbg_cmd)
363
{
364
   DEBUG_Printf(DBG_CHN_MESG, "\nwine_dbg_cmd: ");
365 366
   switch (GetExceptionCode()) {
   case DEBUG_STATUS_INTERNAL_ERROR:
367
      DEBUG_Printf(DBG_CHN_MESG, "WineDbg internal error\n");
368 369
      break;
   case DEBUG_STATUS_NO_SYMBOL:
370
      DEBUG_Printf(DBG_CHN_MESG, "Undefined symbol\n");
371 372
      break;
   case DEBUG_STATUS_DIV_BY_ZERO:
373
      DEBUG_Printf(DBG_CHN_MESG, "Division by zero\n");
374 375
      break;
   case DEBUG_STATUS_BAD_TYPE:
376
      DEBUG_Printf(DBG_CHN_MESG, "No type or type mismatch\n");
377 378
      break;
   default:
379
      DEBUG_Printf(DBG_CHN_MESG, "Exception %lx\n", GetExceptionCode());
380 381
      break;
   }
382

383
   return EXCEPTION_EXECUTE_HANDLER;
384
}
Alexandre Julliard's avatar
Alexandre Julliard committed
385

Alexandre Julliard's avatar
Alexandre Julliard committed
386
/***********************************************************************
387
 *           DEBUG_Parser
Alexandre Julliard's avatar
Alexandre Julliard committed
388
 *
389
 * Debugger editline parser
Alexandre Julliard's avatar
Alexandre Julliard committed
390
 */
391
BOOL	DEBUG_Parser(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
392
{
393 394
    BOOL 	ret_ok;
    BOOL	ret = TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
395
#ifdef YYDEBUG
Alexandre Julliard's avatar
Alexandre Julliard committed
396
    yydebug = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
397
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
398 399
    yyin = stdin;

400 401 402 403
    ret_ok = FALSE;
    do {
       __TRY {
	  issue_prompt();
404
	  ret_ok = TRUE;
405 406 407 408 409 410 411 412 413 414
	  if ((ret = yyparse())) {
	     DEBUG_FlushSymbols();
	  }
       } __EXCEPT(wine_dbg_cmd) {
	  ret_ok = FALSE;
       }
       __ENDTRY;
       
    } while (!ret_ok);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
415 416
}

417
int yyerror(char* s)
Alexandre Julliard's avatar
Alexandre Julliard committed
418
{
419
   DEBUG_Printf(DBG_CHN_MESG, "%s\n", s);
420
   return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
421
}