VirtualBox

Changeset 41559 in vbox for trunk


Ignore:
Timestamp:
Jun 4, 2012 12:57:02 AM (13 years ago)
Author:
vboxsync
Message:

DBGC: More parser fixes, added comma (,) as a argument separator (in addition to space and tab). Not entirely perfect yet for trailing, but who cares.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/err.h

    r41558 r41559  
    21222122/** Syntax error - too many arguments for static storage. */
    21232123#define VERR_DBGC_PARSE_ARGUMENT_OVERFLOW           (VERR_DBGC_PARSE_LOWEST + 2)
     2124/** Syntax error - expected binary operator. */
     2125#define VERR_DBGC_PARSE_EXPECTED_BINARY_OP          (VERR_DBGC_PARSE_LOWEST + 3)
    21242126
    21252127/** Syntax error - the argument does not allow a range to be specified. */
  • trunk/src/VBox/Debugger/DBGCEval.cpp

    r41558 r41559  
    549549    unsigned    cBinaryOps  = 0;
    550550    unsigned    cPar        = 0;
     551    unsigned    cchWord     = 0;
    551552    char        chQuote     = '\0';
    552553    char        chPrev      = ' ';
     
    557558    while ((ch = *psz) != '\0')
    558559    {
    559         //Log2(("ch=%c cPar=%d fBinary=%d\n", ch, cPar, fBinary));
    560560        /*
    561561         * String quoting.
     
    563563        if (chQuote)
    564564        {
    565             if (   ch == chQuote
    566                 && psz[1] != chQuote)
    567             {
    568                 chQuote = '\0';
    569                 fBinary = true;
    570             }
     565            if (ch == chQuote)
     566            {
     567                if (psz[1] == chQuote)
     568                {
     569                    psz++;              /* escaped quote */
     570                    cchWord++;
     571                }
     572                else
     573                {
     574                    chQuote = '\0';
     575                    fBinary = true;
     576                    cchWord = 0;
     577                }
     578            }
     579            else
     580                cchWord++;
    571581        }
    572582        else if (ch == '"' || ch == '\'')
     583        {
     584            if (fBinary || cchWord)
     585                return VERR_DBGC_PARSE_EXPECTED_BINARY_OP;
    573586            chQuote = ch;
     587        }
    574588        /*
    575589         * Parentheses.
     
    577591        else if (ch == '(')
    578592        {
     593            if (!cPar && (fBinary || cchWord)) /** @todo function call */
     594                return VERR_DBGC_PARSE_EXPECTED_BINARY_OP;
    579595            cPar++;
    580596            fBinary = false;
     597            cchWord = 0;
    581598        }
    582599        else if (ch == ')')
     
    586603            cPar--;
    587604            fBinary = true;
     605            cchWord = 0;
    588606        }
    589607        /*
     
    622640                psz += pOp->cchName - 1;
    623641                fBinary = false;
    624             }
     642                cchWord = 0;
     643            }
     644            else if (fBinary && !cchWord)
     645                return VERR_DBGC_PARSE_EXPECTED_BINARY_OP;
    625646            else
     647            {
    626648                fBinary = true;
    627         }
     649                cchWord++;
     650            }
     651        }
     652        else if (cPar == 0 && RT_C_IS_BLANK(ch))
     653            cchWord++;
    628654
    629655        /* next */
     
    9741000
    9751001        /*
    976          * Find the end of the argument.
     1002         * Find the end of the argument.  This is just rough splitting,
     1003         * dbgcEvalSub will do stricter syntax checking later on.
    9771004         */
    9781005        int     cPar    = 0;
     
    10001027             * We use the REXX way of escaping the quotation char, i.e. double occurrence.
    10011028             */
    1002             else if (ch == '\'' || ch == '"')
    1003             {
    1004                 if (chQuote)
     1029            else if (chQuote)
     1030            {
     1031                if (ch == chQuote)
    10051032                {
    1006                     /* end quote? */
    1007                     if (ch == chQuote)
     1033                    if (psz[1] == chQuote)
     1034                        psz++;          /* skip the escaped quote char */
     1035                    else
    10081036                    {
    1009                         if (psz[1] == ch)
    1010                             psz++;          /* skip the escaped quote char */
    1011                         else
    1012                             chQuote = '\0'; /* end of quoted string. */
     1037                        chQuote = '\0'; /* end of quoted string. */
     1038                        fBinary = true;
    10131039                    }
    10141040                }
    1015                 else
    1016                     chQuote = ch;           /* open new quote */
     1041            }
     1042            else if (ch == '\'' || ch == '"')
     1043            {
     1044                if (fBinary)
     1045                    return VERR_DBGC_PARSE_EXPECTED_BINARY_OP;
     1046                chQuote = ch;
    10171047            }
    10181048            /*
    10191049             * Parenthesis can of course be nested.
    10201050             */
    1021             else if (!chQuote && ch == '(')
    1022             {
     1051            else if (ch == '(')
     1052            {
     1053                if (!cPar && fBinary)
     1054                    return VERR_DBGC_PARSE_EXPECTED_BINARY_OP;
    10231055                cPar++;
    10241056                fBinary = false;
    10251057            }
    1026             else if (!chQuote && ch == ')')
     1058            else if (ch == ')')
    10271059            {
    10281060                if (!cPar)
     
    10311063                fBinary = true;
    10321064            }
    1033             else if (!chQuote && !cPar)
     1065            else if (!cPar)
    10341066            {
    10351067                /*
    1036                  * Encountering blanks may mean the end of it all. A binary operator
    1037                  * will force continued parsing.
     1068                 * Encountering a comma is a definite end of parameter.
    10381069                 */
    1039                 if (RT_C_IS_BLANK(*psz))
     1070                if (ch == ',')
    10401071                {
    1041                     pszEnd = psz++;         /* just in case. */
     1072                    pszEnd = psz++;
     1073                    break;
     1074                }
     1075
     1076                /*
     1077                 * Encountering blanks may mean the end of it all.  A binary
     1078                 * operator will force continued parsing.
     1079                 */
     1080                if (RT_C_IS_BLANK(ch))
     1081                {
     1082                    pszEnd = psz++;         /* in case it's the end. */
    10421083                    while (RT_C_IS_BLANK(*psz))
    10431084                        psz++;
     1085
     1086                    if (*psz == ',')
     1087                    {
     1088                        psz++;
     1089                        break;
     1090                    }
     1091
    10441092                    PCDBGCOP pOp = dbgcOperatorLookup(pDbgc, psz, fBinary, ' ');
    10451093                    if (!pOp || pOp->fBinary != fBinary)
    10461094                        break;              /* the end. */
     1095
    10471096                    psz += pOp->cchName;
    10481097                    while (RT_C_IS_BLANK(*psz))   /* skip blanks so we don't get here again */
     
    10551104                 * Look for operators without a space up front.
    10561105                 */
    1057                 if (dbgcIsOpChar(*psz))
     1106                if (dbgcIsOpChar(ch))
    10581107                {
    10591108                    PCDBGCOP pOp = dbgcOperatorLookup(pDbgc, psz, fBinary, ' ');
  • trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp

    r41558 r41559  
    861861    tstTry(pDbgc, "cpu @eax\n", VINF_SUCCESS);
    862862    tstTry(pDbgc, "cpu %bad:bad\n", VERR_DBGC_PARSE_CONVERSION_FAILED);
     863    tstTry(pDbgc, "cpu '1'\n", VERR_DBGC_PARSE_INVALID_NUMBER);
    863864}
    864865
     
    872873
    873874    /* The idea here is that since the prefered input is a string, we
    874        definitely won't be mistaking number like beginnings as numbers. */
     875       definitely won't be confused by the number like beginning. */
    875876    tstTryEx(pDbgc, "echo 1234567890abcdefghijklmn\n", VINF_SUCCESS, false, "1234567890abcdefghijklmn", -1);
    876877
     
    11271128    tstTry(pDbgc, "format \n", VERR_DBGC_PARSE_TOO_FEW_ARGUMENTS);
    11281129    tstTry(pDbgc, "format 0 1 23 4\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
     1130    tstTry(pDbgc, "format 'x'\n", VINF_SUCCESS);
     1131    tstTry(pDbgc, "format 'x' 'x'\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
     1132    tstTry(pDbgc, "format 'x''x'\n", VINF_SUCCESS);
     1133    tstTry(pDbgc, "format 'x'\"x\"\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
     1134    tstTry(pDbgc, "format 'x'1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
     1135    tstTry(pDbgc, "format (1)1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
     1136    tstTry(pDbgc, "format (1)(1)\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
     1137    tstTry(pDbgc, "format (1)''\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
     1138    tstTry(pDbgc, "format foo(1)\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP); /** @todo VERR_DBGC_PARSE_FUNCTION_NOT_FOUND */
    11291139    tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS);
     1140    tstTry(pDbgc, "sa 3,23, 4,'q' ,\"21123123\" , 'b' \n", VINF_SUCCESS);
    11301141}
    11311142
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette