Fixes for ShellExecuteEx.
[wine.git] / debugger / dbg.y
blob663a4e3bb6b997ee75fdaab69974f1c8bc972873
1 %{
2 /*
3 * Parser for command lines in the Wine debugger
5 * Copyright 1993 Eric Youngdale
6 * Copyright 1995 Morten Welinder
7 */
9 #include "config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <signal.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #ifdef HAVE_ALLOCA_H
18 #include <alloca.h>
19 #endif
21 #include "winbase.h"
22 #include "module.h"
23 #include "task.h"
24 #include "options.h"
25 #include "queue.h"
26 #include "wine/winbase16.h"
27 #include "winnt.h"
28 #include "x11drv.h"
29 #include "win.h"
30 #include "debugger.h"
31 #include "neexe.h"
32 #include "process.h"
33 #include "server.h"
34 #include "main.h"
35 #include "expr.h"
36 #include "user.h"
38 extern FILE * yyin;
39 unsigned int dbg_mode = 0;
40 HANDLE dbg_heap = 0;
41 int curr_frame = 0;
43 static enum exec_mode dbg_exec_mode = EXEC_CONT;
44 static int dbg_exec_count = 0;
46 void issue_prompt(void);
47 void mode_command(int);
48 void flush_symbols(void);
49 int yylex(void);
50 int yyerror(char *);
52 #ifdef DBG_need_heap
53 #define malloc(x) DBG_alloc(x)
54 #define realloc(x,y) DBG_realloc(x,y)
55 #define free(x) DBG_free(x)
56 #endif
58 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
62 %union
64 DBG_ADDR address;
65 enum debug_regs reg;
66 char * string;
67 int integer;
68 struct list_id listing;
69 struct expr * expression;
70 struct datatype * type;
73 %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
74 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
75 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
76 %token tPROCESS tMODREF
77 %token tEOL tSTRING tDEBUGSTR
78 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
79 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
80 %token <string> tPATH
81 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
82 %token <integer> tNUM tFORMAT
83 %token <reg> tREG
84 %token tSYMBOLFILE
86 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
87 %token tSTRUCT tUNION tENUM
89 /* %left ',' */
90 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
91 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
92 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
93 /* %left OP_COND */ /* ... ? ... : ... */
94 %left OP_LOR
95 %left OP_LAND
96 %left '|'
97 %left '^'
98 %left '&'
99 %left OP_EQ OP_NE
100 %left '<' '>' OP_LE OP_GE
101 %left OP_SHL OP_SHR
102 %left '+' '-'
103 %left '*' '/' '%'
104 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
105 %left '.' '[' OP_DRF
106 %nonassoc ':'
108 %type <expression> expr lval lvalue
109 %type <type> type_cast type_expr
110 %type <address> expr_addr lval_addr
111 %type <integer> expr_value
112 %type <string> pathname
114 %type <listing> list_arg
118 input: line { issue_prompt(); }
119 | input line { issue_prompt(); }
121 line: command
122 | tEOL
123 | error tEOL { yyerrok; }
125 command:
126 tQUIT tEOL { DEBUG_Exit(0); }
127 | tHELP tEOL { DEBUG_Help(); }
128 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
129 | tCONT tEOL { dbg_exec_count = 1;
130 dbg_exec_mode = EXEC_CONT; return 0; }
131 | tPASS tEOL { dbg_exec_count = 1;
132 dbg_exec_mode = EXEC_PASS; return 0; }
133 | tCONT tNUM tEOL { dbg_exec_count = $2;
134 dbg_exec_mode = EXEC_CONT; return 0; }
135 | tSTEP tEOL { dbg_exec_count = 1;
136 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
137 | tNEXT tEOL { dbg_exec_count = 1;
138 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
139 | tSTEP tNUM tEOL { dbg_exec_count = $2;
140 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
141 | tNEXT tNUM tEOL { dbg_exec_count = $2;
142 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
143 | tSTEPI tEOL { dbg_exec_count = 1;
144 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
145 | tNEXTI tEOL { dbg_exec_count = 1;
146 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
147 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
148 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
149 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
150 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
151 | tABORT tEOL { kill(getpid(), SIGABRT); }
152 | tMODE tNUM tEOL { mode_command($2); }
153 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
154 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
155 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
156 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
157 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
158 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
159 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
160 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
161 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
162 | tFINISH tEOL { dbg_exec_count = 0;
163 dbg_exec_mode = EXEC_FINISH; return 0; }
164 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
165 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
166 | tDIR tEOL { DEBUG_NukePath(); }
167 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
168 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
169 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
170 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
171 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
172 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
173 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
174 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
175 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
176 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
177 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
178 | list_command
179 | disassemble_command
180 | set_command
181 | x_command
182 | print_command
183 | break_command
184 | info_command
185 | walk_command
187 set_command:
188 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
189 DEBUG_FreeExprMem(); }
190 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
191 DEBUG_FreeExprMem(); }
193 pathname:
194 tIDENTIFIER { $$ = $1; }
195 | tPATH { $$ = $1; }
197 disassemble_command:
198 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
199 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
200 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
202 list_command:
203 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
204 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
205 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
206 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
207 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
209 list_arg:
210 tNUM { $$.sourcefile = NULL; $$.line = $1; }
211 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
212 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
213 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
214 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
215 0, & $$ );
216 DEBUG_FreeExprMem(); }
218 x_command:
219 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
220 DEBUG_FreeExprMem(); }
221 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
222 DEBUG_FreeExprMem(); }
224 print_command:
225 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
226 DEBUG_FreeExprMem(); }
227 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
228 DEBUG_FreeExprMem(); }
230 break_command:
231 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
232 DEBUG_FreeExprMem(); }
233 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
234 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
236 DEBUG_AddBreakpoint( &addr );
238 else
240 fprintf(stderr,"Unable to add breakpoint\n");
243 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
244 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
246 DEBUG_AddBreakpoint( &addr );
248 else
250 fprintf(stderr,"Unable to add breakpoint\n");
253 | tBREAK tNUM tEOL { struct name_hash *nh;
254 DBG_ADDR addr;
255 DEBUG_GetCurrentAddress( &addr );
256 DEBUG_FindNearestSymbol(&addr, TRUE,
257 &nh, 0, NULL);
258 if( nh != NULL )
260 DEBUG_GetLineNumberAddr(nh,
261 $2, &addr, TRUE);
262 DEBUG_AddBreakpoint( &addr );
264 else
266 fprintf(stderr,"Unable to add breakpoint\n");
270 | tBREAK tEOL { DBG_ADDR addr;
271 DEBUG_GetCurrentAddress( &addr );
272 DEBUG_AddBreakpoint( &addr );
275 info_command:
276 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
277 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (struct tagCLASS *)$3 );
278 DEBUG_FreeExprMem(); }
279 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
280 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
281 DEBUG_FreeExprMem(); }
282 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
283 DEBUG_FreeExprMem(); }
284 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
285 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
286 DEBUG_FreeExprMem(); }
287 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
288 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
289 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
290 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
291 DEBUG_FreeExprMem(); }
292 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
293 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
295 walk_command:
296 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
297 | tWALK tMODULE tEOL { NE_WalkModules(); }
298 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
299 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
300 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
301 | tWALK tPROCESS tEOL { PROCESS_WalkProcess(); }
302 | tWALK tMODREF expr_value tEOL { MODULE_WalkModref( $3 ); }
305 type_cast:
306 '(' type_expr ')' { $$ = $2; }
308 type_expr:
309 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
310 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
311 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
312 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
313 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
314 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
315 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
316 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
317 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
318 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
319 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
320 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
321 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
322 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
323 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
324 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
325 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
326 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
328 expr_addr:
329 expr { $$ = DEBUG_EvalExpr($1); }
331 expr_value:
332 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
333 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
335 * The expr rule builds an expression tree. When we are done, we call
336 * EvalExpr to evaluate the value of the expression. The advantage of
337 * the two-step approach is that it is possible to save expressions for
338 * use in 'display' commands, and in conditional watchpoints.
340 expr:
341 tNUM { $$ = DEBUG_ConstExpr($1); }
342 | tSTRING { $$ = DEBUG_StringExpr($1); }
343 | tREG { $$ = DEBUG_RegisterExpr($1); }
344 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
345 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
346 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
347 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
348 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
349 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
350 $5); }
351 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
352 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
353 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
354 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
355 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
356 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
357 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
358 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
359 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
360 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
361 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
362 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
363 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
364 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
365 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
366 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
367 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
368 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
369 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
370 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
371 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
372 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
373 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
374 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
375 | '+' expr %prec OP_SIGN { $$ = $2; }
376 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
377 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
378 | '(' expr ')' { $$ = $2; }
379 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
380 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
381 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
384 * The lvalue rule builds an expression tree. This is a limited form
385 * of expression that is suitable to be used as an lvalue.
387 lval_addr:
388 lval { $$ = DEBUG_EvalExpr($1); }
390 lval:
391 lvalue { $$ = $1; }
392 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
394 lvalue:
395 tNUM { $$ = DEBUG_ConstExpr($1); }
396 | tREG { $$ = DEBUG_RegisterExpr($1); }
397 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
398 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
399 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
400 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
404 void
405 issue_prompt(){
406 #ifdef DONT_USE_READLINE
407 fprintf(stderr,"Wine-dbg>");
408 #endif
411 void mode_command(int newmode)
413 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
414 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
417 /***********************************************************************
418 * DEBUG_Freeze
420 static void DEBUG_Freeze( BOOL freeze )
422 static BOOL frozen = FALSE;
424 if ( freeze && !frozen )
426 if ( X11DRV_CritSection.LockSemaphore )
428 /* Don't freeze thread currently holding the X crst! */
429 EnterCriticalSection( &X11DRV_CritSection );
430 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
431 LeaveCriticalSection( &X11DRV_CritSection );
433 else
434 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
436 frozen = TRUE;
439 if ( !freeze && frozen )
441 CLIENT_DebuggerRequest( DEBUGGER_UNFREEZE_ALL );
442 frozen = FALSE;
446 /***********************************************************************
447 * DEBUG_Exit
449 * Kill current process.
451 void DEBUG_Exit( DWORD exit_code )
453 DEBUG_Freeze( FALSE );
455 TASK_KillTask( 0 ); /* FIXME: should not be necessary */
456 TerminateProcess( GetCurrentProcess(), exit_code );
459 /***********************************************************************
460 * DEBUG_Main
462 * Debugger main loop.
464 static void DEBUG_Main( BOOL is_debug )
466 static int loaded_symbols = 0;
467 static BOOL in_debugger = FALSE;
468 char SymbolTableFile[256];
469 int newmode;
470 BOOL ret_ok;
471 #ifdef YYDEBUG
472 yydebug = 0;
473 #endif
475 if (in_debugger)
477 fprintf( stderr, " inside debugger, trying to invoke external debugger.\n" );
478 DEBUG_ExternalDebugger();
479 DEBUG_Exit(1);
481 in_debugger = TRUE;
482 yyin = stdin;
484 DEBUG_SetBreakpoints( FALSE );
486 if (!is_debug)
488 #ifdef __i386__
489 if (IS_SELECTOR_SYSTEM(CS_reg(&DEBUG_context)))
490 fprintf( stderr, " in 32-bit code (0x%08lx).\n", EIP_reg(&DEBUG_context));
491 else
492 fprintf( stderr, " in 16-bit code (%04x:%04lx).\n",
493 (WORD)CS_reg(&DEBUG_context), EIP_reg(&DEBUG_context) );
494 #else
495 fprintf( stderr, " (%p).\n", GET_IP(&DEBUG_context) );
496 #endif
499 if (!loaded_symbols)
501 loaded_symbols++;
503 DEBUG_Freeze( TRUE );
505 #ifdef DBG_need_heap
507 * Initialize the debugger heap.
509 dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
510 #endif
513 * Initialize the type handling stuff.
515 DEBUG_InitTypes();
516 DEBUG_InitCVDataTypes();
519 * In some cases we can read the stabs information directly
520 * from the executable. If this is the case, we don't need
521 * to bother with trying to read a symbol file, as the stabs
522 * also have line number and local variable information.
523 * As long as gcc is used for the compiler, stabs will
524 * be the default. On SVr4, DWARF could be used, but we
525 * don't grok that yet, and in this case we fall back to using
526 * the wine.sym file.
528 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
530 char *symfilename = "wine.sym";
531 struct stat statbuf;
532 if (-1 == stat(symfilename, &statbuf) )
533 symfilename = LIBDIR "wine.sym";
535 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
536 SymbolTableFile, sizeof(SymbolTableFile));
537 DEBUG_ReadSymbolTable( SymbolTableFile );
539 DEBUG_LoadEntryPoints(NULL);
540 DEBUG_ProcessDeferredDebug();
542 else
544 if (DEBUG_LoadEntryPoints("Loading new modules symbols:\n"))
545 DEBUG_ProcessDeferredDebug();
548 #if 0
549 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
550 EIP_reg(&DEBUG_context),
551 dbg_exec_mode, dbg_exec_count);
553 sleep(1);
554 #endif
556 if (!is_debug || !DEBUG_ShouldContinue( dbg_exec_mode, &dbg_exec_count ))
558 DBG_ADDR addr;
559 DEBUG_GetCurrentAddress( &addr );
561 DEBUG_Freeze( TRUE );
563 /* Put the display in a correct state */
564 if (USER_Driver) USER_Driver->pBeginDebugging();
566 #ifdef __i386__
567 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
568 #else
569 newmode = 32;
570 #endif
571 if (newmode != dbg_mode)
572 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
574 DEBUG_DoDisplay();
576 if (!is_debug) /* This is a real crash, dump some info */
578 DEBUG_InfoRegisters();
579 DEBUG_InfoStack();
580 #ifdef __i386__
581 if (dbg_mode == 16)
583 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
584 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
585 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
587 LDT_Print( SELECTOR_TO_ENTRY(FS_reg(&DEBUG_context)), 1 );
588 #endif
589 DEBUG_BackTrace();
591 else
594 * Do a quiet backtrace so that we have an idea of what the situation
595 * is WRT the source files.
597 DEBUG_SilentBackTrace();
600 if (!is_debug ||
601 (dbg_exec_mode == EXEC_STEPI_OVER) ||
602 (dbg_exec_mode == EXEC_STEPI_INSTR))
604 /* Show where we crashed */
605 curr_frame = 0;
606 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
607 fprintf(stderr,": ");
608 if (DBG_CHECK_READ_PTR( &addr, 1 ))
610 DEBUG_Disasm( &addr, TRUE );
611 fprintf(stderr,"\n");
615 ret_ok = 0;
618 issue_prompt();
619 yyparse();
620 flush_symbols();
622 DEBUG_GetCurrentAddress( &addr );
623 ret_ok = DEBUG_ValidateRegisters();
624 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
625 } while (!ret_ok);
628 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
630 * This will have gotten absorbed into the breakpoint info
631 * if it was used. Otherwise it would have been ignored.
632 * In any case, we don't mess with it any more.
634 if ((dbg_exec_mode == EXEC_CONT) || (dbg_exec_mode == EXEC_PASS))
636 dbg_exec_count = 0;
638 DEBUG_Freeze( FALSE );
641 in_debugger = FALSE;
643 if (USER_Driver) USER_Driver->pEndDebugging();
647 DWORD wine_debugger( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
649 BOOL is_debug = FALSE;
651 if (first_chance && !Options.debug) return 0; /* pass to app first */
653 switch(rec->ExceptionCode)
655 case EXCEPTION_BREAKPOINT:
656 case EXCEPTION_SINGLE_STEP:
657 is_debug = TRUE;
658 break;
659 case CONTROL_C_EXIT:
660 if (!Options.debug) DEBUG_Exit(0);
661 break;
664 if (!is_debug)
666 /* print some infos */
667 fprintf( stderr, "%s: ",
668 first_chance ? "First chance exception" : "Unhandled exception" );
669 switch(rec->ExceptionCode)
671 case EXCEPTION_INT_DIVIDE_BY_ZERO:
672 fprintf( stderr, "divide by zero" );
673 break;
674 case EXCEPTION_INT_OVERFLOW:
675 fprintf( stderr, "overflow" );
676 break;
677 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
678 fprintf( stderr, "array bounds " );
679 break;
680 case EXCEPTION_ILLEGAL_INSTRUCTION:
681 fprintf( stderr, "illegal instruction" );
682 break;
683 case EXCEPTION_STACK_OVERFLOW:
684 fprintf( stderr, "stack overflow" );
685 break;
686 case EXCEPTION_PRIV_INSTRUCTION:
687 fprintf( stderr, "priviledged instruction" );
688 break;
689 case EXCEPTION_ACCESS_VIOLATION:
690 if (rec->NumberParameters == 2)
691 fprintf( stderr, "page fault on %s access to 0x%08lx",
692 rec->ExceptionInformation[0] ? "write" : "read",
693 rec->ExceptionInformation[1] );
694 else
695 fprintf( stderr, "page fault" );
696 break;
697 case EXCEPTION_DATATYPE_MISALIGNMENT:
698 fprintf( stderr, "Alignment" );
699 break;
700 case CONTROL_C_EXIT:
701 fprintf( stderr, "^C" );
702 break;
703 case EXCEPTION_CRITICAL_SECTION_WAIT:
704 fprintf( stderr, "critical section %08lx wait failed", rec->ExceptionInformation[0] );
705 break;
706 default:
707 fprintf( stderr, "%08lx", rec->ExceptionCode );
708 break;
712 DEBUG_context = *context;
713 DEBUG_Main( is_debug );
714 *context = DEBUG_context;
715 return (dbg_exec_mode == EXEC_PASS) ? 0 : DBG_CONTINUE;
718 int yyerror(char * s)
720 fprintf(stderr,"%s\n", s);
721 return 0;