When opening the file we don't need MMIO_EXCLUSIVE
[wine/multimedia.git] / debugger / dbg.y
blob2bd5302508d3d6ab20f1ff68aefd23297309dfef
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 "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 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 tEOL tSTRING tDEBUGSTR
77 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
78 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
79 %token <string> tPATH
80 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
81 %token <integer> tNUM tFORMAT
82 %token <reg> tREG
83 %token tSYMBOLFILE
85 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
86 %token tSTRUCT tUNION tENUM
88 /* %left ',' */
89 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
90 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
91 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
92 /* %left OP_COND */ /* ... ? ... : ... */
93 %left OP_LOR
94 %left OP_LAND
95 %left '|'
96 %left '^'
97 %left '&'
98 %left OP_EQ OP_NE
99 %left '<' '>' OP_LE OP_GE
100 %left OP_SHL OP_SHR
101 %left '+' '-'
102 %left '*' '/' '%'
103 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
104 %left '.' '[' OP_DRF
105 %nonassoc ':'
107 %type <expression> expr lval lvalue
108 %type <type> type_cast type_expr
109 %type <address> expr_addr lval_addr
110 %type <integer> expr_value
111 %type <string> pathname
113 %type <listing> list_arg
117 input: line { issue_prompt(); }
118 | input line { issue_prompt(); }
120 line: command
121 | tEOL
122 | error tEOL { yyerrok; }
124 command:
125 tQUIT tEOL { exit(0); }
126 | tHELP tEOL { DEBUG_Help(); }
127 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
128 | tCONT tEOL { dbg_exec_count = 1;
129 dbg_exec_mode = EXEC_CONT; return 0; }
130 | tCONT tNUM tEOL { dbg_exec_count = $2;
131 dbg_exec_mode = EXEC_CONT; return 0; }
132 | tSTEP tEOL { dbg_exec_count = 1;
133 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
134 | tNEXT tEOL { dbg_exec_count = 1;
135 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
136 | tSTEP tNUM tEOL { dbg_exec_count = $2;
137 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
138 | tNEXT tNUM tEOL { dbg_exec_count = $2;
139 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
140 | tSTEPI tEOL { dbg_exec_count = 1;
141 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
142 | tNEXTI tEOL { dbg_exec_count = 1;
143 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
144 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
145 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
146 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
147 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
148 | tABORT tEOL { kill(getpid(), SIGABRT); }
149 | tMODE tNUM tEOL { mode_command($2); }
150 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
151 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
152 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
153 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
154 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
155 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
156 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
157 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
158 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
159 | tFINISH tEOL { dbg_exec_count = 0;
160 dbg_exec_mode = EXEC_FINISH; return 0; }
161 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
162 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
163 | tDIR tEOL { DEBUG_NukePath(); }
164 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
165 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
166 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
167 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
168 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
169 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
170 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
171 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
172 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
173 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
174 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
175 | list_command
176 | disassemble_command
177 | set_command
178 | x_command
179 | print_command
180 | break_command
181 | info_command
182 | walk_command
184 set_command:
185 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
186 DEBUG_FreeExprMem(); }
187 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
188 DEBUG_FreeExprMem(); }
190 pathname:
191 tIDENTIFIER { $$ = $1; }
192 | tPATH { $$ = $1; }
194 disassemble_command:
195 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
196 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
197 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
199 list_command:
200 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
201 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
202 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
203 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
204 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
206 list_arg:
207 tNUM { $$.sourcefile = NULL; $$.line = $1; }
208 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
209 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
210 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
211 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
212 0, & $$ );
213 DEBUG_FreeExprMem(); }
215 x_command:
216 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
217 DEBUG_FreeExprMem(); }
218 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
219 DEBUG_FreeExprMem(); }
221 print_command:
222 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
223 DEBUG_FreeExprMem(); }
224 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
225 DEBUG_FreeExprMem(); }
227 break_command:
228 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
229 DEBUG_FreeExprMem(); }
230 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
231 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
233 DEBUG_AddBreakpoint( &addr );
235 else
237 fprintf(stderr,"Unable to add breakpoint\n");
240 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
241 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
243 DEBUG_AddBreakpoint( &addr );
245 else
247 fprintf(stderr,"Unable to add breakpoint\n");
250 | tBREAK tNUM tEOL { struct name_hash *nh;
251 DBG_ADDR addr;
252 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
254 addr.type = NULL;
255 addr.seg = CS_reg(&DEBUG_context);
256 addr.off = EIP_reg(&DEBUG_context);
258 if (ISV86(&DEBUG_context))
259 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
260 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
261 GlobalUnlock16( GetCurrentTask() );
262 DEBUG_FindNearestSymbol(&addr, TRUE,
263 &nh, 0, NULL);
264 if( nh != NULL )
266 DEBUG_GetLineNumberAddr(nh,
267 $2, &addr, TRUE);
268 DEBUG_AddBreakpoint( &addr );
270 else
272 fprintf(stderr,"Unable to add breakpoint\n");
276 | tBREAK tEOL { DBG_ADDR addr;
277 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
279 addr.type = NULL;
280 addr.seg = CS_reg(&DEBUG_context);
281 addr.off = EIP_reg(&DEBUG_context);
283 if (ISV86(&DEBUG_context))
284 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
285 GlobalUnlock16( GetCurrentTask() );
286 DEBUG_AddBreakpoint( &addr );
289 info_command:
290 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
291 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
292 DEBUG_FreeExprMem(); }
293 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
294 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
295 DEBUG_FreeExprMem(); }
296 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
297 DEBUG_FreeExprMem(); }
298 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
299 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
300 DEBUG_FreeExprMem(); }
301 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
302 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
303 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
304 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
305 DEBUG_FreeExprMem(); }
306 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
307 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
309 walk_command:
310 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
311 | tWALK tMODULE tEOL { NE_WalkModules(); }
312 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
313 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
314 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
317 type_cast:
318 '(' type_expr ')' { $$ = $2; }
320 type_expr:
321 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
322 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
323 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
324 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
325 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
326 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
327 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
328 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
329 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
330 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
331 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
332 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
333 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
334 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
335 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
336 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
337 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
338 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
340 expr_addr:
341 expr { $$ = DEBUG_EvalExpr($1); }
343 expr_value:
344 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
345 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
347 * The expr rule builds an expression tree. When we are done, we call
348 * EvalExpr to evaluate the value of the expression. The advantage of
349 * the two-step approach is that it is possible to save expressions for
350 * use in 'display' commands, and in conditional watchpoints.
352 expr:
353 tNUM { $$ = DEBUG_ConstExpr($1); }
354 | tSTRING { $$ = DEBUG_StringExpr($1); }
355 | tREG { $$ = DEBUG_RegisterExpr($1); }
356 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
357 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
358 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
359 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
360 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
361 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
362 $5); }
363 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
364 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
365 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
366 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
367 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
368 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
369 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
370 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
371 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
372 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
373 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
374 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
375 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
376 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
377 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
378 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
379 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
380 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
381 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
382 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
383 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
384 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
385 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
386 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
387 | '+' expr %prec OP_SIGN { $$ = $2; }
388 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
389 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
390 | '(' expr ')' { $$ = $2; }
391 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
392 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
393 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
396 * The lvalue rule builds an expression tree. This is a limited form
397 * of expression that is suitable to be used as an lvalue.
399 lval_addr:
400 lval { $$ = DEBUG_EvalExpr($1); }
402 lval:
403 lvalue { $$ = $1; }
404 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
406 lvalue:
407 tNUM { $$ = DEBUG_ConstExpr($1); }
408 | tREG { $$ = DEBUG_RegisterExpr($1); }
409 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
410 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
411 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
412 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
416 void
417 issue_prompt(){
418 #ifdef DONT_USE_READLINE
419 fprintf(stderr,"Wine-dbg>");
420 #endif
423 void mode_command(int newmode)
425 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
426 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
430 /***********************************************************************
431 * DEBUG_Main
433 * Debugger main loop.
435 static void DEBUG_Main( int signal )
437 static int loaded_symbols = 0;
438 static BOOL frozen = FALSE;
439 static BOOL in_debugger = FALSE;
440 char SymbolTableFile[256];
441 int newmode;
442 BOOL ret_ok;
443 #ifdef YYDEBUG
444 yydebug = 0;
445 #endif
447 if (in_debugger)
449 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
450 exit(1);
452 in_debugger = TRUE;
453 yyin = stdin;
455 DEBUG_SetBreakpoints( FALSE );
457 if (!loaded_symbols)
459 loaded_symbols++;
461 if ( !frozen )
463 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
464 frozen = TRUE;
467 #ifdef DBG_need_heap
469 * Initialize the debugger heap.
471 dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
472 #endif
475 * Initialize the type handling stuff.
477 DEBUG_InitTypes();
480 * In some cases we can read the stabs information directly
481 * from the executable. If this is the case, we don't need
482 * to bother with trying to read a symbol file, as the stabs
483 * also have line number and local variable information.
484 * As long as gcc is used for the compiler, stabs will
485 * be the default. On SVr4, DWARF could be used, but we
486 * don't grok that yet, and in this case we fall back to using
487 * the wine.sym file.
489 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
491 char *symfilename = "wine.sym";
492 struct stat statbuf;
493 if (-1 == stat(symfilename, &statbuf) )
494 symfilename = LIBDIR "wine.sym";
496 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
497 SymbolTableFile, sizeof(SymbolTableFile));
498 DEBUG_ReadSymbolTable( SymbolTableFile );
501 DEBUG_LoadEntryPoints();
502 DEBUG_ProcessDeferredDebug();
505 #if 0
506 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
507 EIP_reg(&DEBUG_context),
508 dbg_exec_mode, dbg_exec_count);
510 sleep(1);
511 #endif
513 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
514 &dbg_exec_count ))
516 DBG_ADDR addr;
517 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
519 addr.seg = CS_reg(&DEBUG_context);
520 addr.off = EIP_reg(&DEBUG_context);
521 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
522 addr.type = NULL;
523 DBG_FIX_ADDR_SEG( &addr, 0 );
525 GlobalUnlock16( GetCurrentTask() );
527 if ( !frozen )
529 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
530 frozen = TRUE;
533 /* Put the display in a correct state */
534 USER_Driver->pBeginDebugging();
536 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
537 if (newmode != dbg_mode)
538 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
540 DEBUG_DoDisplay();
542 if (signal != SIGTRAP) /* This is a real crash, dump some info */
544 DEBUG_InfoRegisters();
545 DEBUG_InfoStack();
546 if (dbg_mode == 16)
548 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
549 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
550 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
552 DEBUG_BackTrace();
554 else
557 * Do a quiet backtrace so that we have an idea of what the situation
558 * is WRT the source files.
560 DEBUG_SilentBackTrace();
563 if ((signal != SIGTRAP) ||
564 (dbg_exec_mode == EXEC_STEPI_OVER) ||
565 (dbg_exec_mode == EXEC_STEPI_INSTR))
567 /* Show where we crashed */
568 curr_frame = 0;
569 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
570 fprintf(stderr,": ");
571 if (DBG_CHECK_READ_PTR( &addr, 1 ))
573 DEBUG_Disasm( &addr, TRUE );
574 fprintf(stderr,"\n");
578 ret_ok = 0;
581 issue_prompt();
582 yyparse();
583 flush_symbols();
584 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
585 addr.off = EIP_reg(&DEBUG_context);
586 DBG_FIX_ADDR_SEG( &addr, 0 );
587 ret_ok = DEBUG_ValidateRegisters();
588 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
589 } while (!ret_ok);
592 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
594 * This will have gotten absorbed into the breakpoint info
595 * if it was used. Otherwise it would have been ignored.
596 * In any case, we don't mess with it any more.
598 if( dbg_exec_mode == EXEC_CONT )
600 dbg_exec_count = 0;
602 if ( frozen )
604 CLIENT_DebuggerRequest( DEBUGGER_UNFREEZE_ALL );
605 frozen = FALSE;
609 in_debugger = FALSE;
611 USER_Driver->pEndDebugging();
616 /***********************************************************************
617 * DebugBreak (KERNEL.203) (KERNEL32.181)
619 void DebugBreak16( CONTEXT *regs )
621 char module[10];
622 if (!GetModuleName16( GetCurrentTask(), module, sizeof(module) ))
623 strcpy( module, "???" );
624 fprintf( stderr, "%s called DebugBreak\n", module );
625 DEBUG_context = *regs;
626 DEBUG_Main( SIGTRAP );
630 void ctx_debug( int signal, CONTEXT *regs )
632 DEBUG_context = *regs;
633 DEBUG_Main( signal );
634 *regs = DEBUG_context;
637 void wine_debug( int signal, SIGCONTEXT *regs )
639 #if 0
640 DWORD *stack = (DWORD *)ESP_sig(regs);
641 *(--stack) = 0;
642 *(--stack) = 0;
643 *(--stack) = EH_NONCONTINUABLE;
644 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
645 *(--stack) = EIP_sig(regs);
646 ESP_sig(regs) = (DWORD)stack;
647 EIP_sig(regs) = (DWORD)RaiseException;
648 #else
649 DEBUG_SetSigContext( regs );
650 DEBUG_Main( signal );
651 DEBUG_GetSigContext( regs );
652 #endif
655 int yyerror(char * s)
657 fprintf(stderr,"%s\n", s);
658 return 0;