crypt32/tests: Test more Unicode encoded string to string conversions.
[wine.git] / programs / winedbg / dbg.y
blob336f99319b549db77122a14df7722cbb64ecfaa1
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*);
40 static void parser(const char*);
44 %union
46 struct dbg_lvalue lvalue;
47 char* string;
48 INT_PTR integer;
49 IMAGEHLP_LINE64 listing;
50 struct expr* expression;
51 struct type_expr_t type;
54 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tALL tINFO tUP tDOWN
55 %token tENABLE tDISABLE tBREAK tHBREAK tWATCH tDELETE tSET tPRINT tEXAM
56 %token tABORT tECHO
57 %token tCLASS tMAPS tSTACK tSEGMENTS tSYMBOL tREGS tALLREGS tWND tLOCAL tEXCEPTION
58 %token tPROCESS tTHREAD tEOL tEOF
59 %token tFRAME tSHARE tMODULE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
60 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS tSOURCE
61 %token <string> tPATH tIDENTIFIER tSTRING tINTVAR
62 %token <integer> tNUM tFORMAT
63 %token tSYMBOLFILE tRUN tATTACH tDETACH tKILL tMAINTENANCE tTYPE tMINIDUMP
64 %token tNOPROCESS
66 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
67 %token tSTRUCT tUNION tENUM
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 OP_SCOPE
86 %nonassoc ':'
88 %type <expression> expr lvalue
89 %type <lvalue> expr_lvalue lvalue_addr
90 %type <integer> expr_rvalue
91 %type <string> pathname identifier cpp_identifier
92 %type <listing> list_arg
93 %type <type> type_expr
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); dbg_printf("\n"); }
143 | tATTACH tNUM { dbg_attach_debuggee($2, FALSE); dbg_active_wait_for_first_exception(); }
144 | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
145 | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); }
146 | tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
147 | tECHO tSTRING { dbg_printf("%s\n", $2); }
148 | run_command
149 | list_command
150 | disassemble_command
151 | set_command
152 | x_command
153 | print_command
154 | break_command
155 | watch_command
156 | display_command
157 | info_command
158 | maintenance_command
159 | noprocess_state
162 pathname:
163 identifier { $$ = $1; }
164 | tSTRING { $$ = $1; }
165 | tPATH { $$ = $1; }
168 cpp_identifier:
169 tIDENTIFIER { $$ = $1; }
170 | identifier OP_SCOPE tIDENTIFIER { $$ = lexeme_alloc_size(strlen($1) + 2 + strlen($3) + 1);
171 sprintf($$, "%s::%s", $1, $3); }
174 identifier:
175 cpp_identifier { $$ = $1; }
176 | tIDENTIFIER '!' cpp_identifier { $$ = lexeme_alloc_size(strlen($1) + 1 + strlen($3) + 1);
177 sprintf($$, "%s!%s", $1, $3); }
180 list_arg:
181 tNUM { $$.FileName = NULL; $$.LineNumber = $1; }
182 | pathname ':' tNUM { $$.FileName = $1; $$.LineNumber = $3; }
183 | identifier { symbol_get_line(NULL, $1, &$$); }
184 | pathname ':' identifier { symbol_get_line($1, $3, &$$); }
185 | '*' expr_lvalue { DWORD disp; ADDRESS64 addr; $$.SizeOfStruct = sizeof($$);
186 types_extract_as_address(&$2, &addr);
187 SymGetLineFromAddr64(dbg_curr_process->handle, (unsigned long)memory_to_linear_addr(& addr), &disp, & $$); }
190 run_command:
191 tRUN { dbg_run_debuggee(NULL); }
192 | tRUN tSTRING { dbg_run_debuggee($2); }
195 list_command:
196 tLIST { source_list(NULL, NULL, 10); }
197 | tLIST '-' { source_list(NULL, NULL, -10); }
198 | tLIST list_arg { source_list(& $2, NULL, 10); }
199 | tLIST ',' list_arg { source_list(NULL, & $3, -10); }
200 | tLIST list_arg ',' list_arg { source_list(& $2, & $4, 0); }
203 disassemble_command:
204 tDISASSEMBLE { memory_disassemble(NULL, NULL, 10); }
205 | tDISASSEMBLE expr_lvalue { memory_disassemble(&$2, NULL, 10); }
206 | tDISASSEMBLE expr_lvalue ',' expr_lvalue { memory_disassemble(&$2, &$4, 0); }
209 set_command:
210 tSET lvalue_addr '=' expr_rvalue { memory_write_value(&$2, sizeof(int), &$4); }
211 | tSET '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, NULL, $3); }
212 | tSET '+' tALL { info_wine_dbg_channel(TRUE, NULL, "all"); }
213 | tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
214 | tSET '-' tALL { info_wine_dbg_channel(FALSE, NULL, "all"); }
215 | tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
216 | tSET tIDENTIFIER '+' tALL { info_wine_dbg_channel(TRUE, $2, "all"); }
217 | tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
218 | tSET tIDENTIFIER '-' tALL { info_wine_dbg_channel(FALSE, $2, "all"); }
219 | tSET '!' tIDENTIFIER tIDENTIFIER { dbg_set_option($3, $4); }
220 | tSET '!' tIDENTIFIER { dbg_set_option($3, NULL); }
223 x_command:
224 tEXAM expr_lvalue { memory_examine(&$2, 1, 'x'); }
225 | tEXAM tFORMAT expr_lvalue { memory_examine(&$3, $2 >> 8, $2 & 0xff); }
228 print_command:
229 tPRINT expr_lvalue { print_value(&$2, 0, 0); }
230 | tPRINT tFORMAT expr_lvalue { if (($2 >> 8) == 1) print_value(&$3, $2 & 0xff, 0); else dbg_printf("Count is meaningless in print command\n"); }
233 break_command:
234 tBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, TRUE); }
235 | tBREAK identifier { break_add_break_from_id($2, -1, TRUE); }
236 | tBREAK identifier ':' tNUM { break_add_break_from_id($2, $4, TRUE); }
237 | tBREAK tNUM { break_add_break_from_lineno($2, TRUE); }
238 | tBREAK { break_add_break_from_lineno(-1, TRUE); }
239 | tHBREAK '*' expr_lvalue { break_add_break_from_lvalue(&$3, FALSE); }
240 | tHBREAK identifier { break_add_break_from_id($2, -1, FALSE); }
241 | tHBREAK identifier ':' tNUM { break_add_break_from_id($2, $4, FALSE); }
242 | tHBREAK tNUM { break_add_break_from_lineno($2, FALSE); }
243 | tHBREAK { break_add_break_from_lineno(-1, FALSE); }
244 | tENABLE tNUM { break_enable_xpoint($2, TRUE); }
245 | tENABLE tBREAK tNUM { break_enable_xpoint($3, TRUE); }
246 | tDISABLE tNUM { break_enable_xpoint($2, FALSE); }
247 | tDISABLE tBREAK tNUM { break_enable_xpoint($3, FALSE); }
248 | tDELETE tNUM { break_delete_xpoint($2); }
249 | tDELETE tBREAK tNUM { break_delete_xpoint($3); }
252 watch_command:
253 tWATCH '*' expr_lvalue { break_add_watch_from_lvalue(&$3); }
254 | tWATCH identifier { break_add_watch_from_id($2); }
257 display_command:
258 tDISPLAY { display_print(); }
259 | tDISPLAY expr { display_add($2, 1, 0); }
260 | tDISPLAY tFORMAT expr { display_add($3, $2 >> 8, $2 & 0xff); }
261 | tENABLE tDISPLAY tNUM { display_enable($3, TRUE); }
262 | tDISABLE tDISPLAY tNUM { display_enable($3, FALSE); }
263 | tDELETE tDISPLAY tNUM { display_delete($3); }
264 | tDELETE tDISPLAY { display_delete(-1); }
265 | tUNDISPLAY tNUM { display_delete($2); }
266 | tUNDISPLAY { display_delete(-1); }
269 info_command:
270 tINFO tBREAK { break_info(); }
271 | tINFO tSHARE { info_win32_module(0); }
272 | tINFO tSHARE expr_rvalue { info_win32_module($3); }
273 | tINFO tREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); }
274 | tINFO tALLREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); }
275 | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); }
276 | tINFO tSEGMENTS { info_win32_segments(0, -1); }
277 | tINFO tSTACK tNUM { stack_info($3); }
278 | tINFO tSTACK { stack_info(-1); }
279 | tINFO tSYMBOL tSTRING { symbol_info($3); }
280 | tINFO tLOCAL { symbol_info_locals(); }
281 | tINFO tDISPLAY { display_info(); }
282 | tINFO tCLASS { info_win32_class(NULL, NULL); }
283 | tINFO tCLASS tSTRING { info_win32_class(NULL, $3); }
284 | tINFO tWND { info_win32_window(NULL, FALSE); }
285 | tINFO tWND expr_rvalue { info_win32_window((HWND)$3, FALSE); }
286 | tINFO '*' tWND { info_win32_window(NULL, TRUE); }
287 | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)$4, TRUE); }
288 | tINFO tPROCESS { info_win32_processes(); }
289 | tINFO tTHREAD { info_win32_threads(); }
290 | tINFO tEXCEPTION { info_win32_exceptions(dbg_curr_tid); }
291 | tINFO tEXCEPTION expr_rvalue { info_win32_exceptions($3); }
292 | tINFO tMAPS { info_win32_virtual(dbg_curr_pid); }
293 | tINFO tMAPS expr_rvalue { info_win32_virtual($3); }
296 maintenance_command:
297 tMAINTENANCE tTYPE { print_types(); }
298 | tMAINTENANCE tMODULE tSTRING { tgt_module_load($3, FALSE); }
299 | tMAINTENANCE '*' tMODULE tSTRING { tgt_module_load($4, TRUE); }
302 noprocess_state:
303 tNOPROCESS {} /* <CR> shall not barf anything */
304 | tNOPROCESS tBACKTRACE tALL { stack_backtrace(-1); } /* can backtrace all threads with no attached process */
305 | tNOPROCESS tSTRING { dbg_printf("No process loaded, cannot execute '%s'\n", $2); }
308 type_expr:
309 tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_char; }
310 | tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_int; }
311 | tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
312 | tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_long_int; }
313 | tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
314 | tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_int; }
315 | tLONG tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
316 | tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_long_int; }
317 | tSHORT tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
318 | tSHORT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_short_int; }
319 | tSHORT tUNSIGNED tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
320 | tSHORT tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_short_int; }
321 | tSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_char_int; }
322 | tUNSIGNED tCHAR { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_char_int; }
323 | tLONG tLONG tUNSIGNED tINT{ $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
324 | tLONG tLONG tUNSIGNED { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_unsigned_longlong_int; }
325 | tLONG tLONG tINT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
326 | tLONG tLONG { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_signed_longlong_int; }
327 | tFLOAT { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_short_real; }
328 | tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_real; }
329 | tLONG tDOUBLE { $$.type = type_expr_type_id; $$.deref_count = 0; $$.u.type.module = 0; $$.u.type.id = dbg_itype_long_real; }
330 | type_expr '*' { $$ = $1; $$.deref_count++; }
331 | tCLASS identifier { $$.type = type_expr_udt_class; $$.deref_count = 0; $$.u.name = $2; }
332 | tSTRUCT identifier { $$.type = type_expr_udt_struct; $$.deref_count = 0; $$.u.name = $2; }
333 | tUNION identifier { $$.type = type_expr_udt_union; $$.deref_count = 0; $$.u.name = $2; }
334 | tENUM identifier { $$.type = type_expr_enumeration; $$.deref_count = 0; $$.u.name = $2; }
337 expr_lvalue:
338 expr { $$ = expr_eval($1); }
341 expr_rvalue:
342 expr_lvalue { $$ = types_extract_as_integer(&$1); }
346 * The expr rule builds an expression tree. When we are done, we call
347 * EvalExpr to evaluate the value of the expression. The advantage of
348 * the two-step approach is that it is possible to save expressions for
349 * use in 'display' commands, and in conditional watchpoints.
351 expr:
352 tNUM { $$ = expr_alloc_sconstant($1); }
353 | tSTRING { $$ = expr_alloc_string($1); }
354 | tINTVAR { $$ = expr_alloc_internal_var($1); }
355 | identifier { $$ = expr_alloc_symbol($1); }
356 | expr OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
357 | expr '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
358 | identifier '(' ')' { $$ = expr_alloc_func_call($1, 0); }
359 | identifier '(' expr ')' { $$ = expr_alloc_func_call($1, 1, $3); }
360 | identifier '(' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 2, $3, $5); }
361 | identifier '(' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 3, $3, $5, $7); }
362 | identifier '(' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 4, $3, $5, $7, $9); }
363 | identifier '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = expr_alloc_func_call($1, 5, $3, $5, $7, $9, $11); }
364 | expr '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
365 | expr ':' expr { $$ = expr_alloc_binary_op(EXP_OP_SEG, $1, $3); }
366 | expr OP_LOR expr { $$ = expr_alloc_binary_op(EXP_OP_LOR, $1, $3); }
367 | expr OP_LAND expr { $$ = expr_alloc_binary_op(EXP_OP_LAND, $1, $3); }
368 | expr '|' expr { $$ = expr_alloc_binary_op(EXP_OP_OR, $1, $3); }
369 | expr '&' expr { $$ = expr_alloc_binary_op(EXP_OP_AND, $1, $3); }
370 | expr '^' expr { $$ = expr_alloc_binary_op(EXP_OP_XOR, $1, $3); }
371 | expr OP_EQ expr { $$ = expr_alloc_binary_op(EXP_OP_EQ, $1, $3); }
372 | expr '>' expr { $$ = expr_alloc_binary_op(EXP_OP_GT, $1, $3); }
373 | expr '<' expr { $$ = expr_alloc_binary_op(EXP_OP_LT, $1, $3); }
374 | expr OP_GE expr { $$ = expr_alloc_binary_op(EXP_OP_GE, $1, $3); }
375 | expr OP_LE expr { $$ = expr_alloc_binary_op(EXP_OP_LE, $1, $3); }
376 | expr OP_NE expr { $$ = expr_alloc_binary_op(EXP_OP_NE, $1, $3); }
377 | expr OP_SHL expr { $$ = expr_alloc_binary_op(EXP_OP_SHL, $1, $3); }
378 | expr OP_SHR expr { $$ = expr_alloc_binary_op(EXP_OP_SHR, $1, $3); }
379 | expr '+' expr { $$ = expr_alloc_binary_op(EXP_OP_ADD, $1, $3); }
380 | expr '-' expr { $$ = expr_alloc_binary_op(EXP_OP_SUB, $1, $3); }
381 | expr '*' expr { $$ = expr_alloc_binary_op(EXP_OP_MUL, $1, $3); }
382 | expr '/' expr { $$ = expr_alloc_binary_op(EXP_OP_DIV, $1, $3); }
383 | expr '%' expr { $$ = expr_alloc_binary_op(EXP_OP_REM, $1, $3); }
384 | '-' expr %prec OP_SIGN { $$ = expr_alloc_unary_op(EXP_OP_NEG, $2); }
385 | '+' expr %prec OP_SIGN { $$ = $2; }
386 | '!' expr { $$ = expr_alloc_unary_op(EXP_OP_NOT, $2); }
387 | '~' expr { $$ = expr_alloc_unary_op(EXP_OP_LNOT, $2); }
388 | '(' expr ')' { $$ = $2; }
389 | '*' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_DEREF, $2); }
390 | '&' expr %prec OP_DEREF { $$ = expr_alloc_unary_op(EXP_OP_ADDR, $2); }
391 | '(' type_expr ')' expr %prec OP_DEREF { $$ = expr_alloc_typecast(&$2, $4); }
395 * The lvalue rule builds an expression tree. This is a limited form
396 * of expression that is suitable to be used as an lvalue.
398 lvalue_addr:
399 lvalue { $$ = expr_eval($1); }
402 lvalue:
403 tNUM { $$ = expr_alloc_sconstant($1); }
404 | tINTVAR { $$ = expr_alloc_internal_var($1); }
405 | identifier { $$ = expr_alloc_symbol($1); }
406 | lvalue OP_DRF tIDENTIFIER { $$ = expr_alloc_pstruct($1, $3); }
407 | lvalue '.' tIDENTIFIER { $$ = expr_alloc_struct($1, $3); }
408 | lvalue '[' expr ']' { $$ = expr_alloc_binary_op(EXP_OP_ARR, $1, $3); }
409 | '*' expr { $$ = expr_alloc_unary_op(EXP_OP_FORCE_DEREF, $2); }
414 static LONG WINAPI wine_dbg_cmd(EXCEPTION_POINTERS *eptr)
416 switch (eptr->ExceptionRecord->ExceptionCode)
418 case DEBUG_STATUS_INTERNAL_ERROR:
419 dbg_printf("\nWineDbg internal error\n");
420 break;
421 case DEBUG_STATUS_NO_SYMBOL:
422 dbg_printf("\nUndefined symbol\n");
423 break;
424 case DEBUG_STATUS_DIV_BY_ZERO:
425 dbg_printf("\nDivision by zero\n");
426 break;
427 case DEBUG_STATUS_BAD_TYPE:
428 dbg_printf("\nNo type or type mismatch\n");
429 break;
430 case DEBUG_STATUS_NO_FIELD:
431 dbg_printf("\nNo such field in structure or union\n");
432 break;
433 case DEBUG_STATUS_CANT_DEREF:
434 dbg_printf("\nDereference failed (not a pointer, or out of array bounds)\n");
435 break;
436 case DEBUG_STATUS_ABORT:
437 break;
438 case DEBUG_STATUS_NOT_AN_INTEGER:
439 dbg_printf("\nNeeding an integral value\n");
440 break;
441 case CONTROL_C_EXIT:
442 /* this is generally sent by a ctrl-c when we run winedbg outside of wineconsole */
443 /* stop the debuggee, and continue debugger execution, we will be reentered by the
444 * debug events generated by stopping
446 dbg_interrupt_debuggee();
447 return EXCEPTION_CONTINUE_EXECUTION;
448 default:
449 dbg_printf("\nException %x\n", eptr->ExceptionRecord->ExceptionCode);
450 break;
453 return EXCEPTION_EXECUTE_HANDLER;
456 static HANDLE dbg_parser_input;
457 static HANDLE dbg_parser_output;
459 int input_fetch_entire_line(const char* pfx, char** line)
461 char ch;
462 DWORD nread;
463 size_t len, alloc;
465 /* as of today, console handles can be file handles... so better use file APIs rather than
466 * console's
468 WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
470 if (*line)
472 alloc = HeapSize(GetProcessHeap(), 0, *line);
473 assert(alloc);
475 else
477 *line = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
478 assert(*line);
481 len = 0;
484 if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
485 return -1;
487 if (len + 2 > alloc)
489 while (len + 2 > alloc) alloc *= 2;
490 *line = dbg_heap_realloc(*line, alloc);
492 (*line)[len++] = ch;
494 while (ch != '\n');
495 (*line)[len] = '\0';
497 return len;
500 int input_read_line(const char* pfx, char* buf, int size)
502 char* line = NULL;
504 int len = input_fetch_entire_line(pfx, &line);
505 if (len < 0) return 0;
506 /* remove trailing \n */
507 if (len > 0 && line[len - 1] == '\n') len--;
508 len = min(size - 1, len);
509 memcpy(buf, line, len);
510 buf[len] = '\0';
511 HeapFree(GetProcessHeap(), 0, line);
512 return 1;
515 /***********************************************************************
516 * parser_handle
518 * Debugger command line parser
520 void parser_handle(HANDLE input)
522 BOOL ret_ok;
523 HANDLE in_copy = dbg_parser_input;
524 HANDLE out_copy = dbg_parser_output;
526 ret_ok = FALSE;
528 if (input != INVALID_HANDLE_VALUE)
530 dbg_parser_output = INVALID_HANDLE_VALUE;
531 dbg_parser_input = input;
533 else
535 dbg_parser_output = GetStdHandle(STD_OUTPUT_HANDLE);
536 dbg_parser_input = GetStdHandle(STD_INPUT_HANDLE);
541 __TRY
543 ret_ok = TRUE;
544 dbg_parse();
546 __EXCEPT(wine_dbg_cmd)
548 ret_ok = FALSE;
550 __ENDTRY;
551 lexeme_flush();
552 } while (!ret_ok);
554 dbg_parser_input = in_copy;
555 dbg_parser_output = out_copy;
558 static void parser(const char* filename)
560 HANDLE h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0L, 0);
561 if (h != INVALID_HANDLE_VALUE)
563 parser_handle(h);
564 CloseHandle(h);
568 static int dbg_error(const char* s)
570 dbg_printf("%s\n", s);
571 return 0;
574 HANDLE parser_generate_command_file(const char* pmt, ...)
576 HANDLE hFile;
577 char path[MAX_PATH], file[MAX_PATH];
578 DWORD w;
579 const char* p;
581 GetTempPathA(sizeof(path), path);
582 GetTempFileNameA(path, "WD", 0, file);
583 hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
584 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
585 if (hFile != INVALID_HANDLE_VALUE)
587 va_list ap;
589 WriteFile(hFile, pmt, strlen(pmt), &w, 0);
590 va_start(ap, pmt);
591 while ((p = va_arg(ap, const char*)) != NULL)
593 WriteFile(hFile, "\n", 1, &w, 0);
594 WriteFile(hFile, p, strlen(p), &w, 0);
596 va_end(ap);
597 WriteFile(hFile, "\nquit\n", 6, &w, 0);
598 SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
600 return hFile;