Fixed some warnings.
[wine] / debugger / debug.l
1 /* -*-C-*-
2  * Lexical scanner for command line parsing
3  *
4  * Copyright 1993 Eric Youngdale
5  *           2000 Eric Pouech
6  */
7
8 %{
9 #include <stdlib.h>
10 #include <string.h>
11 #include "debugger.h"
12 #include "y.tab.h"
13
14 #ifndef DONT_USE_READLINE
15 #undef YY_INPUT
16 #define YY_INPUT(buf,result,max_size) \
17         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
18             YY_FATAL_ERROR( "read() in flex scanner failed" );
19
20 static int dbg_read(char * buf, int size);
21 static char * DEBUG_MakeSymbol(char *);
22
23 #endif  /* DONT_USE_READLINE */
24
25 #define YY_NO_UNPUT
26
27 static int syntax_error;
28 %}
29
30 DIGIT      [0-9]
31 HEXDIGIT   [0-9a-fA-F]
32 FORMAT     [ubcdiswx]
33 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
34 PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
35 STRING     \"[^\n"]+\"
36
37 %s FORMAT_EXPECTED
38 %s PATH_EXPECTED
39 %s INFO_CMD
40 %s HELP_CMD
41 %s DEL_CMD
42 %s WALK_CMD
43 %s SHOW_CMD
44 %s MODE_CMD
45 %s NOCMD
46
47 %x ASTRING_EXPECTED
48 %x NOPROCESS
49 %%
50                                         /* set to special state when no process is loaded. */
51                                         if (!DEBUG_CurrProcess && YYSTATE == INITIAL) {BEGIN(NOPROCESS);}
52
53 <*>\n                                   { BEGIN(INITIAL); syntax_error = 0; return tEOL; } 
54                                         /* Indicates end of command. Reset state. */
55
56 "||"                                    { return OP_LOR; }
57 "&&"                                    { return OP_LAND; }
58 "=="                                    { return OP_EQ; }
59 "!="                                    { return OP_NE; }
60 "<="                                    { return OP_LE; }
61 ">="                                    { return OP_GE; }
62 "<<"                                    { return OP_SHL; }
63 ">>"                                    { return OP_SHR; }
64 "->"                                    { return OP_DRF; }
65 [-+<=>|&^()*/%:!~,\.]                   { return *yytext; }
66 "["                                     { return *yytext; }
67 "]"                                     { return *yytext; }
68
69 "0x"{HEXDIGIT}+                         { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
70 {DIGIT}+                                { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
71
72 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}    { char* last;
73                                           yylval.integer = strtol( yytext+1, &last, 0 ) << 8;
74                                           yylval.integer |= *last;
75                                           return tFORMAT; }
76
77 <FORMAT_EXPECTED>"/"{FORMAT}            { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
78
79 {STRING}                                { yylval.string = DEBUG_MakeSymbol(yytext); return tSTRING; }
80 <ASTRING_EXPECTED>[^\n]+                { char* p = yytext; while (*p == ' ' || *p == '\t') p++;
81                                           yylval.string = DEBUG_MakeSymbol(p); return tSTRING; }
82
83 <INITIAL>info|inf|in                    { BEGIN(INFO_CMD); return tINFO; }
84 <INITIAL>up                             { BEGIN(NOCMD); return tUP; }
85 <INITIAL>down|dow|do                    { BEGIN(NOCMD); return tDOWN; }
86 <INITIAL>frame|fram|fra|fr              { BEGIN(NOCMD); return tFRAME; }
87 <INITIAL>list|lis|li|l                  { BEGIN(PATH_EXPECTED); return tLIST; }
88 <INITIAL>enable|enabl|enab|ena          { BEGIN(NOCMD); return tENABLE;}
89 <INITIAL>disable|disabl|disab|disa|dis  { BEGIN(NOCMD); return tDISABLE; }
90 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
91 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp     { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
92 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und       { BEGIN(NOCMD); return tUNDISPLAY; }
93 <INITIAL>delete|delet|dele|del          { BEGIN(DEL_CMD); return tDELETE; }
94 <INITIAL,NOPROCESS>quit|qui|qu|q        { BEGIN(NOCMD); return tQUIT; }
95 <INITIAL>set|se                         { BEGIN(NOCMD); return tSET; }
96 <INITIAL,NOPROCESS>walk|w               { BEGIN(WALK_CMD); return tWALK; }
97 <INITIAL>x                              { BEGIN(FORMAT_EXPECTED); return tEXAM; }
98 <INITIAL>help|hel|he|"?"                { BEGIN(HELP_CMD); return tHELP; }
99
100 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
101 <INITIAL>where|wher|whe                 { BEGIN(NOCMD); return tBACKTRACE; }
102
103 <INITIAL>cont|con|co|c                  { BEGIN(NOCMD); return tCONT; }
104 <INITIAL>pass|pas|pa                    { BEGIN(NOCMD); return tPASS; }
105 <INITIAL>condition|conditio|conditi|condit|condi|cond   { BEGIN(NOCMD); return tCOND; }
106 <INITIAL>step|ste|st|s                  { BEGIN(NOCMD); return tSTEP; }
107 <INITIAL>next|nex|ne|n                  { BEGIN(NOCMD); return tNEXT; }
108 <INITIAL>stepi|si                       { BEGIN(NOCMD); return tSTEPI; }
109 <INITIAL>nexti|ni                       { BEGIN(NOCMD); return tNEXTI; }
110 <INITIAL>finish|finis|fini|fin|fi       { BEGIN(NOCMD); return tFINISH; }
111
112 <INITIAL>abort|abor|abo                 { BEGIN(NOCMD); return tABORT; }
113 <INITIAL>print|prin|pri|pr|p            { BEGIN(FORMAT_EXPECTED); return tPRINT; }
114
115 <INITIAL>mode                           { BEGIN(MODE_CMD); return tMODE; }
116 <INITIAL>show|sho|sh                    { BEGIN(SHOW_CMD); return tSHOW; }
117 <INITIAL>symbolfile|symbols|symbol|sf   { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
118
119 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b   { BEGIN(PATH_EXPECTED); return tBREAK; }
120 <INITIAL>watch|watc|wat                 { BEGIN(PATH_EXPECTED); return tWATCH; }
121 <INITIAL>whatis|whati|what              { BEGIN(PATH_EXPECTED); return tWHATIS; }
122 <INITIAL,NOPROCESS>run|ru|r             { BEGIN(ASTRING_EXPECTED); return tRUN;}
123 <NOPROCESS>attach|attac|atta|att        { BEGIN(NOCMD); return tATTACH; }
124 <INFO_CMD>share|shar|sha                { return tSHARE; }
125 <INFO_CMD>locals|local|loca|loc         { return tLOCAL; }
126 <INFO_CMD,WALK_CMD>class|clas|cla       { return tCLASS; }
127 <INFO_CMD,WALK_CMD>module|modul|modu|mod { return tMODULE; }
128 <INFO_CMD,WALK_CMD>queue|queu|que       { return tQUEUE; }
129 <INFO_CMD,WALK_CMD>process|proces|proce|proc            { return tPROCESS; }
130 <INFO_CMD,WALK_CMD>threads|thread|threa|thre|thr|th { return tTHREAD; }
131 <INFO_CMD,WALK_CMD>modref|modre|modr    { return tMODREF; }
132 <INFO_CMD>registers|regs|reg|re         { return tREGS; }
133 <INFO_CMD>segments|segment|segm|seg|se  { return tSEGMENTS; }
134 <INFO_CMD>stack|stac|sta|st             { return tSTACK; }
135 <INFO_CMD>maps|map                      { return tMAPS; }
136 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd    { return tWND; }
137 <HELP_CMD>info|inf|in                   { return tINFO; }
138 <MODE_CMD>vm86                          { return tVM86; }
139
140 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir { 
141                                           BEGIN(PATH_EXPECTED); return tDIR; }
142
143 char                                    { return tCHAR; }
144 short                                   { return tSHORT; }
145 int                                     { return tINT; }
146 long                                    { return tLONG; }
147 float                                   { return tFLOAT; }
148 double                                  { return tDOUBLE; }
149 unsigned                                { return tUNSIGNED; }
150 signed                                  { return tSIGNED; }
151 struct                                  { return tSTRUCT; }
152 union                                   { return tUNION; }
153 enum                                    { return tENUM; }
154
155 {IDENTIFIER}                            { yylval.string = DEBUG_MakeSymbol(yytext); return tIDENTIFIER; }
156 "$"{IDENTIFIER}                         { yylval.string = DEBUG_MakeSymbol(yytext+1); return tINTVAR; }
157
158 <PATH_EXPECTED>{PATHNAME}               { yylval.string = DEBUG_MakeSymbol(yytext); return tPATH; }
159
160 <*>[ \t]+                               /* Eat up whitespace */ 
161
162 <NOPROCESS>.                            { BEGIN(ASTRING_EXPECTED); yyless(0); return tNOPROCESS;}
163 <*>.                                    { if (syntax_error == 0) {
164                                              syntax_error++; 
165                                              DEBUG_Printf(DBG_CHN_MESG, "Syntax Error (%s)\n", yytext); }
166                                         }
167 %%
168
169 #ifndef yywrap
170 int yywrap(void) { return 1; }
171 #endif
172
173 #ifndef DONT_USE_READLINE
174
175 #ifndef whitespace
176 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
177 #endif
178
179
180 /* Strip whitespace from the start and end of STRING. */
181 static void stripwhite (char *string)
182 {
183   register int i = 0;
184
185   while (whitespace (string[i]))
186     i++;
187
188   if (i)
189     strcpy (string, string + i);
190
191   i = strlen (string) - 1;
192
193   while (i > 0 && whitespace (string[i]))
194     i--;
195
196   string[++i] = '\0';
197 }
198
199 static int dbg_read(char * buf, int size)
200 {
201     static char last_line[256] = "";
202     char * line;
203     int len;
204     
205     for (;;)
206     {
207         DEBUG_FlushSymbols();
208         line = readline ("Wine-dbg>");
209         if (!line)
210         {
211             DEBUG_Printf( DBG_CHN_MESG, "\n" );
212             DEBUG_Exit(0);
213         }
214
215         /* Remove leading and trailing whitespace from the line */
216
217         stripwhite (line);
218
219         /* If there is anything left, add it to the history list
220            and execute it. Otherwise, re-execute last command. */
221
222         if (*line)
223         {
224             add_history( line );
225             strncpy( last_line, line, 255 );
226             last_line[255] = '\0'; 
227         }
228
229         free( line );
230         line = last_line;
231
232         if ((len = strlen(line)) > 0)
233         {
234             if (size < len + 1)
235             {
236                 DEBUG_Printf(DBG_CHN_MESG,"Fatal readline goof.\n");
237                 DEBUG_Exit(0);
238             }
239             strcpy(buf, line);
240             buf[len] = '\n';
241             buf[len+1] = 0;
242             return len + 1;
243         }
244     }
245 }
246
247 static char *local_symbols[30];
248 static int next_symbol;
249
250 static char * DEBUG_MakeSymbol(char * symbol)
251 {
252         assert(0 <= next_symbol && next_symbol < (sizeof(local_symbols) / sizeof(local_symbols[0])));
253         return local_symbols[next_symbol++] = DBG_strdup(symbol);
254 }
255
256 void DEBUG_FlushSymbols(void)
257 {
258         while(--next_symbol >= 0) DBG_free(local_symbols[next_symbol]);
259         next_symbol = 0;
260 }
261
262 #endif  /* DONT_USE_READLINE */