winedbg: Add 'info system' command.
[wine.git] / programs / winedbg / debug.l
blobdd7fb0db76f9f7d7ce40052982cc4b7c3863b14d
1 /* -*-C-*-
2  * Lexical scanner for command line parsing
3  *
4  * Copyright 1993 Eric Youngdale
5  *           2000 Eric Pouech
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
22 %option noinput nounput always-interactive 8bit prefix="dbg_"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
29 #define YY_NO_UNISTD_H
30 #include "debugger.h"
31 #include "dbg.tab.h"
33 #undef YY_INPUT
35 static char** local_lexemes /* = NULL */;
36 static int next_lexeme /* = 0 */;
37 static int alloc_lexeme /* = 0 */;
39 char* lexeme_alloc_size(int size)
41     assert(0 <= next_lexeme && next_lexeme < alloc_lexeme + 1);
42     if (next_lexeme >= alloc_lexeme)
43     {
44         alloc_lexeme += 32;
45         local_lexemes = realloc(local_lexemes, alloc_lexeme * sizeof(local_lexemes[0]));
46         assert(local_lexemes);
47     }
48     return local_lexemes[next_lexeme++] = malloc(size + 1);
51 static char* lexeme_alloc(const char* lexeme)
53     char*       ptr = lexeme_alloc_size(strlen(lexeme) + 1);
54     return strcpy(ptr, lexeme);
57 static char* lexeme_alloc_if(const char* lexeme, unsigned sz)
59     size_t len = strlen(lexeme);
60     char* ptr;
61     if (len <= sz) return NULL;
62     len -= sz;
63     ptr = lexeme_alloc_size(len + 1);
64     memcpy(ptr, lexeme, len);
65     ptr[len] = '\0';
66     return ptr;
69 void lexeme_flush(void)
71     while (--next_lexeme >= 0) free(local_lexemes[next_lexeme]);
72     next_lexeme = 0;
75 /* called with quoted string, unescape all elements inside the quotes */
76 static char* unescape_string(const char* str)
78     size_t len = strlen(str) - 2;
79     char* ret = lexeme_alloc_size(len + 1);
80     char* dst = ret;
81     const char* ptr;
82     for (ptr = str + 1; ptr < str + 1 + len; ptr++)
83     {
84         if (*ptr == '\\')
85         {
86             switch (*++ptr)
87             {
88             case 't':  *dst++ = '\t'; break;
89             case 'r':  *dst++ = '\r'; break;
90             case 'n':  *dst++ = '\n'; break;
91             case '\\': *dst++ = '\\'; break;
92             case '"':  *dst++ = '"';  break;
93             default: *dst++ = '\\'; *dst++ = *ptr; /* not handled, don't change */
94             }
95         }
96         else
97             *dst++ = *ptr;
98     }
99     *dst = '\0';
100     return ret;
103 static int resolve_identifier(const char* id, DBG_STYPE* lval)
105     if (types_find_type(id, SymTagTypedef, &lval->type)) return tTYPEDEF;
106     lval->string = lexeme_alloc(id);
107     return tIDENTIFIER;
110 #define YY_INPUT(buf,result,max_size) \
111         (result = input_lex_read_buffer(buf, max_size))
113 static int syntax_error;
116 OCTDIGIT   [0-7]
117 DIGIT      [0-9]
118 HEXDIGIT   [0-9a-fA-F]
119 FORMAT     [ubcdgiswxa]
120 IDENTIFIER [_a-zA-Z~?][_a-zA-Z0-9~?@]*
121 SCOPED_IDENTIFIER [_a-zA-Z~?][_a-zA-Z0-9~?@]*"::"
122 MODULE_IDENTIFIER [_a-zA-Z~?\*][_a-zA-Z0-9~?\*@\.]*"!"
123 PATHNAME   [\\/_a-zA-Z0-9\.~@][\\/\-_a-zA-Z0-9\.~@]*
124 STRING     \"(\\[^\n]|[^\\"\n])*\"
126 %s FORMAT_EXPECTED
127 %s INFO_CMD
128 %s HELP_CMD
129 %s BD_CMD
130 %s LOCAL_CMD
131 %s SHOW_CMD
132 %s MODE_CMD
133 %s MAINT_CMD
134 %s NOCMD
135 %s PATH_ACCEPTED
137 %x PATH_EXPECTED
138 %x ASTRING_EXPECTED
139 %x AWORD_EXPECTED
140 %x NOPROCESS
142                                         /* set to special state when no process is loaded. */
143                                         if (!dbg_num_processes() && YYSTATE == INITIAL) {BEGIN(NOPROCESS);}
145 <<EOF>>                                 { return tEOF; }
146 <*>"#"[^\n]*                            /* Skip comments */
147 <*>\n                                   { BEGIN(INITIAL); syntax_error = 0; return tEOL; }
148                                         /* Indicates end of command. Reset state. */
150 "||"                                    { return OP_LOR; }
151 "&&"                                    { return OP_LAND; }
152 "=="                                    { return OP_EQ; }
153 "!="                                    { return OP_NE; }
154 "<="                                    { return OP_LE; }
155 ">="                                    { return OP_GE; }
156 "<<"                                    { return OP_SHL; }
157 ">>"                                    { return OP_SHR; }
158 "->"                                    { return OP_DRF; }
159 "["                                     { return *yytext; }
160 "]"                                     { return *yytext; }
162 "0x"{HEXDIGIT}+                         { sscanf(yytext, "%I64x", &dbg_lval.integer); return tNUM; }
163 {DIGIT}+                                { sscanf(yytext, "%I64d", &dbg_lval.integer); return tNUM; }
164 "'\\''"                                 { dbg_lval.integer = '\''; return tNUM;}
165 "'\\0"{OCTDIGIT}*"'"                    { sscanf(yytext + 3, "%I64o", &dbg_lval.integer); return tNUM;}
166 "'\\x"{HEXDIGIT}+"'"                    { sscanf(yytext + 3, "%I64x", &dbg_lval.integer); return tNUM;}
167 "'\\"[a-z]"'"                           { dbg_lval.integer = yytext[2] - 'a'; return tNUM;}
168 "'"."'"                                 { dbg_lval.integer = yytext[1]; return tNUM;}
170 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}    { char* last;
171                                           dbg_lval.integer = strtol(yytext+1, &last, 0) << 8;
172                                           dbg_lval.integer |= *last;
173                                           return tFORMAT; }
175 <FORMAT_EXPECTED>"/"{FORMAT}            { dbg_lval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
177 <*>{STRING}                             { dbg_lval.string = unescape_string(yytext); return tSTRING;}
178 <ASTRING_EXPECTED>[^\n]+                { char* p = yytext; while (*p == ' ' || *p == '\t') p++;
179                                           dbg_lval.string = lexeme_alloc(p); return tSTRING; }
180 <AWORD_EXPECTED>[^ \t\n]+               { char* p = yytext; while (*p == ' ' || *p == '\t') p++;
181                                           dbg_lval.string = lexeme_alloc(p); return tSTRING; }
182 <INITIAL,NOPROCESS>info|inf|in          { BEGIN(INFO_CMD); return tINFO; }
183 <INITIAL>up                             { BEGIN(NOCMD); return tUP; }
184 <INITIAL>down|dow|do                    { BEGIN(NOCMD); return tDOWN; }
185 <INITIAL,INFO_CMD>frame|fram|fra|fr     { BEGIN(NOCMD); return tFRAME; }
186 <INITIAL>list|lis|li|l                  { BEGIN(PATH_ACCEPTED); return tLIST; }
187 <INITIAL>enable|enabl|enab|ena          { BEGIN(BD_CMD); return tENABLE;}
188 <INITIAL>disable|disabl|disab|disa|dis  { BEGIN(BD_CMD); return tDISABLE; }
189 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
190 <INITIAL>locally|local                  { BEGIN(LOCAL_CMD); return tLOCAL; }
191 <INITIAL,LOCAL_CMD>display|displa|displ|disp    { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
192 <INFO_CMD,BD_CMD>display|displa|displ|disp|dis|di|d     { BEGIN(NOCMD); return tDISPLAY; }
193 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und       { BEGIN(NOCMD); return tUNDISPLAY; }
194 <INITIAL>delete|delet|dele|del          { BEGIN(BD_CMD); return tDELETE; }
195 <INITIAL>thread|threa|thre|thr|th       { BEGIN(NOCMD); return tTHREAD; }
196 <INITIAL,NOPROCESS>quit|qui|qu|q        { BEGIN(NOCMD); return tQUIT; }
197 <INITIAL>set|se                         { BEGIN(NOCMD); return tSET; }
198 <INITIAL>x                              { BEGIN(FORMAT_EXPECTED); return tEXAM; }
199 <INITIAL,NOPROCESS>help|hel|he|"?"      { BEGIN(HELP_CMD); return tHELP; }
201 <INITIAL,NOPROCESS>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
202 <INITIAL,NOPROCESS>where|wher|whe       { BEGIN(NOCMD); return tBACKTRACE; }
204 <INITIAL>continue|continu|contin|conti|cont|con|co|c    { BEGIN(NOCMD); return tCONT; }
205 <INITIAL>pass|pas|pa                    { BEGIN(NOCMD); return tPASS; }
206 <INITIAL>condition|conditio|conditi|condit|condi|cond   { BEGIN(NOCMD); return tCOND; }
207 <INITIAL>step|ste|st|s                  { BEGIN(NOCMD); return tSTEP; }
208 <INITIAL>next|nex|ne|n                  { BEGIN(NOCMD); return tNEXT; }
209 <INITIAL>stepi|si                       { BEGIN(NOCMD); return tSTEPI; }
210 <INITIAL>nexti|ni                       { BEGIN(NOCMD); return tNEXTI; }
211 <INITIAL>finish|finis|fini|fin|fi       { BEGIN(NOCMD); return tFINISH; }
213 <INITIAL>abort|abor|abo                 { BEGIN(NOCMD); return tABORT; }
214 <INITIAL>print|prin|pri|pr|p            { BEGIN(FORMAT_EXPECTED); return tPRINT; }
216 <INITIAL>show|sho|sh                    { BEGIN(SHOW_CMD); return tSHOW; }
217 <INITIAL,NOPROCESS>source|sourc|sour|src { BEGIN(PATH_EXPECTED); return tSOURCE; }
218 <INITIAL>symbolfile|symbols|symbol|sf   { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
219 <INITIAL,INFO_CMD>wow                   { return tWOW; }
221 <INITIAL,INFO_CMD,BD_CMD>break|brea|bre|br|b    { BEGIN(PATH_ACCEPTED); return tBREAK; }
222 <INITIAL,INFO_CMD,BD_CMD>hbreak|hbrea|hbre|hbr|hb { BEGIN(PATH_ACCEPTED); return tHBREAK; }
223 <INITIAL>watch|watc|wat                 { BEGIN(NOCMD); return tWATCH; }
224 <INITIAL>rwatch|rwatc|rwat              { BEGIN(NOCMD); return tRWATCH; }
225 <INITIAL>whatis|whati|what              { BEGIN(NOCMD); return tWHATIS; }
226 <INITIAL,NOPROCESS>run|ru|r             { BEGIN(AWORD_EXPECTED); return tRUN;}
227 <INITIAL>detach|detac|deta|det          { BEGIN(NOCMD); return tDETACH; }
228 <INITIAL>kill|kil|ki|k                  { BEGIN(NOCMD); return tKILL; }
229 <INITIAL,NOPROCESS>maintenance|maint    { BEGIN(MAINT_CMD); return tMAINTENANCE; }
230 <INITIAL>minidump|mdmp                  { BEGIN(PATH_EXPECTED); return tMINIDUMP; }
231 <INITIAL>echo                           { BEGIN(ASTRING_EXPECTED); return tECHO; }
232 <NOPROCESS>attach|attac|atta|att        { BEGIN(NOCMD); return tATTACH; }
233 <INFO_CMD>share|shar|sha                { return tSHARE; }
234 <MAINT_CMD>module|modul|mod             { BEGIN(ASTRING_EXPECTED); return tMODULE; }
235 <INFO_CMD>locals|local|loca|loc         { return tLOCAL; }
236 <INFO_CMD>class|clas|cla                { return tCLASS; }
237 <INFO_CMD>process|proces|proce|proc     { return tPROCESS; }
238 <INFO_CMD>threads|thread|threa|thre|thr|th { return tTHREAD; }
239 <INFO_CMD>exception|except|exc|ex       { return tEXCEPTION; }
240 <INFO_CMD>registers|regs|reg|re         { return tREGS; }
241 <INFO_CMD>allregs|allreg|allre          { return tALLREGS; }
242 <INFO_CMD>"all-registers"|"all-regs"|"all-reg"|"all-re" { return tALLREGS; }
243 <INFO_CMD>segments|segment|segm|seg|se  { return tSEGMENTS; }
244 <INFO_CMD>stack|stac|sta|st             { return tSTACK; }
245 <INFO_CMD>symbol|symbo|symb|sym         { BEGIN(ASTRING_EXPECTED); return tSYMBOL; }
246 <INFO_CMD>maps|map                      { return tMAPS; }
247 <INFO_CMD>window|windo|wind|win|wnd     { return tWND; }
248 <INFO_CMD>system|syst|sys               { return tSYSTEM; }
249 <HELP_CMD>info|inf|in                   { return tINFO; }
250 <MAINT_CMD>type                         { return tTYPE; }
252 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir {
253                                           BEGIN(PATH_EXPECTED); return tDIR; }
255 {MODULE_IDENTIFIER}?void                { dbg_lval.string = lexeme_alloc_if(yytext, 5); return tVOID; } /* return modulename if present */
256 {MODULE_IDENTIFIER}?char                { dbg_lval.string = lexeme_alloc_if(yytext, 5); return tCHAR; }
257 {MODULE_IDENTIFIER}?WCHAR               { dbg_lval.string = lexeme_alloc_if(yytext, 6); return tWCHAR; }
258 {MODULE_IDENTIFIER}?short               { dbg_lval.string = lexeme_alloc_if(yytext, 6); return tSHORT; }
259 {MODULE_IDENTIFIER}?int                 { dbg_lval.string = lexeme_alloc_if(yytext, 4); return tINT; }
260 {MODULE_IDENTIFIER}?long                { dbg_lval.string = lexeme_alloc_if(yytext, 5); return tLONG; }
261 {MODULE_IDENTIFIER}?float               { dbg_lval.string = lexeme_alloc_if(yytext, 6); return tFLOAT; }
262 {MODULE_IDENTIFIER}?double              { dbg_lval.string = lexeme_alloc_if(yytext, 7); return tDOUBLE; }
263 {MODULE_IDENTIFIER}?unsigned            { dbg_lval.string = lexeme_alloc_if(yytext, 9); return tUNSIGNED; }
264 {MODULE_IDENTIFIER}?signed              { dbg_lval.string = lexeme_alloc_if(yytext, 7); return tSIGNED; }
265 struct                                  { return tSTRUCT; }
266 union                                   { return tUNION; }
267 enum                                    { return tENUM; }
268 all                                     { return tALL; }
270 {MODULE_IDENTIFIER}?{SCOPED_IDENTIFIER}*{IDENTIFIER} { return resolve_identifier(yytext, &dbg_lval); }
271 "$"{IDENTIFIER}                         { dbg_lval.string = lexeme_alloc(yytext+1); return tINTVAR; }
273 <PATH_EXPECTED,PATH_ACCEPTED>{PATHNAME} { dbg_lval.string = lexeme_alloc(yytext); return tPATH; }
275 [-+<=>|&^()*/%:!~,\.]                   { return *yytext; }
277 <*>[ \t\r]+                             /* Eat up whitespace and DOS LF */
279 <NOPROCESS>.                            { BEGIN(ASTRING_EXPECTED); yyless(0); return tNOPROCESS;}
280 <*>.                                    { if (syntax_error == 0) { syntax_error++; dbg_printf("Syntax Error (%s)\n", yytext); } }
283 #ifndef dbg_wrap
284 int dbg_wrap(void) { return 1; }
285 #endif