Release 951003
[wine/multimedia.git] / debugger / dbg.y
blob7eb5a58c0da2b855707e9fef2d763561c2ebc80f
2 %{
3 /*
4 * Parser for command lines in the Wine debugger
6 * Copyright 1993 Eric Youngdale
7 */
9 #include <stdio.h>
10 #include <signal.h>
11 #include <unistd.h>
12 #include "windows.h"
13 #include "debugger.h"
15 extern FILE * yyin;
16 unsigned int dbg_mode = 0;
18 static enum exec_mode dbg_exec_mode = EXEC_CONT;
20 void issue_prompt(void);
21 void mode_command(int);
22 void flush_symbols(void);
23 int yylex(void);
24 int yyerror(char *);
28 %union
30 DBG_ADDR address;
31 enum debug_regs reg;
32 char * string;
33 int integer;
36 %token CONT STEP NEXT QUIT HELP BACKTRACE INFO STACK SEGMENTS REGS
37 %token ENABLE DISABLE BREAK DELETE SET MODE PRINT EXAM DEFINE ABORT
38 %token NO_SYMBOL
39 %token SYMBOLFILE
41 %token <string> IDENTIFIER
42 %token <integer> NUM FORMAT
43 %token <reg> REG
45 %type <integer> expr
46 %type <address> addr symbol
50 input: /* empty */
51 | input line { issue_prompt(); }
53 line: '\n'
54 | error '\n' { yyerrok; }
55 | QUIT '\n' { exit(0); }
56 | HELP '\n' { DEBUG_Help(); }
57 | CONT '\n' { dbg_exec_mode = EXEC_CONT; return 0; }
58 | STEP '\n' { dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
59 | NEXT '\n' { dbg_exec_mode = EXEC_STEP_OVER; return 0; }
60 | ABORT '\n' { kill(getpid(), SIGABRT); }
61 | SYMBOLFILE IDENTIFIER '\n' { DEBUG_ReadSymbolTable( $2 ); }
62 | DEFINE IDENTIFIER addr '\n' { DEBUG_AddSymbol( $2, &$3 ); }
63 | MODE NUM '\n' { mode_command($2); }
64 | ENABLE NUM '\n' { DEBUG_EnableBreakpoint( $2, TRUE ); }
65 | DISABLE NUM '\n' { DEBUG_EnableBreakpoint( $2, FALSE ); }
66 | BREAK '*' addr '\n' { DEBUG_AddBreakpoint( &$3 ); }
67 | BREAK symbol '\n' { DEBUG_AddBreakpoint( &$2 ); }
68 | BREAK '\n' { DBG_ADDR addr = { CS_reg(DEBUG_context),
69 EIP_reg(DEBUG_context) };
70 DEBUG_AddBreakpoint( &addr );
72 | DELETE BREAK NUM '\n' { DEBUG_DelBreakpoint( $3 ); }
73 | BACKTRACE '\n' { DEBUG_BackTrace(); }
74 | infocmd
75 | x_command
76 | print_command
77 | deposit_command
79 deposit_command:
80 SET REG '=' expr '\n' { DEBUG_SetRegister( $2, $4 ); }
81 | SET '*' addr '=' expr '\n' { DEBUG_WriteMemory( &$3, $5 ); }
82 | SET IDENTIFIER '=' addr '\n' { if (!DEBUG_SetSymbolValue( $2, &$4 ))
84 fprintf( stderr, "Symbol %s not found\n", $2 );
85 YYERROR;
90 x_command:
91 EXAM addr '\n' { DEBUG_ExamineMemory( &$2, 1, 'x'); }
92 | EXAM FORMAT addr '\n' { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff ); }
94 print_command:
95 PRINT addr '\n' { DEBUG_Print( &$2, 1, 'x' ); }
96 | PRINT FORMAT addr '\n' { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff ); }
98 symbol: IDENTIFIER { if (!DEBUG_GetSymbolValue( $1, &$$ ))
100 fprintf( stderr, "Symbol %s not found\n", $1 );
101 YYERROR;
105 addr: expr { $$.seg = 0xffffffff; $$.off = $1; }
106 | expr ':' expr { $$.seg = $1; $$.off = $3; }
107 | symbol { $$ = $1; }
109 expr: NUM { $$ = $1; }
110 | REG { $$ = DEBUG_GetRegister($1); }
111 | expr '+' NUM { $$ = $1 + $3; }
112 | expr '-' NUM { $$ = $1 - $3; }
113 | '(' expr ')' { $$ = $2; }
114 | '*' addr { $$ = DEBUG_ReadMemory( &$2 ); }
116 infocmd: INFO REGS '\n' { DEBUG_InfoRegisters(); }
117 | INFO STACK '\n' { DEBUG_InfoStack(); }
118 | INFO BREAK '\n' { DEBUG_InfoBreakpoints(); }
119 | INFO SEGMENTS '\n' { LDT_Print( 0, -1 ); }
120 | INFO SEGMENTS expr '\n' { LDT_Print( SELECTOR_TO_ENTRY($3), 1 ); }
125 void
126 issue_prompt(){
127 #ifndef USE_READLINE
128 fprintf(stderr,"Wine-dbg>");
129 #endif
132 void mode_command(int newmode)
134 if ((newmode == 16) || (newmode == 32)) dbg_mode = newmode;
135 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
139 void wine_debug( int signal, struct sigcontext_struct *regs )
141 static int loaded_symbols = 0;
142 char SymbolTableFile[256];
143 int instr_len = 0, newmode;
144 #ifdef YYDEBUG
145 yydebug = 0;
146 #endif
148 yyin = stdin;
149 DEBUG_context = (struct sigcontext_struct *)regs;
151 DEBUG_SetBreakpoints( FALSE );
153 if (!loaded_symbols)
155 loaded_symbols++;
156 GetPrivateProfileString("wine", "SymbolTableFile", "wine.sym",
157 SymbolTableFile, sizeof(SymbolTableFile), WINE_INI);
158 DEBUG_ReadSymbolTable( SymbolTableFile );
159 DEBUG_LoadEntryPoints();
162 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( regs, dbg_exec_mode ))
164 DBG_ADDR addr;
166 addr.seg = CS_reg(DEBUG_context);
167 addr.off = EIP_reg(DEBUG_context);
168 DBG_FIX_ADDR_SEG( &addr, 0 );
170 if (!addr.seg) newmode = 32;
171 else newmode = (GET_SEL_FLAGS(addr.seg) & LDT_FLAGS_32BIT) ? 32 : 16;
173 if (newmode != dbg_mode)
174 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
176 /* Show where we crashed */
177 DEBUG_PrintAddress( &addr, dbg_mode );
178 fprintf(stderr,": ");
179 if (DBG_CHECK_READ_PTR( &addr, 1 ))
181 DEBUG_Disasm( &addr );
182 fprintf(stderr,"\n");
183 instr_len = addr.off - EIP_reg(DEBUG_context);
188 issue_prompt();
189 yyparse();
190 flush_symbols();
191 addr.seg = CS_reg(DEBUG_context);
192 addr.off = EIP_reg(DEBUG_context);
193 DBG_FIX_ADDR_SEG( &addr, 0 );
194 } while (!DBG_CHECK_READ_PTR( &addr, 1 ));
197 DEBUG_RestartExecution( regs, dbg_exec_mode, instr_len );
201 int yyerror(char * s)
203 fprintf(stderr,"%s\n", s);
204 return 0;