winedbg: Handle multi-machine process in command 'info share'.
[wine.git] / programs / winedbg / dbg.y
blobf46e665e6b933e2fed6c2f76797721514248001a
1 %{
2 /*
3 * Parser for command lines in the Wine debugger
5 * Copyright 1993 Eric Youngdale
6 * Copyright 1995 Morten Welinder
7 * Copyright 2000 Eric Pouech
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "debugger.h"
29 #include "wine/exception.h"
30 #include "expr.h"
32 int dbg_lex(void);
33 static int dbg_error(const char*);
34 static void parser(const char*);
38 %define api.prefix {dbg_}
40 %union
42 struct dbg_lvalue lvalue;
43 char* string;
44 dbg_lgint_t integer;
45 IMAGEHLP_LINE64 listing;
46 struct expr* expression;
47 struct dbg_type type;
48 struct list_string* strings;
51 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tALL tINFO tUP tDOWN
52 %token tENABLE tDISABLE tBREAK tHBREAK tWATCH tRWATCH tDELETE tSET tPRINT tEXAM
53 %token tABORT tECHO
54 %token tCLASS tMAPS tSTACK tSEGMENTS tSYMBOL tREGS tALLREGS tWND tLOCAL tEXCEPTION
55 %token tPROCESS tTHREAD tEOL tEOF
56 %token tFRAME tSHARE tMODULE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
57 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
58 %token <string> tPATH tIDENTIFIER tSTRING tINTVAR
59 %token <integer> tNUM tFORMAT
60 %token <type> tTYPEDEF
61 %token tSYMBOLFILE tRUN tATTACH tDETACH tKILL tMAINTENANCE tTYPE tMINIDUMP
62 %token tNOPROCESS tWOW
64 /* can be prefixed by module name */
65 %token <string> tVOID tCHAR tWCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
66 %token tSTRUCT tUNION tENUM
68 /* %left ',' */
69 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
70 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
71 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
72 /* %left OP_COND */ /* ... ? ... : ... */
73 %left OP_LOR
74 %left OP_LAND
75 %left '|'
76 %left '^'
77 %left '&'
78 %left OP_EQ OP_NE
79 %left '<' '>' OP_LE OP_GE
80 %left OP_SHL OP_SHR
81 %left '+' '-'
82 %left '*' '/' '%'
83 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
84 %left '.' '[' OP_DRF
85 %nonassoc ':'
87 %type <expression> expr lvalue
88 %type <lvalue> expr_lvalue lvalue_addr
89 %type <integer> expr_rvalue
90 %type <string> pathname identifier
91 %type <listing> list_arg
92 %type <type> type_expr
93 %type <strings> list_of_words
97 input:
98 line
99 | input line
102 line:
103 command tEOL { expr_free_all(); }
104 | tEOL
105 | tEOF { return 1; }
106 | error tEOL { yyerrok; expr_free_all(); }
109 command:
110 tQUIT { return 1; }
111 | tHELP { print_help(); }
112 | tHELP tINFO { info_help(); }
113 | tPASS { dbg_wait_next_exception(DBG_EXCEPTION_NOT_HANDLED, 0, 0); }
114 | tCONT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_cont); }
115 | tCONT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_cont); }
116 | tSTEP { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_line); }
117 | tSTEP tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_line); }
118 | tNEXT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_line); }
119 | tNEXT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_line); }
120 | tSTEPI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_insn); }
121 | tSTEPI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_insn); }
122 | tNEXTI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_insn); }
123 | tNEXTI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_insn); }
124 | tFINISH { dbg_wait_next_exception(DBG_CONTINUE, 0, dbg_exec_finish); }
125 | tABORT { abort(); }
126 | tBACKTRACE { stack_backtrace(dbg_curr_tid); }
127 | tBACKTRACE tNUM { stack_backtrace($2); }
128 | tBACKTRACE tALL { stack_backtrace(-1); }
129 | tUP { stack_set_frame(dbg_curr_thread->curr_frame + 1); }
130 | tUP tNUM { stack_set_frame(dbg_curr_thread->curr_frame + $2); }
131 | tDOWN { stack_set_frame(dbg_curr_thread->curr_frame - 1); }
132 | tDOWN tNUM { stack_set_frame(dbg_curr_thread->curr_frame - $2); }
133 | tFRAME tNUM { stack_set_frame($2); }
134 | tSHOW tDIR { source_show_path(); }
135 | tDIR pathname { source_add_path($2); }
136 | tDIR { source_nuke_path(dbg_curr_process); }
137 | tCOND tNUM { break_add_condition($2, NULL); }
138 | tCOND tNUM expr { break_add_condition($2, $3); }
139 | tSOURCE pathname { parser($2); }
140 | tSYMBOLFILE pathname { symbol_read_symtable($2, 0); }
141 | tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); }
142 | tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE, NULL); dbg_printf("\n"); }
143 | tATTACH tNUM { dbg_attach_debuggee($2); dbg_active_wait_for_first_exception(); }
144 | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
145 | tTHREAD tNUM { dbg_set_curr_thread($2); }
146 | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); }
147 | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
148 | tECHO tSTRING { dbg_printf("%s\n", $2); }
149 | run_command
150 | list_command
151 | disassemble_command
152 | set_command
153 | x_command
154 | print_command
155 | break_command
156 | watch_command
157 | display_command
158 | info_command
159 | maintenance_command
160 | noprocess_state
163 pathname:
164 identifier { $$ = $1; }
165 | tSTRING { $$ = $1; }
166 | tPATH { $$ = $1; }
169 identifier:
170 tIDENTIFIER { $$ = $1; }
173 list_arg:
174 tNUM { $$.FileName = NULL; $$.LineNumber = $1; }
175 | pathname ':' tNUM { $$.FileName = $1; $$.LineNumber = $3; }
176 | identifier { symbol_get_line(NULL, $1, &$$); }
177 | pathname ':' identifier { symbol_get_line($1, $3, &$$); }
178 | '*' expr_lvalue { DWORD disp; ADDRESS64 addr; $$.SizeOfStruct = sizeof($$);
179 types_extract_as_address(&$2, &addr);
180 SymGetLineFromAddr64(dbg_curr_process->handle, (ULONG_PTR)memory_to_linear_addr(& addr), &disp, & $$); }
183 run_command:
184 tRUN list_of_words { dbg_run_debuggee($2); }
187 list_of_words:
188 %empty { $$ = NULL; }
189 | tSTRING list_of_words { $$ = (struct list_string*)lexeme_alloc_size(sizeof(*$$)); $$->next = $2; $$->string = $1; }
192 list_command:
193 tLIST { source_list(NULL, NULL, 10); }
194 | tLIST '-' { source_list(NULL, NULL, -10); }
195 | tLIST list_arg { source_list(& $2, NULL, 10); }
196 | tLIST ',' list_arg { source_list(NULL, & $3, -10); }
197 | tLIST list_arg ',' list_arg { source_list(& $2, & $4, 0); }
200 disassemble_command:
201 tDISASSEMBLE { memory_disassemble(NULL, NULL, 10); }
202 | tDISASSEMBLE expr_lvalue { memory_disassemble(&$2, NULL, 10); }
203 | tDISASSEMBLE expr_lvalue ',' expr_lvalue { memory_disassemble(&$2, &$4, 0); }
206 set_command:
207 tSET lvalue_addr '=' expr_lvalue { types_store_value(&$2, &$4); }
208 | tSET '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, NULL, $3); }
209 | tSET '+' tALL { info_wine_dbg_channel(TRUE, NULL, "all"); }
210 | tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
211 | tSET '-' tALL { info_wine_dbg_channel(FALSE, NULL, "all"); }
212 | tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
213 | tSET tIDENTIFIER '+' tALL { info_wine_dbg_channel(TRUE, $2, "all"); }
214 | tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
215 | tSET tIDENTIFIER '-' tALL { info_wine_dbg_channel(FALSE, $2, "all"); }
216 | tSET '!' tIDENTIFIER tIDENTIFIER { dbg_set_option($3, $4); }
217 | tSET '!' tIDENTIFIER { dbg_set_option($3, NULL); }
220 x_command:
221 tEXAM expr_lvalue { memory_examine(&$2, 1, 'x'); }
222 | tEXAM tFORMAT expr_lvalue { memory_examine(&$3, $2 >> 8, $2 & 0xff); }
225 print_command:
226 tPRINT expr_lvalue { print_value(&$2, 0, 0); }
227 | tPRINT tFORMAT expr_lvalue { if (($2 >> 8) == 1) print_value(&$3, $2 & 0xff, 0); else dbg_printf("Count is meaningless in print command\n"); }
228 | tPRINT type_expr { types_print_type(&$2, TRUE, NULL); dbg_printf("\n"); }
231 break_command:
232 tBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, TRUE); }
233 | tBREAK identifier { break_add_break_from_id($2, -1, TRUE); }
234 | tBREAK pathname ':' tNUM { break_add_break_from_lineno($2, $4, TRUE); }
235 | tBREAK tNUM { break_add_break_from_lineno(NULL, $2, TRUE); }
236 | tBREAK { break_add_break_from_lineno(NULL, -1, TRUE); }
237 | tHBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, FALSE); }
238 | tHBREAK identifier { break_add_break_from_id($2, -1, FALSE); }
239 | tHBREAK pathname ':' tNUM { break_add_break_from_lineno($2, $4, FALSE); }
240 | tHBREAK tNUM { break_add_break_from_lineno(NULL, $2, FALSE); }
241 | tHBREAK { break_add_break_from_lineno(NULL, -1, FALSE); }
242 | tENABLE tNUM { break_enable_xpoint($2, TRUE); }
243 | tENABLE tBREAK tNUM { break_enable_xpoint($3, TRUE); }
244 | tDISABLE tNUM { break_enable_xpoint($2, FALSE); }
245 | tDISABLE tBREAK tNUM { break_enable_xpoint($3, FALSE); }
246 | tDELETE tNUM { break_delete_xpoint($2); }
247 | tDELETE tBREAK tNUM { break_delete_xpoint($3); }
250 watch_command:
251 tWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3, TRUE); }
252 | tWATCH identifier { break_add_watch_from_id($2, TRUE); }
253 | tRWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3, FALSE); }
254 | tRWATCH identifier { break_add_watch_from_id($2, FALSE); }
258 display_command:
259 tDISPLAY { display_print(); }
260 | tDISPLAY expr { display_add($2, 1, 0); }
261 | tDISPLAY tFORMAT expr { display_add($3, $2 >> 8, $2 & 0xff); }
262 | tENABLE tDISPLAY tNUM { display_enable($3, TRUE); }
263 | tDISABLE tDISPLAY tNUM { display_enable($3, FALSE); }
264 | tDELETE tDISPLAY tNUM { display_delete($3); }
265 | tDELETE tDISPLAY { display_delete(-1); }
266 | tUNDISPLAY tNUM { display_delete($2); }
267 | tUNDISPLAY { display_delete(-1); }
270 info_command:
271 tINFO tBREAK { break_info(); }
272 | tINFO tSHARE { info_win32_module(0, FALSE); }
273 | tINFO tWOW tSHARE { info_win32_module(0, TRUE); }
274 | tINFO tSHARE expr_rvalue { info_win32_module($3, FALSE); }
275 | tINFO tREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); }
276 | tINFO tALLREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); }
277 | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); }
278 | tINFO tSEGMENTS { info_win32_segments(0, -1); }
279 | tINFO tSTACK tNUM { stack_info($3); }
280 | tINFO tSTACK { stack_info(-1); }
281 | tINFO tSYMBOL tSTRING { symbol_info($3); }
282 | tINFO tLOCAL { symbol_info_locals(); }
283 | tINFO tDISPLAY { display_info(); }
284 | tINFO tCLASS { info_win32_class(NULL, NULL); }
285 | tINFO tCLASS tSTRING { info_win32_class(NULL, $3); }
286 | tINFO tWND { info_win32_window(NULL, FALSE); }
287 | tINFO tWND expr_rvalue { info_win32_window((HWND)(DWORD_PTR)$3, FALSE); }
288 | tINFO '*' tWND { info_win32_window(NULL, TRUE); }
289 | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)(DWORD_PTR)$4, TRUE); }
290 | tINFO tPROCESS { info_win32_processes(); }
291 | tINFO tTHREAD { info_win32_threads(); }
292 | tINFO tFRAME { info_win32_frame_exceptions(dbg_curr_tid); }
293 | tINFO tFRAME expr_rvalue { info_win32_frame_exceptions($3); }
294 | tINFO tMAPS { info_win32_virtual(dbg_curr_pid); }
295 | tINFO tMAPS expr_rvalue { info_win32_virtual($3); }
296 | tINFO tEXCEPTION { info_win32_exception(); }
299 maintenance_command:
300 tMAINTENANCE tTYPE { print_types(); }
301 | tMAINTENANCE tMODULE tSTRING { tgt_module_load($3, FALSE); }
302 | tMAINTENANCE '*' tMODULE tSTRING { tgt_module_load($4, TRUE); }
305 noprocess_state:
306 tNOPROCESS {} /* <CR> shall not barf anything */
307 | tNOPROCESS tBACKTRACE tALL { stack_backtrace(-1); } /* can backtrace all threads with no attached process */
308 | tNOPROCESS tSTRING { dbg_printf("No process loaded, cannot execute '%s'\n", $2); }
311 type_expr:
312 tVOID { if (!types_find_basic(L"void", $1, &$$)) YYERROR; }
313 | tCHAR { if (!types_find_basic(L"char", $1, &$$)) YYERROR; }
314 | tWCHAR { if (!types_find_basic(L"WCHAR", $1, &$$)) YYERROR; }
315 | tSIGNED tCHAR { if (!types_find_basic(L"signed char", $1, &$$)) YYERROR; }
316 | tUNSIGNED tCHAR { if (!types_find_basic(L"unsigned char", $1, &$$)) YYERROR; }
317 | tSHORT tINT { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
318 | tSHORT { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
319 | tSIGNED tSHORT tINT { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
320 | tSIGNED tSHORT { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
321 | tSHORT tSIGNED tINT { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
322 | tSHORT tSIGNED { if (!types_find_basic(L"short int", $1, &$$)) YYERROR; }
323 | tSHORT tUNSIGNED { if (!types_find_basic(L"unsigned short int", $1, &$$)) YYERROR; }
324 | tSHORT tUNSIGNED tINT { if (!types_find_basic(L"unsigned short int", $1, &$$)) YYERROR; }
325 | tUNSIGNED tSHORT { if (!types_find_basic(L"unsigned short int", $1, &$$)) YYERROR; }
326 | tUNSIGNED tSHORT tINT { if (!types_find_basic(L"unsigned short int", $1, &$$)) YYERROR; }
327 | tINT { if (!types_find_basic(L"int", $1, &$$)) YYERROR; }
328 | tSIGNED tINT { if (!types_find_basic(L"int", $1, &$$)) YYERROR; }
329 | tUNSIGNED { if (!types_find_basic(L"unsigned int", $1, &$$)) YYERROR; }
330 | tUNSIGNED tINT { if (!types_find_basic(L"unsigned int", $1, &$$)) YYERROR; }
331 | tLONG { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
332 | tLONG tINT { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
333 | tSIGNED tLONG { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
334 | tSIGNED tLONG tINT { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
335 | tLONG tSIGNED { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
336 | tLONG tSIGNED tINT { if (!types_find_basic(L"long int", $1, &$$)) YYERROR; }
337 | tLONG tUNSIGNED { if (!types_find_basic(L"unsigned long int", $1, &$$)) YYERROR; }
338 | tLONG tUNSIGNED tINT { if (!types_find_basic(L"unsigned long int", $1, &$$)) YYERROR; }
339 | tUNSIGNED tLONG { if (!types_find_basic(L"unsigned long int", $1, &$$)) YYERROR; }
340 | tUNSIGNED tLONG tINT { if (!types_find_basic(L"unsigned long int", $1, &$$)) YYERROR; }
341 | tLONG tLONG { if (!types_find_basic(L"long long int", $1, &$$)) YYERROR; }
342 | tLONG tLONG tINT { if (!types_find_basic(L"long long int", $1, &$$)) YYERROR; }
343 | tSIGNED tLONG tLONG { if (!types_find_basic(L"long long int", $1, &$$)) YYERROR; }
344 | tSIGNED tLONG tLONG tINT { if (!types_find_basic(L"long long int", $1, &$$)) YYERROR; }
345 | tUNSIGNED tLONG tLONG { if (!types_find_basic(L"unsigned long long int", $1, &$$)) YYERROR; }
346 | tUNSIGNED tLONG tLONG tINT{ if (!types_find_basic(L"unsigned long long int", $1, &$$)) YYERROR; }
347 | tLONG tLONG tUNSIGNED { if (!types_find_basic(L"unsigned long long int", $1, &$$)) YYERROR; }
348 | tLONG tLONG tUNSIGNED tINT{ if (!types_find_basic(L"unsigned long long int", $1, &$$)) YYERROR; }
349 | tFLOAT { if (!types_find_basic(L"float", $1, &$$)) YYERROR; }
350 | tDOUBLE { if (!types_find_basic(L"double", $1, &$$)) YYERROR; }
351 | tLONG tDOUBLE { if (!types_find_basic(L"long double", $1, &$$)) YYERROR; }
352 | tTYPEDEF { $$ = $1; }
353 | type_expr '*' { if (!types_find_pointer(&$1, &$$)) {yyerror("Cannot find pointer type\n"); YYERROR; } }
354 | tCLASS identifier { if (!types_find_type($2, SymTagUDT, &$$)) {yyerror("Unknown type\n"); YYERROR; } }
355 | tSTRUCT identifier { if (!types_find_type($2, SymTagUDT, &$$)) {yyerror("Unknown type\n"); YYERROR; } }
356 | tUNION identifier { if (!types_find_type($2, SymTagUDT, &$$)) {yyerror("Unknown type\n"); YYERROR; } }
357 | tENUM identifier { if (!types_find_type($2, SymTagEnum, &$$)) {yyerror("Unknown type\n"); YYERROR; } }
360 expr_lvalue:
361 expr { $$ = expr_eval($1); }
364 expr_rvalue:
365 expr_lvalue { $$ = types_extract_as_integer(&$1); }
369 * The expr rule builds an expression tree. When we are done, we call
370 * EvalExpr to evaluate the value of the expression. The advantage of
371 * the two-step approach is that it is possible to save expressions for
372 * use in 'display' commands, and in conditional watchpoints.
374 expr:
375 tNUM { $$ = expr_alloc_sconstant($1); }
376 | tSTRING { $$ = expr_alloc_string($1); }
377 | tINTVAR { $$ = expr_alloc_internal_var($1); }
378 | identifier { $$ = expr_alloc_symbol($1); }
379 | expr OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
380 | expr '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
381 | identifier '(' ')' { $$ = expr_alloc_func_call($1, 0); }
382 | identifier '(' expr ')' { $$ = expr_alloc_func_call($1, 1, $3); }
383 | identifier '(' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 2, $3, $5); }
384 | identifier '(' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 3, $3, $5, $7); }
385 | identifier '(' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 4, $3, $5, $7, $9); }
386 | identifier '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 5, $3, $5, $7, $9, $11); }
387 | expr '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
388 | expr ':' expr { $$ = expr_alloc_binary_op(EXP_OP_SEG, $1, $3); }
389 | expr OP_LOR expr { $$ = expr_alloc_binary_op(EXP_OP_LOR, $1, $3); }
390 | expr OP_LAND expr { $$ = expr_alloc_binary_op(EXP_OP_LAND, $1, $3); }
391 | expr '|' expr { $$ = expr_alloc_binary_op(EXP_OP_OR, $1, $3); }
392 | expr '&' expr { $$ = expr_alloc_binary_op(EXP_OP_AND, $1, $3); }
393 | expr '^' expr { $$ = expr_alloc_binary_op(EXP_OP_XOR, $1, $3); }
394 | expr OP_EQ expr { $$ = expr_alloc_binary_op(EXP_OP_EQ, $1, $3); }
395 | expr '>' expr { $$ = expr_alloc_binary_op(EXP_OP_GT, $1, $3); }
396 | expr '<' expr { $$ = expr_alloc_binary_op(EXP_OP_LT, $1, $3); }
397 | expr OP_GE expr { $$ = expr_alloc_binary_op(EXP_OP_GE, $1, $3); }
398 | expr OP_LE expr { $$ = expr_alloc_binary_op(EXP_OP_LE, $1, $3); }
399 | expr OP_NE expr { $$ = expr_alloc_binary_op(EXP_OP_NE, $1, $3); }
400 | expr OP_SHL expr { $$ = expr_alloc_binary_op(EXP_OP_SHL, $1, $3); }
401 | expr OP_SHR expr { $$ = expr_alloc_binary_op(EXP_OP_SHR, $1, $3); }
402 | expr '+' expr { $$ = expr_alloc_binary_op(EXP_OP_ADD, $1, $3); }
403 | expr '-' expr { $$ = expr_alloc_binary_op(EXP_OP_SUB, $1, $3); }
404 | expr '*' expr { $$ = expr_alloc_binary_op(EXP_OP_MUL, $1, $3); }
405 | expr '/' expr { $$ = expr_alloc_binary_op(EXP_OP_DIV, $1, $3); }
406 | expr '%' expr { $$ = expr_alloc_binary_op(EXP_OP_REM, $1, $3); }
407 | '-' expr %prec OP_SIGN { $$ = expr_alloc_unary_op(EXP_OP_NEG, $2); }
408 | '+' expr %prec OP_SIGN { $$ = $2; }
409 | '!' expr { $$ = expr_alloc_unary_op(EXP_OP_NOT, $2); }
410 | '~' expr { $$ = expr_alloc_unary_op(EXP_OP_LNOT, $2); }
411 | '(' expr ')' { $$ = $2; }
412 | '*' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
413 | '&' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_ADDR, $2); }
414 | '(' type_expr ')' expr %prec OP_DEREF { $$ = expr_alloc_typecast(&$2, $4); }
418 * The lvalue rule builds an expression tree. This is a limited form
419 * of expression that is suitable to be used as an lvalue.
421 lvalue_addr:
422 lvalue { $$ = expr_eval($1); }
425 lvalue:
426 tNUM { $$ = expr_alloc_sconstant($1); }
427 | tINTVAR { $$ = expr_alloc_internal_var($1); }
428 | identifier { $$ = expr_alloc_symbol($1); }
429 | lvalue OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
430 | lvalue '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
431 | lvalue '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
432 | '*' expr { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
437 static LONG WINAPI wine_dbg_cmd(EXCEPTION_POINTERS *eptr)
439 switch (eptr->ExceptionRecord->ExceptionCode)
441 case DEBUG_STATUS_INTERNAL_ERROR:
442 dbg_printf("\nWineDbg internal error\n");
443 break;
444 case DEBUG_STATUS_NO_SYMBOL:
445 dbg_printf("\nUndefined symbol\n");
446 break;
447 case DEBUG_STATUS_DIV_BY_ZERO:
448 dbg_printf("\nDivision by zero\n");
449 break;
450 case DEBUG_STATUS_BAD_TYPE:
451 dbg_printf("\nNo type or type mismatch\n");
452 break;
453 case DEBUG_STATUS_NO_FIELD:
454 dbg_printf("\nNo such field in structure or union\n");
455 break;
456 case DEBUG_STATUS_CANT_DEREF:
457 dbg_printf("\nDereference failed (not a pointer, or out of array bounds)\n");
458 break;
459 case DEBUG_STATUS_ABORT:
460 break;
461 case DEBUG_STATUS_NOT_AN_INTEGER:
462 dbg_printf("\nNeeding an integral value\n");
463 break;
464 case CONTROL_C_EXIT:
465 /* this is generally sent by a ctrl-c when we run winedbg outside of wineconsole */
466 /* stop the debuggee, and continue debugger execution, we will be reentered by the
467 * debug events generated by stopping
469 dbg_interrupt_debuggee();
470 return EXCEPTION_CONTINUE_EXECUTION;
471 default:
472 dbg_printf("\nException %lx\n", eptr->ExceptionRecord->ExceptionCode);
473 break;
476 return EXCEPTION_EXECUTE_HANDLER;
479 struct parser_context
481 const char* filename;
482 HANDLE input;
483 HANDLE output;
484 unsigned line_no;
485 char* last_line;
486 size_t last_line_idx;
489 static struct parser_context dbg_parser = {NULL, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, NULL, 0};
491 static int input_fetch_entire_line(const char* pfx, char** line)
493 char* buffer;
494 char ch;
495 DWORD nread;
496 size_t len, alloc;
498 /* as of today, console handles can be file handles... so better use file APIs rather than
499 * console's
501 WriteFile(dbg_parser.output, pfx, strlen(pfx), &nread, NULL);
503 buffer = malloc(alloc = 16);
504 assert(buffer != NULL);
506 dbg_parser.line_no++;
507 len = 0;
510 if (!ReadFile(dbg_parser.input, &ch, 1, &nread, NULL) || nread == 0)
512 free(buffer);
513 return -1;
516 if (len + 2 > alloc)
518 char* new;
519 while (len + 2 > alloc) alloc *= 2;
520 if (!(new = realloc(buffer, alloc)))
522 free(buffer);
523 return -1;
525 buffer = new;
527 buffer[len++] = ch;
529 while (ch != '\n');
530 buffer[len] = '\0';
532 *line = buffer;
533 return len;
536 size_t input_lex_read_buffer(char* buf, int size)
538 int len;
540 /* try first to fetch the remaining of an existing line */
541 if (dbg_parser.last_line_idx == 0)
543 char* tmp = NULL;
544 /* no remaining chars to be read from last line, grab a brand new line up to '\n' */
545 lexeme_flush();
546 len = input_fetch_entire_line("Wine-dbg>", &tmp);
547 if (len < 0) return 0; /* eof */
549 /* remove carriage return in newline */
550 if (len >= 2 && tmp[len - 2] == '\r')
552 tmp[len - 2] = '\n';
553 tmp[len - 1] = '\0';
554 len--;
557 /* recall last command when empty input buffer and not parsing a file */
558 if (dbg_parser.last_line && (len == 0 || (len == 1 && tmp[0] == '\n')) &&
559 dbg_parser.output != INVALID_HANDLE_VALUE)
561 free(tmp);
563 else
565 free(dbg_parser.last_line);
566 dbg_parser.last_line = tmp;
570 len = min(strlen(dbg_parser.last_line + dbg_parser.last_line_idx), size - 1);
571 memcpy(buf, dbg_parser.last_line + dbg_parser.last_line_idx, len);
572 buf[len] = '\0';
573 if ((dbg_parser.last_line_idx += len) >= strlen(dbg_parser.last_line))
574 dbg_parser.last_line_idx = 0;
575 return len;
578 int input_read_line(const char* pfx, char* buf, int size)
580 char* line = NULL;
582 int len = input_fetch_entire_line(pfx, &line);
583 if (len < 0) return 0;
584 /* remove trailing \n and \r */
585 while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) len--;
586 len = min(size - 1, len);
587 memcpy(buf, line, len);
588 buf[len] = '\0';
589 free(line);
590 return 1;
593 /***********************************************************************
594 * parser_handle
596 * Debugger command line parser
598 void parser_handle(const char* filename, HANDLE input)
600 BOOL ret_ok;
601 struct parser_context prev = dbg_parser;
603 ret_ok = FALSE;
605 if (input != INVALID_HANDLE_VALUE)
607 dbg_parser.output = INVALID_HANDLE_VALUE;
608 dbg_parser.input = input;
610 else
612 dbg_parser.output = GetStdHandle(STD_OUTPUT_HANDLE);
613 dbg_parser.input = GetStdHandle(STD_INPUT_HANDLE);
615 dbg_parser.line_no = 0;
616 dbg_parser.filename = filename;
617 dbg_parser.last_line = NULL;
618 dbg_parser.last_line_idx = 0;
621 __TRY
623 ret_ok = TRUE;
624 dbg_parse();
626 __EXCEPT(wine_dbg_cmd)
628 ret_ok = FALSE;
630 __ENDTRY;
631 lexeme_flush();
632 } while (!ret_ok);
634 dbg_parser = prev;
637 static void parser(const char* filename)
639 HANDLE h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
640 if (h != INVALID_HANDLE_VALUE)
642 parser_handle(filename, h);
643 CloseHandle(h);
647 static int dbg_error(const char* s)
649 if (dbg_parser.filename)
650 dbg_printf("%s:%d:", dbg_parser.filename, dbg_parser.line_no);
651 dbg_printf("%s\n", s);
652 return 0;
655 HANDLE WINAPIV parser_generate_command_file(const char* pmt, ...)
657 HANDLE hFile;
658 char path[MAX_PATH], file[MAX_PATH];
659 DWORD w;
660 const char* p;
662 GetTempPathA(sizeof(path), path);
663 GetTempFileNameA(path, "WD", 0, file);
664 hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
665 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
666 if (hFile != INVALID_HANDLE_VALUE)
668 va_list ap;
670 WriteFile(hFile, pmt, strlen(pmt), &w, 0);
671 va_start(ap, pmt);
672 while ((p = va_arg(ap, const char*)) != NULL)
674 WriteFile(hFile, "\n", 1, &w, 0);
675 WriteFile(hFile, p, strlen(p), &w, 0);
677 va_end(ap);
678 WriteFile(hFile, "\nquit\n", 6, &w, 0);
679 SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
681 return hFile;