Release 941017
[wine/gsoc-2012-control.git] / debugger / dbg.y
blobf09de83698a9d560b91a9a470c549b2523ca7b63
2 %{
4 /* Parser for command lines in the Wine debugger
6 * Version 1.0
7 * Eric Youngdale
8 * 9/93
9 */
11 #include <stdio.h>
12 #include <signal.h>
14 #define YYSTYPE int
16 #include "regpos.h"
17 extern FILE * yyin;
18 unsigned int * regval = NULL;
19 unsigned int dbg_mask = 0;
20 unsigned int dbg_mode = 0;
22 void issue_prompt(void);
23 void mode_command(int);
27 %token CONT
28 %token QUIT
29 %token HELP
30 %token BACKTRACE
31 %token INFO
32 %token STACK
33 %token REG
34 %token REGS
35 %token NUM
36 %token ENABLE
37 %token DISABLE
38 %token BREAK
39 %token SET
40 %token MODE
41 %token PRINT
42 %token IDENTIFIER
43 %token NO_SYMBOL
44 %token SYMBOLFILE
45 %token DEFINE
46 %token ABORT
50 input: /* empty */
51 | input line { issue_prompt(); }
53 line: '\n'
54 | infocmd '\n'
55 | error '\n' { yyerrok; }
56 | QUIT '\n' { exit(0); }
57 | 'q' '\n' { exit(0); }
58 | HELP '\n' { dbg_help(); }
59 | CONT '\n' { return; }
60 | 'c' '\n' { return; }
61 | ABORT '\n' { kill(getpid(), SIGABRT); }
62 | SYMBOLFILE IDENTIFIER '\n' { read_symboltable($2); }
63 | DEFINE IDENTIFIER expr '\n' { add_hash($2, $3); }
64 | MODE NUM { mode_command($2); }
65 | ENABLE NUM { enable_break($2); }
66 | DISABLE NUM { disable_break($2); }
67 | BREAK '*' expr { add_break($3); }
68 | x_command
69 | BACKTRACE '\n' { dbg_bt(); }
70 | print_command
71 | deposit_command
73 deposit_command:
74 SET REG '=' expr '\n' { if(regval) regval[$2] = $4; else application_not_running();}
75 | SET '*' expr '=' expr '\n' { *((unsigned int *) $3) = $5; }
76 | SET symbol '=' expr '\n' { *((unsigned int *) $2) = $4; }
79 x_command:
80 'x' expr '\n' { examine_memory($2, 1, 'x'); }
81 | 'x' '/' fmt expr '\n' { examine_memory($4, 1, $3); }
82 | 'x' '/' NUM fmt expr '\n' { examine_memory($5, $3, $4); }
84 print:
85 'p'
86 | print
88 print_command:
89 print expr '\n' { examine_memory(((unsigned int) &$2 ), 1, 'x'); }
90 | print '/' fmt expr '\n' { examine_memory((unsigned int) &$4, 1, $3); }
91 | print '/' NUM fmt expr '\n' { examine_memory((unsigned int) &$5, $3, $4); }
93 fmt: 'x' { $$ = 'x'; }
94 | 'd' { $$ = 'd'; }
95 | 'i' { $$ = 'i'; }
96 | 'w' { $$ = 'w'; }
97 | 's' { $$ = 's'; }
98 | 'c' { $$ = 'c'; }
99 | 'b' { $$ = 'b'; }
101 symbol: IDENTIFIER { $$ = find_hash($1);
102 if($$ == 0xffffffff) {
103 fprintf(stderr,"Symbol %s not found\n", $1);
104 YYERROR;
108 expr: NUM { $$ = $1; }
109 | REG { if(regval) $$ = regval[$1]; else application_not_running();}
110 | symbol { $$ = *((unsigned int *) $1); }
111 | expr '+' NUM { $$ = $1 + $3; }
112 | expr '-' NUM { $$ = $1 - $3; }
113 | '(' expr ')' { $$ = $2; }
114 | '*' expr { $$ = *((unsigned int *) $2); }
116 infocmd: INFO REGS { info_reg(); }
117 | INFO STACK { info_stack(); }
118 | INFO BREAK { info_break(); }
123 void
124 issue_prompt(){
125 #ifndef USE_READLINE
126 fprintf(stderr,"Wine-dbg>");
127 #endif
130 void mode_command(int newmode)
132 if(newmode == 16){
133 dbg_mask = 0xffff;
134 dbg_mode = 16;
135 return;
137 if(newmode == 32){
138 dbg_mask = 0xffffffff;
139 dbg_mode = 32;
140 return;
142 fprintf(stderr,"Invalid mode (use 16 or 32)\n");
145 static int loaded_symbols = 0;
147 void
148 wine_debug(int signal, int * regs)
150 static int dummy_regs[32];
151 int i;
152 #ifdef YYDEBUG
153 yydebug = 0;
154 #endif
156 yyin = stdin;
157 regval = regs ? regs : dummy_regs;
159 #ifdef linux
160 if((SC_CS & 7) != 7) {
161 dbg_mask = 0xffffffff;
162 dbg_mode = 32;
163 } else {
164 dbg_mask = 0xffff;
165 dbg_mode = 16;
167 #endif
168 #ifdef __NetBSD__
169 if(SC_CS == 0x1f) {
170 dbg_mask = 0xffffffff;
171 dbg_mode = 32;
172 } else {
173 dbg_mask = 0xffff;
174 dbg_mode = 16;
176 #endif
177 fprintf(stderr,"In %d bit mode.\n", dbg_mode);
179 /* This is intended to read the entry points from the Windows image, and
180 insert them in the hash table. It does not work yet, so it is commented out. */
181 if(!loaded_symbols){
182 loaded_symbols++;
183 read_symboltable("wine.sym");
184 #if 0
185 load_entrypoints();
186 #endif
189 /* Remove the breakpoints from memory... */
190 fprintf(stderr,"Removing BPs\n");
191 insert_break(0);
193 /* If we stopped on a breakpoint, report this fact */
194 if(signal == SIGTRAP)
196 unsigned int addr;
197 addr = SC_EIP(dbg_mask);
198 if((addr & 0xffff0000) == 0 && dbg_mode == 16)
199 addr |= SC_CS << 16;
200 fprintf(stderr,"Stopped on breakpoint %d\n", get_bpnum(addr));
203 /* Show where we crashed */
204 if(regs)
205 examine_memory(SC_EIP(dbg_mask), 1, 'i');
207 issue_prompt();
209 yyparse();
210 flush_symbols();
212 /* Re-insert the breakpoints from memory... */
213 insert_break(1);
215 fprintf(stderr,"Returning to Wine...\n");
220 yyerror(char * s){
221 fprintf(stderr,"%s\n", s);