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