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