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