- Removed no longer used queue & modref related commands.
[wine] / programs / winedbg / dbg.y
1 %{
2 /*
3  * Parser for command lines in the Wine debugger
4  *
5  * Copyright 1993 Eric Youngdale
6  * Copyright 1995 Morten Welinder
7  * Copyright 2000 Eric Pouech
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <signal.h>
30 #include <unistd.h>
31
32 #include "wine/exception.h"
33 #include "debugger.h"
34 #include "expr.h"
35 #include "excpt.h"
36
37 static void mode_command(int);
38 int yylex(void);
39 int yyerror(char *);
40
41 %}
42
43 %union
44 {
45     DBG_VALUE        value;
46     char *           string;
47     int              integer;
48     struct list_id   listing;
49     struct expr *    expression;
50     struct datatype* type;
51 }
52
53 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
54 %token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT tVM86
55 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tSYMBOL tREGS tWND tLOCAL tEXCEPTION
56 %token tPROCESS tTHREAD tEOL tEOF
57 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tSYMBOL tREGS tWND tQUEUE tLOCAL tEXCEPTION
58 %token tPROCESS tTHREAD tMODREF tEOL tEOF
59 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
60 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
61 %token <string> tPATH
62 %token <string> tIDENTIFIER tSTRING tDEBUGSTR tINTVAR
63 %token <integer> tNUM tFORMAT
64 %token tSYMBOLFILE tRUN tATTACH tDETACH tNOPROCESS
65
66 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
67 %token tSTRUCT tUNION tENUM
68
69 /* %left ',' */
70 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
71          OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
72          OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
73 /* %left OP_COND */ /* ... ? ... : ... */
74 %left OP_LOR
75 %left OP_LAND
76 %left '|'
77 %left '^'
78 %left '&'
79 %left OP_EQ OP_NE
80 %left '<' '>' OP_LE OP_GE
81 %left OP_SHL OP_SHR
82 %left '+' '-'
83 %left '*' '/' '%'
84 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
85 %left '.' '[' OP_DRF
86 %nonassoc ':'
87
88 %type <expression> expr lval lvalue
89 %type <type> type_expr
90 %type <value> expr_addr lval_addr
91 %type <integer> expr_value
92 %type <string> pathname identifier
93
94 %type <listing> list_arg
95
96 %%
97
98 input: line
99     | input line
100     ;
101
102 line: command
103     | tEOL
104     | tEOF                      { return 1; }
105     | error tEOL                { yyerrok; }
106     ;
107
108 command:
109       tQUIT tEOL                { /*DEBUG_Quit();*/ return 1; }
110     | tHELP tEOL                { DEBUG_Help(); }
111     | tHELP tINFO tEOL          { DEBUG_HelpInfo(); }
112     | tPASS tEOL                { DEBUG_WaitNextException(DBG_EXCEPTION_NOT_HANDLED, 0, 0); }
113     | tCONT tEOL                { DEBUG_WaitNextException(DBG_CONTINUE, 1,  EXEC_CONT); }
114     | tCONT tNUM tEOL           { DEBUG_WaitNextException(DBG_CONTINUE, $2, EXEC_CONT); }
115     | tSTEP tEOL                { DEBUG_WaitNextException(DBG_CONTINUE, 1,  EXEC_STEP_INSTR); }
116     | tSTEP tNUM tEOL           { DEBUG_WaitNextException(DBG_CONTINUE, $2, EXEC_STEP_INSTR); }
117     | tNEXT tEOL                { DEBUG_WaitNextException(DBG_CONTINUE, 1,  EXEC_STEP_OVER); }
118     | tNEXT tNUM tEOL           { DEBUG_WaitNextException(DBG_CONTINUE, $2, EXEC_STEP_OVER); }
119     | tSTEPI tEOL               { DEBUG_WaitNextException(DBG_CONTINUE, 1,  EXEC_STEPI_INSTR); }
120     | tSTEPI tNUM tEOL          { DEBUG_WaitNextException(DBG_CONTINUE, $2, EXEC_STEPI_INSTR); }
121     | tNEXTI tEOL               { DEBUG_WaitNextException(DBG_CONTINUE, 1,  EXEC_STEPI_OVER); }
122     | tNEXTI tNUM tEOL          { DEBUG_WaitNextException(DBG_CONTINUE, $2, EXEC_STEPI_OVER); }
123     | tFINISH tEOL              { DEBUG_WaitNextException(DBG_CONTINUE, 0,  EXEC_FINISH); }
124     | tABORT tEOL               { kill(getpid(), SIGABRT); }
125     | tMODE tNUM tEOL           { mode_command($2); }
126     | tMODE tVM86 tEOL          { DEBUG_CurrThread->dbg_mode = MODE_VM86; }
127     | tENABLE tNUM tEOL         { DEBUG_EnableBreakpoint( $2, TRUE ); }
128     | tDISABLE tNUM tEOL        { DEBUG_EnableBreakpoint( $2, FALSE ); }
129     | tDELETE tBREAK tNUM tEOL  { DEBUG_DelBreakpoint( $3 ); }
130     | tBACKTRACE tEOL           { DEBUG_BackTrace(DEBUG_CurrTid, TRUE); }
131     | tBACKTRACE tNUM tEOL      { DEBUG_BackTrace($2, TRUE); }
132     | tUP tEOL                  { DEBUG_SetFrame( curr_frame + 1 );  }
133     | tUP tNUM tEOL             { DEBUG_SetFrame( curr_frame + $2 ); }
134     | tDOWN tEOL                { DEBUG_SetFrame( curr_frame - 1 );  }
135     | tDOWN tNUM tEOL           { DEBUG_SetFrame( curr_frame - $2 ); }
136     | tFRAME tNUM tEOL          { DEBUG_SetFrame( $2 ); }
137     | tSHOW tDIR tEOL           { DEBUG_ShowDir(); }
138     | tDIR pathname tEOL        { DEBUG_AddPath( $2 ); }
139     | tDIR tEOL                 { DEBUG_NukePath(); }
140     | tDISPLAY tEOL             { DEBUG_InfoDisplay(); }
141     | tDISPLAY expr tEOL        { DEBUG_AddDisplay($2, 1, 0); }
142     | tDISPLAY tFORMAT expr tEOL{ DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
143     | tDELETE tDISPLAY tNUM tEOL{ DEBUG_DelDisplay( $3 ); }
144     | tDELETE tDISPLAY tEOL     { DEBUG_DelDisplay( -1 ); }
145     | tUNDISPLAY tNUM tEOL      { DEBUG_DelDisplay( $2 ); }
146     | tUNDISPLAY tEOL           { DEBUG_DelDisplay( -1 ); }
147     | tCOND tNUM tEOL           { DEBUG_AddBPCondition($2, NULL); }
148     | tCOND tNUM expr tEOL      { DEBUG_AddBPCondition($2, $3); }
149     | tSOURCE pathname tEOL     { DEBUG_Parser($2); }
150     | tSYMBOLFILE pathname tEOL { DEBUG_ReadSymbolTable($2, 0); }
151     | tSYMBOLFILE pathname tNUM tEOL    { DEBUG_ReadSymbolTable($2, $3); }
152     | tWHATIS expr_addr tEOL    { DEBUG_PrintType(&$2); DEBUG_FreeExprMem(); }
153     | tATTACH tNUM tEOL         { DEBUG_Attach($2, FALSE); }
154     | tDETACH tEOL              { return DEBUG_Detach(); /* FIXME: we shouldn't return, but since we cannot simply clean the symbol table, exit debugger for now */ }
155     | list_command
156     | disassemble_command
157     | set_command
158     | x_command
159     | print_command
160     | break_command
161     | watch_command
162     | info_command
163     | walk_command
164     | run_command
165     | noprocess_state
166     ;
167
168 set_command:
169       tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory(&$2, $4); DEBUG_FreeExprMem(); }
170     | tSET '+' tIDENTIFIER tEOL { DEBUG_DbgChannel(TRUE, NULL, $3); }
171     | tSET '-' tIDENTIFIER tEOL { DEBUG_DbgChannel(FALSE, NULL, $3); }
172     | tSET tIDENTIFIER '+' tIDENTIFIER tEOL { DEBUG_DbgChannel(TRUE, $2, $4); }
173     | tSET tIDENTIFIER '-' tIDENTIFIER tEOL { DEBUG_DbgChannel(FALSE, $2, $4); }
174     ;
175
176 pathname:
177       tIDENTIFIER               { $$ = $1; }
178     | tPATH                     { $$ = $1; }
179     ;
180
181 disassemble_command:
182       tDISASSEMBLE tEOL         { DEBUG_Disassemble( NULL, NULL, 10 ); }
183     | tDISASSEMBLE expr_addr tEOL       { DEBUG_Disassemble( & $2, NULL, 10 ); }
184     | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
185     ;
186
187 list_command:
188       tLIST tEOL                { DEBUG_List( NULL, NULL, 10 ); }
189     | tLIST '-' tEOL            { DEBUG_List( NULL, NULL, -10 ); }
190     | tLIST list_arg tEOL       { DEBUG_List( & $2, NULL, 10 ); }
191     | tLIST ',' list_arg tEOL   { DEBUG_List( NULL, & $3, -10 ); }
192     | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
193     ;
194
195 list_arg:
196       tNUM                     { $$.sourcefile = NULL; $$.line = $1; }
197     | pathname ':' tNUM        { $$.sourcefile = $1; $$.line = $3; }
198     | tIDENTIFIER              { DEBUG_GetFuncInfo( & $$, NULL, $1); }
199     | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
200     | '*' expr_addr            { DEBUG_FindNearestSymbol( & $2.addr, FALSE, NULL, 0, & $$ );
201                                  DEBUG_FreeExprMem(); }
202     ;
203
204 x_command:
205       tEXAM expr_addr tEOL     { DEBUG_ExamineMemory( &$2, 1, 'x'); DEBUG_FreeExprMem(); }
206     | tEXAM tFORMAT expr_addr tEOL  { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
207                                       DEBUG_FreeExprMem(); }
208     ;
209
210 print_command:
211       tPRINT expr_addr tEOL    { DEBUG_Print( &$2, 1, 0, 0 ); DEBUG_FreeExprMem(); }
212     | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
213                                       DEBUG_FreeExprMem(); }
214     ;
215
216 break_command:
217       tBREAK '*' expr_addr tEOL{ DEBUG_AddBreakpointFromValue( &$3 ); DEBUG_FreeExprMem(); }
218     | tBREAK identifier tEOL   { DEBUG_AddBreakpointFromId($2, -1); }
219     | tBREAK identifier ':' tNUM tEOL  { DEBUG_AddBreakpointFromId($2, $4); }
220     | tBREAK tNUM tEOL         { DEBUG_AddBreakpointFromLineno($2); }
221     | tBREAK tEOL              { DEBUG_AddBreakpointFromLineno(-1); }
222     ;
223
224 watch_command:
225       tWATCH '*' expr_addr tEOL { DEBUG_AddWatchpoint( &$3, 1 ); DEBUG_FreeExprMem(); }
226     | tWATCH identifier tEOL    { DEBUG_AddWatchpointFromId($2); }
227     ;
228
229 info_command:
230       tINFO tBREAK tEOL         { DEBUG_InfoBreakpoints(); }
231     | tINFO tCLASS tSTRING tEOL { DEBUG_InfoClass( $3 ); }
232     | tINFO tSHARE tEOL         { DEBUG_InfoShare(); }
233     | tINFO tMODULE expr_value tEOL   { DEBUG_DumpModule( $3 ); DEBUG_FreeExprMem(); }
234     | tINFO tREGS tEOL          { DEBUG_InfoRegisters(&DEBUG_context); }
235     | tINFO tSEGMENTS expr_value tEOL { DEBUG_InfoSegments( $3, 1 ); DEBUG_FreeExprMem(); }
236     | tINFO tSEGMENTS tEOL      { DEBUG_InfoSegments( 0, -1 ); }
237     | tINFO tSTACK tEOL         { DEBUG_InfoStack(); }
238     | tINFO tSYMBOL tSTRING tEOL{ DEBUG_InfoSymbols($3); }
239     | tINFO tWND expr_value tEOL{ DEBUG_InfoWindow( (HWND)$3 ); DEBUG_FreeExprMem(); }
240     | tINFO tLOCAL tEOL         { DEBUG_InfoLocals(); }
241     | tINFO tDISPLAY tEOL       { DEBUG_InfoDisplay(); }
242     ;
243
244 walk_command:
245       tWALK tCLASS tEOL         { DEBUG_WalkClasses(); }
246     | tWALK tMODULE tEOL        { DEBUG_WalkModules(); }
247     | tWALK tWND tEOL           { DEBUG_WalkWindows( 0, 0 ); }
248     | tWALK tWND expr_value tEOL{ DEBUG_WalkWindows( (HWND)$3, 0 ); DEBUG_FreeExprMem(); }
249     | tWALK tMAPS tEOL          { DEBUG_InfoVirtual(0); }
250     | tWALK tMAPS expr_value tEOL { DEBUG_InfoVirtual($3); DEBUG_FreeExprMem(); }
251     | tWALK tPROCESS tEOL       { DEBUG_WalkProcess(); }
252     | tWALK tTHREAD tEOL        { DEBUG_WalkThreads(); }
253     | tWALK tEXCEPTION tEOL     { DEBUG_WalkExceptions(DEBUG_CurrTid); }
254     | tWALK tEXCEPTION expr_value tEOL{ DEBUG_WalkExceptions($3); DEBUG_FreeExprMem(); }
255     ;
256
257 run_command:
258       tRUN tEOL                 { DEBUG_Run(NULL); }
259     | tRUN tSTRING tEOL         { DEBUG_Run($2); }
260     ;
261
262 noprocess_state:
263       tNOPROCESS tEOL           {} /* <CR> shall not barf anything */
264     | tNOPROCESS tSTRING tEOL   { DEBUG_Printf(DBG_CHN_MESG, "No process loaded, cannot execute '%s'\n", $2); }
265     ;
266
267 type_expr:
268       type_expr '*'             { $$ = $1 ? DEBUG_FindOrMakePointerType($1) : NULL; }
269     | tINT                      { $$ = DEBUG_GetBasicType(DT_BASIC_INT); }
270     | tCHAR                     { $$ = DEBUG_GetBasicType(DT_BASIC_CHAR); }
271     | tLONG tINT                { $$ = DEBUG_GetBasicType(DT_BASIC_LONGINT); }
272     | tUNSIGNED tINT            { $$ = DEBUG_GetBasicType(DT_BASIC_UINT); }
273     | tLONG tUNSIGNED tINT      { $$ = DEBUG_GetBasicType(DT_BASIC_ULONGINT); }
274     | tLONG tLONG tINT          { $$ = DEBUG_GetBasicType(DT_BASIC_LONGLONGINT); }
275     | tLONG tLONG tUNSIGNED tINT{ $$ = DEBUG_GetBasicType(DT_BASIC_ULONGLONGINT); }
276     | tSHORT tINT               { $$ = DEBUG_GetBasicType(DT_BASIC_SHORTINT); }
277     | tSHORT tUNSIGNED tINT     { $$ = DEBUG_GetBasicType(DT_BASIC_USHORTINT); }
278     | tSIGNED tCHAR             { $$ = DEBUG_GetBasicType(DT_BASIC_SCHAR); }
279     | tUNSIGNED tCHAR           { $$ = DEBUG_GetBasicType(DT_BASIC_UCHAR); }
280     | tFLOAT                    { $$ = DEBUG_GetBasicType(DT_BASIC_FLOAT); }
281     | tDOUBLE                   { $$ = DEBUG_GetBasicType(DT_BASIC_DOUBLE); }
282     | tLONG tDOUBLE             { $$ = DEBUG_GetBasicType(DT_BASIC_LONGDOUBLE); }
283     | tSTRUCT tIDENTIFIER       { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
284     | tUNION tIDENTIFIER        { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
285     | tENUM tIDENTIFIER         { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
286     ;
287
288 expr_addr: expr                 { $$ = DEBUG_EvalExpr($1); }
289     ;
290
291 expr_value: expr                { DBG_VALUE value = DEBUG_EvalExpr($1);
292                                   /* expr_value is typed as an integer */
293                                   $$ = DEBUG_ReadMemory(&value); }
294     ;
295
296 /*
297  * The expr rule builds an expression tree.  When we are done, we call
298  * EvalExpr to evaluate the value of the expression.  The advantage of
299  * the two-step approach is that it is possible to save expressions for
300  * use in 'display' commands, and in conditional watchpoints.
301  */
302 expr:
303       tNUM                       { $$ = DEBUG_ConstExpr($1); }
304     | tSTRING                    { $$ = DEBUG_StringExpr($1); }
305     | tINTVAR                    { $$ = DEBUG_IntVarExpr($1); }
306     | tIDENTIFIER                { $$ = DEBUG_SymbolExpr($1); }
307     | expr OP_DRF tIDENTIFIER    { $$ = DEBUG_StructPExpr($1, $3); }
308     | expr '.' tIDENTIFIER       { $$ = DEBUG_StructExpr($1, $3); }
309     | tIDENTIFIER '(' ')'        { $$ = DEBUG_CallExpr($1, 0); }
310     | tIDENTIFIER '(' expr ')'   { $$ = DEBUG_CallExpr($1, 1, $3); }
311     | tIDENTIFIER '(' expr ',' expr ')'  { $$ = DEBUG_CallExpr($1, 2, $3, $5); }
312     | tIDENTIFIER '(' expr ',' expr ',' expr ')'         { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
313     | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')'        { $$ = DEBUG_CallExpr($1, 4, $3, $5, $7, $9); }
314     | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')'       { $$ = DEBUG_CallExpr($1, 5, $3, $5, $7, $9, $11); }
315     | expr '[' expr ']'          { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
316     | expr ':' expr              { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
317     | expr OP_LOR expr           { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
318     | expr OP_LAND expr          { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
319     | expr '|' expr              { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
320     | expr '&' expr              { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
321     | expr '^' expr              { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
322     | expr OP_EQ expr            { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
323     | expr '>' expr              { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
324     | expr '<' expr              { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
325     | expr OP_GE expr            { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
326     | expr OP_LE expr            { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
327     | expr OP_NE expr            { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
328     | expr OP_SHL expr           { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
329     | expr OP_SHR expr           { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
330     | expr '+' expr              { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
331     | expr '-' expr              { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
332     | expr '*' expr              { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
333     | expr '/' expr              { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
334     | expr '%' expr              { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
335     | '-' expr %prec OP_SIGN     { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
336     | '+' expr %prec OP_SIGN     { $$ = $2; }
337     | '!' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
338     | '~' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
339     | '(' expr ')'               { $$ = $2; }
340     | '*' expr %prec OP_DEREF    { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
341     | '&' expr %prec OP_DEREF    { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
342     | '(' type_expr ')' expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($2, $4); }
343     ;
344
345 /*
346  * The lvalue rule builds an expression tree.  This is a limited form
347  * of expression that is suitable to be used as an lvalue.
348  */
349 lval_addr: lval                  { $$ = DEBUG_EvalExpr($1); }
350     ;
351
352 lval: lvalue                     { $$ = $1; }
353     | '*' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
354     ;
355
356 lvalue: tNUM                     { $$ = DEBUG_ConstExpr($1); }
357     | tINTVAR                    { $$ = DEBUG_IntVarExpr($1); }
358     | tIDENTIFIER                { $$ = DEBUG_SymbolExpr($1); }
359     | lvalue OP_DRF tIDENTIFIER  { $$ = DEBUG_StructPExpr($1, $3); }
360     | lvalue '.' tIDENTIFIER     { $$ = DEBUG_StructExpr($1, $3); }
361     | lvalue '[' expr ']'        { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
362     ;
363
364 identifier: tIDENTIFIER          { $$ = $1; }
365     | identifier '.' tIDENTIFIER { char* ptr = DBG_alloc(strlen($1) + 1 + strlen($3)+ 1);
366                                    sprintf(ptr, "%s.%s", $1, $3); $$ = DEBUG_MakeSymbol(ptr);
367                                    DBG_free(ptr); }
368     | identifier ':' ':' tIDENTIFIER { char* ptr = DBG_alloc(strlen($1) + 2 + strlen($4) + 1);
369                                    sprintf(ptr, "%s::%s", $1, $4); $$ = DEBUG_MakeSymbol(ptr);
370                                    DBG_free(ptr); }
371     ;
372
373 %%
374
375 static void mode_command(int newmode)
376 {
377     switch(newmode)
378     {
379     case 16: DEBUG_CurrThread->dbg_mode = MODE_16; break;
380     case 32: DEBUG_CurrThread->dbg_mode = MODE_32; break;
381     default: DEBUG_Printf(DBG_CHN_MESG,"Invalid mode (use 16, 32 or vm86)\n");
382     }
383 }
384
385 void DEBUG_Exit(DWORD ec)
386 {
387    ExitProcess(ec);
388 }
389
390 static WINE_EXCEPTION_FILTER(wine_dbg_cmd)
391 {
392    DEBUG_Printf(DBG_CHN_MESG, "\nwine_dbg_cmd: ");
393    switch (GetExceptionCode()) {
394    case DEBUG_STATUS_INTERNAL_ERROR:
395       DEBUG_Printf(DBG_CHN_MESG, "WineDbg internal error\n");
396       break;
397    case DEBUG_STATUS_NO_SYMBOL:
398       DEBUG_Printf(DBG_CHN_MESG, "Undefined symbol\n");
399       break;
400    case DEBUG_STATUS_DIV_BY_ZERO:
401       DEBUG_Printf(DBG_CHN_MESG, "Division by zero\n");
402       break;
403    case DEBUG_STATUS_BAD_TYPE:
404       DEBUG_Printf(DBG_CHN_MESG, "No type or type mismatch\n");
405       break;
406    case DEBUG_STATUS_NO_FIELD:
407       DEBUG_Printf(DBG_CHN_MESG, "No such field in structure or union\n");
408       break;
409    case DEBUG_STATUS_ABORT:
410        break;
411    default:
412       DEBUG_Printf(DBG_CHN_MESG, "Exception %lx\n", GetExceptionCode());
413       DEBUG_ExternalDebugger();
414       break;
415    }
416
417    return EXCEPTION_EXECUTE_HANDLER;
418 }
419
420 static  void set_default_channels(void)
421 {
422     DEBUG_hParserOutput = GetStdHandle(STD_OUTPUT_HANDLE);
423     DEBUG_hParserInput  = GetStdHandle(STD_INPUT_HANDLE);
424 }
425
426 /***********************************************************************
427  *           DEBUG_Parser
428  *
429  * Debugger editline parser
430  */
431 void    DEBUG_Parser(LPCSTR filename)
432 {
433     BOOL                ret_ok;
434 #ifdef YYDEBUG
435     yydebug = 0;
436 #endif
437
438     ret_ok = FALSE;
439
440     if (filename)
441     {
442         DEBUG_hParserOutput = 0;
443         DEBUG_hParserInput  = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
444         if (DEBUG_hParserInput == INVALID_HANDLE_VALUE)
445         {
446             set_default_channels();
447             return;
448         }
449     }
450     else
451         set_default_channels();
452
453     do
454     {
455        __TRY
456            {
457           ret_ok = TRUE;
458           yyparse();
459        }
460        __EXCEPT(wine_dbg_cmd)
461        {
462           ret_ok = FALSE;
463        }
464        __ENDTRY;
465        DEBUG_FlushSymbols();
466     } while (!ret_ok);
467
468     if (filename)
469         CloseHandle(DEBUG_hParserInput);
470     set_default_channels();
471 }
472
473 int yyerror(char* s)
474 {
475    DEBUG_Printf(DBG_CHN_MESG, "%s\n", s);
476    return 0;
477 }