enhmetafile added
[wine/multimedia.git] / debugger / dbg.y
blob26e56bacb293b6c359582f342def7ea6ceab47f2
1 %{
2 /*
3 * Parser for command lines in the Wine debugger
5 * Copyright 1993 Eric Youngdale
6 * Copyright 1995 Morten Welinder
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <signal.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
16 #include "winbase.h"
17 #include "class.h"
18 #include "module.h"
19 #include "task.h"
20 #include "options.h"
21 #include "queue.h"
22 #include "wine/winbase16.h"
23 #include "winnt.h"
24 #include "win.h"
25 #include "debugger.h"
26 #include "neexe.h"
27 #include "process.h"
28 #include "server.h"
29 #include "main.h"
30 #include "expr.h"
31 #include "user.h"
33 extern FILE * yyin;
34 unsigned int dbg_mode = 0;
35 HANDLE dbg_heap = 0;
36 int curr_frame = 0;
38 static enum exec_mode dbg_exec_mode = EXEC_CONT;
39 static int dbg_exec_count = 0;
41 void issue_prompt(void);
42 void mode_command(int);
43 void flush_symbols(void);
44 int yylex(void);
45 int yyerror(char *);
47 #ifdef DBG_need_heap
48 #define malloc(x) DBG_alloc(x)
49 #define realloc(x,y) DBG_realloc(x,y)
50 #define free(x) DBG_free(x)
51 #endif
53 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
57 %union
59 DBG_ADDR address;
60 enum debug_regs reg;
61 char * string;
62 int integer;
63 struct list_id listing;
64 struct expr * expression;
65 struct datatype * type;
68 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
69 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
70 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
71 %token tEOL tSTRING tDEBUGSTR
72 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
73 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
74 %token <string> tPATH
75 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
76 %token <integer> tNUM tFORMAT
77 %token <reg> tREG
78 %token tSYMBOLFILE
80 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
81 %token tSTRUCT tUNION tENUM
83 /* %left ',' */
84 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
85 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
86 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
87 /* %left OP_COND */ /* ... ? ... : ... */
88 %left OP_LOR
89 %left OP_LAND
90 %left '|'
91 %left '^'
92 %left '&'
93 %left OP_EQ OP_NE
94 %left '<' '>' OP_LE OP_GE
95 %left OP_SHL OP_SHR
96 %left '+' '-'
97 %left '*' '/' '%'
98 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
99 %left '.' '[' OP_DRF
100 %nonassoc ':'
102 %type <expression> expr lval lvalue
103 %type <type> type_cast type_expr
104 %type <address> expr_addr lval_addr
105 %type <integer> expr_value
106 %type <string> pathname
108 %type <listing> list_arg
112 input: line { issue_prompt(); }
113 | input line { issue_prompt(); }
115 line: command
116 | tEOL
117 | error tEOL { yyerrok; }
119 command:
120 tQUIT tEOL { exit(0); }
121 | tHELP tEOL { DEBUG_Help(); }
122 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
123 | tCONT tEOL { dbg_exec_count = 1;
124 dbg_exec_mode = EXEC_CONT; return 0; }
125 | tCONT tNUM tEOL { dbg_exec_count = $2;
126 dbg_exec_mode = EXEC_CONT; return 0; }
127 | tSTEP tEOL { dbg_exec_count = 1;
128 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
129 | tNEXT tEOL { dbg_exec_count = 1;
130 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
131 | tSTEP tNUM tEOL { dbg_exec_count = $2;
132 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
133 | tNEXT tNUM tEOL { dbg_exec_count = $2;
134 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
135 | tSTEPI tEOL { dbg_exec_count = 1;
136 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
137 | tNEXTI tEOL { dbg_exec_count = 1;
138 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
139 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
140 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
141 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
142 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
143 | tABORT tEOL { kill(getpid(), SIGABRT); }
144 | tMODE tNUM tEOL { mode_command($2); }
145 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
146 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
147 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
148 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
149 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
150 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
151 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
152 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
153 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
154 | tFINISH tEOL { dbg_exec_count = 0;
155 dbg_exec_mode = EXEC_FINISH; return 0; }
156 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
157 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
158 | tDIR tEOL { DEBUG_NukePath(); }
159 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
160 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
161 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
162 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
163 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
164 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
165 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
166 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
167 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
168 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
169 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
170 | list_command
171 | disassemble_command
172 | set_command
173 | x_command
174 | print_command
175 | break_command
176 | info_command
177 | walk_command
179 set_command:
180 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
181 DEBUG_FreeExprMem(); }
182 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
183 DEBUG_FreeExprMem(); }
185 pathname:
186 tIDENTIFIER { $$ = $1; }
187 | tPATH { $$ = $1; }
189 disassemble_command:
190 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
191 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
192 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
194 list_command:
195 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
196 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
197 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
198 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
199 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
201 list_arg:
202 tNUM { $$.sourcefile = NULL; $$.line = $1; }
203 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
204 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
205 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
206 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
207 0, & $$ );
208 DEBUG_FreeExprMem(); }
210 x_command:
211 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
212 DEBUG_FreeExprMem(); }
213 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
214 DEBUG_FreeExprMem(); }
216 print_command:
217 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
218 DEBUG_FreeExprMem(); }
219 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
220 DEBUG_FreeExprMem(); }
222 break_command:
223 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
224 DEBUG_FreeExprMem(); }
225 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
226 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
228 DEBUG_AddBreakpoint( &addr );
230 else
232 fprintf(stderr,"Unable to add breakpoint\n");
235 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
236 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
238 DEBUG_AddBreakpoint( &addr );
240 else
242 fprintf(stderr,"Unable to add breakpoint\n");
245 | tBREAK tNUM tEOL { struct name_hash *nh;
246 DBG_ADDR addr;
247 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
249 addr.type = NULL;
250 addr.seg = CS_reg(&DEBUG_context);
251 addr.off = EIP_reg(&DEBUG_context);
253 if (ISV86(&DEBUG_context))
254 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
255 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
256 GlobalUnlock16( GetCurrentTask() );
257 DEBUG_FindNearestSymbol(&addr, TRUE,
258 &nh, 0, NULL);
259 if( nh != NULL )
261 DEBUG_GetLineNumberAddr(nh,
262 $2, &addr, TRUE);
263 DEBUG_AddBreakpoint( &addr );
265 else
267 fprintf(stderr,"Unable to add breakpoint\n");
271 | tBREAK tEOL { DBG_ADDR addr;
272 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
274 addr.type = NULL;
275 addr.seg = CS_reg(&DEBUG_context);
276 addr.off = EIP_reg(&DEBUG_context);
278 if (ISV86(&DEBUG_context))
279 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
280 GlobalUnlock16( GetCurrentTask() );
281 DEBUG_AddBreakpoint( &addr );
284 info_command:
285 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
286 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
287 DEBUG_FreeExprMem(); }
288 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
289 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
290 DEBUG_FreeExprMem(); }
291 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
292 DEBUG_FreeExprMem(); }
293 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
294 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
295 DEBUG_FreeExprMem(); }
296 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
297 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
298 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
299 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
300 DEBUG_FreeExprMem(); }
301 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
302 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
304 walk_command:
305 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
306 | tWALK tMODULE tEOL { NE_WalkModules(); }
307 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
308 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
309 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
312 type_cast:
313 '(' type_expr ')' { $$ = $2; }
315 type_expr:
316 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
317 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
318 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
319 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
320 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
321 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
322 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
323 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
324 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
325 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
326 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
327 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
328 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
329 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
330 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
331 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
332 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
333 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
335 expr_addr:
336 expr { $$ = DEBUG_EvalExpr($1); }
338 expr_value:
339 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
340 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
342 * The expr rule builds an expression tree. When we are done, we call
343 * EvalExpr to evaluate the value of the expression. The advantage of
344 * the two-step approach is that it is possible to save expressions for
345 * use in 'display' commands, and in conditional watchpoints.
347 expr:
348 tNUM { $$ = DEBUG_ConstExpr($1); }
349 | tSTRING { $$ = DEBUG_StringExpr($1); }
350 | tREG { $$ = DEBUG_RegisterExpr($1); }
351 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
352 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
353 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
354 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
355 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
356 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
357 $5); }
358 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
359 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
360 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
361 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
362 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
363 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
364 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
365 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
366 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
367 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
368 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
369 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
370 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
371 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
372 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
373 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
374 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
375 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
376 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
377 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
378 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
379 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
380 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
381 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
382 | '+' expr %prec OP_SIGN { $$ = $2; }
383 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
384 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
385 | '(' expr ')' { $$ = $2; }
386 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
387 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
388 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
391 * The lvalue rule builds an expression tree. This is a limited form
392 * of expression that is suitable to be used as an lvalue.
394 lval_addr:
395 lval { $$ = DEBUG_EvalExpr($1); }
397 lval:
398 lvalue { $$ = $1; }
399 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
401 lvalue:
402 tNUM { $$ = DEBUG_ConstExpr($1); }
403 | tREG { $$ = DEBUG_RegisterExpr($1); }
404 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
405 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
406 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
407 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
411 void
412 issue_prompt(){
413 #ifdef DONT_USE_READLINE
414 fprintf(stderr,"Wine-dbg>");
415 #endif
418 void mode_command(int newmode)
420 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
421 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
425 /***********************************************************************
426 * DEBUG_Main
428 * Debugger main loop.
430 static void DEBUG_Main( int signal )
432 static int loaded_symbols = 0;
433 static BOOL frozen = FALSE;
434 static BOOL in_debugger = FALSE;
435 char SymbolTableFile[256];
436 int newmode;
437 BOOL ret_ok;
438 #ifdef YYDEBUG
439 yydebug = 0;
440 #endif
442 if (in_debugger)
444 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
445 exit(1);
447 in_debugger = TRUE;
448 yyin = stdin;
450 DEBUG_SetBreakpoints( FALSE );
452 if (!loaded_symbols)
454 loaded_symbols++;
456 if ( !frozen )
458 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
459 frozen = TRUE;
462 #ifdef DBG_need_heap
464 * Initialize the debugger heap.
466 dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
467 #endif
470 * Initialize the type handling stuff.
472 DEBUG_InitTypes();
475 * In some cases we can read the stabs information directly
476 * from the executable. If this is the case, we don't need
477 * to bother with trying to read a symbol file, as the stabs
478 * also have line number and local variable information.
479 * As long as gcc is used for the compiler, stabs will
480 * be the default. On SVr4, DWARF could be used, but we
481 * don't grok that yet, and in this case we fall back to using
482 * the wine.sym file.
484 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
486 char *symfilename = "wine.sym";
487 struct stat statbuf;
488 if (-1 == stat(symfilename, &statbuf) )
489 symfilename = LIBDIR "wine.sym";
491 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
492 SymbolTableFile, sizeof(SymbolTableFile));
493 DEBUG_ReadSymbolTable( SymbolTableFile );
496 DEBUG_LoadEntryPoints();
497 DEBUG_ProcessDeferredDebug();
500 #if 0
501 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
502 EIP_reg(&DEBUG_context),
503 dbg_exec_mode, dbg_exec_count);
505 sleep(1);
506 #endif
508 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
509 &dbg_exec_count ))
511 DBG_ADDR addr;
512 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
514 addr.seg = CS_reg(&DEBUG_context);
515 addr.off = EIP_reg(&DEBUG_context);
516 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
517 addr.type = NULL;
518 DBG_FIX_ADDR_SEG( &addr, 0 );
520 GlobalUnlock16( GetCurrentTask() );
522 if ( !frozen )
524 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
525 frozen = TRUE;
528 /* Put the display in a correct state */
529 USER_Driver->pBeginDebugging();
531 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
532 if (newmode != dbg_mode)
533 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
535 DEBUG_DoDisplay();
537 if (signal != SIGTRAP) /* This is a real crash, dump some info */
539 DEBUG_InfoRegisters();
540 DEBUG_InfoStack();
541 if (dbg_mode == 16)
543 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
544 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
545 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
547 DEBUG_BackTrace();
549 else
552 * Do a quiet backtrace so that we have an idea of what the situation
553 * is WRT the source files.
555 DEBUG_SilentBackTrace();
558 if ((signal != SIGTRAP) ||
559 (dbg_exec_mode == EXEC_STEPI_OVER) ||
560 (dbg_exec_mode == EXEC_STEPI_INSTR))
562 /* Show where we crashed */
563 curr_frame = 0;
564 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
565 fprintf(stderr,": ");
566 if (DBG_CHECK_READ_PTR( &addr, 1 ))
568 DEBUG_Disasm( &addr, TRUE );
569 fprintf(stderr,"\n");
573 ret_ok = 0;
576 issue_prompt();
577 yyparse();
578 flush_symbols();
579 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
580 addr.off = EIP_reg(&DEBUG_context);
581 DBG_FIX_ADDR_SEG( &addr, 0 );
582 ret_ok = DEBUG_ValidateRegisters();
583 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
584 } while (!ret_ok);
587 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
589 * This will have gotten absorbed into the breakpoint info
590 * if it was used. Otherwise it would have been ignored.
591 * In any case, we don't mess with it any more.
593 if( dbg_exec_mode == EXEC_CONT )
595 dbg_exec_count = 0;
597 if ( frozen )
599 CLIENT_DebuggerRequest( DEBUGGER_UNFREEZE_ALL );
600 frozen = FALSE;
604 in_debugger = FALSE;
606 USER_Driver->pEndDebugging();
611 /***********************************************************************
612 * DebugBreak (KERNEL.203) (KERNEL32.181)
614 void DebugBreak16( CONTEXT *regs )
616 char module[10];
617 if (!GetModuleName16( GetCurrentTask(), module, sizeof(module) ))
618 strcpy( module, "???" );
619 fprintf( stderr, "%s called DebugBreak\n", module );
620 DEBUG_context = *regs;
621 DEBUG_Main( SIGTRAP );
625 void ctx_debug( int signal, CONTEXT *regs )
627 DEBUG_context = *regs;
628 DEBUG_Main( signal );
629 *regs = DEBUG_context;
632 void wine_debug( int signal, SIGCONTEXT *regs )
634 #if 0
635 DWORD *stack = (DWORD *)ESP_sig(regs);
636 *(--stack) = 0;
637 *(--stack) = 0;
638 *(--stack) = EH_NONCONTINUABLE;
639 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
640 *(--stack) = EIP_sig(regs);
641 ESP_sig(regs) = (DWORD)stack;
642 EIP_sig(regs) = (DWORD)RaiseException;
643 #else
644 DEBUG_SetSigContext( regs );
645 DEBUG_Main( signal );
646 DEBUG_GetSigContext( regs );
647 #endif
650 int yyerror(char * s)
652 fprintf(stderr,"%s\n", s);
653 return 0;