3 * Parser for command lines in the Wine debugger
5 * Copyright 1993 Eric Youngdale
6 * Copyright 1995 Morten Welinder
7 * Copyright 2000 Eric Pouech
18 #include "wine/exception.h"
25 static void issue_prompt
(void);
26 static void mode_command
(int);
37 struct list_id listing
;
38 struct expr
* expression
;
39 struct datatype
* type
;
42 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
43 %token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT tVM86
44 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
45 %token tPROCESS tTHREAD tMODREF tEOL
46 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
47 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS
49 %token
<string> tIDENTIFIER tSTRING tDEBUGSTR tINTVAR
50 %token
<integer
> tNUM tFORMAT
51 %token tSYMBOLFILE tRUN tATTACH tNOPROCESS
53 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
54 %token tSTRUCT tUNION tENUM
57 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
58 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
59 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
60 /* %left OP_COND */ /* ... ? ... : ... */
67 %left
'<' '>' OP_LE OP_GE
71 %left OP_SIGN
'!' '~' OP_DEREF
/* OP_INC OP_DEC OP_ADDR */
75 %type
<expression
> expr lval lvalue
76 %type
<type
> type_cast type_expr
77 %type
<value
> expr_addr lval_addr
78 %type
<integer
> expr_value
79 %type
<string> pathname
81 %type
<listing
> list_arg
85 input: line
{ issue_prompt
(); }
86 | input line
{ issue_prompt
(); }
90 |
error tEOL
{ yyerrok; }
93 tQUIT tEOL
{ return FALSE
; }
94 | tHELP tEOL
{ DEBUG_Help
(); }
95 | tHELP tINFO tEOL
{ DEBUG_HelpInfo
(); }
96 | tCONT tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
97 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_CONT
; return TRUE
; }
98 | tPASS tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
99 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_PASS
; return TRUE
; }
100 | tCONT tNUM tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= $2;
101 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_CONT
; return TRUE
; }
102 | tSTEP tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
103 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEP_INSTR
; return TRUE
; }
104 | tNEXT tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
105 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEP_OVER
; return TRUE
; }
106 | tSTEP tNUM tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= $2;
107 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEP_INSTR
; return TRUE
; }
108 | tNEXT tNUM tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= $2;
109 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEP_OVER
; return TRUE
; }
110 | tSTEPI tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
111 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEPI_INSTR
; return TRUE
; }
112 | tNEXTI tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 1;
113 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEPI_OVER
; return TRUE
; }
114 | tSTEPI tNUM tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= $2;
115 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEPI_INSTR
; return TRUE
; }
116 | tNEXTI tNUM tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= $2;
117 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_STEPI_OVER
; return TRUE
; }
118 | tABORT tEOL
{ kill
(getpid
(), SIGABRT
); }
119 | tMODE tNUM tEOL
{ mode_command
($2); }
120 | tMODE tVM86 tEOL
{ DEBUG_CurrThread
->dbg_mode
= MODE_VM86
; }
121 | tENABLE tNUM tEOL
{ DEBUG_EnableBreakpoint
( $2, TRUE
); }
122 | tDISABLE tNUM tEOL
{ DEBUG_EnableBreakpoint
( $2, FALSE
); }
123 | tDELETE tBREAK tNUM tEOL
{ DEBUG_DelBreakpoint
( $3 ); }
124 | tBACKTRACE tEOL
{ DEBUG_BackTrace
(TRUE
); }
125 | tUP tEOL
{ DEBUG_SetFrame
( curr_frame
+ 1 ); }
126 | tUP tNUM tEOL
{ DEBUG_SetFrame
( curr_frame
+ $2 ); }
127 | tDOWN tEOL
{ DEBUG_SetFrame
( curr_frame
- 1 ); }
128 | tDOWN tNUM tEOL
{ DEBUG_SetFrame
( curr_frame
- $2 ); }
129 | tFRAME tNUM tEOL
{ DEBUG_SetFrame
( $2 ); }
130 | tFINISH tEOL
{ DEBUG_CurrThread
->dbg_exec_count
= 0;
131 DEBUG_CurrThread
->dbg_exec_mode
= EXEC_FINISH
; return TRUE
; }
132 | tSHOW tDIR tEOL
{ DEBUG_ShowDir
(); }
133 | tDIR pathname tEOL
{ DEBUG_AddPath
( $2 ); }
134 | tDIR tEOL
{ DEBUG_NukePath
(); }
135 | tDISPLAY tEOL
{ DEBUG_InfoDisplay
(); }
136 | tDISPLAY expr tEOL
{ DEBUG_AddDisplay
($2, 1, 0); }
137 | tDISPLAY tFORMAT expr tEOL
{ DEBUG_AddDisplay
($3, $2 >> 8, $2 & 0xff); }
138 | tDELETE tDISPLAY tNUM tEOL
{ DEBUG_DelDisplay
( $3 ); }
139 | tDELETE tDISPLAY tEOL
{ DEBUG_DelDisplay
( -1 ); }
140 | tUNDISPLAY tNUM tEOL
{ DEBUG_DelDisplay
( $2 ); }
141 | tUNDISPLAY tEOL
{ DEBUG_DelDisplay
( -1 ); }
142 | tCOND tNUM tEOL
{ DEBUG_AddBPCondition
($2, NULL
); }
143 | tCOND tNUM expr tEOL
{ DEBUG_AddBPCondition
($2, $3); }
144 | tSYMBOLFILE pathname tEOL
{ DEBUG_ReadSymbolTable
($2); }
145 | tWHATIS expr_addr tEOL
{ DEBUG_PrintType
(&$2); DEBUG_FreeExprMem
(); }
146 | tATTACH tNUM tEOL
{ DEBUG_Attach
($2, FALSE
); return TRUE
; }
148 | disassemble_command
160 tSET lval_addr
'=' expr_value tEOL
{ DEBUG_WriteMemory
( &$2, $4 );
161 DEBUG_FreeExprMem
(); }
164 tIDENTIFIER
{ $$
= $1; }
168 tDISASSEMBLE tEOL
{ DEBUG_Disassemble
( NULL
, NULL
, 10 ); }
169 | tDISASSEMBLE expr_addr tEOL
{ DEBUG_Disassemble
( & $2, NULL
, 10 ); }
170 | tDISASSEMBLE expr_addr
',' expr_addr tEOL
{ DEBUG_Disassemble
( & $2, & $4, 0 ); }
173 tLIST tEOL
{ DEBUG_List
( NULL
, NULL
, 10 ); }
174 | tLIST
'-' tEOL
{ DEBUG_List
( NULL
, NULL
, -10 ); }
175 | tLIST list_arg tEOL
{ DEBUG_List
( & $2, NULL
, 10 ); }
176 | tLIST
',' list_arg tEOL
{ DEBUG_List
( NULL
, & $3, -10 ); }
177 | tLIST list_arg
',' list_arg tEOL
{ DEBUG_List
( & $2, & $4, 0 ); }
180 tNUM
{ $$.sourcefile
= NULL
; $$.line
= $1; }
181 | pathname
':' tNUM
{ $$.sourcefile
= $1; $$.line
= $3; }
182 | tIDENTIFIER
{ DEBUG_GetFuncInfo
( & $$
, NULL
, $1); }
183 | pathname
':' tIDENTIFIER
{ DEBUG_GetFuncInfo
( & $$
, $1, $3); }
184 |
'*' expr_addr
{ DEBUG_FindNearestSymbol
( & $2.addr
, FALSE
, NULL
, 0, & $$
);
185 DEBUG_FreeExprMem
(); }
188 tEXAM expr_addr tEOL
{ DEBUG_ExamineMemory
( &$2, 1, 'x'); DEBUG_FreeExprMem
(); }
189 | tEXAM tFORMAT expr_addr tEOL
{ DEBUG_ExamineMemory
( &$3, $2>>8, $2&0xff );
190 DEBUG_FreeExprMem
(); }
193 tPRINT expr_addr tEOL
{ DEBUG_Print
( &$2, 1, 0, 0 ); DEBUG_FreeExprMem
(); }
194 | tPRINT tFORMAT expr_addr tEOL
{ DEBUG_Print
( &$3, $2 >> 8, $2 & 0xff, 0 );
195 DEBUG_FreeExprMem
(); }
198 tBREAK
'*' expr_addr tEOL
{ DEBUG_AddBreakpoint
( &$3, NULL
); DEBUG_FreeExprMem
(); }
199 | tBREAK tIDENTIFIER tEOL
{ DEBUG_AddBreakpointFromId
($2, -1); }
200 | tBREAK tIDENTIFIER
':' tNUM tEOL
{ DEBUG_AddBreakpointFromId
($2, $4); }
201 | tBREAK tNUM tEOL
{ DEBUG_AddBreakpointFromLineno
($2); }
202 | tBREAK tEOL
{ DEBUG_AddBreakpointFromLineno
(-1); }
205 tWATCH
'*' expr_addr tEOL
{ DEBUG_AddWatchpoint
( &$3, 1 ); DEBUG_FreeExprMem
(); }
206 | tWATCH tIDENTIFIER tEOL
{ DEBUG_AddWatchpointFromId
($2, -1); }
209 tINFO tBREAK tEOL
{ DEBUG_InfoBreakpoints
(); }
210 | tINFO tCLASS tSTRING tEOL
{ DEBUG_InfoClass
( $3 ); }
211 | tINFO tSHARE tEOL
{ DEBUG_InfoShare
(); }
212 | tINFO tMODULE expr_value tEOL
{ DEBUG_DumpModule
( $3 ); DEBUG_FreeExprMem
(); }
213 | tINFO tQUEUE expr_value tEOL
{ DEBUG_DumpQueue
( $3 ); DEBUG_FreeExprMem
(); }
214 | tINFO tREGS tEOL
{ DEBUG_InfoRegisters
(); }
215 | tINFO tSEGMENTS expr_value tEOL
{ DEBUG_InfoSegments
( $3, 1 ); DEBUG_FreeExprMem
(); }
216 | tINFO tSEGMENTS tEOL
{ DEBUG_InfoSegments
( 0, -1 ); }
217 | tINFO tSTACK tEOL
{ DEBUG_InfoStack
(); }
218 | tINFO tMAPS tEOL
{ DEBUG_InfoVirtual
(); }
219 | tINFO tWND expr_value tEOL
{ DEBUG_InfoWindow
( (HWND
)$3 ); DEBUG_FreeExprMem
(); }
220 | tINFO tLOCAL tEOL
{ DEBUG_InfoLocals
(); }
221 | tINFO tDISPLAY tEOL
{ DEBUG_InfoDisplay
(); }
224 tWALK tCLASS tEOL
{ DEBUG_WalkClasses
(); }
225 | tWALK tMODULE tEOL
{ DEBUG_WalkModules
(); }
226 | tWALK tQUEUE tEOL
{ DEBUG_WalkQueues
(); }
227 | tWALK tWND tEOL
{ DEBUG_WalkWindows
( 0, 0 ); }
228 | tWALK tWND tNUM tEOL
{ DEBUG_WalkWindows
( $3, 0 ); }
229 | tWALK tPROCESS tEOL
{ DEBUG_WalkProcess
(); }
230 | tWALK tTHREAD tEOL
{ DEBUG_WalkThreads
(); }
231 | tWALK tMODREF expr_value tEOL
{ DEBUG_WalkModref
( $3 ); DEBUG_FreeExprMem
(); }
234 tRUN tEOL
{ DEBUG_Run
(NULL
); }
235 | tRUN tSTRING tEOL
{ DEBUG_Run
($2); }
238 tNOPROCESS tEOL
{} /* <CR> shall not barf anything */
239 | tNOPROCESS tSTRING tEOL
{ DEBUG_Printf
(DBG_CHN_MESG
, "No process loaded, cannot execute '%s'\n", $2); }
242 '(' type_expr
')' { $$
= $2; }
245 type_expr
'*' { $$
= DEBUG_FindOrMakePointerType
($1); }
246 | tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "int"); }
247 | tCHAR
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "char"); }
248 | tLONG tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "long int"); }
249 | tUNSIGNED tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "unsigned int"); }
250 | tLONG tUNSIGNED tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "long unsigned int"); }
251 | tLONG tLONG tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "long long int"); }
252 | tLONG tLONG tUNSIGNED tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "long long unsigned int"); }
253 | tSHORT tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "short int"); }
254 | tSHORT tUNSIGNED tINT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "short unsigned int"); }
255 | tSIGNED tCHAR
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "signed char"); }
256 | tUNSIGNED tCHAR
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "unsigned char"); }
257 | tFLOAT
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "float"); }
258 | tDOUBLE
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "double"); }
259 | tLONG tDOUBLE
{ $$
= DEBUG_TypeCast
(DT_BASIC
, "long double"); }
260 | tSTRUCT tIDENTIFIER
{ $$
= DEBUG_TypeCast
(DT_STRUCT
, $2); }
261 | tUNION tIDENTIFIER
{ $$
= DEBUG_TypeCast
(DT_STRUCT
, $2); }
262 | tENUM tIDENTIFIER
{ $$
= DEBUG_TypeCast
(DT_ENUM
, $2); }
265 expr
{ $$
= DEBUG_EvalExpr
($1); }
268 expr
{ DBG_VALUE value
= DEBUG_EvalExpr
($1);
269 /* expr_value is typed as an integer */
270 $$
= DEBUG_ReadMemory
(&value
); }
273 * The expr rule builds an expression tree. When we are done, we call
274 * EvalExpr to evaluate the value of the expression. The advantage of
275 * the two-step approach is that it is possible to save expressions for
276 * use in 'display' commands, and in conditional watchpoints.
279 tNUM
{ $$
= DEBUG_ConstExpr
($1); }
280 | tSTRING
{ $$
= DEBUG_StringExpr
($1); }
281 | tINTVAR
{ $$
= DEBUG_IntVarExpr
($1); }
282 | tIDENTIFIER
{ $$
= DEBUG_SymbolExpr
($1); }
283 | expr OP_DRF tIDENTIFIER
{ $$
= DEBUG_StructPExpr
($1, $3); }
284 | expr
'.' tIDENTIFIER
{ $$
= DEBUG_StructExpr
($1, $3); }
285 | tIDENTIFIER
'(' ')' { $$
= DEBUG_CallExpr
($1, 0); }
286 | tIDENTIFIER
'(' expr
')' { $$
= DEBUG_CallExpr
($1, 1, $3); }
287 | tIDENTIFIER
'(' expr
',' expr
')' { $$
= DEBUG_CallExpr
($1, 2, $3, $5); }
288 | tIDENTIFIER
'(' expr
',' expr
',' expr
')' { $$
= DEBUG_CallExpr
($1, 3, $3, $5, $7); }
289 | tIDENTIFIER
'(' expr
',' expr
',' expr
',' expr
')' { $$
= DEBUG_CallExpr
($1, 4, $3, $5, $7, $9); }
290 | tIDENTIFIER
'(' expr
',' expr
',' expr
',' expr
',' expr
')' { $$
= DEBUG_CallExpr
($1, 5, $3, $5, $7, $9, $11); }
291 | expr
'[' expr
']' { $$
= DEBUG_BinopExpr
(EXP_OP_ARR
, $1, $3); }
292 | expr
':' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_SEG
, $1, $3); }
293 | expr OP_LOR expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_LOR
, $1, $3); }
294 | expr OP_LAND expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_LAND
, $1, $3); }
295 | expr
'|' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_OR
, $1, $3); }
296 | expr
'&' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_AND
, $1, $3); }
297 | expr
'^' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_XOR
, $1, $3); }
298 | expr OP_EQ expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_EQ
, $1, $3); }
299 | expr
'>' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_GT
, $1, $3); }
300 | expr
'<' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_LT
, $1, $3); }
301 | expr OP_GE expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_GE
, $1, $3); }
302 | expr OP_LE expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_LE
, $1, $3); }
303 | expr OP_NE expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_NE
, $1, $3); }
304 | expr OP_SHL expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_SHL
, $1, $3); }
305 | expr OP_SHR expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_SHR
, $1, $3); }
306 | expr
'+' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_ADD
, $1, $3); }
307 | expr
'-' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_SUB
, $1, $3); }
308 | expr
'*' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_MUL
, $1, $3); }
309 | expr
'/' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_DIV
, $1, $3); }
310 | expr
'%' expr
{ $$
= DEBUG_BinopExpr
(EXP_OP_REM
, $1, $3); }
311 |
'-' expr %prec OP_SIGN
{ $$
= DEBUG_UnopExpr
(EXP_OP_NEG
, $2); }
312 |
'+' expr %prec OP_SIGN
{ $$
= $2; }
313 |
'!' expr
{ $$
= DEBUG_UnopExpr
(EXP_OP_NOT
, $2); }
314 |
'~' expr
{ $$
= DEBUG_UnopExpr
(EXP_OP_LNOT
, $2); }
315 |
'(' expr
')' { $$
= $2; }
316 |
'*' expr %prec OP_DEREF
{ $$
= DEBUG_UnopExpr
(EXP_OP_DEREF
, $2); }
317 |
'&' expr %prec OP_DEREF
{ $$
= DEBUG_UnopExpr
(EXP_OP_ADDR
, $2); }
318 | type_cast expr %prec OP_DEREF
{ $$
= DEBUG_TypeCastExpr
($1, $2); }
321 * The lvalue rule builds an expression tree. This is a limited form
322 * of expression that is suitable to be used as an lvalue.
325 lval
{ $$
= DEBUG_EvalExpr
($1); }
329 |
'*' expr
{ $$
= DEBUG_UnopExpr
(EXP_OP_FORCE_DEREF
, $2); }
332 tNUM
{ $$
= DEBUG_ConstExpr
($1); }
333 | tINTVAR
{ $$
= DEBUG_IntVarExpr
($1); }
334 | tIDENTIFIER
{ $$
= DEBUG_SymbolExpr
($1); }
335 | lvalue OP_DRF tIDENTIFIER
{ $$
= DEBUG_StructPExpr
($1, $3); }
336 | lvalue
'.' tIDENTIFIER
{ $$
= DEBUG_StructExpr
($1, $3); }
337 | lvalue
'[' expr
']' { $$
= DEBUG_BinopExpr
(EXP_OP_ARR
, $1, $3); }
341 static void issue_prompt
(void)
343 #ifdef DONT_USE_READLINE
344 DEBUG_Printf
(DBG_CHN_MESG
, "Wine-dbg>");
348 static void mode_command
(int newmode
)
352 case
16: DEBUG_CurrThread
->dbg_mode
= MODE_16
; break
;
353 case
32: DEBUG_CurrThread
->dbg_mode
= MODE_32
; break
;
354 default
: DEBUG_Printf
(DBG_CHN_MESG
,"Invalid mode (use 16, 32 or vm86)\n");
358 void DEBUG_Exit
(DWORD ec
)
363 static WINE_EXCEPTION_FILTER
(wine_dbg_cmd
)
365 DEBUG_Printf
(DBG_CHN_MESG
, "\nwine_dbg_cmd: ");
366 switch
(GetExceptionCode
()) {
367 case DEBUG_STATUS_INTERNAL_ERROR
:
368 DEBUG_Printf
(DBG_CHN_MESG
, "WineDbg internal error\n");
370 case DEBUG_STATUS_NO_SYMBOL
:
371 DEBUG_Printf
(DBG_CHN_MESG
, "Undefined symbol\n");
373 case DEBUG_STATUS_DIV_BY_ZERO
:
374 DEBUG_Printf
(DBG_CHN_MESG
, "Division by zero\n");
376 case DEBUG_STATUS_BAD_TYPE
:
377 DEBUG_Printf
(DBG_CHN_MESG
, "No type or type mismatch\n");
380 DEBUG_Printf
(DBG_CHN_MESG
, "Exception %lx\n", GetExceptionCode
());
384 return EXCEPTION_EXECUTE_HANDLER
;
387 /***********************************************************************
390 * Debugger editline parser
392 BOOL DEBUG_Parser
(void)
406 if
((ret
= yyparse())) {
407 DEBUG_FlushSymbols
();
409 } __EXCEPT
(wine_dbg_cmd
) {
420 DEBUG_Printf
(DBG_CHN_MESG
, "%s\n", s
);