Release 950817
[wine/multimedia.git] / debugger / dbg.y
blob24bde0cf09a5a1c82120352a0df43e0861d66cc9
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 | infocmd '\n'
55 | error '\n' { yyerrok; }
56 | QUIT '\n' { exit(0); }
57 | HELP '\n' { DEBUG_Help(); }
58 | CONT '\n' { dbg_exec_mode = EXEC_CONT; return 0; }
59 | STEP '\n' { dbg_exec_mode = EXEC_STEP_INSTR; return 0; }
60 | NEXT '\n' { dbg_exec_mode = EXEC_STEP_OVER; return 0; }
61 | ABORT '\n' { kill(getpid(), SIGABRT); }
62 | SYMBOLFILE IDENTIFIER '\n' { DEBUG_ReadSymbolTable( $2 ); }
63 | DEFINE IDENTIFIER addr '\n' { DEBUG_AddSymbol( $2, &$3 ); }
64 | MODE NUM '\n' { mode_command($2); }
65 | ENABLE NUM '\n' { DEBUG_EnableBreakpoint( $2, TRUE ); }
66 | DISABLE NUM '\n' { DEBUG_EnableBreakpoint( $2, FALSE ); }
67 | BREAK '*' addr '\n' { DEBUG_AddBreakpoint( &$3 ); }
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 | x_command
75 | print_command
76 | deposit_command
78 deposit_command:
79 SET REG '=' expr '\n' { DEBUG_SetRegister( $2, $4 ); }
80 | SET '*' addr '=' expr '\n' { DEBUG_WriteMemory( &$3, $5 ); }
81 | SET IDENTIFIER '=' addr '\n' { if (!DEBUG_SetSymbolValue( $2, &$4 ))
83 fprintf( stderr, "Symbol %s not found\n", $2 );
84 YYERROR;
89 x_command:
90 EXAM addr '\n' { DEBUG_ExamineMemory( &$2, 1, 'x'); }
91 | EXAM FORMAT addr '\n' { DEBUG_ExamineMemory( &$3, $2>>8, $2&0xff ); }
93 print_command:
94 PRINT addr '\n' { DEBUG_Print( &$2, 1, 'x' ); }
95 | PRINT FORMAT addr '\n' { DEBUG_Print( &$3, $2 >> 8, $2 & 0xff ); }
97 symbol: IDENTIFIER { if (!DEBUG_GetSymbolValue( $1, &$$ ))
99 fprintf( stderr, "Symbol %s not found\n", $1 );
100 YYERROR;
104 addr: expr { $$.seg = 0xffffffff; $$.off = $1; }
105 | expr ':' expr { $$.seg = $1; $$.off = $3; }
106 | symbol { $$ = $1; }
108 expr: NUM { $$ = $1; }
109 | REG { $$ = DEBUG_GetRegister($1); }
110 | expr '+' NUM { $$ = $1 + $3; }
111 | expr '-' NUM { $$ = $1 - $3; }
112 | '(' expr ')' { $$ = $2; }
113 | '*' addr { $$ = DEBUG_ReadMemory( &$2 ); }
115 infocmd: INFO REGS { DEBUG_InfoRegisters(); }
116 | INFO STACK { DEBUG_InfoStack(); }
117 | INFO BREAK { DEBUG_InfoBreakpoints(); }
118 | INFO SEGMENTS { LDT_Print(); }
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) || (newmode == 32)) dbg_mode = newmode;
133 else fprintf(stderr,"Invalid mode (use 16 or 32)\n");
137 void wine_debug( int signal, struct sigcontext_struct *regs )
139 static int loaded_symbols = 0;
140 char SymbolTableFile[256];
141 int instr_len = 0, newmode;
142 #ifdef YYDEBUG
143 yydebug = 1;
144 #endif
146 yyin = stdin;
147 DEBUG_context = (struct sigcontext_struct *)regs;
149 DEBUG_SetBreakpoints( FALSE );
151 if (!loaded_symbols)
153 loaded_symbols++;
154 GetPrivateProfileString("wine", "SymbolTableFile", "wine.sym",
155 SymbolTableFile, sizeof(SymbolTableFile), WINE_INI);
156 DEBUG_ReadSymbolTable( SymbolTableFile );
157 DEBUG_LoadEntryPoints();
160 if ((signal != SIGTRAP) || !DEBUG_ShouldContinue( regs, dbg_exec_mode ))
162 DBG_ADDR addr;
164 addr.seg = (CS_reg(DEBUG_context) == WINE_CODE_SELECTOR) ?
165 0 : CS_reg(DEBUG_context);
166 addr.off = EIP_reg(DEBUG_context);
168 if (!addr.seg) newmode = 32;
169 else newmode = (GET_SEL_FLAGS(addr.seg) & LDT_FLAGS_32BIT) ? 32 : 16;
171 if (newmode != dbg_mode)
172 fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode);
174 /* Show where we crashed */
175 DEBUG_PrintAddress( &addr, dbg_mode );
176 fprintf(stderr,": ");
177 DEBUG_Disasm( &addr );
178 fprintf(stderr,"\n");
179 instr_len = addr.off - EIP_reg(DEBUG_context);
181 issue_prompt();
182 yyparse();
183 flush_symbols();
186 DEBUG_RestartExecution( regs, dbg_exec_mode, instr_len );
190 int yyerror(char * s)
192 fprintf(stderr,"%s\n", s);
193 return 0;