Release 990613.
[wine.git] / debugger / dbg.y
blob33bc94a69d974cfafda98967bfc78052334c6a4a
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"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <signal.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #ifdef HAVE_ALLOCA_H
18 #include <alloca.h>
19 #endif
21 #include "winbase.h"
22 #include "module.h"
23 #include "task.h"
24 #include "options.h"
25 #include "queue.h"
26 #include "wine/winbase16.h"
27 #include "winnt.h"
28 #include "x11drv.h"
29 #include "win.h"
30 #include "debugger.h"
31 #include "neexe.h"
32 #include "process.h"
33 #include "server.h"
34 #include "main.h"
35 #include "expr.h"
36 #include "user.h"
38 extern FILE * yyin;
39 unsigned int dbg_mode = 0;
40 HANDLE dbg_heap = 0;
41 int curr_frame = 0;
43 static enum exec_mode dbg_exec_mode = EXEC_CONT;
44 static int dbg_exec_count = 0;
46 void issue_prompt(void);
47 void mode_command(int);
48 void flush_symbols(void);
49 int yylex(void);
50 int yyerror(char *);
52 #ifdef DBG_need_heap
53 #define malloc(x) DBG_alloc(x)
54 #define realloc(x,y) DBG_realloc(x,y)
55 #define free(x) DBG_free(x)
56 #endif
58 extern void VIRTUAL_Dump(void); /* memory/virtual.c */
62 %union
64 DBG_ADDR address;
65 enum debug_regs reg;
66 char * string;
67 int integer;
68 struct list_id listing;
69 struct expr * expression;
70 struct datatype * type;
73 %token tCONT tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN
74 %token tENABLE tDISABLE tBREAK tDELETE tSET tMODE tPRINT tEXAM tABORT tDEBUGMSG
75 %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL
76 %token tPROCESS tMODREF
77 %token tEOL tSTRING tDEBUGSTR
78 %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE
79 %token tSTEPI tNEXTI tFINISH tSHOW tDIR
80 %token <string> tPATH
81 %token <string> tIDENTIFIER tSTRING tDEBUGSTR
82 %token <integer> tNUM tFORMAT
83 %token <reg> tREG
84 %token tSYMBOLFILE
86 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED
87 %token tSTRUCT tUNION tENUM
89 /* %left ',' */
90 /* %left '=' OP_OR_EQUAL OP_XOR_EQUAL OP_AND_EQUAL OP_SHL_EQUAL \
91 OP_SHR_EQUAL OP_PLUS_EQUAL OP_MINUS_EQUAL \
92 OP_TIMES_EQUAL OP_DIVIDE_EQUAL OP_MODULO_EQUAL */
93 /* %left OP_COND */ /* ... ? ... : ... */
94 %left OP_LOR
95 %left OP_LAND
96 %left '|'
97 %left '^'
98 %left '&'
99 %left OP_EQ OP_NE
100 %left '<' '>' OP_LE OP_GE
101 %left OP_SHL OP_SHR
102 %left '+' '-'
103 %left '*' '/' '%'
104 %left OP_SIGN '!' '~' OP_DEREF /* OP_INC OP_DEC OP_ADDR */
105 %left '.' '[' OP_DRF
106 %nonassoc ':'
108 %type <expression> expr lval lvalue
109 %type <type> type_cast type_expr
110 %type <address> expr_addr lval_addr
111 %type <integer> expr_value
112 %type <string> pathname
114 %type <listing> list_arg
118 input: line { issue_prompt(); }
119 | input line { issue_prompt(); }
121 line: command
122 | tEOL
123 | error tEOL { yyerrok; }
125 command:
126 tQUIT tEOL { exit(0); }
127 | tHELP tEOL { DEBUG_Help(); }
128 | tHELP tINFO tEOL { DEBUG_HelpInfo(); }
129 | tCONT tEOL { dbg_exec_count = 1;
130 dbg_exec_mode = EXEC_CONT; return 0; }
131 | tCONT tNUM tEOL { dbg_exec_count = $2;
132 dbg_exec_mode = EXEC_CONT; return 0; }
133 | tSTEP tEOL { dbg_exec_count = 1;
134 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
135 | tNEXT tEOL { dbg_exec_count = 1;
136 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
137 | tSTEP tNUM tEOL { dbg_exec_count = $2;
138 dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
139 | tNEXT tNUM tEOL { dbg_exec_count = $2;
140 dbg_exec_mode = EXEC_STEP_OVER; return 0; }
141 | tSTEPI tEOL { dbg_exec_count = 1;
142 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
143 | tNEXTI tEOL { dbg_exec_count = 1;
144 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
145 | tSTEPI tNUM tEOL { dbg_exec_count = $2;
146 dbg_exec_mode = EXEC_STEPI_INSTR; return 0; }
147 | tNEXTI tNUM tEOL { dbg_exec_count = $2;
148 dbg_exec_mode = EXEC_STEPI_OVER; return 0; }
149 | tABORT tEOL { kill(getpid(), SIGABRT); }
150 | tMODE tNUM tEOL { mode_command($2); }
151 | tENABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, TRUE ); }
152 | tDISABLE tNUM tEOL { DEBUG_EnableBreakpoint( $2, FALSE ); }
153 | tDELETE tBREAK tNUM tEOL { DEBUG_DelBreakpoint( $3 ); }
154 | tBACKTRACE tEOL { DEBUG_BackTrace(); }
155 | tUP tEOL { DEBUG_SetFrame( curr_frame + 1 ); }
156 | tUP tNUM tEOL { DEBUG_SetFrame( curr_frame + $2 ); }
157 | tDOWN tEOL { DEBUG_SetFrame( curr_frame - 1 ); }
158 | tDOWN tNUM tEOL { DEBUG_SetFrame( curr_frame - $2 ); }
159 | tFRAME tNUM tEOL { DEBUG_SetFrame( $2 ); }
160 | tFINISH tEOL { dbg_exec_count = 0;
161 dbg_exec_mode = EXEC_FINISH; return 0; }
162 | tSHOW tDIR tEOL { DEBUG_ShowDir(); }
163 | tDIR pathname tEOL { DEBUG_AddPath( $2 ); }
164 | tDIR tEOL { DEBUG_NukePath(); }
165 | tDISPLAY tEOL { DEBUG_InfoDisplay(); }
166 | tDISPLAY expr tEOL { DEBUG_AddDisplay($2, 1, 0); }
167 | tDISPLAY tFORMAT expr tEOL { DEBUG_AddDisplay($3, $2 >> 8, $2 & 0xff); }
168 | tDELETE tDISPLAY tNUM tEOL { DEBUG_DelDisplay( $3 ); }
169 | tDELETE tDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
170 | tUNDISPLAY tNUM tEOL { DEBUG_DelDisplay( $2 ); }
171 | tUNDISPLAY tEOL { DEBUG_DelDisplay( -1 ); }
172 | tCOND tNUM tEOL { DEBUG_AddBPCondition($2, NULL); }
173 | tCOND tNUM expr tEOL { DEBUG_AddBPCondition($2, $3); }
174 | tDEBUGMSG tDEBUGSTR tEOL { MAIN_ParseDebugOptions($2); }
175 | tSYMBOLFILE pathname tEOL{ DEBUG_ReadSymbolTable($2); }
176 | list_command
177 | disassemble_command
178 | set_command
179 | x_command
180 | print_command
181 | break_command
182 | info_command
183 | walk_command
185 set_command:
186 tSET tREG '=' expr_value tEOL { DEBUG_SetRegister( $2, $4 );
187 DEBUG_FreeExprMem(); }
188 | tSET lval_addr '=' expr_value tEOL { DEBUG_WriteMemory( &$2, $4 );
189 DEBUG_FreeExprMem(); }
191 pathname:
192 tIDENTIFIER { $$ = $1; }
193 | tPATH { $$ = $1; }
195 disassemble_command:
196 tDISASSEMBLE tEOL { DEBUG_Disassemble( NULL, NULL, 10 ); }
197 | tDISASSEMBLE expr_addr tEOL { DEBUG_Disassemble( & $2, NULL, 10 ); }
198 | tDISASSEMBLE expr_addr ',' expr_addr tEOL { DEBUG_Disassemble( & $2, & $4, 0 ); }
200 list_command:
201 tLIST tEOL { DEBUG_List( NULL, NULL, 10 ); }
202 | tLIST '-' tEOL { DEBUG_List( NULL, NULL, -10 ); }
203 | tLIST list_arg tEOL { DEBUG_List( & $2, NULL, 10 ); }
204 | tLIST ',' list_arg tEOL { DEBUG_List( NULL, & $3, -10 ); }
205 | tLIST list_arg ',' list_arg tEOL { DEBUG_List( & $2, & $4, 0 ); }
207 list_arg:
208 tNUM { $$.sourcefile = NULL; $$.line = $1; }
209 | pathname ':' tNUM { $$.sourcefile = $1; $$.line = $3; }
210 | tIDENTIFIER { DEBUG_GetFuncInfo( & $$, NULL, $1); }
211 | pathname ':' tIDENTIFIER { DEBUG_GetFuncInfo( & $$, $1, $3); }
212 | '*' expr_addr { DEBUG_FindNearestSymbol( & $2, FALSE, NULL,
213 0, & $$ );
214 DEBUG_FreeExprMem(); }
216 x_command:
217 tEXAM expr_addr tEOL { DEBUG_ExamineMemory( &$2, 1, 'x');
218 DEBUG_FreeExprMem(); }
219 | tEXAM tFORMAT expr_addr tEOL { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff );
220 DEBUG_FreeExprMem(); }
222 print_command:
223 tPRINT expr_addr tEOL { DEBUG_Print( &$2, 1, 0, 0 );
224 DEBUG_FreeExprMem(); }
225 | tPRINT tFORMAT expr_addr tEOL { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff, 0 );
226 DEBUG_FreeExprMem(); }
228 break_command:
229 tBREAK '*' expr_addr tEOL { DEBUG_AddBreakpoint( &$3 );
230 DEBUG_FreeExprMem(); }
231 | tBREAK tIDENTIFIER tEOL { DBG_ADDR addr;
232 if( DEBUG_GetSymbolValue($2, -1, &addr, TRUE) )
234 DEBUG_AddBreakpoint( &addr );
236 else
238 fprintf(stderr,"Unable to add breakpoint\n");
241 | tBREAK tIDENTIFIER ':' tNUM tEOL { DBG_ADDR addr;
242 if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
244 DEBUG_AddBreakpoint( &addr );
246 else
248 fprintf(stderr,"Unable to add breakpoint\n");
251 | tBREAK tNUM tEOL { struct name_hash *nh;
252 DBG_ADDR addr;
253 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
255 addr.type = NULL;
256 addr.seg = CS_reg(&DEBUG_context);
257 addr.off = EIP_reg(&DEBUG_context);
259 if (ISV86(&DEBUG_context))
260 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
261 DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) );
262 GlobalUnlock16( GetCurrentTask() );
263 DEBUG_FindNearestSymbol(&addr, TRUE,
264 &nh, 0, NULL);
265 if( nh != NULL )
267 DEBUG_GetLineNumberAddr(nh,
268 $2, &addr, TRUE);
269 DEBUG_AddBreakpoint( &addr );
271 else
273 fprintf(stderr,"Unable to add breakpoint\n");
277 | tBREAK tEOL { DBG_ADDR addr;
278 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
280 addr.type = NULL;
281 addr.seg = CS_reg(&DEBUG_context);
282 addr.off = EIP_reg(&DEBUG_context);
284 if (ISV86(&DEBUG_context))
285 addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
286 GlobalUnlock16( GetCurrentTask() );
287 DEBUG_AddBreakpoint( &addr );
290 info_command:
291 tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
292 | tINFO tCLASS expr_value tEOL { CLASS_DumpClass( (struct tagCLASS *)$3 );
293 DEBUG_FreeExprMem(); }
294 | tINFO tSHARE tEOL { DEBUG_InfoShare(); }
295 | tINFO tMODULE expr_value tEOL { NE_DumpModule( $3 );
296 DEBUG_FreeExprMem(); }
297 | tINFO tQUEUE expr_value tEOL { QUEUE_DumpQueue( $3 );
298 DEBUG_FreeExprMem(); }
299 | tINFO tREGS tEOL { DEBUG_InfoRegisters(); }
300 | tINFO tSEGMENTS expr_value tEOL { LDT_Print( SELECTOR_TO_ENTRY($3), 1 );
301 DEBUG_FreeExprMem(); }
302 | tINFO tSEGMENTS tEOL { LDT_Print( 0, -1 ); }
303 | tINFO tSTACK tEOL { DEBUG_InfoStack(); }
304 | tINFO tMAPS tEOL { VIRTUAL_Dump(); }
305 | tINFO tWND expr_value tEOL { WIN_DumpWindow( $3 );
306 DEBUG_FreeExprMem(); }
307 | tINFO tLOCAL tEOL { DEBUG_InfoLocals(); }
308 | tINFO tDISPLAY tEOL { DEBUG_InfoDisplay(); }
310 walk_command:
311 tWALK tCLASS tEOL { CLASS_WalkClasses(); }
312 | tWALK tMODULE tEOL { NE_WalkModules(); }
313 | tWALK tQUEUE tEOL { QUEUE_WalkQueues(); }
314 | tWALK tWND tEOL { WIN_WalkWindows( 0, 0 ); }
315 | tWALK tWND tNUM tEOL { WIN_WalkWindows( $3, 0 ); }
316 | tWALK tPROCESS tEOL { PROCESS_WalkProcess(); }
317 | tWALK tMODREF expr_value tEOL { MODULE_WalkModref( $3 ); }
320 type_cast:
321 '(' type_expr ')' { $$ = $2; }
323 type_expr:
324 type_expr '*' { $$ = DEBUG_FindOrMakePointerType($1); }
325 | tINT { $$ = DEBUG_TypeCast(DT_BASIC, "int"); }
326 | tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "char"); }
327 | tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long int"); }
328 | tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned int"); }
329 | tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long unsigned int"); }
330 | tLONG tLONG tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long int"); }
331 | tLONG tLONG tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "long long unsigned int"); }
332 | tSHORT tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short int"); }
333 | tSHORT tUNSIGNED tINT { $$ = DEBUG_TypeCast(DT_BASIC, "short unsigned int"); }
334 | tSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "signed char"); }
335 | tUNSIGNED tCHAR { $$ = DEBUG_TypeCast(DT_BASIC, "unsigned char"); }
336 | tFLOAT { $$ = DEBUG_TypeCast(DT_BASIC, "float"); }
337 | tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "double"); }
338 | tLONG tDOUBLE { $$ = DEBUG_TypeCast(DT_BASIC, "long double"); }
339 | tSTRUCT tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
340 | tUNION tIDENTIFIER { $$ = DEBUG_TypeCast(DT_STRUCT, $2); }
341 | tENUM tIDENTIFIER { $$ = DEBUG_TypeCast(DT_ENUM, $2); }
343 expr_addr:
344 expr { $$ = DEBUG_EvalExpr($1); }
346 expr_value:
347 expr { DBG_ADDR addr = DEBUG_EvalExpr($1);
348 $$ = addr.off ? *(unsigned int *) addr.off : 0; }
350 * The expr rule builds an expression tree. When we are done, we call
351 * EvalExpr to evaluate the value of the expression. The advantage of
352 * the two-step approach is that it is possible to save expressions for
353 * use in 'display' commands, and in conditional watchpoints.
355 expr:
356 tNUM { $$ = DEBUG_ConstExpr($1); }
357 | tSTRING { $$ = DEBUG_StringExpr($1); }
358 | tREG { $$ = DEBUG_RegisterExpr($1); }
359 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
360 | expr OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
361 | expr '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
362 | tIDENTIFIER '(' ')' { $$ = DEBUG_CallExpr($1, 0); }
363 | tIDENTIFIER '(' expr ')' { $$ = DEBUG_CallExpr($1, 1, $3); }
364 | tIDENTIFIER '(' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 2, $3,
365 $5); }
366 | tIDENTIFIER '(' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7); }
367 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9); }
368 | tIDENTIFIER '(' expr ',' expr ',' expr ',' expr ',' expr ')' { $$ = DEBUG_CallExpr($1, 3, $3, $5, $7, $9, $11); }
369 | expr '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
370 | expr ':' expr { $$ = DEBUG_BinopExpr(EXP_OP_SEG, $1, $3); }
371 | expr OP_LOR expr { $$ = DEBUG_BinopExpr(EXP_OP_LOR, $1, $3); }
372 | expr OP_LAND expr { $$ = DEBUG_BinopExpr(EXP_OP_LAND, $1, $3); }
373 | expr '|' expr { $$ = DEBUG_BinopExpr(EXP_OP_OR, $1, $3); }
374 | expr '&' expr { $$ = DEBUG_BinopExpr(EXP_OP_AND, $1, $3); }
375 | expr '^' expr { $$ = DEBUG_BinopExpr(EXP_OP_XOR, $1, $3); }
376 | expr OP_EQ expr { $$ = DEBUG_BinopExpr(EXP_OP_EQ, $1, $3); }
377 | expr '>' expr { $$ = DEBUG_BinopExpr(EXP_OP_GT, $1, $3); }
378 | expr '<' expr { $$ = DEBUG_BinopExpr(EXP_OP_LT, $1, $3); }
379 | expr OP_GE expr { $$ = DEBUG_BinopExpr(EXP_OP_GE, $1, $3); }
380 | expr OP_LE expr { $$ = DEBUG_BinopExpr(EXP_OP_LE, $1, $3); }
381 | expr OP_NE expr { $$ = DEBUG_BinopExpr(EXP_OP_NE, $1, $3); }
382 | expr OP_SHL expr { $$ = DEBUG_BinopExpr(EXP_OP_SHL, $1, $3); }
383 | expr OP_SHR expr { $$ = DEBUG_BinopExpr(EXP_OP_SHR, $1, $3); }
384 | expr '+' expr { $$ = DEBUG_BinopExpr(EXP_OP_ADD, $1, $3); }
385 | expr '-' expr { $$ = DEBUG_BinopExpr(EXP_OP_SUB, $1, $3); }
386 | expr '*' expr { $$ = DEBUG_BinopExpr(EXP_OP_MUL, $1, $3); }
387 | expr '/' expr { $$ = DEBUG_BinopExpr(EXP_OP_DIV, $1, $3); }
388 | expr '%' expr { $$ = DEBUG_BinopExpr(EXP_OP_REM, $1, $3); }
389 | '-' expr %prec OP_SIGN { $$ = DEBUG_UnopExpr(EXP_OP_NEG, $2); }
390 | '+' expr %prec OP_SIGN { $$ = $2; }
391 | '!' expr { $$ = DEBUG_UnopExpr(EXP_OP_NOT, $2); }
392 | '~' expr { $$ = DEBUG_UnopExpr(EXP_OP_LNOT, $2); }
393 | '(' expr ')' { $$ = $2; }
394 | '*' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_DEREF, $2); }
395 | '&' expr %prec OP_DEREF { $$ = DEBUG_UnopExpr(EXP_OP_ADDR, $2); }
396 | type_cast expr %prec OP_DEREF { $$ = DEBUG_TypeCastExpr($1, $2); }
399 * The lvalue rule builds an expression tree. This is a limited form
400 * of expression that is suitable to be used as an lvalue.
402 lval_addr:
403 lval { $$ = DEBUG_EvalExpr($1); }
405 lval:
406 lvalue { $$ = $1; }
407 | '*' expr { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
409 lvalue:
410 tNUM { $$ = DEBUG_ConstExpr($1); }
411 | tREG { $$ = DEBUG_RegisterExpr($1); }
412 | tIDENTIFIER { $$ = DEBUG_SymbolExpr($1); }
413 | lvalue OP_DRF tIDENTIFIER { $$ = DEBUG_StructPExpr($1, $3); }
414 | lvalue '.' tIDENTIFIER { $$ = DEBUG_StructExpr($1, $3); }
415 | lvalue '[' expr ']' { $$ = DEBUG_BinopExpr(EXP_OP_ARR, $1, $3); }
419 void
420 issue_prompt(){
421 #ifdef DONT_USE_READLINE
422 fprintf(stderr,"Wine-dbg>");
423 #endif
426 void mode_command(int newmode)
428 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
429 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
433 /***********************************************************************
434 * DEBUG_Main
436 * Debugger main loop.
438 static void DEBUG_Main( int signal )
440 static int loaded_symbols = 0;
441 static BOOL frozen = FALSE;
442 static BOOL in_debugger = FALSE;
443 char SymbolTableFile[256];
444 int newmode;
445 BOOL ret_ok;
446 #ifdef YYDEBUG
447 yydebug = 0;
448 #endif
450 if (in_debugger)
452 fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
453 exit(1);
455 in_debugger = TRUE;
456 yyin = stdin;
458 DEBUG_SetBreakpoints( FALSE );
460 if (!loaded_symbols)
462 loaded_symbols++;
464 if ( !frozen )
466 /* Don't freeze thread currently holding the X crst! */
467 EnterCriticalSection( &X11DRV_CritSection );
468 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
469 LeaveCriticalSection( &X11DRV_CritSection );
470 frozen = TRUE;
473 #ifdef DBG_need_heap
475 * Initialize the debugger heap.
477 dbg_heap = HeapCreate(HEAP_NO_SERIALIZE, 0x1000, 0x8000000); /* 128MB */
478 #endif
481 * Initialize the type handling stuff.
483 DEBUG_InitTypes();
486 * In some cases we can read the stabs information directly
487 * from the executable. If this is the case, we don't need
488 * to bother with trying to read a symbol file, as the stabs
489 * also have line number and local variable information.
490 * As long as gcc is used for the compiler, stabs will
491 * be the default. On SVr4, DWARF could be used, but we
492 * don't grok that yet, and in this case we fall back to using
493 * the wine.sym file.
495 if( DEBUG_ReadExecutableDbgInfo() == FALSE )
497 char *symfilename = "wine.sym";
498 struct stat statbuf;
499 if (-1 == stat(symfilename, &statbuf) )
500 symfilename = LIBDIR "wine.sym";
502 PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
503 SymbolTableFile, sizeof(SymbolTableFile));
504 DEBUG_ReadSymbolTable( SymbolTableFile );
507 DEBUG_LoadEntryPoints();
508 DEBUG_ProcessDeferredDebug();
511 #if 0
512 fprintf(stderr, "Entering debugger PC=%x, mode=%d, count=%d\n",
513 EIP_reg(&DEBUG_context),
514 dbg_exec_mode, dbg_exec_count);
516 sleep(1);
517 #endif
519 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode,
520 &dbg_exec_count ))
522 DBG_ADDR addr;
523 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
525 addr.seg = CS_reg(&DEBUG_context);
526 addr.off = EIP_reg(&DEBUG_context);
527 if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
528 addr.type = NULL;
529 DBG_FIX_ADDR_SEG( &addr, 0 );
531 GlobalUnlock16( GetCurrentTask() );
533 if ( !frozen )
535 /* Don't freeze thread currently holding the X crst! */
536 EnterCriticalSection( &X11DRV_CritSection );
537 CLIENT_DebuggerRequest( DEBUGGER_FREEZE_ALL );
538 LeaveCriticalSection( &X11DRV_CritSection );
539 frozen = TRUE;
542 /* Put the display in a correct state */
543 USER_Driver->pBeginDebugging();
545 newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16;
546 if (newmode != dbg_mode)
547 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
549 DEBUG_DoDisplay();
551 if (signal != SIGTRAP) /* This is a real crash, dump some info */
553 DEBUG_InfoRegisters();
554 DEBUG_InfoStack();
555 if (dbg_mode == 16)
557 LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 );
558 if (ES_reg(&DEBUG_context) != DS_reg(&DEBUG_context))
559 LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 );
561 DEBUG_BackTrace();
563 else
566 * Do a quiet backtrace so that we have an idea of what the situation
567 * is WRT the source files.
569 DEBUG_SilentBackTrace();
572 if ((signal != SIGTRAP) ||
573 (dbg_exec_mode == EXEC_STEPI_OVER) ||
574 (dbg_exec_mode == EXEC_STEPI_INSTR))
576 /* Show where we crashed */
577 curr_frame = 0;
578 DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
579 fprintf(stderr,": ");
580 if (DBG_CHECK_READ_PTR( &addr, 1 ))
582 DEBUG_Disasm( &addr, TRUE );
583 fprintf(stderr,"\n");
587 ret_ok = 0;
590 issue_prompt();
591 yyparse();
592 flush_symbols();
593 addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000);
594 addr.off = EIP_reg(&DEBUG_context);
595 DBG_FIX_ADDR_SEG( &addr, 0 );
596 ret_ok = DEBUG_ValidateRegisters();
597 if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
598 } while (!ret_ok);
601 dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
603 * This will have gotten absorbed into the breakpoint info
604 * if it was used. Otherwise it would have been ignored.
605 * In any case, we don't mess with it any more.
607 if( dbg_exec_mode == EXEC_CONT )
609 dbg_exec_count = 0;
611 if ( frozen )
613 CLIENT_DebuggerRequest( DEBUGGER_UNFREEZE_ALL );
614 frozen = FALSE;
618 in_debugger = FALSE;
620 USER_Driver->pEndDebugging();
625 /***********************************************************************
626 * DebugBreak (KERNEL.203) (KERNEL32.181)
628 void DebugBreak16( CONTEXT *regs )
630 char module[10];
631 if (!GetModuleName16( GetCurrentTask(), module, sizeof(module) ))
632 strcpy( module, "???" );
633 fprintf( stderr, "%s called DebugBreak\n", module );
634 DEBUG_context = *regs;
635 DEBUG_Main( SIGTRAP );
639 void ctx_debug( int signal, CONTEXT *regs )
641 DEBUG_context = *regs;
642 DEBUG_Main( signal );
643 *regs = DEBUG_context;
646 void wine_debug( int signal, SIGCONTEXT *regs )
648 #if 0
649 DWORD *stack = (DWORD *)ESP_sig(regs);
650 *(--stack) = 0;
651 *(--stack) = 0;
652 *(--stack) = EH_NONCONTINUABLE;
653 *(--stack) = EXCEPTION_ACCESS_VIOLATION;
654 *(--stack) = EIP_sig(regs);
655 ESP_sig(regs) = (DWORD)stack;
656 EIP_sig(regs) = (DWORD)RaiseException;
657 #else
658 DEBUG_SetSigContext( regs );
659 DEBUG_Main( signal );
660 DEBUG_GetSigContext( regs );
661 #endif
664 int yyerror(char * s)
666 fprintf(stderr,"%s\n", s);
667 return 0;