Fixed formatting of code
[wine] / debugger / dbg.y
1 %{
2 /*
3  * Parser for command lines in the Wine debugger
4  *
5  * Copyright 1993 Eric Youngdale
6  * Copyright 1995 Morten Welinder
7  */
8
9 #include "ts_xlib.h"
10 #include "x11drv.h"
11
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"
29
30 extern FILE * yyin;
31 unsigned int dbg_mode = 0;
32 int curr_frame = 0;
33
34 static enum exec_mode dbg_exec_mode = EXEC_CONT;
35 static int dbg_exec_count = 0;
36
37 void issue_prompt(void);
38 void mode_command(int);
39 void flush_symbols(void);
40 int yylex(void);
41 int yyerror(char *);
42
43 extern void VIRTUAL_Dump(void);  /* memory/virtual.c */
44
45 %}
46
47 %union
48 {
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;
56 }
57
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
69
70 %token tCHAR tSHORT tINT tLONG tFLOAT tDOUBLE tUNSIGNED tSIGNED 
71 %token tSTRUCT tUNION tENUM
72
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 ':'
91
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
97
98 %type <listing> list_arg
99
100 %%
101
102 input: line                    { issue_prompt(); }
103     | input line               { issue_prompt(); }
104
105 line: command 
106     | tEOL
107     | error tEOL               { yyerrok; }
108
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
168
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(); }
174
175 pathname:
176       tIDENTIFIER                    { $$ = $1; }
177     | tPATH                          { $$ = $1; }
178
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 ); }
183
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 ); }
190
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(); }
199
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(); }
205
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(); }
211
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) )
217                                    {
218                                      DEBUG_AddBreakpoint( &addr );
219                                    }
220                                  else
221                                    {
222                                      fprintf(stderr,"Unable to add breakpoint\n");
223                                    }
224                                 }
225     | tBREAK tIDENTIFIER ':' tNUM tEOL  { DBG_ADDR addr;
226                                  if( DEBUG_GetSymbolValue($2, $4, &addr, TRUE) )
227                                    {
228                                      DEBUG_AddBreakpoint( &addr );
229                                    }
230                                  else
231                                    {
232                                      fprintf(stderr,"Unable to add breakpoint\n");
233                                    }
234                                 }
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 )
247                                    {
248                                      DEBUG_GetLineNumberAddr(nh, 
249                                                       $2, &addr, TRUE);
250                                      DEBUG_AddBreakpoint( &addr );
251                                    }
252                                  else
253                                    {
254                                      fprintf(stderr,"Unable to add breakpoint\n");
255                                    }
256                                }
257
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 );
266                                }
267
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(); }
287
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 ); }
294
295
296 type_cast: 
297       '(' type_expr ')'         { $$ = $2; }
298
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); }
318
319 expr_addr:
320     expr                         { $$ = DEBUG_EvalExpr($1); }
321
322 expr_value:
323       expr        { DBG_ADDR addr  = DEBUG_EvalExpr($1);
324                     $$ = addr.off ? *(unsigned int *) addr.off : 0; }
325 /*
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.
330  */
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); } 
373         
374 /*
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.
377  */
378 lval_addr:
379     lval                         { $$ = DEBUG_EvalExpr($1); }
380
381 lval:
382       lvalue                     { $$ = $1; }
383     | '*' expr                   { $$ = DEBUG_UnopExpr(EXP_OP_FORCE_DEREF, $2); }
384         
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); } 
392         
393 %%
394
395 void 
396 issue_prompt(){
397 #ifdef DONT_USE_READLINE
398         fprintf(stderr,"Wine-dbg>");
399 #endif
400 }
401
402 void mode_command(int newmode)
403 {
404     if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
405     else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
406 }
407
408
409 /***********************************************************************
410  *           DEBUG_Main
411  *
412  * Debugger main loop.
413  */
414 static void DEBUG_Main( int signal )
415 {
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
424
425     if (in_debugger)
426     {
427         fprintf( stderr, "Segmentation fault inside debugger, exiting.\n" );
428         exit(1);
429     }
430     in_debugger = TRUE;
431     yyin = stdin;
432
433     DEBUG_SetBreakpoints( FALSE );
434
435     if (!loaded_symbols)
436     {
437         loaded_symbols++;
438
439         /*
440          * Initialize the type handling stuff.
441          */
442         DEBUG_InitTypes();
443
444         /*
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.
453          */
454         if( DEBUG_ReadExecutableDbgInfo() == FALSE )
455         {
456             char *symfilename = "wine.sym";
457             struct stat statbuf;
458             if (-1 == stat(symfilename, &statbuf) )
459                 symfilename = LIBDIR "wine.sym";
460
461             PROFILE_GetWineIniString( "wine", "SymbolTableFile", symfilename,
462                                      SymbolTableFile, sizeof(SymbolTableFile));
463             DEBUG_ReadSymbolTable( SymbolTableFile );
464         }
465
466         DEBUG_LoadEntryPoints();
467         DEBUG_ProcessDeferredDebug();
468     }
469
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);
474     
475     sleep(1);
476 #endif
477
478     if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( dbg_exec_mode, 
479                                                       &dbg_exec_count ))
480     {
481         DBG_ADDR addr;
482         TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
483
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 );
489
490         GlobalUnlock16( GetCurrentTask() );
491
492         /* Put the display in a correct state */
493
494         TSXUngrabServer( display );
495         TSXFlush( display );
496
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);
500
501         PROCESS_SuspendOtherThreads();
502
503         DEBUG_DoDisplay();
504
505         if (signal != SIGTRAP)  /* This is a real crash, dump some info */
506         {
507             DEBUG_InfoRegisters();
508             DEBUG_InfoStack();
509             if (dbg_mode == 16)
510             {
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 );
514             }
515             DEBUG_BackTrace();
516         }
517         else
518         {
519           /*
520            * Do a quiet backtrace so that we have an idea of what the situation
521            * is WRT the source files.
522            */
523             DEBUG_SilentBackTrace();
524         }
525
526         if ((signal != SIGTRAP) ||
527             (dbg_exec_mode == EXEC_STEPI_OVER) ||
528             (dbg_exec_mode == EXEC_STEPI_INSTR))
529         {
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 ))
535               {
536                 DEBUG_Disasm( &addr, TRUE );
537                 fprintf(stderr,"\n");
538               }
539         }
540
541         ret_ok = 0;
542         do
543         {
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);
553     }
554
555     dbg_exec_mode = DEBUG_RestartExecution( dbg_exec_mode, dbg_exec_count );
556     /*
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.
560      */
561     if( dbg_exec_mode == EXEC_CONT )
562       {
563         dbg_exec_count = 0;
564         PROCESS_ResumeOtherThreads();
565       }
566
567     in_debugger = FALSE;
568 }
569
570
571
572 /***********************************************************************
573  *           DebugBreak   (KERNEL.203) (KERNEL32.181)
574  */
575 void DebugBreak( CONTEXT *regs )
576 {
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 );
583 }
584
585
586 void ctx_debug( int signal, CONTEXT *regs )
587 {
588     DEBUG_context = *regs;
589     DEBUG_Main( signal );
590     *regs = DEBUG_context;
591 }
592
593 void wine_debug( int signal, SIGCONTEXT *regs )
594 {
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
609 }
610
611 int yyerror(char * s)
612 {
613         fprintf(stderr,"%s\n", s);
614         return 0;
615 }