More code moved to the X11 driver (bitmap and palette and misc).
[wine.git] / debugger / dbg.y
blobaabfa8e1b7eb18e9285fdc6c3271238605af520e
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 "main.h"
29 #include "expr.h"
30 #include "user.h"
32 extern FILE * yyin;
33 unsigned int dbg_mode = 0;
34 int curr_frame = 0;
36 static enum exec_mode dbg_exec_mode = EXEC_CONT;
37 static int dbg_exec_count = 0;
39 void issue_prompt(void);
40 void mode_command(int);
41 void flush_symbols(void);
42 int yylex(void);
43 int yyerror(char *);
45 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
49 %union
51 DBG_ADDR address;
52 enum debug_regs reg;
53 char * string;
54 int integer;
55 struct list_id listing;
56 struct expr * expression;
57 struct datatype * type;
60 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
61 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
62 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
63 %token tEOL tSTRING tDEBUGSTR
64 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
65 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
66 %token <string> tPATH
67 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
68 %token <integer> tNUM tFORMAT
69 %token <reg> tREG
70 %token tSYMBOLFILE
72 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
73 %token tSTRUCT tUNION tENUM
75 /* %left ',' */
76 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
77 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
78 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
79 /* %left OP_COND */ /* ... ? ... : ... */
80 %left OP_LOR
81 %left OP_LAND
82 %left '|'
83 %left '^'
84 %left '&'
85 %left OP_EQ OP_NE
86 %left '<' '>' OP_LE OP_GE
87 %left OP_SHL OP_SHR
88 %left '+' '-'
89 %left '*' '/' '%'
90 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
91 %left '.' '[' OP_DRF
92 %nonassoc ':'
94 %type <expression> expr lval lvalue
95 %type <type> type_cast type_expr
96 %type <address> expr_addr lval_addr
97 %type <integer> expr_value
98 %type <string> pathname
100 %type <listing> list_arg
104 input: line { issue_prompt(); }
105 | input line { issue_prompt(); }
107 line: command
108 | tEOL
109 | error tEOL { yyerrok; }
111 command:
112 tQUIT tEOL { exit(0); }
113 | tHELP tEOL { DEBUG_Help(); }
114 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
115 | tCONT tEOL { dbg_exec_count = 1;
116 dbg_exec_mode = EXEC_CONT; return 0; }
117 | tCONT tNUM tEOL { dbg_exec_count = $2;
118 dbg_exec_mode = EXEC_CONT; return 0; }
119 | tSTEP tEOL { dbg_exec_count = 1;
120 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
121 | tNEXT tEOL { dbg_exec_count = 1;
122 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
123 | tSTEP tNUM tEOL { dbg_exec_count = $2;
124 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
125 | tNEXT tNUM tEOL { dbg_exec_count = $2;
126 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
127 | tSTEPI tEOL { dbg_exec_count = 1;
128 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
129 | tNEXTI tEOL { dbg_exec_count = 1;
130 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
131 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
132 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
133 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
134 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
135 | tABORT tEOL { kill(getpid(), SIGABRT); }
136 | tMODE tNUM tEOL { mode_command($2); }
137 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
138 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
139 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
140 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
141 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
142 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
143 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
144 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
145 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
146 | tFINISH tEOL { dbg_exec_count = 0;
147 dbg_exec_mode = EXEC_FINISH; return 0; }
148 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
149 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
150 | tDIR tEOL { DEBUG_NukePath(); }
151 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
152 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
153 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
154 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
155 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
156 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
157 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
158 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
159 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
160 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
161 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
162 | list_command
163 | disassemble_command
164 | set_command
165 | x_command
166 | print_command
167 | break_command
168 | info_command
169 | walk_command
171 set_command:
172 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
173 DEBUG_FreeExprMem(); }
174 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
175 DEBUG_FreeExprMem(); }
177 pathname:
178 tIDENTIFIER { $$ = $1; }
179 | tPATH { $$ = $1; }
181 disassemble_command:
182 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
183 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
184 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
186 list_command:
187 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
188 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
189 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
190 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
191 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
193 list_arg:
194 tNUM { $$.sourcefile = NULL; $$.line = $1; }
195 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
196 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
197 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
198 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
199 0, & $$ );
200 DEBUG_FreeExprMem(); }
202 x_command:
203 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
204 DEBUG_FreeExprMem(); }
205 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
206 DEBUG_FreeExprMem(); }
208 print_command:
209 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
210 DEBUG_FreeExprMem(); }
211 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
212 DEBUG_FreeExprMem(); }
214 break_command:
215 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
216 DEBUG_FreeExprMem(); }
217 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
218 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
220 DEBUG_AddBreakpoint( &addr );
222 else
224 fprintf(stderr,"Unable to add breakpoint\n");
227 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
228 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
230 DEBUG_AddBreakpoint( &addr );
232 else
234 fprintf(stderr,"Unable to add breakpoint\n");
237 | tBREAK tNUM tEOL { struct name_hash *nh;
238 DBG_ADDR addr = { NULL,
239 CS_reg(&DEBUG_context),
240 EIP_reg(&DEBUG_context) };
241 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
242 if (ISV86(&DEBUG_context))
243 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
244 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
245 GlobalUnlock16( GetCurrentTask() );
246 DEBUG_FindNearestSymbol(&addr, TRUE,
247 &nh, 0, NULL);
248 if( nh != NULL )
250 DEBUG_GetLineNumberAddr(nh,
251 $2, &addr, TRUE);
252 DEBUG_AddBreakpoint( &addr );
254 else
256 fprintf(stderr,"Unable to add breakpoint\n");
260 | tBREAK tEOL { DBG_ADDR addr = { NULL,
261 CS_reg(&DEBUG_context),
262 EIP_reg(&DEBUG_context) };
263 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
264 if (ISV86(&DEBUG_context))
265 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
266 GlobalUnlock16( GetCurrentTask() );
267 DEBUG_AddBreakpoint( &addr );
270 info_command:
271 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
272 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (CLASS *)$3 );
273 DEBUG_FreeExprMem(); }
274 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
275 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
276 DEBUG_FreeExprMem(); }
277 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
278 DEBUG_FreeExprMem(); }
279 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
280 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
281 DEBUG_FreeExprMem(); }
282 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
283 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
284 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
285 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
286 DEBUG_FreeExprMem(); }
287 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
288 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
290 walk_command:
291 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
292 | tWALK tMODULE tEOL { NE_WalkModules(); }
293 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
294 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
295 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
298 type_cast:
299 '(' type_expr ')' { $$ = $2; }
301 type_expr:
302 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
303 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
304 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
305 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
306 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
307 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
308 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
309 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
310 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
311 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
312 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
313 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
314 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
315 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
316 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
317 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
318 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
319 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
321 expr_addr:
322 expr { $$ = DEBUG_EvalExpr($1); }
324 expr_value:
325 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
326 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
328 * The expr rule builds an expression tree. When we are done, we call
329 * EvalExpr to evaluate the value of the expression. The advantage of
330 * the two-step approach is that it is possible to save expressions for
331 * use in 'display' commands, and in conditional watchpoints.
333 expr:
334 tNUM { $$ = DEBUG_ConstExpr($1); }
335 | tSTRING { $$ = DEBUG_StringExpr($1); }
336 | tREG { $$ = DEBUG_RegisterExpr($1); }
337 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
338 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
339 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
340 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
341 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
342 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
343 $5); }
344 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
345 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
346 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
347 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
348 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
349 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
350 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
351 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
352 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
353 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
354 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
355 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
356 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
357 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
358 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
359 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
360 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
361 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
362 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
363 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
364 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
365 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
366 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
367 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
368 | '+' expr %prec OP_SIGN { $$ = $2; }
369 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
370 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
371 | '(' expr ')' { $$ = $2; }
372 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
373 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
374 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
377 * The lvalue rule builds an expression tree. This is a limited form
378 * of expression that is suitable to be used as an lvalue.
380 lval_addr:
381 lval { $$ = DEBUG_EvalExpr($1); }
383 lval:
384 lvalue { $$ = $1; }
385 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
387 lvalue:
388 tNUM { $$ = DEBUG_ConstExpr($1); }
389 | tREG { $$ = DEBUG_RegisterExpr($1); }
390 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
391 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
392 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
393 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
397 void
398 issue_prompt(){
399 #ifdef DONT_USE_READLINE
400 fprintf(stderr,"Wine-dbg>");
401 #endif
404 void mode_command(int newmode)
406 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
407 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
411 /***********************************************************************
412 * DEBUG_Main
414 * Debugger main loop.
416 static void DEBUG_Main( int signal )
418 static int loaded_symbols = 0;
419 static BOOL in_debugger = FALSE;
420 char SymbolTableFile[256];
421 int newmode;
422 BOOL ret_ok;
423 #ifdef YYDEBUG
424 yydebug = 0;
425 #endif
427 if (in_debugger)
429 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
430 exit(1);
432 in_debugger = TRUE;
433 yyin = stdin;
435 DEBUG_SetBreakpoints( FALSE );
437 if (!loaded_symbols)
439 loaded_symbols++;
442 * Initialize the type handling stuff.
444 DEBUG_InitTypes();
447 * In some cases we can read the stabs information directly
448 * from the executable. If this is the case, we don't need
449 * to bother with trying to read a symbol file, as the stabs
450 * also have line number and local variable information.
451 * As long as gcc is used for the compiler, stabs will
452 * be the default. On SVr4, DWARF could be used, but we
453 * don't grok that yet, and in this case we fall back to using
454 * the wine.sym file.
456 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
458 char *symfilename = "wine.sym";
459 struct stat statbuf;
460 if (-1 == stat(symfilename, &statbuf) )
461 symfilename = LIBDIR "wine.sym";
463 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
464 SymbolTableFile, sizeof(SymbolTableFile));
465 DEBUG_ReadSymbolTable( SymbolTableFile );
468 DEBUG_LoadEntryPoints();
469 DEBUG_ProcessDeferredDebug();
472 #if 0
473 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
474 EIP_reg(&DEBUG_context),
475 dbg_exec_mode, dbg_exec_count);
477 sleep(1);
478 #endif
480 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
481 &dbg_exec_count ))
483 DBG_ADDR addr;
484 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
486 addr.seg = CS_reg(&DEBUG_context);
487 addr.off = EIP_reg(&DEBUG_context);
488 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
489 addr.type = NULL;
490 DBG_FIX_ADDR_SEG( &addr, 0 );
492 GlobalUnlock16( GetCurrentTask() );
494 /* Put the display in a correct state */
495 USER_Driver->pBeginDebugging();
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;
569 USER_Driver->pEndDebugging();
574 /***********************************************************************
575 * DebugBreak (KERNEL.203) (KERNEL32.181)
577 void DebugBreak16( CONTEXT *regs )
579 char module[10];
580 if (!GetModuleName16( GetCurrentTask(), module, sizeof(module) ))
581 strcpy( module, "???" );
582 fprintf( stderr, "%s called DebugBreak\n", module );
583 DEBUG_context = *regs;
584 DEBUG_Main( SIGTRAP );
588 void ctx_debug( int signal, CONTEXT *regs )
590 DEBUG_context = *regs;
591 DEBUG_Main( signal );
592 *regs = DEBUG_context;
595 void wine_debug( int signal, SIGCONTEXT *regs )
597 #if 0
598 DWORD *stack = (DWORD *)ESP_sig(regs);
599 *(--stack) = 0;
600 *(--stack) = 0;
601 *(--stack) = EH_NONCONTINUABLE;
602 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
603 *(--stack) = EIP_sig(regs);
604 ESP_sig(regs) = (DWORD)stack;
605 EIP_sig(regs) = (DWORD)RaiseException;
606 #else
607 DEBUG_SetSigContext( regs );
608 DEBUG_Main( signal );
609 DEBUG_GetSigContext( regs );
610 #endif
613 int yyerror(char * s)
615 fprintf(stderr,"%s\n", s);
616 return 0;