push 337eb2e2d902d84a5d689451984c5832d7e04fc4
[wine/hacks.git] / programs / winedbg / dbg.y
blob33ca8962c203c9d8aed369842d0f2955284b15da
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>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
34 #include "debugger.h"
35 #include "wine/exception.h"
36 #include "expr.h"
38 int dbg_lex(void);
39 static int dbg_error(const char*);
43 %union
45 struct dbg_lvalue lvalue;
46 char* string;
47 int integer;
48 IMAGEHLP_LINE listing;
49 struct expr* expression;
50 struct type_expr_t type;
53 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tALL tINFO tUP tDOWN
54 %token tENABLE tDISABLE tBREAK tHBREAK tWATCH tDELETE tSET tPRINT tEXAM
55 %token tABORT tECHO
56 %token tCLASS tMAPS tSTACK tSEGMENTS tSYMBOL tREGS tALLREGS tWND tQUEUE tLOCAL tEXCEPTION
57 %token tPROCESS tTHREAD tEOL tEOF
58 %token tFRAME tSHARE tMODULE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
59 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
60 %token <string> tPATH tIDENTIFIER tSTRING tDEBUGSTR tINTVAR
61 %token <integer> tNUM tFORMAT
62 %token tSYMBOLFILE tRUN tATTACH tDETACH tKILL tMAINTENANCE tTYPE tMINIDUMP
63 %token tNOPROCESS
65 %token tCHAR 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 OP_SCOPE
85 %nonassoc ':'
87 %type <expression> expr lvalue
88 %type <lvalue> expr_lvalue lvalue_addr
89 %type <integer> expr_rvalue
90 %type <string> pathname identifier cpp_identifier
91 %type <listing> list_arg
92 %type <type> type_expr
96 input:
97 line
98 | input line
101 line:
102 command tEOL { expr_free_all(); }
103 | tEOL
104 | tEOF { return 1; }
105 | error tEOL { yyerrok; expr_free_all(); }
108 command:
109 tQUIT { return 1; }
110 | tHELP { print_help(); }
111 | tHELP tINFO { info_help(); }
112 | tPASS { dbg_wait_next_exception(DBG_EXCEPTION_NOT_HANDLED, 0, 0); }
113 | tCONT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_cont); }
114 | tCONT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_cont); }
115 | tSTEP { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_line); }
116 | tSTEP tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_line); }
117 | tNEXT { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_line); }
118 | tNEXT tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_line); }
119 | tSTEPI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_into_insn); }
120 | tSTEPI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_into_insn); }
121 | tNEXTI { dbg_wait_next_exception(DBG_CONTINUE, 1, dbg_exec_step_over_insn); }
122 | tNEXTI tNUM { dbg_wait_next_exception(DBG_CONTINUE, $2, dbg_exec_step_over_insn); }
123 | tFINISH { dbg_wait_next_exception(DBG_CONTINUE, 0, dbg_exec_finish); }
124 | tABORT { abort(); }
125 | tBACKTRACE { stack_backtrace(dbg_curr_tid); }
126 | tBACKTRACE tNUM { stack_backtrace($2); }
127 | tBACKTRACE tALL { stack_backtrace(-1); }
128 | tUP { stack_set_frame(dbg_curr_thread->curr_frame + 1); }
129 | tUP tNUM { stack_set_frame(dbg_curr_thread->curr_frame + $2); }
130 | tDOWN { stack_set_frame(dbg_curr_thread->curr_frame - 1); }
131 | tDOWN tNUM { stack_set_frame(dbg_curr_thread->curr_frame - $2); }
132 | tFRAME tNUM { stack_set_frame($2); }
133 | tSHOW tDIR { source_show_path(); }
134 | tDIR pathname { source_add_path($2); }
135 | tDIR { source_nuke_path(dbg_curr_process); }
136 | tCOND tNUM { break_add_condition($2, NULL); }
137 | tCOND tNUM expr { break_add_condition($2, $3); }
138 | tSOURCE pathname { parser($2); }
139 | tSYMBOLFILE pathname { symbol_read_symtable($2, 0); }
140 | tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); }
141 | tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE); dbg_printf("\n"); }
142 | tATTACH tNUM { dbg_attach_debuggee($2, FALSE); dbg_active_wait_for_first_exception(); }
143 | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
144 | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); }
145 | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
146 | tECHO tSTRING { dbg_printf("%s\n", $2); }
147 | run_command
148 | list_command
149 | disassemble_command
150 | set_command
151 | x_command
152 | print_command
153 | break_command
154 | watch_command
155 | display_command
156 | info_command
157 | maintenance_command
158 | noprocess_state
161 pathname:
162 identifier { $$ = $1; }
163 | tSTRING { $$ = $1; }
164 | tPATH { $$ = $1; }
167 cpp_identifier:
168 tIDENTIFIER { $$ = $1; }
169 | identifier OP_SCOPE tIDENTIFIER { $$ = lexeme_alloc_size(strlen($1) + 2 + strlen($3) + 1);
170 sprintf($$, "%s::%s", $1, $3); }
173 identifier:
174 cpp_identifier { $$ = $1; }
175 | tIDENTIFIER '!' cpp_identifier { $$ = lexeme_alloc_size(strlen($1) + 1 + strlen($3) + 1);
176 sprintf($$, "%s!%s", $1, $3); }
179 list_arg:
180 tNUM { $$.FileName = NULL; $$.LineNumber = $1; }
181 | pathname ':' tNUM { $$.FileName = $1; $$.LineNumber = $3; }
182 | identifier { symbol_get_line(NULL, $1, &$$); }
183 | pathname ':' identifier { symbol_get_line($3, $1, &$$); }
184 | '*' expr_lvalue { DWORD disp; $$.SizeOfStruct = sizeof($$);
185 SymGetLineFromAddr(dbg_curr_process->handle, (unsigned long)memory_to_linear_addr(& $2.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_rvalue { memory_write_value(&$2, sizeof(int), &$4); }
209 | tSET '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, NULL, $3); }
210 | tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
211 | tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
212 | tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
213 | tSET '!' tIDENTIFIER tIDENTIFIER { dbg_set_option($3, $4); }
214 | tSET '!' tIDENTIFIER { dbg_set_option($3, NULL); }
217 x_command:
218 tEXAM expr_lvalue { memory_examine(&$2, 1, 'x'); }
219 | tEXAM tFORMAT expr_lvalue { memory_examine(&$3, $2 >> 8, $2 & 0xff); }
222 print_command:
223 tPRINT expr_lvalue { print_value(&$2, 0, 0); }
224 | tPRINT tFORMAT expr_lvalue { if (($2 >> 8) == 1) print_value(&$3, $2 & 0xff, 0); else dbg_printf("Count is meaningless in print command\n"); }
227 break_command:
228 tBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, TRUE); }
229 | tBREAK identifier { break_add_break_from_id($2, -1, TRUE); }
230 | tBREAK identifier ':' tNUM { break_add_break_from_id($2, $4, TRUE); }
231 | tBREAK tNUM { break_add_break_from_lineno($2, TRUE); }
232 | tBREAK { break_add_break_from_lineno(-1, TRUE); }
233 | tHBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, FALSE); }
234 | tHBREAK identifier { break_add_break_from_id($2, -1, FALSE); }
235 | tHBREAK identifier ':' tNUM { break_add_break_from_id($2, $4, FALSE); }
236 | tHBREAK tNUM { break_add_break_from_lineno($2, FALSE); }
237 | tHBREAK { break_add_break_from_lineno(-1, FALSE); }
238 | tENABLE tNUM { break_enable_xpoint($2, TRUE); }
239 | tENABLE tBREAK tNUM { break_enable_xpoint($3, TRUE); }
240 | tDISABLE tNUM { break_enable_xpoint($2, FALSE); }
241 | tDISABLE tBREAK tNUM { break_enable_xpoint($3, FALSE); }
242 | tDELETE tNUM { break_delete_xpoint($2); }
243 | tDELETE tBREAK tNUM { break_delete_xpoint($3); }
246 watch_command:
247 tWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3); }
248 | tWATCH identifier { break_add_watch_from_id($2); }
251 display_command:
252 tDISPLAY { display_print(); }
253 | tDISPLAY expr { display_add($2, 1, 0); }
254 | tDISPLAY tFORMAT expr { display_add($3, $2 >> 8, $2 & 0xff); }
255 | tENABLE tDISPLAY tNUM { display_enable($3, TRUE); }
256 | tDISABLE tDISPLAY tNUM { display_enable($3, FALSE); }
257 | tDELETE tDISPLAY tNUM { display_delete($3); }
258 | tDELETE tDISPLAY { display_delete(-1); }
259 | tUNDISPLAY tNUM { display_delete($2); }
260 | tUNDISPLAY { display_delete(-1); }
263 info_command:
264 tINFO tBREAK { break_info(); }
265 | tINFO tSHARE { info_win32_module(0); }
266 | tINFO tSHARE expr_rvalue { info_win32_module($3); }
267 | tINFO tREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); }
268 | tINFO tALLREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); }
269 | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); }
270 | tINFO tSEGMENTS { info_win32_segments(0, -1); }
271 | tINFO tSTACK { stack_info(); }
272 | tINFO tSYMBOL tSTRING { symbol_info($3); }
273 | tINFO tLOCAL { symbol_info_locals(); }
274 | tINFO tDISPLAY { display_info(); }
275 | tINFO tCLASS { info_win32_class(NULL, NULL); }
276 | tINFO tCLASS tSTRING { info_win32_class(NULL, $3); }
277 | tINFO tWND { info_win32_window(NULL, FALSE); }
278 | tINFO tWND expr_rvalue { info_win32_window((HWND)$3, FALSE); }
279 | tINFO '*' tWND { info_win32_window(NULL, TRUE); }
280 | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)$4, TRUE); }
281 | tINFO tPROCESS { info_win32_processes(); }
282 | tINFO tTHREAD { info_win32_threads(); }
283 | tINFO tEXCEPTION { info_win32_exceptions(dbg_curr_tid); }
284 | tINFO tEXCEPTION expr_rvalue { info_win32_exceptions($3); }
285 | tINFO tMAPS { info_win32_virtual(dbg_curr_pid); }
286 | tINFO tMAPS expr_rvalue { info_win32_virtual($3); }
289 maintenance_command:
290 tMAINTENANCE tTYPE { print_types(); }
291 | tMAINTENANCE tMODULE tSTRING { tgt_module_load($3, FALSE); }
292 | tMAINTENANCE '*' tMODULE tSTRING { tgt_module_load($4, TRUE); }
295 noprocess_state:
296 tNOPROCESS {} /* <CR> shall not barf anything */
297 | tNOPROCESS tBACKTRACE tALL { stack_backtrace(-1); } /* can backtrace all threads with no attached process */
298 | tNOPROCESS tSTRING { dbg_printf("No process loaded, cannot execute '%s'\n", $2); }
301 type_expr:
302 tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_char; }
303 | tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_int; }
304 | tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
305 | tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
306 | tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
307 | tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
308 | tLONG tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
309 | tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
310 | tSHORT tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
311 | tSHORT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
312 | tSHORT tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
313 | tSHORT tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
314 | tSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_char_int; }
315 | tUNSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_char_int; }
316 | tLONG tLONG tUNSIGNED tINT{ $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
317 | tLONG tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
318 | tLONG tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
319 | tLONG tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
320 | tFLOAT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_short_real; }
321 | tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_real; }
322 | tLONG tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_long_real; }
323 | type_expr '*' { $$ = $1; $$.deref_count++; }
324 | tCLASS identifier { $$.type = type_expr_udt_class; $$.deref_count = 0; $$.u.name = $2; }
325 | tSTRUCT identifier { $$.type = type_expr_udt_struct; $$.deref_count = 0; $$.u.name = $2; }
326 | tUNION identifier { $$.type = type_expr_udt_union; $$.deref_count = 0; $$.u.name = $2; }
327 | tENUM identifier { $$.type = type_expr_enumeration; $$.deref_count = 0; $$.u.name = $2; }
330 expr_lvalue:
331 expr { $$ = expr_eval($1); }
334 expr_rvalue:
335 expr_lvalue { $$ = types_extract_as_integer(&$1); }
339 * The expr rule builds an expression tree. When we are done, we call
340 * EvalExpr to evaluate the value of the expression. The advantage of
341 * the two-step approach is that it is possible to save expressions for
342 * use in 'display' commands, and in conditional watchpoints.
344 expr:
345 tNUM { $$ = expr_alloc_sconstant($1); }
346 | tSTRING { $$ = expr_alloc_string($1); }
347 | tINTVAR { $$ = expr_alloc_internal_var($1); }
348 | identifier { $$ = expr_alloc_symbol($1); }
349 | expr OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
350 | expr '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
351 | identifier '(' ')' { $$ = expr_alloc_func_call($1, 0); }
352 | identifier '(' expr ')' { $$ = expr_alloc_func_call($1, 1, $3); }
353 | identifier '(' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 2, $3, $5); }
354 | identifier '(' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 3, $3, $5, $7); }
355 | identifier '(' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 4, $3, $5, $7, $9); }
356 | identifier '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 5, $3, $5, $7, $9, $11); }
357 | expr '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
358 | expr ':' expr { $$ = expr_alloc_binary_op(EXP_OP_SEG, $1, $3); }
359 | expr OP_LOR expr { $$ = expr_alloc_binary_op(EXP_OP_LOR, $1, $3); }
360 | expr OP_LAND expr { $$ = expr_alloc_binary_op(EXP_OP_LAND, $1, $3); }
361 | expr '|' expr { $$ = expr_alloc_binary_op(EXP_OP_OR, $1, $3); }
362 | expr '&' expr { $$ = expr_alloc_binary_op(EXP_OP_AND, $1, $3); }
363 | expr '^' expr { $$ = expr_alloc_binary_op(EXP_OP_XOR, $1, $3); }
364 | expr OP_EQ expr { $$ = expr_alloc_binary_op(EXP_OP_EQ, $1, $3); }
365 | expr '>' expr { $$ = expr_alloc_binary_op(EXP_OP_GT, $1, $3); }
366 | expr '<' expr { $$ = expr_alloc_binary_op(EXP_OP_LT, $1, $3); }
367 | expr OP_GE expr { $$ = expr_alloc_binary_op(EXP_OP_GE, $1, $3); }
368 | expr OP_LE expr { $$ = expr_alloc_binary_op(EXP_OP_LE, $1, $3); }
369 | expr OP_NE expr { $$ = expr_alloc_binary_op(EXP_OP_NE, $1, $3); }
370 | expr OP_SHL expr { $$ = expr_alloc_binary_op(EXP_OP_SHL, $1, $3); }
371 | expr OP_SHR expr { $$ = expr_alloc_binary_op(EXP_OP_SHR, $1, $3); }
372 | expr '+' expr { $$ = expr_alloc_binary_op(EXP_OP_ADD, $1, $3); }
373 | expr '-' expr { $$ = expr_alloc_binary_op(EXP_OP_SUB, $1, $3); }
374 | expr '*' expr { $$ = expr_alloc_binary_op(EXP_OP_MUL, $1, $3); }
375 | expr '/' expr { $$ = expr_alloc_binary_op(EXP_OP_DIV, $1, $3); }
376 | expr '%' expr { $$ = expr_alloc_binary_op(EXP_OP_REM, $1, $3); }
377 | '-' expr %prec OP_SIGN { $$ = expr_alloc_unary_op(EXP_OP_NEG, $2); }
378 | '+' expr %prec OP_SIGN { $$ = $2; }
379 | '!' expr { $$ = expr_alloc_unary_op(EXP_OP_NOT, $2); }
380 | '~' expr { $$ = expr_alloc_unary_op(EXP_OP_LNOT, $2); }
381 | '(' expr ')' { $$ = $2; }
382 | '*' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
383 | '&' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_ADDR, $2); }
384 | '(' type_expr ')' expr %prec OP_DEREF { $$ = expr_alloc_typecast(&$2, $4); }
388 * The lvalue rule builds an expression tree. This is a limited form
389 * of expression that is suitable to be used as an lvalue.
391 lvalue_addr:
392 lvalue { $$ = expr_eval($1); }
395 lvalue:
396 tNUM { $$ = expr_alloc_sconstant($1); }
397 | tINTVAR { $$ = expr_alloc_internal_var($1); }
398 | identifier { $$ = expr_alloc_symbol($1); }
399 | lvalue OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
400 | lvalue '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
401 | lvalue '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
402 | '*' expr { $$ = expr_alloc_unary_op(EXP_OP_FORCE_DEREF, $2); }
407 static LONG WINAPI wine_dbg_cmd(EXCEPTION_POINTERS *eptr)
409 switch (eptr->ExceptionRecord->ExceptionCode)
411 case DEBUG_STATUS_INTERNAL_ERROR:
412 dbg_printf("\nWineDbg internal error\n");
413 break;
414 case DEBUG_STATUS_NO_SYMBOL:
415 dbg_printf("\nUndefined symbol\n");
416 break;
417 case DEBUG_STATUS_DIV_BY_ZERO:
418 dbg_printf("\nDivision by zero\n");
419 break;
420 case DEBUG_STATUS_BAD_TYPE:
421 dbg_printf("\nNo type or type mismatch\n");
422 break;
423 case DEBUG_STATUS_NO_FIELD:
424 dbg_printf("\nNo such field in structure or union\n");
425 break;
426 case DEBUG_STATUS_CANT_DEREF:
427 dbg_printf("\nDereference failed (not a pointer, or out of array bounds)\n");
428 break;
429 case DEBUG_STATUS_ABORT:
430 break;
431 case DEBUG_STATUS_NOT_AN_INTEGER:
432 dbg_printf("\nNeeding an integral value\n");
433 break;
434 case CONTROL_C_EXIT:
435 /* this is generally sent by a ctrl-c when we run winedbg outside of wineconsole */
436 /* stop the debuggee, and continue debugger execution, we will be reentered by the
437 * debug events generated by stopping
439 dbg_interrupt_debuggee();
440 return EXCEPTION_CONTINUE_EXECUTION;
441 default:
442 dbg_printf("\nException %x\n", eptr->ExceptionRecord->ExceptionCode);
443 break;
446 return EXCEPTION_EXECUTE_HANDLER;
449 static HANDLE dbg_parser_input;
450 static HANDLE dbg_parser_output;
452 int input_fetch_entire_line(const char* pfx, char** line)
454 char ch;
455 DWORD nread;
456 size_t len, alloc;
458 /* as of today, console handles can be file handles... so better use file APIs rather than
459 * console's
461 WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
463 if (*line)
465 alloc = HeapSize(GetProcessHeap(), 0, *line);
466 assert(alloc);
468 else
470 *line = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
471 assert(*line);
474 len = 0;
477 if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
478 return -1;
480 if (len + 2 > alloc)
482 while (len + 2 > alloc) alloc *= 2;
483 *line = dbg_heap_realloc(*line, alloc);
485 (*line)[len++] = ch;
487 while (ch != '\n');
488 (*line)[len] = '\0';
490 return len;
493 int input_read_line(const char* pfx, char* buf, int size)
495 char* line = NULL;
497 int len = input_fetch_entire_line(pfx, &line);
498 if (len < 0) return 0;
499 /* remove trailing \n */
500 if (len > 0 && line[len - 1] == '\n') len--;
501 len = min(size - 1, len);
502 memcpy(buf, line, len);
503 buf[len] = '\0';
504 HeapFree(GetProcessHeap(), 0, line);
505 return 1;
508 /***********************************************************************
509 * parser_handle
511 * Debugger command line parser
513 void parser_handle(HANDLE input)
515 BOOL ret_ok;
516 HANDLE in_copy = dbg_parser_input;
517 HANDLE out_copy = dbg_parser_output;
519 ret_ok = FALSE;
521 if (input != INVALID_HANDLE_VALUE)
523 dbg_parser_output = INVALID_HANDLE_VALUE;
524 dbg_parser_input = input;
526 else
528 dbg_parser_output = GetStdHandle(STD_OUTPUT_HANDLE);
529 dbg_parser_input = GetStdHandle(STD_INPUT_HANDLE);
534 __TRY
536 ret_ok = TRUE;
537 dbg_parse();
539 __EXCEPT(wine_dbg_cmd)
541 ret_ok = FALSE;
543 __ENDTRY;
544 lexeme_flush();
545 } while (!ret_ok);
547 dbg_parser_input = in_copy;
548 dbg_parser_output = out_copy;
551 void parser(const char* filename)
553 HANDLE h = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
554 if (h != INVALID_HANDLE_VALUE)
556 parser_handle(h);
557 CloseHandle(h);
561 int dbg_error(const char* s)
563 dbg_printf("%s\n", s);
564 return 0;
567 HANDLE parser_generate_command_file(const char* pmt, ...)
569 HANDLE hFile;
570 char path[MAX_PATH], file[MAX_PATH];
571 DWORD w;
572 const char* p;
574 GetTempPath(sizeof(path), path);
575 GetTempFileName(path, "WD", 0, file);
576 hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
577 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
578 if (hFile != INVALID_HANDLE_VALUE)
580 va_list ap;
582 WriteFile(hFile, pmt, strlen(pmt), &w, 0);
583 va_start(ap, pmt);
584 while ((p = va_arg(ap, const char*)) != NULL)
586 WriteFile(hFile, "\n", 1, &w, 0);
587 WriteFile(hFile, p, strlen(p), &w, 0);
589 va_end(ap);
590 WriteFile(hFile, "\nquit\n", 6, &w, 0);
591 SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
593 return hFile;