Moved some more code to the X11 driver.
[wine.git] / debugger / dbg.y
blob84fc6545b6df89c8f38aa37d3e965f40425c09c9
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"
10 #include "x11drv.h"
12 #include <stdio.h>
13 #include <signal.h>
14 #include <sys/stat.h>
15 #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 "win.h"
23 #include "winnt.h"
24 #include "debugger.h"
25 #include "neexe.h"
26 #include "process.h"
27 #include "main.h"
28 #include "expr.h"
30 extern FILE * yyin;
31 unsigned int dbg_mode = 0;
32 int curr_frame = 0;
34 static enum exec_mode dbg_exec_mode = EXEC_CONT;
35 static int dbg_exec_count = 0;
37 void issue_prompt(void);
38 void mode_command(int);
39 void flush_symbols(void);
40 int yylex(void);
41 int yyerror(char *);
43 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
47 %union
49 DBG_ADDR address;
50 enum debug_regs reg;
51 char * string;
52 int integer;
53 struct list_id listing;
54 struct expr * expression;
55 struct datatype * type;
58 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
59 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
60 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
61 %token tEOL tSTRING tDEBUGSTR
62 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
63 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
64 %token <string> tPATH
65 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
66 %token <integer> tNUM tFORMAT
67 %token <reg> tREG
68 %token tSYMBOLFILE
70 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
71 %token tSTRUCT tUNION tENUM
73 /* %left ',' */
74 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
75 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
76 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
77 /* %left OP_COND */ /* ... ? ... : ... */
78 %left OP_LOR
79 %left OP_LAND
80 %left '|'
81 %left '^'
82 %left '&'
83 %left OP_EQ OP_NE
84 %left '<' '>' OP_LE OP_GE
85 %left OP_SHL OP_SHR
86 %left '+' '-'
87 %left '*' '/' '%'
88 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
89 %left '.' '[' OP_DRF
90 %nonassoc ':'
92 %type <expression> expr lval lvalue
93 %type <type> type_cast type_expr
94 %type <address> expr_addr lval_addr
95 %type <integer> expr_value
96 %type <string> pathname
98 %type <listing> list_arg
102 input: line { issue_prompt(); }
103 | input line { issue_prompt(); }
105 line: command
106 | tEOL
107 | error tEOL { yyerrok; }
109 command:
110 tQUIT tEOL { exit(0); }
111 | tHELP tEOL { DEBUG_Help(); }
112 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
113 | tCONT tEOL { dbg_exec_count = 1;
114 dbg_exec_mode = EXEC_CONT; return 0; }
115 | tCONT tNUM tEOL { dbg_exec_count = $2;
116 dbg_exec_mode = EXEC_CONT; return 0; }
117 | tSTEP tEOL { dbg_exec_count = 1;
118 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
119 | tNEXT tEOL { dbg_exec_count = 1;
120 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
121 | tSTEP tNUM tEOL { dbg_exec_count = $2;
122 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
123 | tNEXT tNUM tEOL { dbg_exec_count = $2;
124 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
125 | tSTEPI tEOL { dbg_exec_count = 1;
126 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
127 | tNEXTI tEOL { dbg_exec_count = 1;
128 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
129 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
130 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
131 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
132 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
133 | tABORT tEOL { kill(getpid(), SIGABRT); }
134 | tMODE tNUM tEOL { mode_command($2); }
135 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
136 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
137 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
138 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
139 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
140 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
141 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
142 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
143 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
144 | tFINISH tEOL { dbg_exec_count = 0;
145 dbg_exec_mode = EXEC_FINISH; return 0; }
146 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
147 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
148 | tDIR tEOL { DEBUG_NukePath(); }
149 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
150 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
151 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
152 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
153 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
154 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
155 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
156 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
157 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
158 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
159 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
160 | list_command
161 | disassemble_command
162 | set_command
163 | x_command
164 | print_command
165 | break_command
166 | info_command
167 | walk_command
169 set_command:
170 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
171 DEBUG_FreeExprMem(); }
172 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
173 DEBUG_FreeExprMem(); }
175 pathname:
176 tIDENTIFIER { $$ = $1; }
177 | tPATH { $$ = $1; }
179 disassemble_command:
180 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
181 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
182 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
184 list_command:
185 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
186 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
187 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
188 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
189 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
191 list_arg:
192 tNUM { $$.sourcefile = NULL; $$.line = $1; }
193 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
194 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
195 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
196 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
197 0, & $$ );
198 DEBUG_FreeExprMem(); }
200 x_command:
201 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
202 DEBUG_FreeExprMem(); }
203 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
204 DEBUG_FreeExprMem(); }
206 print_command:
207 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
208 DEBUG_FreeExprMem(); }
209 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
210 DEBUG_FreeExprMem(); }
212 break_command:
213 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
214 DEBUG_FreeExprMem(); }
215 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
216 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
218 DEBUG_AddBreakpoint( &addr );
220 else
222 fprintf(stderr,"Unable to add breakpoint\n");
225 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
226 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
228 DEBUG_AddBreakpoint( &addr );
230 else
232 fprintf(stderr,"Unable to add breakpoint\n");
235 | tBREAK tNUM tEOL { struct name_hash *nh;
236 DBG_ADDR addr = { NULL,
237 CS_reg(&DEBUG_context),
238 EIP_reg(&DEBUG_context) };
239 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
240 if (ISV86(&DEBUG_context))
241 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
242 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
243 GlobalUnlock16( GetCurrentTask() );
244 DEBUG_FindNearestSymbol(&addr, TRUE,
245 &nh, 0, NULL);
246 if( nh != NULL )
248 DEBUG_GetLineNumberAddr(nh,
249 $2, &addr, TRUE);
250 DEBUG_AddBreakpoint( &addr );
252 else
254 fprintf(stderr,"Unable to add breakpoint\n");
258 | tBREAK tEOL { DBG_ADDR addr = { NULL,
259 CS_reg(&DEBUG_context),
260 EIP_reg(&DEBUG_context) };
261 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
262 if (ISV86(&DEBUG_context))
263 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
264 GlobalUnlock16( GetCurrentTask() );
265 DEBUG_AddBreakpoint( &addr );
268 info_command:
269 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
270 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
271 DEBUG_FreeExprMem(); }
272 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
273 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
274 DEBUG_FreeExprMem(); }
275 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
276 DEBUG_FreeExprMem(); }
277 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
278 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
279 DEBUG_FreeExprMem(); }
280 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
281 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
282 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
283 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
284 DEBUG_FreeExprMem(); }
285 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
286 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
288 walk_command:
289 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
290 | tWALK tMODULE tEOL { NE_WalkModules(); }
291 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
292 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
293 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
296 type_cast:
297 '(' type_expr ')' { $$ = $2; }
299 type_expr:
300 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
301 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
302 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
303 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
304 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
305 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
306 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
307 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
308 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
309 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
310 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
311 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
312 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
313 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
314 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
315 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
316 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
317 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
319 expr_addr:
320 expr { $$ = DEBUG_EvalExpr($1); }
322 expr_value:
323 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
324 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
326 * The expr rule builds an expression tree. When we are done, we call
327 * EvalExpr to evaluate the value of the expression. The advantage of
328 * the two-step approach is that it is possible to save expressions for
329 * use in 'display' commands, and in conditional watchpoints.
331 expr:
332 tNUM { $$ = DEBUG_ConstExpr($1); }
333 | tSTRING { $$ = DEBUG_StringExpr($1); }
334 | tREG { $$ = DEBUG_RegisterExpr($1); }
335 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
336 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
337 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
338 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
339 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
340 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
341 $5); }
342 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
343 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
344 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
345 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
346 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
347 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
348 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
349 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
350 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
351 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
352 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
353 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
354 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
355 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
356 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
357 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
358 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
359 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
360 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
361 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
362 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
363 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
364 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
365 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
366 | '+' expr %prec OP_SIGN { $$ = $2; }
367 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
368 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
369 | '(' expr ')' { $$ = $2; }
370 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
371 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
372 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
375 * The lvalue rule builds an expression tree. This is a limited form
376 * of expression that is suitable to be used as an lvalue.
378 lval_addr:
379 lval { $$ = DEBUG_EvalExpr($1); }
381 lval:
382 lvalue { $$ = $1; }
383 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
385 lvalue:
386 tNUM { $$ = DEBUG_ConstExpr($1); }
387 | tREG { $$ = DEBUG_RegisterExpr($1); }
388 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
389 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
390 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
391 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
395 void
396 issue_prompt(){
397 #ifdef DONT_USE_READLINE
398 fprintf(stderr,"Wine-dbg>");
399 #endif
402 void mode_command(int newmode)
404 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
405 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
409 /***********************************************************************
410 * DEBUG_Main
412 * Debugger main loop.
414 static void DEBUG_Main( int signal )
416 static int loaded_symbols = 0;
417 static BOOL32 in_debugger = FALSE;
418 char SymbolTableFile[256];
419 int newmode;
420 BOOL32 ret_ok;
421 #ifdef YYDEBUG
422 yydebug = 0;
423 #endif
425 if (in_debugger)
427 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
428 exit(1);
430 in_debugger = TRUE;
431 yyin = stdin;
433 DEBUG_SetBreakpoints( FALSE );
435 if (!loaded_symbols)
437 loaded_symbols++;
440 * Initialize the type handling stuff.
442 DEBUG_InitTypes();
445 * In some cases we can read the stabs information directly
446 * from the executable. If this is the case, we don't need
447 * to bother with trying to read a symbol file, as the stabs
448 * also have line number and local variable information.
449 * As long as gcc is used for the compiler, stabs will
450 * be the default. On SVr4, DWARF could be used, but we
451 * don't grok that yet, and in this case we fall back to using
452 * the wine.sym file.
454 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
456 char *symfilename = "wine.sym";
457 struct stat statbuf;
458 if (-1 == stat(symfilename, &statbuf) )
459 symfilename = LIBDIR "wine.sym";
461 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
462 SymbolTableFile, sizeof(SymbolTableFile));
463 DEBUG_ReadSymbolTable( SymbolTableFile );
466 DEBUG_LoadEntryPoints();
467 DEBUG_ProcessDeferredDebug();
470 #if 0
471 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
472 EIP_reg(&DEBUG_context),
473 dbg_exec_mode, dbg_exec_count);
475 sleep(1);
476 #endif
478 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
479 &dbg_exec_count ))
481 DBG_ADDR addr;
482 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
484 addr.seg = CS_reg(&DEBUG_context);
485 addr.off = EIP_reg(&DEBUG_context);
486 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
487 addr.type = NULL;
488 DBG_FIX_ADDR_SEG( &addr, 0 );
490 GlobalUnlock16( GetCurrentTask() );
492 /* Put the display in a correct state */
494 TSXUngrabServer( display );
495 TSXFlush( display );
497 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
498 if (newmode != dbg_mode)
499 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
501 PROCESS_SuspendOtherThreads();
503 DEBUG_DoDisplay();
505 if (signal != SIGTRAP) /* This is a real crash, dump some info */
507 DEBUG_InfoRegisters();
508 DEBUG_InfoStack();
509 if (dbg_mode == 16)
511 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
512 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
513 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
515 DEBUG_BackTrace();
517 else
520 * Do a quiet backtrace so that we have an idea of what the situation
521 * is WRT the source files.
523 DEBUG_SilentBackTrace();
526 if ((signal != SIGTRAP) ||
527 (dbg_exec_mode == EXEC_STEPI_OVER) ||
528 (dbg_exec_mode == EXEC_STEPI_INSTR))
530 /* Show where we crashed */
531 curr_frame = 0;
532 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
533 fprintf(stderr,": ");
534 if (DBG_CHECK_READ_PTR( &addr, 1 ))
536 DEBUG_Disasm( &addr, TRUE );
537 fprintf(stderr,"\n");
541 ret_ok = 0;
544 issue_prompt();
545 yyparse();
546 flush_symbols();
547 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
548 addr.off = EIP_reg(&DEBUG_context);
549 DBG_FIX_ADDR_SEG( &addr, 0 );
550 ret_ok = DEBUG_ValidateRegisters();
551 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
552 } while (!ret_ok);
555 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
557 * This will have gotten absorbed into the breakpoint info
558 * if it was used. Otherwise it would have been ignored.
559 * In any case, we don't mess with it any more.
561 if( dbg_exec_mode == EXEC_CONT )
563 dbg_exec_count = 0;
564 PROCESS_ResumeOtherThreads();
567 in_debugger = FALSE;
572 /***********************************************************************
573 * DebugBreak (KERNEL.203) (KERNEL32.181)
575 void DebugBreak( CONTEXT *regs )
577 char module[10];
578 if (!GetModuleName( GetCurrentTask(), module, sizeof(module) ))
579 strcpy( module, "???" );
580 fprintf( stderr, "%s called DebugBreak\n", module );
581 DEBUG_context = *regs;
582 DEBUG_Main( SIGTRAP );
586 void ctx_debug( int signal, CONTEXT *regs )
588 DEBUG_context = *regs;
589 DEBUG_Main( signal );
590 *regs = DEBUG_context;
593 void wine_debug( int signal, SIGCONTEXT *regs )
595 #if 0
596 DWORD *stack = (DWORD *)ESP_sig(regs);
597 *(--stack) = 0;
598 *(--stack) = 0;
599 *(--stack) = EH_NONCONTINUABLE;
600 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
601 *(--stack) = EIP_sig(regs);
602 ESP_sig(regs) = (DWORD)stack;
603 EIP_sig(regs) = (DWORD)RaiseException;
604 #else
605 DEBUG_SetSigContext( regs );
606 DEBUG_Main( signal );
607 DEBUG_GetSigContext( regs );
608 #endif
611 int yyerror(char * s)
613 fprintf(stderr,"%s\n", s);
614 return 0;