Implementation of VERSION.DLL. Based on old misc/ver.c.
[wine/gsoc_dplay.git] / debugger / dbg.y
blob7362693a6ceb95250e7f0f2f79218a9344875428
1 %{
2 /*
3 * Parser for command lines in the Wine debugger
5 * Copyright 1993 Eric Youngdale
6 * Copyright 1995 Morten Welinder
7 */
9 #include "ts_xlib.h"
11 #include <stdio.h>
12 #include <signal.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include "winbase.h"
16 #include "class.h"
17 #include "module.h"
18 #include "task.h"
19 #include "options.h"
20 #include "queue.h"
21 #include "win.h"
22 #include "winnt.h"
23 #include "debugger.h"
24 #include "neexe.h"
25 #include "process.h"
26 #include "main.h"
27 #include "ts_xlib.h"
29 #include "expr.h"
31 extern FILE * yyin;
32 unsigned int dbg_mode = 0;
33 int curr_frame = 0;
35 static enum exec_mode dbg_exec_mode = EXEC_CONT;
36 static int dbg_exec_count = 0;
38 void issue_prompt(void);
39 void mode_command(int);
40 void flush_symbols(void);
41 int yylex(void);
42 int yyerror(char *);
44 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
48 %union
50 DBG_ADDR address;
51 enum debug_regs reg;
52 char * string;
53 int integer;
54 struct list_id listing;
55 struct expr * expression;
56 struct datatype * type;
59 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
60 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
61 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
62 %token tEOL tSTRING tDEBUGSTR
63 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
64 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
65 %token <string> tPATH
66 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
67 %token <integer> tNUM tFORMAT
68 %token <reg> tREG
69 %token tSYMBOLFILE
71 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
72 %token tSTRUCT tUNION tENUM
74 /* %left ',' */
75 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
76 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
77 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
78 /* %left OP_COND */ /* ... ? ... : ... */
79 %left OP_LOR
80 %left OP_LAND
81 %left '|'
82 %left '^'
83 %left '&'
84 %left OP_EQ OP_NE
85 %left '<' '>' OP_LE OP_GE
86 %left OP_SHL OP_SHR
87 %left '+' '-'
88 %left '*' '/' '%'
89 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
90 %left '.' '[' OP_DRF
91 %nonassoc ':'
93 %type <expression> expr lval lvalue
94 %type <type> type_cast type_expr
95 %type <address> expr_addr lval_addr
96 %type <integer> expr_value
97 %type <string> pathname
99 %type <listing> list_arg
103 input: line { issue_prompt(); }
104 | input line { issue_prompt(); }
106 line: command
107 | tEOL
108 | error tEOL { yyerrok; }
110 command:
111 tQUIT tEOL { exit(0); }
112 | tHELP tEOL { DEBUG_Help(); }
113 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
114 | tCONT tEOL { dbg_exec_count = 1;
115 dbg_exec_mode = EXEC_CONT; return 0; }
116 | tCONT tNUM tEOL { dbg_exec_count = $2;
117 dbg_exec_mode = EXEC_CONT; return 0; }
118 | tSTEP tEOL { dbg_exec_count = 1;
119 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
120 | tNEXT tEOL { dbg_exec_count = 1;
121 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
122 | tSTEP tNUM tEOL { dbg_exec_count = $2;
123 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
124 | tNEXT tNUM tEOL { dbg_exec_count = $2;
125 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
126 | tSTEPI tEOL { dbg_exec_count = 1;
127 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
128 | tNEXTI tEOL { dbg_exec_count = 1;
129 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
130 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
131 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
132 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
133 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
134 | tABORT tEOL { kill(getpid(), SIGABRT); }
135 | tMODE tNUM tEOL { mode_command($2); }
136 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
137 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
138 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
139 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
140 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
141 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
142 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
143 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
144 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
145 | tFINISH tEOL { dbg_exec_count = 0;
146 dbg_exec_mode = EXEC_FINISH; return 0; }
147 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
148 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
149 | tDIR tEOL { DEBUG_NukePath(); }
150 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
151 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
152 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
153 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
154 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
155 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
156 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
157 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
158 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
159 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
160 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
161 | list_command
162 | disassemble_command
163 | set_command
164 | x_command
165 | print_command
166 | break_command
167 | info_command
168 | walk_command
170 set_command:
171 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
172 DEBUG_FreeExprMem(); }
173 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
174 DEBUG_FreeExprMem(); }
176 pathname:
177 tIDENTIFIER { $$ = $1; }
178 | tPATH { $$ = $1; }
180 disassemble_command:
181 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
182 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
183 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
185 list_command:
186 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
187 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
188 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
189 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
190 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
192 list_arg:
193 tNUM { $$.sourcefile = NULL; $$.line = $1; }
194 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
195 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
196 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
197 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
198 0, & $$ );
199 DEBUG_FreeExprMem(); }
201 x_command:
202 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
203 DEBUG_FreeExprMem(); }
204 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
205 DEBUG_FreeExprMem(); }
207 print_command:
208 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
209 DEBUG_FreeExprMem(); }
210 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
211 DEBUG_FreeExprMem(); }
213 break_command:
214 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
215 DEBUG_FreeExprMem(); }
216 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
217 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
219 DEBUG_AddBreakpoint( &addr );
221 else
223 fprintf(stderr,"Unable to add breakpoint\n");
226 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
227 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
229 DEBUG_AddBreakpoint( &addr );
231 else
233 fprintf(stderr,"Unable to add breakpoint\n");
236 | tBREAK tNUM tEOL { struct name_hash *nh;
237 DBG_ADDR addr = { NULL,
238 CS_reg(&DEBUG_context),
239 EIP_reg(&DEBUG_context) };
240 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
241 if (ISV86(&DEBUG_context))
242 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
243 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
244 GlobalUnlock16( GetCurrentTask() );
245 DEBUG_FindNearestSymbol(&addr, TRUE,
246 &nh, 0, NULL);
247 if( nh != NULL )
249 DEBUG_GetLineNumberAddr(nh,
250 $2, &addr, TRUE);
251 DEBUG_AddBreakpoint( &addr );
253 else
255 fprintf(stderr,"Unable to add breakpoint\n");
259 | tBREAK tEOL { DBG_ADDR addr = { NULL,
260 CS_reg(&DEBUG_context),
261 EIP_reg(&DEBUG_context) };
262 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
263 if (ISV86(&DEBUG_context))
264 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
265 GlobalUnlock16( GetCurrentTask() );
266 DEBUG_AddBreakpoint( &addr );
269 info_command:
270 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
271 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
272 DEBUG_FreeExprMem(); }
273 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
274 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
275 DEBUG_FreeExprMem(); }
276 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
277 DEBUG_FreeExprMem(); }
278 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
279 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
280 DEBUG_FreeExprMem(); }
281 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
282 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
283 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
284 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
285 DEBUG_FreeExprMem(); }
286 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
287 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
289 walk_command:
290 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
291 | tWALK tMODULE tEOL { NE_WalkModules(); }
292 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
293 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
294 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
297 type_cast:
298 '(' type_expr ')' { $$ = $2; }
300 type_expr:
301 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
302 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
303 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
304 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
305 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
306 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
307 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
308 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
309 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
310 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
311 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
312 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
313 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
314 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
315 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
316 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
317 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
318 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
320 expr_addr:
321 expr { $$ = DEBUG_EvalExpr($1); }
323 expr_value:
324 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
325 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
327 * The expr rule builds an expression tree. When we are done, we call
328 * EvalExpr to evaluate the value of the expression. The advantage of
329 * the two-step approach is that it is possible to save expressions for
330 * use in 'display' commands, and in conditional watchpoints.
332 expr:
333 tNUM { $$ = DEBUG_ConstExpr($1); }
334 | tSTRING { $$ = DEBUG_StringExpr($1); }
335 | tREG { $$ = DEBUG_RegisterExpr($1); }
336 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
337 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
338 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
339 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
340 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
341 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
342 $5); }
343 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
344 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
345 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
346 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
347 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
348 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
349 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
350 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
351 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
352 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
353 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
354 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
355 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
356 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
357 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
358 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
359 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
360 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
361 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
362 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
363 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
364 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
365 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
366 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
367 | '+' expr %prec OP_SIGN { $$ = $2; }
368 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
369 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
370 | '(' expr ')' { $$ = $2; }
371 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
372 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
373 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
376 * The lvalue rule builds an expression tree. This is a limited form
377 * of expression that is suitable to be used as an lvalue.
379 lval_addr:
380 lval { $$ = DEBUG_EvalExpr($1); }
382 lval:
383 lvalue { $$ = $1; }
384 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
386 lvalue:
387 tNUM { $$ = DEBUG_ConstExpr($1); }
388 | tREG { $$ = DEBUG_RegisterExpr($1); }
389 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
390 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
391 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
392 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
396 void
397 issue_prompt(){
398 #ifdef DONT_USE_READLINE
399 fprintf(stderr,"Wine-dbg>");
400 #endif
403 void mode_command(int newmode)
405 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
406 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
410 /***********************************************************************
411 * DEBUG_Main
413 * Debugger main loop.
415 static void DEBUG_Main( int signal )
417 static int loaded_symbols = 0;
418 static BOOL32 in_debugger = FALSE;
419 char SymbolTableFile[256];
420 int newmode;
421 BOOL32 ret_ok;
422 #ifdef YYDEBUG
423 yydebug = 0;
424 #endif
426 if (in_debugger)
428 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
429 exit(1);
431 in_debugger = TRUE;
432 yyin = stdin;
434 DEBUG_SetBreakpoints( FALSE );
436 if (!loaded_symbols)
438 loaded_symbols++;
441 * Initialize the type handling stuff.
443 DEBUG_InitTypes();
446 * In some cases we can read the stabs information directly
447 * from the executable. If this is the case, we don't need
448 * to bother with trying to read a symbol file, as the stabs
449 * also have line number and local variable information.
450 * As long as gcc is used for the compiler, stabs will
451 * be the default. On SVr4, DWARF could be used, but we
452 * don't grok that yet, and in this case we fall back to using
453 * the wine.sym file.
455 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
457 char *symfilename = "wine.sym";
458 struct stat statbuf;
459 if (-1 == stat(symfilename, &statbuf) )
460 symfilename = LIBDIR "wine.sym";
462 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
463 SymbolTableFile, sizeof(SymbolTableFile));
464 DEBUG_ReadSymbolTable( SymbolTableFile );
467 DEBUG_LoadEntryPoints();
468 DEBUG_ProcessDeferredDebug();
471 #if 0
472 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
473 EIP_reg(&DEBUG_context),
474 dbg_exec_mode, dbg_exec_count);
476 sleep(1);
477 #endif
479 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
480 &dbg_exec_count ))
482 DBG_ADDR addr;
483 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
485 addr.seg = CS_reg(&DEBUG_context);
486 addr.off = EIP_reg(&DEBUG_context);
487 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
488 addr.type = NULL;
489 DBG_FIX_ADDR_SEG( &addr, 0 );
491 GlobalUnlock16( GetCurrentTask() );
493 /* Put the display in a correct state */
495 TSXUngrabServer( display );
496 TSXFlush( display );
498 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
499 if (newmode != dbg_mode)
500 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
502 PROCESS_SuspendOtherThreads();
504 DEBUG_DoDisplay();
506 if (signal != SIGTRAP) /* This is a real crash, dump some info */
508 DEBUG_InfoRegisters();
509 DEBUG_InfoStack();
510 if (dbg_mode == 16)
512 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
513 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
514 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
516 DEBUG_BackTrace();
518 else
521 * Do a quiet backtrace so that we have an idea of what the situation
522 * is WRT the source files.
524 DEBUG_SilentBackTrace();
527 if ((signal != SIGTRAP) ||
528 (dbg_exec_mode == EXEC_STEPI_OVER) ||
529 (dbg_exec_mode == EXEC_STEPI_INSTR))
531 /* Show where we crashed */
532 curr_frame = 0;
533 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
534 fprintf(stderr,": ");
535 if (DBG_CHECK_READ_PTR( &addr, 1 ))
537 DEBUG_Disasm( &addr, TRUE );
538 fprintf(stderr,"\n");
542 ret_ok = 0;
545 issue_prompt();
546 yyparse();
547 flush_symbols();
548 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
549 addr.off = EIP_reg(&DEBUG_context);
550 DBG_FIX_ADDR_SEG( &addr, 0 );
551 ret_ok = DEBUG_ValidateRegisters();
552 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
553 } while (!ret_ok);
556 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
558 * This will have gotten absorbed into the breakpoint info
559 * if it was used. Otherwise it would have been ignored.
560 * In any case, we don't mess with it any more.
562 if( dbg_exec_mode == EXEC_CONT )
564 dbg_exec_count = 0;
565 PROCESS_ResumeOtherThreads();
568 in_debugger = FALSE;
573 /***********************************************************************
574 * DebugBreak (KERNEL.203) (KERNEL32.181)
576 void DebugBreak( CONTEXT *regs )
578 char module[10];
579 if (!GetModuleName( GetCurrentTask(), module, sizeof(module) ))
580 strcpy( module, "???" );
581 fprintf( stderr, "%s called DebugBreak\n", module );
582 DEBUG_context = *regs;
583 DEBUG_Main( SIGTRAP );
587 void ctx_debug( int signal, CONTEXT *regs )
589 DEBUG_context = *regs;
590 DEBUG_Main( signal );
591 *regs = DEBUG_context;
594 void wine_debug( int signal, SIGCONTEXT *regs )
596 #if 0
597 DWORD *stack = (DWORD *)ESP_sig(regs);
598 *(--stack) = 0;
599 *(--stack) = 0;
600 *(--stack) = EH_NONCONTINUABLE;
601 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
602 *(--stack) = EIP_sig(regs);
603 ESP_sig(regs) = (DWORD)stack;
604 EIP_sig(regs) = (DWORD)RaiseException;
605 #else
606 DEBUG_SetSigContext( regs );
607 DEBUG_Main( signal );
608 DEBUG_GetSigContext( regs );
609 #endif
612 int yyerror(char * s)
614 fprintf(stderr,"%s\n", s);
615 return 0;