mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / programs / winedbg / dbg.y
blobac76b5baf8a255d59b4742368fdb036918c78bdb
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 "config.h"
25 #include "wine/port.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include "debugger.h"
32 #include "wine/exception.h"
33 #include "expr.h"
35 int dbg_lex(void);
36 static int dbg_error(const char*);
37 static void parser(const char*);
41 %union
43 struct dbg_lvalue lvalue;
44 char* string;
45 INT_PTR integer;
46 IMAGEHLP_LINE64 listing;
47 struct expr* expression;
48 struct type_expr_t type;
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 tSYMBOLFILE tRUN tATTACH tDETACH tKILL tMAINTENANCE tTYPE tMINIDUMP
61 %token tNOPROCESS
63 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
64 %token tSTRUCT tUNION tENUM
66 /* %left ',' */
67 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
68 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
69 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
70 /* %left OP_COND */ /* ... ? ... : ... */
71 %left OP_LOR
72 %left OP_LAND
73 %left '|'
74 %left '^'
75 %left '&'
76 %left OP_EQ OP_NE
77 %left '<' '>' OP_LE OP_GE
78 %left OP_SHL OP_SHR
79 %left '+' '-'
80 %left '*' '/' '%'
81 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
82 %left '.' '[' OP_DRF OP_SCOPE
83 %nonassoc ':'
85 %type <expression> expr lvalue
86 %type <lvalue> expr_lvalue lvalue_addr
87 %type <integer> expr_rvalue
88 %type <string> pathname identifier cpp_identifier
89 %type <listing> list_arg
90 %type <type> type_expr
94 input:
95 line
96 | input line
99 line:
100 command tEOL { expr_free_all(); }
101 | tEOL
102 | tEOF { return 1; }
103 | error tEOL { yyerrok; expr_free_all(); }
106 command:
107 tQUIT { return 1; }
108 | tHELP { print_help(); }
109 | tHELP tINFO { info_help(); }
110 | tPASS { dbg_wait_next_exception(DBG_EXCEPTION_NOT_HANDLED, 0, 0); }
111 | tCONT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_cont); }
112 | tCONT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_cont); }
113 | tSTEP { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_line); }
114 | tSTEP tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_line); }
115 | tNEXT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_line); }
116 | tNEXT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_line); }
117 | tSTEPI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_insn); }
118 | tSTEPI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_insn); }
119 | tNEXTI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_insn); }
120 | tNEXTI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_insn); }
121 | tFINISH { dbg_wait_next_exception(DBG_CONTINUE, 0, dbg_exec_finish); }
122 | tABORT { abort(); }
123 | tBACKTRACE { stack_backtrace(dbg_curr_tid); }
124 | tBACKTRACE tNUM { stack_backtrace($2); }
125 | tBACKTRACE tALL { stack_backtrace(-1); }
126 | tUP { stack_set_frame(dbg_curr_thread->curr_frame + 1); }
127 | tUP tNUM { stack_set_frame(dbg_curr_thread->curr_frame + $2); }
128 | tDOWN { stack_set_frame(dbg_curr_thread->curr_frame - 1); }
129 | tDOWN tNUM { stack_set_frame(dbg_curr_thread->curr_frame - $2); }
130 | tFRAME tNUM { stack_set_frame($2); }
131 | tSHOW tDIR { source_show_path(); }
132 | tDIR pathname { source_add_path($2); }
133 | tDIR { source_nuke_path(dbg_curr_process); }
134 | tCOND tNUM { break_add_condition($2, NULL); }
135 | tCOND tNUM expr { break_add_condition($2, $3); }
136 | tSOURCE pathname { parser($2); }
137 | tSYMBOLFILE pathname { symbol_read_symtable($2, 0); }
138 | tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); }
139 | tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE); dbg_printf("\n"); }
140 | tATTACH tNUM { dbg_attach_debuggee($2); dbg_active_wait_for_first_exception(); }
141 | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
142 | tTHREAD tNUM { dbg_set_curr_thread($2); }
143 | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); }
144 | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
145 | tECHO tSTRING { dbg_printf("%s\n", $2); }
146 | run_command
147 | list_command
148 | disassemble_command
149 | set_command
150 | x_command
151 | print_command
152 | break_command
153 | watch_command
154 | display_command
155 | info_command
156 | maintenance_command
157 | noprocess_state
160 pathname:
161 identifier { $$ = $1; }
162 | tSTRING { $$ = $1; }
163 | tPATH { $$ = $1; }
166 cpp_identifier:
167 tIDENTIFIER { $$ = $1; }
168 | identifier OP_SCOPE tIDENTIFIER { $$ = lexeme_alloc_size(strlen($1) + 2 + strlen($3) + 1);
169 sprintf($$, "%s::%s", $1, $3); }
172 identifier:
173 cpp_identifier { $$ = $1; }
174 | tIDENTIFIER '!' cpp_identifier { $$ = lexeme_alloc_size(strlen($1) + 1 + strlen($3) + 1);
175 sprintf($$, "%s!%s", $1, $3); }
178 list_arg:
179 tNUM { $$.FileName = NULL; $$.LineNumber = $1; }
180 | pathname ':' tNUM { $$.FileName = $1; $$.LineNumber = $3; }
181 | identifier { symbol_get_line(NULL, $1, &$$); }
182 | pathname ':' identifier { symbol_get_line($1, $3, &$$); }
183 | '*' expr_lvalue { DWORD disp; ADDRESS64 addr; $$.SizeOfStruct = sizeof($$);
184 types_extract_as_address(&$2, &addr);
185 SymGetLineFromAddr64(dbg_curr_process->handle, (ULONG_PTR)memory_to_linear_addr(& addr), &disp, & $$); }
188 run_command:
189 tRUN { dbg_run_debuggee(NULL); }
190 | tRUN tSTRING { dbg_run_debuggee($2); }
193 list_command:
194 tLIST { source_list(NULL, NULL, 10); }
195 | tLIST '-' { source_list(NULL, NULL, -10); }
196 | tLIST list_arg { source_list(& $2, NULL, 10); }
197 | tLIST ',' list_arg { source_list(NULL, & $3, -10); }
198 | tLIST list_arg ',' list_arg { source_list(& $2, & $4, 0); }
201 disassemble_command:
202 tDISASSEMBLE { memory_disassemble(NULL, NULL, 10); }
203 | tDISASSEMBLE expr_lvalue { memory_disassemble(&$2, NULL, 10); }
204 | tDISASSEMBLE expr_lvalue ',' expr_lvalue { memory_disassemble(&$2, &$4, 0); }
207 set_command:
208 tSET lvalue_addr '=' expr_lvalue { types_store_value(&$2, &$4); }
209 | tSET '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, NULL, $3); }
210 | tSET '+' tALL { info_wine_dbg_channel(TRUE, NULL, "all"); }
211 | tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
212 | tSET '-' tALL { info_wine_dbg_channel(FALSE, NULL, "all"); }
213 | tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
214 | tSET tIDENTIFIER '+' tALL { info_wine_dbg_channel(TRUE, $2, "all"); }
215 | tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
216 | tSET tIDENTIFIER '-' tALL { info_wine_dbg_channel(FALSE, $2, "all"); }
217 | tSET '!' tIDENTIFIER tIDENTIFIER { dbg_set_option($3, $4); }
218 | tSET '!' tIDENTIFIER { dbg_set_option($3, NULL); }
221 x_command:
222 tEXAM expr_lvalue { memory_examine(&$2, 1, 'x'); }
223 | tEXAM tFORMAT expr_lvalue { memory_examine(&$3, $2 >> 8, $2 & 0xff); }
226 print_command:
227 tPRINT expr_lvalue { print_value(&$2, 0, 0); }
228 | tPRINT tFORMAT expr_lvalue { if (($2 >> 8) == 1) print_value(&$3, $2 & 0xff, 0); else dbg_printf("Count is meaningless in print command\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); }
273 | tINFO tSHARE expr_rvalue { info_win32_module($3); }
274 | tINFO tREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); }
275 | tINFO tALLREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); }
276 | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); }
277 | tINFO tSEGMENTS { info_win32_segments(0, -1); }
278 | tINFO tSTACK tNUM { stack_info($3); }
279 | tINFO tSTACK { stack_info(-1); }
280 | tINFO tSYMBOL tSTRING { symbol_info($3); }
281 | tINFO tLOCAL { symbol_info_locals(); }
282 | tINFO tDISPLAY { display_info(); }
283 | tINFO tCLASS { info_win32_class(NULL, NULL); }
284 | tINFO tCLASS tSTRING { info_win32_class(NULL, $3); }
285 | tINFO tWND { info_win32_window(NULL, FALSE); }
286 | tINFO tWND expr_rvalue { info_win32_window((HWND)$3, FALSE); }
287 | tINFO '*' tWND { info_win32_window(NULL, TRUE); }
288 | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)$4, TRUE); }
289 | tINFO tPROCESS { info_win32_processes(); }
290 | tINFO tTHREAD { info_win32_threads(); }
291 | tINFO tFRAME { info_win32_frame_exceptions(dbg_curr_tid); }
292 | tINFO tFRAME expr_rvalue { info_win32_frame_exceptions($3); }
293 | tINFO tMAPS { info_win32_virtual(dbg_curr_pid); }
294 | tINFO tMAPS expr_rvalue { info_win32_virtual($3); }
295 | tINFO tEXCEPTION { info_win32_exception(); }
298 maintenance_command:
299 tMAINTENANCE tTYPE { print_types(); }
300 | tMAINTENANCE tMODULE tSTRING { tgt_module_load($3, FALSE); }
301 | tMAINTENANCE '*' tMODULE tSTRING { tgt_module_load($4, TRUE); }
304 noprocess_state:
305 tNOPROCESS {} /* <CR> shall not barf anything */
306 | tNOPROCESS tBACKTRACE tALL { stack_backtrace(-1); } /* can backtrace all threads with no attached process */
307 | tNOPROCESS tSTRING { dbg_printf("No process loaded, cannot execute '%s'\n", $2); }
310 type_expr:
311 tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_char; }
312 | tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_int; }
313 | tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
314 | tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
315 | tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
316 | tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
317 | tLONG tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
318 | tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
319 | tSHORT tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
320 | tSHORT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
321 | tSHORT tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
322 | tSHORT tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
323 | tSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_char_int; }
324 | tUNSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_char_int; }
325 | tLONG tLONG tUNSIGNED tINT{ $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
326 | tLONG tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
327 | tLONG tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
328 | tLONG tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
329 | tFLOAT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_short_real; }
330 | tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_real; }
331 | tLONG tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_long_real; }
332 | type_expr '*' { $$ = $1; $$.deref_count++; }
333 | tCLASS identifier { $$.type = type_expr_udt_class; $$.deref_count = 0; $$.u.name = $2; }
334 | tSTRUCT identifier { $$.type = type_expr_udt_struct; $$.deref_count = 0; $$.u.name = $2; }
335 | tUNION identifier { $$.type = type_expr_udt_union; $$.deref_count = 0; $$.u.name = $2; }
336 | tENUM identifier { $$.type = type_expr_enumeration; $$.deref_count = 0; $$.u.name = $2; }
339 expr_lvalue:
340 expr { $$ = expr_eval($1); }
343 expr_rvalue:
344 expr_lvalue { $$ = types_extract_as_integer(&$1); }
348 * The expr rule builds an expression tree. When we are done, we call
349 * EvalExpr to evaluate the value of the expression. The advantage of
350 * the two-step approach is that it is possible to save expressions for
351 * use in 'display' commands, and in conditional watchpoints.
353 expr:
354 tNUM { $$ = expr_alloc_sconstant($1); }
355 | tSTRING { $$ = expr_alloc_string($1); }
356 | tINTVAR { $$ = expr_alloc_internal_var($1); }
357 | identifier { $$ = expr_alloc_symbol($1); }
358 | expr OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
359 | expr '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
360 | identifier '(' ')' { $$ = expr_alloc_func_call($1, 0); }
361 | identifier '(' expr ')' { $$ = expr_alloc_func_call($1, 1, $3); }
362 | identifier '(' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 2, $3, $5); }
363 | identifier '(' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 3, $3, $5, $7); }
364 | identifier '(' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 4, $3, $5, $7, $9); }
365 | identifier '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 5, $3, $5, $7, $9, $11); }
366 | expr '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
367 | expr ':' expr { $$ = expr_alloc_binary_op(EXP_OP_SEG, $1, $3); }
368 | expr OP_LOR expr { $$ = expr_alloc_binary_op(EXP_OP_LOR, $1, $3); }
369 | expr OP_LAND expr { $$ = expr_alloc_binary_op(EXP_OP_LAND, $1, $3); }
370 | expr '|' expr { $$ = expr_alloc_binary_op(EXP_OP_OR, $1, $3); }
371 | expr '&' expr { $$ = expr_alloc_binary_op(EXP_OP_AND, $1, $3); }
372 | expr '^' expr { $$ = expr_alloc_binary_op(EXP_OP_XOR, $1, $3); }
373 | expr OP_EQ expr { $$ = expr_alloc_binary_op(EXP_OP_EQ, $1, $3); }
374 | expr '>' expr { $$ = expr_alloc_binary_op(EXP_OP_GT, $1, $3); }
375 | expr '<' expr { $$ = expr_alloc_binary_op(EXP_OP_LT, $1, $3); }
376 | expr OP_GE expr { $$ = expr_alloc_binary_op(EXP_OP_GE, $1, $3); }
377 | expr OP_LE expr { $$ = expr_alloc_binary_op(EXP_OP_LE, $1, $3); }
378 | expr OP_NE expr { $$ = expr_alloc_binary_op(EXP_OP_NE, $1, $3); }
379 | expr OP_SHL expr { $$ = expr_alloc_binary_op(EXP_OP_SHL, $1, $3); }
380 | expr OP_SHR expr { $$ = expr_alloc_binary_op(EXP_OP_SHR, $1, $3); }
381 | expr '+' expr { $$ = expr_alloc_binary_op(EXP_OP_ADD, $1, $3); }
382 | expr '-' expr { $$ = expr_alloc_binary_op(EXP_OP_SUB, $1, $3); }
383 | expr '*' expr { $$ = expr_alloc_binary_op(EXP_OP_MUL, $1, $3); }
384 | expr '/' expr { $$ = expr_alloc_binary_op(EXP_OP_DIV, $1, $3); }
385 | expr '%' expr { $$ = expr_alloc_binary_op(EXP_OP_REM, $1, $3); }
386 | '-' expr %prec OP_SIGN { $$ = expr_alloc_unary_op(EXP_OP_NEG, $2); }
387 | '+' expr %prec OP_SIGN { $$ = $2; }
388 | '!' expr { $$ = expr_alloc_unary_op(EXP_OP_NOT, $2); }
389 | '~' expr { $$ = expr_alloc_unary_op(EXP_OP_LNOT, $2); }
390 | '(' expr ')' { $$ = $2; }
391 | '*' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
392 | '&' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_ADDR, $2); }
393 | '(' type_expr ')' expr %prec OP_DEREF { $$ = expr_alloc_typecast(&$2, $4); }
397 * The lvalue rule builds an expression tree. This is a limited form
398 * of expression that is suitable to be used as an lvalue.
400 lvalue_addr:
401 lvalue { $$ = expr_eval($1); }
404 lvalue:
405 tNUM { $$ = expr_alloc_sconstant($1); }
406 | tINTVAR { $$ = expr_alloc_internal_var($1); }
407 | identifier { $$ = expr_alloc_symbol($1); }
408 | lvalue OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
409 | lvalue '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
410 | lvalue '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
411 | '*' expr { $$ = expr_alloc_unary_op(EXP_OP_FORCE_DEREF, $2); }
416 static LONG WINAPI wine_dbg_cmd(EXCEPTION_POINTERS *eptr)
418 switch (eptr->ExceptionRecord->ExceptionCode)
420 case DEBUG_STATUS_INTERNAL_ERROR:
421 dbg_printf("\nWineDbg internal error\n");
422 break;
423 case DEBUG_STATUS_NO_SYMBOL:
424 dbg_printf("\nUndefined symbol\n");
425 break;
426 case DEBUG_STATUS_DIV_BY_ZERO:
427 dbg_printf("\nDivision by zero\n");
428 break;
429 case DEBUG_STATUS_BAD_TYPE:
430 dbg_printf("\nNo type or type mismatch\n");
431 break;
432 case DEBUG_STATUS_NO_FIELD:
433 dbg_printf("\nNo such field in structure or union\n");
434 break;
435 case DEBUG_STATUS_CANT_DEREF:
436 dbg_printf("\nDereference failed (not a pointer, or out of array bounds)\n");
437 break;
438 case DEBUG_STATUS_ABORT:
439 break;
440 case DEBUG_STATUS_NOT_AN_INTEGER:
441 dbg_printf("\nNeeding an integral value\n");
442 break;
443 case CONTROL_C_EXIT:
444 /* this is generally sent by a ctrl-c when we run winedbg outside of wineconsole */
445 /* stop the debuggee, and continue debugger execution, we will be reentered by the
446 * debug events generated by stopping
448 dbg_interrupt_debuggee();
449 return EXCEPTION_CONTINUE_EXECUTION;
450 default:
451 dbg_printf("\nException %x\n", eptr->ExceptionRecord->ExceptionCode);
452 break;
455 return EXCEPTION_EXECUTE_HANDLER;
458 static HANDLE dbg_parser_input;
459 static HANDLE dbg_parser_output;
461 int input_fetch_entire_line(const char* pfx, char** line)
463 char* buffer;
464 char ch;
465 DWORD nread;
466 size_t len, alloc;
468 /* as of today, console handles can be file handles... so better use file APIs rather than
469 * console's
471 WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
473 buffer = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
474 assert(buffer != NULL);
476 len = 0;
479 if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
481 HeapFree(GetProcessHeap(), 0, buffer);
482 return -1;
485 if (len + 2 > alloc)
487 while (len + 2 > alloc) alloc *= 2;
488 buffer = dbg_heap_realloc(buffer, alloc);
490 buffer[len++] = ch;
492 while (ch != '\n');
493 buffer[len] = '\0';
495 *line = buffer;
496 return len;
499 int input_read_line(const char* pfx, char* buf, int size)
501 char* line = NULL;
503 int len = input_fetch_entire_line(pfx, &line);
504 if (len < 0) return 0;
505 /* remove trailing \n and \r */
506 while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) len--;
507 len = min(size - 1, len);
508 memcpy(buf, line, len);
509 buf[len] = '\0';
510 HeapFree(GetProcessHeap(), 0, line);
511 return 1;
514 /***********************************************************************
515 * parser_handle
517 * Debugger command line parser
519 void parser_handle(HANDLE input)
521 BOOL ret_ok;
522 HANDLE in_copy = dbg_parser_input;
523 HANDLE out_copy = dbg_parser_output;
525 ret_ok = FALSE;
527 if (input != INVALID_HANDLE_VALUE)
529 dbg_parser_output = INVALID_HANDLE_VALUE;
530 dbg_parser_input = input;
532 else
534 dbg_parser_output = GetStdHandle(STD_OUTPUT_HANDLE);
535 dbg_parser_input = GetStdHandle(STD_INPUT_HANDLE);
540 __TRY
542 ret_ok = TRUE;
543 dbg_parse();
545 __EXCEPT(wine_dbg_cmd)
547 ret_ok = FALSE;
549 __ENDTRY;
550 lexeme_flush();
551 } while (!ret_ok);
553 dbg_parser_input = in_copy;
554 dbg_parser_output = out_copy;
557 static void parser(const char* filename)
559 HANDLE h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
560 if (h != INVALID_HANDLE_VALUE)
562 parser_handle(h);
563 CloseHandle(h);
567 static int dbg_error(const char* s)
569 dbg_printf("%s\n", s);
570 return 0;
573 HANDLE parser_generate_command_file(const char* pmt, ...)
575 HANDLE hFile;
576 char path[MAX_PATH], file[MAX_PATH];
577 DWORD w;
578 const char* p;
580 GetTempPathA(sizeof(path), path);
581 GetTempFileNameA(path, "WD", 0, file);
582 hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
583 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
584 if (hFile != INVALID_HANDLE_VALUE)
586 va_list ap;
588 WriteFile(hFile, pmt, strlen(pmt), &w, 0);
589 va_start(ap, pmt);
590 while ((p = va_arg(ap, const char*)) != NULL)
592 WriteFile(hFile, "\n", 1, &w, 0);
593 WriteFile(hFile, p, strlen(p), &w, 0);
595 va_end(ap);
596 WriteFile(hFile, "\nquit\n", 6, &w, 0);
597 SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
599 return hFile;