debug.l 7.65 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/* -*-C-*-
Alexandre Julliard's avatar
Alexandre Julliard committed
2
 * Lexical scanner for command line parsing
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
4
 * Copyright 1993 Eric Youngdale
Alexandre Julliard's avatar
Alexandre Julliard committed
5 6 7
 */

%{
Alexandre Julliard's avatar
Alexandre Julliard committed
8
#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
9
#include <string.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
10
#include "debugger.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
11
#include "y.tab.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
12

13 14 15 16 17 18
#ifdef DBG_need_heap
#define malloc(x) DBG_alloc(x)
#define realloc(x,y) DBG_realloc(x,y)
#define free(x) DBG_free(x)
#endif

Alexandre Julliard's avatar
Alexandre Julliard committed
19
#ifndef DONT_USE_READLINE
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21 22 23 24
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
	    YY_FATAL_ERROR( "read() in flex scanner failed" );

Alexandre Julliard's avatar
Alexandre Julliard committed
25
static int dbg_read(char * buf, int size);
Alexandre Julliard's avatar
Alexandre Julliard committed
26
static char * make_symbol(char *);
Alexandre Julliard's avatar
Alexandre Julliard committed
27 28 29

#endif  /* DONT_USE_READLINE */

Alexandre Julliard's avatar
Alexandre Julliard committed
30 31
#define YY_NO_UNPUT

Alexandre Julliard's avatar
Alexandre Julliard committed
32 33 34
static int syntax_error;
%}

Alexandre Julliard's avatar
Alexandre Julliard committed
35 36
DIGIT	   [0-9]
HEXDIGIT   [0-9a-fA-F]
37
FORMAT     [ubcdiswx]
Alexandre Julliard's avatar
Alexandre Julliard committed
38
IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
Alexandre Julliard's avatar
Alexandre Julliard committed
39 40 41 42 43 44 45 46 47 48 49
PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
STRING     \"[^\n"]+\"

%s FORMAT_EXPECTED
%s PATH_EXPECTED
%s INFO_CMD
%s HELP_CMD
%s DEL_CMD
%s WALK_CMD
%s SHOW_CMD
%s NOCMD
50
%s DEBUGSTR
Alexandre Julliard's avatar
Alexandre Julliard committed
51 52 53

%%

Alexandre Julliard's avatar
Alexandre Julliard committed
54 55
\n		{ BEGIN(0); syntax_error = 0; 
		  return tEOL; } /*Indicates end of command.  Reset state. */
Alexandre Julliard's avatar
Alexandre Julliard committed
56 57 58 59 60 61 62 63 64

"||"		{ return OP_LOR; }
"&&"		{ return OP_LAND; }
"=="		{ return OP_EQ; }
"!="		{ return OP_NE; }
"<="		{ return OP_LE; }
">="		{ return OP_GE; }
"<<"		{ return OP_SHL; }
">>"		{ return OP_SHR; }
Alexandre Julliard's avatar
Alexandre Julliard committed
65 66 67 68
"->"		{ return OP_DRF; }
[-+<=>|&^()*/%:!~,\.]	{ return *yytext; }
"["		{ return *yytext; }
"]"		{ return *yytext; }
Alexandre Julliard's avatar
Alexandre Julliard committed
69

Alexandre Julliard's avatar
Alexandre Julliard committed
70 71
"0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
{DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
Alexandre Julliard's avatar
Alexandre Julliard committed
72

Alexandre Julliard's avatar
Alexandre Julliard committed
73 74

<FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}  { char * last;
Alexandre Julliard's avatar
Alexandre Julliard committed
75 76
                       yylval.integer = strtol( yytext+1, &last, NULL );
                       yylval.integer = (yylval.integer << 8) | *last;
Alexandre Julliard's avatar
Alexandre Julliard committed
77
                       return tFORMAT; }
Alexandre Julliard's avatar
Alexandre Julliard committed
78 79 80 81 82


<FORMAT_EXPECTED>"/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }

{STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
83
<DEBUGSTR>[a-z+\-,]* { yylval.string = yytext; return tDEBUGSTR; }
Alexandre Julliard's avatar
Alexandre Julliard committed
84

Alexandre Julliard's avatar
Alexandre Julliard committed
85 86 87 88 89 90
<INITIAL>info|inf|in			{ BEGIN(INFO_CMD); return tINFO; }
<INITIAL>up				{ BEGIN(NOCMD); return tUP; }
<INITIAL>down|dow|do			{ BEGIN(NOCMD); return tDOWN; }
<INITIAL>frame|fram|fra|fr		{ BEGIN(NOCMD); return tFRAME; }
<INITIAL>list|lis|li|l			{ BEGIN(PATH_EXPECTED); return tLIST; }
<INITIAL>enable|enabl|enab|ena		{ BEGIN(NOCMD); return tENABLE;}
Alexandre Julliard's avatar
Alexandre Julliard committed
91 92
<INITIAL>disable|disabl|disab|disa|dis  { BEGIN(NOCMD); return tDISABLE; }
<INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
Alexandre Julliard's avatar
Alexandre Julliard committed
93
<INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp	{ BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95 96 97 98 99 100 101 102
<INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und	{ BEGIN(NOCMD); return tUNDISPLAY; }
<INITIAL>delete|delet|dele|del		{ BEGIN(DEL_CMD); return tDELETE; }
<INITIAL>quit|qui|qu|q			{ BEGIN(NOCMD); return tQUIT; }
<INITIAL>set|se				{ BEGIN(NOCMD); return tSET; }
<INITIAL>walk|w				{ BEGIN(WALK_CMD); return tWALK; }
<INITIAL>x				{ BEGIN(FORMAT_EXPECTED); return tEXAM; }
<INITIAL>help|hel|he|"?"		{ BEGIN(HELP_CMD); return tHELP; }

<INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
103
<INITIAL>where|wher|whe                 { BEGIN(NOCMD); return tBACKTRACE; }
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105

<INITIAL>cont|con|co|c   		{ BEGIN(NOCMD); return tCONT; }
106
<INITIAL>pass|pas|pa   			{ BEGIN(NOCMD); return tPASS; }
Alexandre Julliard's avatar
Alexandre Julliard committed
107 108 109 110 111 112 113 114 115 116 117 118
<INITIAL>condition|conditio|conditi|condit|condi|cond	{ BEGIN(NOCMD); return tCOND; }
<INITIAL>step|ste|st|s   		{ BEGIN(NOCMD); return tSTEP; }
<INITIAL>next|nex|ne|n   		{ BEGIN(NOCMD); return tNEXT; }
<INITIAL>stepi|si	   		{ BEGIN(NOCMD); return tSTEPI; }
<INITIAL>nexti|ni	   		{ BEGIN(NOCMD); return tNEXTI; }
<INITIAL>finish|finis|fini|fin|fi	{ BEGIN(NOCMD); return tFINISH; }

<INITIAL>abort|abor|abo         	{ BEGIN(NOCMD); return tABORT; }
<INITIAL>print|prin|pri|pr|p		{ BEGIN(FORMAT_EXPECTED); return tPRINT; }

<INITIAL>mode				{ BEGIN(NOCMD); return tMODE; }
<INITIAL>show|sho|sh			{ BEGIN(SHOW_CMD); return tSHOW; }
119
<INITIAL>symbolfile|symbols|symbol|sf   { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
Alexandre Julliard's avatar
Alexandre Julliard committed
120

Alexandre Julliard's avatar
Alexandre Julliard committed
121
<INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b	{ BEGIN(PATH_EXPECTED); return tBREAK; }
122
<INITIAL>watch|watc|wat			{ BEGIN(PATH_EXPECTED); return tWATCH; }
123
<INITIAL>whatis|whati|what		{ BEGIN(PATH_EXPECTED); return tWHATIS; }
Alexandre Julliard's avatar
Alexandre Julliard committed
124 125 126

<INFO_CMD>share|shar|sha		{ return tSHARE; }
<INFO_CMD>locals|local|loca|loc		{ return tLOCAL; }
127
<INFO_CMD,WALK_CMD>class|clas|cla       { return tCLASS; }
Alexandre Julliard's avatar
Alexandre Julliard committed
128
<INFO_CMD,WALK_CMD>module|modul|modu|mod  { return tMODULE; }
129
<INFO_CMD,WALK_CMD>queue|queu|que	{ return tQUEUE; }
130
<INFO_CMD,WALK_CMD>process|proces|proce|proc   		{ return tPROCESS; }
131
<INFO_CMD,WALK_CMD>threads|thread|threa|thre|thr|th { return tTHREAD; }
132
<INFO_CMD,WALK_CMD>modref|modre|modr	{ return tMODREF; }
Alexandre Julliard's avatar
Alexandre Julliard committed
133 134
<INFO_CMD>registers|regs|reg|re		{ return tREGS; }
<INFO_CMD>segments|segment|segm|seg|se	{ return tSEGMENTS; }
135
<INFO_CMD>stack|stac|sta|st     	{ return tSTACK; }
Alexandre Julliard's avatar
Alexandre Julliard committed
136
<INFO_CMD>maps|map			{ return tMAPS; }
Alexandre Julliard's avatar
Alexandre Julliard committed
137 138 139 140 141
<INFO_CMD,WALK_CMD>window|windo|wind|win|wnd	{ return tWND; }
<HELP_CMD>info|inf|in                   { return tINFO; }

<INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir { 
			BEGIN(PATH_EXPECTED); return tDIR; }
Alexandre Julliard's avatar
Alexandre Julliard committed
142

Alexandre Julliard's avatar
Alexandre Julliard committed
143 144 145 146 147 148 149 150 151 152 153 154
char					{ return tCHAR; }
short					{ return tSHORT; }
int					{ return tINT; }
long					{ return tLONG; }
float					{ return tFLOAT; }
double					{ return tDOUBLE; }
unsigned				{ return tUNSIGNED; }
signed					{ return tSIGNED; }
struct					{ return tSTRUCT; }
union					{ return tUNION; }
enum					{ return tENUM; }

Alexandre Julliard's avatar
Alexandre Julliard committed
155
{IDENTIFIER}	{ yylval.string = make_symbol(yytext); return tIDENTIFIER; }
156
"$"{IDENTIFIER}	{ yylval.string = make_symbol(yytext+1); return tINTVAR; }
Alexandre Julliard's avatar
Alexandre Julliard committed
157

Alexandre Julliard's avatar
Alexandre Julliard committed
158 159
<PATH_EXPECTED>{PATHNAME}	{ yylval.string = make_symbol(yytext); return tPATH; }

Alexandre Julliard's avatar
Alexandre Julliard committed
160 161
[ \t]+        /* Eat up whitespace */

Alexandre Julliard's avatar
Alexandre Julliard committed
162 163
.		{ if (syntax_error == 0)
                  {
164
		    syntax_error ++; DEBUG_Printf(DBG_CHN_MESG, "Syntax Error\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
165
                  }
Alexandre Julliard's avatar
Alexandre Julliard committed
166 167
		}

Alexandre Julliard's avatar
Alexandre Julliard committed
168

Alexandre Julliard's avatar
Alexandre Julliard committed
169 170
%%

Alexandre Julliard's avatar
Alexandre Julliard committed
171 172 173 174
#ifndef yywrap
int yywrap(void) { return 1; }
#endif

Alexandre Julliard's avatar
Alexandre Julliard committed
175 176
#ifndef DONT_USE_READLINE

Alexandre Julliard's avatar
Alexandre Julliard committed
177 178 179 180 181
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif


Alexandre Julliard's avatar
Alexandre Julliard committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
/* Strip whitespace from the start and end of STRING. */
static void stripwhite (char *string)
{
  register int i = 0;

  while (whitespace (string[i]))
    i++;

  if (i)
    strcpy (string, string + i);

  i = strlen (string) - 1;

  while (i > 0 && whitespace (string[i]))
    i--;

  string[++i] = '\0';
}

Alexandre Julliard's avatar
Alexandre Julliard committed
201 202 203 204 205 206 207 208 209 210
static int dbg_read(char * buf, int size)
{
    static char last_line[256] = "";
    char * line;
    int len;
    
    for (;;)
    {
        flush_symbols();
        line = readline ("Wine-dbg>");
Alexandre Julliard's avatar
Alexandre Julliard committed
211 212
        if (!line)
        {
213
            DEBUG_Printf( DBG_CHN_MESG, "\n" );
214
            DEBUG_Exit(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
215
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
216

Alexandre Julliard's avatar
Alexandre Julliard committed
217 218
        /* Remove leading and trailing whitespace from the line */

Alexandre Julliard's avatar
Alexandre Julliard committed
219 220
        stripwhite (line);

Alexandre Julliard's avatar
Alexandre Julliard committed
221 222 223
        /* If there is anything left, add it to the history list
           and execute it. Otherwise, re-execute last command. */

Alexandre Julliard's avatar
Alexandre Julliard committed
224 225 226 227 228 229
        if (*line)
        {
            add_history( line );
            strncpy( last_line, line, 255 );
            last_line[255] = '\0'; 
       }
Alexandre Julliard's avatar
Alexandre Julliard committed
230 231 232

        free( line );
        line = last_line;
Alexandre Julliard's avatar
Alexandre Julliard committed
233 234 235 236 237

        if ((len = strlen(line)) > 0)
        {
            if (size < len + 1)
            {
238 239
                DEBUG_Printf(DBG_CHN_MESG,"Fatal readline goof.\n");
		DEBUG_Exit(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
240 241 242 243 244 245 246
            }
            strcpy(buf, line);
            buf[len] = '\n';
            buf[len+1] = 0;
            return len + 1;
        }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
247 248
}

Alexandre Julliard's avatar
Alexandre Julliard committed
249
static char *local_symbols[30];
Alexandre Julliard's avatar
Alexandre Julliard committed
250 251
static int next_symbol;

252 253
static char * make_symbol(char * symbol)
{
254
        return local_symbols[next_symbol++] = DBG_strdup(symbol);
Alexandre Julliard's avatar
Alexandre Julliard committed
255 256
}

257
void flush_symbols(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
258
{
259
	while(--next_symbol>= 0) DBG_free(local_symbols[next_symbol]);
Alexandre Julliard's avatar
Alexandre Julliard committed
260 261 262
	next_symbol = 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
263
#endif  /* DONT_USE_READLINE */