Add start menu directories.
[wine/multimedia.git] / debugger / dbg.y
blob1ed882bee30f9018a715891914891fbf707ccdc9
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
8 */
10 #include "config.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <signal.h>
16 #include <unistd.h>
18 #include "wine/exception.h"
19 #include "debugger.h"
20 #include "expr.h"
21 #include "task.h"
23 extern FILE * yyin;
24 int curr_frame = 0;
26 static void issue_prompt(void);
27 static void mode_command(int);
28 void flush_symbols(void);
29 int yylex(void);
30 int yyerror(char *);
34 %union
36 DBG_VALUE value;
37 enum debug_regs reg;
38 char * string;
39 int integer;
40 struct list_id listing;
41 struct expr * expression;
42 struct datatype * type;
45 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
46 %token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT
47 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
48 %token tPROCESS tMODREF
49 %token tEOL tSTRING tDEBUGSTR
50 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
51 %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS
52 %token <string> tPATH
53 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
54 %token <integer> tNUM tFORMAT
55 %token <reg> tREG
56 %token tSYMBOLFILE
58 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
59 %token tSTRUCT tUNION tENUM
61 /* %left ',' */
62 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
63 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
64 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
65 /* %left OP_COND */ /* ... ? ... : ... */
66 %left OP_LOR
67 %left OP_LAND
68 %left '|'
69 %left '^'
70 %left '&'
71 %left OP_EQ OP_NE
72 %left '<' '>' OP_LE OP_GE
73 %left OP_SHL OP_SHR
74 %left '+' '-'
75 %left '*' '/' '%'
76 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
77 %left '.' '[' OP_DRF
78 %nonassoc ':'
80 %type <expression> expr lval lvalue
81 %type <type> type_cast type_expr
82 %type <value> expr_addr lval_addr
83 %type <integer> expr_value
84 %type <string> pathname
86 %type <listing> list_arg
90 input: line { issue_prompt(); }
91 | input line { issue_prompt(); }
93 line: command
94 | tEOL
95 | error tEOL { yyerrok; }
97 command:
98 tQUIT tEOL { DEBUG_Exit(0); }
99 | tHELP tEOL { DEBUG_Help(); }
100 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
101 | tCONT tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
102 DEBUG_CurrThread->dbg_exec_mode = EXEC_CONT; return 0; }
103 | tPASS tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
104 DEBUG_CurrThread->dbg_exec_mode = EXEC_PASS; return 0; }
105 | tCONT tNUM tEOL { DEBUG_CurrThread->dbg_exec_count = $2;
106 DEBUG_CurrThread->dbg_exec_mode = EXEC_CONT; return 0; }
107 | tSTEP tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
108 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
109 | tNEXT tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
110 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_OVER; return 0; }
111 | tSTEP tNUM tEOL { DEBUG_CurrThread->dbg_exec_count = $2;
112 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
113 | tNEXT tNUM tEOL { DEBUG_CurrThread->dbg_exec_count = $2;
114 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEP_OVER; return 0; }
115 | tSTEPI tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
116 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
117 | tNEXTI tEOL { DEBUG_CurrThread->dbg_exec_count = 1;
118 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
119 | tSTEPI tNUM tEOL { DEBUG_CurrThread->dbg_exec_count = $2;
120 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
121 | tNEXTI tNUM tEOL { DEBUG_CurrThread->dbg_exec_count = $2;
122 DEBUG_CurrThread->dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
123 | tABORT tEOL { kill(getpid(), SIGABRT); }
124 | tMODE tNUM tEOL { mode_command($2); }
125 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
126 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
127 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
128 | tBACKTRACE tEOL { DEBUG_BackTrace(TRUE); }
129 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
130 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
131 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
132 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
133 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
134 | tFINISH tEOL { DEBUG_CurrThread->dbg_exec_count = 0;
135 DEBUG_CurrThread->dbg_exec_mode = EXEC_FINISH; return 0; }
136 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
137 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
138 | tDIR tEOL { DEBUG_NukePath(); }
139 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
140 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
141 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
142 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
143 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
144 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
145 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
146 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
147 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
148 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
149 | tWHATIS expr_addr tEOL { DEBUG_PrintType(&$2); DEBUG_FreeExprMem(); }
150 | list_command
151 | disassemble_command
152 | set_command
153 | x_command
154 | print_command
155 | break_command
156 | watch_command
157 | info_command
158 | walk_command
160 set_command:
161 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
162 DEBUG_FreeExprMem(); }
163 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2.addr, $4 );
164 DEBUG_FreeExprMem(); }
166 pathname:
167 tIDENTIFIER { $$ = $1; }
168 | tPATH { $$ = $1; }
170 disassemble_command:
171 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
172 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
173 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
175 list_command:
176 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
177 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
178 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
179 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
180 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
182 list_arg:
183 tNUM { $$.sourcefile = NULL; $$.line = $1; }
184 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
185 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
186 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
187 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2.addr, FALSE, NULL,
188 0, & $$ );
189 DEBUG_FreeExprMem(); }
191 x_command:
192 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
193 DEBUG_FreeExprMem(); }
194 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
195 DEBUG_FreeExprMem(); }
197 print_command:
198 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
199 DEBUG_FreeExprMem(); }
200 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
201 DEBUG_FreeExprMem(); }
203 break_command:
204 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
205 DEBUG_FreeExprMem(); }
206 | tBREAK tIDENTIFIER tEOL { DBG_VALUE value;
207 if( DEBUG_GetSymbolValue($2, -1, &value, TRUE) )
209 DEBUG_AddBreakpoint( &value );
211 else
213 fprintf(stderr,"Unable to add breakpoint\n");
216 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_VALUE value;
217 if( DEBUG_GetSymbolValue($2, $4, &value, TRUE) )
219 DEBUG_AddBreakpoint( &value );
221 else
223 fprintf(stderr,"Unable to add breakpoint\n");
226 | tBREAK tNUM tEOL { struct name_hash *nh;
227 DBG_VALUE value;
228 DEBUG_GetCurrentAddress( &value.addr );
229 DEBUG_FindNearestSymbol(&value.addr, TRUE,
230 &nh, 0, NULL);
231 if( nh != NULL )
233 DEBUG_GetLineNumberAddr(nh, $2, &value.addr, TRUE);
234 value.type = NULL;
235 value.cookie = DV_TARGET;
236 DEBUG_AddBreakpoint( &value );
238 else
240 fprintf(stderr,"Unable to add breakpoint\n");
244 | tBREAK tEOL { DBG_VALUE value;
245 DEBUG_GetCurrentAddress( &value.addr );
246 value.type = NULL;
247 value.cookie = DV_TARGET;
248 DEBUG_AddBreakpoint( &value );
251 watch_command:
252 tWATCH '*' expr_addr tEOL { DEBUG_AddWatchpoint( &$3, 1 );
253 DEBUG_FreeExprMem(); }
254 | tWATCH tIDENTIFIER tEOL { DBG_VALUE value;
255 if( DEBUG_GetSymbolValue($2, -1, &value, TRUE) )
256 DEBUG_AddWatchpoint( &value, 1 );
257 else
258 fprintf(stderr,"Unable to add breakpoint\n");
261 info_command:
262 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
263 | tINFO tCLASS tSTRING tEOL { DEBUG_InfoClass( $3 ); DEBUG_FreeExprMem(); }
264 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
265 | tINFO tMODULE expr_value tEOL { DEBUG_DumpModule( $3 ); DEBUG_FreeExprMem(); }
266 | tINFO tQUEUE expr_value tEOL { DEBUG_DumpQueue( $3 ); DEBUG_FreeExprMem(); }
267 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
268 | tINFO tSEGMENTS expr_value tEOL { DEBUG_InfoSegments( $3, 1 ); DEBUG_FreeExprMem(); }
269 | tINFO tSEGMENTS tEOL { DEBUG_InfoSegments( 0, -1 ); }
270 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
271 | tINFO tMAPS tEOL { DEBUG_InfoVirtual(); }
272 | tINFO tWND expr_value tEOL { DEBUG_InfoWindow( (HWND)$3 );
273 DEBUG_FreeExprMem(); }
274 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
275 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
277 walk_command:
278 tWALK tCLASS tEOL { DEBUG_WalkClasses(); }
279 | tWALK tMODULE tEOL { DEBUG_WalkModules(); }
280 | tWALK tQUEUE tEOL { DEBUG_WalkQueues(); }
281 | tWALK tWND tEOL { DEBUG_WalkWindows( 0, 0 ); }
282 | tWALK tWND tNUM tEOL { DEBUG_WalkWindows( $3, 0 ); }
283 | tWALK tPROCESS tEOL { DEBUG_WalkProcess(); }
284 | tWALK tMODREF expr_value tEOL { DEBUG_WalkModref( $3 ); }
287 type_cast:
288 '(' type_expr ')' { $$ = $2; }
290 type_expr:
291 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
292 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
293 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
294 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
295 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
296 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
297 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
298 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
299 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
300 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
301 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
302 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
303 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
304 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
305 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
306 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
307 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
308 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
310 expr_addr:
311 expr { $$ = DEBUG_EvalExpr($1); }
313 expr_value:
314 expr { DBG_VALUE value = DEBUG_EvalExpr($1);
315 /* expr_value is typed as an integer */
316 if (!value.addr.off ||
317 !DEBUG_READ_MEM((void*)value.addr.off, &$$, sizeof($$)))
318 $$ = 0; }
320 * The expr rule builds an expression tree. When we are done, we call
321 * EvalExpr to evaluate the value of the expression. The advantage of
322 * the two-step approach is that it is possible to save expressions for
323 * use in 'display' commands, and in conditional watchpoints.
325 expr:
326 tNUM { $$ = DEBUG_ConstExpr($1); }
327 | tSTRING { $$ = DEBUG_StringExpr($1); }
328 | tREG { $$ = DEBUG_RegisterExpr($1); }
329 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
330 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
331 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
332 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
333 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
334 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3, $5); }
335 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
336 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
337 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
338 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
339 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
340 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
341 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
342 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
343 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
344 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
345 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
346 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
347 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
348 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
349 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
350 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
351 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
352 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
353 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
354 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
355 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
356 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
357 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
358 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
359 | '+' expr %prec OP_SIGN { $$ = $2; }
360 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
361 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
362 | '(' expr ')' { $$ = $2; }
363 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
364 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
365 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
368 * The lvalue rule builds an expression tree. This is a limited form
369 * of expression that is suitable to be used as an lvalue.
371 lval_addr:
372 lval { $$ = DEBUG_EvalExpr($1); }
374 lval:
375 lvalue { $$ = $1; }
376 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
378 lvalue:
379 tNUM { $$ = DEBUG_ConstExpr($1); }
380 | tREG { $$ = DEBUG_RegisterExpr($1); }
381 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
382 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
383 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
384 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
388 static void issue_prompt(void)
390 #ifdef DONT_USE_READLINE
391 fprintf(stderr, "Wine-dbg>");
392 #endif
395 static void mode_command(int newmode)
397 if ((newmode == 16) || (newmode == 32)) DEBUG_CurrThread->dbg_mode = newmode;
398 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
401 static WINE_EXCEPTION_FILTER(wine_dbg_cmd)
403 fprintf(stderr, "\nwine_dbg_cmd: ");
404 switch (GetExceptionCode()) {
405 case DEBUG_STATUS_INTERNAL_ERROR:
406 fprintf(stderr, "WineDbg internal error\n");
407 break;
408 case DEBUG_STATUS_NO_SYMBOL:
409 fprintf(stderr, "Undefined symbol\n");
410 break;
411 case DEBUG_STATUS_DIV_BY_ZERO:
412 fprintf(stderr, "Division by zero\n");
413 break;
414 case DEBUG_STATUS_BAD_TYPE:
415 fprintf(stderr, "No type or type mismatch\n");
416 break;
417 default:
418 fprintf(stderr, "Exception %lx\n", GetExceptionCode());
419 break;
421 return EXCEPTION_EXECUTE_HANDLER;
424 /***********************************************************************
425 * DEBUG_Exit
427 * Kill current process.
430 void DEBUG_Exit( DWORD exit_code )
432 TASK_KillTask( 0 ); /* FIXME: should not be necessary */
433 TerminateProcess( DEBUG_CurrProcess->handle, exit_code );
436 /***********************************************************************
437 * DEBUG_Main
439 * Debugger main loop.
441 BOOL DEBUG_Main( BOOL is_debug, BOOL force, DWORD code )
443 int newmode;
444 BOOL ret_ok;
445 char ch;
447 #ifdef YYDEBUG
448 yydebug = 0;
449 #endif
451 yyin = stdin;
453 DEBUG_SuspendExecution();
455 if (!is_debug)
457 #ifdef __i386__
458 if (DEBUG_IsSelectorSystem(DEBUG_context.SegCs))
459 fprintf( stderr, " in 32-bit code (0x%08lx).\n", DEBUG_context.Eip );
460 else
461 fprintf( stderr, " in 16-bit code (%04x:%04lx).\n",
462 (WORD)DEBUG_context.SegCs, DEBUG_context.Eip );
463 #else
464 fprintf( stderr, " (%p).\n", GET_IP(&DEBUG_context) );
465 #endif
468 if (DEBUG_LoadEntryPoints("Loading new modules symbols:\n"))
469 DEBUG_ProcessDeferredDebug();
471 if (force || !(is_debug && DEBUG_ShouldContinue( code,
472 DEBUG_CurrThread->dbg_exec_mode,
473 &DEBUG_CurrThread->dbg_exec_count )))
475 DBG_ADDR addr;
476 DEBUG_GetCurrentAddress( &addr );
478 #ifdef __i386__
479 switch (newmode = DEBUG_GetSelectorType(addr.seg)) {
480 case 16: case 32: break;
481 default: fprintf(stderr, "Bad CS (%ld)\n", addr.seg); newmode = 32;
483 #else
484 newmode = 32;
485 #endif
486 if (newmode != DEBUG_CurrThread->dbg_mode)
487 fprintf(stderr,"In %d bit mode.\n", DEBUG_CurrThread->dbg_mode = newmode);
489 DEBUG_DoDisplay();
491 if (is_debug || force)
494 * Do a quiet backtrace so that we have an idea of what the situation
495 * is WRT the source files.
497 DEBUG_BackTrace(FALSE);
499 else
501 /* This is a real crash, dump some info */
502 DEBUG_InfoRegisters();
503 DEBUG_InfoStack();
504 #ifdef __i386__
505 if (DEBUG_CurrThread->dbg_mode == 16)
507 DEBUG_InfoSegments( DEBUG_context.SegDs >> 3, 1 );
508 if (DEBUG_context.SegEs != DEBUG_context.SegDs)
509 DEBUG_InfoSegments( DEBUG_context.SegEs >> 3, 1 );
511 DEBUG_InfoSegments( DEBUG_context.SegFs >> 3, 1 );
512 #endif
513 DEBUG_BackTrace(TRUE);
516 if (!is_debug ||
517 (DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_OVER) ||
518 (DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_INSTR))
520 /* Show where we crashed */
521 curr_frame = 0;
522 DEBUG_PrintAddress( &addr, DEBUG_CurrThread->dbg_mode, TRUE );
523 fprintf(stderr,": ");
524 DEBUG_Disasm( &addr, TRUE );
525 fprintf( stderr, "\n" );
528 ret_ok = 0;
531 __TRY
533 issue_prompt();
534 yyparse();
535 flush_symbols();
537 DEBUG_GetCurrentAddress( &addr );
538 if ((ret_ok = DEBUG_ValidateRegisters()))
539 ret_ok = DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear( &addr ), &ch, 1 );
541 __EXCEPT(wine_dbg_cmd)
543 ret_ok = 0;
545 __ENDTRY;
547 } while (!ret_ok);
550 DEBUG_CurrThread->dbg_exec_mode = DEBUG_RestartExecution( DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count );
552 * This will have gotten absorbed into the breakpoint info
553 * if it was used. Otherwise it would have been ignored.
554 * In any case, we don't mess with it any more.
556 if ((DEBUG_CurrThread->dbg_exec_mode == EXEC_CONT) || (DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS))
557 DEBUG_CurrThread->dbg_exec_count = 0;
559 return (DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS) ? 0 : DBG_CONTINUE;
562 int yyerror(char* s)
564 fprintf(stderr,"%s\n", s);
565 return 0;