First working version.
[wine.git] / debugger / debug.l
blob02aa298c13e6d2bb9529ecedff7db23a07a81f2c
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 "y.tab.h"
14 #ifdef DBG_need_heap
15 #define malloc(x) DBG_alloc(x)
16 #define realloc(x,y) DBG_realloc(x,y)
17 #define free(x) DBG_free(x)
18 #endif
20 #ifndef DONT_USE_READLINE
21 #undef YY_INPUT
22 #define YY_INPUT(buf,result,max_size) \
23         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
24             YY_FATAL_ERROR( "read() in flex scanner failed" );
26 extern char * readline(const char *);
27 extern void add_history(char *);
28 static int dbg_read(char * buf, int size);
29 static char * make_symbol(char *);
30 void flush_symbols();
32 #endif  /* DONT_USE_READLINE */
34 #define YY_NO_UNPUT
36 static int syntax_error;
39 DIGIT      [0-9]
40 HEXDIGIT   [0-9a-fA-F]
41 FORMAT     [ubcdiswx]
42 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
43 PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
44 STRING     \"[^\n"]+\"
46 %s FORMAT_EXPECTED
47 %s PATH_EXPECTED
48 %s INFO_CMD
49 %s HELP_CMD
50 %s DEL_CMD
51 %s WALK_CMD
52 %s SHOW_CMD
53 %s NOCMD
54 %s DEBUGSTR
58 \n              { BEGIN(0); syntax_error = 0; 
59                   return tEOL; } /*Indicates end of command.  Reset state. */
61 "||"            { return OP_LOR; }
62 "&&"            { return OP_LAND; }
63 "=="            { return OP_EQ; }
64 "!="            { return OP_NE; }
65 "<="            { return OP_LE; }
66 ">="            { return OP_GE; }
67 "<<"            { return OP_SHL; }
68 ">>"            { return OP_SHR; }
69 "->"            { return OP_DRF; }
70 [-+<=>|&^()*/%:!~,\.]   { return *yytext; }
71 "["             { return *yytext; }
72 "]"             { return *yytext; }
74 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
75 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
78 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}  { char * last;
79                        yylval.integer = strtol( yytext+1, &last, NULL );
80                        yylval.integer = (yylval.integer << 8) | *last;
81                        return tFORMAT; }
84 <FORMAT_EXPECTED>"/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
86 {STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
87 <DEBUGSTR>[a-z+\-,]* { yylval.string = yytext; return tDEBUGSTR; }
89 $pc     { yylval.reg = REG_EIP; return tREG; }
90 $flags  { yylval.reg = REG_EFL; return tREG; }
91 $eip    { yylval.reg = REG_EIP; return tREG; }
92 $ip     { yylval.reg = REG_IP;  return tREG; }
93 $esp    { yylval.reg = REG_ESP; return tREG; }
94 $sp     { yylval.reg = REG_SP;  return tREG; }
95 $eax    { yylval.reg = REG_EAX; return tREG; }
96 $ebx    { yylval.reg = REG_EBX; return tREG; }
97 $ecx    { yylval.reg = REG_ECX; return tREG; }
98 $edx    { yylval.reg = REG_EDX; return tREG; }
99 $esi    { yylval.reg = REG_ESI; return tREG; }
100 $edi    { yylval.reg = REG_EDI; return tREG; }
101 $ebp    { yylval.reg = REG_EBP; return tREG; }
102 $ax     { yylval.reg = REG_AX;  return tREG; }
103 $bx     { yylval.reg = REG_BX;  return tREG; }
104 $cx     { yylval.reg = REG_CX;  return tREG; }
105 $dx     { yylval.reg = REG_DX;  return tREG; }
106 $si     { yylval.reg = REG_SI;  return tREG; }
107 $di     { yylval.reg = REG_DI;  return tREG; }
108 $bp     { yylval.reg = REG_BP;  return tREG; }
109 $es     { yylval.reg = REG_ES;  return tREG; }
110 $ds     { yylval.reg = REG_DS;  return tREG; }
111 $cs     { yylval.reg = REG_CS;  return tREG; }
112 $ss     { yylval.reg = REG_SS;  return tREG; }
113 $fs     { yylval.reg = REG_FS;  return tREG; }
114 $gs     { yylval.reg = REG_GS;  return tREG; }
116 <INITIAL>info|inf|in                    { BEGIN(INFO_CMD); return tINFO; }
117 <INITIAL>up                             { BEGIN(NOCMD); return tUP; }
118 <INITIAL>down|dow|do                    { BEGIN(NOCMD); return tDOWN; }
119 <INITIAL>frame|fram|fra|fr              { BEGIN(NOCMD); return tFRAME; }
120 <INITIAL>list|lis|li|l                  { BEGIN(PATH_EXPECTED); return tLIST; }
121 <INITIAL>enable|enabl|enab|ena          { BEGIN(NOCMD); return tENABLE;}
122 <INITIAL>debugmsg|debugms|debugm|debug|debu|deb { BEGIN(DEBUGSTR); return tDEBUGMSG;}
123 <INITIAL>disable|disabl|disab|disa|dis  { BEGIN(NOCMD); return tDISABLE; }
124 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
125 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp     { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
126 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und       { BEGIN(NOCMD); return tUNDISPLAY; }
127 <INITIAL>delete|delet|dele|del          { BEGIN(DEL_CMD); return tDELETE; }
128 <INITIAL>quit|qui|qu|q                  { BEGIN(NOCMD); return tQUIT; }
129 <INITIAL>set|se                         { BEGIN(NOCMD); return tSET; }
130 <INITIAL>walk|w                         { BEGIN(WALK_CMD); return tWALK; }
131 <INITIAL>x                              { BEGIN(FORMAT_EXPECTED); return tEXAM; }
132 <INITIAL>help|hel|he|"?"                { BEGIN(HELP_CMD); return tHELP; }
134 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
135 <INITIAL>where|wher|whe                  { BEGIN(NOCMD); return tBACKTRACE; }
137 <INITIAL>cont|con|co|c                  { BEGIN(NOCMD); return tCONT; }
138 <INITIAL>pass|pas|pa                    { BEGIN(NOCMD); return tPASS; }
139 <INITIAL>condition|conditio|conditi|condit|condi|cond   { BEGIN(NOCMD); return tCOND; }
140 <INITIAL>step|ste|st|s                  { BEGIN(NOCMD); return tSTEP; }
141 <INITIAL>next|nex|ne|n                  { BEGIN(NOCMD); return tNEXT; }
142 <INITIAL>stepi|si                       { BEGIN(NOCMD); return tSTEPI; }
143 <INITIAL>nexti|ni                       { BEGIN(NOCMD); return tNEXTI; }
144 <INITIAL>finish|finis|fini|fin|fi       { BEGIN(NOCMD); return tFINISH; }
146 <INITIAL>abort|abor|abo                 { BEGIN(NOCMD); return tABORT; }
147 <INITIAL>print|prin|pri|pr|p            { BEGIN(FORMAT_EXPECTED); return tPRINT; }
149 <INITIAL>mode                           { BEGIN(NOCMD); return tMODE; }
150 <INITIAL>show|sho|sh                    { BEGIN(SHOW_CMD); return tSHOW; }
151 <INITIAL>symbolfile|symbols|symbol|sf   { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
153 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b   { BEGIN(PATH_EXPECTED); return tBREAK; }
155 <INFO_CMD>share|shar|sha                { return tSHARE; }
156 <INFO_CMD>locals|local|loca|loc         { return tLOCAL; }
157 <INFO_CMD,WALK_CMD>class|clas|cla                  { return tCLASS; }
158 <INFO_CMD,WALK_CMD>module|modul|modu|mod  { return tMODULE; }
159 <INFO_CMD,WALK_CMD>queue|queu|que                       { return tQUEUE; }
160 <INFO_CMD,WALK_CMD>process|proces|proce|proc            { return tPROCESS; }
161 <INFO_CMD,WALK_CMD>modref|modre|modr                    { return tMODREF; }
162 <INFO_CMD>registers|regs|reg|re         { return tREGS; }
163 <INFO_CMD>segments|segment|segm|seg|se  { return tSEGMENTS; }
164 <INFO_CMD>stack|stac|sta|st                     { return tSTACK; }
165 <INFO_CMD>maps|map                      { return tMAPS; }
166 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd    { return tWND; }
167 <HELP_CMD>info|inf|in                   { return tINFO; }
169 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir { 
170                         BEGIN(PATH_EXPECTED); return tDIR; }
172 char                                    { return tCHAR; }
173 short                                   { return tSHORT; }
174 int                                     { return tINT; }
175 long                                    { return tLONG; }
176 float                                   { return tFLOAT; }
177 double                                  { return tDOUBLE; }
178 unsigned                                { return tUNSIGNED; }
179 signed                                  { return tSIGNED; }
180 struct                                  { return tSTRUCT; }
181 union                                   { return tUNION; }
182 enum                                    { return tENUM; }
184 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
186 <PATH_EXPECTED>{PATHNAME}       { yylval.string = make_symbol(yytext); return tPATH; }
188 [ \t]+        /* Eat up whitespace */
190 .               { if (syntax_error == 0)
191                   {
192                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
193                   }
194                 }
199 #ifndef yywrap
200 int yywrap(void) { return 1; }
201 #endif
203 #ifndef DONT_USE_READLINE
205 #ifndef whitespace
206 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
207 #endif
210 /* Strip whitespace from the start and end of STRING. */
211 static void stripwhite (char *string)
213   register int i = 0;
215   while (whitespace (string[i]))
216     i++;
218   if (i)
219     strcpy (string, string + i);
221   i = strlen (string) - 1;
223   while (i > 0 && whitespace (string[i]))
224     i--;
226   string[++i] = '\0';
229 static int dbg_read(char * buf, int size)
231     static char last_line[256] = "";
232     char * line;
233     int len;
234     
235     for (;;)
236     {
237         flush_symbols();
238         line = readline ("Wine-dbg>");
239         if (!line)
240         {
241             fprintf( stderr, "\n" );
242             exit(0);
243         }
245         /* Remove leading and trailing whitespace from the line */
247         stripwhite (line);
249         /* If there is anything left, add it to the history list
250            and execute it. Otherwise, re-execute last command. */
252         if (*line)
253         {
254             add_history( line );
255             strncpy( last_line, line, 255 );
256             last_line[255] = '\0'; 
257        }
259         free( line );
260         line = last_line;
262         if ((len = strlen(line)) > 0)
263         {
264             if (size < len + 1)
265             {
266                 fprintf(stderr,"Fatal readline goof.\n");
267                 exit(0);
268             }
269             strcpy(buf, line);
270             buf[len] = '\n';
271             buf[len+1] = 0;
272             return len + 1;
273         }
274     }
277 static char *local_symbols[30];
278 static int next_symbol;
280 char * make_symbol(char * symbol){
281         return local_symbols[next_symbol++] = DBG_strdup(symbol);
284 void flush_symbols()
286         while(--next_symbol>= 0) DBG_free(local_symbols[next_symbol]);
287         next_symbol = 0;
290 #endif  /* DONT_USE_READLINE */