VirtualBox

Ignore:
Timestamp:
Nov 11, 2007 5:54:53 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
26021
Message:

Split out command worker routines and stuffed the variable manipulation routines in with them.

File:
1 edited

Legend:

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

    r5676 r5677  
    136136
    137137
    138 
    139 
    140 
    141 
    142 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    143 //
    144 //
    145 //      V a r i a b l e   M a n i p u l a t i o n
    146 //
    147 //
    148 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    149 
    150 
    151 
    152 /** @todo move me!*/
    153 void dbgcVarSetGCFlat(PDBGCVAR pVar, RTGCPTR GCFlat)
     138/**
     139 * Initalizes g_bmOperatorChars.
     140 */
     141static void dbgcInitOpCharBitMap(void)
    154142{
    155     if (pVar)
    156     {
    157         pVar->enmType  = DBGCVAR_TYPE_GC_FLAT;
    158         pVar->u.GCFlat = GCFlat;
    159         pVar->enmRangeType = DBGCVAR_RANGE_NONE;
    160         pVar->u64Range  = 0;
    161     }
     143    memset(g_bmOperatorChars, 0, sizeof(g_bmOperatorChars));
     144    for (unsigned iOp = 0; iOp < g_cOps; iOp++)
     145        ASMBitSet(&g_bmOperatorChars[0], (uint8_t)g_aOps[iOp].szName[0]);
    162146}
    163147
    164148
    165 /** @todo move me!*/
    166 void dbgcVarSetGCFlatByteRange(PDBGCVAR pVar, RTGCPTR GCFlat, uint64_t cb)
     149/**
     150 * Checks whether the character may be the start of an operator.
     151 *
     152 * @returns true/false.
     153 * @param   ch      The character.
     154 */
     155DECLINLINE(bool) dbgcIsOpChar(char ch)
    167156{
    168     if (pVar)
    169     {
    170         pVar->enmType  = DBGCVAR_TYPE_GC_FLAT;
    171         pVar->u.GCFlat = GCFlat;
    172         pVar->enmRangeType = DBGCVAR_RANGE_BYTES;
    173         pVar->u64Range  = cb;
    174     }
     157    return ASMBitTest(&g_bmOperatorChars[0], (uint8_t)ch);
    175158}
    176 
    177 
    178 /** @todo move me!*/
    179 void dbgcVarSetVar(PDBGCVAR pVar, PCDBGCVAR pVar2)
    180 {
    181     if (pVar)
    182     {
    183         if (pVar2)
    184             *pVar = *pVar2;
    185         else
    186         {
    187             pVar->enmType = DBGCVAR_TYPE_UNKNOWN;
    188             memset(&pVar->u, 0, sizeof(pVar->u));
    189             pVar->enmRangeType = DBGCVAR_RANGE_NONE;
    190             pVar->u64Range  = 0;
    191         }
    192     }
    193 }
    194 
    195 
    196 /** @todo move me!*/
    197 void dbgcVarSetByteRange(PDBGCVAR pVar, uint64_t cb)
    198 {
    199     if (pVar)
    200     {
    201         pVar->enmRangeType = DBGCVAR_RANGE_BYTES;
    202         pVar->u64Range  = cb;
    203     }
    204 }
    205 
    206 
    207 /** @todo move me!*/
    208 void dbgcVarSetNoRange(PDBGCVAR pVar)
    209 {
    210     if (pVar)
    211     {
    212         pVar->enmRangeType = DBGCVAR_RANGE_NONE;
    213         pVar->u64Range  = 0;
    214     }
    215 }
    216 
    217 
    218 /**
    219  * Converts a DBGC variable to a DBGF address.
    220  *
    221  * @returns VBox status code.
    222  * @param   pDbgc       The DBGC instance.
    223  * @param   pVar        The variable.
    224  * @param   pAddress    Where to store the address.
    225  */
    226 int dbgcVarToDbgfAddr(PDBGC pDbgc, PCDBGCVAR pVar, PDBGFADDRESS pAddress)
    227 {
    228     AssertReturn(pVar, VERR_INVALID_PARAMETER);
    229     switch (pVar->enmType)
    230     {
    231         case DBGCVAR_TYPE_GC_FLAT:
    232             DBGFR3AddrFromFlat(pDbgc->pVM, pAddress, pVar->u.GCFlat);
    233             return VINF_SUCCESS;
    234 
    235         case DBGCVAR_TYPE_NUMBER:
    236             DBGFR3AddrFromFlat(pDbgc->pVM, pAddress, (RTGCUINTPTR)pVar->u.u64Number);
    237             return VINF_SUCCESS;
    238 
    239         case DBGCVAR_TYPE_GC_FAR:
    240             return DBGFR3AddrFromSelOff(pDbgc->pVM, pAddress, pVar->u.GCFar.sel, pVar->u.GCFar.sel);
    241 
    242         case DBGCVAR_TYPE_STRING:
    243         case DBGCVAR_TYPE_SYMBOL:
    244         {
    245             DBGCVAR Var;
    246             int rc = pDbgc->CmdHlp.pfnEval(&pDbgc->CmdHlp, &Var, "%%(%DV)", pVar);
    247             if (VBOX_FAILURE(rc))
    248                 return rc;
    249             return dbgcVarToDbgfAddr(pDbgc, &Var, pAddress);
    250         }
    251 
    252         case DBGCVAR_TYPE_GC_PHYS:
    253         case DBGCVAR_TYPE_HC_FLAT:
    254         case DBGCVAR_TYPE_HC_FAR:
    255         case DBGCVAR_TYPE_HC_PHYS:
    256         default:
    257             return VERR_PARSE_CONVERSION_FAILED;
    258     }
    259 }
    260 
    261 
    262 
    263 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    264 //
    265 //
    266 //      B r e a k p o i n t   M a n a g e m e n t
    267 //
    268 //
    269 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    270 
    271 
    272 /**
    273  * Adds a breakpoint to the DBGC breakpoint list.
    274  */
    275 int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd)
    276 {
    277     /*
    278      * Check if it already exists.
    279      */
    280     PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
    281     if (pBp)
    282         return VERR_DBGC_BP_EXISTS;
    283 
    284     /*
    285      * Add the breakpoint.
    286      */
    287     if (pszCmd)
    288         pszCmd = RTStrStripL(pszCmd);
    289     size_t cchCmd = pszCmd ? strlen(pszCmd) : 0;
    290     pBp = (PDBGCBP)RTMemAlloc(RT_OFFSETOF(DBGCBP, szCmd[cchCmd + 1]));
    291     if (!pBp)
    292         return VERR_NO_MEMORY;
    293     if (cchCmd)
    294         memcpy(pBp->szCmd, pszCmd, cchCmd + 1);
    295     else
    296         pBp->szCmd[0] = '\0';
    297     pBp->cchCmd = cchCmd;
    298     pBp->iBp    = iBp;
    299     pBp->pNext  = pDbgc->pFirstBp;
    300     pDbgc->pFirstBp = pBp;
    301 
    302     return VINF_SUCCESS;
    303 }
    304 
    305 /**
    306  * Updates the a breakpoint.
    307  *
    308  * @returns VBox status code.
    309  * @param   pDbgc       The DBGC instance.
    310  * @param   iBp         The breakpoint to update.
    311  * @param   pszCmd      The new command.
    312  */
    313 int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd)
    314 {
    315     /*
    316      * Find the breakpoint.
    317      */
    318     PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
    319     if (!pBp)
    320         return VERR_DBGC_BP_NOT_FOUND;
    321 
    322     /*
    323      * Do we need to reallocate?
    324      */
    325     if (pszCmd)
    326         pszCmd = RTStrStripL(pszCmd);
    327     if (!pszCmd || !*pszCmd)
    328         pBp->szCmd[0] = '\0';
    329     else
    330     {
    331         size_t cchCmd = strlen(pszCmd);
    332         if (strlen(pBp->szCmd) >= cchCmd)
    333         {
    334             memcpy(pBp->szCmd, pszCmd, cchCmd + 1);
    335             pBp->cchCmd = cchCmd;
    336         }
    337         else
    338         {
    339             /*
    340              * Yes, let's do it the simple way...
    341              */
    342             int rc = dbgcBpDelete(pDbgc, iBp);
    343             AssertRC(rc);
    344             return dbgcBpAdd(pDbgc, iBp, pszCmd);
    345         }
    346     }
    347     return VINF_SUCCESS;
    348 }
    349 
    350 
    351 /**
    352  * Deletes a breakpoint.
    353  *
    354  * @returns VBox status code.
    355  * @param   pDbgc       The DBGC instance.
    356  * @param   iBp         The breakpoint to delete.
    357  */
    358 int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp)
    359 {
    360     /*
    361      * Search thru the list, when found unlink and free it.
    362      */
    363     PDBGCBP pBpPrev = NULL;
    364     PDBGCBP pBp = pDbgc->pFirstBp;
    365     for (; pBp; pBp = pBp->pNext)
    366     {
    367         if (pBp->iBp == iBp)
    368         {
    369             if (pBpPrev)
    370                 pBpPrev->pNext = pBp->pNext;
    371             else
    372                 pDbgc->pFirstBp = pBp->pNext;
    373             RTMemFree(pBp);
    374             return VINF_SUCCESS;
    375         }
    376         pBpPrev = pBp;
    377     }
    378 
    379     return VERR_DBGC_BP_NOT_FOUND;
    380 }
    381 
    382 
    383 /**
    384  * Get a breakpoint.
    385  *
    386  * @returns Pointer to the breakpoint.
    387  * @returns NULL if the breakpoint wasn't found.
    388  * @param   pDbgc       The DBGC instance.
    389  * @param   iBp         The breakpoint to get.
    390  */
    391 PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp)
    392 {
    393     /*
    394      * Enumerate the list.
    395      */
    396     PDBGCBP pBp = pDbgc->pFirstBp;
    397     for (; pBp; pBp = pBp->pNext)
    398         if (pBp->iBp == iBp)
    399             return pBp;
    400     return NULL;
    401 }
    402 
    403 
    404 /**
    405  * Executes the command of a breakpoint.
    406  *
    407  * @returns VINF_DBGC_BP_NO_COMMAND if there is no command associated with the breakpoint.
    408  * @returns VERR_DBGC_BP_NOT_FOUND if the breakpoint wasn't found.
    409  * @returns VERR_BUFFER_OVERFLOW if the is not enough space in the scratch buffer for the command.
    410  * @returns VBox status code from dbgcProcessCommand() other wise.
    411  * @param   pDbgc       The DBGC instance.
    412  * @param   iBp         The breakpoint to execute.
    413  */
    414 int dbgcBpExec(PDBGC pDbgc, RTUINT iBp)
    415 {
    416     /*
    417      * Find the breakpoint.
    418      */
    419     PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
    420     if (!pBp)
    421         return VERR_DBGC_BP_NOT_FOUND;
    422 
    423     /*
    424      * Anything to do?
    425      */
    426     if (!pBp->cchCmd)
    427         return VINF_DBGC_BP_NO_COMMAND;
    428 
    429     /*
    430      * Execute the command.
    431      * This means copying it to the scratch buffer and process it as if it
    432      * were user input. We must save and restore the state of the scratch buffer.
    433      */
    434     /* Save the scratch state. */
    435     char       *pszScratch  = pDbgc->pszScratch;
    436     unsigned    iArg        = pDbgc->iArg;
    437 
    438     /* Copy the command to the scratch buffer. */
    439     size_t cbScratch = sizeof(pDbgc->achScratch) - (pDbgc->pszScratch - &pDbgc->achScratch[0]);
    440     if (pBp->cchCmd >= cbScratch)
    441         return VERR_BUFFER_OVERFLOW;
    442     memcpy(pDbgc->pszScratch, pBp->szCmd, pBp->cchCmd + 1);
    443 
    444     /* Execute the command. */
    445     pDbgc->pszScratch = pDbgc->pszScratch + pBp->cchCmd + 1;
    446     int rc = dbgcProcessCommand(pDbgc, pszScratch, pBp->cchCmd);
    447 
    448     /* Restore the scratch state. */
    449     pDbgc->iArg         = iArg;
    450     pDbgc->pszScratch   = pszScratch;
    451 
    452     return rc;
    453 }
    454 
    455 
    456 
    457 
    458 
    459 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    460 //
    461 //
    462 //      I n p u t ,   p a r s i n g   a n d   l o g g i n g
    463 //
    464 //
    465 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    466 
    467159
    468160
     
    715407
    716408    return VERR_PARSE_NOT_IMPLEMENTED;
    717 }
    718 
    719 
    720 /**
    721  * Initalizes g_bmOperatorChars.
    722  */
    723 static void dbgcInitOpCharBitMap(void)
    724 {
    725     memset(g_bmOperatorChars, 0, sizeof(g_bmOperatorChars));
    726     for (unsigned iOp = 0; iOp < g_cOps; iOp++)
    727         ASMBitSet(&g_bmOperatorChars[0], (uint8_t)g_aOps[iOp].szName[0]);
    728 }
    729 
    730 
    731 /**
    732  * Checks whether the character may be the start of an operator.
    733  *
    734  * @returns true/false.
    735  * @param   ch      The character.
    736  */
    737 DECLINLINE(bool) dbgcIsOpChar(char ch)
    738 {
    739     return ASMBitTest(&g_bmOperatorChars[0], (uint8_t)ch);
    740409}
    741410
Note: See TracChangeset for help on using the changeset viewer.

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