VirtualBox

Changeset 5686 in vbox for trunk


Ignore:
Timestamp:
Nov 11, 2007 12:22:14 PM (17 years ago)
Author:
vboxsync
Message:

Got the DBGC parser testcase framework going. enough fun for now.

Location:
trunk/src/VBox/Debugger
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGCCmdHlp.cpp

    r5676 r5686  
    559559     */
    560560    pDbgc->pszScratch = pDbgc->pszScratch + cb + 1;
    561     int rc = dbgcProcessCommand(pDbgc, pszScratch, cb);
     561    int rc = dbgcProcessCommand(pDbgc, pszScratch, cb, false /* fNoExecute */);
    562562
    563563    /* Restore the scratch state. */
  • trunk/src/VBox/Debugger/DBGCCmdWorkers.cpp

    r5677 r5686  
    346346    /* Execute the command. */
    347347    pDbgc->pszScratch = pDbgc->pszScratch + pBp->cchCmd + 1;
    348     int rc = dbgcProcessCommand(pDbgc, pszScratch, pBp->cchCmd);
     348    int rc = dbgcProcessCommand(pDbgc, pszScratch, pBp->cchCmd, false /* fNoExecute */);
    349349
    350350    /* Restore the scratch state. */
  • trunk/src/VBox/Debugger/DBGCInternal.h

    r5685 r5686  
    5454#define VERR_PARSE_WRITEONLY_SYMBOL             (VERR_PARSE_FIRST - 20)
    5555#define VERR_PARSE_NO_ARGUMENT_MATCH            (VERR_PARSE_FIRST - 21)
     56#define VINF_PARSE_COMMAND_NOT_FOUND            (VERR_PARSE_FIRST - 22)
     57#define VINF_PARSE_INVALD_COMMAND_NAME          (VERR_PARSE_FIRST - 23)
    5658#define VERR_PARSE_LAST                         (VERR_PARSE_FIRST - 30)
    5759
     
    186188    DBGCVAR             aArgs[100];
    187189
    188     /** rc from last dbgcHlpPrintfV(). */
     190    /** rc from the last dbgcHlpPrintfV(). */
    189191    int                 rcOutput;
    190 
     192    /** rc from the last command. */
     193    int                 rcCmd;
    191194    /** @} */
    192195} DBGC;
     
    328331*   Internal Functions                                                         *
    329332*******************************************************************************/
    330 int     dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags);
    331 int     dbgcRun(PDBGC pDbgc);
    332 void    dbgcDestroy(PDBGC pDbgc);
    333 
    334333int     dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
    335334int     dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
     
    346345
    347346int     dbgcEvalSub(PDBGC pDbgc, char *pszExpr, size_t cchExpr, PDBGCVAR pResult);
    348 int     dbgcProcessCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd);
     347int     dbgcProcessCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd, bool fNoExecute);
    349348
    350349int     dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult);
     
    359358
    360359void    dbgcInitCmdHlp(PDBGC pDbgc);
     360
     361/* For tstDBGCParser: */
     362int     dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags);
     363int     dbgcRun(PDBGC pDbgc);
     364int     dbgcProcessInput(PDBGC pDbgc, bool fNoExecute);
     365void    dbgcDestroy(PDBGC pDbgc);
    361366
    362367
  • trunk/src/VBox/Debugger/DBGConsole.cpp

    r5685 r5686  
    12031203 *
    12041204 * @returns VBox status code. Any error indicates the termination of the console session.
    1205  * @param   pDbgc   Debugger console instance data.
    1206  * @param   pszCmd  Pointer to the command.
    1207  * @param   cchCmd  Length of the command.
    1208  */
    1209 int dbgcProcessCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd)
     1205 * @param   pDbgc       Debugger console instance data.
     1206 * @param   pszCmd      Pointer to the command.
     1207 * @param   cchCmd      Length of the command.
     1208 * @param   fNoExecute  Indicates that no commands should actually be executed.
     1209 */
     1210int dbgcProcessCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd, bool fNoExecute)
    12101211{
    12111212    char *pszCmdInput = pszCmd;
     
    12301231    if (*pszArgs && (!isblank(*pszArgs) || pszArgs == pszCmd))
    12311232    {
     1233        pDbgc->rcCmd = VINF_PARSE_INVALD_COMMAND_NAME;
    12321234        pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "Syntax error in command '%s'!\n", pszCmdInput);
    12331235        return 0;
     
    12391241    PCDBGCCMD pCmd = dbgcRoutineLookup(pDbgc, pszCmd, pszArgs - pszCmd, fExternal);
    12401242    if (!pCmd || (pCmd->fFlags & DBGCCMD_FLAGS_FUNCTION))
     1243    {
     1244        pDbgc->rcCmd = VINF_PARSE_COMMAND_NOT_FOUND;
    12411245        return pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "Unknown command '%s'!\n", pszCmdInput);
     1246    }
    12421247
    12431248    /*
    12441249     * Parse arguments (if any).
    12451250     */
    1246     unsigned    cArgs;
     1251    unsigned cArgs;
    12471252    int rc = dbgcProcessArguments(pDbgc, pCmd, pszArgs, &pDbgc->aArgs[pDbgc->iArg], ELEMENTS(pDbgc->aArgs) - pDbgc->iArg, &cArgs);
    12481253
     
    12521257    if (!rc)
    12531258    {
    1254         rc = pCmd->pfnHandler(pCmd, &pDbgc->CmdHlp, pDbgc->pVM, &pDbgc->aArgs[0], cArgs, NULL);
     1259        if (!fNoExecute)
     1260            rc = pCmd->pfnHandler(pCmd, &pDbgc->CmdHlp, pDbgc->pVM, &pDbgc->aArgs[0], cArgs, NULL);
     1261        pDbgc->rcCmd = rc;
    12551262    }
    12561263    else
    12571264    {
     1265        pDbgc->rcCmd = rc;
     1266
    12581267        /* report parse / eval error. */
    12591268        switch (rc)
     
    13571366 *
    13581367 * @returns VBox status code. Any error indicates the termination of the console session.
    1359  * @param   pDbgc   Debugger console instance data.
    1360  */
    1361 static int dbgcProcessCommands(PDBGC pDbgc)
     1368 * @param   pDbgc       Debugger console instance data.
     1369 * @param   fNoExecute  Indicates that no commands should actually be executed.
     1370 */
     1371static int dbgcProcessCommands(PDBGC pDbgc, bool fNoExecute)
    13621372{
    13631373    int rc = 0;
     
    14151425        pDbgc->pszScratch = psz;
    14161426        pDbgc->iArg       = 0;
    1417         rc = dbgcProcessCommand(pDbgc, &pDbgc->achScratch[0], psz - &pDbgc->achScratch[0] - 1);
     1427        rc = dbgcProcessCommand(pDbgc, &pDbgc->achScratch[0], psz - &pDbgc->achScratch[0] - 1, fNoExecute);
    14181428        if (rc)
    14191429            break;
     
    15751585 *
    15761586 * @returns VBox status.
    1577  * @param   pDbgc   Debugger console instance data.
    1578  */
    1579 static int dbgcProcessInput(PDBGC pDbgc)
     1587 * @param   pDbgc       Debugger console instance data.
     1588 * @param   fNoExecute  Indicates that no commands should actually be executed.
     1589 */
     1590int dbgcProcessInput(PDBGC pDbgc, bool fNoExecute)
    15801591{
    15811592    /*
     
    15931604        /** @todo this fReady stuff is broken. */
    15941605        pDbgc->fReady = false;
    1595         rc = dbgcProcessCommands(pDbgc);
     1606        rc = dbgcProcessCommands(pDbgc, fNoExecute);
    15961607        if (VBOX_SUCCESS(rc) && rc != VWRN_DBGC_CMD_PENDING)
    15971608            pDbgc->fReady = true;
     
    18581869            if (pDbgc->pBack->pfnInput(pDbgc->pBack, 0))
    18591870            {
    1860                 rc = dbgcProcessInput(pDbgc);
     1871                rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
    18611872                if (VBOX_FAILURE(rc))
    18621873                    break;
     
    18701881            if (pDbgc->pBack->pfnInput(pDbgc->pBack, pDbgc->fLog ? 1 : 1000))
    18711882            {
    1872                 rc = dbgcProcessInput(pDbgc);
     1883                rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
    18731884                if (VBOX_FAILURE(rc))
    18741885                    break;
     
    19391950    //pDbgc->iArg             = 0;
    19401951    //pDbgc->rcOutput         = 0;
     1952    //pDbgc->rcCmd            = 0;
    19411953
    19421954    dbgcInitOpCharBitMap();
  • trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp

    r5685 r5686  
    5050/** For keeping track of output prefixing. */
    5151static bool g_fPendingPrefix = true;
    52 
     52/** Pointer to the the current input position. */
     53const char *g_pszInput = NULL;
    5354
    5455/**
     
    6465static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies)
    6566{
    66     RTPrintf("tstDBGCParser: tstDBGCBackInput was called!\n");
    67     g_cErrors++;
    68     return false;
     67    return g_pszInput != NULL
     68       && *g_pszInput != '\0';
    6969}
    7070
     
    8585static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
    8686{
    87     RTPrintf("tstDBGCParser: tstDBGCBackRead was called!\n");
    88     g_cErrors++;
    89     return VERR_INTERNAL_ERROR;
     87    if (g_pszInput && *g_pszInput)
     88    {
     89        size_t cb = strlen(g_pszInput);
     90        if (cb > cbBuf)
     91            cb = cbBuf;
     92        *pcbRead = cb;
     93        memcpy(pvBuf, g_pszInput, cb);
     94        g_pszInput += cb;
     95    }
     96    else
     97        *pcbRead = 0;
     98    return VINF_SUCCESS;
    9099}
    91100
     
    106115{
    107116    const char *pch = (const char *)pvBuf;
    108     *pcbWritten = cbBuf;
     117    if (pcbWritten)
     118        *pcbWritten = cbBuf;
    109119    while (cbBuf-- > 0)
    110120    {
    111121        if (g_fPendingPrefix)
    112122        {
    113             RTPrintf("tstDBGCParser: OUTPUT: ");
     123            RTPrintf("tstDBGCParser:  OUTPUT: ");
    114124            g_fPendingPrefix = false;
    115125        }
     
    135145
    136146
     147/**
     148 * Tries one command string.
     149 * @param   pDbgc           Pointer to the debugger instance.
     150 * @param   pszCmds         The command to test.
     151 * @param   rcCmd           The expected result.
     152 */
     153static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd)
     154{
     155    g_pszInput = pszCmds;
     156    if (strchr(pszCmds, '\0')[-1] == '\n')
     157        RTPrintf("tstDBGCParser: RUNNING: %s", pszCmds);
     158    else
     159        RTPrintf("tstDBGCParser: RUNNING: %s\n", pszCmds);
     160
     161    pDbgc->rcCmd = VERR_INTERNAL_ERROR;
     162    dbgcProcessInput(pDbgc, true /* fNoExecute */);
     163    tstCompleteOutput();
     164
     165    if (pDbgc->rcCmd != rcCmd)
     166    {
     167        RTPrintf("tstDBGCParser: rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd);
     168        g_cErrors++;
     169    }
     170}
    137171
    138172
     
    152186    if (RT_SUCCESS(rc))
    153187    {
     188        rc = dbgcProcessInput(pDbgc, true /* fNoExecute */);
     189        tstCompleteOutput();
     190        if (RT_SUCCESS(rc))
     191        {
     192            tstTry(pDbgc, "stop\n", VINF_SUCCESS);
     193            tstTry(pDbgc, "format \n", VERR_PARSE_TOO_FEW_ARGUMENTS);
     194            tstTry(pDbgc, "format 0 1 23 4\n", VERR_PARSE_TOO_MANY_ARGUMENTS);
     195            tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS);
     196        }
    154197
    155198        dbgcDestroy(pDbgc);
    156199    }
    157 
    158200
    159201    /*
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