Rearrange winver detection code and cache the winver value we
[wine.git] / debugger / dbg.y
blobcdbab33af551d671508a24ca14d323d4855b5109
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 "class.h"
23 #include "module.h"
24 #include "task.h"
25 #include "options.h"
26 #include "queue.h"
27 #include "wine/winbase16.h"
28 #include "winnt.h"
29 #include "x11drv.h"
30 #include "win.h"
31 #include "debugger.h"
32 #include "neexe.h"
33 #include "process.h"
34 #include "server.h"
35 #include "main.h"
36 #include "expr.h"
37 #include "user.h"
39 extern FILE * yyin;
40 unsigned int dbg_mode = 0;
41 HANDLE dbg_heap = 0;
42 int curr_frame = 0;
44 static enum exec_mode dbg_exec_mode = EXEC_CONT;
45 static int dbg_exec_count = 0;
47 void issue_prompt(void);
48 void mode_command(int);
49 void flush_symbols(void);
50 int yylex(void);
51 int yyerror(char *);
53 #ifdef DBG_need_heap
54 #define malloc(x) DBG_alloc(x)
55 #define realloc(x,y) DBG_realloc(x,y)
56 #define free(x) DBG_free(x)
57 #endif
59 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
63 %union
65 DBG_ADDR address;
66 enum debug_regs reg;
67 char * string;
68 int integer;
69 struct list_id listing;
70 struct expr * expression;
71 struct datatype * type;
74 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
75 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
76 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
77 %token tPROCESS tMODREF
78 %token tEOL tSTRING tDEBUGSTR
79 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
80 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
81 %token <string> tPATH
82 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
83 %token <integer> tNUM tFORMAT
84 %token <reg> tREG
85 %token tSYMBOLFILE
87 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
88 %token tSTRUCT tUNION tENUM
90 /* %left ',' */
91 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
92 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
93 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
94 /* %left OP_COND */ /* ... ? ... : ... */
95 %left OP_LOR
96 %left OP_LAND
97 %left '|'
98 %left '^'
99 %left '&'
100 %left OP_EQ OP_NE
101 %left '<' '>' OP_LE OP_GE
102 %left OP_SHL OP_SHR
103 %left '+' '-'
104 %left '*' '/' '%'
105 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
106 %left '.' '[' OP_DRF
107 %nonassoc ':'
109 %type <expression> expr lval lvalue
110 %type <type> type_cast type_expr
111 %type <address> expr_addr lval_addr
112 %type <integer> expr_value
113 %type <string> pathname
115 %type <listing> list_arg
119 input: line { issue_prompt(); }
120 | input line { issue_prompt(); }
122 line: command
123 | tEOL
124 | error tEOL { yyerrok; }
126 command:
127 tQUIT tEOL { exit(0); }
128 | tHELP tEOL { DEBUG_Help(); }
129 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
130 | tCONT tEOL { dbg_exec_count = 1;
131 dbg_exec_mode = EXEC_CONT; return 0; }
132 | tCONT tNUM tEOL { dbg_exec_count = $2;
133 dbg_exec_mode = EXEC_CONT; return 0; }
134 | tSTEP tEOL { dbg_exec_count = 1;
135 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
136 | tNEXT tEOL { dbg_exec_count = 1;
137 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
138 | tSTEP tNUM tEOL { dbg_exec_count = $2;
139 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
140 | tNEXT tNUM tEOL { dbg_exec_count = $2;
141 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
142 | tSTEPI tEOL { dbg_exec_count = 1;
143 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
144 | tNEXTI tEOL { dbg_exec_count = 1;
145 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
146 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
147 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
148 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
149 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
150 | tABORT tEOL { kill(getpid(), SIGABRT); }
151 | tMODE tNUM tEOL { mode_command($2); }
152 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
153 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
154 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
155 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
156 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
157 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
158 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
159 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
160 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
161 | tFINISH tEOL { dbg_exec_count = 0;
162 dbg_exec_mode = EXEC_FINISH; return 0; }
163 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
164 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
165 | tDIR tEOL { DEBUG_NukePath(); }
166 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
167 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
168 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
169 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
170 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
171 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
172 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
173 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
174 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
175 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
176 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
177 | list_command
178 | disassemble_command
179 | set_command
180 | x_command
181 | print_command
182 | break_command
183 | info_command
184 | walk_command
186 set_command:
187 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
188 DEBUG_FreeExprMem(); }
189 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
190 DEBUG_FreeExprMem(); }
192 pathname:
193 tIDENTIFIER { $$ = $1; }
194 | tPATH { $$ = $1; }
196 disassemble_command:
197 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
198 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
199 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
201 list_command:
202 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
203 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
204 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
205 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
206 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
208 list_arg:
209 tNUM { $$.sourcefile = NULL; $$.line = $1; }
210 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
211 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
212 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
213 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
214 0, & $$ );
215 DEBUG_FreeExprMem(); }
217 x_command:
218 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
219 DEBUG_FreeExprMem(); }
220 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
221 DEBUG_FreeExprMem(); }
223 print_command:
224 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
225 DEBUG_FreeExprMem(); }
226 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
227 DEBUG_FreeExprMem(); }
229 break_command:
230 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
231 DEBUG_FreeExprMem(); }
232 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
233 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
235 DEBUG_AddBreakpoint( &addr );
237 else
239 fprintf(stderr,"Unable to add breakpoint\n");
242 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
243 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
245 DEBUG_AddBreakpoint( &addr );
247 else
249 fprintf(stderr,"Unable to add breakpoint\n");
252 | tBREAK tNUM tEOL { struct name_hash *nh;
253 DBG_ADDR addr;
254 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
256 addr.type = NULL;
257 addr.seg = CS_reg(&DEBUG_context);
258 addr.off = EIP_reg(&DEBUG_context);
260 if (ISV86(&DEBUG_context))
261 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
262 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
263 GlobalUnlock16( GetCurrentTask() );
264 DEBUG_FindNearestSymbol(&addr, TRUE,
265 &nh, 0, NULL);
266 if( nh != NULL )
268 DEBUG_GetLineNumberAddr(nh,
269 $2, &addr, TRUE);
270 DEBUG_AddBreakpoint( &addr );
272 else
274 fprintf(stderr,"Unable to add breakpoint\n");
278 | tBREAK tEOL { DBG_ADDR addr;
279 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
281 addr.type = NULL;
282 addr.seg = CS_reg(&DEBUG_context);
283 addr.off = EIP_reg(&DEBUG_context);
285 if (ISV86(&DEBUG_context))
286 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
287 GlobalUnlock16( GetCurrentTask() );
288 DEBUG_AddBreakpoint( &addr );
291 info_command:
292 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
293 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
294 DEBUG_FreeExprMem(); }
295 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
296 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
297 DEBUG_FreeExprMem(); }
298 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
299 DEBUG_FreeExprMem(); }
300 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
301 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
302 DEBUG_FreeExprMem(); }
303 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
304 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
305 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
306 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
307 DEBUG_FreeExprMem(); }
308 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
309 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
311 walk_command:
312 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
313 | tWALK tMODULE tEOL { NE_WalkModules(); }
314 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
315 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
316 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
317 | tWALK tPROCESS tEOL { PROCESS_WalkProcess(); }
318 | tWALK tMODREF expr_value tEOL { MODULE_WalkModref( $3 ); }
321 type_cast:
322 '(' type_expr ')' { $$ = $2; }
324 type_expr:
325 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
326 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
327 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
328 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
329 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
330 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
331 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
332 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
333 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
334 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
335 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
336 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
337 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
338 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
339 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
340 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
341 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
342 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
344 expr_addr:
345 expr { $$ = DEBUG_EvalExpr($1); }
347 expr_value:
348 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
349 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
351 * The expr rule builds an expression tree. When we are done, we call
352 * EvalExpr to evaluate the value of the expression. The advantage of
353 * the two-step approach is that it is possible to save expressions for
354 * use in 'display' commands, and in conditional watchpoints.
356 expr:
357 tNUM { $$ = DEBUG_ConstExpr($1); }
358 | tSTRING { $$ = DEBUG_StringExpr($1); }
359 | tREG { $$ = DEBUG_RegisterExpr($1); }
360 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
361 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
362 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
363 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
364 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
365 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
366 $5); }
367 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
368 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
369 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
370 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
371 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
372 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
373 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
374 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
375 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
376 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
377 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
378 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
379 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
380 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
381 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
382 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
383 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
384 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
385 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
386 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
387 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
388 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
389 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
390 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
391 | '+' expr %prec OP_SIGN { $$ = $2; }
392 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
393 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
394 | '(' expr ')' { $$ = $2; }
395 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
396 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
397 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
400 * The lvalue rule builds an expression tree. This is a limited form
401 * of expression that is suitable to be used as an lvalue.
403 lval_addr:
404 lval { $$ = DEBUG_EvalExpr($1); }
406 lval:
407 lvalue { $$ = $1; }
408 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
410 lvalue:
411 tNUM { $$ = DEBUG_ConstExpr($1); }
412 | tREG { $$ = DEBUG_RegisterExpr($1); }
413 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
414 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
415 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
416 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
420 void
421 issue_prompt(){
422 #ifdef DONT_USE_READLINE
423 fprintf(stderr,"Wine-dbg>");
424 #endif
427 void mode_command(int newmode)
429 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
430 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
434 /***********************************************************************
435 * DEBUG_Main
437 * Debugger main loop.
439 static void DEBUG_Main( int signal )
441 static int loaded_symbols = 0;
442 static BOOL frozen = FALSE;
443 static BOOL in_debugger = FALSE;
444 char SymbolTableFile[256];
445 int newmode;
446 BOOL ret_ok;
447 #ifdef YYDEBUG
448 yydebug = 0;
449 #endif
451 if (in_debugger)
453 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
454 exit(1);
456 in_debugger = TRUE;
457 yyin = stdin;
459 DEBUG_SetBreakpoints( FALSE );
461 if (!loaded_symbols)
463 loaded_symbols++;
465 if ( !frozen )
467 /* Don't freeze thread currently holding the X crst! */
468 EnterCriticalSection( &X11DRV_CritSection );
469 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
470 LeaveCriticalSection( &X11DRV_CritSection );
471 frozen = TRUE;
474 #ifdef DBG_need_heap
476 * Initialize the debugger heap.
478 dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
479 #endif
482 * Initialize the type handling stuff.
484 DEBUG_InitTypes();
487 * In some cases we can read the stabs information directly
488 * from the executable. If this is the case, we don't need
489 * to bother with trying to read a symbol file, as the stabs
490 * also have line number and local variable information.
491 * As long as gcc is used for the compiler, stabs will
492 * be the default. On SVr4, DWARF could be used, but we
493 * don't grok that yet, and in this case we fall back to using
494 * the wine.sym file.
496 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
498 char *symfilename = "wine.sym";
499 struct stat statbuf;
500 if (-1 == stat(symfilename, &statbuf) )
501 symfilename = LIBDIR "wine.sym";
503 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
504 SymbolTableFile, sizeof(SymbolTableFile));
505 DEBUG_ReadSymbolTable( SymbolTableFile );
508 DEBUG_LoadEntryPoints();
509 DEBUG_ProcessDeferredDebug();
512 #if 0
513 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
514 EIP_reg(&DEBUG_context),
515 dbg_exec_mode, dbg_exec_count);
517 sleep(1);
518 #endif
520 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
521 &dbg_exec_count ))
523 DBG_ADDR addr;
524 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
526 addr.seg = CS_reg(&DEBUG_context);
527 addr.off = EIP_reg(&DEBUG_context);
528 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
529 addr.type = NULL;
530 DBG_FIX_ADDR_SEG( &addr, 0 );
532 GlobalUnlock16( GetCurrentTask() );
534 if ( !frozen )
536 /* Don't freeze thread currently holding the X crst! */
537 EnterCriticalSection( &X11DRV_CritSection );
538 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
539 LeaveCriticalSection( &X11DRV_CritSection );
540 frozen = TRUE;
543 /* Put the display in a correct state */
544 USER_Driver->pBeginDebugging();
546 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
547 if (newmode != dbg_mode)
548 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
550 DEBUG_DoDisplay();
552 if (signal != SIGTRAP) /* This is a real crash, dump some info */
554 DEBUG_InfoRegisters();
555 DEBUG_InfoStack();
556 if (dbg_mode == 16)
558 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
559 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
560 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
562 DEBUG_BackTrace();
564 else
567 * Do a quiet backtrace so that we have an idea of what the situation
568 * is WRT the source files.
570 DEBUG_SilentBackTrace();
573 if ((signal != SIGTRAP) ||
574 (dbg_exec_mode == EXEC_STEPI_OVER) ||
575 (dbg_exec_mode == EXEC_STEPI_INSTR))
577 /* Show where we crashed */
578 curr_frame = 0;
579 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
580 fprintf(stderr,": ");
581 if (DBG_CHECK_READ_PTR( &addr, 1 ))
583 DEBUG_Disasm( &addr, TRUE );
584 fprintf(stderr,"\n");
588 ret_ok = 0;
591 issue_prompt();
592 yyparse();
593 flush_symbols();
594 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
595 addr.off = EIP_reg(&DEBUG_context);
596 DBG_FIX_ADDR_SEG( &addr, 0 );
597 ret_ok = DEBUG_ValidateRegisters();
598 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
599 } while (!ret_ok);
602 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
604 * This will have gotten absorbed into the breakpoint info
605 * if it was used. Otherwise it would have been ignored.
606 * In any case, we don't mess with it any more.
608 if( dbg_exec_mode == EXEC_CONT )
610 dbg_exec_count = 0;
612 if ( frozen )
614 CLIENT_DebuggerRequest( DEBUGGER_UNFREEZE_ALL );
615 frozen = FALSE;
619 in_debugger = FALSE;
621 USER_Driver->pEndDebugging();
626 /***********************************************************************
627 * DebugBreak (KERNEL.203) (KERNEL32.181)
629 void DebugBreak16( CONTEXT *regs )
631 char module[10];
632 if (!GetModuleName16( GetCurrentTask(), module, sizeof(module) ))
633 strcpy( module, "???" );
634 fprintf( stderr, "%s called DebugBreak\n", module );
635 DEBUG_context = *regs;
636 DEBUG_Main( SIGTRAP );
640 void ctx_debug( int signal, CONTEXT *regs )
642 DEBUG_context = *regs;
643 DEBUG_Main( signal );
644 *regs = DEBUG_context;
647 void wine_debug( int signal, SIGCONTEXT *regs )
649 #if 0
650 DWORD *stack = (DWORD *)ESP_sig(regs);
651 *(--stack) = 0;
652 *(--stack) = 0;
653 *(--stack) = EH_NONCONTINUABLE;
654 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
655 *(--stack) = EIP_sig(regs);
656 ESP_sig(regs) = (DWORD)stack;
657 EIP_sig(regs) = (DWORD)RaiseException;
658 #else
659 DEBUG_SetSigContext( regs );
660 DEBUG_Main( signal );
661 DEBUG_GetSigContext( regs );
662 #endif
665 int yyerror(char * s)
667 fprintf(stderr,"%s\n", s);
668 return 0;