Changed many WARN()s related to internal Wine memory failures to
[wine.git] / debugger / debug.l
blob0c4bc8a841245c60458aca0ab6e26fbc2bcc1e67
1 /* -*-C-*-
2  * Lexical scanner for command line parsing
3  *
4  * Copyright 1993 Eric Youngdale
5  */
7 %{
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "debugger.h"
12 #include "xmalloc.h"
13 #include "y.tab.h"
15 #ifndef DONT_USE_READLINE
16 #undef YY_INPUT
17 #define YY_INPUT(buf,result,max_size) \
18         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
19             YY_FATAL_ERROR( "read() in flex scanner failed" );
21 extern char * readline(char *);
22 extern void add_history(char *);
23 static int dbg_read(char * buf, int size);
24 static char * make_symbol(char *);
25 void flush_symbols();
27 #endif  /* DONT_USE_READLINE */
29 #define YY_NO_UNPUT
31 static int syntax_error;
34 DIGIT      [0-9]
35 HEXDIGIT   [0-9a-fA-F]
36 FORMAT     [bcdiswx]
37 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
38 PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
39 STRING     \"[^\n"]+\"
41 %s FORMAT_EXPECTED
42 %s PATH_EXPECTED
43 %s INFO_CMD
44 %s HELP_CMD
45 %s DEL_CMD
46 %s WALK_CMD
47 %s SHOW_CMD
48 %s NOCMD
52 \n              { BEGIN(0); syntax_error = 0; 
53                   return tEOL; } /*Indicates end of command.  Reset state. */
55 "||"            { return OP_LOR; }
56 "&&"            { return OP_LAND; }
57 "=="            { return OP_EQ; }
58 "!="            { return OP_NE; }
59 "<="            { return OP_LE; }
60 ">="            { return OP_GE; }
61 "<<"            { return OP_SHL; }
62 ">>"            { return OP_SHR; }
63 "->"            { return OP_DRF; }
64 [-+<=>|&^()*/%:!~,\.]   { return *yytext; }
65 "["             { return *yytext; }
66 "]"             { return *yytext; }
68 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
69 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
72 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}  { char * last;
73                        yylval.integer = strtol( yytext+1, &last, NULL );
74                        yylval.integer = (yylval.integer << 8) | *last;
75                        return tFORMAT; }
78 <FORMAT_EXPECTED>"/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
80 {STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
82 $pc     { yylval.reg = REG_EIP; return tREG; }
83 $flags  { yylval.reg = REG_EFL; return tREG; }
84 $eip    { yylval.reg = REG_EIP; return tREG; }
85 $ip     { yylval.reg = REG_IP;  return tREG; }
86 $esp    { yylval.reg = REG_ESP; return tREG; }
87 $sp     { yylval.reg = REG_SP;  return tREG; }
88 $eax    { yylval.reg = REG_EAX; return tREG; }
89 $ebx    { yylval.reg = REG_EBX; return tREG; }
90 $ecx    { yylval.reg = REG_ECX; return tREG; }
91 $edx    { yylval.reg = REG_EDX; return tREG; }
92 $esi    { yylval.reg = REG_ESI; return tREG; }
93 $edi    { yylval.reg = REG_EDI; return tREG; }
94 $ebp    { yylval.reg = REG_EBP; return tREG; }
95 $ax     { yylval.reg = REG_AX;  return tREG; }
96 $bx     { yylval.reg = REG_BX;  return tREG; }
97 $cx     { yylval.reg = REG_CX;  return tREG; }
98 $dx     { yylval.reg = REG_DX;  return tREG; }
99 $si     { yylval.reg = REG_SI;  return tREG; }
100 $di     { yylval.reg = REG_DI;  return tREG; }
101 $bp     { yylval.reg = REG_BP;  return tREG; }
102 $es     { yylval.reg = REG_ES;  return tREG; }
103 $ds     { yylval.reg = REG_DS;  return tREG; }
104 $cs     { yylval.reg = REG_CS;  return tREG; }
105 $ss     { yylval.reg = REG_SS;  return tREG; }
106 $fs     { yylval.reg = REG_FS;  return tREG; }
107 $gs     { yylval.reg = REG_GS;  return tREG; }
109 <INITIAL>info|inf|in                    { BEGIN(INFO_CMD); return tINFO; }
110 <INITIAL>up                             { BEGIN(NOCMD); return tUP; }
111 <INITIAL>down|dow|do                    { BEGIN(NOCMD); return tDOWN; }
112 <INITIAL>frame|fram|fra|fr              { BEGIN(NOCMD); return tFRAME; }
113 <INITIAL>list|lis|li|l                  { BEGIN(PATH_EXPECTED); return tLIST; }
114 <INITIAL>enable|enabl|enab|ena          { BEGIN(NOCMD); return tENABLE;}
115 <INITIAL>disable|disabl|disab|disa|dis  { BEGIN(NOCMD); return tDISABLE; }
116 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
117 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp     { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
118 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und       { BEGIN(NOCMD); return tUNDISPLAY; }
119 <INITIAL>delete|delet|dele|del          { BEGIN(DEL_CMD); return tDELETE; }
120 <INITIAL>quit|qui|qu|q                  { BEGIN(NOCMD); return tQUIT; }
121 <INITIAL>set|se                         { BEGIN(NOCMD); return tSET; }
122 <INITIAL>walk|w                         { BEGIN(WALK_CMD); return tWALK; }
123 <INITIAL>x                              { BEGIN(FORMAT_EXPECTED); return tEXAM; }
124 <INITIAL>help|hel|he|"?"                { BEGIN(HELP_CMD); return tHELP; }
126 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
127 <INITIAL>where|wher|whe                  { BEGIN(NOCMD); return tBACKTRACE; }
129 <INITIAL>cont|con|co|c                  { BEGIN(NOCMD); return tCONT; }
130 <INITIAL>condition|conditio|conditi|condit|condi|cond   { BEGIN(NOCMD); return tCOND; }
131 <INITIAL>step|ste|st|s                  { BEGIN(NOCMD); return tSTEP; }
132 <INITIAL>next|nex|ne|n                  { BEGIN(NOCMD); return tNEXT; }
133 <INITIAL>stepi|si                       { BEGIN(NOCMD); return tSTEPI; }
134 <INITIAL>nexti|ni                       { BEGIN(NOCMD); return tNEXTI; }
135 <INITIAL>finish|finis|fini|fin|fi       { BEGIN(NOCMD); return tFINISH; }
137 <INITIAL>abort|abor|abo                 { BEGIN(NOCMD); return tABORT; }
138 <INITIAL>print|prin|pri|pr|p            { BEGIN(FORMAT_EXPECTED); return tPRINT; }
140 <INITIAL>mode                           { BEGIN(NOCMD); return tMODE; }
141 <INITIAL>show|sho|sh                    { BEGIN(SHOW_CMD); return tSHOW; }
143 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b   { BEGIN(PATH_EXPECTED); return tBREAK; }
145 <INFO_CMD>share|shar|sha                { return tSHARE; }
146 <INFO_CMD>locals|local|loca|loc         { return tLOCAL; }
147 <INFO_CMD,WALK_CMD>class|clas|cla                  { return tCLASS; }
148 <INFO_CMD,WALK_CMD>module|modul|modu|mod  { return tMODULE; }
149 <INFO_CMD,WALK_CMD>queue|queu|que                       { return tQUEUE; }
150 <INFO_CMD>registers|regs|reg|re         { return tREGS; }
151 <INFO_CMD>segments|segment|segm|seg|se  { return tSEGMENTS; }
152 <INFO_CMD>stack|stac|sta|st                     { return tSTACK; }
153 <INFO_CMD>maps|map                      { return tMAPS; }
154 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd    { return tWND; }
155 <HELP_CMD>info|inf|in                   { return tINFO; }
157 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir { 
158                         BEGIN(PATH_EXPECTED); return tDIR; }
160 char                                    { return tCHAR; }
161 short                                   { return tSHORT; }
162 int                                     { return tINT; }
163 long                                    { return tLONG; }
164 float                                   { return tFLOAT; }
165 double                                  { return tDOUBLE; }
166 unsigned                                { return tUNSIGNED; }
167 signed                                  { return tSIGNED; }
168 struct                                  { return tSTRUCT; }
169 union                                   { return tUNION; }
170 enum                                    { return tENUM; }
172 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
174 <PATH_EXPECTED>{PATHNAME}       { yylval.string = make_symbol(yytext); return tPATH; }
176 [ \t]+        /* Eat up whitespace */
178 .               { if (syntax_error == 0)
179                   {
180                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
181                   }
182                 }
187 #ifndef yywrap
188 int yywrap(void) { return 1; }
189 #endif
191 #ifndef DONT_USE_READLINE
193 #ifndef whitespace
194 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
195 #endif
198 /* Strip whitespace from the start and end of STRING. */
199 static void stripwhite (char *string)
201   register int i = 0;
203   while (whitespace (string[i]))
204     i++;
206   if (i)
207     strcpy (string, string + i);
209   i = strlen (string) - 1;
211   while (i > 0 && whitespace (string[i]))
212     i--;
214   string[++i] = '\0';
217 static int dbg_read(char * buf, int size)
219     static char last_line[256] = "";
220     char * line;
221     int len;
222     
223     for (;;)
224     {
225         flush_symbols();
226         line = readline ("Wine-dbg>");
227         if (!line)
228         {
229             fprintf( stderr, "\n" );
230             exit(0);
231         }
233         /* Remove leading and trailing whitespace from the line */
235         stripwhite (line);
237         /* If there is anything left, add it to the history list
238            and execute it. Otherwise, re-execute last command. */
240         if (*line)
241         {
242             add_history( line );
243             strncpy( last_line, line, 255 );
244             last_line[255] = '\0'; 
245        }
247         free( line );
248         line = last_line;
250         if ((len = strlen(line)) > 0)
251         {
252             if (size < len + 1)
253             {
254                 fprintf(stderr,"Fatal readline goof.\n");
255                 exit(0);
256             }
257             strcpy(buf, line);
258             buf[len] = '\n';
259             buf[len+1] = 0;
260             return len + 1;
261         }
262     }
265 static char *local_symbols[30];
266 static int next_symbol;
268 char * make_symbol(char * symbol){
269         return local_symbols[next_symbol++] = xstrdup(symbol);
272 void flush_symbols()
274         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
275         next_symbol = 0;
278 #endif  /* DONT_USE_READLINE */